Skip to content

Commit

Permalink
- implement new cvar save_sort_order - for now options are only 0 o…
Browse files Browse the repository at this point in the history
…r 1 - 0 is alphabetical, 1 is descending by time (most recent first)
  • Loading branch information
madame-rachelle committed Dec 28, 2024
1 parent d6e1097 commit 7c2cae5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/common/menu/savegamemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

CVAR(String, save_dir, "", CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
FString SavegameFolder;
CVAR(Int, save_sort_order, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)

//=============================================================================
//
Expand Down Expand Up @@ -136,7 +137,19 @@ int FSavegameManagerBase::InsertSaveNode(FSaveGameNode *node)
//if (SaveGames[0] == &NewSaveNode) i++; // To not insert above the "new savegame" dummy entry.
for (; i < SaveGames.Size(); i++)
{
if (SaveGames[i]->bOldVersion || node->SaveTitle.CompareNoCase(SaveGames[i]->SaveTitle) <= 0)
bool sortcmp = false;
switch(save_sort_order)
{
case 1:
sortcmp = node->CreationTime.CompareNoCase(SaveGames[i]->CreationTime) > 0;
break;
default:
case 0:
sortcmp = node->SaveTitle.CompareNoCase(SaveGames[i]->SaveTitle) <= 0;
break;
}

if (SaveGames[i]->bOldVersion || sortcmp)
{
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/common/menu/savegamemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct FSaveGameNode
{
FString SaveTitle;
FString Filename;
FString CreationTime;
bool bOldVersion = false;
bool bMissingWads = false;
bool bNoDelete = false;
Expand Down
12 changes: 12 additions & 0 deletions src/menu/loadsavemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
// Save name length limit for old binary formats.
#define OLDSAVESTRINGSIZE 24

EXTERN_CVAR(Int, save_sort_order)

//=============================================================================
//
// M_ReadSaveStrings
Expand All @@ -60,6 +62,14 @@

void FSavegameManager::ReadSaveStrings()
{
// re-read list if forced to sort again
static int old_save_sort_order = 0;
if (old_save_sort_order != save_sort_order)
{
ClearSaveGames();
old_save_sort_order = save_sort_order;
}

if (SaveGames.Size() == 0)
{
FString filter;
Expand Down Expand Up @@ -91,6 +101,7 @@ void FSavegameManager::ReadSaveStrings()
FString engine = arc.GetString("Engine");
FString iwad = arc.GetString("Game WAD");
FString title = arc.GetString("Title");
FString creationtime = arc.GetString("Creation Time");


if (engine.Compare(GAMESIG) != 0 || savever > SAVEVER)
Expand Down Expand Up @@ -120,6 +131,7 @@ void FSavegameManager::ReadSaveStrings()
node->bOldVersion = oldVer;
node->bMissingWads = missing;
node->SaveTitle = title;
node->CreationTime = creationtime;
InsertSaveNode(node);
}
}
Expand Down

0 comments on commit 7c2cae5

Please sign in to comment.