Skip to content

Commit

Permalink
libcommon|SaveSlots: Update save slot statuses following engine reset
Browse files Browse the repository at this point in the history
Save slots are linked with corresponding menu widgets on the load/save
pages. Presently these menu widgets are updated by the save slot and
so we must update the save slot's status following an engine reset as
the game menus are now rebuilt at this time.
  • Loading branch information
danij-deng committed Jul 17, 2014
1 parent 3296ad7 commit 0857425
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
14 changes: 14 additions & 0 deletions doomsday/plugins/common/include/saveslots.h
Expand Up @@ -88,6 +88,13 @@ class SaveSlots
*/
void bindSaveName(de::String newName);

/**
* Force a manual update of the save slot status and update any linked menu item.
* Calling this is usually unnecessary as the status is automatically updated when
* the associated saved session changes.
*/
void updateStatus();

private:
friend class SaveSlots;
void setSavedSession(de::game::SavedSession *newSession);
Expand Down Expand Up @@ -165,6 +172,13 @@ class SaveSlots
*/
Slot *slotByUserInput(de::String const &str) const;

/**
* Force a manual update of all save slot statuses and update any linked menu items.
* Calling this is usually unnecessary as the status of a slot is automatically updated
* when the associated saved session changes.
*/
void updateAll();

/**
* Register the console commands and variables of this module.
*
Expand Down
5 changes: 4 additions & 1 deletion doomsday/plugins/common/src/g_update.cpp
Expand Up @@ -21,8 +21,9 @@
#include "common.h"
#include "g_update.h"

#include <ctype.h>
#include <cctype>
#include "animdefs.h"
#include "g_common.h"
#include "hu_chat.h"
#include "hu_log.h"
#include "hu_menu.h"
Expand All @@ -33,6 +34,7 @@
#include "p_sound.h"
#include "p_start.h"
#include "r_common.h"
#include "saveslots.h"

using namespace common;

Expand Down Expand Up @@ -119,6 +121,7 @@ void G_UpdateState(int step)
#endif

Hu_MenuInit();
G_SaveSlots().updateAll();

#if __JHEXEN__
SndInfoParser(AutoStr_FromText("Lumps:SNDINFO"));
Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/common/src/hu_menu.cpp
Expand Up @@ -370,6 +370,7 @@ String Hu_MenuFindPageName(Page const *page)
{
return i.key();
}
i++;
}
}
return "";
Expand Down
13 changes: 13 additions & 0 deletions doomsday/plugins/common/src/saveslots.cpp
Expand Up @@ -216,6 +216,11 @@ void SaveSlots::Slot::setSavedSession(SavedSession *newSession)
}
}

void SaveSlots::Slot::updateStatus()
{
d->updateStatus();
}

DENG2_PIMPL(SaveSlots)
, DENG2_OBSERVES(GameSession::SavedIndex, AvailabilityUpdate)
{
Expand Down Expand Up @@ -369,6 +374,14 @@ SaveSlots::Slot *SaveSlots::slotByUserInput(String const &str) const
return d->slotById(id);
}

void SaveSlots::updateAll()
{
DENG2_FOR_EACH(Instance::Slots, i, d->sslots)
{
i->second->updateStatus();
}
}

void SaveSlots::consoleRegister() // static
{
C_VAR_INT("game-save-last-slot", &cvarLastSlot, CVF_NO_MIN|CVF_NO_MAX|CVF_NO_ARCHIVE|CVF_READ_ONLY, 0, 0);
Expand Down

0 comments on commit 0857425

Please sign in to comment.