From 18336f58d3efb069f3481626cc46219fadf06ed6 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sun, 5 Sep 2021 21:14:18 -0700 Subject: [PATCH] Minor cleanup of notification system. --- game/event/event.py | 41 +++++++---------------- game/game.py | 12 +++---- qt_ui/windows/settings/QSettingsWindow.py | 13 ------- 3 files changed, 18 insertions(+), 48 deletions(-) diff --git a/game/event/event.py b/game/event/event.py index e40cb76f..41fda58f 100644 --- a/game/event/event.py +++ b/game/event/event.py @@ -8,7 +8,6 @@ from dcs.task import Task from game import persistency from game.debriefing import Debriefing -from game.infos.information import Information from game.operation.operation import Operation from game.theater import ControlPoint from gen.ato import AirTaskingOrder @@ -173,13 +172,10 @@ class Event: def commit_building_losses(self, debriefing: Debriefing) -> None: for loss in debriefing.building_losses: loss.ground_object.kill() - self.game.informations.append( - Information( - "Building destroyed", - f"{loss.ground_object.dcs_identifier} has been destroyed at " - f"location {loss.ground_object.obj_name}", - self.game.turn, - ) + self.game.message( + "Building destroyed", + f"{loss.ground_object.dcs_identifier} has been destroyed at " + f"location {loss.ground_object.obj_name}", ) @staticmethod @@ -191,19 +187,16 @@ class Event: for captured in debriefing.base_captures: try: if captured.captured_by_player: - info = Information( + self.game.message( f"{captured.control_point} captured!", f"We took control of {captured.control_point}.", - self.game.turn, ) else: - info = Information( + self.game.message( f"{captured.control_point} lost!", f"The enemy took control of {captured.control_point}.", - self.game.turn, ) - self.game.informations.append(info) captured.control_point.capture(self.game, captured.captured_by_player) logging.info(f"Will run redeploy for {captured.control_point}") self.redeploy_units(captured.control_point) @@ -330,34 +323,28 @@ class Event: # Handle the case where there are no casualties at all on either side but both sides still have units if delta == 0.0: print(status_msg) - info = Information( + self.game.message( "Frontline Report", f"Our ground forces from {cp.name} reached a stalemate with enemy forces from {enemy_cp.name}.", - self.game.turn, ) - self.game.informations.append(info) else: if player_won: print(status_msg) cp.base.affect_strength(delta) enemy_cp.base.affect_strength(-delta) - info = Information( + self.game.message( "Frontline Report", - f"Our ground forces from {cp.name} are making progress toward {enemy_cp.name}. {status_msg}", - self.game.turn, + f"Our ground forces from {cp.name} are making progress toward {enemy_cp.name}. {status_msg}", ) - self.game.informations.append(info) else: print(status_msg) enemy_cp.base.affect_strength(delta) cp.base.affect_strength(-delta) - info = Information( + self.game.message( "Frontline Report", f"Our ground forces from {cp.name} are losing ground against the enemy forces from " f"{enemy_cp.name}. {status_msg}", - self.game.turn, ) - self.game.informations.append(info) def redeploy_units(self, cp: ControlPoint) -> None: """ " @@ -410,10 +397,8 @@ class Event: total_units_redeployed += move_count if total_units_redeployed > 0: - text = ( + self.game.message( + "Units redeployed", f"{total_units_redeployed} units have been redeployed from " - f"{source.name} to {destination.name}" + f"{source.name} to {destination.name}", ) - info = Information("Units redeployed", text, self.game.turn) - self.game.informations.append(info) - logging.info(text) diff --git a/game/game.py b/game/game.py index 6d059692..b6821f8e 100644 --- a/game/game.py +++ b/game/game.py @@ -105,8 +105,8 @@ class Game: self.game_stats = GameStats() self.notes = "" self.ground_planners: dict[int, GroundPlanner] = {} - self.informations = [] - self.informations.append(Information("Game Start", "-" * 40, 0)) + self.informations: list[Information] = [] + self.message("Game Start", "-" * 40) # Culling Zones are for areas around points of interest that contain things we may not wish to cull. self.__culling_zones: List[Point] = [] self.__destroyed_units: list[dict[str, Union[float, str]]] = [] @@ -269,9 +269,7 @@ class Game: Args: skipped: True if the turn was skipped. """ - self.informations.append( - Information("End of turn #" + str(self.turn), "-" * 40, 0) - ) + self.message("End of turn #" + str(self.turn), "-" * 40) self.turn += 1 # The coalition-specific turn finalization *must* happen before unit deliveries, @@ -404,8 +402,8 @@ class Game: gplanner.plan_groundwar() self.ground_planners[cp.id] = gplanner - def message(self, text: str) -> None: - self.informations.append(Information(text, turn=self.turn)) + def message(self, title: str, text: str = "") -> None: + self.informations.append(Information(title, text, turn=self.turn)) @property def current_turn_time_of_day(self) -> TimeOfDay: diff --git a/qt_ui/windows/settings/QSettingsWindow.py b/qt_ui/windows/settings/QSettingsWindow.py index 8cd86618..c7717a74 100644 --- a/qt_ui/windows/settings/QSettingsWindow.py +++ b/qt_ui/windows/settings/QSettingsWindow.py @@ -22,7 +22,6 @@ from dcs.forcedoptions import ForcedOptions import qt_ui.uiconstants as CONST from game.game import Game -from game.infos.information import Information from game.settings import Settings, AutoAtoBehavior from qt_ui.widgets.QLabeledWidget import QLabeledWidget from qt_ui.widgets.spinsliders import TenthsSpinSlider, TimeInputs @@ -894,18 +893,6 @@ class QSettingsWindow(QDialog): def cheatMoney(self, amount): logging.info("CHEATING FOR AMOUNT : " + str(amount) + "M") self.game.blue.budget += amount - if amount > 0: - self.game.informations.append( - Information( - "CHEATER", - "You are a cheater and you should feel bad", - self.game.turn, - ) - ) - else: - self.game.informations.append( - Information("CHEATER", "You are still a cheater !", self.game.turn) - ) GameUpdateSignal.get_instance().updateGame(self.game) def applySettings(self):