diff --git a/UnleashedRecomp/config.cpp b/UnleashedRecomp/config.cpp index 1d930219..07d9b686 100644 --- a/UnleashedRecomp/config.cpp +++ b/UnleashedRecomp/config.cpp @@ -18,7 +18,7 @@ void Config::Load() { def->ReadValue(toml); #if _DEBUG - printf("%s\n", def->GetDefinition().c_str()); + printf("%s (0x%llx)\n", def->GetDefinition().c_str(), def->GetValue()); #endif } } diff --git a/UnleashedRecomp/config.h b/UnleashedRecomp/config.h index 063ced06..1d564ea6 100644 --- a/UnleashedRecomp/config.h +++ b/UnleashedRecomp/config.h @@ -5,7 +5,7 @@ class Config { public: - inline static std::vector Definitions{}; + inline static std::vector Definitions{}; CONFIG_DEFINE_ENUM("System", ELanguage, Language, ELanguage::English); CONFIG_DEFINE("System", bool, Hints, true); diff --git a/UnleashedRecomp/config_detail.h b/UnleashedRecomp/config_detail.h index 5b315401..10ee0def 100644 --- a/UnleashedRecomp/config_detail.h +++ b/UnleashedRecomp/config_detail.h @@ -30,24 +30,23 @@ #define WINDOWPOS_CENTRED 0x2FFF0000 -class ConfigDefBase +class IConfigDef { public: - virtual ~ConfigDefBase() = default; + virtual ~IConfigDef() = default; virtual void ReadValue(toml::v3::ex::parse_result& toml) = 0; virtual void MakeDefault() = 0; - virtual std::string GetSection() const = 0; - virtual std::string GetName() const = 0; + virtual bool IsMenuOption() const = 0; + virtual std::string_view GetSection() const = 0; + virtual std::string_view GetName() const = 0; + virtual void* GetValue() = 0; virtual std::string GetDefinition(bool withSection = false) const = 0; virtual std::string ToString() const = 0; }; template -class ConfigDef : public ConfigDefBase +class ConfigDef : public IConfigDef { -protected: - bool m_isMenuOption{ isMenuOption }; - public: std::string Section{}; std::string Name{}; @@ -123,16 +122,26 @@ public: Value = DefaultValue; } - std::string GetSection() const override + bool IsMenuOption() const override + { + return isMenuOption; + } + + std::string_view GetSection() const override { return Section; } - std::string GetName() const override + std::string_view GetName() const override { return Name; } + void* GetValue() override + { + return &Value; + } + std::string GetDefinition(bool withSection = false) const override { std::string result; @@ -147,27 +156,25 @@ public: std::string ToString() const override { - if constexpr (std::is_same::value) + std::string result = "\"N/A\""; + + if constexpr (std::is_same_v) { - return std::format("\"{}\"", Value); + result = std::format("\"{}\"", Value); } else if constexpr (std::is_enum_v) { auto it = EnumTemplateReverse.find(Value); if (it != EnumTemplateReverse.end()) - { - return std::format("\"{}\"", it->second); - } - else - { - return "\"N/A\""; - } + result = std::format("\"{}\"", it->second); } else { - return std::format("{}", Value); + result = std::format("{}", Value); } + + return result; } ConfigDef& operator=(const ConfigDef& other) diff --git a/UnleashedRecomp/ui/options_menu.cpp b/UnleashedRecomp/ui/options_menu.cpp index 2586e036..cdbcb617 100644 --- a/UnleashedRecomp/ui/options_menu.cpp +++ b/UnleashedRecomp/ui/options_menu.cpp @@ -311,7 +311,7 @@ static void DrawConfigOptions() for (auto& config : Config::Definitions) { - if (_stricmp(config->GetSection().c_str(), CATEGORIES[g_categoryIndex]) != 0) + if (_stricmp(config->GetSection().data(), CATEGORIES[g_categoryIndex]) != 0) continue; // Left side @@ -322,9 +322,9 @@ static void DrawConfigOptions() drawList->AddRectFilledMultiColor(min, max, COLOR0, COLOR0, COLOR1, COLOR1); float size = Scale(26.0f); - auto textSize = g_seuratFont->CalcTextSizeA(size, FLT_MAX, 0.0f, config->GetName().c_str()); + auto textSize = g_seuratFont->CalcTextSizeA(size, FLT_MAX, 0.0f, config->GetName().data()); - drawList->AddText(g_seuratFont, size, { min.x + gridSize, min.y + (optionHeight - textSize.y) / 2.0f }, IM_COL32_WHITE, config->GetName().c_str()); + drawList->AddText(g_seuratFont, size, { min.x + gridSize, min.y + (optionHeight - textSize.y) / 2.0f }, IM_COL32_WHITE, config->GetName().data()); // Right side min = { max.x + (clipRectMax.x - max.x - valueWidth) / 2.0f, min.y + (optionHeight - valueHeight) / 2.0f }; @@ -342,7 +342,7 @@ static void DrawConfigOptions() std::transform(valueText.begin(), valueText.end(), valueText.begin(), toupper); size = Scale(20.0f); - textSize = g_newRodinFont->CalcTextSizeA(size, FLT_MAX, 0.0f, valueText.c_str()); + textSize = g_newRodinFont->CalcTextSizeA(size, FLT_MAX, 0.0f, valueText.data()); min.x += ((max.x - min.x) - textSize.x) / 2.0f; min.y += ((max.y - min.y) - textSize.y) / 2.0f; @@ -359,7 +359,7 @@ static void DrawConfigOptions() size, min, IM_COL32_WHITE, - valueText.c_str(), + valueText.data(), Scale(2), IM_COL32_BLACK);