mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 06:05:38 +00:00
Changed GuiGameEd to GuiMetaDataEd.
Now accepts std::functions for save/delete.
This commit is contained in:
parent
e55e0f3da7
commit
268b918c46
|
@ -151,7 +151,7 @@ set(ES_HEADERS
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiBox.h
|
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiBox.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiDetectDevice.h
|
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiDetectDevice.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiFastSelect.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/GuiGameList.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiInputConfig.h
|
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiInputConfig.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiMenu.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/GuiBox.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiDetectDevice.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiDetectDevice.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiFastSelect.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/GuiGameList.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiInputConfig.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiInputConfig.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiMenu.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiMenu.cpp
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include "../Log.h"
|
#include "../Log.h"
|
||||||
#include "../Settings.h"
|
#include "../Settings.h"
|
||||||
#include "GuiGameEd.h"
|
#include "GuiMetaDataEd.h"
|
||||||
|
|
||||||
std::vector<FolderData::SortState> GuiGameList::sortStates;
|
std::vector<FolderData::SortState> GuiGameList::sortStates;
|
||||||
|
|
||||||
|
@ -127,7 +127,13 @@ bool GuiGameList::input(InputConfig* config, Input input)
|
||||||
{
|
{
|
||||||
GameData* game = dynamic_cast<GameData*>(mList.getSelectedObject());
|
GameData* game = dynamic_cast<GameData*>(mList.getSelectedObject());
|
||||||
if(game)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
#include "GuiGameEd.h"
|
#include "GuiMetaDataEd.h"
|
||||||
#include "../Renderer.h"
|
#include "../Renderer.h"
|
||||||
#include "../Log.h"
|
#include "../Log.h"
|
||||||
|
|
||||||
#define MDED_RESERVED_ROWS 3
|
#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),
|
mBox(mWindow, ":/frame.png", 0xAAAAAAFF, 0xCCCCCCFF),
|
||||||
mList(window, Eigen::Vector2i(3, mdd.size() + MDED_RESERVED_ROWS)),
|
mList(window, Eigen::Vector2i(3, mdd.size() + MDED_RESERVED_ROWS)),
|
||||||
mPathDisp(window),
|
mHeader(window),
|
||||||
mGame(game),
|
mMetaData(md),
|
||||||
|
mSavedCallback(saveCallback), mDeleteFunc(deleteFunc),
|
||||||
mDeleteButton(window), mFetchButton(window), mSaveButton(window)
|
mDeleteButton(window), mFetchButton(window), mSaveButton(window)
|
||||||
{
|
{
|
||||||
LOG(LogInfo) << "Creating GuiGameEd";
|
LOG(LogInfo) << "Creating GuiMetaDataEd";
|
||||||
|
|
||||||
//set size to 80% by 80% of the window
|
//set size to 80% by 80% of the window
|
||||||
mSize << Renderer::getScreenWidth() * 0.8f, Renderer::getScreenHeight() * 0.8f;
|
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);
|
mBox.fitTo(mSize);
|
||||||
|
|
||||||
//initialize path display
|
//initialize path display
|
||||||
addChild(&mPathDisp);
|
addChild(&mHeader);
|
||||||
mPathDisp.setPosition(0, 0);
|
mHeader.setPosition(0, 0);
|
||||||
mPathDisp.setSize(mSize.x(), 0);
|
mHeader.setSize(mSize.x(), 0);
|
||||||
mPathDisp.setCentered(true);
|
mHeader.setCentered(true);
|
||||||
mPathDisp.setText(mGame->getBaseName());
|
mHeader.setText(header);
|
||||||
|
|
||||||
//initialize buttons
|
//initialize buttons
|
||||||
mDeleteButton.setText("DELETE", 0x555555FF);
|
mDeleteButton.setText("DELETE", mDeleteFunc ? 0xFF0000FF : 0x555555FF);
|
||||||
mDeleteButton.setPressedFunc([&] { deleteGame(); delete this; });
|
if(mDeleteFunc)
|
||||||
|
mDeleteButton.setPressedFunc([&] { mDeleteFunc(); delete this; });
|
||||||
|
|
||||||
mFetchButton.setText("FETCH", 0x555555FF);
|
mFetchButton.setText("FETCH", 0x555555FF);
|
||||||
|
|
||||||
mSaveButton.setText("SAVE", 0x0000FFFF);
|
mSaveButton.setText("SAVE", 0x0000FFFF);
|
||||||
mSaveButton.setPressedFunc([&] { saveGame(); delete this; });
|
mSaveButton.setPressedFunc([&] { save(); delete this; });
|
||||||
|
|
||||||
//initialize metadata list
|
//initialize metadata list
|
||||||
addChild(&mList);
|
addChild(&mList);
|
||||||
populateList(mdd);
|
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)
|
// 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);
|
GuiComponent* ed = MetaDataList::makeEditor(mWindow, iter->type);
|
||||||
ed->setSize(mSize.x() / 2, ed->getSize().y());
|
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);
|
mList.setEntry(Vector2i(1, y), Vector2i(1, 1), ed, true, ComponentListComponent::AlignRight);
|
||||||
mEditors.push_back(ed);
|
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);
|
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++)
|
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()
|
if(mSavedCallback)
|
||||||
{
|
mSavedCallback();
|
||||||
//mSystem->getRootFolder()->removeFileRecursive(mGame);
|
|
||||||
//delete mGame;
|
|
||||||
//mGame = NULL;
|
|
||||||
}
|
}
|
|
@ -7,16 +7,17 @@
|
||||||
#include "../GameData.h"
|
#include "../GameData.h"
|
||||||
#include "NinePatchComponent.h"
|
#include "NinePatchComponent.h"
|
||||||
#include "ButtonComponent.h"
|
#include "ButtonComponent.h"
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
class GuiGameEd : public GuiComponent
|
class GuiMetaDataEd : public GuiComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiGameEd(Window* window, GameData* game, const std::vector<MetaDataDecl>& mdd);
|
GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector<MetaDataDecl>& mdd,
|
||||||
virtual ~GuiGameEd();
|
const std::string& header, std::function<void()> savedCallback, std::function<void()> deleteFunc);
|
||||||
|
virtual ~GuiMetaDataEd();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void saveGame();
|
void save();
|
||||||
void deleteGame();
|
|
||||||
|
|
||||||
void populateList(const std::vector<MetaDataDecl>& mdd);
|
void populateList(const std::vector<MetaDataDecl>& mdd);
|
||||||
|
|
||||||
|
@ -24,12 +25,14 @@ private:
|
||||||
|
|
||||||
ComponentListComponent mList;
|
ComponentListComponent mList;
|
||||||
|
|
||||||
TextComponent mPathDisp;
|
TextComponent mHeader;
|
||||||
|
|
||||||
std::vector<TextComponent*> mLabels;
|
std::vector<TextComponent*> mLabels;
|
||||||
std::vector<GuiComponent*> mEditors;
|
std::vector<GuiComponent*> mEditors;
|
||||||
|
|
||||||
GameData* mGame;
|
MetaDataList* mMetaData;
|
||||||
|
std::function<void()> mSavedCallback;
|
||||||
|
std::function<void()> mDeleteFunc;
|
||||||
|
|
||||||
ButtonComponent mDeleteButton;
|
ButtonComponent mDeleteButton;
|
||||||
ButtonComponent mFetchButton;
|
ButtonComponent mFetchButton;
|
Loading…
Reference in a new issue