From 3042c2bb1acc10cd357ed0a9e2c6adc924a1e912 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 21 Jul 2012 22:35:51 +0900 Subject: [PATCH] Create backups of quick.sav. F6 is fantastic, until you hit it by mistake after dieing when you meant to hit F9 (I've done that way too often). quick.sav is still the last file written via F6 (so F9 is unaffected), but now the previous quick.sav becomes quick1.sav. Up to 5 (currently) backups will be kept: quick1 is the newest, quick5 the oldest. A menu for accessing the backups has been added as a sub-menu of the load menu. --- nq/source/host_cmd.c | 22 ++++++++- ruamoko/cl_menu/client_menu.r | 88 +++++++++++++++++++++++++++++++---- 2 files changed, 99 insertions(+), 11 deletions(-) diff --git a/nq/source/host_cmd.c b/nq/source/host_cmd.c index 96b1411d6..d0970eed2 100644 --- a/nq/source/host_cmd.c +++ b/nq/source/host_cmd.c @@ -510,13 +510,18 @@ convert_to_game_dict (script_t *script) return game; } +#define MAX_QUICK 5 + static void Host_Savegame_f (void) { dstring_t *name; + const char *save_name; char *save_text; QFile *f; int i; + char *bup1, *bup2 = 0; + if (cmd_source != src_command) return; @@ -554,10 +559,25 @@ Host_Savegame_f (void) } } + save_name = Cmd_Argv (1); name = dstring_newstr (); - dsprintf (name, "%s/%s", qfs_gamedir->dir.def, Cmd_Argv (1)); + if (strcmp (save_name, "quick") == 0) { + bup2 = nva ("%s/%s%d.sav", qfs_gamedir->dir.def, save_name, MAX_QUICK); + QFS_Remove (bup2); + for (i = MAX_QUICK - 1; i > 0; i--) { + bup1 = nva ("%s/%s%d.sav", qfs_gamedir->dir.def, save_name, i); + QFS_Rename (bup1, bup2); + free (bup2); + bup2 = bup1; + } + } + dsprintf (name, "%s/%s", qfs_gamedir->dir.def, save_name); QFS_DefaultExtension (name, ".sav"); + if (bup2) { + QFS_Rename (name->str, bup2); + free (bup2); + } Sys_Printf ("Saving game to %s...\n", name->str); f = QFS_WOpen (name->str, 0); dstring_delete (name); diff --git a/ruamoko/cl_menu/client_menu.r b/ruamoko/cl_menu/client_menu.r index 6b2f24d40..ef71a55ce 100644 --- a/ruamoko/cl_menu/client_menu.r +++ b/ruamoko/cl_menu/client_menu.r @@ -115,6 +115,7 @@ int quit_index; // ********* LOAD / SAVE #define MAX_SAVEGAMES 12 +#define MAX_QUICK 5 string filenames[MAX_SAVEGAMES]; int loadable[MAX_SAVEGAMES]; int load_cursor; @@ -130,16 +131,23 @@ string (QFile f) get_comment = return line; } -void () scan_saves = +void (int quick) scan_saves = { local int i; local QFile f; local string line; - for (i = 0; i < MAX_SAVEGAMES; i++) { + local int max = MAX_SAVEGAMES; + if (quick) + max = MAX_QUICK; + for (i = 0; i < max; i++) { if (!filenames[i]) filenames[i] = str_new (); loadable[i] = 0; - f = File_Open (sprintf ("s%i.sav", i), "rz"); + if (quick) { + f = File_Open (sprintf ("quick%i.sav", i + 1), "rz"); + } else { + f = File_Open (sprintf ("s%i.sav", i), "rz"); + } if (!f) { str_copy (filenames[i], "--- UNUSED SLOT ---"); continue; @@ -153,31 +161,46 @@ void () scan_saves = loadable[i] = 1; Qclose (f); } + for (i = max; i < MAX_SAVEGAMES; i++) { + loadable[i] = 0; + } }; int (string text, int key) load_f = { - scan_saves (); + scan_saves (0); Menu_SelectMenu ("load"); return 0; }; int (string text, int key) save_f = { - scan_saves (); + scan_saves (0); Menu_SelectMenu ("save"); return 0; }; void () load_save_f = { - scan_saves (); + scan_saves (0); if (Cmd_Argv (0) == "menu_load") Menu_SelectMenu ("load"); else Menu_SelectMenu ("save"); }; +int (int x, int y) load_quickbup_draw = +{ + local int i; + + Draw_CenterPic (x + 160, y + 4, Draw_CachePic ("gfx/p_load.lmp", 1)); + for (i=0 ; i< MAX_QUICK; i++) + Draw_String (x + 16, y + 32 + 8 * i, filenames[i]); + Draw_Character (x + 8, y + 32 + load_cursor * 8, + 12 + ((int) (time * 4) & 1)); + return 1; +}; + int (int x, int y) load_draw = { local int i; @@ -185,6 +208,7 @@ int (int x, int y) load_draw = Draw_CenterPic (x + 160, y + 4, Draw_CachePic ("gfx/p_load.lmp", 1)); for (i=0 ; i< MAX_SAVEGAMES; i++) Draw_String (x + 16, y + 32 + 8 * i, filenames[i]); + Draw_String (x + 16, y + 32 + 8 * i, "Quick save backups"); Draw_Character (x + 8, y + 32 + load_cursor * 8, 12 + ((int) (time * 4) & 1)); return 1; @@ -202,6 +226,34 @@ int (int x, int y) save_draw = return 1; }; +int (int key, int unicode, int down) load_quickbup_keyevent = +{ + switch (key) { + case QFK_DOWN: + case QFM_WHEEL_DOWN: + S_LocalSound ("misc/menu1.wav"); + load_cursor++; + load_cursor %= MAX_QUICK; + return 1; + case QFK_UP: + case QFM_WHEEL_UP: + S_LocalSound ("misc/menu1.wav"); + load_cursor += MAX_QUICK - 1; + load_cursor %= MAX_QUICK; + return 1; + case QFK_RETURN: + case QFM_BUTTON1: + if (loadable[load_cursor]) { + S_LocalSound ("misc/menu2.wav"); + Menu_SelectMenu (nil); + Cbuf_AddText (sprintf ("load quick%i.sav\n", load_cursor)); + load_cursor = MAX_SAVEGAMES; + } + return 1; + } + return 0; +}; + int (int key, int unicode, int down) load_keyevent = { switch (key) { @@ -209,17 +261,21 @@ int (int key, int unicode, int down) load_keyevent = case QFM_WHEEL_DOWN: S_LocalSound ("misc/menu1.wav"); load_cursor++; - load_cursor %= MAX_SAVEGAMES; + load_cursor %= MAX_SAVEGAMES + 1; return 1; case QFK_UP: case QFM_WHEEL_UP: S_LocalSound ("misc/menu1.wav"); - load_cursor += MAX_SAVEGAMES - 1; - load_cursor %= MAX_SAVEGAMES; + load_cursor += MAX_SAVEGAMES; + load_cursor %= MAX_SAVEGAMES + 1; return 1; case QFK_RETURN: case QFM_BUTTON1: - if (loadable[load_cursor]) { + if (load_cursor == MAX_SAVEGAMES) { + load_cursor = 0; + scan_saves (1); + Menu_SelectMenu ("load_quickbup"); + } else if (loadable[load_cursor]) { S_LocalSound ("misc/menu2.wav"); Menu_SelectMenu (nil); Cbuf_AddText (sprintf ("load s%i.sav\n", load_cursor)); @@ -253,6 +309,17 @@ int (int key, int unicode, int down) save_keyevent = return 0; }; +void () load_quickbup_menu = +{ + Menu_Begin (0, 0, "load_quickbup"); + Menu_EnterHook (menu_enter_sound); + Menu_LeaveHook (menu_leave_sound); + Menu_FadeScreen (1); + Menu_KeyEvent (load_quickbup_keyevent); + Menu_Draw (load_quickbup_draw); + Menu_End (); +}; + void () load_menu = { Menu_Begin (0, 0, "load"); @@ -574,6 +641,7 @@ void () menu_init = main_menu (); quit_menu (); load_menu (); + load_quickbup_menu (); save_menu (); Menu_TopMenu ("main");