From 13ac2ba13af8f89b11b6b6546e438259c6151882 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 11 Nov 2020 23:00:45 +0100 Subject: [PATCH] Display comments on settings menu --- dungeonbattle/menus.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/dungeonbattle/menus.py b/dungeonbattle/menus.py index 3713900..1f741d7 100644 --- a/dungeonbattle/menus.py +++ b/dungeonbattle/menus.py @@ -56,8 +56,15 @@ class SettingsMenu(Menu): waiting_for_key: bool = False def update_values(self, settings: Settings) -> None: - s = settings.dumps_to_string() - self.values = s[6:-2].replace("\"", "").split(",\n ") + 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") + self.values.append(s) def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str, game: Any) -> None: @@ -72,15 +79,16 @@ class SettingsMenu(Menu): if key == KeyValues.UP: self.go_up() if key == KeyValues.ENTER: - option = self.validate().split(": ")[0] + option = list(game.settings.settings_keys)[self.position] if option != "TEXTURE_PACK": self.waiting_for_key = True + self.update_values(game.settings) else: - option = self.validate().split(": ")[0] + option = list(game.settings.settings_keys)[self.position] setattr(game.settings, option, raw_key) game.settings.write_settings() - self.update_values(game.settings) self.waiting_for_key = False + self.update_values(game.settings) class ArbitraryMenu(Menu):