diff --git a/src/FolderData.cpp b/src/FolderData.cpp index 451ffbc33..72b093405 100644 --- a/src/FolderData.cpp +++ b/src/FolderData.cpp @@ -184,3 +184,24 @@ std::vector FolderData::getFilesRecursive(bool onlyFiles) const } return temp; } + +void FolderData::removeFileRecursive(FileData* f) +{ + auto iter = mFileVector.begin(); + while(iter != mFileVector.end()) + { + if(*iter == f) + { + iter = mFileVector.erase(iter); + }else{ + + FolderData* folder = dynamic_cast(*iter); + if(folder) + { + folder->removeFileRecursive(f); + } + + iter++; + } + } +} diff --git a/src/FolderData.h b/src/FolderData.h index ecbd844fb..202ea8211 100644 --- a/src/FolderData.h +++ b/src/FolderData.h @@ -39,6 +39,8 @@ public: std::vector getFiles(bool onlyFiles = false) const; std::vector getFilesRecursive(bool onlyFiles = false) const; + void removeFileRecursive(FileData* file); + void pushFileData(FileData* file); void sort(ComparisonFunction & comparisonFunction = compareFileName, bool ascending = true); diff --git a/src/components/ButtonComponent.cpp b/src/components/ButtonComponent.cpp index 74dcdc00b..9d45ccd8c 100644 --- a/src/components/ButtonComponent.cpp +++ b/src/components/ButtonComponent.cpp @@ -22,7 +22,8 @@ bool ButtonComponent::input(InputConfig* config, Input input) { if(config->isMappedTo("a", input)) { - mPressedFunc(); + if(mPressedFunc) + mPressedFunc(); return true; } diff --git a/src/components/GuiGameEd.cpp b/src/components/GuiGameEd.cpp index 4e7972068..3750eb048 100644 --- a/src/components/GuiGameEd.cpp +++ b/src/components/GuiGameEd.cpp @@ -31,10 +31,12 @@ GuiGameEd::GuiGameEd(Window* window, GameData* game, const std::vector& mdd) mList.setEntry(Vector2i(0, y), Vector2i(2, 1), &mSaveButton, true, ComponentListComponent::AlignCenter); } -void GuiGameEd::save() +void GuiGameEd::saveGame() { for(unsigned int i = 0; i < mLabels.size(); i++) { mGame->metadata()->set(mLabels.at(i)->getValue(), mEditors.at(i)->getValue()); } } + +void GuiGameEd::deleteGame() +{ + //mSystem->getRootFolder()->removeFileRecursive(mGame); + //delete mGame; + //mGame = NULL; +} diff --git a/src/components/GuiGameEd.h b/src/components/GuiGameEd.h index 38cd68617..80f628949 100644 --- a/src/components/GuiGameEd.h +++ b/src/components/GuiGameEd.h @@ -15,7 +15,8 @@ public: virtual ~GuiGameEd(); private: - void save(); + void saveGame(); + void deleteGame(); void populateList(const std::vector& mdd); diff --git a/src/components/GuiGameList.cpp b/src/components/GuiGameList.cpp index 718484c74..68c140bb4 100644 --- a/src/components/GuiGameList.cpp +++ b/src/components/GuiGameList.cpp @@ -125,7 +125,9 @@ bool GuiGameList::input(InputConfig* config, Input input) if(input.id == SDLK_F3) { - mWindow->pushGui(new GuiGameEd(mWindow, (GameData*)mSystem->getRootFolder()->getFile(0), MetaDataList::getDefaultGameMDD())); + GameData* game = dynamic_cast(mList.getSelectedObject()); + if(game) + mWindow->pushGui(new GuiGameEd(mWindow, game, MetaDataList::getDefaultGameMDD())); return true; } diff --git a/src/resources/ResourceManager.cpp b/src/resources/ResourceManager.cpp index 37ba8a8cd..0184ff74d 100644 --- a/src/resources/ResourceManager.cpp +++ b/src/resources/ResourceManager.cpp @@ -72,7 +72,7 @@ void ResourceManager::unloadAll() iter->lock()->unload(*this); iter++; }else{ - mReloadables.erase(iter++); + iter = mReloadables.erase(iter); } } } @@ -87,7 +87,7 @@ void ResourceManager::reloadAll() iter->lock()->reload(*this); iter++; }else{ - mReloadables.erase(iter++); + iter = mReloadables.erase(iter); } } }