From 5f5dc6bfbc4604c60402a0d1c3c9216a18ae07e6 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Sun, 21 Aug 2022 17:31:05 +0200 Subject: [PATCH] ModSettings can now have a description --- .gitignore | 1 + Pack/MKWFaraphel/mod_config.json | 12 +++++++++ source/gui/mod_settings.py | 45 ++++++++++++++++--------------- source/mkw/ModConfig.py | 13 +++++++++ source/mkw/ModSettings/Check.py | 5 ++-- source/mkw/ModSettings/Choices.py | 7 +++-- source/mkw/ModSettings/String.py | 13 +++++---- 7 files changed, 65 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 41bb7d5..1c74d3d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /.idea/ /.cache/ +/.pytest_cache/ /option.json /error.log diff --git a/Pack/MKWFaraphel/mod_config.json b/Pack/MKWFaraphel/mod_config.json index ba714c0..9529adb 100644 --- a/Pack/MKWFaraphel/mod_config.json +++ b/Pack/MKWFaraphel/mod_config.json @@ -27,6 +27,10 @@ "en": "Mode", "fr": "Mode" }, + "description": { + "en": "Special mod's configuration.", + "fr": "Configuration spécial du mod." + }, "type": "choices", "choices": [ "normal", @@ -38,6 +42,10 @@ "en": "Highlight if", "fr": "Surligner si" }, + "description": { + "en": "all the tracks selected by this condition will be colored in blue.", + "fr": "toutes les courses sélectionné par cette condition seront coloré en bleu." + }, "type": "string", "default": "'v' + track.since_version == mod_config.version", "preview": "track_selecting" @@ -47,6 +55,10 @@ "en": "Balancing *", "fr": "Équilibrage *" }, + "description": { + "en": "Should the mod balancing (fake item box, blooper) be enabled ?", + "fr": "Est-ce que l'équilibrage du mod (fausse boite d'objet, bloops) devrait être activé ?" + }, "type": "check", "default": true } diff --git a/source/gui/mod_settings.py b/source/gui/mod_settings.py index 7fef9c7..97ff18d 100644 --- a/source/gui/mod_settings.py +++ b/source/gui/mod_settings.py @@ -35,6 +35,15 @@ class Window(tkinter.Toplevel): self.mod_config.specific_settings ) + # add at the end a message from the mod creator where he can put some additional note about the settings. + if text := translate_external( + self.mod_config, + self.root.options.language.get(), + self.mod_config.messages.get("settings_description", {}).get("text", {}) + ): + self.label_description = ttk.Label(self, text="\n" + text, foreground="gray") + self.label_description.grid(row=2, column=1) + class NotebookSettings(ttk.Notebook): def __init__(self, master): @@ -55,37 +64,29 @@ class FrameSettings(ttk.Frame): self.root = self.master.root self.columnconfigure(1, weight=1) - - def get_event_checkbox(enabled_variable: tkinter.BooleanVar): - """ - Return the event for any child of a frmae when clicked - """ - return lambda event: enabled_variable.set(True) + language = self.root.options.language.get() index: int = 0 for index, (settings_name, settings_data) in enumerate(settings.items()): - text = translate_external( - self.master.master.mod_config, - self.root.options.language.get(), - settings_data.text, - ) + text = translate_external(self.master.master.mod_config, language, settings_data.text) + description = translate_external(self.master.master.mod_config, language, settings_data.description) enabled_variable = tkinter.BooleanVar(value=False) checkbox = ttk.Checkbutton(self, text=text, variable=enabled_variable) + frame = ttk.LabelFrame(self, labelwidget=checkbox) frame.grid(row=index, column=1, sticky="NEWS") + frame.columnconfigure(1, weight=1) - settings_data.tkinter_show(frame, enabled_variable) + action_frame = ttk.Frame(frame) + action_frame.grid(row=1, column=1, sticky="NEWS") + settings_data.tkinter_show(action_frame, enabled_variable) + + if description: + description_label = ttk.Label(frame, text=description, wraplength=450, + foreground="gray", justify=tkinter.CENTER) + description_label.grid(row=2, column=1) # if any of the label child are clicked, automatically enable the option for child in frame.winfo_children(): - child.bind("", get_event_checkbox(enabled_variable)) - - # add at the end a message from the mod creator where he can put some additional note about the settings. - if text := translate_external( - self.master.master.mod_config, - self.root.options.language.get(), - self.master.master.mod_config.messages.get("settings_description", {}).get("text", {}) - ): - self.label_description = ttk.Label(self, text="\n"+text, foreground="gray") - self.label_description.grid(row=index+1, column=1) + child.bind("", (lambda variable: (lambda event: variable.set(True)))(enabled_variable)) diff --git a/source/mkw/ModConfig.py b/source/mkw/ModConfig.py index 205baaf..39f2a6e 100644 --- a/source/mkw/ModConfig.py +++ b/source/mkw/ModConfig.py @@ -30,6 +30,11 @@ default_global_settings: dict[str, dict[str, str]] = { "en": "Replace random new tracks by", "fr": "Remplacer les courses aléatoires nouvelle par" }, + "description": { + "en": "The \"Random: New track\" option in the game will select any track respecting this condition.", + "fr": "L'option \"Aléatoire: Nouvelle course\" dans le jeu va sélectionner n'importe quel course qui " + "respecte cette condition." + }, "type": "string", "preview": "track_selecting" }, @@ -38,6 +43,10 @@ default_global_settings: dict[str, dict[str, str]] = { "en": "Include track if", "fr": "Inclure la course si" }, + "description": { + "en": "Only the tracks respecting the condition will be in the patched game.", + "fr": "Seulement les courses respectant la condition seront présente dans le jeu patché." + }, "type": "string", "preview": "track_selecting" }, @@ -46,6 +55,10 @@ default_global_settings: dict[str, dict[str, str]] = { "en": "Sort tracks by", "fr": "Trier les courses par" }, + "description": { + "en": "Define how the tracks should be sorted in the mod.", + "fr": "Défini comment les courses devrait être trié dans le mod." + }, "type": "string", "preview": "track_sorting" } diff --git a/source/mkw/ModSettings/Check.py b/source/mkw/ModSettings/Check.py index e91d19c..44881d0 100644 --- a/source/mkw/ModSettings/Check.py +++ b/source/mkw/ModSettings/Check.py @@ -14,14 +14,15 @@ class Choices(AbstractModSettings): type = "check" def __init__(self, enabled: bool = False, - default: bool | None = None, text: dict[str] = None): + default: bool | None = None, text: dict[str, str] = None, description: dict[str, str] = None): self._value = default if default is not None else False self.default = default + self.description = description if description is not None else {} self.enabled = enabled self.text = text if text is not None else {} - def tkinter_show(self, master: ttk.LabelFrame, checkbox) -> None: + def tkinter_show(self, master, checkbox) -> None: super().tkinter_show(master, checkbox) value_variable = tkinter.BooleanVar(master, value=self._value) diff --git a/source/mkw/ModSettings/Choices.py b/source/mkw/ModSettings/Choices.py index 4177747..7af7d40 100644 --- a/source/mkw/ModSettings/Choices.py +++ b/source/mkw/ModSettings/Choices.py @@ -13,16 +13,18 @@ class Choices(AbstractModSettings): type = "choices" def __init__(self, choices: list[str], enabled: bool = False, - default: str | None = None, text: dict[str] = None): + default: str | None = None, text: dict[str, str] = None, description: dict[str, str] = None): self._value = default if default is not None else choices[0] self.default = default self.enabled = enabled self.text = text if text is not None else {} + self.description = description if description is not None else {} self.choices = choices - def tkinter_show(self, master: ttk.LabelFrame, checkbox) -> None: + def tkinter_show(self, master, checkbox) -> None: super().tkinter_show(master, checkbox) + master.grid_rowconfigure(1, weight=1) master.grid_columnconfigure(1, weight=1) @@ -31,3 +33,4 @@ class Choices(AbstractModSettings): combobox = ttk.Combobox(master, values=self.choices, textvariable=value_variable) combobox.grid(row=1, column=1, sticky="EW") + diff --git a/source/mkw/ModSettings/String.py b/source/mkw/ModSettings/String.py index 64e576c..0cdd22e 100644 --- a/source/mkw/ModSettings/String.py +++ b/source/mkw/ModSettings/String.py @@ -14,16 +14,18 @@ class String(AbstractModSettings): type = "string" def __init__(self, preview: str = None, enabled: bool = False, - default: str | None = None, text: dict[str] = None): + default: str | None = None, text: dict[str, str] = None, description: dict[str, str] = None): self._value: str = default if default is not None else "" self.default = default self.enabled = enabled self.text = text if text is not None else {} + self.description = description if description is not None else {} self.preview: str | None = preview - def tkinter_show(self, master: ttk.LabelFrame, checkbox) -> None: + def tkinter_show(self, master, checkbox) -> None: super().tkinter_show(master, checkbox) + master.grid_rowconfigure(1, weight=1) master.grid_columnconfigure(1, weight=1) @@ -36,8 +38,9 @@ class String(AbstractModSettings): if self.preview is not None: button = ttk.Button( master, text="...", width=3, - command=lambda: AbstractPreviewWindow.get( - self.preview - )(master.master.master.master.mod_config, value_variable) + command=lambda: AbstractPreviewWindow.get(self.preview)( + master.master.master.master.mod_config, value_variable + ) ) button.grid(row=1, column=2, sticky="EW") +