[Scummvm-cvs-logs] scummvm master -> 49fafb48a7f089c97ed3baa9aefe65ec56dce682
lordhoto
lordhoto at gmail.com
Sun Jun 10 05:07:19 CEST 2012
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
7c5cf1b400 GUI: Add helper to SaveLoadChooser, which uses the currently active target.
49fafb48a7 GUI: Refactor default savegame description creation.
Commit: 7c5cf1b400808865a5f601f70d624ad6704a0c8c
https://github.com/scummvm/scummvm/commit/7c5cf1b400808865a5f601f70d624ad6704a0c8c
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2012-06-09T19:53:17-07:00
Commit Message:
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.
Changed paths:
engines/agi/saveload.cpp
engines/cge/events.cpp
engines/cruise/menu.cpp
engines/dialogs.cpp
engines/dreamweb/saveload.cpp
engines/hugo/file.cpp
engines/mohawk/riven.cpp
engines/parallaction/saveload.cpp
engines/sci/engine/kfile.cpp
engines/toon/toon.cpp
engines/tsage/scenes.cpp
gui/saveload.cpp
gui/saveload.h
diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp
index cb7792a..25fa782 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 e903584..095aac2 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 988355e..512259f 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 3fa01dd..9245d9f 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 e659c03..ea9cdc0 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 3c94b2e..f94f3b0 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 d66e46f..e54d6fe 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 8592336..8de2d89 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 6c40be8..4af71f4 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 9da06ce..be298e1 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 8fe7b8c..774a527 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 c7da943..366efa7 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 e6fea0f..dc0f042 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();
Commit: 49fafb48a7f089c97ed3baa9aefe65ec56dce682
https://github.com/scummvm/scummvm/commit/49fafb48a7f089c97ed3baa9aefe65ec56dce682
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2012-06-09T20:04:59-07:00
Commit Message:
GUI: Refactor default savegame description creation.
Formerly the GMM, AGI and SCI duplicated the logic for USE_SAVEGAME_TIMESTAMP.
Now I added a method to SaveLoadChooser instead, which takes care of this. This
might not be the best placement of such a functionality, thus I added a TODO
which talks about moving it to a better place.
Changed paths:
engines/agi/saveload.cpp
engines/dialogs.cpp
engines/sci/engine/kfile.cpp
gui/saveload.cpp
gui/saveload.h
diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp
index 25fa782..3e63da7 100644
--- a/engines/agi/saveload.cpp
+++ b/engines/agi/saveload.cpp
@@ -807,15 +807,7 @@ int AgiEngine::scummVMSaveLoadDialog(bool isSave) {
if (desc.empty()) {
// create our own description for the saved game, the user didnt enter it
-#if defined(USE_SAVEGAME_TIMESTAMP)
- TimeDate curTime;
- g_system->getTimeAndDate(curTime);
- curTime.tm_year += 1900; // fixup year
- curTime.tm_mon++; // fixup month
- desc = Common::String::format("%04d.%02d.%02d / %02d:%02d:%02d", curTime.tm_year, curTime.tm_mon, curTime.tm_mday, curTime.tm_hour, curTime.tm_min, curTime.tm_sec);
-#else
- desc = Common::String::format("Save %d", slot + 1);
-#endif
+ desc = dialog->createDefaultSaveDescription(slot);
}
if (desc.size() > 28)
diff --git a/engines/dialogs.cpp b/engines/dialogs.cpp
index 9245d9f..cf3dfaa 100644
--- a/engines/dialogs.cpp
+++ b/engines/dialogs.cpp
@@ -220,15 +220,7 @@ void MainMenuDialog::save() {
Common::String result(_saveDialog->getResultString());
if (result.empty()) {
// If the user was lazy and entered no save name, come up with a default name.
- #if defined(USE_SAVEGAME_TIMESTAMP)
- TimeDate curTime;
- g_system->getTimeAndDate(curTime);
- curTime.tm_year += 1900; // fixup year
- curTime.tm_mon++; // fixup month
- result = Common::String::format("%04d.%02d.%02d / %02d:%02d:%02d", curTime.tm_year, curTime.tm_mon, curTime.tm_mday, curTime.tm_hour, curTime.tm_min, curTime.tm_sec);
- #else
- result = Common::String::format("Save %d", slot + 1);
- #endif
+ result = _saveDialog->createDefaultSaveDescription(slot);
}
Common::Error status = _engine->saveGameState(slot, result);
diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp
index 4af71f4..42f8b88 100644
--- a/engines/sci/engine/kfile.cpp
+++ b/engines/sci/engine/kfile.cpp
@@ -567,15 +567,7 @@ reg_t kSaveGame(EngineState *s, int argc, reg_t *argv) {
game_description = dialog->getResultString();
if (game_description.empty()) {
// create our own description for the saved game, the user didnt enter it
- #if defined(USE_SAVEGAME_TIMESTAMP)
- TimeDate curTime;
- g_system->getTimeAndDate(curTime);
- curTime.tm_year += 1900; // fixup year
- curTime.tm_mon++; // fixup month
- game_description = Common::String::format("%04d.%02d.%02d / %02d:%02d:%02d", curTime.tm_year, curTime.tm_mon, curTime.tm_mday, curTime.tm_hour, curTime.tm_min, curTime.tm_sec);
- #else
- game_description = Common::String::format("Save %d", savegameId + 1);
- #endif
+ game_description = dialog->createDefaultSaveDescription(savegameId);
}
delete dialog;
g_sci->_soundCmd->pauseAll(false); // unpause music ( we can't have it paused during save)
diff --git a/gui/saveload.cpp b/gui/saveload.cpp
index 366efa7..67d871e 100644
--- a/gui/saveload.cpp
+++ b/gui/saveload.cpp
@@ -21,6 +21,7 @@
#include "common/config-manager.h"
#include "common/translation.h"
+#include "common/system.h"
#include "gui/widgets/list.h"
#include "gui/message.h"
@@ -126,6 +127,18 @@ const Common::String &SaveLoadChooser::getResultString() const {
return (selItem >= 0) ? _list->getSelectedString() : _resultString;
}
+Common::String SaveLoadChooser::createDefaultSaveDescription(const int slot) const {
+#if defined(USE_SAVEGAME_TIMESTAMP)
+ TimeDate curTime;
+ g_system->getTimeAndDate(curTime);
+ curTime.tm_year += 1900; // fixup year
+ curTime.tm_mon++; // fixup month
+ return Common::String::format("%04d.%02d.%02d / %02d:%02d:%02d", curTime.tm_year, curTime.tm_mon, curTime.tm_mday, curTime.tm_hour, curTime.tm_min, curTime.tm_sec);
+#else
+ return Common::String::format("Save %d", slot + 1);
+#endif
+}
+
void SaveLoadChooser::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
int selItem = _list->getSelected();
diff --git a/gui/saveload.h b/gui/saveload.h
index dc0f042..e81b10d 100644
--- a/gui/saveload.h
+++ b/gui/saveload.h
@@ -79,6 +79,21 @@ public:
const Common::String &getResultString() const;
+ /**
+ * Creates a default save description for the specified slot. Depending
+ * on the ScummVM configuration this might be a simple "Slot #" description
+ * or the current date and time.
+ *
+ * TODO: This might not be the best place to put this, since engines not
+ * using this class might want to mimic the same behavior. Check whether
+ * moving this to a better place makes sense and find what this place would
+ * be.
+ *
+ * @param slot The slot number (must be >= 0).
+ * @return The slot description.
+ */
+ Common::String createDefaultSaveDescription(const int slot) const;
+
virtual void reflowLayout();
virtual void close();
More information about the Scummvm-git-logs
mailing list