diff --git a/es-app/src/guis/GuiCollectionSystemsOptions.cpp b/es-app/src/guis/GuiCollectionSystemsOptions.cpp index d320a1f40..abd2db712 100644 --- a/es-app/src/guis/GuiCollectionSystemsOptions.cpp +++ b/es-app/src/guis/GuiCollectionSystemsOptions.cpp @@ -13,257 +13,219 @@ #include "components/SwitchComponent.h" #include "guis/GuiSettings.h" #include "guis/GuiTextEditPopup.h" -#include "utils/StringUtil.h" #include "views/ViewController.h" #include "CollectionSystemManager.h" -#include "SystemData.h" -#include "Window.h" -GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(Window* window) - : GuiComponent(window), mMenu(window, "GAME COLLECTION SETTINGS") +GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(Window* window, std::string title) + : GuiSettings(window, title), mAddedCustomCollection(false) { - initializeMenu(); -} -void GuiCollectionSystemsOptions::initializeMenu() -{ - addChild(&mMenu); + // Finish editing custom collection. + if (CollectionSystemManager::get()->isEditing()) { + ComponentListRow row; + row.addElement(std::make_shared(mWindow, "FINISH EDITING '" + + Utils::String::toUpper(CollectionSystemManager::get()->getEditingCollection()) + + "' COLLECTION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); + row.makeAcceptInputHandler([this] { + CollectionSystemManager::get()->exitEditMode(); + delete this; + }); + addRow(row); + } - // Get collections. - addSystemsToMenu(); + // Automatic collections. + collection_systems_auto = std::make_shared> + (mWindow, getHelpStyle(), "SELECT COLLECTIONS", true); + std::map autoSystems = + CollectionSystemManager::get()->getAutoCollectionSystems(); + // Add automatic systems. + for (std::map::const_iterator + it = autoSystems.cbegin(); it != autoSystems.cend() ; it++) + collection_systems_auto->add(it->second.decl.longName, it->second.decl.name, + it->second.isEnabled); + addWithLabel("AUTOMATIC GAME COLLECTIONS", collection_systems_auto); + addSaveFunc([this] { + std::string autoSystemsSelected = + Utils::String::vectorToCommaString(collection_systems_auto->getSelectedObjects(), true); + std::string autoSystemsConfig = Settings::getInstance()->getString("CollectionSystemsAuto"); + if (autoSystemsSelected != autoSystemsConfig) { + if (CollectionSystemManager::get()->isEditing()) + CollectionSystemManager::get()->exitEditMode(); + Settings::getInstance()->setString("CollectionSystemsAuto", autoSystemsSelected); + setNeedsSaving(); + setNeedsReloading(); + setNeedsCollectionsUpdate(); + if (!mAddedCustomCollection) + setNeedsGoToSystemView(SystemData::sSystemVector.front()); + } + }); - // Add "Create New Custom Collection from Theme". + // Custom collections. + collection_systems_custom = std::make_shared> + (mWindow, getHelpStyle(), "SELECT COLLECTIONS", true); + std::map customSystems = + CollectionSystemManager::get()->getCustomCollectionSystems(); + // Add custom systems. + for (std::map::const_iterator + it = customSystems.cbegin(); it != customSystems.cend() ; it++) + collection_systems_custom->add(it->second.decl.longName, it->second.decl.name, + it->second.isEnabled); + addWithLabel("CUSTOM GAME COLLECTIONS", collection_systems_custom); + addSaveFunc([this] { + std::string customSystemsSelected = Utils::String::vectorToCommaString( + collection_systems_custom->getSelectedObjects(), true); + std::string customSystemsConfig = Settings::getInstance()-> + getString("CollectionSystemsCustom"); + if (customSystemsSelected != customSystemsConfig) { + if (CollectionSystemManager::get()->isEditing()) + CollectionSystemManager::get()->exitEditMode(); + Settings::getInstance()->setString("CollectionSystemsCustom", customSystemsSelected); + setNeedsSaving(); + setNeedsReloading(); + setNeedsCollectionsUpdate(); + if (!mAddedCustomCollection) + setNeedsGoToSystemView(SystemData::sSystemVector.front()); + } + }); + + // Create custom collection from theme. std::vector 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> - folderThemes = std::make_shared< OptionListComponent> - (mWindow, getHelpStyle(), "SELECT THEME FOLDER", true); - + ComponentListRow row; + auto themeCollection = std::make_shared(mWindow, + "CREATE NEW CUSTOM COLLECTION FROM THEME", Font::get(FONT_SIZE_MEDIUM), 0x777777FF); + auto bracketThemeCollection = std::make_shared(mWindow); + bracketThemeCollection->setImage(":/graphics/arrow.svg"); + bracketThemeCollection->setResize(Vector2f(0, + Font::get(FONT_SIZE_MEDIUM)->getLetterHeight())); + row.addElement(themeCollection, true); + row.addElement(bracketThemeCollection, false); + row.makeAcceptInputHandler([this, unusedFolders] { + auto ss = new GuiSettings(mWindow, "SELECT THEME FOLDER"); + std::shared_ptr> folderThemes = + std::make_shared>(mWindow, + getHelpStyle(), "SELECT THEME FOLDER", true); // Add custom systems. for (auto it = unusedFolders.cbegin() ; it != unusedFolders.cend() ; it++ ) { ComponentListRow row; std::string name = *it; - - std::function createCollectionCall = [name, this, s] { - createCollection(name); + std::function createCollectionCall = [this, name] { + createCustomCollection(name); }; row.makeAcceptInputHandler(createCollectionCall); - auto themeFolder = std::make_shared(mWindow, Utils::String::toUpper(name), Font::get(FONT_SIZE_SMALL), 0x777777FF); row.addElement(themeFolder, true); - s->addRow(row); + ss->addRow(row); } - mWindow->pushGui(s); + mWindow->pushGui(ss); }); + addRow(row); } + // Create new custom collection. ComponentListRow row; - row.addElement(std::make_shared(mWindow, - "CREATE NEW CUSTOM COLLECTION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); - auto bracket = std::make_shared(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) { + auto newCollection = std::make_shared(mWindow, + "CREATE NEW CUSTOM COLLECTION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF); + auto bracketNewCollection = std::make_shared(mWindow); + bracketNewCollection->setImage(":/graphics/arrow.svg"); + bracketNewCollection->setResize(Vector2f(0, + Font::get(FONT_SIZE_MEDIUM)->getLetterHeight())); + row.addElement(newCollection, true); + row.addElement(bracketNewCollection, false); + auto createCollectionCall = [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. + // 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); + createCustomCollection(name); }; - row.makeAcceptInputHandler([this, createCustomCollection] { + row.makeAcceptInputHandler([this, createCollectionCall] { mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), - "New Collection Name", "", createCustomCollection, false, "SAVE")); + "New Collection Name", "", createCollectionCall, false, "SAVE")); + }); + addRow(row); + + // Sort favorites on top for custom collections. + auto fav_first_custom = std::make_shared(mWindow); + fav_first_custom->setState(Settings::getInstance()->getBool("FavFirstCustom")); + addWithLabel("SORT FAVORITES ON TOP FOR CUSTOM COLLECTIONS", fav_first_custom); + addSaveFunc([this, fav_first_custom] { + if (fav_first_custom->getState() != Settings::getInstance()->getBool("FavFirstCustom")) { + Settings::getInstance()->setBool("FavFirstCustom", fav_first_custom->getState()); + setNeedsSaving(); + setNeedsReloading(); + setNeedsSorting(); + setNeedsSortingCollections(); + } }); - mMenu.addRow(row); + // Display star markings for custom collections. + auto fav_star_custom = std::make_shared(mWindow); + fav_star_custom->setState(Settings::getInstance()->getBool("FavStarCustom")); + addWithLabel("DISPLAY STAR MARKINGS FOR CUSTOM COLLECTIONS", fav_star_custom); + addSaveFunc([this, fav_star_custom] { + if (fav_star_custom->getState() != Settings::getInstance()->getBool("FavStarCustom")) { + Settings::getInstance()->setBool("FavStarCustom", fav_star_custom->getState()); + setNeedsSaving(); + setNeedsReloading(); + } + }); - sortFavFirstCustomSwitch = std::make_shared(mWindow); - sortFavFirstCustomSwitch->setState(Settings::getInstance()->getBool("FavFirstCustom")); - mMenu.addWithLabel("SORT FAVORITES ON TOP FOR CUSTOM COLLECTIONS", sortFavFirstCustomSwitch); - - favoriteStarCustomSwitch = std::make_shared(mWindow); - favoriteStarCustomSwitch->setState(Settings::getInstance()->getBool("FavStarCustom")); - mMenu.addWithLabel("DISPLAY STAR MARKINGS FOR CUSTOM COLLECTIONS", favoriteStarCustomSwitch); - - bundleCustomCollections = std::make_shared(mWindow); - bundleCustomCollections->setState(Settings::getInstance()-> + // Group unthemed custom collections. + auto use_custom_collections_system = std::make_shared(mWindow); + use_custom_collections_system->setState(Settings::getInstance()-> getBool("UseCustomCollectionsSystem")); - mMenu.addWithLabel("GROUP UNTHEMED CUSTOM COLLECTIONS", bundleCustomCollections); + addWithLabel("GROUP UNTHEMED CUSTOM COLLECTIONS", use_custom_collections_system); + addSaveFunc([this, use_custom_collections_system] { + if (use_custom_collections_system->getState() != + Settings::getInstance()->getBool("UseCustomCollectionsSystem")) { + Settings::getInstance()->setBool("UseCustomCollectionsSystem", + use_custom_collections_system->getState()); + setNeedsSaving(); + setNeedsCollectionsUpdate(); + setNeedsReloading(); + setNeedsGoToSystemView(SystemData::sSystemVector.front()); + } + }); - toggleSystemNameInCollections = std::make_shared(mWindow); - toggleSystemNameInCollections->setState(Settings::getInstance()-> + // Show system names in collections. + auto collection_show_system_info = std::make_shared(mWindow); + collection_show_system_info->setState(Settings::getInstance()-> getBool("CollectionShowSystemInfo")); - mMenu.addWithLabel("SHOW SYSTEM NAMES IN COLLECTIONS", toggleSystemNameInCollections); - - if (CollectionSystemManager::get()->isEditing()) { - row.elements.clear(); - row.addElement(std::make_shared(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); + addWithLabel("SHOW SYSTEM NAMES IN COLLECTIONS", collection_show_system_info); + addSaveFunc([this, collection_show_system_info] { + if (collection_show_system_info->getState() != + Settings::getInstance()->getBool("CollectionShowSystemInfo")) { + Settings::getInstance()->setBool("CollectionShowSystemInfo", + collection_show_system_info->getState()); + setNeedsSaving(); + setNeedsReloading(); + } + }); } -void GuiCollectionSystemsOptions::addEntry(const char* name, unsigned int color, - bool add_arrow, const std::function& func) +void GuiCollectionSystemsOptions::createCustomCollection(std::string inName) { - std::shared_ptr font = Font::get(FONT_SIZE_MEDIUM); - - // Populate the list. - ComponentListRow row; - row.addElement(std::make_shared(mWindow, name, font, color), true); - - if (add_arrow) { - std::shared_ptr bracket = makeArrow(mWindow); - row.addElement(bracket, false); - } - - row.makeAcceptInputHandler(func); - mMenu.addRow(row); -} - -void GuiCollectionSystemsOptions::createCollection(std::string inName) { if (CollectionSystemManager::get()->isEditing()) CollectionSystemManager::get()->exitEditMode(); - std::string name = CollectionSystemManager::get()->getValidNewCollectionName(inName); - SystemData* newSys = CollectionSystemManager::get()->addNewCustomCollection(name); - CollectionSystemManager::get()->saveCustomCollection(newSys); - customOptionList->add(name, name, true); - std::string outAuto = Utils::String::vectorToCommaString( - autoOptionList->getSelectedObjects()); - std::vector customSystems = customOptionList->getSelectedObjects(); - std::string outCustom = Utils::String::vectorToCommaString(customSystems, true); - updateSettings(outAuto, outCustom); - ViewController::get()->goToSystemView(newSys); + + std::string collectionName = CollectionSystemManager::get()-> + getValidNewCollectionName(inName); + SystemData* newCollection = CollectionSystemManager::get()-> + addNewCustomCollection(collectionName); + + CollectionSystemManager::get()->saveCustomCollection(newCollection); + collection_systems_custom->add(collectionName, collectionName, true); + + mAddedCustomCollection = true; + setNeedsGoToSystemView(newCollection); Window* window = mWindow; - CollectionSystemManager::get()->setEditMode(name); while (window->peekGui() && window->peekGui() != ViewController::get()) delete window->peekGui(); - return; -} - -void GuiCollectionSystemsOptions::exitEditMode() -{ - CollectionSystemManager::get()->exitEditMode(); - applySettings(); -} - -GuiCollectionSystemsOptions::~GuiCollectionSystemsOptions() -{ -} - -void GuiCollectionSystemsOptions::addSystemsToMenu() -{ - std::map autoSystems = - CollectionSystemManager::get()->getAutoCollectionSystems(); - - autoOptionList = std::make_shared> - (mWindow, getHelpStyle(), "SELECT COLLECTIONS", true); - - // Add automatic systems. - for (std::map::const_iterator - it = autoSystems.cbegin(); it != autoSystems.cend() ; it++) - autoOptionList->add(it->second.decl.longName, it->second.decl.name, it->second.isEnabled); - mMenu.addWithLabel("AUTOMATIC GAME COLLECTIONS", autoOptionList); - - std::map customSystems = - CollectionSystemManager::get()->getCustomCollectionSystems(); - - customOptionList = std::make_shared> - (mWindow, getHelpStyle(), "SELECT COLLECTIONS", true); - - // Add custom systems. - for (std::map::const_iterator - it = customSystems.cbegin(); it != customSystems.cend() ; it++) - customOptionList->add(it->second.decl.longName, it->second.decl.name, it->second.isEnabled); - mMenu.addWithLabel("CUSTOM GAME COLLECTIONS", customOptionList); -} - -void GuiCollectionSystemsOptions::applySettings() -{ - std::string outAuto = Utils::String::vectorToCommaString( - autoOptionList->getSelectedObjects()); - std::string prevAuto = Settings::getInstance()->getString("CollectionSystemsAuto"); - std::vector customSystems = customOptionList->getSelectedObjects(); - std::string outCustom = Utils::String::vectorToCommaString(customSystems, true); - std::string prevCustom = Settings::getInstance()->getString("CollectionSystemsCustom"); - bool outSort = sortFavFirstCustomSwitch->getState(); - bool prevSort = Settings::getInstance()->getBool("FavFirstCustom"); - bool outFavStar = favoriteStarCustomSwitch->getState(); - bool prevFavStar = Settings::getInstance()->getBool("FavStarCustom"); - 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 || outFavStar != prevFavStar || outBundle != prevBundle || prevShow != outShow; - - if (needUpdateSettings) - updateSettings(outAuto, outCustom); - - delete this; -} - -void GuiCollectionSystemsOptions::updateSettings(std::string newAutoSettings, - std::string newCustomSettings) -{ - if (CollectionSystemManager::get()->isEditing()) - CollectionSystemManager::get()->exitEditMode(); - - Settings::getInstance()->setString("CollectionSystemsAuto", newAutoSettings); - Settings::getInstance()->setString("CollectionSystemsCustom", newCustomSettings); - Settings::getInstance()->setBool("FavFirstCustom", sortFavFirstCustomSwitch->getState()); - Settings::getInstance()->setBool("FavStarCustom", favoriteStarCustomSwitch->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(); - mWindow->invalidateCachedBackground(); -} - -bool GuiCollectionSystemsOptions::input(InputConfig* config, Input input) -{ - bool consumed = GuiComponent::input(config, input); - - if (consumed) - return true; - - if (config->isMappedTo("b", input) && input.value != 0) - applySettings(); - - return false; -} - -std::vector GuiCollectionSystemsOptions::getHelpPrompts() -{ - std::vector prompts = mMenu.getHelpPrompts(); - prompts.push_back(HelpPrompt("a", "select")); - prompts.push_back(HelpPrompt("b", "back")); - return prompts; -} - -HelpStyle GuiCollectionSystemsOptions::getHelpStyle() -{ - HelpStyle style = HelpStyle(); - style.applyTheme(ViewController::get()->getState().getSystem()->getTheme(), "system"); - return style; + CollectionSystemManager::get()->setEditMode(collectionName); } diff --git a/es-app/src/guis/GuiCollectionSystemsOptions.h b/es-app/src/guis/GuiCollectionSystemsOptions.h index fbac6ba82..337bb7473 100644 --- a/es-app/src/guis/GuiCollectionSystemsOptions.h +++ b/es-app/src/guis/GuiCollectionSystemsOptions.h @@ -10,40 +10,23 @@ #ifndef ES_APP_GUIS_GUI_COLLECTION_SYSTEM_OPTIONS_H #define ES_APP_GUIS_GUI_COLLECTION_SYSTEM_OPTIONS_H -#include "components/MenuComponent.h" +#include "GuiSettings.h" template class OptionListComponent; -class SwitchComponent; -class SystemData; -class GuiCollectionSystemsOptions : public GuiComponent +class GuiCollectionSystemsOptions : public GuiSettings { public: - GuiCollectionSystemsOptions(Window* window); - ~GuiCollectionSystemsOptions(); - bool input(InputConfig* config, Input input) override; - - virtual std::vector getHelpPrompts() override; - HelpStyle getHelpStyle() override; + GuiCollectionSystemsOptions(Window* window, std::string title); private: - void initializeMenu(); - void applySettings(); - void addSystemsToMenu(); - void addEntry(const char* name, unsigned int color, - bool add_arrow, const std::function& func); - void updateSettings(std::string newAutoSettings, std::string newCustomSettings); - void createCollection(std::string inName); - void exitEditMode(); - std::shared_ptr> autoOptionList; - std::shared_ptr> customOptionList; - std::shared_ptr bundleCustomCollections; - std::shared_ptr sortFavFirstCustomSwitch; - std::shared_ptr favoriteStarCustomSwitch; - std::shared_ptr toggleSystemNameInCollections; - MenuComponent mMenu; - SystemData* mSystem; + void createCustomCollection(std::string inName); + + std::shared_ptr> collection_systems_auto; + std::shared_ptr> collection_systems_custom; + + bool mAddedCustomCollection; }; #endif // ES_APP_GUIS_GUI_COLLECTION_SYSTEM_OPTIONS_H diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index aa18ff617..11e4b79cb 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -75,8 +75,7 @@ GuiMenu::~GuiMenu() void GuiMenu::openScraperSettings() { - // Open the scrape menu. - mWindow->pushGui(new GuiScraperMenu(mWindow)); + mWindow->pushGui(new GuiScraperMenu(mWindow, "SCRAPER")); } void GuiMenu::openUISettings() @@ -163,7 +162,7 @@ void GuiMenu::openUISettings() CollectionSystemManager::get()->updateSystemsList(); Settings::getInstance()->setString("ThemeSet", theme_set->getSelected()); s->setNeedsSaving(); - s->setNeedsGoToStart(); + s->setNeedsGoToSystemView(SystemData::sSystemVector.front()); s->setNeedsReloading(); } }); @@ -894,12 +893,14 @@ void GuiMenu::addVersionInfo() addChild(&mVersion); } -void GuiMenu::openScreensaverOptions() { +void GuiMenu::openScreensaverOptions() +{ mWindow->pushGui(new GuiScreensaverOptions(mWindow, "SCREENSAVER SETTINGS")); } -void GuiMenu::openCollectionSystemSettings() { - mWindow->pushGui(new GuiCollectionSystemsOptions(mWindow)); +void GuiMenu::openCollectionSystemSettings() +{ + mWindow->pushGui(new GuiCollectionSystemsOptions(mWindow, "GAME COLLECTION SETTINGS")); } void GuiMenu::onSizeChanged() diff --git a/es-app/src/guis/GuiScraperMenu.cpp b/es-app/src/guis/GuiScraperMenu.cpp index b16560f19..c2887fcb8 100644 --- a/es-app/src/guis/GuiScraperMenu.cpp +++ b/es-app/src/guis/GuiScraperMenu.cpp @@ -19,8 +19,8 @@ #include "SystemData.h" #include "guis/GuiSettings.h" -GuiScraperMenu::GuiScraperMenu(Window* window) : GuiComponent(window), - mMenu(window, "SCRAPER") +GuiScraperMenu::GuiScraperMenu(Window* window, std::string title) + : GuiComponent(window), mMenu(window, title) { // Scraper service. mScraper = std::make_shared> diff --git a/es-app/src/guis/GuiScraperMenu.h b/es-app/src/guis/GuiScraperMenu.h index 52715316c..a6daafb7e 100644 --- a/es-app/src/guis/GuiScraperMenu.h +++ b/es-app/src/guis/GuiScraperMenu.h @@ -25,7 +25,7 @@ typedef std::function GameFilterFunc; class GuiScraperMenu : public GuiComponent { public: - GuiScraperMenu(Window* window); + GuiScraperMenu(Window* window, std::string title); ~GuiScraperMenu(); bool input(InputConfig* config, Input input) override; diff --git a/es-app/src/guis/GuiSettings.cpp b/es-app/src/guis/GuiSettings.cpp index 163dd4353..962ed940c 100644 --- a/es-app/src/guis/GuiSettings.cpp +++ b/es-app/src/guis/GuiSettings.cpp @@ -13,20 +13,25 @@ #include "guis/GuiTextEditPopup.h" #include "views/gamelist/IGameListView.h" #include "views/ViewController.h" +#include "CollectionSystemManager.h" #include "Settings.h" #include "SystemData.h" #include "Window.h" GuiSettings::GuiSettings( Window* window, - const char* title) + std::string title) : GuiComponent(window), mMenu(window, title), mNeedsSaving(false), - mNeedsGoToStart(false), + mNeedsCollectionsUpdate(false), mNeedsReloading(false), mNeedsSorting(false), - mNeedsSortingCollections(false) + mNeedsSortingCollections(false), + mGoToSystem(nullptr), + mNeedsGoToStart(false), + mNeedsGoToSystemView(false), + mNeedsDestroyAllWindows(false) { addChild(&mMenu); mMenu.addButton("BACK", "back", [this] { delete this; }); @@ -51,8 +56,10 @@ void GuiSettings::save() if (mNeedsSaving) Settings::getInstance()->saveFile(); - if (mNeedsGoToStart) - ViewController::get()->goToStart(); + if (mNeedsCollectionsUpdate) { + CollectionSystemManager::get()->loadEnabledListFromSettings(); + CollectionSystemManager::get()->updateSystemsList(); + } if (mNeedsReloading) ViewController::get()->reloadAll(); @@ -69,7 +76,19 @@ void GuiSettings::save() } } - if (mNeedsSaving || mNeedsGoToStart || mNeedsReloading || mNeedsSorting) + if (mNeedsGoToStart) + ViewController::get()->goToStart(); + + if (mNeedsGoToSystemView) + ViewController::get()->goToSystemView(mGoToSystem); + + if (mNeedsDestroyAllWindows) { + while (mWindow->peekGui() && mWindow->peekGui() != ViewController::get()) + delete mWindow->peekGui(); + } + + if (mNeedsSaving || mNeedsCollectionsUpdate || mNeedsReloading || mNeedsSorting || + mNeedsGoToStart || mNeedsGoToSystemView || mNeedsDestroyAllWindows) mWindow->invalidateCachedBackground(); } diff --git a/es-app/src/guis/GuiSettings.h b/es-app/src/guis/GuiSettings.h index d1e8b9657..fe1ebdb09 100644 --- a/es-app/src/guis/GuiSettings.h +++ b/es-app/src/guis/GuiSettings.h @@ -12,12 +12,13 @@ #define ES_APP_GUIS_GUI_SETTINGS_H #include "components/MenuComponent.h" +#include "SystemData.h" // This is just a really simple template for a GUI that calls some save functions when closed. class GuiSettings : public GuiComponent { public: - GuiSettings(Window* window, const char* title); + GuiSettings(Window* window, std::string title); virtual ~GuiSettings(); void save(); @@ -29,10 +30,14 @@ public: inline void addSaveFunc(const std::function& func) { mSaveFuncs.push_back(func); }; void setNeedsSaving() { mNeedsSaving = true; }; - void setNeedsGoToStart() { mNeedsGoToStart = true; }; + void setNeedsCollectionsUpdate() { mNeedsCollectionsUpdate = true; }; void setNeedsReloading() { mNeedsReloading = true; }; void setNeedsSorting() { mNeedsSorting = true; }; void setNeedsSortingCollections() { mNeedsSortingCollections = true; }; + void setNeedsGoToStart() { mNeedsGoToStart = true; }; + void setNeedsGoToSystemView(SystemData* goToSystem) + { mNeedsGoToSystemView = true; mGoToSystem = goToSystem; }; + void setNeedsDestroyAllWindows() { mNeedsDestroyAllWindows = true; }; bool input(InputConfig* config, Input input) override; std::vector getHelpPrompts() override; @@ -42,10 +47,15 @@ private: MenuComponent mMenu; std::vector> mSaveFuncs; bool mNeedsSaving; - bool mNeedsGoToStart; + bool mNeedsCollectionsUpdate; bool mNeedsReloading; bool mNeedsSorting; bool mNeedsSortingCollections; + bool mNeedsGoToStart; + bool mNeedsGoToSystemView; + bool mNeedsDestroyAllWindows; + + SystemData* mGoToSystem; }; #endif // ES_APP_GUIS_GUI_SETTINGS_H diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 680e890a4..f546d3c8a 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -154,6 +154,9 @@ void ViewController::goToSystemView(SystemData* system) mCurrentView->setRenderView(false); } + if (system->isGroupedCustomCollection()) + system = system->getRootFolder()->getParent()->getSystem(); + mState.viewing = SYSTEM_SELECT; mState.system = system; diff --git a/es-core/src/components/MenuComponent.cpp b/es-core/src/components/MenuComponent.cpp index 957341f51..623f700a1 100644 --- a/es-core/src/components/MenuComponent.cpp +++ b/es-core/src/components/MenuComponent.cpp @@ -18,7 +18,7 @@ MenuComponent::MenuComponent( Window* window, - const char* title, + std::string title, const std::shared_ptr& titleFont) : GuiComponent(window), mBackground(window), @@ -66,7 +66,7 @@ void MenuComponent::save() } } -void MenuComponent::setTitle(const char* title, const std::shared_ptr& font) +void MenuComponent::setTitle(std::string title, const std::shared_ptr& font) { mTitle->setText(Utils::String::toUpper(title)); mTitle->setFont(font); diff --git a/es-core/src/components/MenuComponent.h b/es-core/src/components/MenuComponent.h index ae17e3f02..6a6639cc4 100644 --- a/es-core/src/components/MenuComponent.h +++ b/es-core/src/components/MenuComponent.h @@ -27,7 +27,7 @@ std::shared_ptr makeArrow(Window* window); class MenuComponent : public GuiComponent { public: - MenuComponent(Window* window, const char* title, + MenuComponent(Window* window, std::string title, const std::shared_ptr& titleFont = Font::get(FONT_SIZE_LARGE)); virtual ~MenuComponent(); // just calls save(); @@ -54,7 +54,7 @@ public: void addButton(const std::string& label, const std::string& helpText, const std::function& callback); - void setTitle(const char* title, const std::shared_ptr& font); + void setTitle(std::string title, const std::shared_ptr& font); inline void setCursorToList() { mGrid.setCursorTo(mList); } inline void setCursorToButtons() { assert(mButtonGrid); mGrid.setCursorTo(mButtonGrid); }