diff --git a/src/config.c b/src/config.c index ad58991810..41551d94a5 100644 --- a/src/config.c +++ b/src/config.c @@ -76,15 +76,19 @@ static const uint16 _defaultShortcutKeys[SHORTCUT_COUNT] = { general_configuration_t gGeneral_config; general_configuration_t gGeneral_config_default = { - 1, - 1, - SCREENSHOT_FORMAT_PNG, - "", - MEASUREMENT_FORMAT_IMPERIAL, - TEMPERATURE_FORMAT_F, - 0, - 0, - 1, + 0, // play_intro + 1, // confirmation_prompt + SCREENSHOT_FORMAT_PNG, // screenshot_format + "", // game_path + MEASUREMENT_FORMAT_IMPERIAL, // measurement_format + TEMPERATURE_FORMAT_F, // temperature_format + CURRENCY_POUNDS, // currency_format + 0, // construction_marker_colour + 1, // edge_scrolling + 0, // always_show_gridlines + 1, // landscape_smoothing + 0, // show_height_as_units + 1, // save_plugin_data }; sound_configuration_t gSound_config; @@ -100,6 +104,10 @@ static void config_create_default(char *path); static int config_parse_currency(char* currency); static void config_error(char *msg); +void config_save_ini(char *path); +void config_write_ini_general(FILE *fp); +void config_write_ini_sound(FILE *fp); + /** * * rct2: 0x006E3604 @@ -136,6 +144,37 @@ void config_load() RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_METRIC, sint8) = gGeneral_config.measurement_format; RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_TEMPERATURE, sint8) = gGeneral_config.temperature_format; + // always show gridlines + if (gGeneral_config.always_show_gridlines){ + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) |= CONFIG_FLAG_ALWAYS_SHOW_GRIDLINES; + } + else { + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) &= !CONFIG_FLAG_ALWAYS_SHOW_GRIDLINES; + } + + // landscape smoothing + if (!gGeneral_config.landscape_smoothing){ + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) |= CONFIG_FLAG_DISABLE_SMOOTH_LANDSCAPE; + } + else { + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) &= !CONFIG_FLAG_DISABLE_SMOOTH_LANDSCAPE; + } + + // show height as units + if (gGeneral_config.show_height_as_units){ + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) |= CONFIG_FLAG_SHOW_HEIGHT_AS_UNITS; + } + else { + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) &= !CONFIG_FLAG_SHOW_HEIGHT_AS_UNITS; + } + + // save plugin data + if (gGeneral_config.save_plugin_data){ + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) |= CONFIG_FLAG_SAVE_PLUGIN_DATA; + } + else { + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) &= !CONFIG_FLAG_SAVE_PLUGIN_DATA; + } //sound configuration RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_QUALITY, sint8) = gSound_config.sound_quality; @@ -189,6 +228,7 @@ void config_load() RCT2_GLOBAL(0x009AA00D, sint8) = 1; } + /** * Save configuration to the data/config.cfg file * rct2: 0x00675487 @@ -196,14 +236,144 @@ void config_load() void config_save() { FILE *fp=NULL; + char *configIniPath = osinterface_get_orct2_homefolder();; + fp = fopen(get_file_path(PATH_ID_GAMECFG), "wb"); if (fp != NULL){ fwrite(&MagicNumber, 4, 1, fp); fwrite((void*)0x009AAC5C, 2155, 1, fp); fclose(fp); } + + sprintf(configIniPath, "%s%c%s", configIniPath, osinterface_get_path_separator(), "config.ini"); + config_save_ini(configIniPath); } +void config_save_ini(char *path) +{ + FILE *fp = NULL; + + + fp = fopen(path, "wt+"); + + config_write_ini_general(fp); + config_write_ini_sound(fp); + + fclose(fp); +} + +void config_write_ini_sound(FILE *fp) +{ + fprintf(fp, "[sound]\n"); + if (gSound_config.sound_quality == SOUND_QUALITY_LOW) { + fprintf(fp, "sound_quality = low\n"); + } + else if (gSound_config.sound_quality == SOUND_QUALITY_MEDIUM) { + fprintf(fp, "sound_quality = medium\n"); + } + else{ + fprintf(fp, "sound_quality = high\n"); + } + + if (gSound_config.forced_software_buffering){ + fprintf(fp, "forced_software_buffering = true\n"); + } + else { + fprintf(fp, "forced_software_buffering = false\n"); + } +} + +void config_write_ini_general(FILE *fp) +{ + int currencyIterator = 0; + + fprintf(fp, "[general]\n"); + fprintf(fp, "game_path = %s\n", gGeneral_config.game_path); + + switch (gGeneral_config.screenshot_format) + { + case SCREENSHOT_FORMAT_BMP: + fprintf(fp, "screenshot_format = BMP\n"); + break; + case SCREENSHOT_FORMAT_PNG: + fprintf(fp, "screenshot_format = PNG\n"); + break; + default: + config_error("error saving config.ini: wrong screenshot_format"); + break; + } + + if (gGeneral_config.play_intro){ + fprintf(fp, "play_intro = true\n"); + } + else { + fprintf(fp, "play_intro = false\n"); + } + + if (gGeneral_config.confirmation_prompt){ + fprintf(fp, "confirmation_prompt = true\n"); + } + else { + fprintf(fp, "confirmation_prompt = false\n"); + } + + if (gGeneral_config.edge_scrolling){ + fprintf(fp, "edge_scrolling = true\n"); + } + else { + fprintf(fp, "edge_scrolling = false\n"); + } + + for (currencyIterator = 0; currencyIterator < countof(_currencyLookupTable); currencyIterator++) { + if (_currencyLookupTable[currencyIterator].value == gGeneral_config.currency_format) { + gGeneral_config.currency_format = _currencyLookupTable[currencyIterator].value; + fprintf(fp, "currency = %s\n", _currencyLookupTable[currencyIterator].key); + break; // There are more than one valid item for Pound, Euro and Dollar ... + } + } + + if (gGeneral_config.measurement_format == MEASUREMENT_FORMAT_IMPERIAL) { + fprintf(fp, "measurement_format = imperial\n"); + } + else { + fprintf(fp, "measurement_format = metric\n"); + } + + if (gGeneral_config.temperature_format == TEMPERATURE_FORMAT_F) { + fprintf(fp, "temperature_format = fahrenheit\n"); + } + else { + fprintf(fp, "temperature_format = celsius\n"); + } + + if (gGeneral_config.always_show_gridlines){ + fprintf(fp, "always_show_gridlines = true\n"); + } + else { + fprintf(fp, "always_show_gridlines = false\n"); + } + + if (gGeneral_config.landscape_smoothing){ + fprintf(fp, "landscape_smoothing = true\n"); + } + else { + fprintf(fp, "landscape_smoothing = false\n"); + } + + if (gGeneral_config.show_height_as_units){ + fprintf(fp, "show_height_as_units = true\n"); + } + else { + fprintf(fp, "show_height_as_units = false\n"); + } + + if (gGeneral_config.save_plugin_data){ + fprintf(fp, "save_plugin_data = true\n"); + } + else { + fprintf(fp, "save_plugin_data = false\n"); + } +} /** * Initilise the settings. @@ -278,8 +448,7 @@ static int config_find_rct2_path(char *resultPath) */ static void config_create_default(char *path) { - FILE* fp; - + gGeneral_config = gGeneral_config_default; if (!config_find_rct2_path(gGeneral_config.game_path)) { osinterface_show_messagebox("Unable to find RCT2 installation directory. Please select the directory where you installed RCT2!"); @@ -287,20 +456,7 @@ static void config_create_default(char *path) strcpy(gGeneral_config.game_path, res); } - fp = fopen(path, "w"); - fprintf(fp, "[general]\n"); - fprintf(fp, "game_path = %s\n", gGeneral_config.game_path); - fprintf(fp, "screenshot_format = PNG\n"); - fprintf(fp, "play_intro = false\n"); - fprintf(fp, "confirmation_prompt = true\n"); - fprintf(fp, "edge_scrolling = true\n"); - fprintf(fp, "currency = GBP\n"); - fprintf(fp, "measurement_format = imperial\n"); - fprintf(fp, "temperature_format = fahrenheit\n"); - fprintf(fp, "[sound]\n"); - fprintf(fp, "sound_quality = high\n"); - fprintf(fp, "forced_software_buffering = false\n"); - fclose(fp); + config_save_ini(path); } @@ -415,7 +571,38 @@ static void config_general(char *setting, char *value){ else if (strcmp(setting, "currency") == 0){ config_parse_currency(value); } - + else if (strcmp(setting, "always_show_gridlines") == 0){ + if (strcmp(value, "true") == 0){ + gGeneral_config.always_show_gridlines = 1; + } + else { + gGeneral_config.always_show_gridlines = 0; + } + } + else if (strcmp(setting, "landscape_smoothing") == 0){ + if (strcmp(value, "true") == 0){ + gGeneral_config.landscape_smoothing = 1; + } + else { + gGeneral_config.landscape_smoothing = 0; + } + } + else if (strcmp(setting, "show_height_as_units") == 0){ + if (strcmp(value, "true") == 0){ + gGeneral_config.show_height_as_units = 1; + } + else { + gGeneral_config.show_height_as_units = 0; + } + } + else if (strcmp(setting, "save_plugin_data") == 0){ + if (strcmp(value, "true") == 0){ + gGeneral_config.save_plugin_data = 1; + } + else { + gGeneral_config.save_plugin_data = 0; + } + } } /** @@ -588,25 +775,6 @@ static int config_parse_section(FILE *fp, char *setting, char *value){ return 1; } -static const struct { char *key; int value; } _currencyLookupTable[] = { - { "GBP", CURRENCY_POUNDS }, - { "USD", CURRENCY_DOLLARS }, - { "FRF", CURRENCY_FRANC }, - { "DEM", CURRENCY_DEUTSCHMARK }, - { "YEN", CURRENCY_YEN }, - { "ESP", CURRENCY_PESETA }, - { "ITL", CURRENCY_LIRA }, - { "NLG", CURRENCY_GUILDERS }, - { "NOK", CURRENCY_KRONA }, - { "SEK", CURRENCY_KRONA }, - { "DEK", CURRENCY_KRONA }, - { "EUR", CURRENCY_EUROS }, - - { "£", CURRENCY_POUNDS }, - { "$", CURRENCY_DOLLARS }, - { "€", CURRENCY_EUROS } -}; - static int config_parse_currency(char *currency) { int i; diff --git a/src/config.h b/src/config.h index eb86ab5da2..6e43a04b4e 100644 --- a/src/config.h +++ b/src/config.h @@ -136,9 +136,31 @@ typedef struct general_configuration { sint8 currency_format; sint8 construction_marker_colour; sint8 edge_scrolling; - + sint8 always_show_gridlines; + sint8 landscape_smoothing; + sint8 show_height_as_units; + sint8 save_plugin_data; } general_configuration_t; +static const struct { char *key; int value; } _currencyLookupTable[] = { + { "GBP", CURRENCY_POUNDS }, + { "USD", CURRENCY_DOLLARS }, + { "FRF", CURRENCY_FRANC }, + { "DEM", CURRENCY_DEUTSCHMARK }, + { "YEN", CURRENCY_YEN }, + { "ESP", CURRENCY_PESETA }, + { "ITL", CURRENCY_LIRA }, + { "NLG", CURRENCY_GUILDERS }, + { "NOK", CURRENCY_KRONA }, + { "SEK", CURRENCY_KRONA }, + { "DEK", CURRENCY_KRONA }, + { "EUR", CURRENCY_EUROS }, + + { "£", CURRENCY_POUNDS }, + { "$", CURRENCY_DOLLARS }, + { "€", CURRENCY_EUROS } +}; + //typedef struct hotkey_configuration{ //}; diff --git a/src/window_options.c b/src/window_options.c index edc4730f25..fa0824904e 100644 --- a/src/window_options.c +++ b/src/window_options.c @@ -223,6 +223,7 @@ static void window_options_mouseup() break; case WIDX_SCREEN_EDGE_SCROLLING: RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_EDGE_SCROLLING, uint8) ^= 1; + gGeneral_config.edge_scrolling ^= 1; config_save(); window_invalidate(w); break; @@ -248,11 +249,15 @@ static void window_options_mouseup() break; case WIDX_TILE_SMOOTHING_CHECKBOX: RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) ^= CONFIG_FLAG_DISABLE_SMOOTH_LANDSCAPE; + gGeneral_config.landscape_smoothing = !(RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) + & CONFIG_FLAG_DISABLE_SMOOTH_LANDSCAPE); config_save(); gfx_invalidate_screen(); break; case WIDX_GRIDLINES_CHECKBOX: RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) ^= CONFIG_FLAG_ALWAYS_SHOW_GRIDLINES; + gGeneral_config.always_show_gridlines = RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) + & CONFIG_FLAG_ALWAYS_SHOW_GRIDLINES; config_save(); gfx_invalidate_screen(); @@ -265,12 +270,15 @@ static void window_options_mouseup() break; case WIDX_SAVE_PLUGIN_DATA_CHECKBOX: RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) ^= CONFIG_FLAG_SAVE_PLUGIN_DATA; + gGeneral_config.save_plugin_data = !(RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) + & CONFIG_FLAG_SAVE_PLUGIN_DATA); config_save(); window_invalidate(w); break; case WIDX_SOUND_SW_BUFFER_CHECKBOX: pause_sounds(); RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER, uint8) ^= 1; + gSound_config.forced_software_buffering ^= 1; config_save(); unpause_sounds(); window_invalidate(w); @@ -445,9 +453,12 @@ static void window_options_dropdown() case WIDX_HEIGHT_LABELS_DROPDOWN: // reset flag and set it to 1 if height as units is selected RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) &= ~CONFIG_FLAG_SHOW_HEIGHT_AS_UNITS; + gGeneral_config.show_height_as_units = 0; - if (dropdownIndex == 0) - RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) |= CONFIG_FLAG_SHOW_HEIGHT_AS_UNITS; + if (dropdownIndex == 0) { + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) |= CONFIG_FLAG_SHOW_HEIGHT_AS_UNITS; + gGeneral_config.show_height_as_units = 1; + } window_options_update_height_markers(); break; @@ -463,17 +474,20 @@ static void window_options_dropdown() // TODO: no clue what this does (and if it's correct) RCT2_GLOBAL(0x009AAC75, uint8) = RCT2_GLOBAL(0x009AF601 + dropdownIndex, uint8); RCT2_GLOBAL(0x009AAC76, uint8) = RCT2_GLOBAL(0x009AF604 + dropdownIndex, uint8); - + gSound_config.sound_quality = (sint8)dropdownIndex; config_save(); window_invalidate(w); break; case WIDX_CURRENCY_DROPDOWN: RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_CURRENCY, uint8) = dropdownIndex | 0xC0; + gGeneral_config.currency_format = (sint8)dropdownIndex; config_save(); gfx_invalidate_screen(); break; case WIDX_DISTANCE_DROPDOWN: RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_METRIC, uint8) = (uint8)dropdownIndex; + gGeneral_config.measurement_format = (sint8)dropdownIndex; + config_save(); window_options_update_height_markers(); break; case WIDX_RESOLUTION_DROPDOWN: @@ -488,6 +502,7 @@ static void window_options_dropdown() case WIDX_TEMPERATURE_DROPDOWN: if (dropdownIndex != RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_TEMPERATURE, uint8)) { RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_TEMPERATURE, uint8) = (uint8)dropdownIndex; + gGeneral_config.temperature_format = (sint8)dropdownIndex; config_save(); gfx_invalidate_screen(); }