2013-08-23 22:15:00 +00:00
|
|
|
#include "GuiMetaDataEd.h"
|
2013-08-18 14:16:11 +00:00
|
|
|
#include "../Renderer.h"
|
|
|
|
#include "../Log.h"
|
|
|
|
|
2013-08-21 19:49:33 +00:00
|
|
|
#define MDED_RESERVED_ROWS 3
|
2013-08-18 14:16:11 +00:00
|
|
|
|
2013-08-23 22:15:00 +00:00
|
|
|
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),
|
2013-08-23 02:41:40 +00:00
|
|
|
mBox(mWindow, ":/frame.png", 0xAAAAAAFF, 0xCCCCCCFF),
|
2013-08-21 19:49:33 +00:00
|
|
|
mList(window, Eigen::Vector2i(3, mdd.size() + MDED_RESERVED_ROWS)),
|
2013-08-23 22:15:00 +00:00
|
|
|
mHeader(window),
|
|
|
|
mMetaData(md),
|
|
|
|
mSavedCallback(saveCallback), mDeleteFunc(deleteFunc),
|
2013-08-22 20:29:50 +00:00
|
|
|
mDeleteButton(window), mFetchButton(window), mSaveButton(window)
|
2013-08-18 14:16:11 +00:00
|
|
|
{
|
2013-08-23 22:15:00 +00:00
|
|
|
LOG(LogInfo) << "Creating GuiMetaDataEd";
|
2013-08-18 14:16:11 +00:00
|
|
|
|
|
|
|
//set size to 80% by 80% of the window
|
|
|
|
mSize << Renderer::getScreenWidth() * 0.8f, Renderer::getScreenHeight() * 0.8f;
|
|
|
|
|
|
|
|
//center us
|
|
|
|
mPosition << (Renderer::getScreenWidth() - mSize.x()) / 2, (Renderer::getScreenHeight() - mSize.y()) / 2, 0.0f;
|
|
|
|
|
|
|
|
addChild(&mBox);
|
2013-08-23 02:41:40 +00:00
|
|
|
mBox.fitTo(mSize);
|
2013-08-18 14:16:11 +00:00
|
|
|
|
|
|
|
//initialize path display
|
2013-08-23 22:15:00 +00:00
|
|
|
addChild(&mHeader);
|
|
|
|
mHeader.setPosition(0, 0);
|
|
|
|
mHeader.setSize(mSize.x(), 0);
|
|
|
|
mHeader.setCentered(true);
|
|
|
|
mHeader.setText(header);
|
2013-08-18 14:16:11 +00:00
|
|
|
|
2013-08-22 20:29:50 +00:00
|
|
|
//initialize buttons
|
2013-08-23 22:15:00 +00:00
|
|
|
mDeleteButton.setText("DELETE", mDeleteFunc ? 0xFF0000FF : 0x555555FF);
|
|
|
|
if(mDeleteFunc)
|
|
|
|
mDeleteButton.setPressedFunc([&] { mDeleteFunc(); delete this; });
|
2013-08-23 17:21:22 +00:00
|
|
|
|
2013-08-22 20:29:50 +00:00
|
|
|
mFetchButton.setText("FETCH", 0x555555FF);
|
|
|
|
|
|
|
|
mSaveButton.setText("SAVE", 0x0000FFFF);
|
2013-08-23 22:15:00 +00:00
|
|
|
mSaveButton.setPressedFunc([&] { save(); delete this; });
|
2013-08-22 20:29:50 +00:00
|
|
|
|
2013-08-18 14:16:11 +00:00
|
|
|
//initialize metadata list
|
|
|
|
addChild(&mList);
|
|
|
|
populateList(mdd);
|
2013-08-23 22:15:00 +00:00
|
|
|
mList.setPosition((mSize.x() - mList.getSize().x()) / 2, mHeader.getSize().y() + 4);
|
2013-08-18 14:16:11 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 22:15:00 +00:00
|
|
|
GuiMetaDataEd::~GuiMetaDataEd()
|
2013-08-18 14:16:11 +00:00
|
|
|
{
|
2013-08-23 22:15:00 +00:00
|
|
|
LOG(LogInfo) << "Deleted GuiMetaDataEd";
|
2013-08-18 14:16:11 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 22:15:00 +00:00
|
|
|
void GuiMetaDataEd::populateList(const std::vector<MetaDataDecl>& mdd)
|
2013-08-18 14:16:11 +00:00
|
|
|
{
|
|
|
|
// PATH //(centered, not part of componentlist)
|
|
|
|
|
|
|
|
//---GAME NAME--- //(at 1,1; size 3,1) (TextEditComponent)
|
|
|
|
//DEL SCRP --- //(buttons)
|
|
|
|
//Fav: Y/N --- //metadata start
|
|
|
|
//Desc: ... --- //multiline texteditcomponent
|
|
|
|
//Img: ... ---
|
|
|
|
//--- SAVE ---
|
|
|
|
|
|
|
|
using namespace Eigen;
|
|
|
|
|
|
|
|
int y = 0;
|
|
|
|
|
2013-08-22 20:29:50 +00:00
|
|
|
//delete button
|
|
|
|
mList.setEntry(Vector2i(0, y), Vector2i(1, 1), &mDeleteButton, true, ComponentListComponent::AlignCenter);
|
2013-08-18 14:16:11 +00:00
|
|
|
|
2013-08-22 20:29:50 +00:00
|
|
|
//fetch button
|
|
|
|
mList.setEntry(Vector2i(1, y), Vector2i(1, 1), &mFetchButton, true, ComponentListComponent::AlignCenter);
|
|
|
|
|
2013-08-18 14:16:11 +00:00
|
|
|
y++;
|
|
|
|
|
|
|
|
for(auto iter = mdd.begin(); iter != mdd.end(); iter++)
|
|
|
|
{
|
|
|
|
TextComponent* label = new TextComponent(mWindow);
|
|
|
|
label->setText(iter->key);
|
|
|
|
mList.setEntry(Vector2i(0, y), Vector2i(1, 1), label, false, ComponentListComponent::AlignLeft);
|
2013-08-22 20:29:50 +00:00
|
|
|
mLabels.push_back(label);
|
2013-08-18 14:16:11 +00:00
|
|
|
|
|
|
|
GuiComponent* ed = MetaDataList::makeEditor(mWindow, iter->type);
|
2013-08-21 20:59:11 +00:00
|
|
|
ed->setSize(mSize.x() / 2, ed->getSize().y());
|
2013-08-23 22:15:00 +00:00
|
|
|
ed->setValue(mMetaData->get(iter->key));
|
2013-08-18 14:16:11 +00:00
|
|
|
mList.setEntry(Vector2i(1, y), Vector2i(1, 1), ed, true, ComponentListComponent::AlignRight);
|
2013-08-22 20:29:50 +00:00
|
|
|
mEditors.push_back(ed);
|
2013-08-18 14:16:11 +00:00
|
|
|
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
|
2013-08-22 20:29:50 +00:00
|
|
|
//save button
|
|
|
|
mList.setEntry(Vector2i(0, y), Vector2i(2, 1), &mSaveButton, true, ComponentListComponent::AlignCenter);
|
|
|
|
}
|
|
|
|
|
2013-08-23 22:15:00 +00:00
|
|
|
void GuiMetaDataEd::save()
|
2013-08-22 20:29:50 +00:00
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < mLabels.size(); i++)
|
|
|
|
{
|
2013-08-23 22:15:00 +00:00
|
|
|
mMetaData->set(mLabels.at(i)->getValue(), mEditors.at(i)->getValue());
|
2013-08-22 20:29:50 +00:00
|
|
|
}
|
2013-08-23 17:21:22 +00:00
|
|
|
|
2013-08-23 22:15:00 +00:00
|
|
|
if(mSavedCallback)
|
|
|
|
mSavedCallback();
|
2013-08-23 17:21:22 +00:00
|
|
|
}
|