Better interaction with inventory menu

This commit is contained in:
Yohann D'ANELLO 2020-12-11 18:07:24 +01:00
parent 089a247b2f
commit 1afa397fec
1 changed files with 8 additions and 1 deletions

View File

@ -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)