options_menu: use config callbacks after setting items

This commit is contained in:
Hyper 2024-11-18 23:37:04 +00:00
parent b6960e7113
commit dd066095a9
7 changed files with 33 additions and 7 deletions

View file

@ -82,6 +82,7 @@ set(SWA_UI_CXX_SOURCES
)
set(SWA_CXX_SOURCES
"exports.cpp"
"main.cpp"
"misc_impl.cpp"
"stdafx.cpp"

View file

@ -2,6 +2,7 @@
#include "config_detail.h"
#include "config_locale.h"
#include "exports.h"
class Config
{
@ -41,7 +42,14 @@ public:
def->Value = std::clamp(def->Value, 0.25f, 2.0f);
});
CONFIG_DEFINE_LOCALISED("Video", bool, Fullscreen, false);
CONFIG_DEFINE_CALLBACK("Video", bool, Fullscreen, false,
{
def->NameLocale = &g_Fullscreen_locale;
def->DescLocale = &g_Fullscreen_desc_locale;
Window_SetFullscreen(def->Value);
});
CONFIG_DEFINE_LOCALISED("Video", bool, VSync, true);
CONFIG_DEFINE_LOCALISED("Video", bool, TripleBuffering, true);
CONFIG_DEFINE_LOCALISED("Video", int32_t, FPS, 60);

View file

@ -40,8 +40,8 @@ ConfigDef<T>::ConfigDef(std::string section, std::string name, CONFIG_LOCALE* na
// CONFIG_DEFINE_CALLBACK
template<typename T>
ConfigDef<T>::ConfigDef(std::string section, std::string name, T defaultValue, std::function<void(ConfigDef<T>*)> readCallback)
: Section(section), Name(name), DefaultValue(defaultValue), ReadCallback(readCallback)
ConfigDef<T>::ConfigDef(std::string section, std::string name, T defaultValue, std::function<void(ConfigDef<T>*)> callback)
: Section(section), Name(name), DefaultValue(defaultValue), Callback(callback)
{
Config::Definitions.emplace_back(this);
}

View file

@ -202,7 +202,7 @@ public:
std::unordered_map<std::string, T>* EnumTemplate;
std::map<T, std::string> EnumTemplateReverse{};
CONFIG_ENUM_LOCALE(T)* EnumLocale;
std::function<void(ConfigDef<T>*)> ReadCallback;
std::function<void(ConfigDef<T>*)> Callback;
// CONFIG_DEFINE
ConfigDef(std::string section, std::string name, T defaultValue);
@ -217,7 +217,7 @@ public:
ConfigDef(std::string section, std::string name, CONFIG_LOCALE* nameLocale, CONFIG_LOCALE* descLocale, T defaultValue, std::unordered_map<std::string, T>* enumTemplate, CONFIG_ENUM_LOCALE(T)* enumLocale);
// CONFIG_DEFINE_CALLBACK
ConfigDef(std::string section, std::string name, T defaultValue, std::function<void(ConfigDef<T>*)> readCallback);
ConfigDef(std::string section, std::string name, T defaultValue, std::function<void(ConfigDef<T>*)> callback);
void ReadValue(toml::v3::ex::parse_result& toml) override
{
@ -240,8 +240,8 @@ public:
Value = section[Name].value_or(DefaultValue);
}
if (ReadCallback)
ReadCallback(this);
if (Callback)
Callback(this);
}
}

View file

@ -0,0 +1,6 @@
#include <ui/window.h>
extern "C" void Window_SetFullscreen(bool isEnabled)
{
Window::SetFullscreen(isEnabled);
}

View file

@ -0,0 +1,3 @@
#pragma once
extern "C" void Window_SetFullscreen(bool isEnabled);

View file

@ -405,7 +405,12 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
if constexpr (std::is_same_v<T, bool>)
{
if (padState.IsTapped(SWA::eKeyState_A))
{
config->Value = !config->Value;
if (config->Callback)
config->Callback(config);
}
}
else
{
@ -586,6 +591,9 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
config->Value = std::clamp(config->Value, valueMin, valueMax);
}
if (config->Callback)
config->Callback(config);
}
std::string valueText;