From 53a241d19733dfd908046d60a7ed7be8d0a19202 Mon Sep 17 00:00:00 2001 From: Robert Jordan Date: Sat, 30 May 2015 11:52:08 -0400 Subject: [PATCH] Finished ini file loading and removed warnings --- data/language/english_uk.txt | 5 + src/config.c | 131 ++++++++++++++---------- src/interface/colour_schemes.c | 64 ++++++++++-- src/interface/colour_schemes.h | 5 +- src/interface/window.h | 6 +- src/windows/colour_schemes.c | 182 +++++++++++++++++++++++++++------ src/windows/staff.c | 6 +- 7 files changed, 294 insertions(+), 105 deletions(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index d4cbaac9f7..0a36350196 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -3572,3 +3572,8 @@ STR_5235 :{SMALLFONT}{BLACK}Settings STR_5236 :Window: STR_5237 :Palette: STR_5238 :Presets: +STR_5239 :Duplicate +STR_5240 :Enter a name for the colour scheme +STR_5241 :Can't change this preset +STR_5242 :Preset name already exists +STR_5243 :Invalid characters used diff --git a/src/config.c b/src/config.c index 7c44868775..65c4ef0038 100644 --- a/src/config.c +++ b/src/config.c @@ -450,7 +450,7 @@ bool config_get_section(const utf8string line, const utf8 **sectionName, int *se return true; } -bool config_get_property_name_value(const utf8string line, const utf8 **propertyName, int *propertyNameSize, const utf8 **value, int *valueSize) +bool config_get_property_name_value(const utf8string line, utf8 **propertyName, int *propertyNameSize, utf8 **value, int *valueSize) { utf8 *ch; int c, lastC; @@ -583,7 +583,7 @@ static void config_read_properties(config_section_definition **currentSection, c *currentSection = config_get_section_def(sectionName, sectionNameSize); } else { if (*currentSection != NULL) { - const utf8 *propertyName, *value; + utf8 *propertyName, *value; int propertyNameSize, valueSize; if (config_get_property_name_value(ch, &propertyName, &propertyNameSize, &value, &valueSize)) { config_property_definition *property; @@ -1002,34 +1002,28 @@ bool config_shortcut_keys_save() #pragma region Colour Schemes - +static void colour_schemes_remove_extension(char *path); static bool colour_schemes_open(const utf8string path); -static bool colour_schemes_save(const utf8string path); -static void colour_schemes_read_properties(int preset, window_colour_scheme **colour_scheme, const_utf8string line); -static void colour_schemes_set_property(window_colour_scheme **colour_scheme, const_utf8string line); +static bool colour_schemes_save(const utf8string path, int preset); +static void colour_schemes_read_properties(int preset, window_colours **current_window_colours, const_utf8string line); +static void colour_schemes_set_property(window_colours *colour_scheme, utf8string name, utf8string value); -void colour_schemes_remove_extension(char *path) -{ - char *ch; - - for (ch = path; *ch != 0; ch++) { - if (*ch == '.') { - *ch = '\0'; - break; - } - } -} - void colour_schemes_set_default() { + + utf8 path[MAX_PATH]; + + platform_get_user_directory(path, "colour schemes"); + platform_ensure_directory_exists(path); + gConfigColourSchemes.num_presets = 2; - gConfigColourSchemes.presets = malloc(sizeof(colour_scheme_preset*) * gConfigColourSchemes.num_presets); + gConfigColourSchemes.presets = malloc(sizeof(colour_scheme_preset) * gConfigColourSchemes.num_presets); // Set RCT2 colour scheme strcpy(gConfigColourSchemes.presets[0].name, language_get_string(2741)); gConfigColourSchemes.presets[0].colour_schemes = malloc(sizeof(window_colours) * gNumColourSchemeWindows); - for (int i = 0; i < gNumColourSchemeWindows; i++) { + for (int i = 0; i < (int)gNumColourSchemeWindows; i++) { for (int j = 0; j < 6; j++) gConfigColourSchemes.presets[0].colour_schemes[i].colours[j] = gColourSchemes[i].colours[j]; } @@ -1037,10 +1031,10 @@ void colour_schemes_set_default() // Set RCT1 colour scheme strcpy(gConfigColourSchemes.presets[1].name, language_get_string(2740)); gConfigColourSchemes.presets[1].colour_schemes = malloc(sizeof(window_colours) * gNumColourSchemeWindows); - for (int i = 0; i < gNumColourSchemeWindows; i++) { + for (int i = 0; i < (int)gNumColourSchemeWindows; i++) { uint8 changed_colour = 0xFF; for (int k = 0; gColourSchemesRCT1[k].classification != 0xFF; k++) { - if (gColourSchemesRCT1[k].classification == gColourSchemes[k].classification) { + if (gColourSchemesRCT1[k].classification == gColourSchemes[i].classification) { changed_colour = (uint8)k; break; } @@ -1055,15 +1049,35 @@ void colour_schemes_load_presets() { utf8 path[MAX_PATH]; file_info file; - int fileEnumHandle; + int fileEnumHandle, i; platform_get_user_directory(path, "colour schemes"); - strcpy(path, "*.ini"); + strcat(path, "*.ini"); fileEnumHandle = platform_enumerate_files_begin(path); while (platform_enumerate_files_next(fileEnumHandle, &file)) { - colour_schemes_open(file.path); + platform_get_user_directory(path, "colour schemes"); + strcat(path, file.path); + colour_schemes_open(path); } platform_enumerate_files_end(fileEnumHandle); + + if (strcmp(gConfigGeneral.current_colour_scheme_preset, "*RCT2") == 0) { + colour_scheme_change_preset(0); + } + else if (strcmp(gConfigGeneral.current_colour_scheme_preset, "*RCT1") == 0) { + colour_scheme_change_preset(1); + } + else { + for (i = 2; i < gConfigColourSchemes.num_presets; i++) { + if (strcmp(gConfigGeneral.current_colour_scheme_preset, gConfigColourSchemes.presets[i].name) == 0) { + colour_scheme_change_preset(i); + break; + } + } + if (i == gConfigColourSchemes.num_presets) { + colour_scheme_change_preset(0); + } + } } bool colour_schemes_save_preset(int preset) @@ -1071,8 +1085,9 @@ bool colour_schemes_save_preset(int preset) utf8 path[MAX_PATH]; platform_get_user_directory(path, "colour schemes"); - strcat(path, "custom.ini"); - if (config_save(path)) { + strcat(path, gConfigColourSchemes.presets[preset].name); + strcat(path, ".ini"); + if (colour_schemes_save(path, preset)) { return true; } @@ -1086,7 +1101,7 @@ bool colour_schemes_open(const utf8string path) size_t lineBufferCapacity; size_t lineLength; int c, preset; - window_colour_scheme *currentColourScheme; + window_colours *currentColourScheme; file = fopen(path, "rb"); if (file == NULL) @@ -1102,10 +1117,11 @@ bool colour_schemes_open(const utf8string path) // Otherwise allocate one if (preset == gConfigColourSchemes.num_presets) { gConfigColourSchemes.num_presets++; - gConfigColourSchemes.presets = realloc(gConfigColourSchemes.presets, sizeof(colour_scheme_preset*) * gConfigColourSchemes.num_presets); + gConfigColourSchemes.presets = realloc(gConfigColourSchemes.presets, sizeof(colour_scheme_preset) * gConfigColourSchemes.num_presets); strcpy(gConfigColourSchemes.presets[preset].name, path_get_filename(path)); + colour_schemes_remove_extension(gConfigColourSchemes.presets[preset].name); gConfigColourSchemes.presets[preset].colour_schemes = malloc(sizeof(window_colours) * gNumColourSchemeWindows); - for (int i = 0; i < gNumColourSchemeWindows; i++) { + for (int i = 0; i < (int)gNumColourSchemeWindows; i++) { for (int j = 0; j < 6; j++) gConfigColourSchemes.presets[preset].colour_schemes[i].colours[j] = gColourSchemes[i].colours[j]; } @@ -1147,11 +1163,10 @@ bool colour_schemes_open(const utf8string path) return true; } -static bool colour_schemes_save(const utf8string path) +static bool colour_schemes_save(const utf8string path, int preset) { FILE *file; - int i, j, preset; - value_union *value; + int i, j; file = fopen(path, "wb"); if (file == NULL) { @@ -1159,25 +1174,16 @@ static bool colour_schemes_save(const utf8string path) return false; } - for (preset = 2; preset < gConfigColourSchemes.num_presets; preset++) { - if (strcmp(path, gConfigColourSchemes.presets[preset].name) == 0) { - break; - } - } - if (preset == gConfigColourSchemes.num_presets) { - log_error("Unable to write colour scheme, no preset with that name found."); - return false; - } - - for (i = 0; i < gNumColourSchemeWindows; i++) { - window_colour_scheme* colour_scheme = &(gColourSchemes[i]); + for (i = 0; i < (int)gNumColourSchemeWindows; i++) { + window_colour_scheme* colour_scheme_info = &gColourSchemes[i]; + window_colours* colour_scheme = &gConfigColourSchemes.presets[preset].colour_schemes[i]; fputc('[', file); - fwrite(colour_scheme->section_name, strlen(colour_scheme->section_name), 1, file); + fwrite(colour_scheme_info->section_name, strlen(colour_scheme_info->section_name), 1, file); fputc(']', file); fputc('\n', file); - for (j = 0; j < colour_scheme->num_colours; j++) { + for (j = 0; j < colour_scheme_info->num_colours; j++) { fprintf(file, "colour_%d", j); fwrite(" = ", 3, 1, file); @@ -1191,18 +1197,19 @@ static bool colour_schemes_save(const utf8string path) return true; } - -static void colour_schemes_read_properties(int preset, window_colour_scheme **colour_scheme, const_utf8string line) +static void colour_schemes_read_properties(int preset, window_colours **colour_scheme, const_utf8string line) { utf8string ch = (utf8string)line; utf8_skip_whitespace(&ch); if (*ch == '[') { - const_utf8string sectionName; + utf8string sectionName; int sectionNameSize; if (config_get_section(ch, §ionName, §ionNameSize)) { - for (int i = 0; i < gNumColourSchemeWindows; i++) { - if (strcmp(sectionName, gColourSchemes[i].section_name)) { + printf("%s\n", sectionName); + sectionName[strlen(sectionName) - 1] = '\0'; + for (int i = 0; i < (int)gNumColourSchemeWindows; i++) { + if (strcmp(sectionName, gColourSchemes[i].section_name) == 0) { *colour_scheme = &(gConfigColourSchemes.presets[preset].colour_schemes[i]); break; } @@ -1211,17 +1218,17 @@ static void colour_schemes_read_properties(int preset, window_colour_scheme **co } else { if (*colour_scheme != NULL) { - const_utf8string propertyName, *value; + utf8string propertyName, value; int propertyNameSize, valueSize; if (config_get_property_name_value(ch, &propertyName, &propertyNameSize, &value, &valueSize)) { - colour_schemes_set_property(colour_scheme, propertyName, value); + propertyName[propertyNameSize] = '\0'; + colour_schemes_set_property(*colour_scheme, propertyName, value); } } } } - -static void colour_schemes_set_property(window_colour_scheme *colour_scheme, const_utf8string name, const_utf8string value) +static void colour_schemes_set_property(window_colours *colour_scheme, utf8string name, utf8string value) { const_utf8string colour_names[] = { "colour_0", "colour_1", "colour_2", "colour_3", "colour_4", "colour_5" }; @@ -1232,4 +1239,16 @@ static void colour_schemes_set_property(window_colour_scheme *colour_scheme, con } } +static void colour_schemes_remove_extension(char *path) +{ + char *ch; + + for (ch = path; *ch != 0; ch++) { + if (*ch == '.') { + *ch = '\0'; + break; + } + } +} + #pragma endregion \ No newline at end of file diff --git a/src/interface/colour_schemes.c b/src/interface/colour_schemes.c index f4c71d6bf0..0bb8eab1f7 100644 --- a/src/interface/colour_schemes.c +++ b/src/interface/colour_schemes.c @@ -110,6 +110,16 @@ window_colour_scheme* colour_scheme_get_by_class(rct_windowclass classification) return NULL; } +int colour_scheme_get_index_by_class(rct_windowclass classification) +{ + for (int i = 0; i < sizeof(gColourSchemes); i++) { + if (gColourSchemes[i].classification == classification) { + return i; + } + } + return -1; +} + void colour_scheme_update(rct_window *window) { @@ -122,10 +132,10 @@ void colour_scheme_update(rct_window *window) transparent = true; } } - if (transparent) + //if (transparent) window->flags |= WF_TRANSPARENT; - else - window->flags &= ~WF_TRANSPARENT; + //else + // window->flags &= ~WF_TRANSPARENT; } void colour_scheme_update_by_class(rct_window *window, rct_windowclass classification) @@ -139,10 +149,10 @@ void colour_scheme_update_by_class(rct_window *window, rct_windowclass classific transparent = true; } } - if (transparent) + //if (transparent) window->flags |= WF_TRANSPARENT; - else - window->flags &= ~WF_TRANSPARENT; + //else + // window->flags &= ~WF_TRANSPARENT; } void colour_scheme_change_preset(int preset) @@ -160,7 +170,7 @@ void colour_scheme_change_preset(int preset) break; } gCurrentColourSchemePreset = preset; - for (int i = 0; i < gNumColourSchemeWindows; i++) { + for (int i = 0; i < (int)gNumColourSchemeWindows; i++) { for (int j = 0; j < gColourSchemes[i].num_colours; j++) { gColourSchemes[i].colours[j] = gConfigColourSchemes.presets[preset].colour_schemes[i].colours[j]; } @@ -169,17 +179,49 @@ void colour_scheme_change_preset(int preset) window_invalidate_all(); } -bool colour_scheme_create_preset(const char *name) +void colour_scheme_create_preset(const char *name) { int preset = gConfigColourSchemes.num_presets; gConfigColourSchemes.num_presets++; - gConfigColourSchemes.presets = realloc(gConfigColourSchemes.presets, sizeof(colour_scheme_preset*) * gConfigColourSchemes.num_presets); + gConfigColourSchemes.presets = realloc(gConfigColourSchemes.presets, sizeof(colour_scheme_preset) * gConfigColourSchemes.num_presets); strcpy(gConfigColourSchemes.presets[preset].name, name); gConfigColourSchemes.presets[preset].colour_schemes = malloc(sizeof(window_colours) * gNumColourSchemeWindows); - for (int i = 0; i < gNumColourSchemeWindows; i++) { + for (int i = 0; i < (int)gNumColourSchemeWindows; i++) { for (int j = 0; j < 6; j++) gConfigColourSchemes.presets[preset].colour_schemes[i].colours[j] = gColourSchemes[i].colours[j]; } colour_schemes_save_preset(preset); - colour_scheme_change_preset(gConfigColourSchemes.num_presets - 1); + colour_scheme_change_preset(preset); +} + +void colour_scheme_delete_preset(int preset) +{ + if (preset >= 2) + { + utf8 path[MAX_PATH]; + platform_get_user_directory(path, "colour schemes"); + strcat(path, gConfigColourSchemes.presets[preset].name); + strcat(path, ".ini"); + platform_file_delete(path); + + for (int i = preset; i < gConfigColourSchemes.num_presets - 1; i++) { + gConfigColourSchemes.presets[i] = gConfigColourSchemes.presets[i + 1]; + } + gConfigColourSchemes.num_presets--; + colour_scheme_change_preset(0); + } +} + +void colour_scheme_rename_preset(int preset, const char *newName) +{ + utf8 src[MAX_PATH], dest[MAX_PATH]; + platform_get_user_directory(src, "colour schemes"); + platform_get_user_directory(dest, "colour schemes"); + strcat(src, gConfigColourSchemes.presets[preset].name); + strcat(dest, newName); + strcat(src, ".ini"); + strcat(dest, ".ini"); + platform_file_move(src, dest); + + strcpy(gConfigColourSchemes.presets[gCurrentColourSchemePreset].name, newName); } diff --git a/src/interface/colour_schemes.h b/src/interface/colour_schemes.h index a453e987e3..f88e1a7c77 100644 --- a/src/interface/colour_schemes.h +++ b/src/interface/colour_schemes.h @@ -47,11 +47,14 @@ extern uint16 gCurrentColourSchemePreset; extern uint32 gNumColourSchemeWindows; window_colour_scheme* colour_scheme_get_by_class(rct_windowclass classification); +int colour_scheme_get_index_by_class(rct_windowclass classification); void colour_scheme_update(rct_window *window); void colour_scheme_update_by_class(rct_window *window, rct_windowclass classification); void colour_scheme_change_preset(int preset); -bool colour_scheme_create_preset(const char *name); +void colour_scheme_create_preset(const char *name); +void colour_scheme_delete_preset(int preset); +void colour_scheme_rename_preset(int preset, const char *newName); #endif \ No newline at end of file diff --git a/src/interface/window.h b/src/interface/window.h index 93bbfce7d4..64ad903235 100644 --- a/src/interface/window.h +++ b/src/interface/window.h @@ -408,9 +408,9 @@ enum { WC_COLOUR_SCHEMES = 119, // Only used for colour schemes - WC_STAFF = 1020, - WC_EDITOR_TRACK_BOTTOM_TOOLBAR = 1021, - WC_EDITOR_SCENARIO_BOTTOM_TOOLBAR = 1022, + WC_STAFF = 220, + WC_EDITOR_TRACK_BOTTOM_TOOLBAR = 221, + WC_EDITOR_SCENARIO_BOTTOM_TOOLBAR = 222, } WINDOW_CLASS; enum PROMPT_MODE { diff --git a/src/windows/colour_schemes.c b/src/windows/colour_schemes.c index b2e91376ce..02cad82d1f 100644 --- a/src/windows/colour_schemes.c +++ b/src/windows/colour_schemes.c @@ -33,6 +33,7 @@ #include "../sprites.h" #include "dropdown.h" #include "../interface/colour_schemes.h" +#include "error.h" enum { WINDOW_COLOUR_SCHEMES_TAB_MAIN_UI, @@ -55,6 +56,7 @@ static void window_colour_schemes_update(rct_window *w); static void window_colour_schemes_scrollgetsize(); static void window_colour_schemes_scrollmousedown(); static void window_colour_schemes_scrollmouseover(); +static void window_colour_schemes_textinput(); static void window_colour_schemes_tooltip(); static void window_colour_schemes_invalidate(); static void window_colour_schemes_paint(); @@ -81,7 +83,7 @@ static void* window_colour_schemes_events[] = { window_colour_schemes_scrollmousedown, window_colour_schemes_emptysub, window_colour_schemes_scrollmouseover, - window_colour_schemes_emptysub, + window_colour_schemes_textinput, window_colour_schemes_emptysub, window_colour_schemes_emptysub, window_colour_schemes_tooltip, @@ -107,6 +109,9 @@ enum WINDOW_STAFF_LIST_WIDGET_IDX { WIDX_COLOUR_SCHEMES_SETTINGS_TAB, WIDX_COLOUR_SCHEMES_PRESETS, WIDX_COLOUR_SCHEMES_PRESETS_DROPDOWN, + WIDX_COLOUR_SCHEMES_DUPLICATE_BUTTON, + WIDX_COLOUR_SCHEMES_DELETE_BUTTON, + WIDX_COLOUR_SCHEMES_RENAME_BUTTON, WIDX_COLOUR_SCHEMES_COLORBTN_MASK, WIDX_COLOUR_SCHEMES_LIST, }; @@ -126,6 +131,9 @@ static rct_widget window_colour_schemes_widgets[] = { { WWT_TAB, 1, 220, 250, 17, 43, 0x02000144E, 5235 }, // settings tab { WWT_DROPDOWN, 1, 125, 299, 60, 71, STR_NONE, STR_NONE }, // Preset colour schemes { WWT_DROPDOWN_BUTTON, 1, 288, 298, 61, 70, 876, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 10, 100, 82, 93, 5239, STR_NONE }, // Duplicate button + { WWT_DROPDOWN_BUTTON, 1, 110, 200, 82, 93, 3349, STR_NONE }, // Delete button + { WWT_DROPDOWN_BUTTON, 1, 210, 300, 82, 93, 3348, STR_NONE }, // Rename button { WWT_COLORBTN, 1, 0, 0, 0, 0, STR_NONE, STR_NONE }, // color button mask { WWT_SCROLL, 1, 3, 316, 60, 266, 2, STR_NONE }, // staff list { WIDGETS_END }, @@ -290,6 +298,19 @@ static int get_colour_scheme_tab_count() return 0; } +static int get_colour_scheme_index() { + switch (_selected_tab) { + case 0: return colour_scheme_get_index_by_class(window_colour_schemes_tab_1_classes[_color_index_1]); + case 1: return colour_scheme_get_index_by_class(window_colour_schemes_tab_2_classes[_color_index_1]); + case 2: return colour_scheme_get_index_by_class(window_colour_schemes_tab_3_classes[_color_index_1]); + case 3: return colour_scheme_get_index_by_class(window_colour_schemes_tab_4_classes[_color_index_1]); + case 4: return colour_scheme_get_index_by_class(window_colour_schemes_tab_5_classes[_color_index_1]); + case 5: return colour_scheme_get_index_by_class(window_colour_schemes_tab_6_classes[_color_index_1]); + case 6: return colour_scheme_get_index_by_class(window_colour_schemes_tab_7_classes[_color_index_1]); + } + return -1; +} + static void window_colour_schemes_draw_tab_images(rct_drawpixelinfo *dpi, rct_window *w) { int sprite_idx; @@ -325,7 +346,10 @@ void window_colour_schemes_open() (1 << WIDX_COLOUR_SCHEMES_SETTINGS_TAB) | (1 << WIDX_COLOUR_SCHEMES_COLORBTN_MASK) | (1 << WIDX_COLOUR_SCHEMES_PRESETS) | - (1 << WIDX_COLOUR_SCHEMES_PRESETS_DROPDOWN); + (1 << WIDX_COLOUR_SCHEMES_PRESETS_DROPDOWN) | + (1 << WIDX_COLOUR_SCHEMES_DUPLICATE_BUTTON) | + (1 << WIDX_COLOUR_SCHEMES_DELETE_BUTTON) | + (1 << WIDX_COLOUR_SCHEMES_RENAME_BUTTON); window_colour_schemes_widgets[WIDX_COLOUR_SCHEMES_LIST].type = WWT_SCROLL; @@ -368,15 +392,32 @@ static void window_colour_schemes_resize() window_get_register(w); - w->min_width = 320; - w->min_height = 270; - if (w->width < w->min_width) { - w->width = w->min_width; - window_invalidate(w); + if (_selected_tab == WINDOW_COLOUR_SCHEMES_TAB_SETTINGS) { + window_set_resize(w, 320, 107, 320, 107); + gfx_invalidate_screen(); } - if (w->height < w->min_height) { - w->height = w->min_height; - window_invalidate(w); + else { + w->min_width = 320; + w->min_height = 270; + w->max_width = 320; + w->max_height = 450; + + if (w->width < w->min_width) { + w->width = w->min_width; + window_invalidate(w); + } + if (w->height < w->min_height) { + w->height = w->min_height; + window_invalidate(w); + } + if (w->width > w->max_width) { + w->width = w->max_width; + window_invalidate(w); + } + if (w->height > w->max_height) { + w->height = w->max_height; + window_invalidate(w); + } } } @@ -394,24 +435,30 @@ static void window_colour_schemes_mousedown(int widgetIndex, rct_window* w, rct_ case WIDX_COLOUR_SCHEMES_MISC_TAB: case WIDX_COLOUR_SCHEMES_PROMPTS_TAB: case WIDX_COLOUR_SCHEMES_SETTINGS_TAB: + /*if (widgetIndex == WIDX_COLOUR_SCHEMES_SETTINGS_TAB) { + window_set_resize(w, 320, 100, 320, 100); + w->flags &= ~WF_RESIZABLE; + } + else if (_selected_tab == WINDOW_COLOUR_SCHEMES_TAB_SETTINGS) { + w->flags |= WF_RESIZABLE; + window_set_resize(w, 320, 270, 320, 450); + }*/ newSelectedTab = widgetIndex - WIDX_COLOUR_SCHEMES_MAIN_UI_TAB; if (_selected_tab == newSelectedTab) break; _selected_tab = (uint8)newSelectedTab; w->scrolls[0].v_top = 0; w->frame_no = 0; + window_event_resize_call(w); window_invalidate(w); break; case WIDX_COLOUR_SCHEMES_PRESETS_DROPDOWN: num_items = gConfigColourSchemes.num_presets; + widget--; for (i = 0; i < num_items; i++) { - //gDropdownItemsFormat[i] = 2777; - //gDropdownItemsArgs[i] = 1170 | ((uint64)(intptr_t)gConfigColourSchemes.presets[i].name << 16); - //gDropdownItemsFormat[i] = 1170; - //gDropdownItemsArgs[i] = ((uint64)&gConfigColourSchemes.presets[i].name) << 32; - gDropdownItemsFormat[i] = 1170; - gDropdownItemsArgs[i] = &gConfigColourSchemes.presets[i].name; + gDropdownItemsFormat[i] = 2777; + gDropdownItemsArgs[i] = (uint64)&gConfigColourSchemes.presets[i].name; } window_dropdown_show_text_custom_width( @@ -426,6 +473,25 @@ static void window_colour_schemes_mousedown(int widgetIndex, rct_window* w, rct_ gDropdownItemsChecked = 1 << gCurrentColourSchemePreset; break; + case WIDX_COLOUR_SCHEMES_DUPLICATE_BUTTON: + window_text_input_open(w, widgetIndex, 5239, 5240, 1170, (rct_string_id)&gConfigColourSchemes.presets[gCurrentColourSchemePreset].name, 64); + break; + case WIDX_COLOUR_SCHEMES_DELETE_BUTTON: + if (gCurrentColourSchemePreset >= 2) { + colour_scheme_delete_preset(gCurrentColourSchemePreset); + } + else { + window_error_open(5241, STR_NONE); + } + break; + case WIDX_COLOUR_SCHEMES_RENAME_BUTTON: + if (gCurrentColourSchemePreset >= 2) { + window_text_input_open(w, widgetIndex, 3348, 5240, 1170, (rct_string_id)&gConfigColourSchemes.presets[gCurrentColourSchemePreset].name, 64); + } + else { + window_error_open(5241, STR_NONE); + } + break; } } @@ -439,15 +505,20 @@ static void window_colour_schemes_dropdown() case WIDX_COLOUR_SCHEMES_LIST: if (dropdownIndex != -1) { get_colour_scheme_tab()->colours[_color_index_2] = dropdownIndex | get_colour_scheme_tab()->colours[_color_index_2] & 0x80; + gConfigColourSchemes.presets[gCurrentColourSchemePreset].colour_schemes[get_colour_scheme_index()].colours[_color_index_2] = dropdownIndex | get_colour_scheme_tab()->colours[_color_index_2] & 0x80; window_invalidate_all(); _color_index_1 = -1; _color_index_2 = -1; + + if (gCurrentColourSchemePreset >= 2) + colour_schemes_save_preset(gCurrentColourSchemePreset); } break; case WIDX_COLOUR_SCHEMES_PRESETS_DROPDOWN: if (dropdownIndex != -1) { colour_scheme_change_preset(dropdownIndex); } + config_save_default(); break; } @@ -464,8 +535,6 @@ void window_colour_schemes_update(rct_window *w) } void window_colour_schemes_scrollgetsize() { - int spriteIndex; - rct_peep *peep; rct_window *w; window_get_register(w); @@ -493,18 +562,14 @@ void window_colour_schemes_scrollgetsize() { } void window_colour_schemes_scrollmousedown() { - int i, spriteIndex; short x, y, scrollIndex; - uint8 selectedTab; rct_window *w; - rct_drawpixelinfo *dpi; window_scrollmouse_get_registers(w, scrollIndex, x, y); if (_selected_tab == 7) return; - selectedTab = _selected_tab; if (y / _row_height < get_colour_scheme_tab_count()) { int y2 = y % _row_height; _color_index_1 = y / _row_height; @@ -518,10 +583,17 @@ void window_colour_schemes_scrollmousedown() { window_dropdown_show_colour(w, &(window_colour_schemes_widgets[WIDX_COLOUR_SCHEMES_COLORBTN_MASK]), w->colours[1], get_colour_scheme_tab()->colours[_color_index_2]); } else if (x >= _button_offset_x && x < _button_offset_x + 12 * 6 - 1 && y2 >= _check_offset_y && y2 < _check_offset_y + 11) { - if (get_colour_scheme_tab()->colours[_color_index_2] & 0x80) + if (get_colour_scheme_tab()->colours[_color_index_2] & 0x80) { get_colour_scheme_tab()->colours[_color_index_2] &= 0x7F; - else + + gConfigColourSchemes.presets[gCurrentColourSchemePreset].colour_schemes[get_colour_scheme_index()].colours[_color_index_2] &= 0x7F; + } + else { get_colour_scheme_tab()->colours[_color_index_2] |= 0x80; + gConfigColourSchemes.presets[gCurrentColourSchemePreset].colour_schemes[get_colour_scheme_index()].colours[_color_index_2] |= 0x80; + } + if (gCurrentColourSchemePreset >= 2) + colour_schemes_save_preset(gCurrentColourSchemePreset); window_invalidate_all(); } } @@ -529,7 +601,6 @@ void window_colour_schemes_scrollmousedown() { } void window_colour_schemes_scrollmouseover() { - int i; short x, y, scrollIndex; rct_window *w; @@ -539,6 +610,57 @@ void window_colour_schemes_scrollmouseover() { // return; } +static bool valid_characters(const char *name) +{ + for (int i = 0; name[i] != '\0'; i++) { + if (name[i] == '\\' || name[i] == '/' || name[i] == ':' || name[i] == '?' || name[i] == '*' || name[i] == '<' || name[i] == '>' || name[i] == '|') + return false; + } + return true; +} + +static void window_colour_schemes_textinput() +{ + rct_window *w; + short widgetIndex; + uint8 result; + char *text; + + window_textinput_get_registers(w, widgetIndex, result, text); + + if (!result || text[0] == 0) + return; + + switch (widgetIndex) { + case WIDX_COLOUR_SCHEMES_DUPLICATE_BUTTON: + case WIDX_COLOUR_SCHEMES_RENAME_BUTTON: + if (valid_characters(text)) { + bool nameTaken = false; + for (int i = 0; i < gConfigColourSchemes.num_presets; i++) { + if (strcmp(gConfigColourSchemes.presets[i].name, text) == 0) { + window_error_open(5242, STR_NONE); + nameTaken = true; + break; + } + } + if (!nameTaken) { + if (widgetIndex == WIDX_COLOUR_SCHEMES_DUPLICATE_BUTTON) { + colour_scheme_create_preset(text); + } + else { + colour_scheme_rename_preset(gCurrentColourSchemePreset, text); + } + config_save_default(); + window_invalidate(w); + } + } + else { + window_error_open(5243, STR_NONE); + } + break; + } +} + void window_colour_schemes_tooltip() { RCT2_GLOBAL(0x013CE952, uint16) = STR_LIST; @@ -582,8 +704,6 @@ void window_colour_schemes_invalidate() } void window_colour_schemes_paint() { - int i; - uint8 selectedTab; rct_window *w; rct_drawpixelinfo *dpi; @@ -599,13 +719,13 @@ void window_colour_schemes_paint() { gfx_draw_string_left(dpi, 5237, w, w->colours[1], w->x + 220, 58 - 12 + w->y + 1); } else { - RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 0, uint32) = &gConfigColourSchemes.presets[gCurrentColourSchemePreset].name; - gfx_draw_string_left(dpi, 5238, NULL, 12, w->x + 10, w->y + window_colour_schemes_widgets[WIDX_COLOUR_SCHEMES_PRESETS].top + 1); + RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 0, uint32) = (uint32)&gConfigColourSchemes.presets[gCurrentColourSchemePreset].name; + gfx_draw_string_left(dpi, 5238, NULL, w->colours[1], w->x + 10, w->y + window_colour_schemes_widgets[WIDX_COLOUR_SCHEMES_PRESETS].top + 1); gfx_draw_string_left( dpi, 1170, (void*)RCT2_ADDRESS_COMMON_FORMAT_ARGS, - 12, + w->colours[1], w->x + window_colour_schemes_widgets[WIDX_COLOUR_SCHEMES_PRESETS].left + 1, w->y + window_colour_schemes_widgets[WIDX_COLOUR_SCHEMES_PRESETS].top ); @@ -618,7 +738,7 @@ void window_colour_schemes_paint() { */ void window_colour_schemes_scrollpaint() { - int spriteIndex, y; + int y; uint8 selectedTab; rct_window *w; rct_drawpixelinfo *dpi; diff --git a/src/windows/staff.c b/src/windows/staff.c index 239833b297..f865bbe3b5 100644 --- a/src/windows/staff.c +++ b/src/windows/staff.c @@ -724,7 +724,7 @@ void window_staff_unknown_05(){ void window_staff_stats_invalidate(){ rct_window* w; window_get_register(w); - colour_scheme_update_by_class(w, WC_STAFF); + colour_scheme_update_by_class(w, (rct_windowclass)WC_STAFF); if (window_staff_page_widgets[w->page] != w->widgets){ w->widgets = window_staff_page_widgets[w->page]; @@ -757,7 +757,7 @@ void window_staff_stats_invalidate(){ void window_staff_options_invalidate(){ rct_window* w; window_get_register(w); - colour_scheme_update_by_class(w, WC_STAFF); + colour_scheme_update_by_class(w, (rct_windowclass)WC_STAFF); if (window_staff_page_widgets[w->page] != w->widgets){ w->widgets = window_staff_page_widgets[w->page]; @@ -830,7 +830,7 @@ void window_staff_options_invalidate(){ void window_staff_overview_invalidate(){ rct_window* w; window_get_register(w); - colour_scheme_update_by_class(w, WC_STAFF); + colour_scheme_update_by_class(w, (rct_windowclass)WC_STAFF); if (window_staff_page_widgets[w->page] != w->widgets){ w->widgets = window_staff_page_widgets[w->page];