Files
Shiip-of-Hakinian-Espanol/soh/soh/SohGui/SohMenuSettings.cpp
2025-03-19 11:11:47 +01:00

386 lines
18 KiB
C++

#include "SohMenu.h"
#include "soh/Notification/Notification.h"
#include <soh/GameVersions.h>
#include "soh/ResourceManagerHelpers.h"
#include "UIWidgets.hpp"
#include <spdlog/fmt/fmt.h>
extern "C" {
#include "include/z64audio.h"
#include "variables.h"
}
namespace SohGui {
extern std::shared_ptr<SohMenu> mSohMenu;
using namespace UIWidgets;
static std::unordered_map<int32_t, const char*> languages = {{ LANGUAGE_ENG, "English" }, { LANGUAGE_GER, "German" }, { LANGUAGE_FRA, "French" }};
static std::unordered_map<int32_t, const char*> imguiScaleOptions = {{ 0, "Small" }, { 1, "Normal" }, { 2, "Large" }, { 3, "X-Large" }};
const char* GetGameVersionString(uint32_t index) {
uint32_t gameVersion = ResourceMgr_GetGameVersion(index);
switch (gameVersion) {
case OOT_NTSC_US_10:
return "NTSC-U 1.0";
case OOT_NTSC_US_11:
return "NTSC-U 1.1";
case OOT_NTSC_US_12:
return "NTSC-U 1.2";
case OOT_PAL_10:
return "PAL 1.0";
case OOT_PAL_11:
return "PAL 1.1";
case OOT_PAL_GC:
return "PAL GC";
case OOT_PAL_MQ:
return "PAL MQ";
case OOT_PAL_GC_DBG1:
case OOT_PAL_GC_DBG2:
return "PAL GC-D";
case OOT_PAL_GC_MQ_DBG:
return "PAL MQ-D";
case OOT_IQUE_CN:
return "IQUE CN";
case OOT_IQUE_TW:
return "IQUE TW";
default:
return "UNKNOWN";
}
}
void SohMenu::AddMenuSettings() {
// Add Settings Menu
AddMenuEntry("Settings", CVAR_SETTING("Menu.SettingsSidebarSection"));
AddSidebarEntry("Settings", "General", 3);
WidgetPath path = { "Settings", "General", SECTION_COLUMN_1 };
// General - Settings
AddWidget(path, "General Settings", WIDGET_SEPARATOR_TEXT);
AddWidget(path, "Menu Theme", WIDGET_CVAR_COMBOBOX)
.CVar(CVAR_SETTING("Menu.Theme"))
.Options(ComboboxOptions()
.Tooltip("Changes the Theme of the Menu Widgets.")
.ComboMap(menuThemeOptions)
.DefaultIndex(Colors::LightBlue));
#if not defined(__SWITCH__) and not defined(__WIIU__)
AddWidget(path, "Menu Controller Navigation", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_IMGUI_CONTROLLER_NAV)
.Options(CheckboxOptions().Tooltip(
"Allows controller navigation of the port menu (Settings, Enhancements,...)\nCAUTION: "
"This will disable game inputs while the menu is visible.\n\nD-pad to move between "
"items, A to select, B to move up in scope."));
AddWidget(path, "Cursor Always Visible", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_SETTING("CursorVisibility"))
.Callback([](WidgetInfo& info) {
Ship::Context::GetInstance()->GetWindow()->SetForceCursorVisibility(
CVarGetInteger(CVAR_SETTING("CursorVisibility"), 0));
})
.Options(CheckboxOptions().Tooltip("Makes the cursor always visible, even in full screen."));
#endif
AddWidget(path, "Search In Sidebar", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_SETTING("Menu.SidebarSearch"))
.Callback([](WidgetInfo& info) {
if (CVarGetInteger(CVAR_SETTING("Menu.SidebarSearch"), 0)) {
mSohMenu->InsertSidebarSearch();
} else {
mSohMenu->RemoveSidebarSearch();
}
})
.Options(CheckboxOptions().Tooltip(
"Displays the Search menu as a sidebar entry in Settings instead of in the header."));
AddWidget(path, "Search Input Autofocus", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_SETTING("Menu.SearchAutofocus"))
.Options(CheckboxOptions().Tooltip(
"Search input box gets autofocus when visible. Does not affect using other widgets."));
AddWidget(path, "Alt Assets Tab hotkey", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_SETTING("Mods.AlternateAssetsHotkey"))
.Options(
CheckboxOptions().Tooltip("Allows pressing the Tab key to toggle alternate assets").DefaultValue(true));
AddWidget(path, "Open App Files Folder", WIDGET_BUTTON)
.Callback([](WidgetInfo& info) {
std::string filesPath = Ship::Context::GetInstance()->GetAppDirectoryPath();
SDL_OpenURL(std::string("file:///" + std::filesystem::absolute(filesPath).string()).c_str());
})
.Options(ButtonOptions().Tooltip("Opens the folder that contains the save and mods folders, etc."));
AddWidget(path, "Boot", WIDGET_SEPARATOR_TEXT);
AddWidget(path, "Boot Sequence", WIDGET_CVAR_COMBOBOX)
.CVar(CVAR_ENHANCEMENT("BootSequence"))
.Options(ComboboxOptions()
.DefaultIndex(BOOTSEQUENCE_DEFAULT)
.LabelPosition(LabelPosition::Far)
.ComponentAlignment(ComponentAlignment::Right)
.ComboMap(bootSequenceLabels)
.Tooltip("Configure what happens when starting or resetting the game.\n\n"
"Default: LUS logo -> N64 logo\n"
"Authentic: N64 logo only\n"
"File Select: Skip to file select menu"));
AddWidget(path, "Languages", WIDGET_SEPARATOR_TEXT);
AddWidget(path, "Translate Title Screen", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_SETTING("TitleScreenTranslation"));
AddWidget(path, "Menu Language", WIDGET_CVAR_COMBOBOX)
.CVar(CVAR_SETTING("Languages"))
.Options(ComboboxOptions().LabelPosition(LabelPosition::Far).ComponentAlignment(ComponentAlignment::Right).ComboMap(languages).DefaultIndex(LANGUAGE_ENG));
AddWidget(path, "Accessibility", WIDGET_SEPARATOR_TEXT);
#if defined(_WIN32) || defined(__APPLE__)
AddWidget(path, "Text to Speech", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_SETTING("A11yTTS"))
.Options(CheckboxOptions().Tooltip("Enables text to speech for in game dialog"));
#endif
AddWidget(path, "Disable Idle Camera Re-Centering", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_SETTING("A11yDisableIdleCam"))
.Options(CheckboxOptions().Tooltip("Disables the automatic re-centering of the camera when idle."));
AddWidget(path, "EXPERIMENTAL", WIDGET_SEPARATOR_TEXT)
.Options(TextOptions().Color(Colors::Orange));
AddWidget(path, "ImGui Menu Scaling", WIDGET_CVAR_COMBOBOX)
.CVar(CVAR_SETTING("ImGuiScale"))
.Options(ComboboxOptions().ComboMap(imguiScaleOptions).Tooltip("Changes the scaling of the ImGui menu elements.").DefaultIndex(1)
.ComponentAlignment(ComponentAlignment::Right).LabelPosition(LabelPosition::Far))
.Callback([](WidgetInfo& info) {
OTRGlobals::Instance->ScaleImGui();
});
// General - About
path.column = SECTION_COLUMN_2;
AddWidget(path, "About", WIDGET_SEPARATOR_TEXT);
AddWidget(path, "Ship Of Harkinian", WIDGET_TEXT);
if (gGitCommitTag[0] != 0) {
AddWidget(path, gBuildVersion, WIDGET_TEXT);
} else {
AddWidget(path, ("Branch: " + std::string(gGitBranch)), WIDGET_TEXT);
AddWidget(path, ("Commit: " + std::string(gGitCommitHash)), WIDGET_TEXT);
}
for (uint32_t i = 0; i < ResourceMgr_GetNumGameVersions(); i++) {
AddWidget(path, GetGameVersionString(i), WIDGET_TEXT);
}
// Audio Settings
path.sidebarName = "Audio";
path.column = SECTION_COLUMN_1;
AddSidebarEntry("Settings", "Audio", 3);
AddWidget(path, "Master Volume: %d %%", WIDGET_CVAR_SLIDER_INT)
.CVar(CVAR_SETTING("Volume.Master"))
.Options(IntSliderOptions()
.Min(0)
.Max(100)
.DefaultValue(40)
.ShowButtons(true)
.Format(""));
AddWidget(path, "Main Music Volume: %d %%", WIDGET_CVAR_SLIDER_INT)
.CVar(CVAR_SETTING("Volume.MainMusic"))
.Options(IntSliderOptions()
.Min(0)
.Max(100)
.DefaultValue(100)
.ShowButtons(true)
.Format(""))
.Callback([](WidgetInfo& info) {
Audio_SetGameVolume(SEQ_PLAYER_BGM_MAIN, ((float)CVarGetInteger(CVAR_SETTING("Volume.MainMusic"), 100) / 100.0f));
});
AddWidget(path, "Sub Music Volume: %d %%", WIDGET_CVAR_SLIDER_INT)
.CVar(CVAR_SETTING("Volume.SubMusic"))
.Options(IntSliderOptions()
.Min(0)
.Max(100)
.DefaultValue(100)
.ShowButtons(true)
.Format(""))
.Callback([](WidgetInfo& info) {
Audio_SetGameVolume(SEQ_PLAYER_BGM_SUB, ((float)CVarGetInteger(CVAR_SETTING("Volume.SubMusic"), 100) / 100.0f));
});
AddWidget(path, "Fanfare Volume: %d %%", WIDGET_CVAR_SLIDER_INT)
.CVar(CVAR_SETTING("Volume.Fanfare"))
.Options(IntSliderOptions()
.Min(0)
.Max(100)
.DefaultValue(100)
.ShowButtons(true)
.Format(""))
.Callback([](WidgetInfo& info) {
Audio_SetGameVolume(SEQ_PLAYER_FANFARE, ((float)CVarGetInteger(CVAR_SETTING("Volume.Fanfare"), 100) / 100.0f));
});
AddWidget(path, "Sound Effects Volume: %d %%", WIDGET_CVAR_SLIDER_INT)
.CVar(CVAR_SETTING("Volume.SFX"))
.Options(IntSliderOptions()
.Min(0)
.Max(100)
.DefaultValue(100)
.ShowButtons(true)
.Format(""))
.Callback([](WidgetInfo& info) {
Audio_SetGameVolume(SEQ_PLAYER_SFX, ((float)CVarGetInteger(CVAR_SETTING("Volume.SFX"), 100) / 100.0f));
});
AddWidget(path, "Audio API (Needs reload)", WIDGET_AUDIO_BACKEND);
// Graphics Settings
static int32_t maxFps = 360;
const char* tooltip = "Uses Matrix Interpolation to create extra frames, resulting in smoother graphics. This is "
"purely visual and does not impact game logic, execution of glitches etc.\n\nA higher target "
"FPS than your monitor's refresh rate will waste resources, and might give a worse result.";
path.sidebarName = "Graphics";
AddSidebarEntry("Settings", "Graphics", 3);
AddWidget(path, "Graphics Options", WIDGET_SEPARATOR_TEXT);
AddWidget(path, "Toggle Fullscreen", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_SETTING("Fullscreen"))
.Callback([](WidgetInfo& info) { Ship::Context::GetInstance()->GetWindow()->ToggleFullscreen(); })
.Options(CheckboxOptions().Tooltip("Toggles Fullscreen On/Off."));
AddWidget(path, "Internal Resolution", WIDGET_CVAR_SLIDER_FLOAT)
.CVar(CVAR_INTERNAL_RESOLUTION)
.Callback([](WidgetInfo& info) {
Ship::Context::GetInstance()->GetWindow()->SetResolutionMultiplier(
CVarGetFloat(CVAR_INTERNAL_RESOLUTION, 1));
})
.PreFunc([](WidgetInfo& info) {
if (mSohMenu->disabledMap.at(DISABLE_FOR_ADVANCED_RESOLUTION_ON).active &&
mSohMenu->disabledMap.at(DISABLE_FOR_VERTICAL_RES_TOGGLE_ON).active) {
info.activeDisables.push_back(DISABLE_FOR_ADVANCED_RESOLUTION_ON);
info.activeDisables.push_back(DISABLE_FOR_VERTICAL_RES_TOGGLE_ON);
} else if (mSohMenu->disabledMap.at(DISABLE_FOR_LOW_RES_MODE_ON).active) {
info.activeDisables.push_back(DISABLE_FOR_LOW_RES_MODE_ON);
}
})
.Options(
FloatSliderOptions()
.Tooltip("Multiplies your output resolution by the value inputted, as a more intensive but effective "
"form of anti-aliasing.")
.ShowButtons(false)
.IsPercentage()
.Min(0.5f)
.Max(2.0f));
#ifndef __WIIU__
AddWidget(path, "Anti-aliasing (MSAA)", WIDGET_CVAR_SLIDER_INT)
.CVar(CVAR_MSAA_VALUE)
.Callback([](WidgetInfo& info) {
Ship::Context::GetInstance()->GetWindow()->SetMsaaLevel(CVarGetInteger(CVAR_MSAA_VALUE, 1));
})
.Options(
IntSliderOptions()
.Tooltip("Activates MSAA (multi-sample anti-aliasing) from 2x up to 8x, to smooth the edges of "
"rendered geometry.\n"
"Higher sample count will result in smoother edges on models, but may reduce performance.")
.Min(1)
.Max(8)
.DefaultValue(1));
#endif
auto fps = CVarGetInteger(CVAR_SETTING("InterpolationFPS"), 20);
const char* fpsFormat = fps == 20 ? "Original (%d)" : "%d";
AddWidget(path, "Current FPS", WIDGET_CVAR_SLIDER_INT)
.CVar(CVAR_SETTING("InterpolationFPS"))
.Callback([](WidgetInfo& info) {
auto options = std::static_pointer_cast<IntSliderOptions>(info.options);
int32_t defaultValue = options->defaultValue;
if (CVarGetInteger(info.cVar, defaultValue) == defaultValue) {
options->format = "Original (%d)";
}
else {
options->format = "%d";
}
})
.PreFunc([](WidgetInfo& info) {
if (mSohMenu->disabledMap.at(DISABLE_FOR_MATCH_REFRESH_RATE_ON).active)
info.activeDisables.push_back(DISABLE_FOR_MATCH_REFRESH_RATE_ON);
})
.Options(IntSliderOptions().Tooltip(tooltip).Min(20).Max(maxFps).DefaultValue(20).Format(fpsFormat));
AddWidget(path, "Match Refresh Rate", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_SETTING("MatchRefreshRate"))
.Options(CheckboxOptions().Tooltip("Matches interpolation value to the refresh rate of your display."));
AddWidget(path, "Renderer API (Needs reload)", WIDGET_VIDEO_BACKEND);
AddWidget(path, "Enable Vsync", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_VSYNC_ENABLED)
.PreFunc([](WidgetInfo& info) { info.isHidden = mSohMenu->disabledMap.at(DISABLE_FOR_NO_VSYNC).active; })
.Options(CheckboxOptions().Tooltip("Removes tearing, but clamps your max FPS to your displays refresh rate."));
AddWidget(path, "Windowed Fullscreen", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_SDL_WINDOWED_FULLSCREEN)
.PreFunc([](WidgetInfo& info) {
info.isHidden = mSohMenu->disabledMap.at(DISABLE_FOR_NO_WINDOWED_FULLSCREEN).active;
})
.Options(CheckboxOptions().Tooltip("Enables Windowed Fullscreen Mode."));
AddWidget(path, "Allow multi-windows", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_ENABLE_MULTI_VIEWPORTS)
.PreFunc(
[](WidgetInfo& info) { info.isHidden = mSohMenu->disabledMap.at(DISABLE_FOR_NO_MULTI_VIEWPORT).active; })
.Options(CheckboxOptions().Tooltip(
"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));
path.column = SECTION_COLUMN_2;
AddWidget(path, "Advanced Graphics Options", WIDGET_SEPARATOR_TEXT);
// Controls
path.sidebarName = "Controls";
path.column = SECTION_COLUMN_1;
AddSidebarEntry("Settings", "Controls", 2);
AddWidget(path, "Controller Bindings", WIDGET_SEPARATOR_TEXT);
AddWidget(path, "Popout Bindings Window", WIDGET_WINDOW_BUTTON)
.CVar(CVAR_WINDOW("ControllerConfiguration"))
.WindowName("Configure Controller")
.Options(WindowButtonOptions().Tooltip("Enables the separate Bindings Window."));
// Input Viewer
path.sidebarName = "Input Viewer";
AddSidebarEntry("Settings", path.sidebarName, 3);
AddWidget(path, "Input Viewer", WIDGET_SEPARATOR_TEXT);
AddWidget(path, "Toggle Input Viewer", WIDGET_WINDOW_BUTTON)
.CVar(CVAR_WINDOW("InputViewer"))
.WindowName("Input Viewer")
.Options(WindowButtonOptions().Tooltip("Toggles the Input Viewer.").EmbedWindow(false));
AddWidget(path, "Input Viewer Settings", WIDGET_SEPARATOR_TEXT);
AddWidget(path, "Popout Input Viewer Settings", WIDGET_WINDOW_BUTTON)
.CVar(CVAR_WINDOW("InputViewerSettings"))
.WindowName("Input Viewer Settings")
.Options(WindowButtonOptions().Tooltip("Enables the separate Input Viewer Settings Window."));
// Notifications
path.sidebarName = "Notifications";
path.column = SECTION_COLUMN_1;
AddSidebarEntry("Settings", path.sidebarName, 3);
AddWidget(path, "Position", WIDGET_CVAR_COMBOBOX)
.CVar(CVAR_SETTING("Notifications.Position"))
.Options(ComboboxOptions()
.Tooltip("Which corner of the screen notifications appear in.")
.ComboMap(notificationPosition)
.DefaultIndex(3));
AddWidget(path, "Duration: %.0f seconds", WIDGET_CVAR_SLIDER_FLOAT)
.CVar(CVAR_SETTING("Notifications.Duration"))
.Options(FloatSliderOptions()
.Tooltip("How long notifications are displayed for.")
.Format("%.1f")
.Step(0.1f)
.Min(3.0f)
.Max(30.0f)
.DefaultValue(10.0f));
AddWidget(path, "Background Opacity: %.0f%%", WIDGET_CVAR_SLIDER_FLOAT)
.CVar(CVAR_SETTING("Notifications.BgOpacity"))
.Options(FloatSliderOptions()
.Tooltip("How opaque the background of notifications is.")
.DefaultValue(0.5f)
.IsPercentage());
AddWidget(path, "Size %.1f", WIDGET_CVAR_SLIDER_FLOAT)
.CVar(CVAR_SETTING("Notifications.Size"))
.Options(FloatSliderOptions()
.Tooltip("How large notifications are.")
.Format("%.1f")
.Step(0.1f)
.Min(1.0f)
.Max(5.0f)
.DefaultValue(1.8f));
AddWidget(path, "Test Notification", WIDGET_BUTTON)
.Callback([](WidgetInfo& info) {
Notification::Emit({
.itemIcon = "__OTR__textures/icon_item_24_static/gQuestIconGoldSkulltulaTex",
.prefix = "This",
.message = "is a",
.suffix = "test.",
});
})
.Options(ButtonOptions().Tooltip("Displays a test notification."));
}
} // namespace SohGui