diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index ad2abc6f..752c6cce 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -82,6 +82,7 @@ set(SWA_UI_CXX_SOURCES ) set(SWA_CXX_SOURCES + "exports.cpp" "main.cpp" "misc_impl.cpp" "stdafx.cpp" diff --git a/UnleashedRecomp/cfg/config.h b/UnleashedRecomp/cfg/config.h index 7013c376..9378be2b 100644 --- a/UnleashedRecomp/cfg/config.h +++ b/UnleashedRecomp/cfg/config.h @@ -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); diff --git a/UnleashedRecomp/cfg/config_detail.cpp b/UnleashedRecomp/cfg/config_detail.cpp index b8edf28a..5359b751 100644 --- a/UnleashedRecomp/cfg/config_detail.cpp +++ b/UnleashedRecomp/cfg/config_detail.cpp @@ -40,8 +40,8 @@ ConfigDef::ConfigDef(std::string section, std::string name, CONFIG_LOCALE* na // CONFIG_DEFINE_CALLBACK template -ConfigDef::ConfigDef(std::string section, std::string name, T defaultValue, std::function*)> readCallback) - : Section(section), Name(name), DefaultValue(defaultValue), ReadCallback(readCallback) +ConfigDef::ConfigDef(std::string section, std::string name, T defaultValue, std::function*)> callback) + : Section(section), Name(name), DefaultValue(defaultValue), Callback(callback) { Config::Definitions.emplace_back(this); } diff --git a/UnleashedRecomp/cfg/config_detail.h b/UnleashedRecomp/cfg/config_detail.h index 3853c94a..8b2f8470 100644 --- a/UnleashedRecomp/cfg/config_detail.h +++ b/UnleashedRecomp/cfg/config_detail.h @@ -202,7 +202,7 @@ public: std::unordered_map* EnumTemplate; std::map EnumTemplateReverse{}; CONFIG_ENUM_LOCALE(T)* EnumLocale; - std::function*)> ReadCallback; + std::function*)> 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* enumTemplate, CONFIG_ENUM_LOCALE(T)* enumLocale); // CONFIG_DEFINE_CALLBACK - ConfigDef(std::string section, std::string name, T defaultValue, std::function*)> readCallback); + ConfigDef(std::string section, std::string name, T defaultValue, std::function*)> 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); } } diff --git a/UnleashedRecomp/exports.cpp b/UnleashedRecomp/exports.cpp new file mode 100644 index 00000000..65dbae7a --- /dev/null +++ b/UnleashedRecomp/exports.cpp @@ -0,0 +1,6 @@ +#include + +extern "C" void Window_SetFullscreen(bool isEnabled) +{ + Window::SetFullscreen(isEnabled); +} diff --git a/UnleashedRecomp/exports.h b/UnleashedRecomp/exports.h new file mode 100644 index 00000000..a19eea6a --- /dev/null +++ b/UnleashedRecomp/exports.h @@ -0,0 +1,3 @@ +#pragma once + +extern "C" void Window_SetFullscreen(bool isEnabled); diff --git a/UnleashedRecomp/ui/options_menu.cpp b/UnleashedRecomp/ui/options_menu.cpp index 1f490abd..19734973 100644 --- a/UnleashedRecomp/ui/options_menu.cpp +++ b/UnleashedRecomp/ui/options_menu.cpp @@ -405,7 +405,12 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf if constexpr (std::is_same_v) { 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* conf config->Value = std::clamp(config->Value, valueMin, valueMax); } + + if (config->Callback) + config->Callback(config); } std::string valueText;