diff --git a/src/config.c b/src/config.c index 1a6986dec7..d9cb2c5e30 100644 --- a/src/config.c +++ b/src/config.c @@ -1003,7 +1003,6 @@ bool config_shortcut_keys_save() #pragma region Themes -static void themes_remove_extension(char *path); static bool themes_open(const utf8string path); static bool themes_save(const utf8string path, int preset); static void themes_read_properties(int preset, window_colours **current_window_colours, const_utf8string line); @@ -1120,7 +1119,7 @@ bool themes_open(const utf8string path) gConfigThemes.num_presets++; gConfigThemes.presets = realloc(gConfigThemes.presets, sizeof(theme_preset) * gConfigThemes.num_presets); strcpy(gConfigThemes.presets[preset].name, path_get_filename(path)); - themes_remove_extension(gConfigThemes.presets[preset].name); + path_remove_extension(gConfigThemes.presets[preset].name); gConfigThemes.presets[preset].colour_schemes = malloc(sizeof(window_colours) * gNumColourSchemeWindows); for (int i = 0; i < (int)gNumColourSchemeWindows; i++) { for (int j = 0; j < 6; j++) @@ -1239,16 +1238,4 @@ static void themes_set_property(window_colours *colour_scheme, utf8string name, } } -static void themes_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/game.c b/src/game.c index 7923bcff6d..4beb1b3cd1 100644 --- a/src/game.c +++ b/src/game.c @@ -568,7 +568,7 @@ static int open_load_game_dialog() */ static void load_landscape() { - window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_LANDSCAPE); + window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_LANDSCAPE, NULL); return; if (open_landscape_file_dialog() == 0) { @@ -611,6 +611,11 @@ int game_load_save(const char *path) log_verbose("loading saved game, %s", path); strcpy((char*)0x0141EF68, path); + strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, path); + + strcpy(gScenarioSaveName, path_get_filename(path)); + path_remove_extension(gScenarioSaveName); + file = fopen(path, "rb"); if (file == NULL) { log_error("unable to open %s", path); @@ -737,7 +742,7 @@ void reset_all_sprite_quadrant_placements() */ static void load_game() { - window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME); + window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME, NULL); return; if (open_load_game_dialog() == 0) { @@ -794,7 +799,7 @@ static int show_save_game_dialog(char *resultPath) char save_game() { - window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME); + window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME, gScenarioSaveName); return 0; char path[256]; diff --git a/src/interface/window.h b/src/interface/window.h index f7163bb8fe..4e8e5074e2 100644 --- a/src/interface/window.h +++ b/src/interface/window.h @@ -576,7 +576,7 @@ void window_themes_open(); void window_text_input_open(rct_window* call_w, int call_widget, rct_string_id title, rct_string_id description, rct_string_id existing_text, uint32 existing_args, int maxLength); void window_text_input_raw_open(rct_window* call_w, int call_widget, rct_string_id title, rct_string_id description, utf8string existing_text, int maxLength); rct_window *window_mapgen_open(); -rct_window *window_loadsave_open(int type); +rct_window *window_loadsave_open(int type, char *defaultName); void window_editor_main_open(); void window_editor_bottom_toolbar_open(); diff --git a/src/scenario.c b/src/scenario.c index 4fdae3f241..79448e7747 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -46,6 +46,8 @@ static char _scenarioPath[MAX_PATH]; static const char *_scenarioFileName; +char gScenarioSaveName[MAX_PATH]; + static int scenario_create_ducks(); /** @@ -305,8 +307,9 @@ int scenario_load_and_play_from_path(const char *path) } // Set the last saved game path + format_string(gScenarioSaveName, RCT2_GLOBAL(RCT2_ADDRESS_PARK_NAME, rct_string_id), (void*)RCT2_ADDRESS_PARK_NAME_ARGS); strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, (char*)RCT2_ADDRESS_SAVED_GAMES_PATH); - format_string((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2 + strlen((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2), RCT2_GLOBAL(0x0013573D4, uint16), (void*)0x0013573D8); + strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2 + strlen((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2), gScenarioSaveName); strcat((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, ".SV6"); memset((void*)0x001357848, 0, 56); @@ -968,6 +971,9 @@ int scenario_save(char *path, int flags) rct_viewport *viewport; int viewX, viewY, viewZoom, viewRotation; + strcpy(gScenarioSaveName, path_get_filename(path)); + path_remove_extension(gScenarioSaveName); + if (flags & 2) log_verbose("saving scenario, %s", path); else diff --git a/src/scenario.h b/src/scenario.h index 3ef3ce16fd..a5bf2ad84e 100644 --- a/src/scenario.h +++ b/src/scenario.h @@ -23,6 +23,7 @@ #include "rct2.h" #include "object.h" +#include "platform/platform.h" /** * SV6/SC6 header chunk @@ -400,6 +401,8 @@ extern int gScenarioListCount; extern int gScenarioListCapacity; extern rct_scenario_basic *gScenarioList; +extern char gScenarioSaveName[MAX_PATH]; + int scenario_scores_save(); void scenario_load_list(); rct_scenario_basic *get_scenario_by_filename(const char *filename); diff --git a/src/util/util.c b/src/util/util.c index 93bc8b2460..30f874385a 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -69,6 +69,17 @@ void path_set_extension(char *path, const char *extension) strcpy(ch, extension); } +void path_remove_extension(char *path) +{ + char *ch = path + strlen(path); + for (--ch; ch >= path; --ch) { + if (*ch == '.') { + *ch = '\0'; + break; + } + } +} + long fsize(FILE *fp) { long originalPosition, size; diff --git a/src/util/util.h b/src/util/util.h index f68deabe2a..3d14485aa9 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -29,6 +29,7 @@ int mph_to_kmph(int mph); const char *path_get_filename(const char *path); void path_set_extension(char *path, const char *extension); +void path_remove_extension(char *path); long fsize(FILE *fp); bool readentirefile(const char *path, void **outBuffer, long *outLength); diff --git a/src/windows/editor_bottom_toolbar.c b/src/windows/editor_bottom_toolbar.c index 4035526cfd..8485ded736 100644 --- a/src/windows/editor_bottom_toolbar.c +++ b/src/windows/editor_bottom_toolbar.c @@ -314,7 +314,7 @@ void window_editor_bottom_toolbar_jump_forward_to_save_scenario() window_close_all(); - window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_SCENARIO); + window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_SCENARIO, s6Info->name); return; if (!show_save_scenario_dialog(path)) { diff --git a/src/windows/editor_object_selection.c b/src/windows/editor_object_selection.c index a32f4bdf0f..cee5bef0be 100644 --- a/src/windows/editor_object_selection.c +++ b/src/windows/editor_object_selection.c @@ -354,7 +354,7 @@ static void window_editor_object_selection_mouseup() } window_invalidate(w); - window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_TRACK); + window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_TRACK, NULL); break; case WIDX_FILTER_STRING_BUTTON: //window_text_input_open(w, widgetIndex, 5275, 5276, 1170, (uint32)_filter_string, 40); diff --git a/src/windows/loadsave.c b/src/windows/loadsave.c index 8c2ce3b618..4907433e01 100644 --- a/src/windows/loadsave.c +++ b/src/windows/loadsave.c @@ -29,6 +29,7 @@ #include "../title.h" #include "../windows/error.h" #include "../interface/themes.h" +#include "../util/util.h" #pragma region Widgets @@ -112,6 +113,7 @@ int _listItemsCount = 0; loadsave_list_item *_listItems = NULL; char _directory[MAX_PATH]; char _extension[32]; +char *_defaultName = NULL; int _loadsaveType; int _type; @@ -122,12 +124,13 @@ static int hasExtension(char *path, char *extension); static rct_window *window_overwrite_prompt_open(const char *name, const char *path); -rct_window *window_loadsave_open(int type) +rct_window *window_loadsave_open(int type, char *defaultName) { char path[MAX_PATH], *ch; int includeNewItem; rct_window* w; _type = type; + _defaultName = defaultName; w = window_bring_to_front_by_class(WC_LOADSAVE); if (w == NULL) { @@ -345,7 +348,8 @@ static void window_loadsave_scrollmousedown() char *templateString; templateString = (char*)language_get_string(templateStringId); - strcpy(templateString, (char*)RCT2_ADDRESS_SCENARIO_NAME); + strcpy(templateString, _defaultName); + window_text_input_open(w, WIDX_SCROLL, STR_NONE, 2710, templateStringId, 0, 64); } else { if (_listItems[selectedItem].path[strlen(_listItems[selectedItem].path) - 1] == platform_get_path_separator()){ diff --git a/src/windows/top_toolbar.c b/src/windows/top_toolbar.c index 464c510e5a..df0c7a3e1e 100644 --- a/src/windows/top_toolbar.c +++ b/src/windows/top_toolbar.c @@ -434,7 +434,8 @@ static void window_top_toolbar_dropdown() case DDIDX_SAVE_GAME: if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) { // RCT2_CALLPROC_EBPSAFE(0x0066FE2A); - window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE); + rct_s6_info *s6Info = (rct_s6_info*)0x0141F570; + window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE, s6Info->name); } else { tool_cancel(); save_game();