diff options
-rw-r--r-- | backends/saves/default/default-saves.cpp | 4 | ||||
-rw-r--r-- | engines/cge/detection.cpp | 5 | ||||
-rw-r--r-- | engines/metaengine.h | 10 | ||||
-rw-r--r-- | engines/savestate.cpp | 4 | ||||
-rw-r--r-- | engines/savestate.h | 23 | ||||
-rw-r--r-- | gui/saveload-dialog.cpp | 56 | ||||
-rw-r--r-- | gui/saveload-dialog.h | 19 |
7 files changed, 99 insertions, 22 deletions
diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp index a11d687c16..a669c2ce81 100644 --- a/backends/saves/default/default-saves.cpp +++ b/backends/saves/default/default-saves.cpp @@ -75,9 +75,7 @@ Common::StringArray DefaultSaveFileManager::listSavefiles(const Common::String & Common::HashMap<Common::String, bool> locked; for (Common::StringArray::const_iterator i = _lockedFiles.begin(), end = _lockedFiles.end(); i != end; ++i) { - if (i->matchString(pattern, true)) { - locked[*i] = true; - } + locked[*i] = true; } Common::StringArray results; diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index 82d27f8d54..0c79be51d9 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -131,6 +131,7 @@ public: virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; virtual int getMaximumSaveSlot() const; virtual SaveStateList listSaves(const char *target) const; + virtual Common::String getSavefilesPattern(Common::String &target) const; SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; virtual void removeSaveState(const char *target, int slot) const; }; @@ -239,6 +240,10 @@ SaveStateList CGEMetaEngine::listSaves(const char *target) const { return saveList; } +Common::String CGEMetaEngine::getSavefilesPattern(Common::String &target) const { + return target + ".###"; +} + SaveStateDescriptor CGEMetaEngine::querySaveMetaInfos(const char *target, int slot) const { Common::String fileName = Common::String::format("%s.%03d", target, slot); Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(fileName); diff --git a/engines/metaengine.h b/engines/metaengine.h index e7bfebab71..913f61d280 100644 --- a/engines/metaengine.h +++ b/engines/metaengine.h @@ -116,6 +116,16 @@ public: } /** + * Return a common pattern which all engine's save filenames should match. + * + * @param target name of a config manager target + * @return a pattern for filenames + */ + virtual Common::String getSavefilesPattern(Common::String &target) const { + return target + ".s##"; + } + + /** * Return a list of extra GUI options for the specified target. * If no target is specified, all of the available custom GUI options are * Returned for the plugin (used to set default values). diff --git a/engines/savestate.cpp b/engines/savestate.cpp index 186d7bc5f2..7366aa6a61 100644 --- a/engines/savestate.cpp +++ b/engines/savestate.cpp @@ -27,12 +27,12 @@ SaveStateDescriptor::SaveStateDescriptor() // FIXME: default to 0 (first slot) or to -1 (invalid slot) ? : _slot(-1), _description(), _isDeletable(true), _isWriteProtected(false), - _saveDate(), _saveTime(), _playTime(), _thumbnail() { + _isLocked(false), _saveDate(), _saveTime(), _playTime(), _thumbnail() { } SaveStateDescriptor::SaveStateDescriptor(int s, const Common::String &d) : _slot(s), _description(d), _isDeletable(true), _isWriteProtected(false), - _saveDate(), _saveTime(), _playTime(), _thumbnail() { + _isLocked(false), _saveDate(), _saveTime(), _playTime(), _thumbnail() { } void SaveStateDescriptor::setThumbnail(Graphics::Surface *t) { diff --git a/engines/savestate.h b/engines/savestate.h index 21ade602fa..3244d61fdb 100644 --- a/engines/savestate.h +++ b/engines/savestate.h @@ -90,6 +90,24 @@ public: bool getWriteProtectedFlag() const { return _isWriteProtected; } /** + * Defines whether the save state is "locked" because is being synced. + */ + void setLocked(bool state) { + _isLocked = state; + + //just in case: + if (state) { + setDeletableFlag(false); + setWriteProtectedFlag(true); + } + } + + /** + * Queries whether the save state is "locked" because is being synced. + */ + bool getLocked() const { return _isLocked; } + + /** * Return a thumbnail graphics surface representing the savestate visually. * This is usually a scaled down version of the game graphics. The size * should be either 160x100 or 160x120 pixels, depending on the aspect @@ -180,6 +198,11 @@ private: bool _isWriteProtected; /** + * Whether the save state is "locked" because is being synced. + */ + bool _isLocked; + + /** * Human readable description of the date the save state was created. */ Common::String _saveDate; diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp index 2646194b4b..5360bfe1ac 100644 --- a/gui/saveload-dialog.cpp +++ b/gui/saveload-dialog.cpp @@ -251,6 +251,32 @@ void SaveLoadChooserDialog::reflowLayout() { void SaveLoadChooserDialog::updateSaveList() { Common::Array<Common::String> files = CloudMan.getSyncingFiles(); //returns empty array if not syncing g_system->getSavefileManager()->updateSavefilesList(files); + listSaves(); +} + +void SaveLoadChooserDialog::listSaves() { + _saveList = _metaEngine->listSaves(_target.c_str()); + + Common::String pattern = _metaEngine->getSavefilesPattern(_target); + Common::Array<Common::String> files = CloudMan.getSyncingFiles(); //returns empty array if not syncing + for (uint32 i = 0; i < files.size(); ++i) { + if (!files[i].matchString(pattern, true)) continue; + + //make up some slot number + int slotNum = 0; + for (int j = files[i].size() - 3; j < files[i].size(); ++j) { //3 last chars + if (j < 0) continue; + char c = files[i][j]; + if (c < '0' || c > '9') continue; + slotNum = slotNum * 10 + (c - '0'); + } + + SaveStateDescriptor slot(slotNum, files[i]); + slot.setLocked(true); + _saveList.push_back(slot); + } + + Common::sort(_saveList.begin(), _saveList.end(), SaveStateDescriptorSlotComparator()); } #ifndef DISABLE_SAVELOADCHOOSER_GRID @@ -454,6 +480,7 @@ void SaveLoadChooserSimple::updateSelection(bool redraw) { bool isDeletable = _delSupport; bool isWriteProtected = false; bool startEditMode = _list->isEditable(); + bool isLocked = false; // We used to support letting the themes specify the fill color with our // initial theme based GUI. But this support was dropped. @@ -463,10 +490,11 @@ void SaveLoadChooserSimple::updateSelection(bool redraw) { _playtime->setLabel(_("No playtime saved")); if (selItem >= 0 && _metaInfoSupport) { - SaveStateDescriptor desc = _metaEngine->querySaveMetaInfos(_target.c_str(), _saveList[selItem].getSaveSlot()); + SaveStateDescriptor desc = (_saveList[selItem].getLocked() ? _saveList[selItem] : _metaEngine->querySaveMetaInfos(_target.c_str(), _saveList[selItem].getSaveSlot())); isDeletable = desc.getDeletableFlag() && _delSupport; isWriteProtected = desc.getWriteProtectedFlag(); + isLocked = desc.getLocked(); // Don't allow the user to change the description of write protected games if (isWriteProtected) @@ -499,9 +527,9 @@ void SaveLoadChooserSimple::updateSelection(bool redraw) { if (_list->isEditable()) { - // Disable the save button if nothing is selected, or if the selected - // game is write protected - _chooseButton->setEnabled(selItem >= 0 && !isWriteProtected); + // Disable the save button if slot is locked, nothing is selected, + // or if the selected game is write protected + _chooseButton->setEnabled(!isLocked && selItem >= 0 && !isWriteProtected); if (startEditMode) { _list->startEditMode(); @@ -513,13 +541,13 @@ void SaveLoadChooserSimple::updateSelection(bool redraw) { } } } else { - // Disable the load button if nothing is selected, or if an empty - // list item is selected. - _chooseButton->setEnabled(selItem >= 0 && !_list->getSelectedString().empty()); + // Disable the load button if slot is locked, nothing is selected, + // or if an empty list item is selected. + _chooseButton->setEnabled(!isLocked && 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())); + _deleteButton->setEnabled(isDeletable && !isLocked && (selItem >= 0) && (!_list->getSelectedString().empty())); if (redraw) { _gfxWidget->draw(); @@ -565,7 +593,6 @@ void SaveLoadChooserSimple::close() { void SaveLoadChooserSimple::updateSaveList() { SaveLoadChooserDialog::updateSaveList(); - _saveList = _metaEngine->listSaves(_target.c_str()); int curSlot = 0; int saveSlot = 0; @@ -598,7 +625,7 @@ void SaveLoadChooserSimple::updateSaveList() { description = _("Untitled savestate"); colors.push_back(ThemeEngine::kFontColorAlternate); } else { - colors.push_back(ThemeEngine::kFontColorNormal); + colors.push_back((x->getLocked() ? ThemeEngine::kFontColorAlternate : ThemeEngine::kFontColorNormal)); } saveNames.push_back(description); @@ -724,7 +751,6 @@ void SaveLoadChooserGrid::handleMouseWheel(int x, int y, int direction) { void SaveLoadChooserGrid::updateSaveList() { SaveLoadChooserDialog::updateSaveList(); - _saveList = _metaEngine->listSaves(_target.c_str()); updateSaves(); draw(); } @@ -732,7 +758,7 @@ void SaveLoadChooserGrid::updateSaveList() { void SaveLoadChooserGrid::open() { SaveLoadChooserDialog::open(); - _saveList = _metaEngine->listSaves(_target.c_str()); + listSaves(); _resultString.clear(); // Load information to restore the last page the user had open. @@ -973,7 +999,7 @@ void SaveLoadChooserGrid::updateSaves() { for (uint i = _curPage * _entriesPerPage, curNum = 0; i < _saveList.size() && curNum < _entriesPerPage; ++i, ++curNum) { const uint saveSlot = _saveList[i].getSaveSlot(); - SaveStateDescriptor desc = _metaEngine->querySaveMetaInfos(_target.c_str(), saveSlot); + SaveStateDescriptor desc = (_saveList[i].getLocked() ? _saveList[i] : _metaEngine->querySaveMetaInfos(_target.c_str(), saveSlot)); SlotButton &curButton = _buttons[curNum]; curButton.setVisible(true); const Graphics::Surface *thumbnail = desc.getThumbnail(); @@ -984,6 +1010,10 @@ void SaveLoadChooserGrid::updateSaves() { } curButton.description->setLabel(Common::String::format("%d. %s", saveSlot, desc.getDescription().c_str())); + //that would make it look "disabled" if slot is locked + curButton.button->setEnabled(!desc.getLocked()); + curButton.description->setEnabled(!desc.getLocked()); + Common::String tooltip(_("Name: ")); tooltip += desc.getDescription(); diff --git a/gui/saveload-dialog.h b/gui/saveload-dialog.h index 435bfc7a5d..a81e03c881 100644 --- a/gui/saveload-dialog.h +++ b/gui/saveload-dialog.h @@ -89,8 +89,20 @@ public: protected: virtual int runIntern() = 0; + + /** Common function to refresh the list on the screen. */ virtual void updateSaveList(); + /** + * Common function to get saves list from MetaEngine. + * + * It also checks whether there are some locked saves + * because of saves sync and adds such saves as locked + * slots. User sees these slots, but is unable to save + * or load from these. + */ + virtual void listSaves(); + const bool _saveMode; const MetaEngine *_metaEngine; bool _delSupport; @@ -100,6 +112,7 @@ protected: bool _playTimeSupport; Common::String _target; bool _dialogWasShown; + SaveStateList _saveList; #ifndef DISABLE_SAVELOADCHOOSER_GRID ButtonWidget *_listButton; @@ -128,8 +141,8 @@ public: virtual void open(); virtual void close(); -protected: - virtual void updateSaveList(); +protected: + virtual void updateSaveList(); private: virtual int runIntern(); @@ -142,7 +155,6 @@ private: StaticTextWidget *_time; StaticTextWidget *_playtime; - SaveStateList _saveList; String _resultString; void updateSelection(bool redraw); @@ -194,7 +206,6 @@ private: uint _columns, _lines; uint _entriesPerPage; uint _curPage; - SaveStateList _saveList; ButtonWidget *_nextButton; ButtonWidget *_prevButton; |