Skip to content

Commit

Permalink
PEGASUS: Implement saving/loading from the in-game pause menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Hoops committed Dec 19, 2011
1 parent fa92148 commit 924e0b3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
59 changes: 54 additions & 5 deletions engines/pegasus/pegasus.cpp
Expand Up @@ -306,7 +306,7 @@ void PegasusEngine::runIntro() {
delete video;
}

void PegasusEngine::showLoadDialog() {
Common::Error PegasusEngine::showLoadDialog() {
GUI::SaveLoadChooser slc(_("Load game:"), _("Load"));
slc.setSaveMode(false);

Expand All @@ -317,10 +317,47 @@ void PegasusEngine::showLoadDialog() {

int slot = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());

if (slot >= 0)
loadGameState(slot);
Common::Error result;

if (slot >= 0) {
if (loadGameState(slot).getCode() == Common::kNoError)
result = Common::kNoError;
else
result = Common::kUnknownError;
} else {
result = Common::kUserCanceled;
}

slc.close();

return result;
}

Common::Error PegasusEngine::showSaveDialog() {
GUI::SaveLoadChooser slc(_("Save game:"), _("Save"));
slc.setSaveMode(true);

Common::String gameId = ConfMan.get("gameid");

const EnginePlugin *plugin = 0;
EngineMan.findGame(gameId, &plugin);

int slot = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());

Common::Error result;

if (slot >= 0) {
if (saveGameState(slot, slc.getResultString()).getCode() == Common::kNoError)
result = Common::kNoError;
else
result = Common::kUnknownError;
} else {
result = Common::kUserCanceled;
}

slc.close();

return result;
}

GUI::Debugger *PegasusEngine::getDebugger() {
Expand Down Expand Up @@ -640,6 +677,8 @@ bool PegasusEngine::checkGameMenu() {
}

void PegasusEngine::doGameMenuCommand(const GameMenuCommand command) {
Common::Error result;

switch (command) {
case kMenuCmdStartAdventure:
GameState.setWalkthroughMode(false);
Expand Down Expand Up @@ -734,13 +773,23 @@ void PegasusEngine::doGameMenuCommand(const GameMenuCommand command) {
resetIntroTimer();
break;
case kMenuCmdPauseSave:
error("Save game");
if (showSaveDialog().getCode() != Common::kUserCanceled)
pauseMenu(false);
break;
case kMenuCmdPauseContinue:
pauseMenu(false);
break;
case kMenuCmdPauseRestore:
error("Load game");
makeContinuePoint();
result = showLoadDialog();

if (result.getCode() == Common::kNoError) {
// Successfully loaded, unpause the game
pauseMenu(false);
} else if (result.getCode() != Common::kUserCanceled) {
// Try to get us back to a sane state
loadFromContinuePoint();
}
break;
case kMenuCmdPauseQuit:
_gfx->doFadeOutSync();
Expand Down
3 changes: 2 additions & 1 deletion engines/pegasus/pegasus.h
Expand Up @@ -236,11 +236,12 @@ friend class InputHandler;
void loadFromContinuePoint();
Common::ReadStream *_continuePoint;
bool _saveAllowed, _loadAllowed; // It's so nice that this was in the original code already :P
Common::Error showLoadDialog();
Common::Error showSaveDialog();

// Misc.
Hotspot _returnHotspot;
InputHandler *_savedHandler;
void showLoadDialog();
void showTempScreen(const Common::String &fileName);
bool playMovieScaled(Video::SeekableVideoDecoder *video, uint16 x, uint16 y);
void throwAwayEverything();
Expand Down

0 comments on commit 924e0b3

Please sign in to comment.