1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Use locale info to create default config

Issue #736, get measurement system, temperature system, language and
currency from locale and use it as default.
This commit is contained in:
Thomas
2015-02-19 20:40:14 +01:00
parent e0b2c30b27
commit b8a9745eda
5 changed files with 150 additions and 3 deletions

View File

@@ -200,7 +200,24 @@ void config_set_defaults()
config_property_definition *property = &section->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]);
}
}
}
}

View File

@@ -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();

View File

@@ -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

View File

@@ -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
#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;
}
}

View File

@@ -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();