Merge pull request #900 from protocultor/delete_save

Quicksaves can be deleted from menu
This commit is contained in:
Yamagi 2022-10-08 15:16:06 +02:00 committed by GitHub
commit 3222270df6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3317,11 +3317,58 @@ static menuaction_s s_savegame_actions[MAX_SAVESLOTS + 1]; // One for quick
static qboolean menukeyitem_delete = false; static qboolean menukeyitem_delete = false;
static void static void
DeleteSaveGameFunc(void * self) PromptDeleteSaveFunc(menuframework_s *m)
{ {
menuaction_s * a = ( menuaction_s * )self; menucommon_s *item = Menu_ItemAtCursor(m);
menukeyitem_delete = true; if (item == NULL || item->type != MTYPE_ACTION)
Menu_SetStatusBar( a->generic.parent, "are you sure you want to delete? y\\n" ); {
return;
}
if (item->localdata[0] == -1)
{
if (m_quicksavevalid)
{
menukeyitem_delete = true;
}
}
else
{
if (m_savevalid[item->localdata[0] - m_loadsave_page * MAX_SAVESLOTS])
{
menukeyitem_delete = true;
}
}
if (menukeyitem_delete)
{
Menu_SetStatusBar( m, "are you sure you want to delete? y\\n" );
}
}
static qboolean
ExecDeleteSaveFunc(menuframework_s *m, int menu_key)
{
menucommon_s *item = Menu_ItemAtCursor(m);
menukeyitem_delete = false;
if (menu_key == K_ENTER || menu_key == 'y' || menu_key == 'Y')
{
char name[MAX_OSPATH] = {0};
if (item->localdata[0] == -1) // quicksave
{
Com_sprintf(name, sizeof(name), "%s/save/quick/", FS_Gamedir());
}
else
{
Com_sprintf(name, sizeof(name), "%s/save/save%d/", FS_Gamedir(),
item->localdata[0]);
}
Sys_RemoveDir(name);
return true;
}
Menu_SetStatusBar( m, m_loadsave_statusbar );
return false;
} }
static void static void
@ -3503,26 +3550,13 @@ LoadGame_MenuKey(int key)
{ {
static menuframework_s *m = &s_loadgame_menu; static menuframework_s *m = &s_loadgame_menu;
int menu_key = Key_GetMenuKey(key); int menu_key = Key_GetMenuKey(key);
menucommon_s * item = NULL;
if (menukeyitem_delete) { if (menukeyitem_delete)
{
item = Menu_ItemAtCursor( m ); if (ExecDeleteSaveFunc(m, menu_key))
menukeyitem_delete = false; {
LoadGame_MenuInit();
if ( menu_key == K_ENTER || menu_key == 'y' || menu_key == 'Y' ) {
char name[MAX_OSPATH] = { 0 };
Com_sprintf( name, sizeof( name ), "%s/save/save%d/", FS_Gamedir(),
item->localdata[0] );
Sys_RemoveDir( name );
LoadGame_MenuInit();
} else {
Menu_SetStatusBar( &s_loadgame_menu, m_loadsave_statusbar );
} }
return menu_move_sound; return menu_move_sound;
} }
@ -3555,14 +3589,7 @@ LoadGame_MenuKey(int key)
return menu_move_sound; return menu_move_sound;
case K_BACKSPACE: case K_BACKSPACE:
if ((item = Menu_ItemAtCursor(m)) != NULL) PromptDeleteSaveFunc(m);
{
if (item->type == MTYPE_ACTION)
{
DeleteSaveGameFunc( item );
}
}
return menu_move_sound; return menu_move_sound;
default: default:
@ -3667,7 +3694,6 @@ SaveGame_MenuKey(int key)
{ {
static menuframework_s *m = &s_savegame_menu; static menuframework_s *m = &s_savegame_menu;
int menu_key = Key_GetMenuKey(key); int menu_key = Key_GetMenuKey(key);
menucommon_s * item = NULL;
if (m_popup_string) if (m_popup_string)
{ {
@ -3675,24 +3701,12 @@ SaveGame_MenuKey(int key)
return NULL; return NULL;
} }
if (menukeyitem_delete) { if (menukeyitem_delete)
{
item = Menu_ItemAtCursor( m ); if (ExecDeleteSaveFunc(m, menu_key))
menukeyitem_delete = false; {
if ( menu_key == K_ENTER || menu_key == 'y' || menu_key == 'Y' ) {
char name[MAX_OSPATH] = { 0 };
Com_sprintf( name, sizeof( name ), "%s/save/save%d/", FS_Gamedir(),
item->localdata[0] );
Sys_RemoveDir( name );
SaveGame_MenuInit(); SaveGame_MenuInit();
} else {
Menu_SetStatusBar( &s_savegame_menu, m_loadsave_statusbar );
} }
return menu_move_sound; return menu_move_sound;
} }
@ -3725,15 +3739,9 @@ SaveGame_MenuKey(int key)
return menu_move_sound; return menu_move_sound;
case K_BACKSPACE: case K_BACKSPACE:
if ((item = Menu_ItemAtCursor(m)) != NULL) PromptDeleteSaveFunc(m);
{
if (item->type == MTYPE_ACTION)
{
DeleteSaveGameFunc( item );
}
}
return menu_move_sound; return menu_move_sound;
default: default:
s_loadgame_menu.cursor = s_savegame_menu.cursor; s_loadgame_menu.cursor = s_savegame_menu.cursor;
break; break;