Display comments on settings menu

This commit is contained in:
Yohann D'ANELLO 2020-11-11 23:00:45 +01:00
parent 1eee45a0fd
commit 13ac2ba13a
1 changed files with 13 additions and 5 deletions

View File

@ -56,8 +56,15 @@ class SettingsMenu(Menu):
waiting_for_key: bool = False waiting_for_key: bool = False
def update_values(self, settings: Settings) -> None: def update_values(self, settings: Settings) -> None:
s = settings.dumps_to_string() self.values = []
self.values = s[6:-2].replace("\"", "").split(",\n ") 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, def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str,
game: Any) -> None: game: Any) -> None:
@ -72,15 +79,16 @@ class SettingsMenu(Menu):
if key == KeyValues.UP: if key == KeyValues.UP:
self.go_up() self.go_up()
if key == KeyValues.ENTER: if key == KeyValues.ENTER:
option = self.validate().split(": ")[0] option = list(game.settings.settings_keys)[self.position]
if option != "TEXTURE_PACK": if option != "TEXTURE_PACK":
self.waiting_for_key = True self.waiting_for_key = True
self.update_values(game.settings)
else: else:
option = self.validate().split(": ")[0] option = list(game.settings.settings_keys)[self.position]
setattr(game.settings, option, raw_key) setattr(game.settings, option, raw_key)
game.settings.write_settings() game.settings.write_settings()
self.update_values(game.settings)
self.waiting_for_key = False self.waiting_for_key = False
self.update_values(game.settings)
class ArbitraryMenu(Menu): class ArbitraryMenu(Menu):