mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-12 23:54:35 +00:00
- separated the savegame menu code into an internal class managing the savegame data and the actual menu.
The manager class cannot be scriptified because it provides the internal implementation which may change at some point in the future. It also encapsulates all access to the file level because if that part is not protected, modders could write malware mods.
This commit is contained in:
parent
947b625c50
commit
fc4e1ffcdf
5 changed files with 392 additions and 356 deletions
|
@ -2307,7 +2307,7 @@ void G_DoSaveGame (bool okForQuicksave, FString filename, const char *descriptio
|
||||||
|
|
||||||
WriteZip(filename, savegame_filenames, savegame_content);
|
WriteZip(filename, savegame_filenames, savegame_content);
|
||||||
|
|
||||||
M_NotifyNewSave (filename.GetChars(), description, okForQuicksave);
|
savegameManager.NotifyNewSave (filename.GetChars(), description, okForQuicksave);
|
||||||
|
|
||||||
// delete the JSON buffers we created just above. Everything else will
|
// delete the JSON buffers we created just above. Everything else will
|
||||||
// either still be needed or taken care of automatically.
|
// either still be needed or taken care of automatically.
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -22,6 +22,7 @@ class FFont;
|
||||||
enum EColorRange : int;
|
enum EColorRange : int;
|
||||||
class FPlayerClass;
|
class FPlayerClass;
|
||||||
class FKeyBindings;
|
class FKeyBindings;
|
||||||
|
struct FBrokenLines;
|
||||||
|
|
||||||
enum EMenuKey
|
enum EMenuKey
|
||||||
{
|
{
|
||||||
|
@ -66,7 +67,37 @@ struct FSaveGameNode
|
||||||
FSaveGameNode() { bNoDelete = false; }
|
FSaveGameNode() { bNoDelete = false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SavegameManager
|
||||||
|
{
|
||||||
|
TArray<FSaveGameNode*> SaveGames;
|
||||||
|
int LastSaved = -1;
|
||||||
|
int LastAccessed = -1;
|
||||||
|
int WindowSize = 0;
|
||||||
|
FSaveGameNode *quickSaveSlot = nullptr;
|
||||||
|
|
||||||
|
FileReader *currentSavePic = nullptr;
|
||||||
|
TArray<char> SavePicData;
|
||||||
|
|
||||||
|
FTexture *SavePic = nullptr;
|
||||||
|
FBrokenLines *SaveComment = nullptr;
|
||||||
|
|
||||||
|
void ClearSaveGames();
|
||||||
|
int InsertSaveNode(FSaveGameNode *node);
|
||||||
|
int RemoveSaveSlot(int index);
|
||||||
|
void ReadSaveStrings();
|
||||||
|
void NotifyNewSave(const char *file, const char *title, bool okForQuicksave);
|
||||||
|
void LoadSavegame(int Selected);
|
||||||
|
void DoSave(int Selected, const char *savegamestring);
|
||||||
|
void DeleteEntry(int Selected);
|
||||||
|
void ExtractSaveData(int index);
|
||||||
|
void UnloadSaveData();
|
||||||
|
void ClearSaveStuff();
|
||||||
|
bool DrawSavePic(int x, int y, int w, int h);
|
||||||
|
void SetFileInfo(int Selected);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
extern SavegameManager savegameManager;
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
//
|
//
|
||||||
|
@ -707,7 +738,6 @@ void M_StartupSkillMenu(FGameStartup *gs);
|
||||||
int M_GetDefaultSkill();
|
int M_GetDefaultSkill();
|
||||||
void M_StartControlPanel (bool makeSound);
|
void M_StartControlPanel (bool makeSound);
|
||||||
void M_SetMenu(FName menu, int param = -1);
|
void M_SetMenu(FName menu, int param = -1);
|
||||||
void M_NotifyNewSave (const char *file, const char *title, bool okForQuicksave);
|
|
||||||
void M_StartMessage(const char *message, int messagemode, FName action = NAME_None);
|
void M_StartMessage(const char *message, int messagemode, FName action = NAME_None);
|
||||||
DMenu *StartPickerMenu(DMenu *parent, const char *name, FColorCVar *cvar);
|
DMenu *StartPickerMenu(DMenu *parent, const char *name, FColorCVar *cvar);
|
||||||
void M_RefreshModesList ();
|
void M_RefreshModesList ();
|
||||||
|
|
|
@ -148,7 +148,7 @@ static void DeinitMenus()
|
||||||
MenuDescriptors.Clear();
|
MenuDescriptors.Clear();
|
||||||
OptionValues.Clear();
|
OptionValues.Clear();
|
||||||
DMenu::CurrentMenu = nullptr;
|
DMenu::CurrentMenu = nullptr;
|
||||||
ClearSaveGames();
|
savegameManager.ClearSaveGames();
|
||||||
}
|
}
|
||||||
|
|
||||||
static FTextureID GetMenuTexture(const char* const name)
|
static FTextureID GetMenuTexture(const char* const name)
|
||||||
|
|
|
@ -47,7 +47,6 @@
|
||||||
#include "g_game.h"
|
#include "g_game.h"
|
||||||
|
|
||||||
|
|
||||||
extern FSaveGameNode *quickSaveSlot;
|
|
||||||
EXTERN_CVAR (Bool, saveloadconfirmation) // [mxd]
|
EXTERN_CVAR (Bool, saveloadconfirmation) // [mxd]
|
||||||
|
|
||||||
class DMessageBoxMenu : public DMenu
|
class DMessageBoxMenu : public DMenu
|
||||||
|
@ -549,7 +548,7 @@ DQuickSaveMenu::DQuickSaveMenu(bool playsound)
|
||||||
{
|
{
|
||||||
FString tempstring;
|
FString tempstring;
|
||||||
|
|
||||||
tempstring.Format(GStrings("QSPROMPT"), quickSaveSlot->Title);
|
tempstring.Format(GStrings("QSPROMPT"), savegameManager.quickSaveSlot->Title);
|
||||||
Init(NULL, tempstring, 0, playsound);
|
Init(NULL, tempstring, 0, playsound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,7 +562,7 @@ void DQuickSaveMenu::HandleResult(bool res)
|
||||||
{
|
{
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
G_SaveGame (quickSaveSlot->Filename.GetChars(), quickSaveSlot->Title);
|
G_SaveGame (savegameManager.quickSaveSlot->Filename.GetChars(), savegameManager.quickSaveSlot->Title);
|
||||||
S_Sound (CHAN_VOICE | CHAN_UI, "menu/dismiss", snd_menuvolume, ATTN_NONE);
|
S_Sound (CHAN_VOICE | CHAN_UI, "menu/dismiss", snd_menuvolume, ATTN_NONE);
|
||||||
M_ClearMenus();
|
M_ClearMenus();
|
||||||
}
|
}
|
||||||
|
@ -591,7 +590,7 @@ CCMD (quicksave)
|
||||||
if (gamestate != GS_LEVEL)
|
if (gamestate != GS_LEVEL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (quickSaveSlot == NULL)
|
if (savegameManager.quickSaveSlot == NULL)
|
||||||
{
|
{
|
||||||
S_Sound(CHAN_VOICE | CHAN_UI, "menu/activate", snd_menuvolume, ATTN_NONE);
|
S_Sound(CHAN_VOICE | CHAN_UI, "menu/activate", snd_menuvolume, ATTN_NONE);
|
||||||
M_StartControlPanel(false);
|
M_StartControlPanel(false);
|
||||||
|
@ -602,7 +601,7 @@ CCMD (quicksave)
|
||||||
// [mxd]. Just save the game, no questions asked.
|
// [mxd]. Just save the game, no questions asked.
|
||||||
if (!saveloadconfirmation)
|
if (!saveloadconfirmation)
|
||||||
{
|
{
|
||||||
G_SaveGame(quickSaveSlot->Filename.GetChars(), quickSaveSlot->Title);
|
G_SaveGame(savegameManager.quickSaveSlot->Filename.GetChars(), savegameManager.quickSaveSlot->Title);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -645,7 +644,7 @@ DQuickLoadMenu::DQuickLoadMenu(bool playsound)
|
||||||
{
|
{
|
||||||
FString tempstring;
|
FString tempstring;
|
||||||
|
|
||||||
tempstring.Format(GStrings("QLPROMPT"), quickSaveSlot->Title);
|
tempstring.Format(GStrings("QLPROMPT"), savegameManager.quickSaveSlot->Title);
|
||||||
Init(NULL, tempstring, 0, playsound);
|
Init(NULL, tempstring, 0, playsound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,7 +658,7 @@ void DQuickLoadMenu::HandleResult(bool res)
|
||||||
{
|
{
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
G_LoadGame (quickSaveSlot->Filename.GetChars());
|
G_LoadGame (savegameManager.quickSaveSlot->Filename.GetChars());
|
||||||
S_Sound (CHAN_VOICE | CHAN_UI, "menu/dismiss", snd_menuvolume, ATTN_NONE);
|
S_Sound (CHAN_VOICE | CHAN_UI, "menu/dismiss", snd_menuvolume, ATTN_NONE);
|
||||||
M_ClearMenus();
|
M_ClearMenus();
|
||||||
}
|
}
|
||||||
|
@ -685,11 +684,11 @@ CCMD (quickload)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quickSaveSlot == NULL)
|
if (savegameManager.quickSaveSlot == NULL)
|
||||||
{
|
{
|
||||||
M_StartControlPanel(true);
|
M_StartControlPanel(true);
|
||||||
// signal that whatever gets loaded should be the new quicksave
|
// signal that whatever gets loaded should be the new quicksave
|
||||||
quickSaveSlot = (FSaveGameNode *)1;
|
savegameManager.quickSaveSlot = (FSaveGameNode *)1;
|
||||||
M_SetMenu(NAME_Loadgamemenu);
|
M_SetMenu(NAME_Loadgamemenu);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -697,7 +696,7 @@ CCMD (quickload)
|
||||||
// [mxd]. Just load the game, no questions asked.
|
// [mxd]. Just load the game, no questions asked.
|
||||||
if (!saveloadconfirmation)
|
if (!saveloadconfirmation)
|
||||||
{
|
{
|
||||||
G_LoadGame(quickSaveSlot->Filename.GetChars());
|
G_LoadGame(savegameManager.quickSaveSlot->Filename.GetChars());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue