Ticket #9065: gmm-load_del_empty-v2.patch

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

Like first patch but with empty descriptions mapped to "Untitled savestate" (Made against trunk r43077, 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++;
     
    345351                        }
    346352                }
    347353
    348                 saveNames.push_back(x->description());
     354                // Show "Untitled savestate" for empty/whitespace savegame descriptions
     355                Common::String description = x->description();
     356                Common::String trimmedDescription = description;
     357                trimmedDescription.trim();
     358                if (trimmedDescription.empty())
     359                        description = "Untitled savestate";
     360
     361                saveNames.push_back(description);
    349362                curSlot++;
    350363        }
    351364
    352         // Fill the rest of the save slots with empty saves
     365        // Fill the rest of the save slots with dummy saves
    353366        Common::String emptyDesc;
    354367        for (int i = curSlot; i <= (*_plugin)->getMaximumSaveSlot(); i++) {
    355368                saveNames.push_back(emptyDesc);
    356369                SaveStateDescriptor dummySave(i, "");
     370                dummySave.setDummyFlag(true);
    357371                _saveList.push_back(dummySave);
    358372        }
    359373
  • 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         */