2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// GuiMetaDataEd.cpp
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Game metadata edit user interface.
|
|
|
|
// This interface is triggered from the GuiGamelistOptions menu.
|
|
|
|
// The scraping interface is handled by GuiGameScraper which calls
|
|
|
|
// GuiScraperSearch.
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "guis/GuiMetaDataEd.h"
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
#include "CollectionSystemsManager.h"
|
|
|
|
#include "FileData.h"
|
|
|
|
#include "FileFilterIndex.h"
|
|
|
|
#include "Gamelist.h"
|
|
|
|
#include "SystemData.h"
|
|
|
|
#include "Window.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "components/ButtonComponent.h"
|
|
|
|
#include "components/ComponentList.h"
|
2018-10-13 01:08:15 +00:00
|
|
|
#include "components/DateTimeEditComponent.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "components/MenuComponent.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "components/RatingComponent.h"
|
2017-06-12 16:38:59 +00:00
|
|
|
#include "components/SwitchComponent.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "components/TextComponent.h"
|
2021-07-07 18:03:42 +00:00
|
|
|
#include "guis/GuiComplexTextEditPopup.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "guis/GuiGameScraper.h"
|
|
|
|
#include "guis/GuiMsgBox.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "guis/GuiTextEditPopup.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "resources/Font.h"
|
2018-01-27 17:04:28 +00:00
|
|
|
#include "utils/StringUtil.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "views/ViewController.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
GuiMetaDataEd::GuiMetaDataEd(Window* window,
|
|
|
|
MetaDataList* md,
|
|
|
|
const std::vector<MetaDataDecl>& mdd,
|
|
|
|
ScraperSearchParams scraperParams,
|
|
|
|
const std::string& /*header*/,
|
|
|
|
std::function<void()> saveCallback,
|
|
|
|
std::function<void()> clearGameFunc,
|
|
|
|
std::function<void()> deleteGameFunc)
|
|
|
|
: GuiComponent(window)
|
|
|
|
, mScraperParams(scraperParams)
|
|
|
|
, mBackground(window, ":/graphics/frame.svg")
|
|
|
|
, mGrid(window, Vector2i(1, 3))
|
|
|
|
, mMetaDataDecl(mdd)
|
|
|
|
, mMetaData(md)
|
|
|
|
, mSavedCallback(saveCallback)
|
|
|
|
, mClearGameFunc(clearGameFunc)
|
|
|
|
, mDeleteGameFunc(deleteGameFunc)
|
|
|
|
, mMediaFilesUpdated(false)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
addChild(&mBackground);
|
|
|
|
addChild(&mGrid);
|
|
|
|
|
|
|
|
mHeaderGrid = std::make_shared<ComponentGrid>(mWindow, Vector2i(1, 5));
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
mTitle = std::make_shared<TextComponent>(mWindow, "EDIT METADATA", Font::get(FONT_SIZE_LARGE),
|
|
|
|
0x555555FF, ALIGN_CENTER);
|
2021-01-31 20:30:47 +00:00
|
|
|
|
|
|
|
// Extract possible subfolders from the path.
|
2021-07-07 18:03:42 +00:00
|
|
|
std::string folderPath =
|
|
|
|
Utils::String::replace(Utils::FileSystem::getParent(scraperParams.game->getPath()),
|
|
|
|
scraperParams.system->getSystemEnvData()->mStartPath, "");
|
2021-01-31 20:30:47 +00:00
|
|
|
|
|
|
|
if (folderPath.size() >= 2) {
|
|
|
|
folderPath.erase(0, 1);
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2021-01-31 20:33:32 +00:00
|
|
|
folderPath.push_back('\\');
|
2021-01-31 20:30:47 +00:00
|
|
|
folderPath = Utils::String::replace(folderPath, "/", "\\");
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2021-01-31 20:30:47 +00:00
|
|
|
folderPath.push_back('/');
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-01-31 20:30:47 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
mSubtitle = std::make_shared<TextComponent>(
|
|
|
|
mWindow,
|
|
|
|
folderPath + Utils::FileSystem::getFileName(scraperParams.game->getPath()) + " [" +
|
|
|
|
Utils::String::toUpper(scraperParams.system->getName()) + "]" +
|
2021-01-31 20:30:47 +00:00
|
|
|
(scraperParams.game->getType() == FOLDER ? " " + ViewController::FOLDER_CHAR : ""),
|
2021-07-07 18:03:42 +00:00
|
|
|
Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER, Vector3f(0.0f, 0.0f, 0.0f),
|
|
|
|
Vector2f(0.0f, 0.0f), 0x00000000, 0.05f);
|
2020-06-21 12:25:28 +00:00
|
|
|
mHeaderGrid->setEntry(mTitle, Vector2i(0, 1), false, true);
|
|
|
|
mHeaderGrid->setEntry(mSubtitle, Vector2i(0, 3), false, true);
|
|
|
|
|
|
|
|
mGrid.setEntry(mHeaderGrid, Vector2i(0, 0), false, true);
|
|
|
|
|
|
|
|
mList = std::make_shared<ComponentList>(mWindow);
|
|
|
|
mGrid.setEntry(mList, Vector2i(0, 1), true, true);
|
|
|
|
|
|
|
|
// Populate list.
|
|
|
|
for (auto iter = mdd.cbegin(); iter != mdd.cend(); iter++) {
|
|
|
|
std::shared_ptr<GuiComponent> ed;
|
2020-08-02 09:45:59 +00:00
|
|
|
std::string currentKey = iter->key;
|
|
|
|
std::string originalValue = mMetaData->get(iter->key);
|
|
|
|
std::string gamePath;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Don't add statistics.
|
|
|
|
if (iter->isStatistic)
|
|
|
|
continue;
|
|
|
|
|
2020-07-10 18:58:53 +00:00
|
|
|
// Don't show the launch command override entry if this option has been disabled.
|
2020-07-08 15:06:34 +00:00
|
|
|
if (!Settings::getInstance()->getBool("LaunchCommandOverride") &&
|
2021-07-07 18:03:42 +00:00
|
|
|
iter->type == MD_LAUNCHCOMMAND) {
|
|
|
|
ed = std::make_shared<TextComponent>(
|
|
|
|
window, "", Font::get(FONT_SIZE_SMALL, FONT_PATH_LIGHT), 0x777777FF, ALIGN_RIGHT);
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(ed);
|
|
|
|
ed->setValue(mMetaData->get(iter->key));
|
|
|
|
mEditors.push_back(ed);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's very important to put the element with the help prompt as the last row
|
|
|
|
// entry instead of for instance the spacer. That is so because ComponentList
|
|
|
|
// always looks for the help prompt at the back of the element stack.
|
|
|
|
ComponentListRow row;
|
2021-07-07 18:03:42 +00:00
|
|
|
auto lbl =
|
|
|
|
std::make_shared<TextComponent>(mWindow, Utils::String::toUpper(iter->displayName),
|
|
|
|
Font::get(FONT_SIZE_SMALL), 0x777777FF);
|
2020-06-21 12:25:28 +00:00
|
|
|
row.addElement(lbl, true); // Label.
|
|
|
|
|
|
|
|
switch (iter->type) {
|
2021-07-07 18:03:42 +00:00
|
|
|
case MD_BOOL: {
|
2020-06-21 12:25:28 +00:00
|
|
|
ed = std::make_shared<SwitchComponent>(window);
|
2020-12-17 19:49:20 +00:00
|
|
|
// Make the switches slightly smaller.
|
2020-12-29 11:54:24 +00:00
|
|
|
auto switchSize = ed->getSize() * 0.9f;
|
2020-12-17 19:49:20 +00:00
|
|
|
ed->setResize(switchSize.x(), switchSize.y());
|
2020-12-29 11:54:24 +00:00
|
|
|
ed->setOrigin(-0.05f, -0.09f);
|
2020-12-17 19:49:20 +00:00
|
|
|
|
2020-07-15 15:44:27 +00:00
|
|
|
ed->setChangedColor(ICONCOLOR_USERMARKED);
|
2020-06-21 12:25:28 +00:00
|
|
|
row.addElement(ed, false, true);
|
|
|
|
break;
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
case MD_RATING: {
|
2020-06-21 12:25:28 +00:00
|
|
|
auto spacer = std::make_shared<GuiComponent>(mWindow);
|
2021-07-07 18:03:42 +00:00
|
|
|
spacer->setSize(Renderer::getScreenWidth() * 0.0025f, 0.0f);
|
2020-06-21 12:25:28 +00:00
|
|
|
row.addElement(spacer, false);
|
|
|
|
|
2020-07-15 15:44:27 +00:00
|
|
|
ed = std::make_shared<RatingComponent>(window, true);
|
|
|
|
ed->setChangedColor(ICONCOLOR_USERMARKED);
|
2020-06-21 12:25:28 +00:00
|
|
|
const float height = lbl->getSize().y() * 0.71f;
|
|
|
|
ed->setSize(0, height);
|
|
|
|
row.addElement(ed, false, true);
|
|
|
|
|
2021-03-20 09:26:18 +00:00
|
|
|
auto ratingSpacer = std::make_shared<GuiComponent>(mWindow);
|
2021-07-07 18:03:42 +00:00
|
|
|
ratingSpacer->setSize(Renderer::getScreenWidth() * 0.001f, 0.0f);
|
2021-03-20 09:26:18 +00:00
|
|
|
row.addElement(ratingSpacer, false);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Pass input to the actual RatingComponent instead of the spacer.
|
2021-07-07 18:03:42 +00:00
|
|
|
row.input_handler = std::bind(&GuiComponent::input, ed.get(), std::placeholders::_1,
|
|
|
|
std::placeholders::_2);
|
2020-06-21 12:25:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
case MD_DATE: {
|
2020-06-21 12:25:28 +00:00
|
|
|
auto spacer = std::make_shared<GuiComponent>(mWindow);
|
2021-07-07 18:03:42 +00:00
|
|
|
spacer->setSize(Renderer::getScreenWidth() * 0.0025f, 0.0f);
|
2020-06-21 12:25:28 +00:00
|
|
|
row.addElement(spacer, false);
|
|
|
|
|
2021-03-20 10:08:28 +00:00
|
|
|
ed = std::make_shared<DateTimeEditComponent>(window, true);
|
2020-08-02 13:56:32 +00:00
|
|
|
ed->setOriginalColor(DEFAULT_TEXTCOLOR);
|
2020-07-15 15:44:27 +00:00
|
|
|
ed->setChangedColor(TEXTCOLOR_USERMARKED);
|
2020-06-21 12:25:28 +00:00
|
|
|
row.addElement(ed, false);
|
|
|
|
|
2021-03-20 09:26:18 +00:00
|
|
|
auto dateSpacer = std::make_shared<GuiComponent>(mWindow);
|
2021-07-07 18:03:42 +00:00
|
|
|
dateSpacer->setSize(Renderer::getScreenWidth() * 0.0035f, 0.0f);
|
2021-03-20 09:26:18 +00:00
|
|
|
row.addElement(dateSpacer, false);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Pass input to the actual DateTimeEditComponent instead of the spacer.
|
2021-07-07 18:03:42 +00:00
|
|
|
row.input_handler = std::bind(&GuiComponent::input, ed.get(), std::placeholders::_1,
|
|
|
|
std::placeholders::_2);
|
2020-06-21 12:25:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
case MD_LAUNCHCOMMAND: {
|
2020-06-21 12:25:28 +00:00
|
|
|
ed = std::make_shared<TextComponent>(window, "",
|
2021-07-07 18:03:42 +00:00
|
|
|
Font::get(FONT_SIZE_SMALL, FONT_PATH_LIGHT),
|
|
|
|
0x777777FF, ALIGN_RIGHT);
|
2020-06-21 12:25:28 +00:00
|
|
|
row.addElement(ed, true);
|
|
|
|
|
|
|
|
auto spacer = std::make_shared<GuiComponent>(mWindow);
|
2021-07-07 18:03:42 +00:00
|
|
|
spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0.0f);
|
2020-06-21 12:25:28 +00:00
|
|
|
row.addElement(spacer, false);
|
|
|
|
|
|
|
|
auto bracket = std::make_shared<ImageComponent>(mWindow);
|
2020-06-21 17:35:43 +00:00
|
|
|
bracket->setImage(":/graphics/arrow.svg");
|
2020-06-21 12:25:28 +00:00
|
|
|
bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight()));
|
|
|
|
row.addElement(bracket, false);
|
|
|
|
|
|
|
|
bool multiLine = false;
|
|
|
|
const std::string title = iter->displayPrompt;
|
2020-07-15 15:44:27 +00:00
|
|
|
|
|
|
|
// OK callback (apply new value to ed).
|
|
|
|
auto updateVal = [ed, originalValue](const std::string& newVal) {
|
|
|
|
ed->setValue(newVal);
|
|
|
|
if (newVal == originalValue)
|
|
|
|
ed->setColor(DEFAULT_TEXTCOLOR);
|
|
|
|
else
|
|
|
|
ed->setColor(TEXTCOLOR_USERMARKED);
|
|
|
|
};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-06-16 16:54:04 +00:00
|
|
|
std::string staticTextString = "Default value from es_systems.xml:";
|
2021-07-07 18:03:42 +00:00
|
|
|
std::string defaultLaunchCommand =
|
|
|
|
scraperParams.system->getSystemEnvData()->mLaunchCommand;
|
|
|
|
|
|
|
|
row.makeAcceptInputHandler([this, title, staticTextString, defaultLaunchCommand, ed,
|
|
|
|
updateVal, multiLine] {
|
|
|
|
mWindow->pushGui(new GuiComplexTextEditPopup(
|
|
|
|
mWindow, getHelpStyle(), title, staticTextString, defaultLaunchCommand,
|
|
|
|
ed->getValue(), updateVal, multiLine, "APPLY", "APPLY CHANGES?"));
|
2020-06-21 12:25:28 +00:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
case MD_MULTILINE_STRING:
|
|
|
|
default: {
|
2020-06-21 12:25:28 +00:00
|
|
|
// MD_STRING.
|
2021-07-07 18:03:42 +00:00
|
|
|
ed = std::make_shared<TextComponent>(window, "",
|
|
|
|
Font::get(FONT_SIZE_SMALL, FONT_PATH_LIGHT),
|
|
|
|
0x777777FF, ALIGN_RIGHT);
|
2020-06-21 12:25:28 +00:00
|
|
|
row.addElement(ed, true);
|
|
|
|
|
|
|
|
auto spacer = std::make_shared<GuiComponent>(mWindow);
|
2021-07-07 18:03:42 +00:00
|
|
|
spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0.0f);
|
2020-06-21 12:25:28 +00:00
|
|
|
row.addElement(spacer, false);
|
|
|
|
|
|
|
|
auto bracket = std::make_shared<ImageComponent>(mWindow);
|
2020-06-21 17:35:43 +00:00
|
|
|
bracket->setImage(":/graphics/arrow.svg");
|
2020-06-21 12:25:28 +00:00
|
|
|
bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight()));
|
|
|
|
row.addElement(bracket, false);
|
|
|
|
|
|
|
|
bool multiLine = iter->type == MD_MULTILINE_STRING;
|
|
|
|
const std::string title = iter->displayPrompt;
|
|
|
|
|
2020-08-02 09:45:59 +00:00
|
|
|
gamePath = Utils::FileSystem::getStem(mScraperParams.game->getPath());
|
2020-07-15 15:44:27 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
// OK callback (apply new value to ed).
|
|
|
|
auto updateVal = [ed, currentKey, originalValue,
|
|
|
|
gamePath](const std::string& newVal) {
|
2020-08-02 09:45:59 +00:00
|
|
|
// If the user has entered a blank game name, then set the name to the ROM
|
|
|
|
// filename (minus the extension).
|
|
|
|
if (currentKey == "name" && newVal == "") {
|
|
|
|
ed->setValue(gamePath);
|
|
|
|
if (gamePath == originalValue)
|
|
|
|
ed->setColor(DEFAULT_TEXTCOLOR);
|
|
|
|
else
|
|
|
|
ed->setColor(TEXTCOLOR_USERMARKED);
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
else if (newVal == "" &&
|
|
|
|
(currentKey == "developer" || currentKey == "publisher" ||
|
|
|
|
currentKey == "genre" || currentKey == "players")) {
|
2020-12-17 19:49:20 +00:00
|
|
|
ed->setValue("unknown");
|
|
|
|
if (originalValue == "unknown")
|
|
|
|
ed->setColor(DEFAULT_TEXTCOLOR);
|
|
|
|
else
|
2021-07-07 18:03:42 +00:00
|
|
|
ed->setColor(TEXTCOLOR_USERMARKED);
|
2020-12-17 19:49:20 +00:00
|
|
|
}
|
2020-08-02 09:45:59 +00:00
|
|
|
else {
|
|
|
|
ed->setValue(newVal);
|
|
|
|
if (newVal == originalValue)
|
|
|
|
ed->setColor(DEFAULT_TEXTCOLOR);
|
|
|
|
else
|
2021-07-07 18:03:42 +00:00
|
|
|
ed->setColor(TEXTCOLOR_USERMARKED);
|
2020-08-02 09:45:59 +00:00
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
};
|
2020-07-15 15:44:27 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
row.makeAcceptInputHandler([this, title, ed, updateVal, multiLine] {
|
|
|
|
mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), title,
|
2021-07-07 18:03:42 +00:00
|
|
|
ed->getValue(), updateVal, multiLine,
|
|
|
|
"APPLY", "APPLY CHANGES?"));
|
2020-06-21 12:25:28 +00:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(ed);
|
|
|
|
mList->addRow(row);
|
|
|
|
ed->setValue(mMetaData->get(iter->key));
|
|
|
|
mEditors.push_back(ed);
|
|
|
|
}
|
|
|
|
|
2020-07-15 15:44:27 +00:00
|
|
|
std::vector<std::shared_ptr<ButtonComponent>> buttons;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-07-28 19:08:17 +00:00
|
|
|
if (!scraperParams.system->hasPlatformId(PlatformIds::PLATFORM_IGNORE))
|
2021-07-07 18:03:42 +00:00
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(
|
|
|
|
mWindow, "SCRAPE", "scrape", std::bind(&GuiMetaDataEd::fetch, this)));
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-09-27 11:14:50 +00:00
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "SAVE", "save metadata", [&] {
|
|
|
|
save();
|
|
|
|
ViewController::get()->onPauseVideo();
|
|
|
|
delete this;
|
|
|
|
}));
|
2020-06-21 12:25:28 +00:00
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "CANCEL", "cancel changes",
|
2021-07-07 18:03:42 +00:00
|
|
|
[&] { delete this; }));
|
2020-07-30 18:05:57 +00:00
|
|
|
if (scraperParams.game->getType() == FOLDER) {
|
2020-09-27 08:41:00 +00:00
|
|
|
if (mClearGameFunc) {
|
2021-07-07 18:03:42 +00:00
|
|
|
auto clearSelf = [&] {
|
|
|
|
mClearGameFunc();
|
|
|
|
delete this;
|
|
|
|
};
|
2020-09-27 08:41:00 +00:00
|
|
|
auto clearSelfBtnFunc = [this, clearSelf] {
|
2020-07-30 18:05:57 +00:00
|
|
|
mWindow->pushGui(new GuiMsgBox(mWindow, getHelpStyle(),
|
2021-07-07 18:03:42 +00:00
|
|
|
"THIS WILL DELETE ANY MEDIA FILES AND\n"
|
|
|
|
"THE GAMELIST.XML ENTRY FOR THIS FOLDER,\n"
|
|
|
|
"BUT NEITHER THE FOLDER ITSELF OR ANY\n"
|
|
|
|
"CONTENT INSIDE IT WILL BE REMOVED\n"
|
|
|
|
"ARE YOU SURE?",
|
|
|
|
"YES", clearSelf, "NO", nullptr));
|
|
|
|
};
|
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "CLEAR", "clear folder",
|
|
|
|
clearSelfBtnFunc));
|
2020-07-30 18:05:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-09-27 08:41:00 +00:00
|
|
|
if (mClearGameFunc) {
|
2021-07-07 18:03:42 +00:00
|
|
|
auto clearSelf = [&] {
|
|
|
|
mClearGameFunc();
|
|
|
|
delete this;
|
|
|
|
};
|
2020-09-27 08:41:00 +00:00
|
|
|
auto clearSelfBtnFunc = [this, clearSelf] {
|
|
|
|
mWindow->pushGui(new GuiMsgBox(mWindow, getHelpStyle(),
|
2021-07-07 18:03:42 +00:00
|
|
|
"THIS WILL DELETE ANY MEDIA FILES\n"
|
|
|
|
"AND THE GAMELIST.XML ENTRY FOR\n"
|
|
|
|
"THIS GAME, BUT THE GAME FILE\n"
|
|
|
|
"ITSELF WILL NOT BE REMOVED\n"
|
|
|
|
"ARE YOU SURE?",
|
|
|
|
"YES", clearSelf, "NO", nullptr));
|
|
|
|
};
|
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "CLEAR", "clear file",
|
|
|
|
clearSelfBtnFunc));
|
2020-09-27 08:41:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 18:05:57 +00:00
|
|
|
if (mDeleteGameFunc) {
|
2021-07-07 18:03:42 +00:00
|
|
|
auto deleteFilesAndSelf = [&] {
|
|
|
|
mDeleteGameFunc();
|
|
|
|
delete this;
|
|
|
|
};
|
2020-07-30 18:05:57 +00:00
|
|
|
auto deleteGameBtnFunc = [this, deleteFilesAndSelf] {
|
|
|
|
mWindow->pushGui(new GuiMsgBox(mWindow, getHelpStyle(),
|
2021-07-07 18:03:42 +00:00
|
|
|
"THIS WILL DELETE THE GAME\n"
|
|
|
|
"FILE, ANY MEDIA FILES AND\n"
|
|
|
|
"THE GAMELIST.XML ENTRY\n"
|
|
|
|
"ARE YOU SURE?",
|
|
|
|
"YES", deleteFilesAndSelf, "NO", nullptr));
|
|
|
|
};
|
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "DELETE", "delete game",
|
|
|
|
deleteGameBtnFunc));
|
2020-07-30 18:05:57 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mButtons = makeButtonGrid(mWindow, buttons);
|
|
|
|
mGrid.setEntry(mButtons, Vector2i(0, 2), true, false);
|
|
|
|
|
|
|
|
// Resize + center.
|
2021-07-07 18:03:42 +00:00
|
|
|
float width =
|
|
|
|
static_cast<float>(std::min(static_cast<int>(Renderer::getScreenHeight() * 1.05f),
|
|
|
|
static_cast<int>(Renderer::getScreenWidth() * 0.90f)));
|
2021-01-29 17:02:04 +00:00
|
|
|
setSize(width, Renderer::getScreenHeight() * 0.83f);
|
2021-07-07 18:03:42 +00:00
|
|
|
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2.0f,
|
|
|
|
(Renderer::getScreenHeight() - mSize.y()) / 2.0f);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiMetaDataEd::onSizeChanged()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mGrid.setSize(mSize);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
const float titleHeight = mTitle->getFont()->getLetterHeight();
|
|
|
|
const float subtitleHeight = mSubtitle->getFont()->getLetterHeight();
|
|
|
|
const float titleSubtitleSpacing = mSize.y() * 0.03f;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
mGrid.setRowHeightPerc(
|
|
|
|
0, (titleHeight + titleSubtitleSpacing + subtitleHeight + TITLE_VERT_PADDING) / mSize.y());
|
2020-06-21 12:25:28 +00:00
|
|
|
mGrid.setRowHeightPerc(2, mButtons->getSize().y() / mSize.y());
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-03-14 08:36:50 +00:00
|
|
|
// Snap list size to the row height to prevent a fraction of a row from being displayed.
|
2021-01-29 17:02:04 +00:00
|
|
|
float listHeight = 0;
|
|
|
|
float listSize = mList->getSize().y();
|
|
|
|
int i = 0;
|
|
|
|
while (i < mList->size()) {
|
|
|
|
// Add the separator height to the row height so that it also gets properly rendered.
|
|
|
|
float rowHeight = mList->getRowHeight(i) + (1 * Renderer::getScreenHeightModifier());
|
|
|
|
if (listHeight + rowHeight < listSize)
|
|
|
|
listHeight += rowHeight;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust the size of the list and window.
|
|
|
|
float heightAdjustment = listSize - listHeight;
|
|
|
|
mList->setSize(mList->getSize().x(), listHeight);
|
|
|
|
Vector2f newWindowSize = mSize;
|
|
|
|
newWindowSize.y() -= heightAdjustment;
|
2021-07-07 18:03:42 +00:00
|
|
|
mBackground.fitTo(newWindowSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
|
2021-01-29 17:02:04 +00:00
|
|
|
|
|
|
|
// Move the buttons up as well to make the layout align correctly after the resize.
|
|
|
|
Vector3f newButtonPos = mButtons->getPosition();
|
|
|
|
newButtonPos.y() -= heightAdjustment;
|
|
|
|
mButtons->setPosition(newButtonPos);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mHeaderGrid->setRowHeightPerc(1, titleHeight / mHeaderGrid->getSize().y());
|
|
|
|
mHeaderGrid->setRowHeightPerc(2, titleSubtitleSpacing / mHeaderGrid->getSize().y());
|
|
|
|
mHeaderGrid->setRowHeightPerc(3, subtitleHeight / mHeaderGrid->getSize().y());
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiMetaDataEd::save()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Remove game from index.
|
|
|
|
mScraperParams.system->getIndex()->removeFromIndex(mScraperParams.game);
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2020-07-26 20:19:29 +00:00
|
|
|
// We need this to handle the special situation where the user sets a game to hidden while
|
|
|
|
// ShowHiddenGames is set to false, meaning it will immediately disappear from the gamelist.
|
|
|
|
bool showHiddenGames = Settings::getInstance()->getBool("ShowHiddenGames");
|
|
|
|
bool hideGameWhileHidden = false;
|
2020-12-31 20:54:32 +00:00
|
|
|
bool setGameAsCounted = false;
|
2020-07-26 20:19:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned int i = 0; i < mEditors.size(); i++) {
|
|
|
|
if (mMetaDataDecl.at(i).isStatistic)
|
|
|
|
continue;
|
2020-05-19 15:52:11 +00:00
|
|
|
|
2020-07-26 20:19:29 +00:00
|
|
|
if (!showHiddenGames && mMetaDataDecl.at(i).key == "hidden" &&
|
2021-07-07 18:03:42 +00:00
|
|
|
mEditors.at(i)->getValue() != mMetaData->get("hidden"))
|
2020-07-26 20:19:29 +00:00
|
|
|
hideGameWhileHidden = true;
|
|
|
|
|
2020-12-31 20:54:32 +00:00
|
|
|
// Check whether the flag to count the entry as a game was set to enabled.
|
|
|
|
if (mMetaDataDecl.at(i).key == "nogamecount" &&
|
2021-07-07 18:03:42 +00:00
|
|
|
mEditors.at(i)->getValue() != mMetaData->get("nogamecount") &&
|
|
|
|
mMetaData->get("nogamecount") == "true") {
|
2020-12-31 20:54:32 +00:00
|
|
|
setGameAsCounted = true;
|
|
|
|
}
|
|
|
|
|
2020-08-02 09:45:59 +00:00
|
|
|
mMetaData->set(mMetaDataDecl.at(i).key, mEditors.at(i)->getValue());
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-11-08 17:33:28 +00:00
|
|
|
// If hidden games are not shown and the hide flag was set for the entry, then write the
|
2020-07-26 20:19:29 +00:00
|
|
|
// metadata immediately regardless of the SaveGamelistsMode setting. Otherwise the file
|
|
|
|
// will never be written as the game will be filtered from the gamelist. This solution is not
|
|
|
|
// really good as the gamelist will be written twice, but it's a very special and hopefully
|
|
|
|
// rare situation.
|
|
|
|
if (hideGameWhileHidden)
|
|
|
|
updateGamelist(mScraperParams.system);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Enter game in index.
|
|
|
|
mScraperParams.system->getIndex()->addToIndex(mScraperParams.game);
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2020-09-27 09:19:55 +00:00
|
|
|
// If it's a folder that has been updated, we need to manually sort the gamelist
|
2020-12-23 17:06:30 +00:00
|
|
|
// as CollectionSystemsManager ignores folders.
|
2020-09-27 09:19:55 +00:00
|
|
|
if (mScraperParams.game->getType() == FOLDER)
|
|
|
|
mScraperParams.system->sortSystem(false);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mSavedCallback)
|
|
|
|
mSavedCallback();
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2021-02-04 22:58:27 +00:00
|
|
|
if (hideGameWhileHidden) {
|
2021-02-05 16:10:47 +00:00
|
|
|
std::vector<FileData*> hideGames;
|
|
|
|
// If a folder was hidden there may be children inside that we also need to hide.
|
|
|
|
if (mScraperParams.game->getType() == FOLDER) {
|
|
|
|
for (FileData* child : mScraperParams.game->getChildrenRecursive()) {
|
|
|
|
if (!child->getHidden())
|
|
|
|
child->metadata.set("hidden", "true");
|
2021-07-07 18:03:42 +00:00
|
|
|
hideGames.push_back(child);
|
2021-02-05 16:10:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
hideGames.push_back(mScraperParams.game);
|
|
|
|
}
|
|
|
|
for (FileData* hideGame : hideGames) {
|
|
|
|
if (hideGame->getType() == GAME) {
|
|
|
|
// Update disabled auto collections when hiding a game, as otherwise these could
|
|
|
|
// get invalid gamelist cursor positions. A cursor pointing to a removed game
|
|
|
|
// would crash the application upon enabling the collections.
|
|
|
|
CollectionSystemsManager::get()->refreshCollectionSystems(hideGame, true);
|
|
|
|
// Remove the game from the index of all systems.
|
|
|
|
for (SystemData* sys : SystemData::sSystemVector) {
|
|
|
|
std::vector<FileData*> children;
|
|
|
|
for (FileData* child : sys->getRootFolder()->getChildrenRecursive())
|
|
|
|
children.push_back(child->getSourceFileData());
|
|
|
|
if (std::find(children.begin(), children.end(), hideGame) != children.end()) {
|
|
|
|
sys->getIndex()->removeFromIndex(hideGame);
|
|
|
|
// Reload the gamelist as well as the view style may need to change.
|
|
|
|
ViewController::get()->reloadGameListView(sys);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Update all collections where the game is present.
|
|
|
|
CollectionSystemsManager::get()->refreshCollectionSystems(mScraperParams.game);
|
2021-02-04 22:58:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-31 20:54:32 +00:00
|
|
|
// If game counting was re-enabled for the game, then reactivate it in any custom collections
|
|
|
|
// where it may exist.
|
|
|
|
if (setGameAsCounted)
|
|
|
|
CollectionSystemsManager::get()->reactivateCustomCollectionEntry(mScraperParams.game);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mScraperParams.system->onMetaDataSavePoint();
|
2020-09-27 09:19:55 +00:00
|
|
|
|
2020-11-08 17:33:28 +00:00
|
|
|
// If hidden games are not shown and the hide flag was set for the entry, we also need
|
|
|
|
// to re-sort the gamelist as we may need to remove the parent folder if all the entries
|
|
|
|
// within this folder are now hidden.
|
|
|
|
if (hideGameWhileHidden)
|
|
|
|
mScraperParams.system->sortSystem(true);
|
|
|
|
|
2020-09-13 17:20:30 +00:00
|
|
|
// Make sure that the cached background is updated to reflect any possible visible
|
|
|
|
// changes to the gamelist (e.g. the game name).
|
|
|
|
mWindow->invalidateCachedBackground();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiMetaDataEd::fetch()
|
|
|
|
{
|
2021-07-07 18:03:42 +00:00
|
|
|
GuiGameScraper* scr = new GuiGameScraper(
|
|
|
|
mWindow, mScraperParams, std::bind(&GuiMetaDataEd::fetchDone, this, std::placeholders::_1));
|
2020-06-21 12:25:28 +00:00
|
|
|
mWindow->pushGui(scr);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiMetaDataEd::fetchDone(const ScraperSearchResult& result)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Clone the mMetaData object.
|
|
|
|
MetaDataList* metadata = nullptr;
|
|
|
|
metadata = new MetaDataList(*mMetaData);
|
|
|
|
|
2020-08-05 20:38:44 +00:00
|
|
|
mMediaFilesUpdated = result.savedNewMedia;
|
2020-07-13 18:10:09 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Check if any values were manually changed before starting the scraping.
|
|
|
|
// If so, it's these values we should compare against when scraping, not
|
|
|
|
// the values previously saved for the game.
|
|
|
|
for (unsigned int i = 0; i < mEditors.size(); i++) {
|
|
|
|
const std::string& key = mMetaDataDecl.at(i).key;
|
|
|
|
if (metadata->get(key) != mEditors[i]->getValue())
|
|
|
|
metadata->set(key, mEditors[i]->getValue());
|
|
|
|
}
|
|
|
|
|
2021-01-26 16:40:37 +00:00
|
|
|
GuiScraperSearch::saveMetadata(result, *metadata, mScraperParams.game);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Update the list with the scraped metadata values.
|
|
|
|
for (unsigned int i = 0; i < mEditors.size(); i++) {
|
|
|
|
const std::string& key = mMetaDataDecl.at(i).key;
|
|
|
|
if (mEditors.at(i)->getValue() != metadata->get(key)) {
|
2020-07-15 15:44:27 +00:00
|
|
|
if (key == "rating")
|
|
|
|
mEditors.at(i)->setOriginalColor(ICONCOLOR_SCRAPERMARKED);
|
|
|
|
else
|
|
|
|
mEditors.at(i)->setColor(TEXTCOLOR_SCRAPERMARKED);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2020-08-08 09:36:43 +00:00
|
|
|
// Save all the keys that should be scraped.
|
|
|
|
if (mMetaDataDecl.at(i).shouldScrape)
|
2020-07-15 15:44:27 +00:00
|
|
|
mEditors.at(i)->setValue(metadata->get(key));
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete metadata;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 18:03:31 +00:00
|
|
|
void GuiMetaDataEd::close()
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Find out if the user made any changes.
|
2020-07-15 15:44:27 +00:00
|
|
|
bool metadataUpdated = false;
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned int i = 0; i < mEditors.size(); i++) {
|
|
|
|
const std::string& key = mMetaDataDecl.at(i).key;
|
|
|
|
std::string mMetaDataValue = mMetaData->get(key);
|
|
|
|
std::string mEditorsValue = mEditors.at(i)->getValue();
|
|
|
|
|
|
|
|
if (mMetaDataValue != mEditorsValue) {
|
2020-07-15 15:44:27 +00:00
|
|
|
metadataUpdated = true;
|
2020-06-21 12:25:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::function<void()> closeFunc;
|
2021-07-07 18:03:42 +00:00
|
|
|
closeFunc = [this] {
|
|
|
|
if (mMediaFilesUpdated) {
|
|
|
|
// Always reload the gamelist if media files were updated, even if the user
|
|
|
|
// chose to not save any metadata changes. Also manually unload the game image
|
|
|
|
// and marquee, as otherwise they would not get updated until the user scrolls up
|
|
|
|
// and down the gamelist.
|
|
|
|
TextureResource::manualUnload(mScraperParams.game->getImagePath(), false);
|
|
|
|
TextureResource::manualUnload(mScraperParams.game->getMarqueePath(), false);
|
|
|
|
ViewController::get()->reloadGameListView(mScraperParams.system);
|
|
|
|
mWindow->invalidateCachedBackground();
|
|
|
|
}
|
|
|
|
ViewController::get()->onPauseVideo();
|
|
|
|
delete this;
|
|
|
|
};
|
2020-09-27 09:41:53 +00:00
|
|
|
|
2020-07-15 15:44:27 +00:00
|
|
|
if (metadataUpdated) {
|
2020-06-21 12:25:28 +00:00
|
|
|
// Changes were made, ask if the user wants to save them.
|
2021-07-07 18:03:42 +00:00
|
|
|
mWindow->pushGui(new GuiMsgBox(
|
|
|
|
mWindow, getHelpStyle(), "SAVE CHANGES?", "YES",
|
|
|
|
[this, closeFunc] {
|
|
|
|
save();
|
|
|
|
closeFunc();
|
|
|
|
},
|
|
|
|
"NO", closeFunc));
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-07-13 18:10:09 +00:00
|
|
|
// Always save if the media files have been changed (i.e. newly scraped images).
|
|
|
|
if (mMediaFilesUpdated)
|
|
|
|
save();
|
2020-06-21 12:25:28 +00:00
|
|
|
closeFunc();
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiMetaDataEd::input(InputConfig* config, Input input)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (GuiComponent::input(config, input))
|
|
|
|
return true;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (input.value != 0 && (config->isMappedTo("b", input))) {
|
|
|
|
close();
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-11-08 12:24:34 +00:00
|
|
|
if (input.value != 0 && (config->isMappedTo("y", input))) {
|
|
|
|
fetch();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return false;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<HelpPrompt> GuiMetaDataEd::getHelpPrompts()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<HelpPrompt> prompts = mGrid.getHelpPrompts();
|
2020-11-08 12:24:34 +00:00
|
|
|
prompts.push_back(HelpPrompt("y", "scrape"));
|
2020-06-21 12:25:28 +00:00
|
|
|
prompts.push_back(HelpPrompt("b", "back"));
|
|
|
|
return prompts;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
2020-06-07 18:09:02 +00:00
|
|
|
|
|
|
|
HelpStyle GuiMetaDataEd::getHelpStyle()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
HelpStyle style = HelpStyle();
|
|
|
|
style.applyTheme(ViewController::get()->getState().getSystem()->getTheme(), "system");
|
|
|
|
return style;
|
2020-06-07 18:09:02 +00:00
|
|
|
}
|