From 268b918c464ccbdaf024b96c98e95333e397570e Mon Sep 17 00:00:00 2001 From: Aloshi Date: Fri, 23 Aug 2013 17:15:00 -0500 Subject: [PATCH] Changed GuiGameEd to GuiMetaDataEd. Now accepts std::functions for save/delete. --- CMakeLists.txt | 4 +- src/components/GuiGameList.cpp | 10 +++- .../{GuiGameEd.cpp => GuiMetaDataEd.cpp} | 51 +++++++++---------- .../{GuiGameEd.h => GuiMetaDataEd.h} | 17 ++++--- 4 files changed, 45 insertions(+), 37 deletions(-) rename src/components/{GuiGameEd.cpp => GuiMetaDataEd.cpp} (63%) rename src/components/{GuiGameEd.h => GuiMetaDataEd.h} (56%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 86370a5b2..e4ab862fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,7 +151,7 @@ set(ES_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiBox.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiDetectDevice.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiFastSelect.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiGameEd.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiMetaDataEd.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiGameList.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiInputConfig.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiMenu.h @@ -198,7 +198,7 @@ set(ES_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiBox.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiDetectDevice.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiFastSelect.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiGameEd.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiMetaDataEd.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiGameList.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiInputConfig.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiMenu.cpp diff --git a/src/components/GuiGameList.cpp b/src/components/GuiGameList.cpp index 68c140bb4..24ef6d003 100644 --- a/src/components/GuiGameList.cpp +++ b/src/components/GuiGameList.cpp @@ -6,7 +6,7 @@ #include #include "../Log.h" #include "../Settings.h" -#include "GuiGameEd.h" +#include "GuiMetaDataEd.h" std::vector GuiGameList::sortStates; @@ -127,7 +127,13 @@ bool GuiGameList::input(InputConfig* config, Input input) { GameData* game = dynamic_cast(mList.getSelectedObject()); if(game) - mWindow->pushGui(new GuiGameEd(mWindow, game, MetaDataList::getDefaultGameMDD())); + { + FolderData* root = mSystem->getRootFolder(); + mWindow->pushGui(new GuiMetaDataEd(mWindow, game->metadata(), MetaDataList::getDefaultGameMDD(), game->getBaseName(), + [&] { updateDetailData(); }, + [game, root, this] { root->removeFileRecursive(game); updateList(); } + )); + } return true; } diff --git a/src/components/GuiGameEd.cpp b/src/components/GuiMetaDataEd.cpp similarity index 63% rename from src/components/GuiGameEd.cpp rename to src/components/GuiMetaDataEd.cpp index 3750eb048..3f4e632bd 100644 --- a/src/components/GuiGameEd.cpp +++ b/src/components/GuiMetaDataEd.cpp @@ -1,17 +1,19 @@ -#include "GuiGameEd.h" +#include "GuiMetaDataEd.h" #include "../Renderer.h" #include "../Log.h" #define MDED_RESERVED_ROWS 3 -GuiGameEd::GuiGameEd(Window* window, GameData* game, const std::vector& mdd) : GuiComponent(window), +GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector& mdd, + const std::string& header, std::function saveCallback, std::function deleteFunc) : GuiComponent(window), mBox(mWindow, ":/frame.png", 0xAAAAAAFF, 0xCCCCCCFF), mList(window, Eigen::Vector2i(3, mdd.size() + MDED_RESERVED_ROWS)), - mPathDisp(window), - mGame(game), + mHeader(window), + mMetaData(md), + mSavedCallback(saveCallback), mDeleteFunc(deleteFunc), mDeleteButton(window), mFetchButton(window), mSaveButton(window) { - LOG(LogInfo) << "Creating GuiGameEd"; + LOG(LogInfo) << "Creating GuiMetaDataEd"; //set size to 80% by 80% of the window mSize << Renderer::getScreenWidth() * 0.8f, Renderer::getScreenHeight() * 0.8f; @@ -23,33 +25,34 @@ GuiGameEd::GuiGameEd(Window* window, GameData* game, const std::vectorgetBaseName()); + addChild(&mHeader); + mHeader.setPosition(0, 0); + mHeader.setSize(mSize.x(), 0); + mHeader.setCentered(true); + mHeader.setText(header); //initialize buttons - mDeleteButton.setText("DELETE", 0x555555FF); - mDeleteButton.setPressedFunc([&] { deleteGame(); delete this; }); + mDeleteButton.setText("DELETE", mDeleteFunc ? 0xFF0000FF : 0x555555FF); + if(mDeleteFunc) + mDeleteButton.setPressedFunc([&] { mDeleteFunc(); delete this; }); mFetchButton.setText("FETCH", 0x555555FF); mSaveButton.setText("SAVE", 0x0000FFFF); - mSaveButton.setPressedFunc([&] { saveGame(); delete this; }); + mSaveButton.setPressedFunc([&] { save(); delete this; }); //initialize metadata list addChild(&mList); populateList(mdd); - mList.setPosition((mSize.x() - mList.getSize().x()) / 2, mPathDisp.getSize().y() + 4); + mList.setPosition((mSize.x() - mList.getSize().x()) / 2, mHeader.getSize().y() + 4); } -GuiGameEd::~GuiGameEd() +GuiMetaDataEd::~GuiMetaDataEd() { - LOG(LogInfo) << "Deleted GuiGameEd"; + LOG(LogInfo) << "Deleted GuiMetaDataEd"; } -void GuiGameEd::populateList(const std::vector& mdd) +void GuiMetaDataEd::populateList(const std::vector& mdd) { // PATH //(centered, not part of componentlist) @@ -81,7 +84,7 @@ void GuiGameEd::populateList(const std::vector& mdd) GuiComponent* ed = MetaDataList::makeEditor(mWindow, iter->type); ed->setSize(mSize.x() / 2, ed->getSize().y()); - ed->setValue(mGame->metadata()->get(iter->key)); + ed->setValue(mMetaData->get(iter->key)); mList.setEntry(Vector2i(1, y), Vector2i(1, 1), ed, true, ComponentListComponent::AlignRight); mEditors.push_back(ed); @@ -92,17 +95,13 @@ void GuiGameEd::populateList(const std::vector& mdd) mList.setEntry(Vector2i(0, y), Vector2i(2, 1), &mSaveButton, true, ComponentListComponent::AlignCenter); } -void GuiGameEd::saveGame() +void GuiMetaDataEd::save() { for(unsigned int i = 0; i < mLabels.size(); i++) { - mGame->metadata()->set(mLabels.at(i)->getValue(), mEditors.at(i)->getValue()); + mMetaData->set(mLabels.at(i)->getValue(), mEditors.at(i)->getValue()); } -} -void GuiGameEd::deleteGame() -{ - //mSystem->getRootFolder()->removeFileRecursive(mGame); - //delete mGame; - //mGame = NULL; + if(mSavedCallback) + mSavedCallback(); } diff --git a/src/components/GuiGameEd.h b/src/components/GuiMetaDataEd.h similarity index 56% rename from src/components/GuiGameEd.h rename to src/components/GuiMetaDataEd.h index 80f628949..bdad64344 100644 --- a/src/components/GuiGameEd.h +++ b/src/components/GuiMetaDataEd.h @@ -7,16 +7,17 @@ #include "../GameData.h" #include "NinePatchComponent.h" #include "ButtonComponent.h" +#include -class GuiGameEd : public GuiComponent +class GuiMetaDataEd : public GuiComponent { public: - GuiGameEd(Window* window, GameData* game, const std::vector& mdd); - virtual ~GuiGameEd(); + GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector& mdd, + const std::string& header, std::function savedCallback, std::function deleteFunc); + virtual ~GuiMetaDataEd(); private: - void saveGame(); - void deleteGame(); + void save(); void populateList(const std::vector& mdd); @@ -24,12 +25,14 @@ private: ComponentListComponent mList; - TextComponent mPathDisp; + TextComponent mHeader; std::vector mLabels; std::vector mEditors; - GameData* mGame; + MetaDataList* mMetaData; + std::function mSavedCallback; + std::function mDeleteFunc; ButtonComponent mDeleteButton; ButtonComponent mFetchButton;