From 2a0cd87246eb7da2a8ec9e419a2917d5fd6298ef Mon Sep 17 00:00:00 2001 From: TakaRikka Date: Wed, 5 Aug 2026 14:27:59 -0700 Subject: [PATCH] ui: start implementing menu tabs and controls --- mods/randomizer/src/ui/rando_config.cpp | 204 ++++++++++++++++++++++++ mods/randomizer/src/ui/rando_config.hpp | 2 + mods/randomizer/src/ui/ui.cpp | 64 +------- 3 files changed, 209 insertions(+), 61 deletions(-) diff --git a/mods/randomizer/src/ui/rando_config.cpp b/mods/randomizer/src/ui/rando_config.cpp index d817474d7c..d61c05accc 100644 --- a/mods/randomizer/src/ui/rando_config.cpp +++ b/mods/randomizer/src/ui/rando_config.cpp @@ -95,6 +95,210 @@ const std::vector>& GetStartingInventoryLayo return layoutOrder; } +namespace { +// Control Helpers +void add_button(UiElementHandle pane, const char* label, const char* help_rml, + UiPressedFn on_pressed, UiElementHandle* out_handle = nullptr) +{ + UiControlDesc desc = UI_CONTROL_DESC_INIT; + desc.kind = UI_CONTROL_BUTTON; + desc.label = label; + desc.help_rml = help_rml; + desc.on_pressed = on_pressed; + session::svc_mng.ui->pane_add_control(session::svc_mng.mod_ctx, pane, &desc, out_handle); +} + +void add_section(UiElementHandle pane, const char* label) { + session::svc_mng.ui->pane_add_section(session::svc_mng.mod_ctx, pane, label); +} + +void add_string_input(UiElementHandle pane, const char* label, const char* help_rml, + int32_t max_length, UiControlGetFn getFn, UiControlSetFn setFn, UiElementHandle* out_handle = nullptr) +{ + UiControlDesc desc = UI_CONTROL_DESC_INIT; + desc.kind = UI_CONTROL_STRING; + desc.label = label; + desc.help_rml = help_rml; + desc.binding = UI_BINDING_CALLBACKS; + desc.get = getFn; + desc.set = setFn; + desc.max_length = max_length; + session::svc_mng.ui->pane_add_control(session::svc_mng.mod_ctx, pane, &desc, out_handle); +} + +void add_select_setting(UiElementHandle pane, const char* key, const char* help_rml, + UiControlGetFn getFn, UiControlSetFn setFn, UiElementHandle* out_handle = nullptr) +{ + auto setting = FindSetting(key); + auto info = setting->GetInfo(); + + std::vector optionsList; + for (size_t i = 0; i < info->GetOptions().size(); ++i) { + optionsList.push_back(info->GetOptions()[i].c_str()); + } + + UiControlDesc desc = UI_CONTROL_DESC_INIT; + desc.kind = UI_CONTROL_SELECT; + desc.label = key; + desc.help_rml = help_rml; + desc.binding = UI_BINDING_CALLBACKS; + desc.get = getFn; + desc.set = setFn; + desc.options = optionsList.data(); + desc.option_count = optionsList.size(); + session::svc_mng.ui->pane_add_control(session::svc_mng.mod_ctx, pane, &desc, out_handle); +} + +// Seed Management Tab +ModResult buildSeedManagementTab(ModContext* ctx, UiWindowHandle, UiElementHandle leftPane, + UiElementHandle rightPane, void*, ModError*) +{ + add_button(leftPane, + "Generate Seed", + "Generate a Randomizer seed using the current configuration options, and the supplied seed string.", + [](ModContext*, void*) {}); + + add_string_input(leftPane, + "Seed String", + "Current value of the seed used by the randomizer for generation. Leave blank for a random value.", + 32, + [](ModContext*, void*, UiControlValue*) {}, + [](ModContext*, void*, const UiControlValue*) {}); + + add_button(leftPane, + "Delete Seeds", + " ", + [](ModContext*, void*) {}); + + add_section(leftPane, "Permalink"); + + add_button(leftPane, + "Copy Permalink", + "Copy your current settings permalink to share with others.", + [](ModContext*, void*) {}); + + add_button(leftPane, + "Paste Permalink", + "Paste in a permalink from your clipboard. This will overwrite your current settings.", + [](ModContext*, void*) {}); + + add_section(leftPane, "Presets"); + + add_button(leftPane, + "Save Current Settings as Preset", + "Save the current settings to your list of presets.", + [](ModContext*, void*) {}); + + add_button(leftPane, + "Load Preset", + "Choose an existing preset to load from.", + [](ModContext*, void*) {}); + + return MOD_OK; +} + +ModResult updateSeedManagementTab(ModContext* ctx, void*, ModError*) { + return MOD_OK; +} + +// Seed Options Tab +ModResult buildSeedOptionsTab(ModContext* ctx, UiWindowHandle, UiElementHandle leftPane, + UiElementHandle rightPane, void*, ModError*) +{ + add_button(leftPane, + "Reset Settings to Default", + "Reset all settings to their default values. This will also clear starting items and excluded locations.", + [](ModContext*, void*) {}); + + add_section(leftPane, "Logic Settings"); + + add_select_setting(leftPane, + "Logic Rules", + " ", + [](ModContext*, void*, UiControlValue*) {}, + [](ModContext*, void*, const UiControlValue*) {}); + + add_section(leftPane, "Access Options"); + + add_section(leftPane, "Shuffles"); + + add_section(leftPane, "Dungeon Items"); + + add_section(leftPane, "Timesavers"); + + add_section(leftPane, "Additional Settings"); + + add_section(leftPane, "Dungeon Entrance Settings"); + + add_section(leftPane, "Tricks"); + + return MOD_OK; +} + +// Hints Tab +ModResult buildHintsTab(ModContext* ctx, UiWindowHandle, UiElementHandle leftPane, + UiElementHandle rightPane, void*, ModError*) +{ + return MOD_OK; +} + +// Starting Inventory Tab +ModResult buildStartingInventoryTab(ModContext* ctx, UiWindowHandle, UiElementHandle leftPane, + UiElementHandle rightPane, void*, ModError*) +{ + return MOD_OK; +} + +// Excluded Locations Tab +ModResult buildExcludedLocationsTab(ModContext* ctx, UiWindowHandle, UiElementHandle leftPane, + UiElementHandle rightPane, void*, ModError*) +{ + return MOD_OK; +} + +// Menu Tab +void OnMenuTabSelected(ModContext* ctx, void*) { + UiTabDesc tabs[5]{}; + + tabs[0].struct_size = sizeof(UiTabDesc); + tabs[0].title = "Seed Management"; + tabs[0].build = buildSeedManagementTab; + tabs[0].update = updateSeedManagementTab; + + tabs[1].struct_size = sizeof(UiTabDesc); + tabs[1].title = "Seed Options"; + tabs[1].build = buildSeedOptionsTab; + + tabs[2].struct_size = sizeof(UiTabDesc); + tabs[2].title = "Hints"; + tabs[2].build = buildHintsTab; + + tabs[3].struct_size = sizeof(UiTabDesc); + tabs[3].title = "Starting Inventory"; + tabs[3].build = buildStartingInventoryTab; + + tabs[4].struct_size = sizeof(UiTabDesc); + tabs[4].title = "Excluded Locations"; + tabs[4].build = buildExcludedLocationsTab; + + UiWindowDesc desc = UI_WINDOW_DESC_INIT; + desc.tabs = tabs; + desc.tab_count = 5; + UiWindowHandle window{}; + session::svc_mng.ui->window_push(ctx, &desc, &window); +} +} + +UiMenuTabHandle g_menu_tab{}; + +ModResult buildMenuTab() { + UiMenuTabDesc desc = UI_MENU_TAB_DESC_INIT; + desc.label = "Randomizer"; + desc.on_selected = OnMenuTabSelected; + + return session::svc_mng.ui->register_menu_tab(session::svc_mng.mod_ctx, &desc, &g_menu_tab); +} + std::filesystem::path GetRandomizerPath() { return paths::GetRandomizerPath() / "randomizer"; } diff --git a/mods/randomizer/src/ui/rando_config.hpp b/mods/randomizer/src/ui/rando_config.hpp index 1c5457e0c9..329428531c 100644 --- a/mods/randomizer/src/ui/rando_config.hpp +++ b/mods/randomizer/src/ui/rando_config.hpp @@ -17,6 +17,8 @@ void ApplyExistingRandomizerPreset(const std::filesystem::path& presetFilePath); void CopyPermalinkToClipboard(); void PastePermalinkFromClipboard(); +ModResult buildMenuTab(); + std::filesystem::path GetRandomizerPath(); std::filesystem::path GetRandomizerSettingsPath(); std::filesystem::path GetRandomizerPreferencesPath(); diff --git a/mods/randomizer/src/ui/ui.cpp b/mods/randomizer/src/ui/ui.cpp index 2914b2b2af..0f8bfd6bd4 100644 --- a/mods/randomizer/src/ui/ui.cpp +++ b/mods/randomizer/src/ui/ui.cpp @@ -1,73 +1,15 @@ #include "ui.hpp" -#include -#include -#include -#include -#include -#include -#include - #include -#include "../session.hpp" -#include "../randomizer_context.hpp" -#include "../paths.hpp" - -#include "config_store.hpp" #include "rando_seed_generation.hpp" +#include "rando_config.hpp" namespace randomizer::ui { -namespace { -// Seed Tab -ModResult buildSeedTab(ModContext* ctx, UiWindowHandle, UiElementHandle leftPane, - UiElementHandle rightPane, void*, ModError*) -{ - return MOD_OK; -} - -ModResult updateSeedTab(ModContext* ctx, void*, ModError*) { - return MOD_OK; -} - -// Settings Tab -ModResult buildSettingsTab(ModContext* ctx, UiWindowHandle, UiElementHandle leftPane, - UiElementHandle rightPane, void*, ModError*) -{ - return MOD_OK; -} - -// Menu Tab -void OnMenuTabSelected(ModContext* ctx, void*) { - UiTabDesc tabs[2]{}; - - tabs[0].struct_size = sizeof(UiTabDesc); - tabs[0].title = "Seed"; - tabs[0].build = buildSeedTab; - tabs[0].update = updateSeedTab; - - tabs[1].struct_size = sizeof(UiTabDesc); - tabs[1].title = "Settings"; - tabs[1].build = buildSettingsTab; - - UiWindowDesc desc = UI_WINDOW_DESC_INIT; - desc.tabs = tabs; - desc.tab_count = 2; - UiWindowHandle window{}; - session::svc_mng.ui->window_push(ctx, &desc, &window); -} -} - -UiMenuTabHandle g_menu_tab{}; - ModResult initialize() { - UiMenuTabDesc desc = UI_MENU_TAB_DESC_INIT; - desc.label = "Randomizer"; - desc.on_selected = OnMenuTabSelected; - - ModResult res = - session::svc_mng.ui->register_menu_tab(session::svc_mng.mod_ctx, &desc, &g_menu_tab); + ModResult res = buildMenuTab(); if (res != MOD_OK) { + mods::log::error("failed to initialize randomizer menu tab!"); return res; }