From 60d6c7509a3079e2b5e9c902d3f034713ee1a11c Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 6 Nov 2020 18:25:02 +0100 Subject: [PATCH] Bind Return key to menus --- dungeonbattle/game.py | 2 ++ dungeonbattle/menus.py | 3 ++- dungeonbattle/settings.py | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/dungeonbattle/game.py b/dungeonbattle/game.py index 1466dfd..0787f9c 100644 --- a/dungeonbattle/game.py +++ b/dungeonbattle/game.py @@ -68,6 +68,8 @@ class Game: elif key in (self.settings.KEY_UP_PRIMARY, self.settings.KEY_UP_SECONDARY): return KeyValues.UP + elif key == self.settings.KEY_ENTER: + return KeyValues.ENTER def handle_key_pressed(self, key: KeyValues) -> None: if self.state == GameMode.PLAY: diff --git a/dungeonbattle/menus.py b/dungeonbattle/menus.py index 904fa17..66dc199 100644 --- a/dungeonbattle/menus.py +++ b/dungeonbattle/menus.py @@ -1,4 +1,5 @@ from enum import Enum, auto +from typing import Any class Menu: @@ -13,7 +14,7 @@ class Menu: def go_down(self) -> None: self.position = min(len(self.values) - 1, self.position + 1) - def validate(self) -> None: + def validate(self) -> Any: return self.values[self.position] diff --git a/dungeonbattle/settings.py b/dungeonbattle/settings.py index 5c80b7c..db216df 100644 --- a/dungeonbattle/settings.py +++ b/dungeonbattle/settings.py @@ -27,6 +27,8 @@ class Settings: ['d', 'Touche principale pour aller vers la droite'] self.KEY_RIGHT_SECONDARY = \ ['KEY_RIGHT', 'Touche secondaire pour aller vers la droite'] + self.KEY_ENTER = \ + ['\n', 'Touche pour valider un menu'] self.TEXTURE_PACK = ['ASCII', 'Pack de textures utilisé'] def __getattribute__(self, item: str) -> Any: