1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Upgrade platform_get_locale_currency()

This commit is contained in:
Gymnasiast
2022-01-08 12:24:57 +01:00
parent 12034b2d36
commit 3f22b60f94
12 changed files with 60 additions and 60 deletions

View File

@@ -151,7 +151,7 @@ namespace Config
model->autosave_amount = reader->GetInt32("autosave_amount", DEFAULT_NUM_AUTOSAVES_TO_KEEP);
model->confirmation_prompt = reader->GetBoolean("confirmation_prompt", false);
model->currency_format = reader->GetEnum<CurrencyType>(
"currency_format", platform_get_locale_currency(), Enum_Currency);
"currency_format", Platform::GetLocaleCurrency(), Enum_Currency);
model->custom_currency_rate = reader->GetInt32("custom_currency_rate", 10);
model->custom_currency_affix = reader->GetEnum<CurrencyAffix>(
"custom_currency_affix", CurrencyAffix::Suffix, Enum_CurrencySymbolAffix);

View File

@@ -26,11 +26,6 @@ bool platform_get_font_path(TTFFontDescriptor* font, utf8* buffer, size_t size)
}
# endif
CurrencyType platform_get_locale_currency()
{
return platform_get_currency_value(NULL);
}
MeasurementFormat platform_get_locale_measurement_format()
{
return MeasurementFormat::Metric;

View File

@@ -34,20 +34,6 @@
# include <locale.h>
# include <pwd.h>
CurrencyType platform_get_locale_currency()
{
char* langstring = setlocale(LC_MONETARY, "");
if (langstring == nullptr)
{
return platform_get_currency_value(NULL);
}
struct lconv* lc = localeconv();
return platform_get_currency_value(lc->int_curr_symbol);
}
MeasurementFormat platform_get_locale_measurement_format()
{
// LC_MEASUREMENT is GNU specific.

View File

@@ -60,6 +60,11 @@ namespace Platform
{
return LANGUAGE_ENGLISH_UK;
}
CurrencyType GetLocaleCurrency()
{
return Platform::GetCurrencyValue(NULL);
}
} // namespace Platform
#endif

View File

@@ -236,6 +236,20 @@ namespace Platform
}
return LANGUAGE_ENGLISH_UK;
}
CurrencyType GetLocaleCurrency()
{
char* langstring = setlocale(LC_MONETARY, "");
if (langstring == nullptr)
{
return Platform::GetCurrencyValue(NULL);
}
struct lconv* lc = localeconv();
return Platform::GetCurrencyValue(lc->int_curr_symbol);
}
} // namespace Platform
#endif

View File

@@ -696,6 +696,17 @@ namespace Platform
}
return LANGUAGE_UNDEFINED;
}
CurrencyType GetLocaleCurrency()
{
CHAR currCode[4];
if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SINTLSYMBOL, reinterpret_cast<LPSTR>(&currCode), sizeof(currCode)) == 0)
{
return Platform::GetCurrencyValue(nullptr);
}
return Platform::GetCurrencyValue(currCode);
}
} // namespace Platform
#endif

View File

@@ -207,6 +207,15 @@ namespace Platform
return LANGUAGE_ENGLISH_UK;
}
}
CurrencyType GetLocaleCurrency()
{
@autoreleasepool
{
NSString* currencyCode = [[NSLocale currentLocale] objectForKey:NSLocaleCurrencyCode];
return Platform::GetCurrencyValue(currencyCode.UTF8String);
}
}
}
#endif

View File

@@ -43,6 +43,8 @@ namespace Platform
std::string ResolveCasing(const std::string& path, bool fileExists);
uint16_t GetLocaleLanguage();
CurrencyType GetLocaleCurrency();
CurrencyType GetCurrencyValue(const char* currCode);
rct2_time GetTimeLocal();
rct2_date GetDateLocal();

View File

@@ -70,6 +70,24 @@ static LARGE_INTEGER _entryTimestamp;
namespace Platform
{
CurrencyType GetCurrencyValue(const char* currCode)
{
if (currCode == nullptr || strlen(currCode) < 3)
{
return CurrencyType::Pounds;
}
for (int32_t currency = 0; currency < EnumValue(CurrencyType::Count); ++currency)
{
if (strncmp(currCode, CurrencyDescriptors[currency].isoCode, 3) == 0)
{
return static_cast<CurrencyType>(currency);
}
}
return CurrencyType::Pounds;
}
rct2_date GetDateLocal()
{
auto time = std::time(nullptr);
@@ -242,24 +260,6 @@ void platform_sleep(uint32_t ms)
#endif
}
CurrencyType platform_get_currency_value(const char* currCode)
{
if (currCode == nullptr || strlen(currCode) < 3)
{
return CurrencyType::Pounds;
}
for (int32_t currency = 0; currency < EnumValue(CurrencyType::Count); ++currency)
{
if (strncmp(currCode, CurrencyDescriptors[currency].isoCode, 3) == 0)
{
return static_cast<CurrencyType>(currency);
}
}
return CurrencyType::Pounds;
}
#ifndef __ANDROID__
float platform_get_default_scale()
{

View File

@@ -205,17 +205,6 @@ time_t platform_file_get_modified_time(const utf8* path)
return 0;
}
CurrencyType platform_get_locale_currency()
{
CHAR currCode[4];
if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SINTLSYMBOL, reinterpret_cast<LPSTR>(&currCode), sizeof(currCode)) == 0)
{
return platform_get_currency_value(nullptr);
}
return platform_get_currency_value(currCode);
}
MeasurementFormat platform_get_locale_measurement_format()
{
UINT measurement_system;

View File

@@ -45,15 +45,6 @@ bool platform_get_font_path(TTFFontDescriptor* font, utf8* buffer, size_t size)
}
# endif // NO_TTF
CurrencyType platform_get_locale_currency()
{
@autoreleasepool
{
NSString* currencyCode = [[NSLocale currentLocale] objectForKey:NSLocaleCurrencyCode];
return platform_get_currency_value(currencyCode.UTF8String);
}
}
MeasurementFormat platform_get_locale_measurement_format()
{
@autoreleasepool

View File

@@ -105,8 +105,6 @@ void platform_sleep(uint32_t ms);
void platform_get_user_directory(utf8* outPath, const utf8* subDirectory, size_t outSize);
bool platform_open_common_file_dialog(utf8* outFilename, file_dialog_desc* desc, size_t outSize);
utf8* platform_open_directory_browser(const utf8* title);
CurrencyType platform_get_locale_currency();
CurrencyType platform_get_currency_value(const char* currencyCode);
MeasurementFormat platform_get_locale_measurement_format();
TemperatureUnit platform_get_locale_temperature_format();
uint8_t platform_get_locale_date_format();