mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-01-06 03:29:55 -06:00
Cleanup some of the unordered_map usage. (#432)
This commit is contained in:
@@ -41,7 +41,7 @@
|
|||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
std::unordered_map<std::string, std::unordered_map<ELanguage, std::string>> g_locale =
|
std::unordered_map<std::string_view, std::unordered_map<ELanguage, std::string>> g_locale =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"Options_Header_Name",
|
"Options_Header_Name",
|
||||||
@@ -777,22 +777,18 @@ std::unordered_map<std::string, std::unordered_map<ELanguage, std::string>> g_lo
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string& Localise(const char* key)
|
std::string& Localise(const std::string_view& key)
|
||||||
{
|
{
|
||||||
if (!g_locale.count(key))
|
auto localeFindResult = g_locale.find(key);
|
||||||
return g_localeMissing;
|
if (localeFindResult != g_locale.end())
|
||||||
|
|
||||||
if (!g_locale[key].count(Config::Language))
|
|
||||||
{
|
{
|
||||||
if (g_locale[key].count(ELanguage::English))
|
auto languageFindResult = localeFindResult->second.find(Config::Language);
|
||||||
{
|
if (languageFindResult == localeFindResult->second.end())
|
||||||
return g_locale[key][ELanguage::English];
|
languageFindResult = localeFindResult->second.find(ELanguage::English);
|
||||||
}
|
|
||||||
else
|
if (languageFindResult != localeFindResult->second.end())
|
||||||
{
|
return languageFindResult->second;
|
||||||
return g_localeMissing;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return g_locale[key][Config::Language];
|
return g_localeMissing;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ enum class ELanguage : uint32_t
|
|||||||
|
|
||||||
inline std::string g_localeMissing = "<missing string>";
|
inline std::string g_localeMissing = "<missing string>";
|
||||||
|
|
||||||
extern std::unordered_map<std::string, std::unordered_map<ELanguage, std::string>> g_locale;
|
extern std::unordered_map<std::string_view, std::unordered_map<ELanguage, std::string>> g_locale;
|
||||||
|
|
||||||
std::string& Localise(const char* key);
|
std::string& Localise(const std::string_view& key);
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include <os/registry.h>
|
#include <os/registry.h>
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
inline const wchar_t* g_registryRoot = L"Software\\UnleashedRecomp";
|
inline const wchar_t* g_registryRoot = L"Software\\UnleashedRecomp";
|
||||||
|
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ void ButtonGuide::Draw()
|
|||||||
if (btn.Visibility && !*btn.Visibility)
|
if (btn.Visibility && !*btn.Visibility)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto str = Localise(btn.Name.c_str()).c_str();
|
auto str = Localise(btn.Name).c_str();
|
||||||
auto iconWidth = Scale(g_iconWidths[btn.Icon]);
|
auto iconWidth = Scale(g_iconWidths[btn.Icon]);
|
||||||
auto iconHeight = Scale(g_iconHeights[btn.Icon]);
|
auto iconHeight = Scale(g_iconHeights[btn.Icon]);
|
||||||
auto textWidth = g_fntNewRodin->CalcTextSizeA(fontSize, FLT_MAX, 0, str).x;
|
auto textWidth = g_fntNewRodin->CalcTextSizeA(fontSize, FLT_MAX, 0, str).x;
|
||||||
@@ -283,7 +283,7 @@ void ButtonGuide::Draw()
|
|||||||
if (btn.Visibility && !*btn.Visibility)
|
if (btn.Visibility && !*btn.Visibility)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto str = Localise(btn.Name.c_str()).c_str();
|
auto str = Localise(btn.Name).c_str();
|
||||||
auto iconWidth = Scale(g_iconWidths[btn.Icon]);
|
auto iconWidth = Scale(g_iconWidths[btn.Icon]);
|
||||||
auto iconHeight = Scale(g_iconHeights[btn.Icon]);
|
auto iconHeight = Scale(g_iconHeights[btn.Icon]);
|
||||||
auto textWidth = g_fntNewRodin->CalcTextSizeA(fontSize, FLT_MAX, 0, str).x;
|
auto textWidth = g_fntNewRodin->CalcTextSizeA(fontSize, FLT_MAX, 0, str).x;
|
||||||
|
|||||||
@@ -1399,7 +1399,7 @@ static void DrawNavigationButton()
|
|||||||
|
|
||||||
float squashRatio;
|
float squashRatio;
|
||||||
constexpr float NAV_BUTTON_MAX_TEXT_WIDTH = 90.0f;
|
constexpr float NAV_BUTTON_MAX_TEXT_WIDTH = 90.0f;
|
||||||
const char *nextButtonKey = "Installer_Button_Next";
|
std::string_view nextButtonKey = "Installer_Button_Next";
|
||||||
if (skipButton)
|
if (skipButton)
|
||||||
{
|
{
|
||||||
nextButtonKey = "Installer_Button_Skip";
|
nextButtonKey = "Installer_Button_Skip";
|
||||||
|
|||||||
@@ -59,7 +59,11 @@
|
|||||||
|
|
||||||
#define VALUE_THUMBNAIL_MAP(type) std::unordered_map<type, std::unique_ptr<GuestTexture>>
|
#define VALUE_THUMBNAIL_MAP(type) std::unordered_map<type, std::unique_ptr<GuestTexture>>
|
||||||
|
|
||||||
static std::unordered_map<std::string_view, std::unique_ptr<GuestTexture>> g_namedThumbnails;
|
static std::unique_ptr<GuestTexture> g_defaultThumbnail;
|
||||||
|
|
||||||
|
static std::unique_ptr<GuestTexture> g_controlTutorialXBThumbnail;
|
||||||
|
static std::unique_ptr<GuestTexture> g_controlTutorialPSThumbnail;
|
||||||
|
|
||||||
static std::unordered_map<const IConfigDef*, std::unique_ptr<GuestTexture>> g_configThumbnails;
|
static std::unordered_map<const IConfigDef*, std::unique_ptr<GuestTexture>> g_configThumbnails;
|
||||||
|
|
||||||
static VALUE_THUMBNAIL_MAP(ETimeOfDayTransition) g_timeOfDayTransitionThumbnails;
|
static VALUE_THUMBNAIL_MAP(ETimeOfDayTransition) g_timeOfDayTransitionThumbnails;
|
||||||
@@ -76,10 +80,10 @@ static VALUE_THUMBNAIL_MAP(EUIAlignmentMode) g_uiAlignmentThumbnails;
|
|||||||
|
|
||||||
void LoadThumbnails()
|
void LoadThumbnails()
|
||||||
{
|
{
|
||||||
g_namedThumbnails["Default"] = LOAD_ZSTD_TEXTURE(g_default);
|
g_defaultThumbnail = LOAD_ZSTD_TEXTURE(g_default);
|
||||||
g_namedThumbnails["WindowSize"] = LOAD_ZSTD_TEXTURE(g_window_size);
|
|
||||||
g_namedThumbnails["ControlTutorialXB"] = LOAD_ZSTD_TEXTURE(g_control_tutorial_xb);
|
g_controlTutorialXBThumbnail = LOAD_ZSTD_TEXTURE(g_control_tutorial_xb);
|
||||||
g_namedThumbnails["ControlTutorialPS"] = LOAD_ZSTD_TEXTURE(g_control_tutorial_ps);
|
g_controlTutorialPSThumbnail = LOAD_ZSTD_TEXTURE(g_control_tutorial_ps);
|
||||||
|
|
||||||
g_configThumbnails[&Config::Language] = LOAD_ZSTD_TEXTURE(g_language);
|
g_configThumbnails[&Config::Language] = LOAD_ZSTD_TEXTURE(g_language);
|
||||||
g_configThumbnails[&Config::VoiceLanguage] = LOAD_ZSTD_TEXTURE(g_voice_language);
|
g_configThumbnails[&Config::VoiceLanguage] = LOAD_ZSTD_TEXTURE(g_voice_language);
|
||||||
@@ -109,6 +113,7 @@ void LoadThumbnails()
|
|||||||
g_configThumbnails[&Config::AspectRatio] = LOAD_ZSTD_TEXTURE(g_aspect_ratio);
|
g_configThumbnails[&Config::AspectRatio] = LOAD_ZSTD_TEXTURE(g_aspect_ratio);
|
||||||
g_configThumbnails[&Config::ResolutionScale] = LOAD_ZSTD_TEXTURE(g_resolution_scale);
|
g_configThumbnails[&Config::ResolutionScale] = LOAD_ZSTD_TEXTURE(g_resolution_scale);
|
||||||
g_configThumbnails[&Config::Fullscreen] = LOAD_ZSTD_TEXTURE(g_fullscreen);
|
g_configThumbnails[&Config::Fullscreen] = LOAD_ZSTD_TEXTURE(g_fullscreen);
|
||||||
|
g_configThumbnails[&Config::XboxColorCorrection] = LOAD_ZSTD_TEXTURE(g_xbox_color_correction);
|
||||||
|
|
||||||
g_vsyncThumbnails[false] = LOAD_ZSTD_TEXTURE(g_vsync_off);
|
g_vsyncThumbnails[false] = LOAD_ZSTD_TEXTURE(g_vsync_off);
|
||||||
g_vsyncThumbnails[true] = LOAD_ZSTD_TEXTURE(g_vsync_on);
|
g_vsyncThumbnails[true] = LOAD_ZSTD_TEXTURE(g_vsync_on);
|
||||||
@@ -143,8 +148,6 @@ void LoadThumbnails()
|
|||||||
|
|
||||||
g_uiAlignmentThumbnails[EUIAlignmentMode::Centre] = LOAD_ZSTD_TEXTURE(g_ui_alignment_centre);
|
g_uiAlignmentThumbnails[EUIAlignmentMode::Centre] = LOAD_ZSTD_TEXTURE(g_ui_alignment_centre);
|
||||||
g_uiAlignmentThumbnails[EUIAlignmentMode::Edge] = LOAD_ZSTD_TEXTURE(g_ui_alignment_edge);
|
g_uiAlignmentThumbnails[EUIAlignmentMode::Edge] = LOAD_ZSTD_TEXTURE(g_ui_alignment_edge);
|
||||||
|
|
||||||
g_configThumbnails[&Config::XboxColorCorrection] = LOAD_ZSTD_TEXTURE(g_xbox_color_correction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -156,29 +159,23 @@ bool TryGetValueThumbnail(const IConfigDef* cfg, VALUE_THUMBNAIL_MAP(T)* thumbna
|
|||||||
if (!cfg->GetValue())
|
if (!cfg->GetValue())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto result = thumbnails->at(*(T*)cfg->GetValue()).get();
|
auto findResult = thumbnails->find(*(T*)cfg->GetValue());
|
||||||
|
|
||||||
if (!result)
|
if (findResult != thumbnails->end())
|
||||||
return false;
|
{
|
||||||
|
*texture = findResult->second.get();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
*texture = result;
|
return false;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
GuestTexture* GetThumbnail(const std::string_view name)
|
|
||||||
{
|
|
||||||
if (!g_namedThumbnails.count(name))
|
|
||||||
return g_namedThumbnails["Default"].get();
|
|
||||||
|
|
||||||
return g_namedThumbnails[name].get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GuestTexture* GetThumbnail(const IConfigDef* cfg)
|
GuestTexture* GetThumbnail(const IConfigDef* cfg)
|
||||||
{
|
{
|
||||||
if (!g_configThumbnails.count(cfg))
|
auto findResult = g_configThumbnails.find(cfg);
|
||||||
|
if (findResult == g_configThumbnails.end())
|
||||||
{
|
{
|
||||||
auto texture = g_namedThumbnails["Default"].get();
|
auto texture = g_defaultThumbnail.get();
|
||||||
|
|
||||||
if (cfg == &Config::ControlTutorial)
|
if (cfg == &Config::ControlTutorial)
|
||||||
{
|
{
|
||||||
@@ -187,7 +184,7 @@ GuestTexture* GetThumbnail(const IConfigDef* cfg)
|
|||||||
if (Config::ControllerIcons == EControllerIcons::Auto)
|
if (Config::ControllerIcons == EControllerIcons::Auto)
|
||||||
isPlayStation = hid::g_inputDeviceController == hid::EInputDevice::PlayStation;
|
isPlayStation = hid::g_inputDeviceController == hid::EInputDevice::PlayStation;
|
||||||
|
|
||||||
texture = isPlayStation ? g_namedThumbnails["ControlTutorialPS"].get() : g_namedThumbnails["ControlTutorialXB"].get();
|
texture = isPlayStation ? g_controlTutorialPSThumbnail.get() : g_controlTutorialXBThumbnail.get();
|
||||||
}
|
}
|
||||||
if (cfg == &Config::TimeOfDayTransition)
|
if (cfg == &Config::TimeOfDayTransition)
|
||||||
{
|
{
|
||||||
@@ -237,5 +234,5 @@ GuestTexture* GetThumbnail(const IConfigDef* cfg)
|
|||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
return g_configThumbnails[cfg].get();
|
return findResult->second.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,4 @@
|
|||||||
|
|
||||||
void LoadThumbnails();
|
void LoadThumbnails();
|
||||||
|
|
||||||
GuestTexture* GetThumbnail(const std::string_view name);
|
|
||||||
GuestTexture* GetThumbnail(const IConfigDef* cfg);
|
GuestTexture* GetThumbnail(const IConfigDef* cfg);
|
||||||
|
|||||||
@@ -511,43 +511,33 @@ std::string_view ConfigDef<T, isHidden>::GetName() const
|
|||||||
template<typename T, bool isHidden>
|
template<typename T, bool isHidden>
|
||||||
std::string ConfigDef<T, isHidden>::GetNameLocalised(ELanguage language) const
|
std::string ConfigDef<T, isHidden>::GetNameLocalised(ELanguage language) const
|
||||||
{
|
{
|
||||||
if (!Locale)
|
if (Locale != nullptr)
|
||||||
return Name;
|
|
||||||
|
|
||||||
if (!Locale->count(language))
|
|
||||||
{
|
{
|
||||||
if (Locale->count(ELanguage::English))
|
auto languageFindResult = Locale->find(language);
|
||||||
{
|
if (languageFindResult == Locale->end())
|
||||||
return std::get<0>(Locale->at(ELanguage::English));
|
languageFindResult = Locale->find(ELanguage::English);
|
||||||
}
|
|
||||||
else
|
if (languageFindResult != Locale->end())
|
||||||
{
|
return std::get<0>(languageFindResult->second);
|
||||||
return Name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::get<0>(Locale->at(language));
|
return Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, bool isHidden>
|
template<typename T, bool isHidden>
|
||||||
std::string ConfigDef<T, isHidden>::GetDescription(ELanguage language) const
|
std::string ConfigDef<T, isHidden>::GetDescription(ELanguage language) const
|
||||||
{
|
{
|
||||||
if (!Locale)
|
if (Locale != nullptr)
|
||||||
return "";
|
|
||||||
|
|
||||||
if (!Locale->count(language))
|
|
||||||
{
|
{
|
||||||
if (Locale->count(ELanguage::English))
|
auto languageFindResult = Locale->find(language);
|
||||||
{
|
if (languageFindResult == Locale->end())
|
||||||
return std::get<1>(Locale->at(ELanguage::English));
|
languageFindResult = Locale->find(ELanguage::English);
|
||||||
}
|
|
||||||
else
|
if (languageFindResult != Locale->end())
|
||||||
{
|
return std::get<1>(languageFindResult->second);
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::get<1>(Locale->at(language));
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, bool isHidden>
|
template<typename T, bool isHidden>
|
||||||
@@ -578,27 +568,27 @@ std::string ConfigDef<T, isHidden>::GetValueLocalised(ELanguage language) const
|
|||||||
: Localise("Common_Off");
|
: Localise("Common_Off");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!locale)
|
if (locale != nullptr)
|
||||||
return ToString(false);
|
|
||||||
|
|
||||||
if (!locale->count(language))
|
|
||||||
{
|
{
|
||||||
if (locale->count(ELanguage::English))
|
ELanguage languages[] = { language, ELanguage::English };
|
||||||
|
|
||||||
|
for (auto languageToFind : languages)
|
||||||
{
|
{
|
||||||
language = ELanguage::English;
|
auto languageFindResult = locale->find(languageToFind);
|
||||||
}
|
|
||||||
else
|
if (languageFindResult != locale->end())
|
||||||
{
|
{
|
||||||
return ToString(false);
|
auto valueFindResult = languageFindResult->second.find(Value);
|
||||||
|
if (valueFindResult != languageFindResult->second.end())
|
||||||
|
return std::get<0>(valueFindResult->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (languageToFind == ELanguage::English)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto strings = locale->at(language);
|
return ToString(false);
|
||||||
|
|
||||||
if (!strings.count(Value))
|
|
||||||
return ToString(false);
|
|
||||||
|
|
||||||
return std::get<0>(strings.at(Value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, bool isHidden>
|
template<typename T, bool isHidden>
|
||||||
@@ -615,27 +605,27 @@ std::string ConfigDef<T, isHidden>::GetValueDescription(ELanguage language) cons
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!locale)
|
if (locale != nullptr)
|
||||||
return "";
|
|
||||||
|
|
||||||
if (!locale->count(language))
|
|
||||||
{
|
{
|
||||||
if (locale->count(ELanguage::English))
|
ELanguage languages[] = { language, ELanguage::English };
|
||||||
|
|
||||||
|
for (auto languageToFind : languages)
|
||||||
{
|
{
|
||||||
language = ELanguage::English;
|
auto languageFindResult = locale->find(languageToFind);
|
||||||
}
|
|
||||||
else
|
if (languageFindResult != locale->end())
|
||||||
{
|
{
|
||||||
return "";
|
auto valueFindResult = languageFindResult->second.find(Value);
|
||||||
|
if (valueFindResult != languageFindResult->second.end())
|
||||||
|
return std::get<1>(valueFindResult->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (languageToFind == ELanguage::English)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto strings = locale->at(language);
|
return "";
|
||||||
|
|
||||||
if (!strings.count(Value))
|
|
||||||
return "";
|
|
||||||
|
|
||||||
return std::get<1>(strings.at(Value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, bool isHidden>
|
template<typename T, bool isHidden>
|
||||||
|
|||||||
Reference in New Issue
Block a user