From a2afa3b0b999de930a16a6d624bd2290342e4a04 Mon Sep 17 00:00:00 2001 From: Matej Straka Date: Thu, 3 Oct 2024 09:29:14 +0200 Subject: [PATCH] refactor: Add FoV toggle to all modes --- generals/gui/event_handler.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/generals/gui/event_handler.py b/generals/gui/event_handler.py index 50f1012..8946c8a 100644 --- a/generals/gui/event_handler.py +++ b/generals/gui/event_handler.py @@ -78,6 +78,16 @@ def is_click_on_agents_row(self, x: int, y: int, i: int) -> bool: and (i + 1) * c.GUI_ROW_HEIGHT <= y < (i + 2) * c.GUI_ROW_HEIGHT ) + def toggle_player_fov(self): + agents = self.properties.game.agents + agent_fov = self.properties.agent_fov + + x, y = pygame.mouse.get_pos() + for i, agent in enumerate(agents): + if self.is_click_on_agents_row(x, y, i): + agent_fov[agent] = not agent_fov[agent] + break + @abstractmethod def handle_key_event(self, event: Event) -> Command: raise NotImplementedError @@ -113,14 +123,7 @@ def handle_mouse_event(self) -> None: """ Handle mouse clicks in replay mode. """ - agents = self.properties.game.agents - agent_fov = self.properties.agent_fov - - x, y = pygame.mouse.get_pos() - for i, agent in enumerate(agents): - if self.is_click_on_agents_row(x, y, i): - agent_fov[agent] = not agent_fov[agent] - break + self.toggle_player_fov() class GameEventHandler(EventHandler): @@ -132,7 +135,7 @@ def handle_key_event(self, event: Event) -> GameCommand: raise NotImplementedError def handle_mouse_event(self) -> None: - raise NotImplementedError + self.toggle_player_fov() class TrainEventHandler(EventHandler): @@ -146,4 +149,4 @@ def handle_key_event(self, event: Event) -> TrainCommand: return self.command def handle_mouse_event(self) -> None: - raise NotImplementedError + self.toggle_player_fov()