2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-23 18:07:00 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-23 18:07:00 +00:00
|
|
|
// GuiSettings.cpp
|
|
|
|
//
|
|
|
|
// User interface template for a settings GUI.
|
2020-11-05 17:18:11 +00:00
|
|
|
// The saving of es_settings.cfg and the reload of the gamelists are triggered from here
|
|
|
|
// based on the flags set by the actual menu entries' lambda functions.
|
2020-06-23 18:07:00 +00:00
|
|
|
//
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "guis/GuiSettings.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2020-11-05 17:18:11 +00:00
|
|
|
#include "guis/GuiTextEditPopup.h"
|
|
|
|
#include "views/gamelist/IGameListView.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "views/ViewController.h"
|
2020-11-06 19:27:41 +00:00
|
|
|
#include "CollectionSystemManager.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "Settings.h"
|
|
|
|
#include "SystemData.h"
|
|
|
|
#include "Window.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-11-05 17:18:11 +00:00
|
|
|
GuiSettings::GuiSettings(
|
|
|
|
Window* window,
|
2020-11-06 19:27:41 +00:00
|
|
|
std::string title)
|
2020-11-05 17:18:11 +00:00
|
|
|
: GuiComponent(window),
|
|
|
|
mMenu(window, title),
|
|
|
|
mNeedsSaving(false),
|
2020-11-06 19:27:41 +00:00
|
|
|
mNeedsCollectionsUpdate(false),
|
2020-11-05 17:18:11 +00:00
|
|
|
mNeedsReloading(false),
|
|
|
|
mNeedsSorting(false),
|
2020-11-06 19:27:41 +00:00
|
|
|
mNeedsSortingCollections(false),
|
|
|
|
mGoToSystem(nullptr),
|
|
|
|
mNeedsGoToStart(false),
|
2020-11-09 16:50:02 +00:00
|
|
|
mNeedsGoToSystemView(false)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
addChild(&mMenu);
|
|
|
|
mMenu.addButton("BACK", "back", [this] { delete this; });
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-23 18:07:00 +00:00
|
|
|
setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
|
|
|
mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GuiSettings::~GuiSettings()
|
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
save();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiSettings::save()
|
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
if (!mSaveFuncs.size())
|
|
|
|
return;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-23 18:07:00 +00:00
|
|
|
for (auto it = mSaveFuncs.cbegin(); it != mSaveFuncs.cend(); it++)
|
|
|
|
(*it)();
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-11-05 17:18:11 +00:00
|
|
|
if (mNeedsSaving)
|
|
|
|
Settings::getInstance()->saveFile();
|
|
|
|
|
2020-11-06 19:27:41 +00:00
|
|
|
if (mNeedsCollectionsUpdate) {
|
|
|
|
CollectionSystemManager::get()->loadEnabledListFromSettings();
|
|
|
|
CollectionSystemManager::get()->updateSystemsList();
|
|
|
|
}
|
2020-11-05 17:18:11 +00:00
|
|
|
|
|
|
|
if (mNeedsReloading)
|
|
|
|
ViewController::get()->reloadAll();
|
|
|
|
|
|
|
|
if (mNeedsSorting) {
|
|
|
|
for (auto it = SystemData::sSystemVector.cbegin(); it !=
|
|
|
|
SystemData::sSystemVector.cend(); it++) {
|
|
|
|
if (!(!mNeedsSortingCollections && (*it)->isCollection())) {
|
|
|
|
(*it)->sortSystem(true);
|
|
|
|
}
|
|
|
|
// Jump to the first row of the gamelist.
|
|
|
|
IGameListView* gameList = ViewController::get()->getGameListView((*it)).get();
|
|
|
|
gameList->setCursor(gameList->getFirstEntry());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-06 19:27:41 +00:00
|
|
|
if (mNeedsGoToStart)
|
|
|
|
ViewController::get()->goToStart();
|
|
|
|
|
|
|
|
if (mNeedsGoToSystemView)
|
|
|
|
ViewController::get()->goToSystemView(mGoToSystem);
|
|
|
|
|
|
|
|
if (mNeedsSaving || mNeedsCollectionsUpdate || mNeedsReloading || mNeedsSorting ||
|
2020-11-09 16:50:02 +00:00
|
|
|
mNeedsGoToStart || mNeedsGoToSystemView)
|
2020-11-05 17:18:11 +00:00
|
|
|
mWindow->invalidateCachedBackground();
|
|
|
|
}
|
|
|
|
|
2020-11-07 14:34:15 +00:00
|
|
|
void GuiSettings::addEditableTextComponent(
|
|
|
|
const std::string label,
|
|
|
|
std::shared_ptr<GuiComponent> ed,
|
|
|
|
std::string value,
|
|
|
|
std::string defaultValue,
|
|
|
|
bool isPassword)
|
2020-11-05 17:18:11 +00:00
|
|
|
{
|
|
|
|
ComponentListRow row;
|
|
|
|
row.elements.clear();
|
|
|
|
|
|
|
|
auto lbl = std::make_shared<TextComponent>(mWindow, Utils::String::toUpper(label),
|
|
|
|
Font::get(FONT_SIZE_MEDIUM), 0x777777FF);
|
|
|
|
|
|
|
|
row.addElement(lbl, true);
|
|
|
|
row.addElement(ed, true);
|
|
|
|
|
|
|
|
auto spacer = std::make_shared<GuiComponent>(mWindow);
|
|
|
|
spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0);
|
|
|
|
row.addElement(spacer, false);
|
|
|
|
|
|
|
|
auto bracket = std::make_shared<ImageComponent>(mWindow);
|
|
|
|
bracket->setImage(":/graphics/arrow.svg");
|
|
|
|
bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight()));
|
|
|
|
row.addElement(bracket, false);
|
|
|
|
|
|
|
|
// OK callback (apply new value to ed).
|
2020-11-07 14:34:15 +00:00
|
|
|
auto updateVal = [ed, defaultValue, isPassword](const std::string& newVal) {
|
2020-11-05 17:18:11 +00:00
|
|
|
// If the field is blank, apply the default value if it's been passes as an argument.
|
2020-11-07 14:34:15 +00:00
|
|
|
if (defaultValue != "" && newVal == "") {
|
2020-11-05 17:18:11 +00:00
|
|
|
ed->setValue(defaultValue);
|
2020-11-07 14:34:15 +00:00
|
|
|
}
|
|
|
|
// If it's a password and actually set to something, then show a star mask.
|
|
|
|
else if (isPassword && newVal == "") {
|
|
|
|
ed->setValue("");
|
|
|
|
ed->setHiddenValue("");
|
|
|
|
}
|
|
|
|
else if (isPassword) {
|
|
|
|
ed->setValue("********");
|
|
|
|
ed->setHiddenValue(newVal);
|
|
|
|
}
|
|
|
|
else {
|
2020-11-05 17:18:11 +00:00
|
|
|
ed->setValue(newVal);
|
2020-11-07 14:34:15 +00:00
|
|
|
}
|
2020-11-05 17:18:11 +00:00
|
|
|
};
|
2020-11-07 14:34:15 +00:00
|
|
|
|
|
|
|
row.makeAcceptInputHandler([this, label, ed, updateVal, isPassword] {
|
|
|
|
// Never display the value if it's a password, instead set it to blank.
|
|
|
|
if (isPassword)
|
|
|
|
mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), label,
|
|
|
|
"", updateVal, false));
|
|
|
|
else
|
|
|
|
mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), label,
|
|
|
|
ed->getValue(), updateVal, false));
|
2020-11-05 17:18:11 +00:00
|
|
|
});
|
|
|
|
assert(ed);
|
|
|
|
addRow(row);
|
|
|
|
|
|
|
|
ed->setValue(value);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiSettings::input(InputConfig* config, Input input)
|
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
if (config->isMappedTo("b", input) && input.value != 0) {
|
|
|
|
delete this;
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-23 18:07:00 +00:00
|
|
|
// Keep code for potential future use.
|
2020-11-05 17:18:11 +00:00
|
|
|
// if (config->isMappedTo("start", input) && input.value != 0) {
|
|
|
|
// // Close everything.
|
2020-06-23 18:07:00 +00:00
|
|
|
// Window* window = mWindow;
|
|
|
|
// while (window->peekGui() && window->peekGui() != ViewController::get())
|
|
|
|
// delete window->peekGui();
|
|
|
|
// return true;
|
|
|
|
// }
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-23 18:07:00 +00:00
|
|
|
return GuiComponent::input(config, input);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2017-05-28 18:13:00 +00:00
|
|
|
HelpStyle GuiSettings::getHelpStyle()
|
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
HelpStyle style = HelpStyle();
|
|
|
|
style.applyTheme(ViewController::get()->getState().getSystem()->getTheme(), "system");
|
|
|
|
return style;
|
2017-05-28 18:13:00 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
std::vector<HelpPrompt> GuiSettings::getHelpPrompts()
|
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
std::vector<HelpPrompt> prompts = mMenu.getHelpPrompts();
|
|
|
|
prompts.push_back(HelpPrompt("b", "back"));
|
|
|
|
return prompts;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|