|
10 | 10 |
|
11 | 11 | from mods_base import Mod, NestedOption, hook, html_to_plain_text |
12 | 12 |
|
| 13 | +from .lobby import open_lobby_mods_menu |
13 | 14 | from .util import find_focused_item |
14 | 15 |
|
15 | 16 | if TYPE_CHECKING: |
16 | 17 | from .populators import Populator |
17 | 18 | from .util import WillowGFxMenu |
18 | 19 |
|
19 | 20 | CUSTOM_OPTIONS_MENU_TAG = "willow1-mod-menu:custom-option" |
20 | | -RE_SELECTED_IDX = re.compile(r"^_level\d+\.menu\.selections\.mMenu\.mList\.item(\d+)$") |
| 21 | +RE_SELECTED_IDX = re.compile(r"^_level\d+\.(menu\.selections|content)\.mMenu\.mList\.item(\d+)$") |
21 | 22 |
|
22 | 23 | populator_stack: list[Populator] = [] |
23 | 24 |
|
24 | 25 |
|
| 26 | +def create_mod_list_options_menu(menu: WillowGFxMenu) -> None: |
| 27 | + """ |
| 28 | + Creates a new menu holding the full mods list. |
| 29 | +
|
| 30 | + Args: |
| 31 | + menu: The current menu to create the new one under. |
| 32 | + """ |
| 33 | + populator_stack.append(ModListPopulator("Mods")) |
| 34 | + open_new_generic_menu(menu) |
| 35 | + |
| 36 | + |
25 | 37 | def create_mod_options_menu(menu: WillowGFxMenu, mod: Mod) -> None: |
26 | | - populator_stack.append(OptionPopulator(mod.name, mod.options)) |
| 38 | + """ |
| 39 | + Creates a new menu holding a single mod's options. |
| 40 | +
|
| 41 | + Args: |
| 42 | + menu: The current menu to create the new one under. |
| 43 | + mod: The mod to create the options menu for. |
| 44 | + """ |
| 45 | + populator_stack.append(ModOptionPopulator(mod.name, mod.options, mod)) |
27 | 46 | open_new_generic_menu(menu) |
28 | 47 |
|
29 | 48 |
|
30 | 49 | def create_nested_options_menu(menu: WillowGFxMenu, option: NestedOption) -> None: |
| 50 | + """ |
| 51 | + Creates a new menu holding a nested option's children. |
| 52 | +
|
| 53 | + Args: |
| 54 | + menu: The current menu to create the new one under. |
| 55 | + option: The options whose children to create a menu for. |
| 56 | + """ |
31 | 57 | populator_stack.append(OptionPopulator(option.display_name, option.children)) |
32 | 58 | open_new_generic_menu(menu) |
33 | 59 |
|
34 | 60 |
|
| 61 | +# ================================================================================================== |
| 62 | + |
35 | 63 | # Avoid circular imports |
| 64 | +from .populators.mod_list import ModListPopulator # noqa: E402 |
| 65 | +from .populators.mod_options import ModOptionPopulator # noqa: E402 |
36 | 66 | from .populators.options import OptionPopulator # noqa: E402 |
37 | 67 |
|
38 | | -# ================================================================================================== |
39 | | - |
40 | 68 |
|
41 | 69 | def open_new_generic_menu(menu: WillowGFxMenu) -> None: |
42 | 70 | if len(populator_stack) == 1: |
@@ -82,7 +110,7 @@ def get_selected_idx(menu: WillowGFxMenu) -> int | None: |
82 | 110 | return None |
83 | 111 |
|
84 | 112 | try: |
85 | | - return int(match.group(1)) |
| 113 | + return int(match.group(2)) |
86 | 114 | except ValueError: |
87 | 115 | return None |
88 | 116 |
|
@@ -145,15 +173,19 @@ def generic_screen_deactivate( |
145 | 173 | _ret: Any, |
146 | 174 | _func: BoundFunction, |
147 | 175 | ) -> None: |
148 | | - if obj.MenuTag == CUSTOM_OPTIONS_MENU_TAG: |
149 | | - populator_stack.pop() |
150 | | - # TODO: save mod settings |
| 176 | + if obj.MenuTag == CUSTOM_OPTIONS_MENU_TAG and populator_stack: |
| 177 | + last_populator = populator_stack.pop() |
| 178 | + if isinstance(last_populator, ModOptionPopulator): |
| 179 | + last_populator.mod.save_settings() |
151 | 180 |
|
152 | 181 | if not populator_stack: |
153 | 182 | custom_menu_activate.disable() |
154 | 183 | custom_menu_spinner_change.disable() |
155 | 184 | custom_menu_slider_change.disable() |
156 | 185 |
|
| 186 | + if (owner := obj.MenuOwner).Class.Name == "WillowGFxMenuFrontend": |
| 187 | + open_lobby_mods_menu(owner) |
| 188 | + |
157 | 189 |
|
158 | 190 | # ================================================================================================== |
159 | 191 | # experimental |
|
0 commit comments