Added FolderData::removeFileRecursive(FileData* f).

Fixed ButtonComponent crashing when pressed with no press func set.
This commit is contained in:
Aloshi 2013-08-23 12:21:22 -05:00
parent f2689f49a6
commit e55e0f3da7
7 changed files with 43 additions and 7 deletions

View file

@ -184,3 +184,24 @@ std::vector<FileData*> 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<FolderData*>(*iter);
if(folder)
{
folder->removeFileRecursive(f);
}
iter++;
}
}
}

View file

@ -39,6 +39,8 @@ public:
std::vector<FileData*> getFiles(bool onlyFiles = false) const;
std::vector<FileData*> getFilesRecursive(bool onlyFiles = false) const;
void removeFileRecursive(FileData* file);
void pushFileData(FileData* file);
void sort(ComparisonFunction & comparisonFunction = compareFileName, bool ascending = true);

View file

@ -22,6 +22,7 @@ bool ButtonComponent::input(InputConfig* config, Input input)
{
if(config->isMappedTo("a", input))
{
if(mPressedFunc)
mPressedFunc();
return true;
}

View file

@ -31,10 +31,12 @@ GuiGameEd::GuiGameEd(Window* window, GameData* game, const std::vector<MetaDataD
//initialize buttons
mDeleteButton.setText("DELETE", 0x555555FF);
mDeleteButton.setPressedFunc([&] { deleteGame(); delete this; });
mFetchButton.setText("FETCH", 0x555555FF);
mSaveButton.setText("SAVE", 0x0000FFFF);
mSaveButton.setPressedFunc([&] { save(); delete this; });
mSaveButton.setPressedFunc([&] { saveGame(); delete this; });
//initialize metadata list
addChild(&mList);
@ -90,10 +92,17 @@ void GuiGameEd::populateList(const std::vector<MetaDataDecl>& 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;
}

View file

@ -15,7 +15,8 @@ public:
virtual ~GuiGameEd();
private:
void save();
void saveGame();
void deleteGame();
void populateList(const std::vector<MetaDataDecl>& mdd);

View file

@ -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<GameData*>(mList.getSelectedObject());
if(game)
mWindow->pushGui(new GuiGameEd(mWindow, game, MetaDataList::getDefaultGameMDD()));
return true;
}

View file

@ -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);
}
}
}