mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 23:55:38 +00:00
Split old, big settings into three submenus from the main menu.
Window now only draws the bottom and top of the GuiStack, instead of everything (hides windows-behind-windows and is faster).
This commit is contained in:
parent
bbb8aeeac3
commit
5039b38d8d
|
@ -155,6 +155,7 @@ set(ES_HEADERS
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Sound.h
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Sound.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/SystemData.h
|
${CMAKE_CURRENT_SOURCE_DIR}/src/SystemData.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ThemeData.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/VolumeControl.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Window.h
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Window.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/XMLReader.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/GuiGameScraper.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInputConfig.h
|
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInputConfig.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMenu.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/GuiScraperStart.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiScraperLog.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/GuiGameScraper.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInputConfig.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInputConfig.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMenu.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/GuiScraperStart.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiScraperLog.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiScraperLog.cpp
|
||||||
|
|
||||||
|
|
22
src/Util.h
Normal file
22
src/Util.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
|
@ -154,14 +154,29 @@ void Window::render()
|
||||||
{
|
{
|
||||||
Eigen::Affine3f transform = Eigen::Affine3f::Identity();
|
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++)
|
for(unsigned int i = 0; i < mGuiStack.size(); i++)
|
||||||
{
|
{
|
||||||
mGuiStack.at(i)->render(transform);
|
mGuiStack.at(i)->render(transform);
|
||||||
|
|
||||||
if(i == drawBGAfter)
|
if(i == drawBGAfter)
|
||||||
mBackgroundOverlay->render(transform);
|
mBackgroundOverlay->render(transform);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
mHelp->render(transform);
|
mHelp->render(transform);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "ButtonComponent.h"
|
#include "ButtonComponent.h"
|
||||||
#include "../Renderer.h"
|
#include "../Renderer.h"
|
||||||
#include "../Window.h"
|
#include "../Window.h"
|
||||||
|
#include "../Util.h"
|
||||||
|
|
||||||
ButtonComponent::ButtonComponent(Window* window, const std::string& text, const std::string& helpText, const std::function<void()>& func) : GuiComponent(window),
|
ButtonComponent::ButtonComponent(Window* window, const std::string& text, const std::string& helpText, const std::function<void()>& func) : GuiComponent(window),
|
||||||
mBox(window, ":/button.png"),
|
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)
|
void ButtonComponent::setText(const std::string& text, const std::string& helpText)
|
||||||
{
|
{
|
||||||
mText = text;
|
mText = strToUpper(text);
|
||||||
mHelpText = helpText;
|
mHelpText = helpText;
|
||||||
|
|
||||||
std::shared_ptr<Font> f = getFont();
|
std::shared_ptr<Font> f = getFont();
|
||||||
|
|
|
@ -57,6 +57,8 @@ public:
|
||||||
|
|
||||||
inline int getCursorId() const { return mCursor; }
|
inline int getCursorId() const { return mCursor; }
|
||||||
|
|
||||||
|
float getTotalRowHeight() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onCursorChanged(const CursorState& state) override;
|
void onCursorChanged(const CursorState& state) override;
|
||||||
|
|
||||||
|
@ -67,7 +69,6 @@ private:
|
||||||
void updateElementSize(const ComponentListRow& row);
|
void updateElementSize(const ComponentListRow& row);
|
||||||
|
|
||||||
float getRowHeight(const ComponentListRow& row) const;
|
float getRowHeight(const ComponentListRow& row) const;
|
||||||
float getTotalRowHeight() const;
|
|
||||||
|
|
||||||
float mSelectorBarOffset;
|
float mSelectorBarOffset;
|
||||||
float mCameraOffset;
|
float mCameraOffset;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "MenuComponent.h"
|
#include "MenuComponent.h"
|
||||||
#include "ButtonComponent.h"
|
#include "ButtonComponent.h"
|
||||||
|
|
||||||
|
#define BUTTON_GRID_HEIGHT ((float)Font::get(FONT_SIZE_MEDIUM)->getHeight() + 32)
|
||||||
|
|
||||||
using namespace Eigen;
|
using namespace Eigen;
|
||||||
|
|
||||||
MenuComponent::MenuComponent(Window* window, const char* title) : GuiComponent(window),
|
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");
|
mBackground.setImagePath(":/frame.png");
|
||||||
|
|
||||||
// set up title which will never change
|
// set up title which will never change
|
||||||
mTitle = std::make_shared<TextComponent>(mWindow, title, Font::get(FONT_SIZE_LARGE), 0x555555FF, true);
|
mTitle = std::make_shared<TextComponent>(mWindow, strToUpper(title), Font::get(FONT_SIZE_LARGE), 0x555555FF, true);
|
||||||
mGrid.setEntry(mTitle, Vector2i(0, 0), false);
|
mGrid.setEntry(mTitle, Vector2i(0, 0), false);
|
||||||
|
|
||||||
// set up list which will never change (externally, anyway)
|
// set up list which will never change (externally, anyway)
|
||||||
mList = std::make_shared<ComponentList>(mWindow);
|
mList = std::make_shared<ComponentList>(mWindow);
|
||||||
mGrid.setEntry(mList, Vector2i(0, 1), true);
|
mGrid.setEntry(mList, Vector2i(0, 1), true);
|
||||||
|
|
||||||
setSize(Renderer::getScreenWidth() * 0.5f, Renderer::getScreenHeight() * 0.75f);
|
|
||||||
updateGrid();
|
updateGrid();
|
||||||
|
updateSize();
|
||||||
|
|
||||||
mGrid.resetCursor();
|
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()
|
void MenuComponent::onSizeChanged()
|
||||||
{
|
{
|
||||||
mBackground.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32));
|
mBackground.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32));
|
||||||
|
|
||||||
// update grid row/col sizes
|
// update grid row/col sizes
|
||||||
mGrid.setRowHeightPerc(0, mTitle->getSize().y() / mSize.y());
|
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);
|
mGrid.setSize(mSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuComponent::addButton(const std::string& name, const std::string& helpText, const std::function<void()>& callback)
|
void MenuComponent::addButton(const std::string& name, const std::string& helpText, const std::function<void()>& callback)
|
||||||
{
|
{
|
||||||
mButtons.push_back(std::make_shared<ButtonComponent>(mWindow, name, helpText, callback));
|
mButtons.push_back(std::make_shared<ButtonComponent>(mWindow, strToUpper(name), helpText, callback));
|
||||||
updateGrid();
|
updateGrid();
|
||||||
onSizeChanged();
|
updateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuComponent::updateGrid()
|
void MenuComponent::updateGrid()
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "ComponentList.h"
|
#include "ComponentList.h"
|
||||||
#include "TextComponent.h"
|
#include "TextComponent.h"
|
||||||
#include "ComponentGrid.h"
|
#include "ComponentGrid.h"
|
||||||
|
#include "../Util.h"
|
||||||
|
|
||||||
class ButtonComponent;
|
class ButtonComponent;
|
||||||
|
|
||||||
|
@ -14,12 +15,12 @@ public:
|
||||||
|
|
||||||
void onSizeChanged() override;
|
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<GuiComponent>& comp, bool setCursorHere = false)
|
inline void addWithLabel(const std::string& label, const std::shared_ptr<GuiComponent>& comp, bool setCursorHere = false)
|
||||||
{
|
{
|
||||||
ComponentListRow row;
|
ComponentListRow row;
|
||||||
row.addElement(std::make_shared<TextComponent>(mWindow, label, Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
row.addElement(std::make_shared<TextComponent>(mWindow, strToUpper(label), Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
||||||
row.addElement(comp, false);
|
row.addElement(comp, false);
|
||||||
addRow(row, setCursorHere);
|
addRow(row, setCursorHere);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +31,7 @@ public:
|
||||||
inline void setCursorToButtons() { assert(mButtonGrid); mGrid.setCursorTo(mButtonGrid); }
|
inline void setCursorToButtons() { assert(mButtonGrid); mGrid.setCursorTo(mButtonGrid); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateSize();
|
||||||
void updateGrid();
|
void updateGrid();
|
||||||
|
|
||||||
NinePatchComponent mBackground;
|
NinePatchComponent mBackground;
|
||||||
|
|
|
@ -1,59 +1,173 @@
|
||||||
#include "GuiMenu.h"
|
#include "GuiMenu.h"
|
||||||
#include "GuiSettingsMenu.h"
|
|
||||||
#include "GuiScraperStart.h"
|
|
||||||
#include "../Window.h"
|
#include "../Window.h"
|
||||||
#include "../Sound.h"
|
#include "../Sound.h"
|
||||||
#include "../Log.h"
|
#include "../Log.h"
|
||||||
#include "GuiMsgBoxYesNo.h"
|
|
||||||
#include <initializer_list>
|
|
||||||
#include "../Settings.h"
|
#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<ImageComponent> makeBracket(Window* window)
|
||||||
|
{
|
||||||
|
auto bracket = std::make_shared<ImageComponent>(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")
|
GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MENU")
|
||||||
{
|
{
|
||||||
setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
||||||
mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, (mSize.y() - mMenu.getSize().y()) / 2);
|
|
||||||
|
|
||||||
// populate our list
|
// SCRAPER >
|
||||||
addEntry("GENERAL SETTINGS", 0x777777FF, true,
|
// SOUND SETTINGS >
|
||||||
[this] { mWindow->pushGui(new GuiSettingsMenu(mWindow)); }
|
// UI SETTINGS >
|
||||||
);
|
// QUIT >
|
||||||
|
|
||||||
addEntry("SCRAPE NOW", 0x777777FF, true,
|
auto openScrapeNow = [this] { mWindow->pushGui(new GuiScraperStart(mWindow)); };
|
||||||
[this] { mWindow->pushGui(new GuiScraperStart(mWindow)); }
|
addEntry("SCRAPER", 0x777777FF, true,
|
||||||
);
|
[this, openScrapeNow] {
|
||||||
|
auto s = new GuiSettings(mWindow, "SCRAPER");
|
||||||
|
|
||||||
addEntry("RESTART SYSTEM", 0x990000FF, false,
|
// scrape from
|
||||||
|
auto scraper_list = std::make_shared< OptionListComponent< std::shared_ptr<Scraper> > >(mWindow, false);
|
||||||
|
std::vector< std::shared_ptr<Scraper> > scrapers;
|
||||||
|
scrapers.push_back(std::make_shared<GamesDBScraper>());
|
||||||
|
scrapers.push_back(std::make_shared<TheArchiveScraper>());
|
||||||
|
|
||||||
|
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<SwitchComponent>(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<void()> openAndSave = openScrapeNow;
|
||||||
|
openAndSave = [s, openAndSave] { s->save(); openAndSave(); };
|
||||||
|
row.makeAcceptInputHandler(openAndSave);
|
||||||
|
|
||||||
|
auto scrape_now = std::make_shared<TextComponent>(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] {
|
[this] {
|
||||||
mWindow->pushGui(new GuiMsgBoxYesNo(mWindow, "Do you really want to restart the system?",
|
auto s = new GuiSettings(mWindow, "SOUND SETTINGS");
|
||||||
[] {
|
|
||||||
if(system("sudo shutdown -r now") != 0)
|
|
||||||
LOG(LogWarning) << "Restart terminated with non-zero result!";
|
|
||||||
})
|
|
||||||
);}
|
|
||||||
);
|
|
||||||
|
|
||||||
addEntry("SHUTDOWN SYSTEM", 0x990000FF, false,
|
// volume
|
||||||
|
auto volume = std::make_shared<SliderComponent>(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<SwitchComponent>(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] {
|
[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<SliderComponent>(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<SwitchComponent>(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<SwitchComponent>(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<TextComponent>(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)
|
if(system("sudo shutdown -h now") != 0)
|
||||||
LOG(LogWarning) << "Shutdown terminated with non-zero result!";
|
LOG(LogWarning) << "Shutdown terminated with non-zero result!";
|
||||||
}));
|
}));
|
||||||
}
|
});
|
||||||
);
|
row.addElement(std::make_shared<TextComponent>(window, "SHUTDOWN SYSTEM", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
||||||
|
s->addRow(row);
|
||||||
|
|
||||||
if(Settings::getInstance()->getBool("ShowExit"))
|
if(Settings::getInstance()->getBool("ShowExit"))
|
||||||
{
|
{
|
||||||
addEntry("EXIT EMULATIONSTATION", 0x990000FF, false,
|
row.elements.clear();
|
||||||
[] {
|
row.makeAcceptInputHandler([window] {
|
||||||
SDL_Event ev;
|
window->pushGui(new GuiMsgBoxYesNo(window, "REALLY EXIT?",
|
||||||
ev.type = SDL_QUIT;
|
[] {
|
||||||
SDL_PushEvent(&ev);
|
SDL_Event ev;
|
||||||
|
ev.type = SDL_QUIT;
|
||||||
|
SDL_PushEvent(&ev);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
row.addElement(std::make_shared<TextComponent>(window, "EXIT EMULATIONSTATION", Font::get(FONT_SIZE_MEDIUM), 0x770000FF), true);
|
||||||
|
s->addRow(row);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
mWindow->pushGui(s);
|
||||||
|
});
|
||||||
|
|
||||||
addChild(&mMenu);
|
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<void()>& func)
|
void GuiMenu::addEntry(const char* name, unsigned int color, bool add_arrow, const std::function<void()>& func)
|
||||||
|
@ -66,11 +180,7 @@ void GuiMenu::addEntry(const char* name, unsigned int color, bool add_arrow, con
|
||||||
|
|
||||||
if(add_arrow)
|
if(add_arrow)
|
||||||
{
|
{
|
||||||
std::shared_ptr<ImageComponent> bracket = std::make_shared<ImageComponent>(mWindow);
|
std::shared_ptr<ImageComponent> bracket = makeBracket(mWindow);
|
||||||
bracket->setImage(":/sq_bracket.png");
|
|
||||||
if(bracket->getTextureSize().y() > font->getHeight())
|
|
||||||
bracket->setResize(0, (float)font->getHeight());
|
|
||||||
|
|
||||||
row.addElement(bracket, false);
|
row.addElement(bracket, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector
|
||||||
mMenu.setCursorToButtons();
|
mMenu.setCursorToButtons();
|
||||||
|
|
||||||
// position menu
|
// 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()
|
void GuiMetaDataEd::save()
|
||||||
|
|
|
@ -35,7 +35,7 @@ GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window),
|
||||||
row.makeAcceptInputHandler(std::bind(&GuiScraperStart::pressedStart, this));
|
row.makeAcceptInputHandler(std::bind(&GuiScraperStart::pressedStart, this));
|
||||||
mMenu.addRow(row);
|
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()
|
void GuiScraperStart::pressedStart()
|
||||||
|
|
42
src/guis/GuiSettings.cpp
Normal file
42
src/guis/GuiSettings.cpp
Normal file
|
@ -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<HelpPrompt> GuiSettings::getHelpPrompts()
|
||||||
|
{
|
||||||
|
return mMenu.getHelpPrompts();
|
||||||
|
}
|
22
src/guis/GuiSettings.h
Normal file
22
src/guis/GuiSettings.h
Normal file
|
@ -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<GuiComponent>& comp) { mMenu.addWithLabel(label, comp); };
|
||||||
|
inline void addSaveFunc(const std::function<void()>& func) { mSaveFuncs.push_back(func); };
|
||||||
|
|
||||||
|
bool input(InputConfig* config, Input input) override;
|
||||||
|
std::vector<HelpPrompt> getHelpPrompts() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
MenuComponent mMenu;
|
||||||
|
std::vector< std::function<void()> > mSaveFuncs;
|
||||||
|
};
|
|
@ -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<SwitchComponent>(mWindow);
|
|
||||||
framerate->setState(s->getBool("DrawFramerate"));
|
|
||||||
addSetting("Draw framerate:", framerate,
|
|
||||||
[framerate] { Settings::getInstance()->setBool("DrawFramerate", framerate->getState()); });
|
|
||||||
|
|
||||||
// volume
|
|
||||||
auto volume = std::make_shared<SliderComponent>(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<SwitchComponent>(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<Scraper> > >(mWindow, false);
|
|
||||||
std::vector< std::shared_ptr<Scraper> > scrapers;
|
|
||||||
scrapers.push_back(std::make_shared<GamesDBScraper>());
|
|
||||||
scrapers.push_back(std::make_shared<TheArchiveScraper>());
|
|
||||||
|
|
||||||
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<SwitchComponent>(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<SliderComponent>(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<SwitchComponent>(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<TextComponent>(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<GuiComponent>& comp, const std::function<void()>& saveFunc)
|
|
||||||
{
|
|
||||||
ComponentListRow row;
|
|
||||||
row.addElement(std::make_shared<TextComponent>(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<HelpPrompt> GuiSettingsMenu::getHelpPrompts()
|
|
||||||
{
|
|
||||||
std::vector<HelpPrompt> prompts = mMenu.getHelpPrompts();
|
|
||||||
prompts.push_back(HelpPrompt("b", "discard changes"));
|
|
||||||
return prompts;
|
|
||||||
}
|
|
|
@ -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<HelpPrompt> getHelpPrompts() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void addSetting(const char* label, const std::shared_ptr<GuiComponent>& comp, const std::function<void()>& saveFunc);
|
|
||||||
void save();
|
|
||||||
|
|
||||||
std::vector< std::function<void()> > mApplyFuncs;
|
|
||||||
|
|
||||||
MenuComponent mMenu;
|
|
||||||
};
|
|
Loading…
Reference in a new issue