diff --git a/dungeonbattle/display/display_manager.py b/dungeonbattle/display/display_manager.py index b2cb125..4b2604f 100644 --- a/dungeonbattle/display/display_manager.py +++ b/dungeonbattle/display/display_manager.py @@ -1,7 +1,8 @@ import curses from dungeonbattle.display.mapdisplay import MapDisplay from dungeonbattle.display.statsdisplay import StatsDisplay -from dungeonbattle.display.menudisplay import MenuDisplay, MainMenuDisplay +from dungeonbattle.display.menudisplay import SettingsMenuDisplay, \ + MainMenuDisplay from dungeonbattle.display.texturepack import TexturePack from typing import Any from dungeonbattle.game import Game, GameMode @@ -18,7 +19,7 @@ class DisplayManager: self.statsdisplay = StatsDisplay(screen, pack) self.mainmenudisplay = MainMenuDisplay(self.game.main_menu, screen, pack) - self.settingsmenudisplay = MenuDisplay(screen, pack) + self.settingsmenudisplay = SettingsMenuDisplay(screen, pack) self.displays = [self.statsdisplay, self.mapdisplay, self.mainmenudisplay, self.settingsmenudisplay] self.update_game_components() diff --git a/dungeonbattle/display/menudisplay.py b/dungeonbattle/display/menudisplay.py index 973dd31..36694d0 100644 --- a/dungeonbattle/display/menudisplay.py +++ b/dungeonbattle/display/menudisplay.py @@ -60,22 +60,32 @@ class MenuDisplay(Display): return [str(a) for a in self.menu.values] +class SettingsMenuDisplay(MenuDisplay): + @property + def values(self) -> List[str]: + return [a[1][1] + (" : " + + ("?" if self.menu.waiting_for_key else a[1][0]) + if a[1][0] else "") for a in self.menu.values] + + class MainMenuDisplay(Display): def __init__(self, menu: MainMenu, *args): super().__init__(*args) self.menu = menu - self.pad = self.newpad(self.rows, self.cols) with open("resources/ascii_art.txt", "r") as file: self.title = file.read().split("\n") + self.pad = self.newpad(max(self.rows, len(self.title) + 30), + max(len(self.title[0]) + 5, self.cols)) + self.menudisplay = MenuDisplay(self.screen, self.pack) self.menudisplay.update_menu(self.menu) def display(self) -> None: for i in range(len(self.title)): - self.pad.addstr(4 + i, self.width // 2 - - len(self.title[0]) // 2 - 1, self.title[i]) + self.pad.addstr(4 + i, max(self.width // 2 + - len(self.title[0]) // 2 - 1, 0), self.title[i]) self.pad.refresh(0, 0, self.y, self.x, self.height, self.width) menuwidth = min(self.menudisplay.preferred_width, self.width) menuy, menux = len(self.title) + 8, self.width // 2 - menuwidth // 2 - 1 diff --git a/dungeonbattle/menus.py b/dungeonbattle/menus.py index 798a9ed..cd7604a 100644 --- a/dungeonbattle/menus.py +++ b/dungeonbattle/menus.py @@ -63,24 +63,8 @@ class SettingsMenu(Menu): waiting_for_key: bool = False def update_values(self, settings: Settings) -> None: - """ - The settings can change, so they are updated - """ - self.values = [] - for i, key in enumerate(settings.settings_keys): - s = settings.get_comment(key) - s += " : " - if self.waiting_for_key and i == self.position: - s += "?" - else: - s += getattr(settings, key).replace("\n", "\\n") - s += 8 * " " # Write over old text - self.values.append(s) - self.values.append("") - self.values.append("Changer le pack de textures n'aura effet") - self.values.append("qu'après avoir relancé le jeu.") - self.values.append("") - self.values.append("Retour (espace)") + self.values = list(settings.__dict__.items()) + self.values.append(("RETURN", ["", "Retour"])) def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str, game: Any) -> None: @@ -99,9 +83,9 @@ class SettingsMenu(Menu): self.go_down() if key == KeyValues.UP: self.go_up() - if key == KeyValues.ENTER and self.position < len(self.values) - 3: + if key == KeyValues.ENTER and self.position < len(self.values) - 1: # Change a setting - option = list(game.settings.settings_keys)[self.position] + option = self.values[self.position][0] if option == "TEXTURE_PACK": game.settings.TEXTURE_PACK = \ TexturePack.get_next_pack_name( @@ -112,7 +96,7 @@ class SettingsMenu(Menu): self.waiting_for_key = True self.update_values(game.settings) else: - option = list(game.settings.settings_keys)[self.position] + option = self.values[self.position][0] # Don't use an already mapped key if any(getattr(game.settings, opt) == raw_key for opt in game.settings.settings_keys if opt != option):