diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index d8a4dfd097..2c478d476a 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -166,7 +166,7 @@ namespace Config model->landscape_smoothing = reader->GetBoolean("landscape_smoothing", true); model->language = reader->GetEnum("language", Platform::GetLocaleLanguage(), Enum_LanguageEnum); model->measurement_format = reader->GetEnum( - "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); diff --git a/src/openrct2/platform/Android.cpp b/src/openrct2/platform/Android.cpp index a3e93557d5..7c56f22f8e 100644 --- a/src/openrct2/platform/Android.cpp +++ b/src/openrct2/platform/Android.cpp @@ -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(SDL_AndroidGetJNIEnv()); diff --git a/src/openrct2/platform/Linux.cpp b/src/openrct2/platform/Linux.cpp index 12aa1a54a3..4bd1f0edff 100644 --- a/src/openrct2/platform/Linux.cpp +++ b/src/openrct2/platform/Linux.cpp @@ -32,30 +32,8 @@ # include "../util/Util.h" # include "platform.h" -# include -# include # include -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"); diff --git a/src/openrct2/platform/Platform.Android.cpp b/src/openrct2/platform/Platform.Android.cpp index e626828354..736c7bc2db 100644 --- a/src/openrct2/platform/Platform.Android.cpp +++ b/src/openrct2/platform/Platform.Android.cpp @@ -65,6 +65,11 @@ namespace Platform { return Platform::GetCurrencyValue(NULL); } + + MeasurementFormat GetLocaleMeasurementFormat() + { + return MeasurementFormat::Metric; + } } // namespace Platform #endif diff --git a/src/openrct2/platform/Platform.Linux.cpp b/src/openrct2/platform/Platform.Linux.cpp index ebdb622e31..e90b8c6e47 100644 --- a/src/openrct2/platform/Platform.Linux.cpp +++ b/src/openrct2/platform/Platform.Linux.cpp @@ -12,6 +12,7 @@ # include # include # include +# include # include # include # 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 diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index 229273eedc..8180107354 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -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(&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 diff --git a/src/openrct2/platform/Platform.macOS.mm b/src/openrct2/platform/Platform.macOS.mm index dbd8060208..5ff2962b33 100644 --- a/src/openrct2/platform/Platform.macOS.mm +++ b/src/openrct2/platform/Platform.macOS.mm @@ -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 diff --git a/src/openrct2/platform/Platform2.h b/src/openrct2/platform/Platform2.h index 989ad727b4..f19428c5c9 100644 --- a/src/openrct2/platform/Platform2.h +++ b/src/openrct2/platform/Platform2.h @@ -45,6 +45,7 @@ namespace Platform uint16_t GetLocaleLanguage(); CurrencyType GetLocaleCurrency(); CurrencyType GetCurrencyValue(const char* currCode); + MeasurementFormat GetLocaleMeasurementFormat(); rct2_time GetTimeLocal(); rct2_date GetDateLocal(); diff --git a/src/openrct2/platform/Windows.cpp b/src/openrct2/platform/Windows.cpp index 1aad3ef08b..ba622ffa27 100644 --- a/src/openrct2/platform/Windows.cpp +++ b/src/openrct2/platform/Windows.cpp @@ -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(&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; diff --git a/src/openrct2/platform/macos.mm b/src/openrct2/platform/macos.mm index 09918ab389..2ea7864562 100644 --- a/src/openrct2/platform/macos.mm +++ b/src/openrct2/platform/macos.mm @@ -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 }; diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index d5f5ca2686..e5bcaf2b59 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -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();