1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-18 12:33:17 +01:00

Upgrade platform_get_locale_measurement_format()

This commit is contained in:
Gymnasiast
2022-01-10 12:38:26 +01:00
parent ef77f9c2c1
commit 95717573f5
11 changed files with 64 additions and 65 deletions

View File

@@ -166,7 +166,7 @@ namespace Config
model->landscape_smoothing = reader->GetBoolean("landscape_smoothing", true);
model->language = reader->GetEnum<int32_t>("language", Platform::GetLocaleLanguage(), Enum_LanguageEnum);
model->measurement_format = reader->GetEnum<MeasurementFormat>(
"measurement_format", platform_get_locale_measurement_format(), Enum_MeasurementFormat);
"measurement_format", Platform::GetLocaleMeasurementFormat(), Enum_MeasurementFormat);
model->play_intro = reader->GetBoolean("play_intro", false);
model->save_plugin_data = reader->GetBoolean("save_plugin_data", true);
model->debugging_tools = reader->GetBoolean("debugging_tools", false);

View File

@@ -26,11 +26,6 @@ bool platform_get_font_path(TTFFontDescriptor* font, utf8* buffer, size_t size)
}
# endif
MeasurementFormat platform_get_locale_measurement_format()
{
return MeasurementFormat::Metric;
}
float platform_get_default_scale()
{
JNIEnv* env = static_cast<JNIEnv*>(SDL_AndroidGetJNIEnv());

View File

@@ -32,30 +32,8 @@
# include "../util/Util.h"
# include "platform.h"
# include <fnmatch.h>
# include <locale.h>
# include <pwd.h>
MeasurementFormat platform_get_locale_measurement_format()
{
// LC_MEASUREMENT is GNU specific.
# ifdef LC_MEASUREMENT
const char* langstring = setlocale(LC_MEASUREMENT, "");
# else
const char* langstring = setlocale(LC_ALL, "");
# endif
if (langstring != nullptr)
{
// using https://en.wikipedia.org/wiki/Metrication#Chronology_and_status_of_conversion_by_country as reference
if (!fnmatch("*_US*", langstring, 0) || !fnmatch("*_MM*", langstring, 0) || !fnmatch("*_LR*", langstring, 0))
{
return MeasurementFormat::Imperial;
}
}
return MeasurementFormat::Metric;
}
bool platform_get_steam_path(utf8* outPath, size_t outSize)
{
const char* steamRoot = getenv("STEAMROOT");

View File

@@ -65,6 +65,11 @@ namespace Platform
{
return Platform::GetCurrencyValue(NULL);
}
MeasurementFormat GetLocaleMeasurementFormat()
{
return MeasurementFormat::Metric;
}
} // namespace Platform
#endif

View File

@@ -12,6 +12,7 @@
# include <cstring>
# include <fnmatch.h>
# include <limits.h>
# include <locale.h>
# include <pwd.h>
# include <vector>
# if defined(__FreeBSD__) || defined(__NetBSD__)
@@ -250,6 +251,26 @@ namespace Platform
return Platform::GetCurrencyValue(lc->int_curr_symbol);
}
MeasurementFormat GetLocaleMeasurementFormat()
{
// LC_MEASUREMENT is GNU specific.
# ifdef LC_MEASUREMENT
const char* langstring = setlocale(LC_MEASUREMENT, "");
# else
const char* langstring = setlocale(LC_ALL, "");
# endif
if (langstring != nullptr)
{
// using https://en.wikipedia.org/wiki/Metrication#Chronology_and_status_of_conversion_by_country as reference
if (!fnmatch("*_US*", langstring, 0) || !fnmatch("*_MM*", langstring, 0) || !fnmatch("*_LR*", langstring, 0))
{
return MeasurementFormat::Imperial;
}
}
return MeasurementFormat::Metric;
}
} // namespace Platform
#endif

View File

@@ -707,6 +707,27 @@ namespace Platform
return Platform::GetCurrencyValue(currCode);
}
MeasurementFormat GetLocaleMeasurementFormat()
{
UINT measurement_system;
if (GetLocaleInfo(
LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, reinterpret_cast<LPSTR>(&measurement_system),
sizeof(measurement_system))
== 0)
{
return MeasurementFormat::Metric;
}
switch (measurement_system)
{
case 1:
return MeasurementFormat::Imperial;
case 0:
default:
return MeasurementFormat::Metric;
}
}
} // namespace Platform
#endif

View File

@@ -216,6 +216,21 @@ namespace Platform
return Platform::GetCurrencyValue(currencyCode.UTF8String);
}
}
MeasurementFormat GetLocaleMeasurementFormat()
{
@autoreleasepool
{
NSNumber* metricSystem = [[NSLocale currentLocale] objectForKey:NSLocaleUsesMetricSystem];
if (metricSystem.boolValue)
{
return MeasurementFormat::Metric;
}
return MeasurementFormat::Imperial;
}
}
}
#endif

View File

@@ -45,6 +45,7 @@ namespace Platform
uint16_t GetLocaleLanguage();
CurrencyType GetLocaleCurrency();
CurrencyType GetCurrencyValue(const char* currCode);
MeasurementFormat GetLocaleMeasurementFormat();
rct2_time GetTimeLocal();
rct2_date GetDateLocal();

View File

@@ -176,27 +176,6 @@ time_t platform_file_get_modified_time(const utf8* path)
return 0;
}
MeasurementFormat platform_get_locale_measurement_format()
{
UINT measurement_system;
if (GetLocaleInfo(
LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, reinterpret_cast<LPSTR>(&measurement_system),
sizeof(measurement_system))
== 0)
{
return MeasurementFormat::Metric;
}
switch (measurement_system)
{
case 1:
return MeasurementFormat::Imperial;
case 0:
default:
return MeasurementFormat::Metric;
}
}
TemperatureUnit platform_get_locale_temperature_format()
{
UINT fahrenheit;

View File

@@ -46,21 +46,6 @@ bool platform_get_font_path(TTFFontDescriptor* font, utf8* buffer, size_t size)
}
# endif // NO_TTF
MeasurementFormat platform_get_locale_measurement_format()
{
@autoreleasepool
{
NSNumber* metricSystem = [[NSLocale currentLocale] objectForKey:NSLocaleUsesMetricSystem];
if (metricSystem.boolValue)
{
return MeasurementFormat::Metric;
}
return MeasurementFormat::Imperial;
}
}
bool platform_get_steam_path(utf8* outPath, size_t outSize)
{
char steamPath[1024] = { 0 };

View File

@@ -100,7 +100,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);
MeasurementFormat platform_get_locale_measurement_format();
TemperatureUnit platform_get_locale_temperature_format();
uint8_t platform_get_locale_date_format();
bool platform_process_is_elevated();