ULTIMA: Move methods for showing save/restore dialogs into Engine class

This commit is contained in:
Paul Gilbert 2020-02-02 16:19:29 -08:00 committed by Paul Gilbert
parent 31f4bc74ab
commit 866cc57d64
11 changed files with 56 additions and 98 deletions

View File

@ -56,6 +56,7 @@
#include "gui/debugger.h" #include "gui/debugger.h"
#include "gui/dialog.h" #include "gui/dialog.h"
#include "gui/message.h" #include "gui/message.h"
#include "gui/saveload.h"
#include "audio/mixer.h" #include "audio/mixer.h"
@ -686,6 +687,43 @@ bool Engine::canSaveGameStateCurrently() {
return false; return false;
} }
bool Engine::loadGameDialog() {
if (!canLoadGameStateCurrently())
return false;
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Load game:"), _("Load"), false);
pauseEngine(true);
int slotNum = dialog->runModalWithCurrentTarget();
pauseEngine(false);
delete dialog;
if (slotNum != -1)
return loadGameState(slotNum).getCode() == Common::kNoError;
return false;
}
bool Engine::saveGameDialog() {
if (!canSaveGameStateCurrently())
return false;
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
pauseEngine(true);
int slotNum = dialog->runModalWithCurrentTarget();
pauseEngine(false);
Common::String desc = dialog->getResultString();
if (desc.empty())
desc = dialog->createDefaultSaveDescription(slotNum);
delete dialog;
if (slotNum != -1)
return saveGameState(slotNum, desc).getCode() == Common::kNoError;
return false;
}
void Engine::quitGame() { void Engine::quitGame() {
Common::Event event; Common::Event event;

View File

@ -259,6 +259,16 @@ public:
*/ */
virtual bool canSaveGameStateCurrently(); virtual bool canSaveGameStateCurrently();
/**
* Shows the ScummVM save dialog, allowing users to save their game
*/
bool saveGameDialog();
/**
* Shows the ScummVM Restore dialog, allowing users to load a game
*/
bool loadGameDialog();
protected: protected:
/** /**

View File

@ -313,7 +313,7 @@ void ActionPartyMode(int const *params) {
} }
void ActionSaveDialog(int const *params) { void ActionSaveDialog(int const *params) {
g_engine->saveGame(); g_engine->saveGameDialog();
} }
void ActionLoadLatestSave(int const *params) { void ActionLoadLatestSave(int const *params) {

View File

@ -146,9 +146,9 @@ GUI_status GameMenuDialog::callback(uint16 msg, GUI_CallBack *caller, void *data
if (caller == this) { if (caller == this) {
close_dialog(); close_dialog();
} else if (caller == save_button) { } else if (caller == save_button) {
g_engine->saveGame(); g_engine->saveGameDialog();
} else if (caller == load_button) { } else if (caller == load_button) {
g_engine->loadGame(); g_engine->loadGameDialog();
} else if (caller == video_button) { } else if (caller == video_button) {
GUI_Widget *video_dialog; GUI_Widget *video_dialog;
video_dialog = (GUI_Widget *) new VideoDialog(this); video_dialog = (GUI_Widget *) new VideoDialog(this);

View File

@ -28,7 +28,6 @@
#include "common/debug-channels.h" #include "common/debug-channels.h"
#include "common/file.h" #include "common/file.h"
#include "common/translation.h" #include "common/translation.h"
#include "gui/saveload.h"
namespace Ultima { namespace Ultima {
namespace Shared { namespace Shared {
@ -107,35 +106,6 @@ Common::FSNode UltimaEngine::getGameDirectory() const {
return Common::FSNode(ConfMan.get("path")); return Common::FSNode(ConfMan.get("path"));
} }
bool UltimaEngine::loadGame() {
if (!canLoadGameStateCurrently())
return false;
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Load game:"), _("Load"), false);
int slotNum = dialog->runModalWithCurrentTarget();
delete dialog;
if (slotNum != -1)
return loadGameState(slotNum).getCode() == Common::kNoError;
return false;
}
bool UltimaEngine::saveGame() {
if (!canSaveGameStateCurrently())
return false;
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
int slotNum = dialog->runModalWithCurrentTarget();
Common::String saveName = dialog->getResultString();
delete dialog;
if (slotNum != -1)
return saveGameState(slotNum, saveName).getCode() == Common::kNoError;
return false;
}
UltimaMetaEngine *UltimaEngine::getMetaEngine() const { UltimaMetaEngine *UltimaEngine::getMetaEngine() const {
return g_metaEngine; return g_metaEngine;
} }

View File

@ -149,16 +149,6 @@ public:
*/ */
Common::FSNode getGameDirectory() const; Common::FSNode getGameDirectory() const;
/**
* Shows the ScummVM save dialog, allowing users to save their game
*/
virtual bool saveGame();
/**
* Shows the ScummVM Restore dialog, allowing users to restore a game
*/
virtual bool loadGame();
/** /**
* Indicates whether a game state can be loaded. * Indicates whether a game state can be loaded.
* @param isAutosave Flags whether it's an autosave check * @param isAutosave Flags whether it's an autosave check

View File

@ -37,7 +37,7 @@ END_MESSAGE_MAP()
bool Quit::QuitMsg(CQuitMsg &msg) { bool Quit::QuitMsg(CQuitMsg &msg) {
Ultima1Game *game = static_cast<Ultima1Game *>(getGame()); Ultima1Game *game = static_cast<Ultima1Game *>(getGame());
addInfoMsg(game->_res->ACTION_NAMES[16]); addInfoMsg(game->_res->ACTION_NAMES[16]);
g_vm->saveGame(); g_vm->saveGameDialog();
return true; return true;
} }

View File

@ -398,7 +398,7 @@ bool ViewCharacterGeneration::save() {
_character->_armour[1]->_quantity = 1; // Leather armour _character->_armour[1]->_quantity = 1; // Leather armour
_character->_equippedSpell = 0; _character->_equippedSpell = 0;
return g_vm->saveGame(); return g_vm->saveGameDialog();
} }
} // End of namespace U1Gfx } // End of namespace U1Gfx

View File

@ -304,7 +304,7 @@ bool ViewTitle::KeypressMsg(CKeypressMsg &msg) {
if (msg._keyState.keycode == Common::KEYCODE_a) { if (msg._keyState.keycode == Common::KEYCODE_a) {
setView("CharGen"); setView("CharGen");
} else { } else {
if (!g_vm->loadGame()) if (!g_vm->loadGameDialog())
textCursor->setVisible(true); textCursor->setVisible(true);
} }
} }

View File

@ -1291,33 +1291,6 @@ void Ultima8Engine::writeSaveInfo(ODataSource *ods) {
game->writeSaveInfo(ods); game->writeSaveInfo(ods);
} }
bool Ultima8Engine::saveGame() {
if (!canSaveGameStateCurrently(false))
return false;
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
bool result = false;
pauseEngine(true);
int slot = dialog->runModalWithCurrentTarget();
pauseEngine(false);
if (slot >= 0) {
Common::String desc = dialog->getResultString();
if (desc.empty()) {
// create our own description for the saved game, the user didn't enter it
desc = dialog->createDefaultSaveDescription(slot);
}
// Save the game
result = saveGameState(slot, desc, false).getCode() == Common::kNoError;
}
delete dialog;
return result;
}
bool Ultima8Engine::canSaveGameStateCurrently(bool isAutosave) { bool Ultima8Engine::canSaveGameStateCurrently(bool isAutosave) {
if (desktopGump->FindGump<ModalGump>()) if (desktopGump->FindGump<ModalGump>())
// Can't save when a modal gump is open // Can't save when a modal gump is open
@ -1563,25 +1536,6 @@ void Ultima8Engine::syncSoundSettings() {
midiPlayer->setVolume(_mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType)); midiPlayer->setVolume(_mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType));
} }
bool Ultima8Engine::loadGame() {
if (!canLoadGameStateCurrently())
return false;
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
bool result = false;
pauseEngine(true);
int slot = dialog->runModalWithCurrentTarget();
pauseEngine(false);
if (slot >= 0) {
result = loadGameState(slot).getCode() == Common::kNoError;
}
delete dialog;
return result;
}
Common::Error Ultima8Engine::loadGameState(int slot) { Common::Error Ultima8Engine::loadGameState(int slot) {
return loadGame(Std::string::format("@save/%d", slot)) ? return loadGame(Std::string::format("@save/%d", slot)) ?
Common::kNoError : Common::kReadingFailed; Common::kNoError : Common::kReadingFailed;
@ -1849,7 +1803,7 @@ void Ultima8Engine::ConCmd_saveGame(const Console::ArgvType &argv) {
// Save a game with the given name into the quicksave slot // Save a game with the given name into the quicksave slot
Ultima8Engine::get_instance()->saveGame("@save/1", argv[1]); Ultima8Engine::get_instance()->saveGame("@save/1", argv[1]);
} else { } else {
Ultima8Engine::get_instance()->saveGame(); Ultima8Engine::get_instance()->saveGameDialog();
} }
} }
@ -1859,7 +1813,7 @@ void Ultima8Engine::ConCmd_loadGame(const Console::ArgvType &argv) {
// it just needs to be present to differentiate from showing the GUI load dialog // it just needs to be present to differentiate from showing the GUI load dialog
Ultima8Engine::get_instance()->loadGame("@save/1"); Ultima8Engine::get_instance()->loadGame("@save/1");
} else { } else {
Ultima8Engine::get_instance()->loadGame(); Ultima8Engine::get_instance()->loadGameDialog();
} }
} }

View File

@ -337,16 +337,12 @@ public:
*/ */
virtual Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave) override; virtual Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave) override;
bool saveGame() override;
//! save a game //! save a game
//! \param filename the file to save to //! \param filename the file to save to
//! \return true if succesful //! \return true if succesful
bool saveGame(Std::string filename, Std::string desc, bool saveGame(Std::string filename, Std::string desc,
bool ignore_modals = false); bool ignore_modals = false);
bool loadGame() override;
//! load a game //! load a game
//! \param filename the savegame to load //! \param filename the savegame to load
//! \return true if succesful. //! \return true if succesful.