mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-28 05:11:37 +00:00
Refactor Config.
This commit is contained in:
parent
32d9d52d5e
commit
5512602231
11 changed files with 600 additions and 648 deletions
|
|
@ -195,7 +195,6 @@ set(MINIAUDIO_INCLUDE_DIRS "${SWA_THIRDPARTY_ROOT}/miniaudio")
|
||||||
set(SWA_USER_CXX_SOURCES
|
set(SWA_USER_CXX_SOURCES
|
||||||
"user/achievement_data.cpp"
|
"user/achievement_data.cpp"
|
||||||
"user/config.cpp"
|
"user/config.cpp"
|
||||||
"user/config_detail.cpp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SWA_CXX_SOURCES
|
set(SWA_CXX_SOURCES
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <user/config_detail.h>
|
#include <user/config.h>
|
||||||
|
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ void ImFontAtlasSnapshot::GenerateGlyphRanges()
|
||||||
{
|
{
|
||||||
std::vector<std::string_view> localeStrings;
|
std::vector<std::string_view> localeStrings;
|
||||||
|
|
||||||
for (auto& config : Config::Definitions)
|
for (auto& config : g_configDefinitions)
|
||||||
config->GetLocaleStrings(localeStrings);
|
config->GetLocaleStrings(localeStrings);
|
||||||
|
|
||||||
std::set<ImWchar> glyphs;
|
std::set<ImWchar> glyphs;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
#include <user/config.h>
|
#include <user/config.h>
|
||||||
#include <user/config_detail.h>
|
|
||||||
|
|
||||||
#define CONFIG_DEFINE_LOCALE(name) \
|
#define CONFIG_DEFINE_LOCALE(name) \
|
||||||
CONFIG_LOCALE Config::g_##name##_locale =
|
CONFIG_LOCALE Config::g_##name##_locale =
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <user/config.h>
|
||||||
#include <locale/locale.h>
|
#include <locale/locale.h>
|
||||||
|
|
||||||
std::unordered_map<std::string, std::unordered_map<ELanguage, std::string>> g_locale =
|
std::unordered_map<std::string, std::unordered_map<ELanguage, std::string>> g_locale =
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <user/config.h>
|
enum class ELanguage : uint32_t
|
||||||
|
{
|
||||||
|
English = 1,
|
||||||
|
Japanese,
|
||||||
|
German,
|
||||||
|
French,
|
||||||
|
Spanish,
|
||||||
|
Italian
|
||||||
|
};
|
||||||
|
|
||||||
inline std::string g_localeMissing = "<missing string>";
|
inline std::string g_localeMissing = "<missing string>";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -444,7 +444,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
|
||||||
ImVec2 min = { clipRectMin.x, clipRectMin.y + (optionHeight + optionPadding) * rowIndex + yOffset };
|
ImVec2 min = { clipRectMin.x, clipRectMin.y + (optionHeight + optionPadding) * rowIndex + yOffset };
|
||||||
ImVec2 max = { min.x + optionWidth, min.y + optionHeight };
|
ImVec2 max = { min.x + optionWidth, min.y + optionHeight };
|
||||||
|
|
||||||
auto configName = config->GetNameLocalised();
|
auto configName = config->GetNameLocalised(Config::Language);
|
||||||
auto size = Scale(26.0f);
|
auto size = Scale(26.0f);
|
||||||
auto textSize = g_seuratFont->CalcTextSizeA(size, FLT_MAX, 0.0f, configName.c_str());
|
auto textSize = g_seuratFont->CalcTextSizeA(size, FLT_MAX, 0.0f, configName.c_str());
|
||||||
|
|
||||||
|
|
@ -747,7 +747,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
valueText = config->GetValueLocalised();
|
valueText = config->GetValueLocalised(Config::Language);
|
||||||
}
|
}
|
||||||
|
|
||||||
size = Scale(20.0f);
|
size = Scale(20.0f);
|
||||||
|
|
@ -952,7 +952,7 @@ static void DrawInfoPanel()
|
||||||
|
|
||||||
if (g_selectedItem)
|
if (g_selectedItem)
|
||||||
{
|
{
|
||||||
auto desc = g_selectedItem->GetDescription();
|
auto desc = g_selectedItem->GetDescription(Config::Language);
|
||||||
auto thumbnail = GetThumbnail(g_selectedItem);
|
auto thumbnail = GetThumbnail(g_selectedItem);
|
||||||
|
|
||||||
if (thumbnail)
|
if (thumbnail)
|
||||||
|
|
@ -977,7 +977,7 @@ static void DrawInfoPanel()
|
||||||
desc = buf;
|
desc = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
desc += "\n\n" + g_selectedItem->GetValueDescription();
|
desc += "\n\n" + g_selectedItem->GetValueDescription(Config::Language);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto size = Scale(26.0f);
|
auto size = Scale(26.0f);
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ void Config::Load()
|
||||||
toml = toml::parse(tomlStream);
|
toml = toml::parse(tomlStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto def : Config::Definitions)
|
for (auto def : g_configDefinitions)
|
||||||
{
|
{
|
||||||
def->ReadValue(toml);
|
def->ReadValue(toml);
|
||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
|
|
@ -44,7 +44,7 @@ void Config::Save()
|
||||||
std::string result;
|
std::string result;
|
||||||
std::string section;
|
std::string section;
|
||||||
|
|
||||||
for (auto def : Config::Definitions)
|
for (auto def : g_configDefinitions)
|
||||||
{
|
{
|
||||||
auto isFirstSection = section.empty();
|
auto isFirstSection = section.empty();
|
||||||
auto isDefWithSection = section != def->GetSection();
|
auto isDefWithSection = section != def->GetSection();
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,592 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <user/config_detail.h>
|
#include <locale/locale.h>
|
||||||
#include <user/paths.h>
|
#include <user/paths.h>
|
||||||
#include <exports.h>
|
#include <exports.h>
|
||||||
|
|
||||||
|
class IConfigDef
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IConfigDef() = default;
|
||||||
|
virtual void ReadValue(toml::v3::ex::parse_result& toml) = 0;
|
||||||
|
virtual void MakeDefault() = 0;
|
||||||
|
virtual std::string_view GetSection() const = 0;
|
||||||
|
virtual std::string_view GetName() const = 0;
|
||||||
|
virtual std::string GetNameLocalised(ELanguage language) const = 0;
|
||||||
|
virtual std::string GetDescription(ELanguage language) const = 0;
|
||||||
|
virtual bool IsDefaultValue() const = 0;
|
||||||
|
virtual const void* GetValue() const = 0;
|
||||||
|
virtual std::string GetValueLocalised(ELanguage language) const = 0;
|
||||||
|
virtual std::string GetValueDescription(ELanguage language) const = 0;
|
||||||
|
virtual std::string GetDefinition(bool withSection = false) const = 0;
|
||||||
|
virtual std::string ToString(bool strWithQuotes = true) const = 0;
|
||||||
|
virtual void GetLocaleStrings(std::vector<std::string_view>& localeStrings) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define CONFIG_LOCALE std::unordered_map<ELanguage, std::tuple<std::string, std::string>>
|
||||||
|
#define CONFIG_ENUM_LOCALE(type) std::unordered_map<ELanguage, std::unordered_map<type, std::tuple<std::string, std::string>>>
|
||||||
|
|
||||||
|
#define CONFIG_DEFINE(section, type, name, defaultValue) \
|
||||||
|
static inline ConfigDef<type> name{section, #name, defaultValue};
|
||||||
|
|
||||||
|
#define CONFIG_DEFINE_LOCALISED(section, type, name, defaultValue) \
|
||||||
|
static CONFIG_LOCALE g_##name##_locale; \
|
||||||
|
static inline ConfigDef<type> name{section, #name, &g_##name##_locale, defaultValue};
|
||||||
|
|
||||||
|
#define CONFIG_DEFINE_ENUM(section, type, name, defaultValue) \
|
||||||
|
static inline ConfigDef<type> name{section, #name, defaultValue, &g_##type##_template};
|
||||||
|
|
||||||
|
#define CONFIG_DEFINE_ENUM_LOCALISED(section, type, name, defaultValue) \
|
||||||
|
static CONFIG_LOCALE g_##name##_locale; \
|
||||||
|
static CONFIG_ENUM_LOCALE(type) g_##type##_locale; \
|
||||||
|
static inline ConfigDef<type> name{section, #name, &g_##name##_locale, defaultValue, &g_##type##_template, &g_##type##_locale};
|
||||||
|
|
||||||
|
#define CONFIG_DEFINE_CALLBACK(section, type, name, defaultValue, readCallback) \
|
||||||
|
static CONFIG_LOCALE g_##name##_locale; \
|
||||||
|
static inline ConfigDef<type> name{section, #name, defaultValue, [](ConfigDef<type>* def) readCallback};
|
||||||
|
|
||||||
|
#define CONFIG_DEFINE_ENUM_TEMPLATE(type) \
|
||||||
|
inline std::unordered_map<std::string, type> g_##type##_template =
|
||||||
|
|
||||||
|
#define WINDOWPOS_CENTRED 0x2FFF0000
|
||||||
|
|
||||||
|
static inline std::vector<IConfigDef*> g_configDefinitions{};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(ELanguage)
|
||||||
|
{
|
||||||
|
{ "English", ELanguage::English },
|
||||||
|
{ "Japanese", ELanguage::Japanese },
|
||||||
|
{ "German", ELanguage::German },
|
||||||
|
{ "French", ELanguage::French },
|
||||||
|
{ "Spanish", ELanguage::Spanish },
|
||||||
|
{ "Italian", ELanguage::Italian }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class EUnleashGaugeBehaviour : uint32_t
|
||||||
|
{
|
||||||
|
Original,
|
||||||
|
Revised
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(EUnleashGaugeBehaviour)
|
||||||
|
{
|
||||||
|
{ "Original", EUnleashGaugeBehaviour::Original },
|
||||||
|
{ "Revised", EUnleashGaugeBehaviour::Revised }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class ETimeOfDayTransition : uint32_t
|
||||||
|
{
|
||||||
|
Xbox,
|
||||||
|
PlayStation
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(ETimeOfDayTransition)
|
||||||
|
{
|
||||||
|
{ "Xbox", ETimeOfDayTransition::Xbox },
|
||||||
|
{ "PlayStation", ETimeOfDayTransition::PlayStation }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class EControllerIcons : uint32_t
|
||||||
|
{
|
||||||
|
Auto,
|
||||||
|
Xbox,
|
||||||
|
PlayStation
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(EControllerIcons)
|
||||||
|
{
|
||||||
|
{ "Auto", EControllerIcons::Auto },
|
||||||
|
{ "Xbox", EControllerIcons::Xbox },
|
||||||
|
{ "PlayStation", EControllerIcons::PlayStation }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class EVoiceLanguage : uint32_t
|
||||||
|
{
|
||||||
|
English,
|
||||||
|
Japanese
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(EVoiceLanguage)
|
||||||
|
{
|
||||||
|
{ "English", EVoiceLanguage::English },
|
||||||
|
{ "Japanese", EVoiceLanguage::Japanese }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class EGraphicsAPI : uint32_t
|
||||||
|
{
|
||||||
|
#ifdef SWA_D3D12
|
||||||
|
D3D12,
|
||||||
|
#endif
|
||||||
|
Vulkan
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(EGraphicsAPI)
|
||||||
|
{
|
||||||
|
#ifdef SWA_D3D12
|
||||||
|
{ "D3D12", EGraphicsAPI::D3D12 },
|
||||||
|
#endif
|
||||||
|
{ "Vulkan", EGraphicsAPI::Vulkan }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class EWindowState : uint32_t
|
||||||
|
{
|
||||||
|
Normal,
|
||||||
|
Maximised
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(EWindowState)
|
||||||
|
{
|
||||||
|
{ "Normal", EWindowState::Normal },
|
||||||
|
{ "Maximised", EWindowState::Maximised },
|
||||||
|
{ "Maximized", EWindowState::Maximised }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class EAspectRatio : uint32_t
|
||||||
|
{
|
||||||
|
Auto,
|
||||||
|
Square,
|
||||||
|
Widescreen
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(EAspectRatio)
|
||||||
|
{
|
||||||
|
{ "Auto", EAspectRatio::Auto },
|
||||||
|
{ "4:3", EAspectRatio::Square },
|
||||||
|
{ "16:9", EAspectRatio::Widescreen }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class ETripleBuffering : uint32_t
|
||||||
|
{
|
||||||
|
Auto,
|
||||||
|
On,
|
||||||
|
Off
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(ETripleBuffering)
|
||||||
|
{
|
||||||
|
{ "Auto", ETripleBuffering::Auto },
|
||||||
|
{ "On", ETripleBuffering::On },
|
||||||
|
{ "Off", ETripleBuffering::Off }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class EAntiAliasing : uint32_t
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
MSAA2x = 2,
|
||||||
|
MSAA4x = 4,
|
||||||
|
MSAA8x = 8
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(EAntiAliasing)
|
||||||
|
{
|
||||||
|
{ "None", EAntiAliasing::None },
|
||||||
|
{ "2x MSAA", EAntiAliasing::MSAA2x },
|
||||||
|
{ "4x MSAA", EAntiAliasing::MSAA4x },
|
||||||
|
{ "8x MSAA", EAntiAliasing::MSAA8x }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class EShadowResolution : int32_t
|
||||||
|
{
|
||||||
|
Original = -1,
|
||||||
|
x512 = 512,
|
||||||
|
x1024 = 1024,
|
||||||
|
x2048 = 2048,
|
||||||
|
x4096 = 4096,
|
||||||
|
x8192 = 8192
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(EShadowResolution)
|
||||||
|
{
|
||||||
|
{ "Original", EShadowResolution::Original },
|
||||||
|
{ "512", EShadowResolution::x512 },
|
||||||
|
{ "1024", EShadowResolution::x1024 },
|
||||||
|
{ "2048", EShadowResolution::x2048 },
|
||||||
|
{ "4096", EShadowResolution::x4096 },
|
||||||
|
{ "8192", EShadowResolution::x8192 },
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class EGITextureFiltering : uint32_t
|
||||||
|
{
|
||||||
|
Bilinear,
|
||||||
|
Bicubic
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(EGITextureFiltering)
|
||||||
|
{
|
||||||
|
{ "Bilinear", EGITextureFiltering::Bilinear },
|
||||||
|
{ "Bicubic", EGITextureFiltering::Bicubic }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class EDepthOfFieldQuality : uint32_t
|
||||||
|
{
|
||||||
|
Auto,
|
||||||
|
Low,
|
||||||
|
Medium,
|
||||||
|
High,
|
||||||
|
Ultra
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(EDepthOfFieldQuality)
|
||||||
|
{
|
||||||
|
{ "Auto", EDepthOfFieldQuality::Auto },
|
||||||
|
{ "Low", EDepthOfFieldQuality::Low },
|
||||||
|
{ "Medium", EDepthOfFieldQuality::Medium },
|
||||||
|
{ "High", EDepthOfFieldQuality::High },
|
||||||
|
{ "Ultra", EDepthOfFieldQuality::Ultra }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class EMotionBlur : uint32_t
|
||||||
|
{
|
||||||
|
Off,
|
||||||
|
Original,
|
||||||
|
Enhanced
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(EMotionBlur)
|
||||||
|
{
|
||||||
|
{ "Off", EMotionBlur::Off },
|
||||||
|
{ "Original", EMotionBlur::Original },
|
||||||
|
{ "Enhanced", EMotionBlur::Enhanced }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class EMovieScaleMode : uint32_t
|
||||||
|
{
|
||||||
|
Stretch,
|
||||||
|
Fit,
|
||||||
|
Fill
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(EMovieScaleMode)
|
||||||
|
{
|
||||||
|
{ "Stretch", EMovieScaleMode::Stretch },
|
||||||
|
{ "Fit", EMovieScaleMode::Fit },
|
||||||
|
{ "Fill", EMovieScaleMode::Fill }
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class EUIScaleMode : uint32_t
|
||||||
|
{
|
||||||
|
Stretch,
|
||||||
|
Edge,
|
||||||
|
Centre
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_ENUM_TEMPLATE(EUIScaleMode)
|
||||||
|
{
|
||||||
|
{ "Stretch", EUIScaleMode::Stretch },
|
||||||
|
{ "Edge", EUIScaleMode::Edge },
|
||||||
|
{ "Centre", EUIScaleMode::Centre },
|
||||||
|
{ "Center", EUIScaleMode::Centre }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class ConfigDef final : public IConfigDef
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string Section{};
|
||||||
|
std::string Name{};
|
||||||
|
CONFIG_LOCALE* Locale{};
|
||||||
|
T DefaultValue{};
|
||||||
|
T Value{ DefaultValue };
|
||||||
|
std::unordered_map<std::string, T>* EnumTemplate;
|
||||||
|
std::map<T, std::string> EnumTemplateReverse{};
|
||||||
|
CONFIG_ENUM_LOCALE(T)* EnumLocale{};
|
||||||
|
std::function<void(ConfigDef<T>*)> Callback;
|
||||||
|
|
||||||
|
// CONFIG_DEFINE
|
||||||
|
ConfigDef(std::string section, std::string name, T defaultValue) : Section(section), Name(name), DefaultValue(defaultValue)
|
||||||
|
{
|
||||||
|
g_configDefinitions.emplace_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// CONFIG_DEFINE_LOCALISED
|
||||||
|
ConfigDef(std::string section, std::string name, CONFIG_LOCALE* nameLocale, T defaultValue) : Section(section), Name(name), Locale(nameLocale), DefaultValue(defaultValue)
|
||||||
|
{
|
||||||
|
g_configDefinitions.emplace_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// CONFIG_DEFINE_ENUM
|
||||||
|
ConfigDef(std::string section, std::string name, T defaultValue, std::unordered_map<std::string, T>* enumTemplate) : Section(section), Name(name), DefaultValue(defaultValue), EnumTemplate(enumTemplate)
|
||||||
|
{
|
||||||
|
for (const auto& pair : *EnumTemplate)
|
||||||
|
EnumTemplateReverse[pair.second] = pair.first;
|
||||||
|
|
||||||
|
g_configDefinitions.emplace_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// CONFIG_DEFINE_ENUM_LOCALISED
|
||||||
|
ConfigDef(std::string section, std::string name, CONFIG_LOCALE* nameLocale, T defaultValue, std::unordered_map<std::string, T>* enumTemplate, CONFIG_ENUM_LOCALE(T)* enumLocale) : Section(section), Name(name), Locale(nameLocale), DefaultValue(defaultValue), EnumTemplate(enumTemplate), EnumLocale(enumLocale)
|
||||||
|
{
|
||||||
|
for (const auto& pair : *EnumTemplate)
|
||||||
|
EnumTemplateReverse[pair.second] = pair.first;
|
||||||
|
|
||||||
|
g_configDefinitions.emplace_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// CONFIG_DEFINE_CALLBACK
|
||||||
|
ConfigDef(std::string section, std::string name, T defaultValue, std::function<void(ConfigDef<T>*)> callback) : Section(section), Name(name), DefaultValue(defaultValue), Callback(callback)
|
||||||
|
{
|
||||||
|
g_configDefinitions.emplace_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReadValue(toml::v3::ex::parse_result& toml) override
|
||||||
|
{
|
||||||
|
if (auto pSection = toml[Section].as_table())
|
||||||
|
{
|
||||||
|
const auto& section = *pSection;
|
||||||
|
|
||||||
|
if constexpr (std::is_same<T, std::string>::value)
|
||||||
|
{
|
||||||
|
Value = section[Name].value_or<std::string>(DefaultValue);
|
||||||
|
}
|
||||||
|
else if constexpr (std::is_enum_v<T>)
|
||||||
|
{
|
||||||
|
std::string value = section[Name].value_or(std::string());
|
||||||
|
auto it = EnumTemplate->find(value);
|
||||||
|
if (it != EnumTemplate->end())
|
||||||
|
{
|
||||||
|
Value = it->second;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Value = DefaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Value = section[Name].value_or(DefaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Callback)
|
||||||
|
Callback(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MakeDefault() override
|
||||||
|
{
|
||||||
|
Value = DefaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string_view GetSection() const override
|
||||||
|
{
|
||||||
|
return Section;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string_view GetName() const override
|
||||||
|
{
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetNameLocalised(ELanguage language) const override
|
||||||
|
{
|
||||||
|
if (!Locale)
|
||||||
|
return Name;
|
||||||
|
|
||||||
|
if (!Locale->count(language))
|
||||||
|
{
|
||||||
|
if (Locale->count(ELanguage::English))
|
||||||
|
{
|
||||||
|
return std::get<0>(Locale->at(ELanguage::English));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::get<0>(Locale->at(language));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetDescription(ELanguage language) const override
|
||||||
|
{
|
||||||
|
if (!Locale)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
if (!Locale->count(language))
|
||||||
|
{
|
||||||
|
if (Locale->count(ELanguage::English))
|
||||||
|
{
|
||||||
|
return std::get<1>(Locale->at(ELanguage::English));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::get<1>(Locale->at(language));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsDefaultValue() const override
|
||||||
|
{
|
||||||
|
return Value == DefaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const void* GetValue() const override
|
||||||
|
{
|
||||||
|
return &Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetValueLocalised(ELanguage language) const override
|
||||||
|
{
|
||||||
|
CONFIG_ENUM_LOCALE(T)* locale = nullptr;
|
||||||
|
|
||||||
|
if constexpr (std::is_enum_v<T>)
|
||||||
|
{
|
||||||
|
locale = EnumLocale;
|
||||||
|
}
|
||||||
|
else if constexpr (std::is_same_v<T, bool>)
|
||||||
|
{
|
||||||
|
return Value
|
||||||
|
? Localise("Common_On")
|
||||||
|
: Localise("Common_Off");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!locale)
|
||||||
|
return ToString(false);
|
||||||
|
|
||||||
|
if (!locale->count(language))
|
||||||
|
{
|
||||||
|
if (locale->count(ELanguage::English))
|
||||||
|
{
|
||||||
|
language = ELanguage::English;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ToString(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto strings = locale->at(language);
|
||||||
|
|
||||||
|
if (!strings.count(Value))
|
||||||
|
return ToString(false);
|
||||||
|
|
||||||
|
return std::get<0>(strings.at(Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetValueDescription(ELanguage language) const override
|
||||||
|
{
|
||||||
|
CONFIG_ENUM_LOCALE(T)* locale = nullptr;
|
||||||
|
|
||||||
|
if constexpr (std::is_enum_v<T>)
|
||||||
|
{
|
||||||
|
locale = EnumLocale;
|
||||||
|
}
|
||||||
|
else if constexpr (std::is_same_v<T, bool>)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!locale)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
if (!locale->count(language))
|
||||||
|
{
|
||||||
|
if (locale->count(ELanguage::English))
|
||||||
|
{
|
||||||
|
language = ELanguage::English;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto strings = locale->at(language);
|
||||||
|
|
||||||
|
if (!strings.count(Value))
|
||||||
|
return "";
|
||||||
|
|
||||||
|
return std::get<1>(strings.at(Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetDefinition(bool withSection = false) const override
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
|
||||||
|
if (withSection)
|
||||||
|
result += "[" + Section + "]\n";
|
||||||
|
|
||||||
|
result += Name + " = " + ToString();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ToString(bool strWithQuotes = true) const override
|
||||||
|
{
|
||||||
|
std::string result = "N/A";
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<T, std::string>)
|
||||||
|
{
|
||||||
|
result = fmt::format("{}", Value);
|
||||||
|
|
||||||
|
if (strWithQuotes)
|
||||||
|
result = fmt::format("\"{}\"", result);
|
||||||
|
}
|
||||||
|
else if constexpr (std::is_enum_v<T>)
|
||||||
|
{
|
||||||
|
auto it = EnumTemplateReverse.find(Value);
|
||||||
|
|
||||||
|
if (it != EnumTemplateReverse.end())
|
||||||
|
result = fmt::format("{}", it->second);
|
||||||
|
|
||||||
|
if (strWithQuotes)
|
||||||
|
result = fmt::format("\"{}\"", result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = fmt::format("{}", Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetLocaleStrings(std::vector<std::string_view>& localeStrings) const override
|
||||||
|
{
|
||||||
|
if (Locale != nullptr)
|
||||||
|
{
|
||||||
|
for (auto& [language, nameAndDesc] : *Locale)
|
||||||
|
{
|
||||||
|
localeStrings.push_back(std::get<0>(nameAndDesc));
|
||||||
|
localeStrings.push_back(std::get<1>(nameAndDesc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EnumLocale != nullptr)
|
||||||
|
{
|
||||||
|
for (auto& [language, locale] : *EnumLocale)
|
||||||
|
{
|
||||||
|
for (auto& [value, nameAndDesc] : locale)
|
||||||
|
{
|
||||||
|
localeStrings.push_back(std::get<0>(nameAndDesc));
|
||||||
|
localeStrings.push_back(std::get<1>(nameAndDesc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigDef& operator=(const ConfigDef& other)
|
||||||
|
{
|
||||||
|
if (this != &other)
|
||||||
|
Value = other.Value;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator T() const
|
||||||
|
{
|
||||||
|
return Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator=(const T& other)
|
||||||
|
{
|
||||||
|
Value = other;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class Config
|
class Config
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static inline std::vector<IConfigDef*> Definitions{};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_LOCALISED("System", ELanguage, Language, ELanguage::English);
|
CONFIG_DEFINE_ENUM_LOCALISED("System", ELanguage, Language, ELanguage::English);
|
||||||
CONFIG_DEFINE_LOCALISED("System", bool, Hints, true);
|
CONFIG_DEFINE_LOCALISED("System", bool, Hints, true);
|
||||||
CONFIG_DEFINE_LOCALISED("System", bool, ControlTutorial, true);
|
CONFIG_DEFINE_LOCALISED("System", bool, ControlTutorial, true);
|
||||||
|
|
@ -84,4 +662,4 @@ public:
|
||||||
|
|
||||||
static void Load();
|
static void Load();
|
||||||
static void Save();
|
static void Save();
|
||||||
};
|
};
|
||||||
|
|
@ -1,193 +0,0 @@
|
||||||
#include "config.h"
|
|
||||||
#include "config_detail.h"
|
|
||||||
#include <locale/locale.h>
|
|
||||||
|
|
||||||
// CONFIG_DEFINE
|
|
||||||
template<typename T>
|
|
||||||
ConfigDef<T>::ConfigDef(std::string section, std::string name, T defaultValue) : Section(section), Name(name), DefaultValue(defaultValue)
|
|
||||||
{
|
|
||||||
Config::Definitions.emplace_back(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// CONFIG_DEFINE_LOCALISED
|
|
||||||
template<typename T>
|
|
||||||
ConfigDef<T>::ConfigDef(std::string section, std::string name, CONFIG_LOCALE* locale, T defaultValue)
|
|
||||||
: Section(section), Name(name), Locale(locale), DefaultValue(defaultValue)
|
|
||||||
{
|
|
||||||
Config::Definitions.emplace_back(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// CONFIG_DEFINE_ENUM
|
|
||||||
template<typename T>
|
|
||||||
ConfigDef<T>::ConfigDef(std::string section, std::string name, T defaultValue, std::unordered_map<std::string, T>* enumTemplate)
|
|
||||||
: Section(section), Name(name), DefaultValue(defaultValue), EnumTemplate(enumTemplate)
|
|
||||||
{
|
|
||||||
for (const auto& pair : *EnumTemplate)
|
|
||||||
EnumTemplateReverse[pair.second] = pair.first;
|
|
||||||
|
|
||||||
Config::Definitions.emplace_back(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// CONFIG_DEFINE_ENUM_LOCALISED
|
|
||||||
template<typename T>
|
|
||||||
ConfigDef<T>::ConfigDef(std::string section, std::string name, CONFIG_LOCALE* locale, T defaultValue, std::unordered_map<std::string, T>* enumTemplate, CONFIG_ENUM_LOCALE(T)* enumLocale)
|
|
||||||
: Section(section), Name(name), Locale(locale), DefaultValue(defaultValue), EnumTemplate(enumTemplate), EnumLocale(enumLocale)
|
|
||||||
{
|
|
||||||
for (const auto& pair : *EnumTemplate)
|
|
||||||
EnumTemplateReverse[pair.second] = pair.first;
|
|
||||||
|
|
||||||
Config::Definitions.emplace_back(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// CONFIG_DEFINE_CALLBACK
|
|
||||||
template<typename T>
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
std::string ConfigDef<T>::GetNameLocalised() const
|
|
||||||
{
|
|
||||||
if (!Locale)
|
|
||||||
return Name;
|
|
||||||
|
|
||||||
if (!Locale->count(Config::Language))
|
|
||||||
{
|
|
||||||
if (Locale->count(ELanguage::English))
|
|
||||||
{
|
|
||||||
return std::get<0>(Locale->at(ELanguage::English));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::get<0>(Locale->at(Config::Language));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
std::string ConfigDef<T>::GetDescription() const
|
|
||||||
{
|
|
||||||
if (!Locale)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
if (!Locale->count(Config::Language))
|
|
||||||
{
|
|
||||||
if (Locale->count(ELanguage::English))
|
|
||||||
{
|
|
||||||
return std::get<1>(Locale->at(ELanguage::English));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::get<1>(Locale->at(Config::Language));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
std::string ConfigDef<T>::GetValueLocalised() const
|
|
||||||
{
|
|
||||||
auto language = Config::Language;
|
|
||||||
CONFIG_ENUM_LOCALE(T)* locale = nullptr;
|
|
||||||
|
|
||||||
if constexpr (std::is_enum_v<T>)
|
|
||||||
{
|
|
||||||
locale = EnumLocale;
|
|
||||||
}
|
|
||||||
else if constexpr (std::is_same_v<T, bool>)
|
|
||||||
{
|
|
||||||
return Value
|
|
||||||
? Localise("Common_On")
|
|
||||||
: Localise("Common_Off");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!locale)
|
|
||||||
return ToString(false);
|
|
||||||
|
|
||||||
if (!locale->count(language))
|
|
||||||
{
|
|
||||||
if (locale->count(ELanguage::English))
|
|
||||||
{
|
|
||||||
language = ELanguage::English;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return ToString(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto strings = locale->at(language);
|
|
||||||
|
|
||||||
if (!strings.count(Value))
|
|
||||||
return ToString(false);
|
|
||||||
|
|
||||||
return std::get<0>(strings.at(Value));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
std::string ConfigDef<T>::GetValueDescription() const
|
|
||||||
{
|
|
||||||
auto language = Config::Language;
|
|
||||||
CONFIG_ENUM_LOCALE(T)* locale = nullptr;
|
|
||||||
|
|
||||||
if constexpr (std::is_enum_v<T>)
|
|
||||||
{
|
|
||||||
locale = EnumLocale;
|
|
||||||
}
|
|
||||||
else if constexpr (std::is_same_v<T, bool>)
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!locale)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
if (!locale->count(language))
|
|
||||||
{
|
|
||||||
if (locale->count(ELanguage::English))
|
|
||||||
{
|
|
||||||
language = ELanguage::English;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto strings = locale->at(language);
|
|
||||||
|
|
||||||
if (!strings.count(Value))
|
|
||||||
return "";
|
|
||||||
|
|
||||||
return std::get<1>(strings.at(Value));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline void ConfigDef<T>::GetLocaleStrings(std::vector<std::string_view>& localeStrings) const
|
|
||||||
{
|
|
||||||
if (Locale != nullptr)
|
|
||||||
{
|
|
||||||
for (auto& [language, nameAndDesc] : *Locale)
|
|
||||||
{
|
|
||||||
localeStrings.push_back(std::get<0>(nameAndDesc));
|
|
||||||
localeStrings.push_back(std::get<1>(nameAndDesc));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EnumLocale != nullptr)
|
|
||||||
{
|
|
||||||
for (auto& [language, locale] : *EnumLocale)
|
|
||||||
{
|
|
||||||
for (auto& [value, nameAndDesc] : locale)
|
|
||||||
{
|
|
||||||
localeStrings.push_back(std::get<0>(nameAndDesc));
|
|
||||||
localeStrings.push_back(std::get<1>(nameAndDesc));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,440 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#define CONFIG_LOCALE std::unordered_map<ELanguage, std::tuple<std::string, std::string>>
|
|
||||||
#define CONFIG_ENUM_LOCALE(type) std::unordered_map<ELanguage, std::unordered_map<type, std::tuple<std::string, std::string>>>
|
|
||||||
|
|
||||||
#define CONFIG_DEFINE(section, type, name, defaultValue) \
|
|
||||||
static inline ConfigDef<type> name{section, #name, defaultValue};
|
|
||||||
|
|
||||||
#define CONFIG_DEFINE_LOCALISED(section, type, name, defaultValue) \
|
|
||||||
static CONFIG_LOCALE g_##name##_locale; \
|
|
||||||
static inline ConfigDef<type> name{section, #name, &g_##name##_locale, defaultValue};
|
|
||||||
|
|
||||||
#define CONFIG_DEFINE_ENUM(section, type, name, defaultValue) \
|
|
||||||
static inline ConfigDef<type> name{section, #name, defaultValue, &g_##type##_template};
|
|
||||||
|
|
||||||
#define CONFIG_DEFINE_ENUM_LOCALISED(section, type, name, defaultValue) \
|
|
||||||
static CONFIG_LOCALE g_##name##_locale; \
|
|
||||||
static CONFIG_ENUM_LOCALE(type) g_##type##_locale; \
|
|
||||||
static inline ConfigDef<type> name{section, #name, &g_##name##_locale, defaultValue, &g_##type##_template, &g_##type##_locale};
|
|
||||||
|
|
||||||
#define CONFIG_DEFINE_CALLBACK(section, type, name, defaultValue, readCallback) \
|
|
||||||
static CONFIG_LOCALE g_##name##_locale; \
|
|
||||||
static inline ConfigDef<type> name{section, #name, defaultValue, [](ConfigDef<type>* def) readCallback};
|
|
||||||
|
|
||||||
#define CONFIG_DEFINE_ENUM_TEMPLATE(type) \
|
|
||||||
inline std::unordered_map<std::string, type> g_##type##_template =
|
|
||||||
|
|
||||||
#define WINDOWPOS_CENTRED 0x2FFF0000
|
|
||||||
|
|
||||||
enum class ELanguage : uint32_t
|
|
||||||
{
|
|
||||||
English = 1,
|
|
||||||
Japanese,
|
|
||||||
German,
|
|
||||||
French,
|
|
||||||
Spanish,
|
|
||||||
Italian
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(ELanguage)
|
|
||||||
{
|
|
||||||
{ "English", ELanguage::English },
|
|
||||||
{ "Japanese", ELanguage::Japanese },
|
|
||||||
{ "German", ELanguage::German },
|
|
||||||
{ "French", ELanguage::French },
|
|
||||||
{ "Spanish", ELanguage::Spanish },
|
|
||||||
{ "Italian", ELanguage::Italian }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EUnleashGaugeBehaviour : uint32_t
|
|
||||||
{
|
|
||||||
Original,
|
|
||||||
Revised
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(EUnleashGaugeBehaviour)
|
|
||||||
{
|
|
||||||
{ "Original", EUnleashGaugeBehaviour::Original },
|
|
||||||
{ "Revised", EUnleashGaugeBehaviour::Revised }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ETimeOfDayTransition : uint32_t
|
|
||||||
{
|
|
||||||
Xbox,
|
|
||||||
PlayStation
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(ETimeOfDayTransition)
|
|
||||||
{
|
|
||||||
{ "Xbox", ETimeOfDayTransition::Xbox },
|
|
||||||
{ "PlayStation", ETimeOfDayTransition::PlayStation }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EControllerIcons : uint32_t
|
|
||||||
{
|
|
||||||
Auto,
|
|
||||||
Xbox,
|
|
||||||
PlayStation
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(EControllerIcons)
|
|
||||||
{
|
|
||||||
{ "Auto", EControllerIcons::Auto },
|
|
||||||
{ "Xbox", EControllerIcons::Xbox },
|
|
||||||
{ "PlayStation", EControllerIcons::PlayStation }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EVoiceLanguage : uint32_t
|
|
||||||
{
|
|
||||||
English,
|
|
||||||
Japanese
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(EVoiceLanguage)
|
|
||||||
{
|
|
||||||
{ "English", EVoiceLanguage::English },
|
|
||||||
{ "Japanese", EVoiceLanguage::Japanese }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EGraphicsAPI : uint32_t
|
|
||||||
{
|
|
||||||
#ifdef SWA_D3D12
|
|
||||||
D3D12,
|
|
||||||
#endif
|
|
||||||
Vulkan
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(EGraphicsAPI)
|
|
||||||
{
|
|
||||||
#ifdef SWA_D3D12
|
|
||||||
{ "D3D12", EGraphicsAPI::D3D12 },
|
|
||||||
#endif
|
|
||||||
{ "Vulkan", EGraphicsAPI::Vulkan }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EWindowState : uint32_t
|
|
||||||
{
|
|
||||||
Normal,
|
|
||||||
Maximised
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(EWindowState)
|
|
||||||
{
|
|
||||||
{ "Normal", EWindowState::Normal },
|
|
||||||
{ "Maximised", EWindowState::Maximised },
|
|
||||||
{ "Maximized", EWindowState::Maximised }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EAspectRatio : uint32_t
|
|
||||||
{
|
|
||||||
Auto,
|
|
||||||
Square,
|
|
||||||
Widescreen
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(EAspectRatio)
|
|
||||||
{
|
|
||||||
{ "Auto", EAspectRatio::Auto },
|
|
||||||
{ "4:3", EAspectRatio::Square },
|
|
||||||
{ "16:9", EAspectRatio::Widescreen }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ETripleBuffering : uint32_t
|
|
||||||
{
|
|
||||||
Auto,
|
|
||||||
On,
|
|
||||||
Off
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(ETripleBuffering)
|
|
||||||
{
|
|
||||||
{ "Auto", ETripleBuffering::Auto },
|
|
||||||
{ "On", ETripleBuffering::On },
|
|
||||||
{ "Off", ETripleBuffering::Off }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EAntiAliasing : uint32_t
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
MSAA2x = 2,
|
|
||||||
MSAA4x = 4,
|
|
||||||
MSAA8x = 8
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(EAntiAliasing)
|
|
||||||
{
|
|
||||||
{ "None", EAntiAliasing::None },
|
|
||||||
{ "2x MSAA", EAntiAliasing::MSAA2x },
|
|
||||||
{ "4x MSAA", EAntiAliasing::MSAA4x },
|
|
||||||
{ "8x MSAA", EAntiAliasing::MSAA8x }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EShadowResolution : int32_t
|
|
||||||
{
|
|
||||||
Original = -1,
|
|
||||||
x512 = 512,
|
|
||||||
x1024 = 1024,
|
|
||||||
x2048 = 2048,
|
|
||||||
x4096 = 4096,
|
|
||||||
x8192 = 8192
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(EShadowResolution)
|
|
||||||
{
|
|
||||||
{ "Original", EShadowResolution::Original },
|
|
||||||
{ "512", EShadowResolution::x512 },
|
|
||||||
{ "1024", EShadowResolution::x1024 },
|
|
||||||
{ "2048", EShadowResolution::x2048 },
|
|
||||||
{ "4096", EShadowResolution::x4096 },
|
|
||||||
{ "8192", EShadowResolution::x8192 },
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EGITextureFiltering : uint32_t
|
|
||||||
{
|
|
||||||
Bilinear,
|
|
||||||
Bicubic
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(EGITextureFiltering)
|
|
||||||
{
|
|
||||||
{ "Bilinear", EGITextureFiltering::Bilinear },
|
|
||||||
{ "Bicubic", EGITextureFiltering::Bicubic }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EDepthOfFieldQuality : uint32_t
|
|
||||||
{
|
|
||||||
Auto,
|
|
||||||
Low,
|
|
||||||
Medium,
|
|
||||||
High,
|
|
||||||
Ultra
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(EDepthOfFieldQuality)
|
|
||||||
{
|
|
||||||
{ "Auto", EDepthOfFieldQuality::Auto },
|
|
||||||
{ "Low", EDepthOfFieldQuality::Low },
|
|
||||||
{ "Medium", EDepthOfFieldQuality::Medium },
|
|
||||||
{ "High", EDepthOfFieldQuality::High },
|
|
||||||
{ "Ultra", EDepthOfFieldQuality::Ultra }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EMotionBlur : uint32_t
|
|
||||||
{
|
|
||||||
Off,
|
|
||||||
Original,
|
|
||||||
Enhanced
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(EMotionBlur)
|
|
||||||
{
|
|
||||||
{ "Off", EMotionBlur::Off },
|
|
||||||
{ "Original", EMotionBlur::Original },
|
|
||||||
{ "Enhanced", EMotionBlur::Enhanced }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EMovieScaleMode : uint32_t
|
|
||||||
{
|
|
||||||
Stretch,
|
|
||||||
Fit,
|
|
||||||
Fill
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(EMovieScaleMode)
|
|
||||||
{
|
|
||||||
{ "Stretch", EMovieScaleMode::Stretch },
|
|
||||||
{ "Fit", EMovieScaleMode::Fit },
|
|
||||||
{ "Fill", EMovieScaleMode::Fill }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EUIScaleMode : uint32_t
|
|
||||||
{
|
|
||||||
Stretch,
|
|
||||||
Edge,
|
|
||||||
Centre
|
|
||||||
};
|
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM_TEMPLATE(EUIScaleMode)
|
|
||||||
{
|
|
||||||
{ "Stretch", EUIScaleMode::Stretch },
|
|
||||||
{ "Edge", EUIScaleMode::Edge },
|
|
||||||
{ "Centre", EUIScaleMode::Centre },
|
|
||||||
{ "Center", EUIScaleMode::Centre }
|
|
||||||
};
|
|
||||||
|
|
||||||
class IConfigDef
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~IConfigDef() = default;
|
|
||||||
virtual void ReadValue(toml::v3::ex::parse_result& toml) = 0;
|
|
||||||
virtual void MakeDefault() = 0;
|
|
||||||
virtual std::string_view GetSection() const = 0;
|
|
||||||
virtual std::string_view GetName() const = 0;
|
|
||||||
virtual std::string GetNameLocalised() const = 0;
|
|
||||||
virtual std::string GetDescription() const = 0;
|
|
||||||
virtual bool IsDefaultValue() const = 0;
|
|
||||||
virtual const void* GetValue() const = 0;
|
|
||||||
virtual std::string GetValueLocalised() const = 0;
|
|
||||||
virtual std::string GetValueDescription() const = 0;
|
|
||||||
virtual std::string GetDefinition(bool withSection = false) const = 0;
|
|
||||||
virtual std::string ToString(bool strWithQuotes = true) const = 0;
|
|
||||||
virtual void GetLocaleStrings(std::vector<std::string_view>& localeStrings) const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class ConfigDef final : public IConfigDef
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string Section{};
|
|
||||||
std::string Name{};
|
|
||||||
CONFIG_LOCALE* Locale{};
|
|
||||||
T DefaultValue{};
|
|
||||||
T Value{ DefaultValue };
|
|
||||||
std::unordered_map<std::string, T>* EnumTemplate;
|
|
||||||
std::map<T, std::string> EnumTemplateReverse{};
|
|
||||||
CONFIG_ENUM_LOCALE(T)* EnumLocale{};
|
|
||||||
std::function<void(ConfigDef<T>*)> Callback;
|
|
||||||
|
|
||||||
// CONFIG_DEFINE
|
|
||||||
ConfigDef(std::string section, std::string name, T defaultValue);
|
|
||||||
|
|
||||||
// CONFIG_DEFINE_LOCALISED
|
|
||||||
ConfigDef(std::string section, std::string name, CONFIG_LOCALE* nameLocale, T defaultValue);
|
|
||||||
|
|
||||||
// CONFIG_DEFINE_ENUM
|
|
||||||
ConfigDef(std::string section, std::string name, T defaultValue, std::unordered_map<std::string, T>* enumTemplate);
|
|
||||||
|
|
||||||
// CONFIG_DEFINE_ENUM_LOCALISED
|
|
||||||
ConfigDef(std::string section, std::string name, CONFIG_LOCALE* nameLocale, 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>*)> callback);
|
|
||||||
|
|
||||||
void ReadValue(toml::v3::ex::parse_result& toml) override
|
|
||||||
{
|
|
||||||
if (auto pSection = toml[Section].as_table())
|
|
||||||
{
|
|
||||||
const auto& section = *pSection;
|
|
||||||
|
|
||||||
if constexpr (std::is_same<T, std::string>::value)
|
|
||||||
{
|
|
||||||
Value = section[Name].value_or<std::string>(DefaultValue);
|
|
||||||
}
|
|
||||||
else if constexpr (std::is_enum_v<T>)
|
|
||||||
{
|
|
||||||
std::string value = section[Name].value_or(std::string());
|
|
||||||
auto it = EnumTemplate->find(value);
|
|
||||||
if (it != EnumTemplate->end())
|
|
||||||
{
|
|
||||||
Value = it->second;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Value = DefaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Value = section[Name].value_or(DefaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Callback)
|
|
||||||
Callback(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MakeDefault() override
|
|
||||||
{
|
|
||||||
Value = DefaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string_view GetSection() const override
|
|
||||||
{
|
|
||||||
return Section;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string_view GetName() const override
|
|
||||||
{
|
|
||||||
return Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetNameLocalised() const override;
|
|
||||||
|
|
||||||
std::string GetDescription() const override;
|
|
||||||
|
|
||||||
bool IsDefaultValue() const override
|
|
||||||
{
|
|
||||||
return Value == DefaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const void* GetValue() const override
|
|
||||||
{
|
|
||||||
return &Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetValueLocalised() const override;
|
|
||||||
|
|
||||||
std::string GetValueDescription() const override;
|
|
||||||
|
|
||||||
std::string GetDefinition(bool withSection = false) const override
|
|
||||||
{
|
|
||||||
std::string result;
|
|
||||||
|
|
||||||
if (withSection)
|
|
||||||
result += "[" + Section + "]\n";
|
|
||||||
|
|
||||||
result += Name + " = " + ToString();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ToString(bool strWithQuotes = true) const override
|
|
||||||
{
|
|
||||||
std::string result = "N/A";
|
|
||||||
|
|
||||||
if constexpr (std::is_same_v<T, std::string>)
|
|
||||||
{
|
|
||||||
result = fmt::format("{}", Value);
|
|
||||||
|
|
||||||
if (strWithQuotes)
|
|
||||||
result = fmt::format("\"{}\"", result);
|
|
||||||
}
|
|
||||||
else if constexpr (std::is_enum_v<T>)
|
|
||||||
{
|
|
||||||
auto it = EnumTemplateReverse.find(Value);
|
|
||||||
|
|
||||||
if (it != EnumTemplateReverse.end())
|
|
||||||
result = fmt::format("{}", it->second);
|
|
||||||
|
|
||||||
if (strWithQuotes)
|
|
||||||
result = fmt::format("\"{}\"", result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = fmt::format("{}", Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GetLocaleStrings(std::vector<std::string_view>& localeStrings) const override;
|
|
||||||
|
|
||||||
ConfigDef& operator=(const ConfigDef& other)
|
|
||||||
{
|
|
||||||
if (this != &other)
|
|
||||||
Value = other.Value;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator T() const
|
|
||||||
{
|
|
||||||
return Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator=(const T& other)
|
|
||||||
{
|
|
||||||
Value = other;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Loading…
Add table
Reference in a new issue