From 15046a7529e3c755de1f00b4a2666786eb2bd4f8 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 10 Jun 2012 04:14:17 +0200 Subject: GUI: Get rid of SaveLoadChooser::setSaveMode. We already pass the title and process button name to the constructor of SaveLoadChooser and then do not offer any way of changing it, thus changing the edit mode of the chooser is kind of pointless and was never actually used. Instead we pass the mode on SaveLoadChooser construction now. --- gui/saveload.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index 3dc9961906..c7da94357f 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -40,7 +40,7 @@ enum { }; -SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel) +SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode) : Dialog("SaveLoadChooser"), _delSupport(0), _list(0), _chooseButton(0), _deleteButton(0), _gfxWidget(0) { _delSupport = _metaInfoSupport = _thumbnailSupport = _saveDateSupport = _playTimeSupport = false; @@ -51,7 +51,7 @@ SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel) // Add choice list _list = new GUI::ListWidget(this, "SaveLoadChooser.List"); _list->setNumberingMode(GUI::kListNumberingZero); - setSaveMode(false); + _list->setEditable(saveMode); _gfxWidget = new GUI::GraphicsWidget(this, 0, 0, 10, 10); @@ -117,10 +117,6 @@ const Common::String &SaveLoadChooser::getResultString() const { return (selItem >= 0) ? _list->getSelectedString() : _resultString; } -void SaveLoadChooser::setSaveMode(bool saveMode) { - _list->setEditable(saveMode); -} - void SaveLoadChooser::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { int selItem = _list->getSelected(); -- cgit v1.2.3 From 7c5cf1b400808865a5f601f70d624ad6704a0c8c Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 10 Jun 2012 04:49:42 +0200 Subject: 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. --- gui/saveload.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index c7da94357f..366efa7a90 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); -- cgit v1.2.3 From 49fafb48a7f089c97ed3baa9aefe65ec56dce682 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 10 Jun 2012 05:04:59 +0200 Subject: 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. --- gui/saveload.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index 366efa7a90..67d871e133 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(); -- cgit v1.2.3