From 7c5cf1b400808865a5f601f70d624ad6704a0c8c Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 10 Jun 2012 04:49:42 +0200 Subject: [PATCH] GUI: Add helper to SaveLoadChooser, which uses the currently active target. This reduces the code duplication in all client code, which formerly duplicated the querying of the plugin, game id etc. and now simply calls the newly added method runModalWithCurrentTarget() on a SaveLoadChooser object. --- engines/agi/saveload.cpp | 6 ++---- engines/cge/events.cpp | 10 ++-------- engines/cruise/menu.cpp | 4 +--- engines/dialogs.cpp | 14 ++------------ engines/dreamweb/saveload.cpp | 10 ++-------- engines/hugo/file.cpp | 8 ++------ engines/mohawk/riven.cpp | 7 +------ engines/parallaction/saveload.cpp | 7 +------ engines/sci/engine/kfile.cpp | 8 ++------ engines/toon/toon.cpp | 8 ++------ engines/tsage/scenes.cpp | 4 +--- gui/saveload.cpp | 9 +++++++++ gui/saveload.h | 7 +++++++ 13 files changed, 34 insertions(+), 68 deletions(-) diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index cb7792af8e8..25fa7829efe 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -795,8 +795,6 @@ int AgiEngine::selectSlot() { } int AgiEngine::scummVMSaveLoadDialog(bool isSave) { - const EnginePlugin *plugin = NULL; - EngineMan.findGame(ConfMan.get("gameid"), &plugin); GUI::SaveLoadChooser *dialog; Common::String desc; int slot; @@ -804,7 +802,7 @@ int AgiEngine::scummVMSaveLoadDialog(bool isSave) { if (isSave) { dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true); - slot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + slot = dialog->runModalWithCurrentTarget(); desc = dialog->getResultString(); if (desc.empty()) { @@ -824,7 +822,7 @@ int AgiEngine::scummVMSaveLoadDialog(bool isSave) { desc = Common::String(desc.c_str(), 28); } else { dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false); - slot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + slot = dialog->runModalWithCurrentTarget(); } delete dialog; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index e9035841000..095aac24120 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -70,11 +70,8 @@ bool Keyboard::getKey(Common::Event &event) { return false; case Common::KEYCODE_F5: if (_vm->canSaveGameStateCurrently()) { - const EnginePlugin *plugin = NULL; - EngineMan.findGame(_vm->_gameDescription->gameid, &plugin); - GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Save game:", "Save", true); - int16 savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + int16 savegameId = dialog->runModalWithCurrentTarget(); Common::String savegameDescription = dialog->getResultString(); delete dialog; @@ -84,11 +81,8 @@ bool Keyboard::getKey(Common::Event &event) { return false; case Common::KEYCODE_F7: if (_vm->canLoadGameStateCurrently()) { - const EnginePlugin *plugin = NULL; - EngineMan.findGame(_vm->_gameDescription->gameid, &plugin); - GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Restore game:", "Restore", false); - int16 savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + int16 savegameId = dialog->runModalWithCurrentTarget(); delete dialog; if (savegameId != -1) diff --git a/engines/cruise/menu.cpp b/engines/cruise/menu.cpp index 988355e7773..512259f7d74 100644 --- a/engines/cruise/menu.cpp +++ b/engines/cruise/menu.cpp @@ -207,15 +207,13 @@ int processMenu(menuStruct *pMenu) { } static void handleSaveLoad(bool saveFlag) { - const EnginePlugin *plugin = 0; - EngineMan.findGame(_vm->getGameId(), &plugin); GUI::SaveLoadChooser *dialog; if (saveFlag) dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true); else dialog = new GUI::SaveLoadChooser(_("Load game:"), _("Load"), false); - int slot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + int slot = dialog->runModalWithCurrentTarget(); if (slot >= 0) { if (!saveFlag) diff --git a/engines/dialogs.cpp b/engines/dialogs.cpp index 3fa01ddcbf6..9245d9fe624 100644 --- a/engines/dialogs.cpp +++ b/engines/dialogs.cpp @@ -214,12 +214,7 @@ void MainMenuDialog::reflowLayout() { } void MainMenuDialog::save() { - const Common::String gameId = ConfMan.get("gameid"); - - const EnginePlugin *plugin = 0; - EngineMan.findGame(gameId, &plugin); - - int slot = _saveDialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + int slot = _saveDialog->runModalWithCurrentTarget(); if (slot >= 0) { Common::String result(_saveDialog->getResultString()); @@ -250,12 +245,7 @@ void MainMenuDialog::save() { } void MainMenuDialog::load() { - const Common::String gameId = ConfMan.get("gameid"); - - const EnginePlugin *plugin = 0; - EngineMan.findGame(gameId, &plugin); - - int slot = _loadDialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + int slot = _loadDialog->runModalWithCurrentTarget(); _engine->setGameToLoadSlot(slot); diff --git a/engines/dreamweb/saveload.cpp b/engines/dreamweb/saveload.cpp index e659c03e135..ea9cdc0249f 100644 --- a/engines/dreamweb/saveload.cpp +++ b/engines/dreamweb/saveload.cpp @@ -158,11 +158,8 @@ void DreamWebEngine::doLoad(int savegameId) { if (savegameId == -1) { // Open dialog to get savegameId - const EnginePlugin *plugin = NULL; - Common::String gameId = ConfMan.get("gameid"); - EngineMan.findGame(gameId, &plugin); GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false); - savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + savegameId = dialog->runModalWithCurrentTarget(); delete dialog; } @@ -244,11 +241,8 @@ void DreamWebEngine::saveGame() { } return; } else { - const EnginePlugin *plugin = NULL; - Common::String gameId = ConfMan.get("gameid"); - EngineMan.findGame(gameId, &plugin); GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true); - int savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + int savegameId = dialog->runModalWithCurrentTarget(); Common::String game_description = dialog->getResultString(); if (game_description.empty()) game_description = "Untitled"; diff --git a/engines/hugo/file.cpp b/engines/hugo/file.cpp index 3c94b2ee3da..f94f3b0443b 100644 --- a/engines/hugo/file.cpp +++ b/engines/hugo/file.cpp @@ -330,14 +330,12 @@ sound_pt FileManager::getSound(const int16 sound, uint16 *size) { bool FileManager::saveGame(const int16 slot, const Common::String &descrip) { debugC(1, kDebugFile, "saveGame(%d, %s)", slot, descrip.c_str()); - const EnginePlugin *plugin = NULL; int16 savegameId; Common::String savegameDescription; - EngineMan.findGame(_vm->getGameId(), &plugin); if (slot == -1) { GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Save game:", "Save", true); - savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + savegameId = dialog->runModalWithCurrentTarget(); savegameDescription = dialog->getResultString(); delete dialog; } else { @@ -435,13 +433,11 @@ bool FileManager::saveGame(const int16 slot, const Common::String &descrip) { bool FileManager::restoreGame(const int16 slot) { debugC(1, kDebugFile, "restoreGame(%d)", slot); - const EnginePlugin *plugin = NULL; int16 savegameId; - EngineMan.findGame(_vm->getGameId(), &plugin); if (slot == -1) { GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Restore game:", "Restore", false); - savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + savegameId = dialog->runModalWithCurrentTarget(); delete dialog; } else { savegameId = slot; diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp index d66e46f4a80..e54d6fefa2a 100644 --- a/engines/mohawk/riven.cpp +++ b/engines/mohawk/riven.cpp @@ -715,12 +715,7 @@ void MohawkEngine_Riven::delayAndUpdate(uint32 ms) { void MohawkEngine_Riven::runLoadDialog() { GUI::SaveLoadChooser slc(_("Load game:"), _("Load"), false); - Common::String gameId = ConfMan.get("gameid"); - - const EnginePlugin *plugin = 0; - EngineMan.findGame(gameId, &plugin); - - int slot = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + int slot = slc.runModalWithCurrentTarget(); if (slot >= 0) loadGameState(slot); } diff --git a/engines/parallaction/saveload.cpp b/engines/parallaction/saveload.cpp index 85923363c78..8de2d89b187 100644 --- a/engines/parallaction/saveload.cpp +++ b/engines/parallaction/saveload.cpp @@ -184,12 +184,7 @@ int SaveLoad::selectSaveFile(Common::String &selectedName, bool saveMode, const selectedName.clear(); - Common::String gameId = ConfMan.get("gameid"); - - const EnginePlugin *plugin = 0; - EngineMan.findGame(gameId, &plugin); - - int idx = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + int idx = slc.runModalWithCurrentTarget(); if (idx >= 0) { selectedName = slc.getResultString(); } diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp index 6c40be87e28..4af71f41af0 100644 --- a/engines/sci/engine/kfile.cpp +++ b/engines/sci/engine/kfile.cpp @@ -562,10 +562,8 @@ reg_t kSaveGame(EngineState *s, int argc, reg_t *argv) { // we are supposed to show a dialog for the user and let him choose where to save g_sci->_soundCmd->pauseAll(true); // pause music - const EnginePlugin *plugin = NULL; - EngineMan.findGame(g_sci->getGameIdStr(), &plugin); GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true); - savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + savegameId = dialog->runModalWithCurrentTarget(); game_description = dialog->getResultString(); if (game_description.empty()) { // create our own description for the saved game, the user didnt enter it @@ -668,10 +666,8 @@ reg_t kRestoreGame(EngineState *s, int argc, reg_t *argv) { if (savegameId == -1) { // we are supposed to show a dialog for the user and let him choose a saved game g_sci->_soundCmd->pauseAll(true); // pause music - const EnginePlugin *plugin = NULL; - EngineMan.findGame(g_sci->getGameIdStr(), &plugin); GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false); - savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + savegameId = dialog->runModalWithCurrentTarget(); delete dialog; if (savegameId < 0) { g_sci->_soundCmd->pauseAll(false); // unpause music diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp index 9da06ce5bee..be298e12366 100644 --- a/engines/toon/toon.cpp +++ b/engines/toon/toon.cpp @@ -2955,14 +2955,12 @@ Common::String ToonEngine::getSavegameName(int nr) { } bool ToonEngine::saveGame(int32 slot, const Common::String &saveGameDesc) { - const EnginePlugin *plugin = NULL; int16 savegameId; Common::String savegameDescription; - EngineMan.findGame(_gameDescription->gameid, &plugin); if (slot == -1) { GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Save game:", "Save", true); - savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + savegameId = dialog->runModalWithCurrentTarget(); savegameDescription = dialog->getResultString(); delete dialog; } else { @@ -3051,13 +3049,11 @@ bool ToonEngine::saveGame(int32 slot, const Common::String &saveGameDesc) { } bool ToonEngine::loadGame(int32 slot) { - const EnginePlugin *plugin = NULL; int16 savegameId; - EngineMan.findGame(_gameDescription->gameid, &plugin); if (slot == -1) { GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Restore game:", "Restore", false); - savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + savegameId = dialog->runModalWithCurrentTarget(); delete dialog; } else { savegameId = slot; diff --git a/engines/tsage/scenes.cpp b/engines/tsage/scenes.cpp index 8fe7b8c4586..774a5277dc4 100644 --- a/engines/tsage/scenes.cpp +++ b/engines/tsage/scenes.cpp @@ -569,15 +569,13 @@ void Game::quitGame() { } void Game::handleSaveLoad(bool saveFlag, int &saveSlot, Common::String &saveName) { - const EnginePlugin *plugin = 0; - EngineMan.findGame(g_vm->getGameId(), &plugin); GUI::SaveLoadChooser *dialog; if (saveFlag) dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), saveFlag); else dialog = new GUI::SaveLoadChooser(_("Load game:"), _("Load"), saveFlag); - saveSlot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + saveSlot = dialog->runModalWithCurrentTarget(); saveName = dialog->getResultString(); delete dialog; diff --git a/gui/saveload.cpp b/gui/saveload.cpp index c7da94357f7..366efa7a904 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -76,6 +76,15 @@ SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, SaveLoadChooser::~SaveLoadChooser() { } +int SaveLoadChooser::runModalWithCurrentTarget() { + const Common::String gameId = ConfMan.get("gameid"); + + const EnginePlugin *plugin = 0; + EngineMan.findGame(gameId, &plugin); + + return runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); +} + int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target) { if (_gfxWidget) _gfxWidget->setGfx(0); diff --git a/gui/saveload.h b/gui/saveload.h index e6fea0fb522..dc0f0429c71 100644 --- a/gui/saveload.h +++ b/gui/saveload.h @@ -67,6 +67,13 @@ public: virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data); void setList(const StringArray& list); + /** + * Runs the save/load chooser with the currently active config manager + * domain as target. + * + * @return The selcted save slot. -1 in case none is selected. + */ + int runModalWithCurrentTarget(); int runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target); void open();