Ticket #9065: gmm-load_del_empty.patch

File gmm-load_del_empty.patch, 3.5 KB (added by SF/buddha_, 15 years ago)

Patch for adding loading & deleting of unnamed savegames to GMM-load/save interface (Made against trunk r43054, Unix style line endings)

  • gui/saveload.cpp

     
    235235        bool isWriteProtected = false;
    236236        bool startEditMode = _list->isEditable();
    237237
    238         if (selItem >= 0 && !_list->getSelectedString().empty() && _metaInfoSupport) {
     238        // Only try to fetch meta information about a savegame if
     239        // 1) there's a savegame selected,
     240        // 2) it is not a dummy one (i.e. a filler for a gap in the savegame list)
     241        // 3) and the engine supports savegame meta information.
     242        if (selItem >= 0 && !_saveList[selItem].getBool("is_dummy") && _metaInfoSupport) {
    239243                SaveStateDescriptor desc = (*_plugin)->querySaveMetaInfos(_target.c_str(), atoi(_saveList[selItem].save_slot().c_str()));
    240244
    241245                isDeletable = desc.getBool("is_deletable") && _delSupport;
     
    292296                if (startEditMode)
    293297                        _list->startEditMode();
    294298        } else {
    295                 // Disable the load button if nothing is selected, or if an empty
     299                // Disable the load button if nothing is selected, or if a dummy
    296300                // list item is selected.
    297                 _chooseButton->setEnabled(selItem >= 0 && !_list->getSelectedString().empty());
     301                _chooseButton->setEnabled(selItem >= 0 && !_saveList[selItem].getBool("is_dummy"));
    298302        }
    299303
    300304        // Delete will always be disabled if the engine doesn't support it.
    301         _deleteButton->setEnabled(isDeletable && (selItem >= 0) && (!_list->getSelectedString().empty()));
     305        // Also don't allow trying to delete dummy list items.
     306        _deleteButton->setEnabled(isDeletable && (selItem >= 0) && (!_saveList[selItem].getBool("is_dummy")));
    302307
    303308        if (redraw) {
    304309                _gfxWidget->draw();
     
    328333        int saveSlot = 0;
    329334        StringList saveNames;
    330335        for (SaveStateList::const_iterator x = _saveList.begin(); x != _saveList.end(); ++x) {
    331                 // Handle gaps in the list of save games
     336                // Handle gaps in the list of save games by filling them with dummy SaveStateDescriptors
    332337                saveSlot = atoi(x->save_slot().c_str());
    333338                if (curSlot < saveSlot) {
    334339                        while (curSlot < saveSlot) {
    335340                                SaveStateDescriptor dummySave(curSlot, "");
     341                                dummySave.setDummyFlag(true);
    336342                                _saveList.insert_at(curSlot, dummySave);
    337343                                saveNames.push_back(dummySave.description());
    338344                                curSlot++;
     
    349355                curSlot++;
    350356        }
    351357
    352         // Fill the rest of the save slots with empty saves
     358        // Fill the rest of the save slots with dummy saves
    353359        Common::String emptyDesc;
    354360        for (int i = curSlot; i <= (*_plugin)->getMaximumSaveSlot(); i++) {
    355361                saveNames.push_back(emptyDesc);
    356362                SaveStateDescriptor dummySave(i, "");
     363                dummySave.setDummyFlag(true);
    357364                _saveList.push_back(dummySave);
    358365        }
    359366
  • engines/game.cpp

     
    128128        return false;
    129129}
    130130
     131void SaveStateDescriptor::setDummyFlag(bool state) {
     132        setVal("is_dummy", state ? "true" : "false");
     133}
     134
    131135void SaveStateDescriptor::setDeletableFlag(bool state) {
    132136        setVal("is_deletable", state ? "true" : "false");
    133137}
  • engines/game.h

     
    166166        bool getBool(const Common::String &key) const;
    167167
    168168        /**
     169         * Sets the 'is_dummy' key, which indicates if the
     170         * given savestate is a dummy one
     171         * (i.e. a filler for a gap in the savegame list).
     172         */
     173        void setDummyFlag(bool state);
     174
     175        /**
    169176         * Sets the 'is_deletable' key, which indicates if the
    170177         * given savestate is safe for deletion.
    171178         */