Changed GuiGameEd to GuiMetaDataEd.

Now accepts std::functions for save/delete.
This commit is contained in:
Aloshi 2013-08-23 17:15:00 -05:00
parent e55e0f3da7
commit 268b918c46
4 changed files with 45 additions and 37 deletions

View file

@ -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

View file

@ -6,7 +6,7 @@
#include <boost/filesystem.hpp>
#include "../Log.h"
#include "../Settings.h"
#include "GuiGameEd.h"
#include "GuiMetaDataEd.h"
std::vector<FolderData::SortState> GuiGameList::sortStates;
@ -127,7 +127,13 @@ bool GuiGameList::input(InputConfig* config, Input input)
{
GameData* game = dynamic_cast<GameData*>(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;
}

View file

@ -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<MetaDataDecl>& mdd) : GuiComponent(window),
GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector<MetaDataDecl>& mdd,
const std::string& header, std::function<void()> saveCallback, std::function<void()> 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::vector<MetaDataD
mBox.fitTo(mSize);
//initialize path display
addChild(&mPathDisp);
mPathDisp.setPosition(0, 0);
mPathDisp.setSize(mSize.x(), 0);
mPathDisp.setCentered(true);
mPathDisp.setText(mGame->getBaseName());
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<MetaDataDecl>& mdd)
void GuiMetaDataEd::populateList(const std::vector<MetaDataDecl>& mdd)
{
// PATH //(centered, not part of componentlist)
@ -81,7 +84,7 @@ void GuiGameEd::populateList(const std::vector<MetaDataDecl>& 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<MetaDataDecl>& 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();
}

View file

@ -7,16 +7,17 @@
#include "../GameData.h"
#include "NinePatchComponent.h"
#include "ButtonComponent.h"
#include <functional>
class GuiGameEd : public GuiComponent
class GuiMetaDataEd : public GuiComponent
{
public:
GuiGameEd(Window* window, GameData* game, const std::vector<MetaDataDecl>& mdd);
virtual ~GuiGameEd();
GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector<MetaDataDecl>& mdd,
const std::string& header, std::function<void()> savedCallback, std::function<void()> deleteFunc);
virtual ~GuiMetaDataEd();
private:
void saveGame();
void deleteGame();
void save();
void populateList(const std::vector<MetaDataDecl>& mdd);
@ -24,12 +25,14 @@ private:
ComponentListComponent mList;
TextComponent mPathDisp;
TextComponent mHeader;
std::vector<TextComponent*> mLabels;
std::vector<GuiComponent*> mEditors;
GameData* mGame;
MetaDataList* mMetaData;
std::function<void()> mSavedCallback;
std::function<void()> mDeleteFunc;
ButtonComponent mDeleteButton;
ButtonComponent mFetchButton;