From d34a446d6105727fc0a21c0dac6447fa964e9520 Mon Sep 17 00:00:00 2001 From: Runelaenen Date: Wed, 19 Aug 2015 21:54:25 +0200 Subject: [PATCH 1/4] Easier saving Replace Save game functionality and add 'save game as' function --- data/language/english_uk.txt | 3 +- src/game.c | 41 +++++++++++++---------- src/game.h | 1 + src/localisation/string_ids.h | 3 +- src/scenario.c | 5 +-- src/scenario.h | 1 + src/windows/loadsave.c | 9 +++++ src/windows/save_prompt.c | 2 +- src/windows/top_toolbar.c | 63 +++++++++++++++++++++-------------- 9 files changed, 80 insertions(+), 48 deletions(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index bdeb3e3aa8..eaddffc88d 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -885,7 +885,7 @@ STR_0879 :Can't lower land here... STR_0880 :Can't raise land here... STR_0881 :Object in the way STR_0882 :Load Game -STR_0883 :Save Game +STR_0883 :Save Game as STR_0884 :Load Landscape STR_0885 :Save Landscape STR_0886 :Quit Game @@ -3850,3 +3850,4 @@ STR_5508 :Allow loading files with incorrect checksums STR_5509 :{SMALLFONT}{BLACK}Allows loading scenarios and saves that have an incorrect checksum, like the scenarios from the demo or damaged saves. STR_5510 :Default sound device STR_5511 :(UNKNOWN) +STR_5512 :Save game diff --git a/src/game.c b/src/game.c index e41de01196..60dddf34f5 100644 --- a/src/game.c +++ b/src/game.c @@ -990,32 +990,37 @@ static int show_save_game_dialog(char *resultPath) int save_game() { - window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME, gScenarioSaveName); - return 0; + if (!gFirstTimeSave) { + utf8 path[MAX_PATH]; - char path[256]; + log_error("Saving to %s", gScenarioSaveName); + + platform_get_user_directory(path, "save"); + + strcat(path, gScenarioSaveName); + strcat(path, ".sv6"); + + SDL_RWops* rw = platform_sdl_rwfromfile(path, "wb+"); + if (rw != NULL) { + scenario_save(rw, 0x80000000); + log_error("Saved to %s", gScenarioSaveName); + SDL_RWclose(rw); + } - if (!show_save_game_dialog(path)) { - gfx_invalidate_screen(); return 0; } - - // Ensure path has .SV6 extension - path_set_extension(path, ".SV6"); - - SDL_RWops* rw = platform_sdl_rwfromfile(path, "wb+"); - if (rw != NULL) { - int success = scenario_save(rw, gConfigGeneral.save_plugin_data ? 1 : 0); - SDL_RWclose(rw); - if (success) { - game_do_command(0, 1047, 0, -1, GAME_COMMAND_SET_RIDE_APPEARANCE, 0, 0); - gfx_invalidate_screen(); - return 1; - } + else { + save_game_as(); } + +} +int save_game_as() +{ + window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME, gScenarioSaveName); return 0; } + void game_autosave() { utf8 path[MAX_PATH]; diff --git a/src/game.h b/src/game.h index be95fcd879..7516ea50b6 100644 --- a/src/game.h +++ b/src/game.h @@ -133,6 +133,7 @@ void game_load_init(); void game_pause_toggle(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp); void pause_toggle(); int save_game(); +int save_game_as(); void rct2_exit(); void rct2_exit_reason(rct_string_id title, rct_string_id body); void game_autosave(); diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index 9dc99a6756..f1ab68af8f 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -114,7 +114,8 @@ enum { STR_CANT_RAISE_LAND_HERE = 880, STR_LOAD_GAME = 882, - STR_SAVE_GAME = 883, + STR_SAVE_GAME_AS = 883, + STR_SAVE_GAME = 5512, STR_LOAD_LANDSCAPE = 884, STR_SAVE_LANDSCAPE = 885, STR_QUIT_GAME = 886, diff --git a/src/scenario.c b/src/scenario.c index 925071bb7f..39e15eeb22 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -48,6 +48,7 @@ static char _scenarioPath[MAX_PATH]; static const char *_scenarioFileName; char gScenarioSaveName[MAX_PATH]; +int gFirstTimeSave = 1; static int scenario_create_ducks(); static void scenario_objective_check(); @@ -906,9 +907,9 @@ int scenario_save(SDL_RWops* rw, int flags) int viewX, viewY, viewZoom, viewRotation; if (flags & 2) - log_verbose("saving scenario"); + log_error("saving scenario"); else - log_verbose("saving game"); + log_error("saving game"); if (!(flags & 0x80000000)) diff --git a/src/scenario.h b/src/scenario.h index 80df725b6f..a11a2cf9dc 100644 --- a/src/scenario.h +++ b/src/scenario.h @@ -413,6 +413,7 @@ extern int gScenarioListCapacity; extern rct_scenario_basic *gScenarioList; extern char gScenarioSaveName[MAX_PATH]; +extern int gFirstTimeSave; int scenario_scores_save(); void scenario_load_list(); diff --git a/src/windows/loadsave.c b/src/windows/loadsave.c index c11303cb1e..786cb694ef 100644 --- a/src/windows/loadsave.c +++ b/src/windows/loadsave.c @@ -753,6 +753,10 @@ static void window_loadsave_select(rct_window *w, const char *path) network_begin_server(gConfigNetwork.default_port); } + strcpy(gScenarioSaveName, path_get_filename(path)); + path_remove_extension(gScenarioSaveName); + gFirstTimeSave = 0; + window_close(w); gfx_invalidate_screen(); rct2_endupdate(); @@ -768,6 +772,11 @@ static void window_loadsave_select(rct_window *w, const char *path) int success = scenario_save(rw, gConfigGeneral.save_plugin_data ? 1 : 0); SDL_RWclose(rw); if (success) { + + strcpy(gScenarioSaveName, path_get_filename(path)); + path_remove_extension(gScenarioSaveName); + gFirstTimeSave = 0; + window_close_by_class(WC_LOADSAVE); game_do_command(0, 1047, 0, -1, GAME_COMMAND_SET_RIDE_APPEARANCE, 0, 0); gfx_invalidate_screen(); diff --git a/src/windows/save_prompt.c b/src/windows/save_prompt.c index 8abd3a72e8..cca05c7420 100644 --- a/src/windows/save_prompt.c +++ b/src/windows/save_prompt.c @@ -235,7 +235,7 @@ static void window_save_prompt_mouseup(rct_window *w, int widgetIndex) } else { switch (widgetIndex) { case WIDX_SAVE: - if (!save_game()) { + if (!save_game_as()) { // user pressed cancel window_close(w); return; diff --git a/src/windows/top_toolbar.c b/src/windows/top_toolbar.c index f1b94142f5..b7035a4a73 100644 --- a/src/windows/top_toolbar.c +++ b/src/windows/top_toolbar.c @@ -72,18 +72,19 @@ enum { }; typedef enum { - DDIDX_LOAD_GAME = 0, - DDIDX_SAVE_GAME = 1, + DDIDX_SAVE_GAME = 0, + DDIDX_SAVE_GAME_AS = 1, + DDIDX_LOAD_GAME = 2, // separator - DDIDX_ABOUT = 3, - DDIDX_OPTIONS = 4, - DDIDX_SCREENSHOT = 5, - DDIDX_GIANT_SCREENSHOT = 6, + DDIDX_ABOUT = 4, + DDIDX_OPTIONS = 5, + DDIDX_SCREENSHOT = 6, + DDIDX_GIANT_SCREENSHOT = 7, // separator - DDIDX_QUIT_TO_MENU = 8, - DDIDX_EXIT_OPENRCT2 = 9, + DDIDX_QUIT_TO_MENU = 9, + DDIDX_EXIT_OPENRCT2 = 10, // separator - DDIDX_ENABLE_TWITCH = 11 + DDIDX_ENABLE_TWITCH = 12 } FILE_MENU_DDIDX; typedef enum { @@ -377,25 +378,26 @@ static void window_top_toolbar_mousedown(int widgetIndex, rct_window*w, rct_widg gDropdownItemsFormat[9] = STR_EXIT_OPENRCT2; numItems = 10; } else { - gDropdownItemsFormat[0] = STR_LOAD_GAME; - gDropdownItemsFormat[1] = STR_SAVE_GAME; - gDropdownItemsFormat[2] = 0; - gDropdownItemsFormat[3] = STR_ABOUT; - gDropdownItemsFormat[4] = STR_OPTIONS; - gDropdownItemsFormat[5] = STR_SCREENSHOT; - gDropdownItemsFormat[6] = STR_GIANT_SCREENSHOT; - gDropdownItemsFormat[7] = 0; - gDropdownItemsFormat[8] = STR_QUIT_TO_MENU; - gDropdownItemsFormat[9] = STR_EXIT_OPENRCT2; - numItems = 10; + gDropdownItemsFormat[0] = STR_SAVE_GAME; + gDropdownItemsFormat[1] = STR_SAVE_GAME_AS; + gDropdownItemsFormat[2] = STR_LOAD_GAME; + gDropdownItemsFormat[3] = 0; + gDropdownItemsFormat[4] = STR_ABOUT; + gDropdownItemsFormat[5] = STR_OPTIONS; + gDropdownItemsFormat[6] = STR_SCREENSHOT; + gDropdownItemsFormat[7] = STR_GIANT_SCREENSHOT; + gDropdownItemsFormat[8] = 0; + gDropdownItemsFormat[9] = STR_QUIT_TO_MENU; + gDropdownItemsFormat[10] = STR_EXIT_OPENRCT2; + numItems = 11; #ifndef DISABLE_TWITCH if (gConfigTwitch.channel != NULL && gConfigTwitch.channel[0] != 0) { _menuDropdownIncludesTwitch = true; - gDropdownItemsFormat[10] = 0; - gDropdownItemsFormat[11] = 1156; - gDropdownItemsArgs[11] = STR_TWITCH_ENABLE; - numItems = 12; + gDropdownItemsFormat[11] = 0; + gDropdownItemsFormat[12] = 1156; + gDropdownItemsArgs[12] = STR_TWITCH_ENABLE; + numItems = 13; } #endif } @@ -492,11 +494,22 @@ static void window_top_toolbar_dropdown(rct_window *w, int widgetIndex, int drop case DDIDX_LOAD_GAME: game_do_command(0, 1, 0, 0, GAME_COMMAND_LOAD_OR_QUIT, 0, 0); break; + case DDIDX_SAVE_GAME_AS: + if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) { + rct_s6_info *s6Info = (rct_s6_info*)0x0141F570; + window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE, s6Info->name); + } + else { + tool_cancel(); + save_game_as(); + } + break; case DDIDX_SAVE_GAME: if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) { rct_s6_info *s6Info = (rct_s6_info*)0x0141F570; window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE, s6Info->name); - } else { + } + else { tool_cancel(); save_game(); } From 6ec01c6d6557c484288b61cda0b2fb5bca2ba57b Mon Sep 17 00:00:00 2001 From: Runelaenen Date: Wed, 19 Aug 2015 22:35:20 +0200 Subject: [PATCH 2/4] Changed localisation strings --- data/language/english_uk.txt | 4 ++-- src/localisation/string_ids.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index eaddffc88d..216f95d53c 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -885,7 +885,7 @@ STR_0879 :Can't lower land here... STR_0880 :Can't raise land here... STR_0881 :Object in the way STR_0882 :Load Game -STR_0883 :Save Game as +STR_0883 :Save Game STR_0884 :Load Landscape STR_0885 :Save Landscape STR_0886 :Quit Game @@ -3850,4 +3850,4 @@ STR_5508 :Allow loading files with incorrect checksums STR_5509 :{SMALLFONT}{BLACK}Allows loading scenarios and saves that have an incorrect checksum, like the scenarios from the demo or damaged saves. STR_5510 :Default sound device STR_5511 :(UNKNOWN) -STR_5512 :Save game +STR_5512 :Save game as diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index f1ab68af8f..40c7dead82 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -114,8 +114,8 @@ enum { STR_CANT_RAISE_LAND_HERE = 880, STR_LOAD_GAME = 882, - STR_SAVE_GAME_AS = 883, - STR_SAVE_GAME = 5512, + STR_SAVE_GAME_AS = 5512, + STR_SAVE_GAME = 883, STR_LOAD_LANDSCAPE = 884, STR_SAVE_LANDSCAPE = 885, STR_QUIT_GAME = 886, From 3b1708f1be97908707889ff2ac4b16965f72eb9c Mon Sep 17 00:00:00 2001 From: Runelaenen Date: Wed, 19 Aug 2015 23:09:54 +0200 Subject: [PATCH 3/4] Wrong logging fixed --- src/game.c | 4 ++-- src/scenario.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/game.c b/src/game.c index 60dddf34f5..e080552abf 100644 --- a/src/game.c +++ b/src/game.c @@ -993,7 +993,7 @@ int save_game() if (!gFirstTimeSave) { utf8 path[MAX_PATH]; - log_error("Saving to %s", gScenarioSaveName); + log_verbose("Saving to %s", gScenarioSaveName); platform_get_user_directory(path, "save"); @@ -1003,7 +1003,7 @@ int save_game() SDL_RWops* rw = platform_sdl_rwfromfile(path, "wb+"); if (rw != NULL) { scenario_save(rw, 0x80000000); - log_error("Saved to %s", gScenarioSaveName); + log_verbose("Saved to %s", gScenarioSaveName); SDL_RWclose(rw); } diff --git a/src/scenario.c b/src/scenario.c index 39e15eeb22..1ea9937d98 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -907,9 +907,9 @@ int scenario_save(SDL_RWops* rw, int flags) int viewX, viewY, viewZoom, viewRotation; if (flags & 2) - log_error("saving scenario"); + log_verbose("saving scenario"); else - log_error("saving game"); + log_verbose("saving game"); if (!(flags & 0x80000000)) From 2830cdd3a3d6494748f143cd748bfde469d3000b Mon Sep 17 00:00:00 2001 From: Runelaenen Date: Wed, 19 Aug 2015 23:16:07 +0200 Subject: [PATCH 4/4] Capitalisation of 5512 --- data/language/english_uk.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index 216f95d53c..01ac55132a 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -3850,4 +3850,4 @@ STR_5508 :Allow loading files with incorrect checksums STR_5509 :{SMALLFONT}{BLACK}Allows loading scenarios and saves that have an incorrect checksum, like the scenarios from the demo or damaged saves. STR_5510 :Default sound device STR_5511 :(UNKNOWN) -STR_5512 :Save game as +STR_5512 :Save Game As