diff options
| author | louist103 <35883445+louist103@users.noreply.github.com> | 2025-06-28 03:50:36 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-27 21:50:36 -0600 |
| commit | eb7d1f00a810d4c1e2e4323e4fd628ad01739fb5 (patch) | |
| tree | a55666e843403fc6d1200dd39b46abf2723a9398 /mm/2s2h | |
| parent | 620859447c6bddcdf1dded50a7a4110f825536bf (diff) | |
Add vector support to comboboxes (#1159)
* Add vector support to comboboxes
* Move vectors out of header
* Format
* Use variant
---------
Co-authored-by: balloondude2 <55861555+balloondude2@users.noreply.github.com>
Diffstat (limited to 'mm/2s2h')
| -rw-r--r-- | mm/2s2h/BenGui/BenMenu.cpp | 143 | ||||
| -rw-r--r-- | mm/2s2h/BenGui/BenMenu.h | 105 | ||||
| -rw-r--r-- | mm/2s2h/BenGui/Menu.cpp | 32 | ||||
| -rw-r--r-- | mm/2s2h/BenGui/ResolutionEditor.cpp | 2 | ||||
| -rw-r--r-- | mm/2s2h/BenGui/UIWidgets.hpp | 51 | ||||
| -rw-r--r-- | mm/2s2h/DeveloperTools/SaveEditor.cpp | 4 | ||||
| -rw-r--r-- | mm/2s2h/Enhancements/Trackers/DisplayOverlay.cpp | 4 | ||||
| -rw-r--r-- | mm/2s2h/Enhancements/Trackers/ItemTracker.cpp | 10 | ||||
| -rw-r--r-- | mm/2s2h/Rando/Menu.cpp | 6 |
9 files changed, 192 insertions, 165 deletions
diff --git a/mm/2s2h/BenGui/BenMenu.cpp b/mm/2s2h/BenGui/BenMenu.cpp index d433efcec..9899dd3b2 100644 --- a/mm/2s2h/BenGui/BenMenu.cpp +++ b/mm/2s2h/BenGui/BenMenu.cpp @@ -28,6 +28,114 @@ extern SaveContext gSaveContext; extern std::unordered_map<s16, const char*> warpPointSceneList; extern void Warp(); +static const std::unordered_map<int32_t, const char*> menuThemeOptions = { + { UIWidgets::Colors::Red, "Red" }, + { UIWidgets::Colors::DarkRed, "Dark Red" }, + { UIWidgets::Colors::Orange, "Orange" }, + { UIWidgets::Colors::Green, "Green" }, + { UIWidgets::Colors::DarkGreen, "Dark Green" }, + { UIWidgets::Colors::LightBlue, "Light Blue" }, + { UIWidgets::Colors::Blue, "Blue" }, + { UIWidgets::Colors::DarkBlue, "Dark Blue" }, + { UIWidgets::Colors::Indigo, "Indigo" }, + { UIWidgets::Colors::Violet, "Violet" }, + { UIWidgets::Colors::Purple, "Purple" }, + { UIWidgets::Colors::Brown, "Brown" }, + { UIWidgets::Colors::Gray, "Gray" }, + { UIWidgets::Colors::DarkGray, "Dark Gray" }, +}; + +static const std::vector<const char*> alwaysWinDoggyraceOptions = { + "Off", // ALWAYS_WIN_DOGGY_RACE_OFF + "When owning Mask of Truth", // ALWAYS_WIN_DOGGY_RACE_MASKOFTRUTH + "Always", // ALWAYS_WIN_DOGGY_RACE_ALWAYS +}; + +static const std::vector<const char*> cremiaRewardOptions = { + "Vanilla", // CREMIA_REWARD_RANDOM + "Hug", // CREMIA_REWARD_ALWAYS_HUG + "Rupee", // CREMIA_REWARD_ALWAYS_RUPEE +}; + +static const std::vector<const char*> gibdoTradeSequenceOptions = { + "Vanilla", // GIBDO_TRADE_SEQUENCE_VANILLA + "MM3D", // GIBDO_TRADE_SEQUENCE_MM3D + "No trade", // GIBDO_TRADE_SEQUENCE_NO_TRADE +}; + +static const std::vector<const char*> clockTypeOptions = { + "Original", // CLOCK_TYPE_ORIGINAL + "MM3D style", // CLOCK_TYPE_3DS + "Text only", // CLOCK_TYPE_TEXT_BASED +}; + +static const std::vector<const char*> textureFilteringOptions = { + "Three-Point", // Fast::FILTER_THREE_POINT, + "Linear", // Fast::FILTER_LINEAR + "None", // Fast::FILTER_NONE +}; + +static const std::vector<const char*> motionBlurOptions = { + "Dynamic (default)", // MOTION_BLUR_DYNAMIC + "Always Off", // MOTION_BLUR_ALWAYS_OFF + "Always On", // MOTION_BLUR_ALWAYS_ON +}; +static const std::vector<const char*> debugSaveOptions = { + "100% save", // DEBUG_SAVE_INFO_COMPLETE + "Vanilla debug save", // DEBUG_SAVE_INFO_VANILLA_DEBUG + "Empty save", // DEBUG_SAVE_INFO_NONE +}; + +static const std::vector<const char*> logLevels = { + "Trace", // DEBUG_LOG_TRACE + "Debug", // DEBUG_LOG_DEBUG + "Info", // DEBUG_LOG_INFO + "Warn", // DEBUG_LOG_WARN + "Error", // DEBUG_LOG_ERROR + "Critical", // DEBUG_LOG_CRITICAL + "Off", // DEBUG_LOG_OFF +}; + +static const std::vector<const char*> timeStopOptions = { + "Off", // TIME_STOP_OFF + "Temples", // TIME_STOP_TEMPLES + "Temples + Mini Dungeons", // TIME_STOP_TEMPLES_DUNGEONS +}; + +static const std::vector<const char*> notificationPosition = { + "Top Left", "Top Right", "Bottom Left", "Bottom Right", "Hidden", +}; + +static const std::vector<const char*> dekuGuardSearchBallsOptions = { + "Never", // DEKU_GUARD_SEARCH_BALLS_NEVER + "Night Only", // DEKU_GUARD_SEARCH_BALLS_NIGHT_ONLY + "Always", // DEKU_GUARD_SEARCH_BALLS_ALWAYS +}; + +static const std::vector<const char*> skipGetItemCutscenesOptions = { + "Never", + "Junk Items Only", + "Everything But Major", + "Always", +}; + +static const std::vector<const char*> powerCrouchStabOptions = { + "Patched (US/EU)", + "Unpatched (JP)", + "Unpatched (OoT)", +}; + +static const std::vector<const char*> maskOfTruthGrottoOptions = { + "Off", // HIDDEN_GROTTOS_VISIBLITY_OFF + "Wear Mask of Truth", // HIDDEN_GROTTOS_VISIBLITY_WEAR_MASK_OF_TRUTH + "Have Mask of Truth", // HIDDEN_GROTTOS_VISIBLITY_HAVE_MASK_OF_TRUTH + "Always", // HIDDEN_GROTTOS_VISIBLITY_ALWAYS +}; + +static const std::unordered_map<int32_t, const char*> damageMultiplierOptions = { + { 0, "1x" }, { 1, "2x" }, { 2, "4x" }, { 3, "8x" }, { 4, "16x" }, { 10, "1 Hit KO" }, +}; + namespace BenGui { extern std::shared_ptr<BenMenu> mBenMenu; void FreeLookPitchMinMax() { @@ -165,7 +273,7 @@ void BenMenu::AddSettings() { .CVar("gSettings.Menu.Theme") .Options(ComboboxOptions() .Tooltip("Changes the Theme of the Menu Widgets.") - .ComboMap(menuThemeOptions) + .ComboMap(&menuThemeOptions) .DefaultIndex(Colors::LightBlue)); #if not defined(__SWITCH__) and not defined(__WIIU__) AddWidget(path, "Menu Controller Navigation", WIDGET_CVAR_CHECKBOX) @@ -384,7 +492,7 @@ void BenMenu::AddSettings() { "Allows multiple windows to be opened at once. Requires a reload to take effect.")); AddWidget(path, "Texture Filter (Needs reload)", WIDGET_CVAR_COMBOBOX) .CVar(CVAR_TEXTURE_FILTER) - .Options(ComboboxOptions().Tooltip("Sets the applied Texture Filtering.").ComboMap(textureFilteringMap)); + .Options(ComboboxOptions().Tooltip("Sets the applied Texture Filtering.").ComboVec(&textureFilteringOptions)); path.sidebarName = "Controls"; AddSidebarEntry("Settings", "Controls", 1); @@ -400,7 +508,7 @@ void BenMenu::AddSettings() { .CVar("gNotifications.Position") .Options(ComboboxOptions() .Tooltip("Which corner of the screen notifications appear in.") - .ComboMap(notificationPosition) + .ComboVec(¬ificationPosition) .DefaultIndex(3)); AddWidget(path, "Duration: %.0f seconds", WIDGET_CVAR_SLIDER_FLOAT) .CVar("gNotifications.Duration") @@ -730,7 +838,7 @@ void BenMenu::AddEnhancements() { "- Temples: Stops time in Woodfall, Snowhead, Great Bay, and Stone Tower Temples.\n" "- Temples + Mini Dungeons: In addition to the above temples, stops time in both Spider " "Houses, Pirate's Fortress, Beneath the Well, Ancient Castle of Ikana, and Secret Shrine.") - .ComboMap(timeStopOptions)); + .ComboVec(&timeStopOptions)); //// Gameplay Enhancements path = { "Enhancements", "Gameplay", SECTION_COLUMN_1 }; @@ -834,7 +942,7 @@ void BenMenu::AddEnhancements() { AddWidget(path, "Minigames", WIDGET_SEPARATOR_TEXT); AddWidget(path, "Always Win Doggy Race", WIDGET_CVAR_COMBOBOX) .CVar("gEnhancements.Minigames.AlwaysWinDoggyRace") - .Options(ComboboxOptions().Tooltip("Makes the Doggy Race easier to win.").ComboMap(alwaysWinDoggyraceOptions)); + .Options(ComboboxOptions().Tooltip("Makes the Doggy Race easier to win.").ComboVec(&alwaysWinDoggyraceOptions)); AddWidget(path, "Milk Run Reward Options", WIDGET_CVAR_COMBOBOX) .CVar("gEnhancements.Minigames.CremiaHugs") .Options(ComboboxOptions() @@ -842,7 +950,7 @@ void BenMenu::AddEnhancements() { "-Vanilla: Reward is Random\n" "-Hug: Get the hugging cutscene\n" "-Rupee: Get the rupee reward") - .ComboMap(cremiaRewardOptions)); + .ComboVec(&cremiaRewardOptions)); AddWidget(path, "Cucco Shack Cucco Count", WIDGET_CVAR_SLIDER_INT) .CVar("gEnhancements.Minigames.CuccoShackCuccoCount") .Options(IntSliderOptions() @@ -1008,8 +1116,9 @@ void BenMenu::AddEnhancements() { AddWidget(path, "Clock", WIDGET_SEPARATOR_TEXT); AddWidget(path, "Clock Type", WIDGET_CVAR_COMBOBOX) .CVar("gEnhancements.Graphics.ClockType") - .Options( - ComboboxOptions().Tooltip("Swaps between Graphical and Text only Clock types.").ComboMap(clockTypeOptions)); + .Options(ComboboxOptions() + .Tooltip("Swaps between Graphical and Text only Clock types.") + .ComboVec(&clockTypeOptions)); AddWidget(path, "24 Hours Clock", WIDGET_CVAR_CHECKBOX) .CVar("gEnhancements.Graphics.24HoursClock") .Options(CheckboxOptions().Tooltip("Changes from a 12 Hour to a 24 Hour Clock.")); @@ -1025,7 +1134,7 @@ void BenMenu::AddEnhancements() { .Options(ComboboxOptions() .Tooltip("Selects the Mode for Motion Blur.") .LabelPosition(LabelPosition::None) - .ComboMap(motionBlurOptions)); + .ComboVec(&motionBlurOptions)); AddWidget(path, "Interpolate", WIDGET_CVAR_CHECKBOX) .CVar("gEnhancements.Graphics.MotionBlur.Interpolate") .PreFunc([](WidgetInfo& info) { @@ -1216,7 +1325,7 @@ void BenMenu::AddEnhancements() { .CVar("gEnhancements.Cutscenes.SkipGetItemCutscenes") .Options(ComboboxOptions() .Tooltip("Note: This only works in Randomizer currently.") - .ComboMap(skipGetItemCutscenesOptions)); + .ComboVec(&skipGetItemCutscenesOptions)); // Dialogue Enhancements path.column = SECTION_COLUMN_2; @@ -1319,7 +1428,7 @@ void BenMenu::AddEnhancements() { " pots).\n" "- Unpatched (OoT): Glitch restored, and your initial damage is 1 (a Kokiri Sword slash).") .DefaultIndex(0) - .ComboMap(powerCrouchStabOptions)); + .ComboVec(&powerCrouchStabOptions)); AddWidget(path, "Side Rolls", WIDGET_CVAR_CHECKBOX) .CVar("gEnhancements.Restorations.SideRoll") .Options(CheckboxOptions().Tooltip("Restores side rolling from OoT.")); @@ -1367,7 +1476,7 @@ void BenMenu::AddEnhancements() { "- Night Only: Only show the search balls at night. This matches original N64 behaviour.\n" "- Always: Always show the search balls.") .DefaultIndex(DekuGuardSearchBallsOptions::DEKU_GUARD_SEARCH_BALLS_NIGHT_ONLY) - .ComboMap(dekuGuardSearchBallsOptions)); + .ComboVec(&dekuGuardSearchBallsOptions)); AddWidget(path, "Lower Bank Reward Thresholds", WIDGET_CVAR_CHECKBOX) .CVar("gEnhancements.DifficultyOptions.LowerBankRewardThresholds") .Options( @@ -1384,7 +1493,7 @@ void BenMenu::AddEnhancements() { " The Gibdo requesting a blue potion will also accept a red potion.\n" "- No trade: Gibdos will vanish without taking items.") .DefaultIndex(GibdoTradeSequenceOptions::GIBDO_TRADE_SEQUENCE_VANILLA) - .ComboMap(gibdoTradeSequenceOptions)); + .ComboVec(&gibdoTradeSequenceOptions)); AddWidget(path, "Hidden Grottos Visibility", WIDGET_CVAR_COMBOBOX) .CVar("gEnhancements.DifficultyOptions.HiddenGrottosVisibility") .Options( @@ -1396,7 +1505,7 @@ void BenMenu::AddEnhancements() { "- Have Mask of Truth: Hidden grottos are visible once the Mask of Truth is obtained.\n" "- Always: Hidden grottos always have a visual marker.\n") .DefaultIndex(HiddenGrottosVisibilityOptions::HIDDEN_GROTTOS_VISIBLITY_OFF) - .ComboMap(maskOfTruthGrottoOptions)); + .ComboVec(&maskOfTruthGrottoOptions)); path.column = SECTION_COLUMN_2; AddWidget(path, "Hyper Enemies", WIDGET_CVAR_CHECKBOX) @@ -1406,7 +1515,7 @@ void BenMenu::AddEnhancements() { .CVar("gEnhancements.DifficultyOptions.DamageMultiplier") .Options(ComboboxOptions() .Tooltip("Adjusts the amount of damage Link takes from all sources.") - .ComboMap(damageMultiplierOptions)); + .ComboMap(&damageMultiplierOptions)); AddWidget(path, "Permanent Heart Loss", WIDGET_CVAR_CHECKBOX) .CVar("gEnhancements.DifficultyOptions.PermanentHeartLoss") .Options(CheckboxOptions().Tooltip( @@ -1487,7 +1596,7 @@ void BenMenu::AddDevTools() { "- Empty Save: The default 3 heart save file in first cycle.\n" "- Vanilla Debug Save: Uses the title screen save info (8 hearts, all items and masks).\n" "- 100\% Save: All items, equipment, mask, quest status and Bombers' Notebook complete.") - .ComboMap(debugSaveOptions)) + .ComboVec(&debugSaveOptions)) .PreFunc([](WidgetInfo& info) { info.isHidden = mBenMenu->disabledMap.at(DISABLE_FOR_DEBUG_MODE_OFF).active; }); AddWidget(path, "Prevent Actor Update", WIDGET_CVAR_CHECKBOX) .CVar("gDeveloperTools.PreventActorUpdate") @@ -1510,7 +1619,7 @@ void BenMenu::AddDevTools() { .Options(ComboboxOptions() .Tooltip("The log level determines which messages are printed to the " "console. This does not affect the log file output.") - .ComboMap(logLevels)) + .ComboVec(&logLevels)) .Callback([](WidgetInfo& info) { Ship::Context::GetInstance()->GetLogger()->set_level( (spdlog::level::level_enum)CVarGetInteger("gDeveloperTools.LogLevel", 1)); diff --git a/mm/2s2h/BenGui/BenMenu.h b/mm/2s2h/BenGui/BenMenu.h index 3198ee109..592e14f0a 100644 --- a/mm/2s2h/BenGui/BenMenu.h +++ b/mm/2s2h/BenGui/BenMenu.h @@ -9,111 +9,6 @@ namespace BenGui { -static const std::unordered_map<int32_t, const char*> menuThemeOptions = { - { UIWidgets::Colors::Red, "Red" }, - { UIWidgets::Colors::DarkRed, "Dark Red" }, - { UIWidgets::Colors::Orange, "Orange" }, - { UIWidgets::Colors::Green, "Green" }, - { UIWidgets::Colors::DarkGreen, "Dark Green" }, - { UIWidgets::Colors::LightBlue, "Light Blue" }, - { UIWidgets::Colors::Blue, "Blue" }, - { UIWidgets::Colors::DarkBlue, "Dark Blue" }, - { UIWidgets::Colors::Indigo, "Indigo" }, - { UIWidgets::Colors::Violet, "Violet" }, - { UIWidgets::Colors::Purple, "Purple" }, - { UIWidgets::Colors::Brown, "Brown" }, - { UIWidgets::Colors::Gray, "Gray" }, - { UIWidgets::Colors::DarkGray, "Dark Gray" }, -}; - -static const std::unordered_map<int32_t, const char*> alwaysWinDoggyraceOptions = { - { ALWAYS_WIN_DOGGY_RACE_OFF, "Off" }, - { ALWAYS_WIN_DOGGY_RACE_MASKOFTRUTH, "When owning Mask of Truth" }, - { ALWAYS_WIN_DOGGY_RACE_ALWAYS, "Always" }, -}; - -static const std::unordered_map<int32_t, const char*> cremiaRewardOptions = { - { CREMIA_REWARD_RANDOM, "Vanilla" }, - { CREMIA_REWARD_ALWAYS_HUG, "Hug" }, - { CREMIA_REWARD_ALWAYS_RUPEE, "Rupee" }, -}; - -static const std::unordered_map<int32_t, const char*> gibdoTradeSequenceOptions = { - { GIBDO_TRADE_SEQUENCE_VANILLA, "Vanilla" }, - { GIBDO_TRADE_SEQUENCE_MM3D, "MM3D" }, - { GIBDO_TRADE_SEQUENCE_NO_TRADE, "No trade" }, -}; - -static const std::unordered_map<int32_t, const char*> clockTypeOptions = { - { CLOCK_TYPE_ORIGINAL, "Original" }, - { CLOCK_TYPE_3DS, "MM3D style" }, - { CLOCK_TYPE_TEXT_BASED, "Text only" }, -}; - -static const std::unordered_map<int32_t, const char*> textureFilteringMap = { - { Fast::FILTER_THREE_POINT, "Three-Point" }, - { Fast::FILTER_LINEAR, "Linear" }, - { Fast::FILTER_NONE, "None" }, -}; - -static const std::unordered_map<int32_t, const char*> motionBlurOptions = { - { MOTION_BLUR_DYNAMIC, "Dynamic (default)" }, - { MOTION_BLUR_ALWAYS_OFF, "Always Off" }, - { MOTION_BLUR_ALWAYS_ON, "Always On" }, -}; - -static const std::unordered_map<int32_t, const char*> debugSaveOptions = { - { DEBUG_SAVE_INFO_COMPLETE, "100\% save" }, - { DEBUG_SAVE_INFO_VANILLA_DEBUG, "Vanilla debug save" }, - { DEBUG_SAVE_INFO_NONE, "Empty save" }, -}; - -static const std::unordered_map<int32_t, const char*> logLevels = { - { DEBUG_LOG_TRACE, "Trace" }, { DEBUG_LOG_DEBUG, "Debug" }, { DEBUG_LOG_INFO, "Info" }, - { DEBUG_LOG_WARN, "Warn" }, { DEBUG_LOG_ERROR, "Error" }, { DEBUG_LOG_CRITICAL, "Critical" }, - { DEBUG_LOG_OFF, "Off" }, -}; - -static const std::unordered_map<int32_t, const char*> timeStopOptions = { - { TIME_STOP_OFF, "Off" }, - { TIME_STOP_TEMPLES, "Temples" }, - { TIME_STOP_TEMPLES_DUNGEONS, "Temples + Mini Dungeons" }, -}; - -static const std::unordered_map<int32_t, const char*> notificationPosition = { - { 0, "Top Left" }, { 1, "Top Right" }, { 2, "Bottom Left" }, { 3, "Bottom Right" }, { 4, "Hidden" }, -}; - -static const std::unordered_map<int32_t, const char*> dekuGuardSearchBallsOptions = { - { DEKU_GUARD_SEARCH_BALLS_NEVER, "Never" }, - { DEKU_GUARD_SEARCH_BALLS_NIGHT_ONLY, "Night Only" }, - { DEKU_GUARD_SEARCH_BALLS_ALWAYS, "Always" }, -}; - -static const std::unordered_map<int32_t, const char*> skipGetItemCutscenesOptions = { - { 0, "Never" }, - { 1, "Junk Items Only" }, - { 2, "Everything But Major" }, - { 3, "Always" }, -}; - -static const std::unordered_map<int32_t, const char*> powerCrouchStabOptions = { - { 0, "Patched (US/EU)" }, - { 1, "Unpatched (JP)" }, - { 2, "Unpatched (OoT)" }, -}; - -static const std::unordered_map<int32_t, const char*> maskOfTruthGrottoOptions = { - { HIDDEN_GROTTOS_VISIBLITY_OFF, "Off" }, - { HIDDEN_GROTTOS_VISIBLITY_WEAR_MASK_OF_TRUTH, "Wear Mask of Truth" }, - { HIDDEN_GROTTOS_VISIBLITY_HAVE_MASK_OF_TRUTH, "Have Mask of Truth" }, - { HIDDEN_GROTTOS_VISIBLITY_ALWAYS, "Always" }, -}; - -static const std::unordered_map<int32_t, const char*> damageMultiplierOptions = { - { 0, "1x" }, { 1, "2x" }, { 2, "4x" }, { 3, "8x" }, { 4, "16x" }, { 10, "1 Hit KO" }, -}; - class BenMenu : public Ship::Menu { public: BenMenu(const std::string& consoleVariable, const std::string& name); diff --git a/mm/2s2h/BenGui/Menu.cpp b/mm/2s2h/BenGui/Menu.cpp index 59de4ebcf..aaa938030 100644 --- a/mm/2s2h/BenGui/Menu.cpp +++ b/mm/2s2h/BenGui/Menu.cpp @@ -179,7 +179,7 @@ uint32_t Menu::DrawSearchResults(std::string& menuSearchText) { auto& menuEntry = menuEntries.at(menuLabel); for (auto& sidebarLabel : menuEntry.sidebarOrder) { auto& sidebar = menuEntry.sidebars[sidebarLabel]; - for (int i = 0; i < sidebar.columnWidgets.size(); i++) { + for (size_t i = 0; i < sidebar.columnWidgets.size(); i++) { auto& column = sidebar.columnWidgets.at(i); for (auto& info : column) { if (info.type == WIDGET_SEARCH || info.type == WIDGET_SEPARATOR || @@ -187,7 +187,7 @@ uint32_t Menu::DrawSearchResults(std::string& menuSearchText) { continue; } const char* tooltip = info.options->tooltip; - std::string widgetStr = std::string(info.name) + std::string(tooltip != NULL ? tooltip : ""); + std::string widgetStr = std::string(info.name) + std::string(tooltip != nullptr ? tooltip : ""); std::transform(menuSearchText.begin(), menuSearchText.end(), menuSearchText.begin(), ::tolower); menuSearchText.erase(std::remove(menuSearchText.begin(), menuSearchText.end(), ' '), menuSearchText.end()); @@ -276,7 +276,7 @@ void Menu::MenuDrawItem(WidgetInfo& widget, uint32_t width, UIWidgets::Colors me options.tooltip = "Sets the audio API used by the game. Requires a relaunch to take effect."; options.disabled = Ship::Context::GetInstance()->GetAudio()->GetAvailableAudioBackends()->size() <= 1; options.disabledTooltip = "Only one audio API is available on this platform."; - if (UIWidgets::Combobox("Audio API", ¤tAudioBackend, audioBackendsMap, options)) { + if (UIWidgets::Combobox("Audio API", ¤tAudioBackend, &audioBackendsMap, options)) { Ship::Context::GetInstance()->GetAudio()->SetCurrentAudioBackend(currentAudioBackend); } } break; @@ -286,8 +286,8 @@ void Menu::MenuDrawItem(WidgetInfo& widget, uint32_t width, UIWidgets::Colors me options.tooltip = "Sets the renderer API used by the game."; options.disabled = availableWindowBackends->size() <= 1; options.disabledTooltip = "Only one renderer API is available on this platform."; - if (UIWidgets::Combobox("Renderer API (Needs reload)", &configWindowBackend, availableWindowBackendsMap, - options)) { + if (UIWidgets::Combobox("Renderer API (Needs reload)", &configWindowBackend, + &availableWindowBackendsMap, options)) { Ship::Context::GetInstance()->GetConfig()->SetInt("Window.Backend.Id", (int32_t)(configWindowBackend)); Ship::Context::GetInstance()->GetConfig()->SetString("Window.Backend.Name", @@ -327,7 +327,15 @@ void Menu::MenuDrawItem(WidgetInfo& widget, uint32_t width, UIWidgets::Colors me } auto options = std::static_pointer_cast<UIWidgets::ComboboxOptions>(widget.options); options->color = menuThemeIndex; - if (UIWidgets::Combobox(widget.name.c_str(), pointer, options->comboMap, *options)) { + bool result = false; + if (std::holds_alternative<UIWidgets::ComboVec_t>(options->comboVariant)) { + result = UIWidgets::Combobox(widget.name.c_str(), pointer, + *std::get<UIWidgets::ComboVec_t>(options->comboVariant), *options); + } else if (std::holds_alternative<UIWidgets::ComboMap_t>(options->comboVariant)) { + result = UIWidgets::Combobox(widget.name.c_str(), pointer, + std::get<UIWidgets::ComboMap_t>(options->comboVariant), *options); + } + if (result) { if (widget.callback != nullptr) { widget.callback(widget); } @@ -336,7 +344,15 @@ void Menu::MenuDrawItem(WidgetInfo& widget, uint32_t width, UIWidgets::Colors me case WIDGET_CVAR_COMBOBOX: { auto options = std::static_pointer_cast<UIWidgets::ComboboxOptions>(widget.options); options->color = menuThemeIndex; - if (UIWidgets::CVarCombobox(widget.name.c_str(), widget.cVar, options->comboMap, *options)) { + bool result = false; + if (std::holds_alternative<UIWidgets::ComboVec_t>(options->comboVariant)) { + result = UIWidgets::CVarCombobox(widget.name.c_str(), widget.cVar, + *std::get<UIWidgets::ComboVec_t>(options->comboVariant), *options); + } else if (std::holds_alternative<UIWidgets::ComboMap_t>(options->comboVariant)) { + result = UIWidgets::CVarCombobox(widget.name.c_str(), widget.cVar, + std::get<UIWidgets::ComboMap_t>(options->comboVariant), *options); + } + if (result) { if (widget.callback != nullptr) { widget.callback(widget); } @@ -769,7 +785,7 @@ void Menu::DrawElement() { } } } - for (int i = 0; i < columnFuncs; i++) { + for (size_t i = 0; i < columnFuncs; i++) { std::string sectionId = fmt::format("{} Column {}", sectionMenuId, i); if (useColumns) { ImGui::SetNextWindowSizeConstraints({ columnWidth, 0 }, { columnWidth, columnHeight }); diff --git a/mm/2s2h/BenGui/ResolutionEditor.cpp b/mm/2s2h/BenGui/ResolutionEditor.cpp index 854ebe46b..1450e6bbf 100644 --- a/mm/2s2h/BenGui/ResolutionEditor.cpp +++ b/mm/2s2h/BenGui/ResolutionEditor.cpp @@ -167,7 +167,7 @@ void RegisterResolutionWidgets() { CVarSetInteger(CVAR_PREFIX_ADVANCED_RESOLUTION ".UIComboItem.AspectRatio", item_aspectRatio); CVarSave(); }) - .Options(ComboboxOptions().ComboMap(aspectRatioPresetLabels)); + .Options(ComboboxOptions().ComboMap(&aspectRatioPresetLabels)); mBenMenu->AddWidget(path, "AspectRationCustom", WIDGET_CUSTOM).CustomFunction([](WidgetInfo& info) { auto gfx_current_dimensions = GetInterpreter().get()->mCurDimensions; diff --git a/mm/2s2h/BenGui/UIWidgets.hpp b/mm/2s2h/BenGui/UIWidgets.hpp index 6903d56c6..bf5d756eb 100644 --- a/mm/2s2h/BenGui/UIWidgets.hpp +++ b/mm/2s2h/BenGui/UIWidgets.hpp @@ -173,19 +173,26 @@ namespace UIWidgets { return *this; } }; - +using ComboMap_t = std::unordered_map<int32_t, const char*>*; +using ComboVec_t = std::vector<const char*>*; struct ComboboxOptions : WidgetOptions { - std::unordered_map<int32_t, const char*> comboMap = {}; + std::variant<ComboMap_t, ComboVec_t> comboVariant; uint32_t defaultIndex = 0; // Only applicable to CVarCombobox ComponentAlignment alignment = ComponentAlignment::Left; LabelPosition labelPosition = LabelPosition::Above; ImGuiComboFlags flags = 0; Colors color = Colors::LightBlue; - ComboboxOptions& ComboMap(std::unordered_map<int32_t, const char*> comboMap_) { - comboMap = comboMap_; + ComboboxOptions& ComboMap(const std::unordered_map<int32_t, const char*>* comboMap_) { + comboVariant = const_cast<std::unordered_map<int32_t, const char*>*>(comboMap_); + return *this; + } + + ComboboxOptions& ComboVec(const std::vector<const char*>* comboMap_) { + comboVariant = const_cast<std::vector<const char*>*>(comboMap_); return *this; } + ComboboxOptions& DefaultIndex(uint32_t defaultIndex_) { defaultIndex = defaultIndex_; return *this; @@ -362,13 +369,13 @@ namespace UIWidgets { void PopStyleCombobox(); template <typename T> - bool Combobox(const char* label, T* value, const std::unordered_map<T, const char*>& comboMap, const ComboboxOptions& options = {}) { + bool Combobox(const char* label, T* value, const std::unordered_map<T, const char*>* comboMap, const ComboboxOptions& options = {}) { bool dirty = false; float startX = ImGui::GetCursorPosX(); std::string invisibleLabelStr = "##" + std::string(label); const char* invisibleLabel = invisibleLabelStr.c_str(); - if (!comboMap.contains(*value)) { - *value = comboMap.begin()->first; + if (!comboMap->contains(*value)) { + *value = comboMap->begin()->first; } ImGui::PushID(label); ImGui::BeginGroup(); @@ -381,7 +388,7 @@ namespace UIWidgets { } else if (options.labelPosition == LabelPosition::Near) { ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x - ImGui::GetStyle().ItemSpacing.x * 2); } else if (options.labelPosition == LabelPosition::Far || options.labelPosition == LabelPosition::None) { - ImGui::SetNextItemWidth(ImGui::CalcTextSize(comboMap.at(*value)).x + ImGui::GetStyle().FramePadding.x * 4 + ImGui::GetStyle().ItemSpacing.x); + ImGui::SetNextItemWidth(ImGui::CalcTextSize(comboMap->at(*value)).x + ImGui::GetStyle().FramePadding.x * 4 + ImGui::GetStyle().ItemSpacing.x); } } else if (options.alignment == ComponentAlignment::Right) { if (options.labelPosition == LabelPosition::Above) { @@ -393,14 +400,14 @@ namespace UIWidgets { ImGui::SameLine(ImGui::CalcTextSize(label).x + ImGui::GetStyle().ItemSpacing.x * 2); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); } else if (options.labelPosition == LabelPosition::Far || options.labelPosition == LabelPosition::None) { - float width = ImGui::CalcTextSize(comboMap.at(*value)).x + ImGui::GetStyle().FramePadding.x * 4; + float width = ImGui::CalcTextSize(comboMap->at(*value)).x + ImGui::GetStyle().FramePadding.x * 4; ImGui::SameLine(ImGui::GetContentRegionAvail().x - width); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); } } - if (ImGui::BeginCombo(invisibleLabel, comboMap.at(*value), options.flags)) { + if (ImGui::BeginCombo(invisibleLabel, comboMap->at(*value), options.flags)) { ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10.0f, 10.0f)); - for (const auto& pair : comboMap) { + for (const auto& pair : *comboMap) { if (strlen(pair.second) > 1) { if (ImGui::Selectable(pair.second, pair.first == *value)) { *value = pair.first; @@ -453,7 +460,7 @@ namespace UIWidgets { PushStyleCombobox(options.color); if (options.alignment == ComponentAlignment::Left) { if (options.labelPosition == LabelPosition::Above) { - ImGui::Text(label); + ImGui::Text("%s",label); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); } else if (options.labelPosition == LabelPosition::Near) { ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x - ImGui::GetStyle().ItemSpacing.x * 2); @@ -464,7 +471,7 @@ namespace UIWidgets { if (options.labelPosition == LabelPosition::Above) { ImGui::NewLine(); ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x); - ImGui::Text(label); + ImGui::Text("%s",label); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); } else if (options.labelPosition == LabelPosition::Near) { ImGui::SameLine(ImGui::CalcTextSize(label).x + ImGui::GetStyle().ItemSpacing.x * 2); @@ -492,15 +499,15 @@ namespace UIWidgets { if (options.alignment == ComponentAlignment::Left) { if (options.labelPosition == LabelPosition::Near) { ImGui::SameLine(); - ImGui::Text(label); + ImGui::Text("%s",label); } else if (options.labelPosition == LabelPosition::Far) { ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x); - ImGui::Text(label); + ImGui::Text("%s",label); } } else if (options.alignment == ComponentAlignment::Right) { if (options.labelPosition == LabelPosition::Near || options.labelPosition == LabelPosition::Far) { ImGui::SameLine(startX); - ImGui::Text(label); + ImGui::Text("%s",label); } } PopStyleCombobox(); @@ -528,7 +535,7 @@ namespace UIWidgets { PushStyleCombobox(options.color); if (options.alignment == ComponentAlignment::Left) { if (options.labelPosition == LabelPosition::Above) { - ImGui::Text(label); + ImGui::Text("%s",label); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); } else if (options.labelPosition == LabelPosition::Near) { ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x - ImGui::GetStyle().ItemSpacing.x * 2); @@ -539,7 +546,7 @@ namespace UIWidgets { if (options.labelPosition == LabelPosition::Above) { ImGui::NewLine(); ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x); - ImGui::Text(label); + ImGui::Text("%s",label); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); } else if (options.labelPosition == LabelPosition::Near) { ImGui::SameLine(ImGui::CalcTextSize(label).x + ImGui::GetStyle().ItemSpacing.x * 2); @@ -567,15 +574,15 @@ namespace UIWidgets { if (options.alignment == ComponentAlignment::Left) { if (options.labelPosition == LabelPosition::Near) { ImGui::SameLine(); - ImGui::Text(label); + ImGui::Text("%s",label); } else if (options.labelPosition == LabelPosition::Far) { ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x); - ImGui::Text(label); + ImGui::Text("%s",label); } } else if (options.alignment == ComponentAlignment::Right) { if (options.labelPosition == LabelPosition::Near || options.labelPosition == LabelPosition::Far) { ImGui::SameLine(startX); - ImGui::Text(label); + ImGui::Text("%s", label); } } PopStyleCombobox(); @@ -669,7 +676,7 @@ namespace UIWidgets { } template <typename T = int32_t> - bool CVarCombobox(const char* label, const char* cvarName, const std::unordered_map<T, const char*>& comboMap, const ComboboxOptions& options = {}) { + bool CVarCombobox(const char* label, const char* cvarName, const std::unordered_map<T, const char*>* comboMap, const ComboboxOptions& options = {}) { bool dirty = false; int32_t value = CVarGetInteger(cvarName, options.defaultIndex); if (Combobox<T>(label, &value, comboMap, options)) { diff --git a/mm/2s2h/DeveloperTools/SaveEditor.cpp b/mm/2s2h/DeveloperTools/SaveEditor.cpp index ca4365b0f..e9dc59cfc 100644 --- a/mm/2s2h/DeveloperTools/SaveEditor.cpp +++ b/mm/2s2h/DeveloperTools/SaveEditor.cpp @@ -1629,7 +1629,7 @@ void DrawFlagsTab() { static int16_t selectedScene = 0; if (selectedFlagSection == 5 || selectedFlagSection == 6) { ImGui::SameLine(); - UIWidgets::Combobox("Scene", &selectedScene, sceneList, + UIWidgets::Combobox("Scene", &selectedScene, &sceneList, { .alignment = UIWidgets::ComponentAlignment::Left, .labelPosition = UIWidgets::LabelPosition::None, @@ -2133,7 +2133,7 @@ void DrawRandoTab() { : UIWidgets::ColorValues.at(UIWidgets::Colors::White), randoStaticCheck.name); ImGui::TableNextColumn(); - UIWidgets::Combobox((hiddenName + "reward").c_str(), &randoSaveCheck.randoItemId, randoItemIdComboboxMap, + UIWidgets::Combobox((hiddenName + "reward").c_str(), &randoSaveCheck.randoItemId, &randoItemIdComboboxMap, { .labelPosition = UIWidgets::LabelPosition::None }); } diff --git a/mm/2s2h/Enhancements/Trackers/DisplayOverlay.cpp b/mm/2s2h/Enhancements/Trackers/DisplayOverlay.cpp index 389fb0217..656319d9c 100644 --- a/mm/2s2h/Enhancements/Trackers/DisplayOverlay.cpp +++ b/mm/2s2h/Enhancements/Trackers/DisplayOverlay.cpp @@ -42,10 +42,10 @@ void DrawInGameTimer(uint32_t timer, ImVec4 color = ImVec4(1, 1, 1, 1)) { if (c == '.') { ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (8.0f * windowScale)); ImGui::Image(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(digitList[textureIndex]), - ImVec2(8.0f * windowScale, 8.0f * windowScale), ImVec2(0, 0.5f), ImVec2(1, 1), color); + ImVec2(8.0f * windowScale, 8.0f * windowScale), ImVec2(0, 0.5f), ImVec2(1, 1), color, {}); } else { ImGui::Image(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(digitList[textureIndex]), - ImVec2(8.0f * windowScale, 16.0f * windowScale), ImVec2(0, 0), ImVec2(1, 1), color); + ImVec2(8.0f * windowScale, 16.0f * windowScale), ImVec2(0, 0), ImVec2(1, 1), color, {}); } ImGui::SameLine(0, 0); } diff --git a/mm/2s2h/Enhancements/Trackers/ItemTracker.cpp b/mm/2s2h/Enhancements/Trackers/ItemTracker.cpp index 24fb8eaf5..4275443b2 100644 --- a/mm/2s2h/Enhancements/Trackers/ItemTracker.cpp +++ b/mm/2s2h/Enhancements/Trackers/ItemTracker.cpp @@ -145,7 +145,7 @@ void DrawItem(char* tex, bool drawFaded, float itemSize) { } ImGui::Image(gui->GetTextureByName(tex), ImVec2(itemSize, itemSize), ImVec2(0, 0), ImVec2(1, 1), - drawFaded ? fadedTex : opaqueTex); + drawFaded ? fadedTex : opaqueTex, {}); } void DrawItemTinted(char* tex, bool drawFaded, float itemSize, ImVec4 tintColor) { @@ -157,7 +157,7 @@ void DrawItemTinted(char* tex, bool drawFaded, float itemSize, ImVec4 tintColor) ImVec4 opacityMix = drawFaded ? fadedTex : opaqueTex; ImVec4 color = ImVec4(opacityMix.x * tintColor.x, opacityMix.y * tintColor.y, opacityMix.z * tintColor.z, opacityMix.w * tintColor.w); - ImGui::Image(gui->GetTextureByName(tex), ImVec2(itemSize, itemSize), ImVec2(0, 0), ImVec2(1, 1), color); + ImGui::Image(gui->GetTextureByName(tex), ImVec2(itemSize, itemSize), ImVec2(0, 0), ImVec2(1, 1), color, {}); } static constexpr std::array<ImVec4, 5> songInfo = { @@ -190,7 +190,7 @@ void ItemTrackerWindow::DrawNote(size_t songIndex, bool drawFaded) { color.w *= 0.5f; } ImGui::Image(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(gItemIconSongNoteTex), - scaledNoteSize, ImVec2(0, 0), ImVec2(1, 1), color); + scaledNoteSize, ImVec2(0, 0), ImVec2(1, 1), color, {}); } void ItemTrackerWindow::DrawOwlFace(bool drawFaded) { @@ -202,7 +202,7 @@ void ItemTrackerWindow::DrawOwlFace(bool drawFaded) { const ImVec2 scaledOwlSize(owlToScale * 24.0f * iconScale, owlToScale * 12.0f * iconScale); ImGui::Image(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(gWorldMapOwlFaceTex), - scaledOwlSize, ImVec2(0, 0), ImVec2(1, 1), drawFaded ? fadedTex : opaqueTex); + scaledOwlSize, ImVec2(0, 0), ImVec2(1, 1), drawFaded ? fadedTex : opaqueTex, {}); } extern "C" { @@ -624,7 +624,7 @@ int ItemTrackerWindow::DrawStrayFairies(int columns, int prevDrawnColumns) { } ImGui::Image( Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName((char*)sStrayFairyTextures[0]), - ImVec2(mIconSize, mIconSize), ImVec2(0, 0), ImVec2(1, 1), color); + ImVec2(mIconSize, mIconSize), ImVec2(0, 0), ImVec2(1, 1), color, {}); } else { ImGui::BeginGroup(); DrawItem((char*)sStrayFairyTextures[i - 1], gSaveContext.save.saveInfo.inventory.strayFairies[i - 1] == 0, diff --git a/mm/2s2h/Rando/Menu.cpp b/mm/2s2h/Rando/Menu.cpp index 0911986a6..1cf1f8c1d 100644 --- a/mm/2s2h/Rando/Menu.cpp +++ b/mm/2s2h/Rando/Menu.cpp @@ -108,7 +108,7 @@ static void DrawLogicConditionsTab() { f32 columnWidth = ImGui::GetContentRegionAvail().x / 3 - (ImGui::GetStyle().ItemSpacing.x * 2); f32 halfHeight = ImGui::GetContentRegionAvail().y / 2 - (ImGui::GetStyle().ItemSpacing.y * 2); ImGui::BeginChild("randoLogicColumn1", ImVec2(columnWidth, halfHeight)); - UIWidgets::CVarCombobox("Logic", Rando::StaticData::Options[RO_LOGIC].cvar, logicOptions); + UIWidgets::CVarCombobox("Logic", Rando::StaticData::Options[RO_LOGIC].cvar, &logicOptions); UIWidgets::Tooltip( "Glitchless - The items are shuffled in a way that guarantees the seed is beatable without " "glitches.\n\n" @@ -126,7 +126,7 @@ static void DrawLogicConditionsTab() { ImGui::BeginChild("randoLogicColumn2", ImVec2(columnWidth, halfHeight)); UIWidgets::CVarCombobox("Dungeon Access", Rando::StaticData::Options[RO_ACCESS_DUNGEONS].cvar, - accessDungeonOptions); + &accessDungeonOptions); UIWidgets::Tooltip("Dungeon access requirements:\n\n" "Requires Transformation & Song - Requires both the correct form and the song (Vanilla).\n\n" "Requires Transformation or Song - Requires either the correct form or the song.\n\n" @@ -139,7 +139,7 @@ static void DrawLogicConditionsTab() { UIWidgets::CVarSliderInt("Moon Access Remains Required", Rando::StaticData::Options[RO_ACCESS_MOON_REMAINS_COUNT].cvar, IntSliderOptions().Min(0).Max(4).DefaultValue(4)); - UIWidgets::CVarCombobox("Trials Access", Rando::StaticData::Options[RO_ACCESS_TRIALS].cvar, accessTrialsOptions); + UIWidgets::CVarCombobox("Trials Access", Rando::StaticData::Options[RO_ACCESS_TRIALS].cvar, &accessTrialsOptions); ImGui::EndChild(); ImGui::BeginChild("randoLogicTricks", ImVec2(0, 0)); ImGui::SeparatorText("Tricks & Glitches"); |
