Easier saving

Replace Save game functionality and add 'save game as' function
This commit is contained in:
Runelaenen 2015-08-19 21:54:25 +02:00
parent 4e578aeaf2
commit d34a446d61
9 changed files with 80 additions and 48 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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