diff --git a/CMakeLists.txt b/CMakeLists.txt index 241b4cbb9..61bdad719 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,6 +155,7 @@ set(ES_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/Sound.h ${CMAKE_CURRENT_SOURCE_DIR}/src/SystemData.h ${CMAKE_CURRENT_SOURCE_DIR}/src/ThemeData.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/Util.h ${CMAKE_CURRENT_SOURCE_DIR}/src/VolumeControl.h ${CMAKE_CURRENT_SOURCE_DIR}/src/Window.h ${CMAKE_CURRENT_SOURCE_DIR}/src/XMLReader.h @@ -188,7 +189,7 @@ set(ES_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiGameScraper.h ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInputConfig.h ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMenu.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiSettingsMenu.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiSettings.h ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiScraperStart.h ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiScraperLog.h @@ -268,7 +269,7 @@ set(ES_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiGameScraper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInputConfig.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMenu.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiSettingsMenu.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiSettings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiScraperStart.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiScraperLog.cpp diff --git a/src/Util.h b/src/Util.h new file mode 100644 index 000000000..cd406d911 --- /dev/null +++ b/src/Util.h @@ -0,0 +1,22 @@ +#include + +inline std::string strToUpper(const char* from) +{ + std::string str(from); + for(unsigned int i = 0; i < str.size(); i++) + str[i] = toupper(from[i]); + return str; +} + +inline std::string& strToUpper(std::string& str) +{ + for(unsigned int i = 0; i < str.size(); i++) + str[i] = toupper(str[i]); + + return str; +} + +inline std::string strToUpper(const std::string& str) +{ + return strToUpper(str.c_str()); +} \ No newline at end of file diff --git a/src/Window.cpp b/src/Window.cpp index 04ec0f2b5..c735e8cda 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -154,14 +154,29 @@ void Window::render() { Eigen::Affine3f transform = Eigen::Affine3f::Identity(); - const unsigned int drawBGAfter = mGuiStack.size() > 1 ? mGuiStack.size() - 2 : mGuiStack.size(); + // draw only bottom and top of GuiStack (if they are different) + if(mGuiStack.size()) + { + auto& bottom = mGuiStack.front(); + auto& top = mGuiStack.back(); + + bottom->render(transform); + if(bottom != top) + { + mBackgroundOverlay->render(transform); + top->render(transform); + } + } + + // draw everything + /*const unsigned int drawBGAfter = mGuiStack.size() > 1 ? mGuiStack.size() - 2 : mGuiStack.size(); for(unsigned int i = 0; i < mGuiStack.size(); i++) { mGuiStack.at(i)->render(transform); - + if(i == drawBGAfter) mBackgroundOverlay->render(transform); - } + }*/ mHelp->render(transform); diff --git a/src/components/ButtonComponent.cpp b/src/components/ButtonComponent.cpp index a0d18b463..02b1d7042 100644 --- a/src/components/ButtonComponent.cpp +++ b/src/components/ButtonComponent.cpp @@ -1,6 +1,7 @@ #include "ButtonComponent.h" #include "../Renderer.h" #include "../Window.h" +#include "../Util.h" ButtonComponent::ButtonComponent(Window* window, const std::string& text, const std::string& helpText, const std::function& func) : GuiComponent(window), mBox(window, ":/button.png"), @@ -36,7 +37,7 @@ bool ButtonComponent::input(InputConfig* config, Input input) void ButtonComponent::setText(const std::string& text, const std::string& helpText) { - mText = text; + mText = strToUpper(text); mHelpText = helpText; std::shared_ptr f = getFont(); diff --git a/src/components/ComponentList.h b/src/components/ComponentList.h index d4d58c651..23dad2f32 100644 --- a/src/components/ComponentList.h +++ b/src/components/ComponentList.h @@ -57,6 +57,8 @@ public: inline int getCursorId() const { return mCursor; } + float getTotalRowHeight() const; + protected: void onCursorChanged(const CursorState& state) override; @@ -67,8 +69,7 @@ private: void updateElementSize(const ComponentListRow& row); float getRowHeight(const ComponentListRow& row) const; - float getTotalRowHeight() const; - + float mSelectorBarOffset; float mCameraOffset; }; diff --git a/src/components/MenuComponent.cpp b/src/components/MenuComponent.cpp index 98aef7954..fa053d648 100644 --- a/src/components/MenuComponent.cpp +++ b/src/components/MenuComponent.cpp @@ -1,6 +1,8 @@ #include "MenuComponent.h" #include "ButtonComponent.h" +#define BUTTON_GRID_HEIGHT ((float)Font::get(FONT_SIZE_MEDIUM)->getHeight() + 32) + using namespace Eigen; MenuComponent::MenuComponent(Window* window, const char* title) : GuiComponent(window), @@ -12,34 +14,44 @@ MenuComponent::MenuComponent(Window* window, const char* title) : GuiComponent(w mBackground.setImagePath(":/frame.png"); // set up title which will never change - mTitle = std::make_shared(mWindow, title, Font::get(FONT_SIZE_LARGE), 0x555555FF, true); + mTitle = std::make_shared(mWindow, strToUpper(title), Font::get(FONT_SIZE_LARGE), 0x555555FF, true); mGrid.setEntry(mTitle, Vector2i(0, 0), false); // set up list which will never change (externally, anyway) mList = std::make_shared(mWindow); mGrid.setEntry(mList, Vector2i(0, 1), true); - setSize(Renderer::getScreenWidth() * 0.5f, Renderer::getScreenHeight() * 0.75f); updateGrid(); + updateSize(); + mGrid.resetCursor(); } +void MenuComponent::updateSize() +{ + float height = mTitle->getSize().y() + mList->getTotalRowHeight() + BUTTON_GRID_HEIGHT + 2; + if(height > Renderer::getScreenHeight() * 0.7f) + height = Renderer::getScreenHeight() * 0.7f; + + setSize(Renderer::getScreenWidth() * 0.4f, height); +} + void MenuComponent::onSizeChanged() { mBackground.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32)); // update grid row/col sizes mGrid.setRowHeightPerc(0, mTitle->getSize().y() / mSize.y()); - mGrid.setRowHeightPerc(2, mButtonGrid ? (mButtonGrid->getSize().y() + 32) / mSize.y() : 0.07f); + mGrid.setRowHeightPerc(2, (BUTTON_GRID_HEIGHT) / mSize.y()); mGrid.setSize(mSize); } void MenuComponent::addButton(const std::string& name, const std::string& helpText, const std::function& callback) { - mButtons.push_back(std::make_shared(mWindow, name, helpText, callback)); + mButtons.push_back(std::make_shared(mWindow, strToUpper(name), helpText, callback)); updateGrid(); - onSizeChanged(); + updateSize(); } void MenuComponent::updateGrid() diff --git a/src/components/MenuComponent.h b/src/components/MenuComponent.h index 98a0a54fb..937515c47 100644 --- a/src/components/MenuComponent.h +++ b/src/components/MenuComponent.h @@ -4,6 +4,7 @@ #include "ComponentList.h" #include "TextComponent.h" #include "ComponentGrid.h" +#include "../Util.h" class ButtonComponent; @@ -14,12 +15,12 @@ public: void onSizeChanged() override; - inline void addRow(const ComponentListRow& row, bool setCursorHere = false) { mList->addRow(row, setCursorHere); } + inline void addRow(const ComponentListRow& row, bool setCursorHere = false) { mList->addRow(row, setCursorHere); updateSize(); } inline void addWithLabel(const std::string& label, const std::shared_ptr& comp, bool setCursorHere = false) { ComponentListRow row; - row.addElement(std::make_shared(mWindow, label, Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); + row.addElement(std::make_shared(mWindow, strToUpper(label), Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); row.addElement(comp, false); addRow(row, setCursorHere); } @@ -30,6 +31,7 @@ public: inline void setCursorToButtons() { assert(mButtonGrid); mGrid.setCursorTo(mButtonGrid); } private: + void updateSize(); void updateGrid(); NinePatchComponent mBackground; diff --git a/src/guis/GuiMenu.cpp b/src/guis/GuiMenu.cpp index 4a91fe767..35271ef4e 100644 --- a/src/guis/GuiMenu.cpp +++ b/src/guis/GuiMenu.cpp @@ -1,59 +1,173 @@ #include "GuiMenu.h" -#include "GuiSettingsMenu.h" -#include "GuiScraperStart.h" #include "../Window.h" #include "../Sound.h" #include "../Log.h" -#include "GuiMsgBoxYesNo.h" -#include #include "../Settings.h" +#include "GuiMsgBoxYesNo.h" +#include "GuiSettings.h" +#include "GuiScraperStart.h" + +#include "../components/ButtonComponent.h" +#include "../components/SwitchComponent.h" +#include "../components/SliderComponent.h" +#include "../components/TextComponent.h" +#include "../components/OptionListComponent.h" +#include "../VolumeControl.h" +#include "../scrapers/GamesDBScraper.h" +#include "../scrapers/TheArchiveScraper.h" + +std::shared_ptr makeBracket(Window* window) +{ + auto bracket = std::make_shared(window); + bracket->setImage(":/sq_bracket.png"); + + // resize + const float fontHeight = (float)Font::get(FONT_SIZE_MEDIUM)->getHeight(); + if(bracket->getTextureSize().y() > fontHeight) + bracket->setResize(0, fontHeight); + + return bracket; +} GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MENU") { setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); - mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, (mSize.y() - mMenu.getSize().y()) / 2); - // populate our list - addEntry("GENERAL SETTINGS", 0x777777FF, true, - [this] { mWindow->pushGui(new GuiSettingsMenu(mWindow)); } - ); + // SCRAPER > + // SOUND SETTINGS > + // UI SETTINGS > + // QUIT > + + auto openScrapeNow = [this] { mWindow->pushGui(new GuiScraperStart(mWindow)); }; + addEntry("SCRAPER", 0x777777FF, true, + [this, openScrapeNow] { + auto s = new GuiSettings(mWindow, "SCRAPER"); - addEntry("SCRAPE NOW", 0x777777FF, true, - [this] { mWindow->pushGui(new GuiScraperStart(mWindow)); } - ); + // scrape from + auto scraper_list = std::make_shared< OptionListComponent< std::shared_ptr > >(mWindow, false); + std::vector< std::shared_ptr > scrapers; + scrapers.push_back(std::make_shared()); + scrapers.push_back(std::make_shared()); - addEntry("RESTART SYSTEM", 0x990000FF, false, + for(auto it = scrapers.begin(); it != scrapers.end(); it++) + scraper_list->add((*it)->getName(), *it, (*it)->getName() == Settings::getInstance()->getScraper()->getName()); + + s->addWithLabel("SCRAPE FROM", scraper_list); + s->addSaveFunc([scraper_list] { Settings::getInstance()->setScraper(scraper_list->getSelected()); }); + + // scrape ratings + auto scrape_ratings = std::make_shared(mWindow); + scrape_ratings->setState(Settings::getInstance()->getBool("ScrapeRatings")); + s->addWithLabel("SCRAPE RATINGS", scrape_ratings); + s->addSaveFunc([scrape_ratings] { Settings::getInstance()->setBool("ScrapeRatings", scrape_ratings->getState()); }); + + // scrape now + ComponentListRow row; + std::function openAndSave = openScrapeNow; + openAndSave = [s, openAndSave] { s->save(); openAndSave(); }; + row.makeAcceptInputHandler(openAndSave); + + auto scrape_now = std::make_shared(mWindow, "SCRAPE NOW", Font::get(FONT_SIZE_MEDIUM), 0x777777FF); + auto bracket = makeBracket(mWindow); + row.addElement(scrape_now, true); + row.addElement(bracket, false); + s->addRow(row); + + mWindow->pushGui(s); + }); + + addEntry("SOUND SETTINGS", 0x777777FF, true, [this] { - mWindow->pushGui(new GuiMsgBoxYesNo(mWindow, "Do you really want to restart the system?", - [] { - if(system("sudo shutdown -r now") != 0) - LOG(LogWarning) << "Restart terminated with non-zero result!"; - }) - );} - ); + auto s = new GuiSettings(mWindow, "SOUND SETTINGS"); - addEntry("SHUTDOWN SYSTEM", 0x990000FF, false, + // volume + auto volume = std::make_shared(mWindow, 0.f, 100.f, 1.f, "%"); + volume->setValue((float)VolumeControl::getInstance()->getVolume()); + s->addWithLabel("SYSTEM VOLUME", volume); + s->addSaveFunc([volume] { VolumeControl::getInstance()->setVolume((int)volume->getValue()); }); + + // disable sounds + auto sounds_enabled = std::make_shared(mWindow); + sounds_enabled->setState(Settings::getInstance()->getBool("EnableSounds")); + s->addWithLabel("ENABLE SOUNDS", sounds_enabled); + s->addSaveFunc([sounds_enabled] { Settings::getInstance()->setBool("EnableSounds", sounds_enabled->getState()); }); + + mWindow->pushGui(s); + }); + + addEntry("UI SETTINGS", 0x777777FF, true, [this] { - mWindow->pushGui(new GuiMsgBoxYesNo(mWindow, "Do you really want to shutdown the system?", + auto s = new GuiSettings(mWindow, "UI SETTINGS"); + + // dim time + auto dim_time = std::make_shared(mWindow, 0.f, 1200.f, 30.f, "s"); + dim_time->setValue((float)(Settings::getInstance()->getInt("DimTime") / 1000)); + s->addWithLabel("DIM SCREEN AFTER", dim_time); + s->addSaveFunc([dim_time] { Settings::getInstance()->setInt("DimTime", (int)(dim_time->getValue() * 1000)); }); + + // framerate + auto framerate = std::make_shared(mWindow); + framerate->setState(Settings::getInstance()->getBool("DrawFramerate")); + s->addWithLabel("SHOW FRAMERATE", framerate); + s->addSaveFunc([framerate] { Settings::getInstance()->setBool("DrawFramerate", framerate->getState()); }); + + // show help + auto show_help = std::make_shared(mWindow); + show_help->setState(Settings::getInstance()->getBool("ShowHelpPrompts")); + s->addWithLabel("ON-SCREEN HELP", show_help); + s->addSaveFunc([show_help] { Settings::getInstance()->setBool("ShowHelpPrompts", show_help->getState()); }); + + mWindow->pushGui(s); + }); + + addEntry("QUIT", 0x777777FF, true, + [this] { + auto s = new GuiSettings(mWindow, "QUIT"); + + Window* window = mWindow; + + ComponentListRow row; + row.makeAcceptInputHandler([window] { + window->pushGui(new GuiMsgBoxYesNo(window, "REALLY RESTART?", + [] { + if(system("sudo shutdown -r now") != 0) + LOG(LogWarning) << "Restart terminated with non-zero result!"; + })); + }); + row.addElement(std::make_shared(window, "RESTART SYSTEM", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); + s->addRow(row); + + row.elements.clear(); + row.makeAcceptInputHandler([window] { + window->pushGui(new GuiMsgBoxYesNo(window, "REALLY SHUTDOWN?", [] { if(system("sudo shutdown -h now") != 0) LOG(LogWarning) << "Shutdown terminated with non-zero result!"; })); - } - ); + }); + row.addElement(std::make_shared(window, "SHUTDOWN SYSTEM", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); + s->addRow(row); - if(Settings::getInstance()->getBool("ShowExit")) - { - addEntry("EXIT EMULATIONSTATION", 0x990000FF, false, - [] { - SDL_Event ev; - ev.type = SDL_QUIT; - SDL_PushEvent(&ev); + if(Settings::getInstance()->getBool("ShowExit")) + { + row.elements.clear(); + row.makeAcceptInputHandler([window] { + window->pushGui(new GuiMsgBoxYesNo(window, "REALLY EXIT?", + [] { + SDL_Event ev; + ev.type = SDL_QUIT; + SDL_PushEvent(&ev); + })); + }); + row.addElement(std::make_shared(window, "EXIT EMULATIONSTATION", Font::get(FONT_SIZE_MEDIUM), 0x770000FF), true); + s->addRow(row); } - ); - } - + + mWindow->pushGui(s); + }); + addChild(&mMenu); + mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f); } void GuiMenu::addEntry(const char* name, unsigned int color, bool add_arrow, const std::function& func) @@ -66,11 +180,7 @@ void GuiMenu::addEntry(const char* name, unsigned int color, bool add_arrow, con if(add_arrow) { - std::shared_ptr bracket = std::make_shared(mWindow); - bracket->setImage(":/sq_bracket.png"); - if(bracket->getTextureSize().y() > font->getHeight()) - bracket->setResize(0, (float)font->getHeight()); - + std::shared_ptr bracket = makeBracket(mWindow); row.addElement(bracket, false); } diff --git a/src/guis/GuiMetaDataEd.cpp b/src/guis/GuiMetaDataEd.cpp index a99758b79..451064414 100644 --- a/src/guis/GuiMetaDataEd.cpp +++ b/src/guis/GuiMetaDataEd.cpp @@ -43,7 +43,7 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector mMenu.setCursorToButtons(); // position menu - mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, (mSize.y() - mMenu.getSize().y()) / 2); //center it + mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f); //center it } void GuiMetaDataEd::save() diff --git a/src/guis/GuiScraperStart.cpp b/src/guis/GuiScraperStart.cpp index 99e572173..a12e6f091 100644 --- a/src/guis/GuiScraperStart.cpp +++ b/src/guis/GuiScraperStart.cpp @@ -35,7 +35,7 @@ GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window), row.makeAcceptInputHandler(std::bind(&GuiScraperStart::pressedStart, this)); mMenu.addRow(row); - mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, (Renderer::getScreenHeight() - mMenu.getSize().y()) / 2); + mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f); } void GuiScraperStart::pressedStart() diff --git a/src/guis/GuiSettings.cpp b/src/guis/GuiSettings.cpp new file mode 100644 index 000000000..1b4416e71 --- /dev/null +++ b/src/guis/GuiSettings.cpp @@ -0,0 +1,42 @@ +#include "GuiSettings.h" +#include "../Settings.h" + +GuiSettings::GuiSettings(Window* window, const char* title) : GuiComponent(window), mMenu(window, title) +{ + addChild(&mMenu); + + setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); + mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f); +} + +GuiSettings::~GuiSettings() +{ + save(); +} + +void GuiSettings::save() +{ + if(!mSaveFuncs.size()) + return; + + for(auto it = mSaveFuncs.begin(); it != mSaveFuncs.end(); it++) + (*it)(); + + Settings::getInstance()->saveFile(); +} + +bool GuiSettings::input(InputConfig* config, Input input) +{ + if(config->isMappedTo("b", input) && input.value != 0) + { + delete this; + return true; + } + + return GuiComponent::input(config, input); +} + +std::vector GuiSettings::getHelpPrompts() +{ + return mMenu.getHelpPrompts(); +} diff --git a/src/guis/GuiSettings.h b/src/guis/GuiSettings.h new file mode 100644 index 000000000..f0f31dd1a --- /dev/null +++ b/src/guis/GuiSettings.h @@ -0,0 +1,22 @@ +#include "../GuiComponent.h" +#include "../components/MenuComponent.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); + virtual ~GuiSettings(); // just calls save(); + + void save(); + inline void addRow(const ComponentListRow& row) { mMenu.addRow(row); }; + inline void addWithLabel(const std::string& label, const std::shared_ptr& comp) { mMenu.addWithLabel(label, comp); }; + inline void addSaveFunc(const std::function& func) { mSaveFuncs.push_back(func); }; + + bool input(InputConfig* config, Input input) override; + std::vector getHelpPrompts() override; + +private: + MenuComponent mMenu; + std::vector< std::function > mSaveFuncs; +}; \ No newline at end of file diff --git a/src/guis/GuiSettingsMenu.cpp b/src/guis/GuiSettingsMenu.cpp deleted file mode 100644 index 71903ab0a..000000000 --- a/src/guis/GuiSettingsMenu.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include "GuiSettingsMenu.h" -#include "../Renderer.h" -#include "../Settings.h" -#include "../VolumeControl.h" -#include "../Log.h" -#include "../scrapers/TheArchiveScraper.h" -#include "../scrapers/GamesDBScraper.h" - -GuiSettingsMenu::GuiSettingsMenu(Window* window) : GuiComponent(window), - mMenu(mWindow, "SETTINGS") -{ - setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); - - // center menu - mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, (mSize.y() - mMenu.getSize().y()) / 2); - - using namespace Eigen; - - Settings* s = Settings::getInstance(); - - // framerate - auto framerate = std::make_shared(mWindow); - framerate->setState(s->getBool("DrawFramerate")); - addSetting("Draw framerate:", framerate, - [framerate] { Settings::getInstance()->setBool("DrawFramerate", framerate->getState()); }); - - // volume - auto volume = std::make_shared(mWindow, 0.f, 100.f, 1.f, "%"); - volume->setValue((float)VolumeControl::getInstance()->getVolume()); - addSetting("System volume:", volume, - [volume] { VolumeControl::getInstance()->setVolume((int)volume->getValue()); }); - - // disable sounds - auto sound_disable = std::make_shared(mWindow); - sound_disable->setState(s->getBool("EnableSounds")); - addSetting("Enable sounds:", sound_disable, - [sound_disable] { Settings::getInstance()->setBool("EnableSounds", sound_disable->getState()); }); - - // scraper - auto scraper_list = std::make_shared< OptionListComponent< std::shared_ptr > >(mWindow, false); - std::vector< std::shared_ptr > scrapers; - scrapers.push_back(std::make_shared()); - scrapers.push_back(std::make_shared()); - - for(auto it = scrapers.begin(); it != scrapers.end(); it++) - scraper_list->add((*it)->getName(), *it, (*it)->getName() == Settings::getInstance()->getScraper()->getName()); - - addSetting("Scraper:", scraper_list, - [scraper_list] { - Settings::getInstance()->setScraper(scraper_list->getSelected()); - }); - - // scrape ratings - auto scrape_ratings = std::make_shared(mWindow); - scrape_ratings->setState(s->getBool("ScrapeRatings")); - addSetting("Scrape ratings:", scrape_ratings, - [scrape_ratings] { Settings::getInstance()->setBool("ScrapeRatings", scrape_ratings->getState()); }); - - // dim time - auto dim_time = std::make_shared(mWindow, 0.f, 1200.f, 30.f, "s"); - dim_time->setValue((float)(s->getInt("DimTime") / 1000)); - addSetting("Dim screen after:", dim_time, - [dim_time] { Settings::getInstance()->setInt("DimTime", (int)(dim_time->getValue() * 1000)); }); - - // disable help - auto disable_help = std::make_shared(mWindow); - disable_help->setState(s->getBool("ShowHelpPrompts")); - addSetting("Show help:", disable_help, - [disable_help] { Settings::getInstance()->setBool("ShowHelpPrompts", disable_help->getState()); }); - - // save button - ComponentListRow row; - row.addElement(std::make_shared(mWindow, "SAVE", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); - row.makeAcceptInputHandler(std::bind(&GuiSettingsMenu::save, this)); - mMenu.addRow(row); - - addChild(&mMenu); -} - -void GuiSettingsMenu::addSetting(const char* label, const std::shared_ptr& comp, const std::function& saveFunc) -{ - ComponentListRow row; - row.addElement(std::make_shared(mWindow, label, Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); - row.addElement(comp, false); - mApplyFuncs.push_back(saveFunc); - mMenu.addRow(row); -} - -bool GuiSettingsMenu::input(InputConfig* config, Input input) -{ - //let our children (read: list) go first - if(GuiComponent::input(config, input)) - return true; - - //cancel if b is pressed - if(config->isMappedTo("b", input) && input.value != 0) - { - delete this; - return true; - } - - return false; -} - -void GuiSettingsMenu::save() -{ - LOG(LogInfo) << "saving"; - - for(auto it = mApplyFuncs.begin(); it != mApplyFuncs.end(); it++) - (*it)(); - - Settings::getInstance()->saveFile(); - - delete this; -} - -std::vector GuiSettingsMenu::getHelpPrompts() -{ - std::vector prompts = mMenu.getHelpPrompts(); - prompts.push_back(HelpPrompt("b", "discard changes")); - return prompts; -} diff --git a/src/guis/GuiSettingsMenu.h b/src/guis/GuiSettingsMenu.h deleted file mode 100644 index 6f542dd75..000000000 --- a/src/guis/GuiSettingsMenu.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "../GuiComponent.h" -#include "../components/MenuComponent.h" -#include "../components/SwitchComponent.h" -#include "../components/SliderComponent.h" -#include "../components/TextComponent.h" -#include "../components/NinePatchComponent.h" -#include "../components/OptionListComponent.h" -#include "../components/ButtonComponent.h" -#include "../scrapers/Scraper.h" - -class GuiSettingsMenu : public GuiComponent -{ -public: - GuiSettingsMenu(Window* window); - - bool input(InputConfig* config, Input input) override; - - std::vector getHelpPrompts() override; - -private: - void addSetting(const char* label, const std::shared_ptr& comp, const std::function& saveFunc); - void save(); - - std::vector< std::function > mApplyFuncs; - - MenuComponent mMenu; -};