From 089a247b2fdf9c56a45600195fe581b5472bb040 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 11 Dec 2020 17:43:46 +0100 Subject: [PATCH] Maybe mouse clicks may use the game --- squirrelbattle/display/display.py | 3 ++- squirrelbattle/display/display_manager.py | 2 +- squirrelbattle/display/menudisplay.py | 11 +++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/squirrelbattle/display/display.py b/squirrelbattle/display/display.py index ef4053f..c5b1aa3 100644 --- a/squirrelbattle/display/display.py +++ b/squirrelbattle/display/display.py @@ -5,6 +5,7 @@ import curses from typing import Any, Optional, Union from squirrelbattle.display.texturepack import TexturePack +from squirrelbattle.game import Game from squirrelbattle.tests.screen import FakePad @@ -86,7 +87,7 @@ class Display: def display(self) -> None: raise NotImplementedError - def handle_click(self, y: int, x: int) -> None: + def handle_click(self, y: int, x: int, game: Game) -> None: """ A mouse click was performed on the coordinates (y, x) of the pad. Maybe it can do something. diff --git a/squirrelbattle/display/display_manager.py b/squirrelbattle/display/display_manager.py index 708f003..743baef 100644 --- a/squirrelbattle/display/display_manager.py +++ b/squirrelbattle/display/display_manager.py @@ -65,7 +65,7 @@ class DisplayManager: # of that display display = d if display: - display.handle_click(y - display.y, x - display.x) + display.handle_click(y - display.y, x - display.x, self.game) def refresh(self) -> List[Display]: displays = [] diff --git a/squirrelbattle/display/menudisplay.py b/squirrelbattle/display/menudisplay.py index a494484..d745c28 100644 --- a/squirrelbattle/display/menudisplay.py +++ b/squirrelbattle/display/menudisplay.py @@ -1,10 +1,13 @@ # Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse # SPDX-License-Identifier: GPL-3.0-or-later + import curses from typing import List from squirrelbattle.menus import Menu, MainMenu from .display import Display, Box +from ..enums import KeyValues +from ..game import Game from ..resources import ResourceManager from ..translations import gettext as _ @@ -41,12 +44,12 @@ class MenuDisplay(Display): self.height - 2 + self.y, self.width - 2 + self.x) - def handle_click(self, y: int, x: int) -> None: + def handle_click(self, y: int, x: int, game: Game) -> None: """ We can select a menu item with the mouse. """ self.menu.position = y - 1 - curses.ungetch('\n') + game.handle_key_pressed(KeyValues.ENTER) @property def truewidth(self) -> int: @@ -106,13 +109,13 @@ class MainMenuDisplay(Display): menuy, menux, min(self.menudisplay.preferred_height, self.height - menuy), menuwidth) - def handle_click(self, y: int, x: int) -> None: + def handle_click(self, y: int, x: int, game: Game) -> None: menuwidth = min(self.menudisplay.preferred_width, self.width) menuy, menux = len(self.title) + 8, self.width // 2 - menuwidth // 2 - 1 menuheight = min(self.menudisplay.preferred_height, self.height - menuy) if menuy <= y < menuy + menuheight and menux <= x < menux + menuwidth: - self.menudisplay.handle_click(y - menuy, x - menux) + self.menudisplay.handle_click(y - menuy, x - menux, game) class InventoryDisplay(MenuDisplay):