From b8a9745eda630d6dbdc6ef395bd37ce5a69d6f11 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 19 Feb 2015 20:40:14 +0100 Subject: [PATCH 1/6] Use locale info to create default config Issue #736, get measurement system, temperature system, language and currency from locale and use it as default. --- src/config.c | 19 +++++- src/config.h | 2 + src/platform/platform.h | 4 ++ src/platform/windows.c | 127 +++++++++++++++++++++++++++++++++++++++- src/title.c | 1 - 5 files changed, 150 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index 9cb38dc80f..191471e12d 100644 --- a/src/config.c +++ b/src/config.c @@ -200,7 +200,24 @@ void config_set_defaults() config_property_definition *property = §ion->property_definitions[j]; value_union *destValue = (value_union*)((size_t)section->base_address + (size_t)property->offset); - memcpy(destValue, &property->default_value, _configValueTypeSize[property->type]); + + if (strcmp(property->property_name, "language") == 0){ + destValue->value_uint16 = platform_get_locale_language(); + if (destValue->value_uint16 == LANGUAGE_UNDEFINED) + memcpy(destValue, &property->default_value, _configValueTypeSize[property->type]); + } + else if (strcmp(property->property_name, "currency_format") == 0){ + destValue->value_uint8 = platform_get_locale_currency(); + } + else if (strcmp(property->property_name, "measurement_format") == 0){ + destValue->value_uint8 = platform_get_locale_measurement_format(); + } + else if (strcmp(property->property_name, "temperature_format") == 0){ + destValue->value_uint8 = platform_get_locale_temperature_format(); + } + else { + memcpy(destValue, &property->default_value, _configValueTypeSize[property->type]); + } } } } diff --git a/src/config.h b/src/config.h index 1ab8935edf..66787fd8ab 100644 --- a/src/config.h +++ b/src/config.h @@ -141,6 +141,8 @@ void config_set_defaults(); bool config_open_default(); bool config_save_default(); +uint16 getLanguage(); + void config_reset_shortcut_keys(); bool config_find_or_browse_install_directory(); diff --git a/src/platform/platform.h b/src/platform/platform.h index 3ffb128872..98bd6b0041 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -105,6 +105,10 @@ void platform_get_user_directory(char *outPath, const char *subDirectory); void platform_show_messagebox(char *message); int platform_open_common_file_dialog(int type, char *title, char *filename, char *filterPattern, char *filterName); char *platform_open_directory_browser(char *title); +uint8 platform_get_locale_currency(); +uint16 platform_get_locale_language(); +uint8 platform_get_locale_measurement_format(); +uint8 platform_get_locale_temperature_format(); // Windows specific definitions #ifdef _WIN32 diff --git a/src/platform/windows.c b/src/platform/windows.c index 35a8493c81..3b191cfeba 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -26,6 +26,9 @@ #include "../addresses.h" #include "../cmdline.h" #include "../openrct2.h" +#include "../localisation/language.h" +#include "../localisation/currency.h" +#include "../config.h" #include "platform.h" // The name of the mutex used to prevent multiple instances of the game from running @@ -591,4 +594,126 @@ PCHAR *CommandLineToArgvA(PCHAR CmdLine, int *_argc) return argv; } -#endif \ No newline at end of file +#endif + +uint16 platform_get_locale_language(){ + WCHAR langCode[4]; + + if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, + LOCALE_SABBREVLANGNAME, + langCode, + sizeof(langCode) / sizeof(WCHAR)) == 0){ + return LANGUAGE_UNDEFINED; + } + + if (wcscmp(langCode, L"ENG") == 0){ + return LANGUAGE_ENGLISH_UK; + } + else if (wcscmp(langCode, L"ENU") == 0){ + return LANGUAGE_ENGLISH_US; + } + else if (wcscmp(langCode, L"DEU") == 0){ + return LANGUAGE_GERMAN; + } + else if (wcscmp(langCode, L"NLD") == 0){ + return LANGUAGE_DUTCH; + } + else if (wcscmp(langCode, L"FRA") == 0){ + return LANGUAGE_FRENCH; + } + else if (wcscmp(langCode, L"HUN") == 0){ + return LANGUAGE_HUNGARIAN; + } + else if (wcscmp(langCode, L"PLK") == 0){ + return LANGUAGE_POLISH; + } + else if (wcscmp(langCode, L"ESP") == 0){ + return LANGUAGE_SPANISH; + } + else if (wcscmp(langCode, L"SVE") == 0){ + return LANGUAGE_SWEDISH; + } + return LANGUAGE_UNDEFINED; +} + +uint8 platform_get_locale_currency(){ + WCHAR currCode[4]; + + if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, + LOCALE_SINTLSYMBOL, + currCode, + sizeof(currCode) / sizeof(WCHAR)) == 0){ + return CURRENCY_POUNDS; + } + if (wcscmp(currCode, L"GBP") == 0){ + return CURRENCY_POUNDS; + } + else if (wcscmp(currCode, L"USD") == 0){ + return CURRENCY_DOLLARS; + } + else if (wcscmp(currCode, L"EUR") == 0){ + return CURRENCY_EUROS; + } + else if (wcscmp(currCode, L"SEK") == 0){ + return CURRENCY_KRONA; + } + else if (wcscmp(currCode, L"SEK") == 0){ + return CURRENCY_KRONA; + } + else if (wcscmp(currCode, L"ITL") == 0){ + return CURRENCY_LIRA; + } + else if (wcscmp(currCode, L"JPY") == 0){ + return CURRENCY_YEN; + } + else if (wcscmp(currCode, L"ESP") == 0){ + return CURRENCY_PESETA; + } + else if (wcscmp(currCode, L"FRF") == 0){ + return CURRENCY_FRANC; + } + else if (wcscmp(currCode, L"NLG") == 0){ + return CURRENCY_GUILDERS; + } + return CURRENCY_POUNDS; +} + +uint8 platform_get_locale_measurement_format(){ + UINT measurement_system; + if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, + LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, + (LPWSTR)&measurement_system, + sizeof(measurement_system)) == 0){ + return MEASUREMENT_FORMAT_IMPERIAL; + } + switch (measurement_system){ + case 0: + return MEASUREMENT_FORMAT_METRIC; + case 1: + return MEASUREMENT_FORMAT_IMPERIAL; + default: + return MEASUREMENT_FORMAT_IMPERIAL; + } +} + +uint8 platform_get_locale_temperature_format(){ + // There does not seem to be a function to obtain this, just check the countries + // According + UINT country; + if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, + LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, + (LPWSTR)&country, + sizeof(country)) == 0){ + return TEMPERATURE_FORMAT_C; + } + switch (country){ + case CTRY_UNITED_STATES: + //USA + return TEMPERATURE_FORMAT_F; + case CTRY_BELIZE: + // Belize + return TEMPERATURE_FORMAT_F; + default: + return TEMPERATURE_FORMAT_C; + } +} \ No newline at end of file diff --git a/src/title.c b/src/title.c index d1daa1eb9a..21acac7d5e 100644 --- a/src/title.c +++ b/src/title.c @@ -265,7 +265,6 @@ static void DrawOpenRCT2(int x, int y) void game_handle_input(); void title_update() { - int tmp; screenshot_check(); title_handle_keyboard_input(); From ee6cbf8059bdef9dea3f6521138aa01d4d00ad3d Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 19 Feb 2015 20:48:48 +0100 Subject: [PATCH 2/6] Add import --- src/platform/windows.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/platform/windows.c b/src/platform/windows.c index 3b191cfeba..bd70ece87a 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -30,6 +30,7 @@ #include "../localisation/currency.h" #include "../config.h" #include "platform.h" +#include "winnls.h" // The name of the mutex used to prevent multiple instances of the game from running #define SINGLE_INSTANCE_MUTEX_NAME "RollerCoaster Tycoon 2_GSKMUTEX" From 23304b17704d0c28dfd399f1dc6b949f6d0aed36 Mon Sep 17 00:00:00 2001 From: Thomas den Hollander Date: Fri, 20 Feb 2015 08:59:09 +0100 Subject: [PATCH 3/6] Moved endif to end of file --- src/platform/windows.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/platform/windows.c b/src/platform/windows.c index bd70ece87a..a65f58ade2 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -30,7 +30,6 @@ #include "../localisation/currency.h" #include "../config.h" #include "platform.h" -#include "winnls.h" // The name of the mutex used to prevent multiple instances of the game from running #define SINGLE_INSTANCE_MUTEX_NAME "RollerCoaster Tycoon 2_GSKMUTEX" @@ -595,8 +594,6 @@ PCHAR *CommandLineToArgvA(PCHAR CmdLine, int *_argc) return argv; } -#endif - uint16 platform_get_locale_language(){ WCHAR langCode[4]; @@ -717,4 +714,6 @@ uint8 platform_get_locale_temperature_format(){ default: return TEMPERATURE_FORMAT_C; } -} \ No newline at end of file +} + +#endif \ No newline at end of file From d528273d1554f87b724ac324cd53b6be904fd7e4 Mon Sep 17 00:00:00 2001 From: Thomas den Hollander Date: Sat, 21 Feb 2015 00:09:02 +0100 Subject: [PATCH 4/6] Change to GetLocaleInfo --- src/platform/windows.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/platform/windows.c b/src/platform/windows.c index 650a919de6..189003acf8 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -597,7 +597,7 @@ PCHAR *CommandLineToArgvA(PCHAR CmdLine, int *_argc) uint16 platform_get_locale_language(){ WCHAR langCode[4]; - if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, + if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, langCode, sizeof(langCode) / sizeof(WCHAR)) == 0){ @@ -637,7 +637,7 @@ uint16 platform_get_locale_language(){ uint8 platform_get_locale_currency(){ WCHAR currCode[4]; - if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, + if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SINTLSYMBOL, currCode, sizeof(currCode) / sizeof(WCHAR)) == 0){ @@ -678,7 +678,7 @@ uint8 platform_get_locale_currency(){ uint8 platform_get_locale_measurement_format(){ UINT measurement_system; - if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, + if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, (LPWSTR)&measurement_system, sizeof(measurement_system)) == 0){ @@ -698,7 +698,7 @@ uint8 platform_get_locale_temperature_format(){ // There does not seem to be a function to obtain this, just check the countries // According UINT country; - if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, + if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, (LPWSTR)&country, sizeof(country)) == 0){ @@ -715,4 +715,4 @@ uint8 platform_get_locale_temperature_format(){ return TEMPERATURE_FORMAT_C; } } -#endif \ No newline at end of file +#endif From 7bc4c4270d2e1687663b76a8ffdcccb056b7aa4a Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 21 Feb 2015 17:13:15 +0100 Subject: [PATCH 5/6] Fix warnings --- src/platform/windows.c | 62 ++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/src/platform/windows.c b/src/platform/windows.c index 189003acf8..2e95408715 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -595,82 +595,83 @@ PCHAR *CommandLineToArgvA(PCHAR CmdLine, int *_argc) } uint16 platform_get_locale_language(){ - WCHAR langCode[4]; + CHAR langCode[4]; if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, - langCode, - sizeof(langCode) / sizeof(WCHAR)) == 0){ + (LPSTR)&langCode, + sizeof(langCode)) == 0){ return LANGUAGE_UNDEFINED; } - if (wcscmp(langCode, L"ENG") == 0){ + if (strcmp(langCode, "ENG") == 0){ return LANGUAGE_ENGLISH_UK; } - else if (wcscmp(langCode, L"ENU") == 0){ + else if (strcmp(langCode, "ENU") == 0){ return LANGUAGE_ENGLISH_US; } - else if (wcscmp(langCode, L"DEU") == 0){ + else if (strcmp(langCode, "DEU") == 0){ return LANGUAGE_GERMAN; } - else if (wcscmp(langCode, L"NLD") == 0){ + else if (strcmp(langCode, "NLD") == 0){ return LANGUAGE_DUTCH; } - else if (wcscmp(langCode, L"FRA") == 0){ + else if (strcmp(langCode, "FRA") == 0){ return LANGUAGE_FRENCH; } - else if (wcscmp(langCode, L"HUN") == 0){ + else if (strcmp(langCode, "HUN") == 0){ return LANGUAGE_HUNGARIAN; } - else if (wcscmp(langCode, L"PLK") == 0){ + else if (strcmp(langCode, "PLK") == 0){ return LANGUAGE_POLISH; } - else if (wcscmp(langCode, L"ESP") == 0){ + else if (strcmp(langCode, "ESP") == 0){ return LANGUAGE_SPANISH; } - else if (wcscmp(langCode, L"SVE") == 0){ + else if (strcmp(langCode, "SVE") == 0){ return LANGUAGE_SWEDISH; } + printf("%s\n", langCode); return LANGUAGE_UNDEFINED; } uint8 platform_get_locale_currency(){ - WCHAR currCode[4]; + CHAR currCode[4]; if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SINTLSYMBOL, - currCode, - sizeof(currCode) / sizeof(WCHAR)) == 0){ + (LPSTR)&currCode, + sizeof(currCode)) == 0){ return CURRENCY_POUNDS; } - if (wcscmp(currCode, L"GBP") == 0){ + if (wcscmp(strcmp, "GBP") == 0){ return CURRENCY_POUNDS; } - else if (wcscmp(currCode, L"USD") == 0){ + else if (strcmp(currCode, "USD") == 0){ return CURRENCY_DOLLARS; } - else if (wcscmp(currCode, L"EUR") == 0){ + else if (strcmp(currCode, "EUR") == 0){ return CURRENCY_EUROS; } - else if (wcscmp(currCode, L"SEK") == 0){ + else if (strcmp(currCode, "SEK") == 0){ return CURRENCY_KRONA; } - else if (wcscmp(currCode, L"SEK") == 0){ - return CURRENCY_KRONA; + else if (strcmp(currCode, "DEM") == 0){ + return CURRENCY_DEUTSCHMARK; } - else if (wcscmp(currCode, L"ITL") == 0){ + else if (strcmp(currCode, "ITL") == 0){ return CURRENCY_LIRA; } - else if (wcscmp(currCode, L"JPY") == 0){ + else if (strcmp(currCode, "JPY") == 0){ return CURRENCY_YEN; } - else if (wcscmp(currCode, L"ESP") == 0){ + else if (strcmp(currCode, "ESP") == 0){ return CURRENCY_PESETA; } - else if (wcscmp(currCode, L"FRF") == 0){ + else if (strcmp(currCode, "FRF") == 0){ return CURRENCY_FRANC; } - else if (wcscmp(currCode, L"NLG") == 0){ + else if (strcmp(currCode, "NLG") == 0){ return CURRENCY_GUILDERS; } return CURRENCY_POUNDS; @@ -680,7 +681,7 @@ uint8 platform_get_locale_measurement_format(){ UINT measurement_system; if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, - (LPWSTR)&measurement_system, + (LPSTR)&measurement_system, sizeof(measurement_system)) == 0){ return MEASUREMENT_FORMAT_IMPERIAL; } @@ -688,7 +689,6 @@ uint8 platform_get_locale_measurement_format(){ case 0: return MEASUREMENT_FORMAT_METRIC; case 1: - return MEASUREMENT_FORMAT_IMPERIAL; default: return MEASUREMENT_FORMAT_IMPERIAL; } @@ -696,20 +696,16 @@ uint8 platform_get_locale_measurement_format(){ uint8 platform_get_locale_temperature_format(){ // There does not seem to be a function to obtain this, just check the countries - // According UINT country; if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, - (LPWSTR)&country, + (LPSTR)&country, sizeof(country)) == 0){ return TEMPERATURE_FORMAT_C; } switch (country){ case CTRY_UNITED_STATES: - //USA - return TEMPERATURE_FORMAT_F; case CTRY_BELIZE: - // Belize return TEMPERATURE_FORMAT_F; default: return TEMPERATURE_FORMAT_C; From acad7af40ee9556e0c5dfa2cb4892db902c83f29 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 21 Feb 2015 17:26:38 +0100 Subject: [PATCH 6/6] Fix error and removed debugging in platform_get_locale_currency() --- src/platform/windows.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/platform/windows.c b/src/platform/windows.c index 2e95408715..7517d30fa7 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -631,7 +631,6 @@ uint16 platform_get_locale_language(){ else if (strcmp(langCode, "SVE") == 0){ return LANGUAGE_SWEDISH; } - printf("%s\n", langCode); return LANGUAGE_UNDEFINED; } @@ -644,7 +643,7 @@ uint8 platform_get_locale_currency(){ sizeof(currCode)) == 0){ return CURRENCY_POUNDS; } - if (wcscmp(strcmp, "GBP") == 0){ + if (strcmp(currCode, "GBP") == 0){ return CURRENCY_POUNDS; } else if (strcmp(currCode, "USD") == 0){