From 1afa397fec73b94d7cfb0169ed3e1b6d90060ea0 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 11 Dec 2020 18:07:24 +0100 Subject: [PATCH] Better interaction with inventory menu --- squirrelbattle/display/menudisplay.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/squirrelbattle/display/menudisplay.py b/squirrelbattle/display/menudisplay.py index d745c28..eee4606 100644 --- a/squirrelbattle/display/menudisplay.py +++ b/squirrelbattle/display/menudisplay.py @@ -48,7 +48,7 @@ class MenuDisplay(Display): """ We can select a menu item with the mouse. """ - self.menu.position = y - 1 + self.menu.position = max(0, min(len(self.menu.values) - 1, y - 1)) game.handle_key_pressed(KeyValues.ENTER) @property @@ -136,3 +136,10 @@ class InventoryDisplay(MenuDisplay): @property def trueheight(self) -> int: return 2 + super().trueheight + + def handle_click(self, y: int, x: int, game: Game) -> None: + """ + We can select a menu item with the mouse. + """ + self.menu.position = max(0, min(len(self.menu.values) - 1, y - 3)) + game.handle_key_pressed(KeyValues.ENTER)