2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-22 15:27:53 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-22 15:27:53 +00:00
|
|
|
// GuiCollectionSystemsOptions.cpp
|
|
|
|
//
|
|
|
|
// User interface for the game collection settings.
|
2020-06-28 16:39:18 +00:00
|
|
|
// Submenu to the GuiMenu main menu.
|
2020-06-22 15:27:53 +00:00
|
|
|
//
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
#include "guis/GuiCollectionSystemsOptions.h"
|
|
|
|
|
|
|
|
#include "components/OptionListComponent.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "components/SwitchComponent.h"
|
|
|
|
#include "guis/GuiSettings.h"
|
|
|
|
#include "guis/GuiTextEditPopup.h"
|
2018-01-26 18:53:19 +00:00
|
|
|
#include "utils/StringUtil.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "views/ViewController.h"
|
|
|
|
#include "CollectionSystemManager.h"
|
2020-06-07 18:09:02 +00:00
|
|
|
#include "SystemData.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "Window.h"
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(Window* window)
|
|
|
|
: GuiComponent(window), mMenu(window, "GAME COLLECTION SETTINGS")
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
initializeMenu();
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiCollectionSystemsOptions::initializeMenu()
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
addChild(&mMenu);
|
|
|
|
|
|
|
|
// Get collections.
|
|
|
|
addSystemsToMenu();
|
|
|
|
|
|
|
|
// Add "Create New Custom Collection from Theme".
|
|
|
|
std::vector<std::string> unusedFolders =
|
|
|
|
CollectionSystemManager::get()->getUnusedSystemsFromTheme();
|
|
|
|
if (unusedFolders.size() > 0) {
|
|
|
|
addEntry("CREATE NEW CUSTOM COLLECTION FROM THEME", 0x777777FF, true,
|
|
|
|
[this, unusedFolders] {
|
|
|
|
auto s = new GuiSettings(mWindow, "SELECT THEME FOLDER");
|
|
|
|
std::shared_ptr< OptionListComponent<std::string>>
|
|
|
|
folderThemes = std::make_shared< OptionListComponent<std::string>>
|
|
|
|
(mWindow, getHelpStyle(), "SELECT THEME FOLDER", true);
|
|
|
|
|
|
|
|
// Add custom systems.
|
2020-07-13 18:58:25 +00:00
|
|
|
for (auto it = unusedFolders.cbegin() ; it != unusedFolders.cend() ; it++ ) {
|
2020-06-22 15:27:53 +00:00
|
|
|
ComponentListRow row;
|
|
|
|
std::string name = *it;
|
|
|
|
|
|
|
|
std::function<void()> createCollectionCall = [name, this, s] {
|
|
|
|
createCollection(name);
|
|
|
|
};
|
|
|
|
row.makeAcceptInputHandler(createCollectionCall);
|
|
|
|
|
|
|
|
auto themeFolder = std::make_shared<TextComponent>(mWindow,
|
|
|
|
Utils::String::toUpper(name), Font::get(FONT_SIZE_SMALL), 0x777777FF);
|
|
|
|
row.addElement(themeFolder, true);
|
|
|
|
s->addRow(row);
|
|
|
|
}
|
|
|
|
mWindow->pushGui(s);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ComponentListRow row;
|
|
|
|
row.addElement(std::make_shared<TextComponent>(mWindow,
|
|
|
|
"CREATE NEW CUSTOM COLLECTION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
|
|
|
auto bracket = std::make_shared<ImageComponent>(mWindow);
|
|
|
|
bracket->setImage(":/graphics/arrow.svg");
|
|
|
|
bracket->setResize(Vector2f(0, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight()));
|
|
|
|
row.addElement(bracket, false);
|
|
|
|
auto createCustomCollection = [this](const std::string& newVal) {
|
|
|
|
std::string name = newVal;
|
|
|
|
// We need to store the first GUI and remove it, as it'll
|
|
|
|
// be deleted by the actual GUI.
|
|
|
|
Window* window = mWindow;
|
|
|
|
GuiComponent* topGui = window->peekGui();
|
|
|
|
window->removeGui(topGui);
|
|
|
|
createCollection(name);
|
|
|
|
};
|
|
|
|
row.makeAcceptInputHandler([this, createCustomCollection] {
|
|
|
|
mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(),
|
|
|
|
"New Collection Name", "", createCustomCollection, false, "SAVE"));
|
|
|
|
});
|
|
|
|
|
|
|
|
mMenu.addRow(row);
|
|
|
|
|
|
|
|
sortFavFirstCustomSwitch = std::make_shared<SwitchComponent>(mWindow);
|
|
|
|
sortFavFirstCustomSwitch->setState(Settings::getInstance()->getBool("FavFirstCustom"));
|
|
|
|
mMenu.addWithLabel("SORT FAVORITES ON TOP FOR CUSTOM COLLECTIONS", sortFavFirstCustomSwitch);
|
|
|
|
|
|
|
|
bundleCustomCollections = std::make_shared<SwitchComponent>(mWindow);
|
|
|
|
bundleCustomCollections->setState(Settings::getInstance()->
|
|
|
|
getBool("UseCustomCollectionsSystem"));
|
|
|
|
mMenu.addWithLabel("GROUP UNTHEMED CUSTOM COLLECTIONS", bundleCustomCollections);
|
|
|
|
|
|
|
|
toggleSystemNameInCollections = std::make_shared<SwitchComponent>(mWindow);
|
|
|
|
toggleSystemNameInCollections->setState(Settings::getInstance()->
|
|
|
|
getBool("CollectionShowSystemInfo"));
|
|
|
|
mMenu.addWithLabel("SHOW SYSTEM NAMES IN COLLECTIONS", toggleSystemNameInCollections);
|
|
|
|
|
2020-07-13 18:58:25 +00:00
|
|
|
if (CollectionSystemManager::get()->isEditing()) {
|
2020-06-22 15:27:53 +00:00
|
|
|
row.elements.clear();
|
|
|
|
row.addElement(std::make_shared<TextComponent>(mWindow, "FINISH EDITING '" +
|
|
|
|
Utils::String::toUpper(CollectionSystemManager::get()->getEditingCollection()) +
|
|
|
|
"' COLLECTION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
|
|
|
row.makeAcceptInputHandler(std::bind(&GuiCollectionSystemsOptions::exitEditMode, this));
|
|
|
|
mMenu.addRow(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
mMenu.addButton("BACK", "back", std::bind(&GuiCollectionSystemsOptions::applySettings, this));
|
|
|
|
mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2,
|
|
|
|
Renderer::getScreenHeight() * 0.15f);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
void GuiCollectionSystemsOptions::addEntry(const char* name, unsigned int color,
|
|
|
|
bool add_arrow, const std::function<void()>& func)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
std::shared_ptr<Font> font = Font::get(FONT_SIZE_MEDIUM);
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
// Populate the list.
|
|
|
|
ComponentListRow row;
|
|
|
|
row.addElement(std::make_shared<TextComponent>(mWindow, name, font, color), true);
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-07-13 18:58:25 +00:00
|
|
|
if (add_arrow) {
|
2020-06-22 15:27:53 +00:00
|
|
|
std::shared_ptr<ImageComponent> bracket = makeArrow(mWindow);
|
|
|
|
row.addElement(bracket, false);
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
row.makeAcceptInputHandler(func);
|
|
|
|
mMenu.addRow(row);
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiCollectionSystemsOptions::createCollection(std::string inName) {
|
2020-10-20 19:01:24 +00:00
|
|
|
if (CollectionSystemManager::get()->isEditing())
|
|
|
|
CollectionSystemManager::get()->exitEditMode();
|
2020-06-22 15:27:53 +00:00
|
|
|
std::string name = CollectionSystemManager::get()->getValidNewCollectionName(inName);
|
|
|
|
SystemData* newSys = CollectionSystemManager::get()->addNewCustomCollection(name);
|
2020-10-19 18:58:00 +00:00
|
|
|
CollectionSystemManager::get()->saveCustomCollection(newSys);
|
2020-06-22 15:27:53 +00:00
|
|
|
customOptionList->add(name, name, true);
|
|
|
|
std::string outAuto = Utils::String::vectorToCommaString(
|
|
|
|
autoOptionList->getSelectedObjects());
|
2020-10-22 19:23:16 +00:00
|
|
|
std::vector<std::string> customSystems = customOptionList->getSelectedObjects();
|
|
|
|
std::string outCustom = Utils::String::vectorToCommaString(customSystems, true);
|
2020-06-22 15:27:53 +00:00
|
|
|
updateSettings(outAuto, outCustom);
|
|
|
|
ViewController::get()->goToSystemView(newSys);
|
|
|
|
|
|
|
|
Window* window = mWindow;
|
|
|
|
CollectionSystemManager::get()->setEditMode(name);
|
2020-07-13 18:58:25 +00:00
|
|
|
while (window->peekGui() && window->peekGui() != ViewController::get())
|
2020-06-22 15:27:53 +00:00
|
|
|
delete window->peekGui();
|
|
|
|
return;
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiCollectionSystemsOptions::exitEditMode()
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
CollectionSystemManager::get()->exitEditMode();
|
|
|
|
applySettings();
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
GuiCollectionSystemsOptions::~GuiCollectionSystemsOptions()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiCollectionSystemsOptions::addSystemsToMenu()
|
|
|
|
{
|
2020-10-22 19:23:16 +00:00
|
|
|
std::map<std::string, CollectionSystemData, stringComparator> autoSystems =
|
2020-06-22 15:27:53 +00:00
|
|
|
CollectionSystemManager::get()->getAutoCollectionSystems();
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
autoOptionList = std::make_shared<OptionListComponent<std::string>>
|
|
|
|
(mWindow, getHelpStyle(), "SELECT COLLECTIONS", true);
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
// Add automatic systems.
|
2020-10-22 19:23:16 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, stringComparator>::const_iterator
|
|
|
|
it = autoSystems.cbegin(); it != autoSystems.cend() ; it++)
|
2020-06-22 15:27:53 +00:00
|
|
|
autoOptionList->add(it->second.decl.longName, it->second.decl.name, it->second.isEnabled);
|
|
|
|
mMenu.addWithLabel("AUTOMATIC GAME COLLECTIONS", autoOptionList);
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-10-22 19:23:16 +00:00
|
|
|
std::map<std::string, CollectionSystemData, stringComparator> customSystems =
|
2020-06-22 15:27:53 +00:00
|
|
|
CollectionSystemManager::get()->getCustomCollectionSystems();
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
customOptionList = std::make_shared<OptionListComponent<std::string>>
|
|
|
|
(mWindow, getHelpStyle(), "SELECT COLLECTIONS", true);
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
// Add custom systems.
|
2020-10-22 19:23:16 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, stringComparator>::const_iterator
|
|
|
|
it = customSystems.cbegin(); it != customSystems.cend() ; it++)
|
2020-06-22 15:27:53 +00:00
|
|
|
customOptionList->add(it->second.decl.longName, it->second.decl.name, it->second.isEnabled);
|
|
|
|
mMenu.addWithLabel("CUSTOM GAME COLLECTIONS", customOptionList);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiCollectionSystemsOptions::applySettings()
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
std::string outAuto = Utils::String::vectorToCommaString(
|
|
|
|
autoOptionList->getSelectedObjects());
|
|
|
|
std::string prevAuto = Settings::getInstance()->getString("CollectionSystemsAuto");
|
2020-10-22 19:23:16 +00:00
|
|
|
std::vector<std::string> customSystems = customOptionList->getSelectedObjects();
|
|
|
|
std::string outCustom = Utils::String::vectorToCommaString(customSystems, true);
|
2020-06-22 15:27:53 +00:00
|
|
|
std::string prevCustom = Settings::getInstance()->getString("CollectionSystemsCustom");
|
|
|
|
bool outSort = sortFavFirstCustomSwitch->getState();
|
|
|
|
bool prevSort = Settings::getInstance()->getBool("FavFirstCustom");
|
|
|
|
bool outBundle = bundleCustomCollections->getState();
|
|
|
|
bool prevBundle = Settings::getInstance()->getBool("UseCustomCollectionsSystem");
|
|
|
|
bool prevShow = Settings::getInstance()->getBool("CollectionShowSystemInfo");
|
|
|
|
bool outShow = toggleSystemNameInCollections->getState();
|
|
|
|
bool needUpdateSettings = prevAuto != outAuto || prevCustom != outCustom || outSort !=
|
|
|
|
prevSort || outBundle != prevBundle || prevShow != outShow ;
|
|
|
|
|
|
|
|
if (needUpdateSettings)
|
|
|
|
updateSettings(outAuto, outCustom);
|
|
|
|
|
|
|
|
delete this;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
void GuiCollectionSystemsOptions::updateSettings(std::string newAutoSettings,
|
|
|
|
std::string newCustomSettings)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
Settings::getInstance()->setString("CollectionSystemsAuto", newAutoSettings);
|
|
|
|
Settings::getInstance()->setString("CollectionSystemsCustom", newCustomSettings);
|
|
|
|
Settings::getInstance()->setBool("FavFirstCustom", sortFavFirstCustomSwitch->getState());
|
|
|
|
Settings::getInstance()->setBool("UseCustomCollectionsSystem",
|
|
|
|
bundleCustomCollections->getState());
|
|
|
|
Settings::getInstance()->setBool("CollectionShowSystemInfo",
|
|
|
|
toggleSystemNameInCollections->getState());
|
|
|
|
Settings::getInstance()->saveFile();
|
|
|
|
CollectionSystemManager::get()->loadEnabledListFromSettings();
|
|
|
|
CollectionSystemManager::get()->updateSystemsList();
|
|
|
|
ViewController::get()->goToStart();
|
|
|
|
ViewController::get()->reloadAll();
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiCollectionSystemsOptions::input(InputConfig* config, Input input)
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
bool consumed = GuiComponent::input(config, input);
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-07-13 18:58:25 +00:00
|
|
|
if (consumed)
|
2020-06-22 15:27:53 +00:00
|
|
|
return true;
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-07-13 18:58:25 +00:00
|
|
|
if (config->isMappedTo("b", input) && input.value != 0)
|
2020-06-22 15:27:53 +00:00
|
|
|
applySettings();
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
return false;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<HelpPrompt> GuiCollectionSystemsOptions::getHelpPrompts()
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
std::vector<HelpPrompt> prompts = mMenu.getHelpPrompts();
|
|
|
|
prompts.push_back(HelpPrompt("a", "select"));
|
|
|
|
prompts.push_back(HelpPrompt("b", "back"));
|
|
|
|
return prompts;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
2020-06-07 18:09:02 +00:00
|
|
|
|
|
|
|
HelpStyle GuiCollectionSystemsOptions::getHelpStyle()
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
HelpStyle style = HelpStyle();
|
|
|
|
style.applyTheme(ViewController::get()->getState().getSystem()->getTheme(), "system");
|
|
|
|
return style;
|
2020-06-07 18:09:02 +00:00
|
|
|
}
|