From 27b8b7e9b6644767ad9de1e40c188a7abd631c4e Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 10 Jun 2012 04:06:25 +0200 Subject: GUI: Hide save/load chooser implementation. --- gui/saveload.cpp | 125 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 99 insertions(+), 26 deletions(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index 67d871e133..717523b107 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -41,8 +41,52 @@ enum { }; -SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode) - : Dialog("SaveLoadChooser"), _delSupport(0), _list(0), _chooseButton(0), _deleteButton(0), _gfxWidget(0) { +class SaveLoadChooserImpl : GUI::Dialog { + typedef Common::String String; + typedef Common::Array StringArray; +public: + SaveLoadChooserImpl(const String &title, const String &buttonLabel, bool saveMode); + + int runModalWithCurrentTarget(); + int runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target); + + virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data); + + const Common::String &getResultString() const; + + virtual void open(); + + virtual void reflowLayout(); + + virtual void close(); +private: + GUI::ListWidget *_list; + GUI::ButtonWidget *_chooseButton; + GUI::ButtonWidget *_deleteButton; + GUI::GraphicsWidget *_gfxWidget; + GUI::ContainerWidget *_container; + GUI::StaticTextWidget *_date; + GUI::StaticTextWidget *_time; + GUI::StaticTextWidget *_playtime; + + const EnginePlugin *_plugin; + bool _delSupport; + bool _metaInfoSupport; + bool _thumbnailSupport; + bool _saveDateSupport; + bool _playTimeSupport; + String _target; + SaveStateList _saveList; + String _resultString; + + uint8 _fillR, _fillG, _fillB; + + void updateSaveList(); + void updateSelection(bool redraw); +}; + +SaveLoadChooserImpl::SaveLoadChooserImpl(const String &title, const String &buttonLabel, bool saveMode) + : Dialog("SaveLoadChooser"), _list(0), _chooseButton(0), _deleteButton(0), _gfxWidget(0) { _delSupport = _metaInfoSupport = _thumbnailSupport = _saveDateSupport = _playTimeSupport = false; _backgroundType = ThemeEngine::kDialogBackgroundSpecial; @@ -74,10 +118,7 @@ SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, // _container->setHints(GUI::THEME_HINT_USE_SHADOW); } -SaveLoadChooser::~SaveLoadChooser() { -} - -int SaveLoadChooser::runModalWithCurrentTarget() { +int SaveLoadChooserImpl::runModalWithCurrentTarget() { const Common::String gameId = ConfMan.get("gameid"); const EnginePlugin *plugin = 0; @@ -86,7 +127,7 @@ int SaveLoadChooser::runModalWithCurrentTarget() { return runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); } -int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target) { +int SaveLoadChooserImpl::runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target) { if (_gfxWidget) _gfxWidget->setGfx(0); @@ -114,7 +155,7 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, con return ret; } -void SaveLoadChooser::open() { +void SaveLoadChooserImpl::open() { Dialog::open(); // So that quitting ScummVM will not cause the dialog result to say a @@ -122,24 +163,12 @@ void SaveLoadChooser::open() { setResult(-1); } -const Common::String &SaveLoadChooser::getResultString() const { +const Common::String &SaveLoadChooserImpl::getResultString() const { int selItem = _list->getSelected(); 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) { +void SaveLoadChooserImpl::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { int selItem = _list->getSelected(); switch (cmd) { @@ -189,7 +218,7 @@ void SaveLoadChooser::handleCommand(CommandSender *sender, uint32 cmd, uint32 da } } -void SaveLoadChooser::reflowLayout() { +void SaveLoadChooserImpl::reflowLayout() { if (g_gui.xmlEval()->getVar("Globals.SaveLoadChooser.ExtInfo.Visible") == 1 && _thumbnailSupport) { int16 x, y; uint16 w, h; @@ -246,7 +275,7 @@ void SaveLoadChooser::reflowLayout() { Dialog::reflowLayout(); } -void SaveLoadChooser::updateSelection(bool redraw) { +void SaveLoadChooserImpl::updateSelection(bool redraw) { int selItem = _list->getSelected(); bool isDeletable = _delSupport; @@ -329,7 +358,7 @@ void SaveLoadChooser::updateSelection(bool redraw) { } } -void SaveLoadChooser::close() { +void SaveLoadChooserImpl::close() { _plugin = 0; _target.clear(); _saveList.clear(); @@ -338,7 +367,7 @@ void SaveLoadChooser::close() { Dialog::close(); } -void SaveLoadChooser::updateSaveList() { +void SaveLoadChooserImpl::updateSaveList() { _saveList = (*_plugin)->listSaves(_target.c_str()); int curSlot = 0; @@ -402,4 +431,48 @@ void SaveLoadChooser::updateSaveList() { _list->setList(saveNames, &colors); } +// --- SaveLoadChooser implementation --- + +SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode) { + _impl = new SaveLoadChooserImpl(title, buttonLabel, saveMode); +} + +SaveLoadChooser::~SaveLoadChooser() { + delete _impl; + _impl = 0; +} + +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 +} + +int SaveLoadChooser::runModalWithCurrentTarget() { + if (_impl) + return _impl->runModalWithCurrentTarget(); + else + return -1; +} + +int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target) { + if (_impl) + return _impl->runModalWithPluginAndTarget(plugin, target); + else + return -1; +} + +Common::String SaveLoadChooser::getResultString() const { + if (_impl) + return _impl->getResultString(); + else + return Common::String(); +} + } // End of namespace GUI -- cgit v1.2.3 From e866dfd4069dfb4418ebdc0d4522b56aebed7522 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 14 Jun 2012 03:13:49 +0200 Subject: GUI: Refactor engine plugin access out of SaveLoadChooserImpl into SaveLoadChooser. --- gui/saveload.cpp | 77 ++++++++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 41 deletions(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index 717523b107..e2f9461ddb 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -47,8 +47,7 @@ class SaveLoadChooserImpl : GUI::Dialog { public: SaveLoadChooserImpl(const String &title, const String &buttonLabel, bool saveMode); - int runModalWithCurrentTarget(); - int runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target); + int run(const String &target, const MetaEngine *metaEngine); virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data); @@ -69,7 +68,7 @@ private: GUI::StaticTextWidget *_time; GUI::StaticTextWidget *_playtime; - const EnginePlugin *_plugin; + const MetaEngine *_metaEngine; bool _delSupport; bool _metaInfoSupport; bool _thumbnailSupport; @@ -118,41 +117,22 @@ SaveLoadChooserImpl::SaveLoadChooserImpl(const String &title, const String &butt // _container->setHints(GUI::THEME_HINT_USE_SHADOW); } -int SaveLoadChooserImpl::runModalWithCurrentTarget() { - const Common::String gameId = ConfMan.get("gameid"); - - const EnginePlugin *plugin = 0; - EngineMan.findGame(gameId, &plugin); - - return runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); -} - -int SaveLoadChooserImpl::runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target) { +int SaveLoadChooserImpl::run(const String &target, const MetaEngine *metaEngine) { if (_gfxWidget) _gfxWidget->setGfx(0); - // Set up the game domain as newly active domain, so - // target specific savepath will be checked - String oldDomain = ConfMan.getActiveDomainName(); - ConfMan.setActiveDomain(target); - - _plugin = plugin; + _metaEngine = metaEngine; _target = target; - _delSupport = (*_plugin)->hasFeature(MetaEngine::kSupportsDeleteSave); - _metaInfoSupport = (*_plugin)->hasFeature(MetaEngine::kSavesSupportMetaInfo); - _thumbnailSupport = _metaInfoSupport && (*_plugin)->hasFeature(MetaEngine::kSavesSupportThumbnail); - _saveDateSupport = _metaInfoSupport && (*_plugin)->hasFeature(MetaEngine::kSavesSupportCreationDate); - _playTimeSupport = _metaInfoSupport && (*_plugin)->hasFeature(MetaEngine::kSavesSupportPlayTime); + _delSupport = _metaEngine->hasFeature(MetaEngine::kSupportsDeleteSave); + _metaInfoSupport = _metaEngine->hasFeature(MetaEngine::kSavesSupportMetaInfo); + _thumbnailSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngine::kSavesSupportThumbnail); + _saveDateSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngine::kSavesSupportCreationDate); + _playTimeSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngine::kSavesSupportPlayTime); _resultString.clear(); reflowLayout(); updateSaveList(); - int ret = Dialog::runModal(); - - // Revert to the old active domain - ConfMan.setActiveDomain(oldDomain); - - return ret; + return Dialog::runModal(); } void SaveLoadChooserImpl::open() { @@ -201,7 +181,7 @@ void SaveLoadChooserImpl::handleCommand(CommandSender *sender, uint32 cmd, uint3 MessageDialog alert(_("Do you really want to delete this savegame?"), _("Delete"), _("Cancel")); if (alert.runModal() == GUI::kMessageOK) { - (*_plugin)->removeSaveState(_target.c_str(), _saveList[selItem].getSaveSlot()); + _metaEngine->removeSaveState(_target.c_str(), _saveList[selItem].getSaveSlot()); setResult(-1); _list->setSelected(-1); @@ -288,7 +268,7 @@ void SaveLoadChooserImpl::updateSelection(bool redraw) { _playtime->setLabel(_("No playtime saved")); if (selItem >= 0 && _metaInfoSupport) { - SaveStateDescriptor desc = (*_plugin)->querySaveMetaInfos(_target.c_str(), _saveList[selItem].getSaveSlot()); + SaveStateDescriptor desc = _metaEngine->querySaveMetaInfos(_target.c_str(), _saveList[selItem].getSaveSlot()); isDeletable = desc.getDeletableFlag() && _delSupport; isWriteProtected = desc.getWriteProtectedFlag(); @@ -359,7 +339,7 @@ void SaveLoadChooserImpl::updateSelection(bool redraw) { } void SaveLoadChooserImpl::close() { - _plugin = 0; + _metaEngine = 0; _target.clear(); _saveList.clear(); _list->setList(StringArray()); @@ -368,7 +348,7 @@ void SaveLoadChooserImpl::close() { } void SaveLoadChooserImpl::updateSaveList() { - _saveList = (*_plugin)->listSaves(_target.c_str()); + _saveList = _metaEngine->listSaves(_target.c_str()); int curSlot = 0; int saveSlot = 0; @@ -410,7 +390,7 @@ void SaveLoadChooserImpl::updateSaveList() { // Fill the rest of the save slots with empty saves - int maximumSaveSlots = (*_plugin)->getMaximumSaveSlot(); + int maximumSaveSlots = _metaEngine->getMaximumSaveSlot(); #ifdef __DS__ // Low memory on the DS means too many save slots are impractical, so limit @@ -455,17 +435,32 @@ Common::String SaveLoadChooser::createDefaultSaveDescription(const int slot) con } int SaveLoadChooser::runModalWithCurrentTarget() { - if (_impl) - return _impl->runModalWithCurrentTarget(); - else + if (!_impl) return -1; + + 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 (_impl) - return _impl->runModalWithPluginAndTarget(plugin, target); - else + if (!_impl) return -1; + + // Set up the game domain as newly active domain, so + // target specific savepath will be checked + String oldDomain = ConfMan.getActiveDomainName(); + ConfMan.setActiveDomain(target); + + int ret = _impl->run(target, &(**plugin)); + + // Revert to the old active domain + ConfMan.setActiveDomain(oldDomain); + + return ret; } Common::String SaveLoadChooser::getResultString() const { -- cgit v1.2.3 From 1aa5200bb824119651e19a1809d9c07292da57fe Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 14 Jun 2012 03:33:50 +0200 Subject: GUI: Create an interface for save/load dialogs. --- gui/saveload.cpp | 388 +------------------------------------------------------ 1 file changed, 2 insertions(+), 386 deletions(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index e2f9461ddb..e0e6d6187e 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -20,401 +20,17 @@ */ #include "common/config-manager.h" -#include "common/translation.h" #include "common/system.h" -#include "gui/widgets/list.h" -#include "gui/message.h" #include "gui/saveload.h" -#include "gui/ThemeEval.h" -#include "gui/gui-manager.h" - -#include "graphics/scaler.h" +#include "gui/saveload-dialog.h" #include "engines/metaengine.h" namespace GUI { -enum { - kChooseCmd = 'CHOS', - kDelCmd = 'DEL ' - -}; - -class SaveLoadChooserImpl : GUI::Dialog { - typedef Common::String String; - typedef Common::Array StringArray; -public: - SaveLoadChooserImpl(const String &title, const String &buttonLabel, bool saveMode); - - int run(const String &target, const MetaEngine *metaEngine); - - virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data); - - const Common::String &getResultString() const; - - virtual void open(); - - virtual void reflowLayout(); - - virtual void close(); -private: - GUI::ListWidget *_list; - GUI::ButtonWidget *_chooseButton; - GUI::ButtonWidget *_deleteButton; - GUI::GraphicsWidget *_gfxWidget; - GUI::ContainerWidget *_container; - GUI::StaticTextWidget *_date; - GUI::StaticTextWidget *_time; - GUI::StaticTextWidget *_playtime; - - const MetaEngine *_metaEngine; - bool _delSupport; - bool _metaInfoSupport; - bool _thumbnailSupport; - bool _saveDateSupport; - bool _playTimeSupport; - String _target; - SaveStateList _saveList; - String _resultString; - - uint8 _fillR, _fillG, _fillB; - - void updateSaveList(); - void updateSelection(bool redraw); -}; - -SaveLoadChooserImpl::SaveLoadChooserImpl(const String &title, const String &buttonLabel, bool saveMode) - : Dialog("SaveLoadChooser"), _list(0), _chooseButton(0), _deleteButton(0), _gfxWidget(0) { - _delSupport = _metaInfoSupport = _thumbnailSupport = _saveDateSupport = _playTimeSupport = false; - - _backgroundType = ThemeEngine::kDialogBackgroundSpecial; - - new StaticTextWidget(this, "SaveLoadChooser.Title", title); - - // Add choice list - _list = new GUI::ListWidget(this, "SaveLoadChooser.List"); - _list->setNumberingMode(GUI::kListNumberingZero); - _list->setEditable(saveMode); - - _gfxWidget = new GUI::GraphicsWidget(this, 0, 0, 10, 10); - - _date = new StaticTextWidget(this, 0, 0, 10, 10, _("No date saved"), Graphics::kTextAlignCenter); - _time = new StaticTextWidget(this, 0, 0, 10, 10, _("No time saved"), Graphics::kTextAlignCenter); - _playtime = new StaticTextWidget(this, 0, 0, 10, 10, _("No playtime saved"), Graphics::kTextAlignCenter); - - // Buttons - new GUI::ButtonWidget(this, "SaveLoadChooser.Cancel", _("Cancel"), 0, kCloseCmd); - _chooseButton = new GUI::ButtonWidget(this, "SaveLoadChooser.Choose", buttonLabel, 0, kChooseCmd); - _chooseButton->setEnabled(false); - - _deleteButton = new GUI::ButtonWidget(this, "SaveLoadChooser.Delete", _("Delete"), 0, kDelCmd); - _deleteButton->setEnabled(false); - - _delSupport = _metaInfoSupport = _thumbnailSupport = false; - - _container = new GUI::ContainerWidget(this, 0, 0, 10, 10); -// _container->setHints(GUI::THEME_HINT_USE_SHADOW); -} - -int SaveLoadChooserImpl::run(const String &target, const MetaEngine *metaEngine) { - if (_gfxWidget) - _gfxWidget->setGfx(0); - - _metaEngine = metaEngine; - _target = target; - _delSupport = _metaEngine->hasFeature(MetaEngine::kSupportsDeleteSave); - _metaInfoSupport = _metaEngine->hasFeature(MetaEngine::kSavesSupportMetaInfo); - _thumbnailSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngine::kSavesSupportThumbnail); - _saveDateSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngine::kSavesSupportCreationDate); - _playTimeSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngine::kSavesSupportPlayTime); - _resultString.clear(); - reflowLayout(); - updateSaveList(); - - return Dialog::runModal(); -} - -void SaveLoadChooserImpl::open() { - Dialog::open(); - - // So that quitting ScummVM will not cause the dialog result to say a - // savegame was selected. - setResult(-1); -} - -const Common::String &SaveLoadChooserImpl::getResultString() const { - int selItem = _list->getSelected(); - return (selItem >= 0) ? _list->getSelectedString() : _resultString; -} - -void SaveLoadChooserImpl::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { - int selItem = _list->getSelected(); - - switch (cmd) { - case GUI::kListItemActivatedCmd: - case GUI::kListItemDoubleClickedCmd: - if (selItem >= 0 && _chooseButton->isEnabled()) { - if (_list->isEditable() || !_list->getSelectedString().empty()) { - _list->endEditMode(); - if (!_saveList.empty()) { - setResult(_saveList[selItem].getSaveSlot()); - _resultString = _list->getSelectedString(); - } - close(); - } - } - break; - case kChooseCmd: - _list->endEditMode(); - if (!_saveList.empty()) { - setResult(_saveList[selItem].getSaveSlot()); - _resultString = _list->getSelectedString(); - } - close(); - break; - case GUI::kListSelectionChangedCmd: - updateSelection(true); - break; - case kDelCmd: - if (selItem >= 0 && _delSupport) { - MessageDialog alert(_("Do you really want to delete this savegame?"), - _("Delete"), _("Cancel")); - if (alert.runModal() == GUI::kMessageOK) { - _metaEngine->removeSaveState(_target.c_str(), _saveList[selItem].getSaveSlot()); - - setResult(-1); - _list->setSelected(-1); - - updateSaveList(); - updateSelection(true); - } - } - break; - case kCloseCmd: - setResult(-1); - default: - Dialog::handleCommand(sender, cmd, data); - } -} - -void SaveLoadChooserImpl::reflowLayout() { - if (g_gui.xmlEval()->getVar("Globals.SaveLoadChooser.ExtInfo.Visible") == 1 && _thumbnailSupport) { - int16 x, y; - uint16 w, h; - - if (!g_gui.xmlEval()->getWidgetData("SaveLoadChooser.Thumbnail", x, y, w, h)) - error("Error when loading position data for Save/Load Thumbnails"); - - int thumbW = kThumbnailWidth; - int thumbH = kThumbnailHeight2; - int thumbX = x + (w >> 1) - (thumbW >> 1); - int thumbY = y + kLineHeight; - - int textLines = 0; - if (!_saveDateSupport) - textLines++; - if (!_playTimeSupport) - textLines++; - - _container->resize(x, y, w, h - (kLineHeight * textLines)); - _gfxWidget->resize(thumbX, thumbY, thumbW, thumbH); - - int height = thumbY + thumbH + kLineHeight; - - if (_saveDateSupport) { - _date->resize(thumbX, height, kThumbnailWidth, kLineHeight); - height += kLineHeight; - _time->resize(thumbX, height, kThumbnailWidth, kLineHeight); - height += kLineHeight; - } - - if (_playTimeSupport) - _playtime->resize(thumbX, height, kThumbnailWidth, kLineHeight); - - _container->setVisible(true); - _gfxWidget->setVisible(true); - - _date->setVisible(_saveDateSupport); - _time->setVisible(_saveDateSupport); - - _playtime->setVisible(_playTimeSupport); - - _fillR = 0; - _fillG = 0; - _fillB = 0; - updateSelection(false); - } else { - _container->setVisible(false); - _gfxWidget->setVisible(false); - _date->setVisible(false); - _time->setVisible(false); - _playtime->setVisible(false); - } - - Dialog::reflowLayout(); -} - -void SaveLoadChooserImpl::updateSelection(bool redraw) { - int selItem = _list->getSelected(); - - bool isDeletable = _delSupport; - bool isWriteProtected = false; - bool startEditMode = _list->isEditable(); - - _gfxWidget->setGfx(-1, -1, _fillR, _fillG, _fillB); - _date->setLabel(_("No date saved")); - _time->setLabel(_("No time saved")); - _playtime->setLabel(_("No playtime saved")); - - if (selItem >= 0 && _metaInfoSupport) { - SaveStateDescriptor desc = _metaEngine->querySaveMetaInfos(_target.c_str(), _saveList[selItem].getSaveSlot()); - - isDeletable = desc.getDeletableFlag() && _delSupport; - isWriteProtected = desc.getWriteProtectedFlag(); - - // Don't allow the user to change the description of write protected games - if (isWriteProtected) - startEditMode = false; - - if (_thumbnailSupport) { - const Graphics::Surface *thumb = desc.getThumbnail(); - if (thumb) { - _gfxWidget->setGfx(thumb); - _gfxWidget->useAlpha(256); - } - } - - if (_saveDateSupport) { - const Common::String &saveDate = desc.getSaveDate(); - if (!saveDate.empty()) - _date->setLabel(_("Date: ") + saveDate); - - const Common::String &saveTime = desc.getSaveTime(); - if (!saveTime.empty()) - _time->setLabel(_("Time: ") + saveTime); - } - - if (_playTimeSupport) { - const Common::String &playTime = desc.getPlayTime(); - if (!playTime.empty()) - _playtime->setLabel(_("Playtime: ") + playTime); - } - } - - - if (_list->isEditable()) { - // Disable the save button if nothing is selected, or if the selected - // game is write protected - _chooseButton->setEnabled(selItem >= 0 && !isWriteProtected); - - if (startEditMode) { - _list->startEditMode(); - - if (_chooseButton->isEnabled() && _list->getSelectedString() == _("Untitled savestate") && - _list->getSelectionColor() == ThemeEngine::kFontColorAlternate) { - _list->setEditString(""); - _list->setEditColor(ThemeEngine::kFontColorNormal); - } - } - } else { - // Disable the load button if nothing is selected, or if an empty - // list item is selected. - _chooseButton->setEnabled(selItem >= 0 && !_list->getSelectedString().empty()); - } - - // Delete will always be disabled if the engine doesn't support it. - _deleteButton->setEnabled(isDeletable && (selItem >= 0) && (!_list->getSelectedString().empty())); - - if (redraw) { - _gfxWidget->draw(); - _date->draw(); - _time->draw(); - _playtime->draw(); - _chooseButton->draw(); - _deleteButton->draw(); - - draw(); - } -} - -void SaveLoadChooserImpl::close() { - _metaEngine = 0; - _target.clear(); - _saveList.clear(); - _list->setList(StringArray()); - - Dialog::close(); -} - -void SaveLoadChooserImpl::updateSaveList() { - _saveList = _metaEngine->listSaves(_target.c_str()); - - int curSlot = 0; - int saveSlot = 0; - StringArray saveNames; - ListWidget::ColorList colors; - for (SaveStateList::const_iterator x = _saveList.begin(); x != _saveList.end(); ++x) { - // Handle gaps in the list of save games - saveSlot = x->getSaveSlot(); - if (curSlot < saveSlot) { - while (curSlot < saveSlot) { - SaveStateDescriptor dummySave(curSlot, ""); - _saveList.insert_at(curSlot, dummySave); - saveNames.push_back(dummySave.getDescription()); - colors.push_back(ThemeEngine::kFontColorNormal); - curSlot++; - } - - // Sync the save list iterator - for (x = _saveList.begin(); x != _saveList.end(); ++x) { - if (x->getSaveSlot() == saveSlot) - break; - } - } - - // Show "Untitled savestate" for empty/whitespace savegame descriptions - Common::String description = x->getDescription(); - Common::String trimmedDescription = description; - trimmedDescription.trim(); - if (trimmedDescription.empty()) { - description = _("Untitled savestate"); - colors.push_back(ThemeEngine::kFontColorAlternate); - } else { - colors.push_back(ThemeEngine::kFontColorNormal); - } - - saveNames.push_back(description); - curSlot++; - } - - // Fill the rest of the save slots with empty saves - - int maximumSaveSlots = _metaEngine->getMaximumSaveSlot(); - -#ifdef __DS__ - // Low memory on the DS means too many save slots are impractical, so limit - // the maximum here. - if (maximumSaveSlots > 99) { - maximumSaveSlots = 99; - } -#endif - - Common::String emptyDesc; - for (int i = curSlot; i <= maximumSaveSlots; i++) { - saveNames.push_back(emptyDesc); - SaveStateDescriptor dummySave(i, ""); - _saveList.push_back(dummySave); - colors.push_back(ThemeEngine::kFontColorNormal); - } - - _list->setList(saveNames, &colors); -} - -// --- SaveLoadChooser implementation --- - SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode) { - _impl = new SaveLoadChooserImpl(title, buttonLabel, saveMode); + _impl = new SaveLoadChooserSimple(title, buttonLabel, saveMode); } SaveLoadChooser::~SaveLoadChooser() { -- cgit v1.2.3 From 72ea449431d9db61c45160f7c42d546599e84afe Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 15 Jun 2012 22:47:57 +0200 Subject: GUI: Hook up the new load chooser for > 320x200 and engines which support thumbnails. --- gui/saveload.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index e0e6d6187e..becc3f6b4f 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -24,13 +24,14 @@ #include "gui/saveload.h" #include "gui/saveload-dialog.h" +#include "gui/gui-manager.h" #include "engines/metaengine.h" namespace GUI { -SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode) { - _impl = new SaveLoadChooserSimple(title, buttonLabel, saveMode); +SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode) + : _impl(0), _title(title), _buttonLabel(buttonLabel), _saveMode(saveMode) { } SaveLoadChooser::~SaveLoadChooser() { @@ -38,6 +39,19 @@ SaveLoadChooser::~SaveLoadChooser() { _impl = 0; } +void SaveLoadChooser::selectChooser(const MetaEngine &engine) { + delete _impl; + _impl = 0; + + if (!_saveMode && g_gui.getWidth() > 320 && g_gui.getHeight() > 200 + && engine.hasFeature(MetaEngine::kSavesSupportMetaInfo) + && engine.hasFeature(MetaEngine::kSavesSupportThumbnail)) { + _impl = new LoadChooserThumbnailed(_title); + } else { + _impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode); + } +} + Common::String SaveLoadChooser::createDefaultSaveDescription(const int slot) const { #if defined(USE_SAVEGAME_TIMESTAMP) TimeDate curTime; @@ -51,9 +65,6 @@ Common::String SaveLoadChooser::createDefaultSaveDescription(const int slot) con } int SaveLoadChooser::runModalWithCurrentTarget() { - if (!_impl) - return -1; - const Common::String gameId = ConfMan.get("gameid"); const EnginePlugin *plugin = 0; @@ -63,6 +74,7 @@ int SaveLoadChooser::runModalWithCurrentTarget() { } int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target) { + selectChooser(**plugin); if (!_impl) return -1; -- cgit v1.2.3 From d3e5763276826d3f469fd93077c2f1ef6ef61314 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 29 Jun 2012 15:52:56 +0200 Subject: GUI: Allow the user to switch between list and thumbnail based load chooser. --- gui/saveload.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index becc3f6b4f..f544f0e6a0 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -83,7 +83,18 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, con String oldDomain = ConfMan.getActiveDomainName(); ConfMan.setActiveDomain(target); - int ret = _impl->run(target, &(**plugin)); + int ret; + do { + ret = _impl->run(target, &(**plugin)); + + if (ret == kSwitchToList) { + delete _impl; + _impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode); + } else if (ret == kSwitchToGrid) { + delete _impl; + _impl = new LoadChooserThumbnailed(_title); + } + } while (ret < -1); // Revert to the old active domain ConfMan.setActiveDomain(oldDomain); -- cgit v1.2.3 From e2056bdfd93ba247c819ec3fd2f0b487dde05709 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 29 Jun 2012 16:09:28 +0200 Subject: GUI: Remember last save/load chooser selection. --- gui/saveload.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index f544f0e6a0..9ae27f31be 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -43,9 +43,12 @@ void SaveLoadChooser::selectChooser(const MetaEngine &engine) { delete _impl; _impl = 0; + Common::String userConfig = ConfMan.get("gui_saveload_chooser", Common::ConfigManager::kApplicationDomain); + if (!_saveMode && g_gui.getWidth() > 320 && g_gui.getHeight() > 200 && engine.hasFeature(MetaEngine::kSavesSupportMetaInfo) - && engine.hasFeature(MetaEngine::kSavesSupportThumbnail)) { + && engine.hasFeature(MetaEngine::kSavesSupportThumbnail) + && userConfig.equalsIgnoreCase("grid")) { _impl = new LoadChooserThumbnailed(_title); } else { _impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode); @@ -90,9 +93,11 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, con if (ret == kSwitchToList) { delete _impl; _impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode); + ConfMan.set("gui_saveload_chooser", "list", Common::ConfigManager::kApplicationDomain); } else if (ret == kSwitchToGrid) { delete _impl; _impl = new LoadChooserThumbnailed(_title); + ConfMan.set("gui_saveload_chooser", "grid", Common::ConfigManager::kApplicationDomain); } } while (ret < -1); -- cgit v1.2.3 From 1c389e55105d40468ff9415a3d2b3ca31ef602b8 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 1 Jul 2012 15:43:20 +0200 Subject: GUI: Only use grid load dialog for 640x400 or bigger. Formerly it was enabled for everything above 320x200, but resolutions below 640x400 feature not enough space. --- gui/saveload.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index 9ae27f31be..9cc8935f03 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -45,7 +45,7 @@ void SaveLoadChooser::selectChooser(const MetaEngine &engine) { Common::String userConfig = ConfMan.get("gui_saveload_chooser", Common::ConfigManager::kApplicationDomain); - if (!_saveMode && g_gui.getWidth() > 320 && g_gui.getHeight() > 200 + if (!_saveMode && g_gui.getWidth() >= 640 && g_gui.getHeight() >= 400 && engine.hasFeature(MetaEngine::kSavesSupportMetaInfo) && engine.hasFeature(MetaEngine::kSavesSupportThumbnail) && userConfig.equalsIgnoreCase("grid")) { -- cgit v1.2.3 From 236db5ed87acf603898243734e2c5273c23568cb Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 1 Jul 2012 15:58:42 +0200 Subject: GUI: Automatically switch to list based save/load chooser when changing resolution below 640x400. --- gui/saveload.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index 9cc8935f03..7f3dd6d5d8 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -93,11 +93,9 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, con if (ret == kSwitchToList) { delete _impl; _impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode); - ConfMan.set("gui_saveload_chooser", "list", Common::ConfigManager::kApplicationDomain); } else if (ret == kSwitchToGrid) { delete _impl; _impl = new LoadChooserThumbnailed(_title); - ConfMan.set("gui_saveload_chooser", "grid", Common::ConfigManager::kApplicationDomain); } } while (ret < -1); -- cgit v1.2.3 From bd3d5fb8ffed3938c68a723d5c5bfbb6b56fb0ec Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 1 Jul 2012 16:07:48 +0200 Subject: GUI: Clean up save load chooser selection code. --- gui/saveload.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index 7f3dd6d5d8..12e62122fe 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -40,18 +40,20 @@ SaveLoadChooser::~SaveLoadChooser() { } void SaveLoadChooser::selectChooser(const MetaEngine &engine) { - delete _impl; - _impl = 0; + const SaveLoadChooserType requestedType = getRequestedSaveLoadDialog(_saveMode, engine); + if (!_impl || _impl->getType() != requestedType) { + delete _impl; + _impl = 0; - Common::String userConfig = ConfMan.get("gui_saveload_chooser", Common::ConfigManager::kApplicationDomain); + switch (requestedType) { + case kSaveLoadDialogGrid: + _impl = new LoadChooserThumbnailed(_title); + break; - if (!_saveMode && g_gui.getWidth() >= 640 && g_gui.getHeight() >= 400 - && engine.hasFeature(MetaEngine::kSavesSupportMetaInfo) - && engine.hasFeature(MetaEngine::kSavesSupportThumbnail) - && userConfig.equalsIgnoreCase("grid")) { - _impl = new LoadChooserThumbnailed(_title); - } else { - _impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode); + case kSaveLoadDialogList: + _impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode); + break; + } } } @@ -90,12 +92,8 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, con do { ret = _impl->run(target, &(**plugin)); - if (ret == kSwitchToList) { - delete _impl; - _impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode); - } else if (ret == kSwitchToGrid) { - delete _impl; - _impl = new LoadChooserThumbnailed(_title); + if (ret == kSwitchSaveLoadDialog) { + selectChooser(**plugin); } } while (ret < -1); -- cgit v1.2.3 From 90eb773c5d862d38f3dc834d51c5a57319c61c3f Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 13 Jul 2012 17:17:58 +0200 Subject: GUI: Implement saving in the grid based save/load chooser. --- gui/saveload.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index 12e62122fe..1eceff79cd 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -40,14 +40,14 @@ SaveLoadChooser::~SaveLoadChooser() { } void SaveLoadChooser::selectChooser(const MetaEngine &engine) { - const SaveLoadChooserType requestedType = getRequestedSaveLoadDialog(_saveMode, engine); + const SaveLoadChooserType requestedType = getRequestedSaveLoadDialog(engine); if (!_impl || _impl->getType() != requestedType) { delete _impl; _impl = 0; switch (requestedType) { case kSaveLoadDialogGrid: - _impl = new LoadChooserThumbnailed(_title); + _impl = new LoadChooserThumbnailed(_title, _saveMode); break; case kSaveLoadDialogList: -- cgit v1.2.3 From 89b638128ff0482a01cfd3d058d87aa95faf58c3 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 24 Jul 2012 23:24:17 +0200 Subject: GUI: Rename LoadChooserThumbnailed to SaveLoadChooserGrid. --- gui/saveload.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index 1eceff79cd..0650be388c 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -47,7 +47,7 @@ void SaveLoadChooser::selectChooser(const MetaEngine &engine) { switch (requestedType) { case kSaveLoadDialogGrid: - _impl = new LoadChooserThumbnailed(_title, _saveMode); + _impl = new SaveLoadChooserGrid(_title, _saveMode); break; case kSaveLoadDialogList: -- cgit v1.2.3 From f006eddac56fdf4305a3d63914245b8707210725 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 24 Jul 2012 23:32:17 +0200 Subject: GUI: Let SaveLoadChooser::getResultString return a const reference. --- gui/saveload.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index 0650be388c..d6a8688ce3 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -103,11 +103,9 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, con return ret; } -Common::String SaveLoadChooser::getResultString() const { - if (_impl) - return _impl->getResultString(); - else - return Common::String(); +const Common::String &SaveLoadChooser::getResultString() const { + assert(_impl); + return _impl->getResultString(); } } // End of namespace GUI -- cgit v1.2.3 From 7d519074053ab0482c1d163a626a9554b52a8783 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 24 Jul 2012 23:46:54 +0200 Subject: GUI: Add possibility to disable the grid based chooser via DISABLE_SAVELOADCHOOSER_GRID. --- gui/saveload.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'gui/saveload.cpp') diff --git a/gui/saveload.cpp b/gui/saveload.cpp index d6a8688ce3..c2bbcd9bec 100644 --- a/gui/saveload.cpp +++ b/gui/saveload.cpp @@ -40,6 +40,7 @@ SaveLoadChooser::~SaveLoadChooser() { } void SaveLoadChooser::selectChooser(const MetaEngine &engine) { +#ifndef DISABLE_SAVELOADCHOOSER_GRID const SaveLoadChooserType requestedType = getRequestedSaveLoadDialog(engine); if (!_impl || _impl->getType() != requestedType) { delete _impl; @@ -51,10 +52,13 @@ void SaveLoadChooser::selectChooser(const MetaEngine &engine) { break; case kSaveLoadDialogList: +#endif // !DISABLE_SAVELOADCHOOSER_GRID _impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode); +#ifndef DISABLE_SAVELOADCHOOSER_GRID break; } } +#endif // !DISABLE_SAVELOADCHOOSER_GRID } Common::String SaveLoadChooser::createDefaultSaveDescription(const int slot) const { @@ -91,10 +95,11 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, con int ret; do { ret = _impl->run(target, &(**plugin)); - +#ifndef DISABLE_SAVELOADCHOOSER_GRID if (ret == kSwitchSaveLoadDialog) { selectChooser(**plugin); } +#endif // !DISABLE_SAVELOADCHOOSER_GRID } while (ret < -1); // Revert to the old active domain -- cgit v1.2.3