mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 12:51:42 +00:00
options_menu: use config callbacks after setting items
This commit is contained in:
parent
b6960e7113
commit
dd066095a9
7 changed files with 33 additions and 7 deletions
|
|
@ -82,6 +82,7 @@ set(SWA_UI_CXX_SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SWA_CXX_SOURCES
|
set(SWA_CXX_SOURCES
|
||||||
|
"exports.cpp"
|
||||||
"main.cpp"
|
"main.cpp"
|
||||||
"misc_impl.cpp"
|
"misc_impl.cpp"
|
||||||
"stdafx.cpp"
|
"stdafx.cpp"
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "config_detail.h"
|
#include "config_detail.h"
|
||||||
#include "config_locale.h"
|
#include "config_locale.h"
|
||||||
|
#include "exports.h"
|
||||||
|
|
||||||
class Config
|
class Config
|
||||||
{
|
{
|
||||||
|
|
@ -41,7 +42,14 @@ public:
|
||||||
def->Value = std::clamp(def->Value, 0.25f, 2.0f);
|
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, VSync, true);
|
||||||
CONFIG_DEFINE_LOCALISED("Video", bool, TripleBuffering, true);
|
CONFIG_DEFINE_LOCALISED("Video", bool, TripleBuffering, true);
|
||||||
CONFIG_DEFINE_LOCALISED("Video", int32_t, FPS, 60);
|
CONFIG_DEFINE_LOCALISED("Video", int32_t, FPS, 60);
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ ConfigDef<T>::ConfigDef(std::string section, std::string name, CONFIG_LOCALE* na
|
||||||
|
|
||||||
// CONFIG_DEFINE_CALLBACK
|
// CONFIG_DEFINE_CALLBACK
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ConfigDef<T>::ConfigDef(std::string section, std::string name, T defaultValue, std::function<void(ConfigDef<T>*)> readCallback)
|
ConfigDef<T>::ConfigDef(std::string section, std::string name, T defaultValue, std::function<void(ConfigDef<T>*)> callback)
|
||||||
: Section(section), Name(name), DefaultValue(defaultValue), ReadCallback(readCallback)
|
: Section(section), Name(name), DefaultValue(defaultValue), Callback(callback)
|
||||||
{
|
{
|
||||||
Config::Definitions.emplace_back(this);
|
Config::Definitions.emplace_back(this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ public:
|
||||||
std::unordered_map<std::string, T>* EnumTemplate;
|
std::unordered_map<std::string, T>* EnumTemplate;
|
||||||
std::map<T, std::string> EnumTemplateReverse{};
|
std::map<T, std::string> EnumTemplateReverse{};
|
||||||
CONFIG_ENUM_LOCALE(T)* EnumLocale;
|
CONFIG_ENUM_LOCALE(T)* EnumLocale;
|
||||||
std::function<void(ConfigDef<T>*)> ReadCallback;
|
std::function<void(ConfigDef<T>*)> Callback;
|
||||||
|
|
||||||
// CONFIG_DEFINE
|
// CONFIG_DEFINE
|
||||||
ConfigDef(std::string section, std::string name, T defaultValue);
|
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);
|
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
|
// 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
|
void ReadValue(toml::v3::ex::parse_result& toml) override
|
||||||
{
|
{
|
||||||
|
|
@ -240,8 +240,8 @@ public:
|
||||||
Value = section[Name].value_or(DefaultValue);
|
Value = section[Name].value_or(DefaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ReadCallback)
|
if (Callback)
|
||||||
ReadCallback(this);
|
Callback(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
6
UnleashedRecomp/exports.cpp
Normal file
6
UnleashedRecomp/exports.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include <ui/window.h>
|
||||||
|
|
||||||
|
extern "C" void Window_SetFullscreen(bool isEnabled)
|
||||||
|
{
|
||||||
|
Window::SetFullscreen(isEnabled);
|
||||||
|
}
|
||||||
3
UnleashedRecomp/exports.h
Normal file
3
UnleashedRecomp/exports.h
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
extern "C" void Window_SetFullscreen(bool isEnabled);
|
||||||
|
|
@ -405,7 +405,12 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
|
||||||
if constexpr (std::is_same_v<T, bool>)
|
if constexpr (std::is_same_v<T, bool>)
|
||||||
{
|
{
|
||||||
if (padState.IsTapped(SWA::eKeyState_A))
|
if (padState.IsTapped(SWA::eKeyState_A))
|
||||||
|
{
|
||||||
config->Value = !config->Value;
|
config->Value = !config->Value;
|
||||||
|
|
||||||
|
if (config->Callback)
|
||||||
|
config->Callback(config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -586,6 +591,9 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
|
||||||
|
|
||||||
config->Value = std::clamp(config->Value, valueMin, valueMax);
|
config->Value = std::clamp(config->Value, valueMin, valueMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config->Callback)
|
||||||
|
config->Callback(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string valueText;
|
std::string valueText;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue