From 94ca712759531e12c8045671db27ea3b8a2f533a Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 23 Nov 2013 14:04:11 -0600 Subject: [PATCH] Redid GuiMenu. --- CMakeLists.txt | 2 + src/ThemeData.h | 4 ++ src/components/GuiMenu.cpp | 68 +++++++++++++++++++++++++++++ src/components/GuiMenu.h | 18 ++++++++ src/components/NinePatchComponent.h | 2 +- src/views/GameListView.cpp | 4 +- 6 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 src/components/GuiMenu.cpp create mode 100644 src/components/GuiMenu.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d2f7ce5c6..c287b8781 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,6 +179,7 @@ set(ES_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiMsgBoxYesNo.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiGameScraper.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiInputConfig.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiMenu.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiSettingsMenu.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiScraperStart.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiScraperLog.h @@ -243,6 +244,7 @@ set(ES_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiMsgBoxYesNo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiGameScraper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiInputConfig.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiMenu.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiSettingsMenu.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiScraperStart.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiScraperLog.cpp diff --git a/src/ThemeData.h b/src/ThemeData.h index ea4222801..572e6c63e 100644 --- a/src/ThemeData.h +++ b/src/ThemeData.h @@ -60,11 +60,15 @@ public: void setDefaults(); void loadFile(const std::string& path); + inline const FontDef& getFontDef(const std::string& identifier) const { return mFontMap.at(identifier); } inline std::shared_ptr getFont(const std::string& identifier) const { return mFontMap.at(identifier).get(); } inline const ImageDef& getImage(const std::string& identifier) const { return mImageMap.at(identifier); } inline unsigned int getColor(const std::string& identifier) const { return mColorMap.at(identifier); } void playSound(const std::string& identifier) const; + inline void setFont(const std::string& identifier, FontDef def) { mFontMap[identifier] = def; } + inline void setColor(const std::string& identifier, unsigned int color) { mColorMap[identifier] = color; } + private: static std::map sDefaultImages; static std::map sDefaultColors; diff --git a/src/components/GuiMenu.cpp b/src/components/GuiMenu.cpp new file mode 100644 index 000000000..653c745fc --- /dev/null +++ b/src/components/GuiMenu.cpp @@ -0,0 +1,68 @@ +#include "GuiMenu.h" +#include "GuiSettingsMenu.h" +#include "GuiScraperStart.h" +#include "../Window.h" + +GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mBackground(window, ":/button.png"), mList(window) +{ + mList.add("Settings", [&] { + mWindow->pushGui(new GuiSettingsMenu(mWindow)); + }, 0); + + mList.add("Scrape Systems", [&] { + mWindow->pushGui(new GuiScraperStart(mWindow)); + }, 0); + + mList.add("Restart", [] { + if(system("sudo shutdown -r now") != 0) + LOG(LogWarning) << "Restart terminated with non-zero result!"; + }, 0); + + mList.add("Shutdown", [] { + if(system("sudo shutdown -h now") != 0) + LOG(LogWarning) << "Shutdown terminated with non-zero result!"; + }, 1); + + mList.add("Exit", [] { + SDL_Event* ev = new SDL_Event(); + ev->type = SDL_QUIT; + SDL_PushEvent(ev); + }, 0); + + + setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); + + mList.setPosition(mSize.x() * 0.175f, mSize.y() * 0.05f); + mList.setSize(mSize.x() * 0.65f, mSize.y() * 0.9f); + + mBackground.fitTo(Eigen::Vector2f(mList.getSize().x(), mSize.y()), Eigen::Vector3f(mList.getPosition().x(), 0, 0)); + addChild(&mBackground); + + std::shared_ptr theme = std::make_shared(); + theme->setFont("listFont", FontDef(0.09f, theme->getFontDef("listFont").path)); + theme->setColor("listSelectorColor", 0xBBBBBBFF); + theme->setColor("listPrimaryColor", 0x0000FFFF); + theme->setColor("listSecondaryColor", 0xFF0000FF); + mList.setTheme(theme); + + addChild(&mList); +} + +bool GuiMenu::input(InputConfig* config, Input input) +{ + if(input.value != 0) + { + if(config->isMappedTo("b", input) || config->isMappedTo("menu", input)) + { + delete this; + return true; + }else if(config->isMappedTo("a", input) && mList.getList().size() > 0) + { + mList.getSelected()(); + delete this; + return true; + } + } + + return GuiComponent::input(config, input); +} diff --git a/src/components/GuiMenu.h b/src/components/GuiMenu.h new file mode 100644 index 000000000..17249b7f3 --- /dev/null +++ b/src/components/GuiMenu.h @@ -0,0 +1,18 @@ +#pragma once + +#include "../GuiComponent.h" +#include "TextListComponent.h" +#include "NinePatchComponent.h" +#include + +class GuiMenu : public GuiComponent +{ +public: + GuiMenu(Window* window); + + bool input(InputConfig* config, Input input) override; + +private: + NinePatchComponent mBackground; + TextListComponent< std::function > mList; +}; diff --git a/src/components/NinePatchComponent.h b/src/components/NinePatchComponent.h index e3281b20b..fad6feb65 100644 --- a/src/components/NinePatchComponent.h +++ b/src/components/NinePatchComponent.h @@ -6,7 +6,7 @@ class NinePatchComponent : public GuiComponent { public: - NinePatchComponent(Window* window, const std::string& path, unsigned int edgeColor = 0xFFFFFFFF, unsigned int centerColor = 0xFFFFFFFF); + NinePatchComponent(Window* window, const std::string& path = "", unsigned int edgeColor = 0xFFFFFFFF, unsigned int centerColor = 0xFFFFFFFF); void render(const Eigen::Affine3f& parentTrans) override; diff --git a/src/views/GameListView.cpp b/src/views/GameListView.cpp index 123677e9a..e2153ef45 100644 --- a/src/views/GameListView.cpp +++ b/src/views/GameListView.cpp @@ -1,6 +1,7 @@ #include "GameListView.h" #include "../Window.h" #include "../components/GuiMetaDataEd.h" +#include "../components/GuiMenu.h" bool GameListView::input(InputConfig* config, Input input) { @@ -19,9 +20,10 @@ bool GameListView::input(InputConfig* config, Input input) delete file; //free it })); return true; - }else if(config->isMappedTo("start", input) && input.value != 0) + }else if(config->isMappedTo("menu", input) && input.value != 0) { // open menu + mWindow->pushGui(new GuiMenu(mWindow)); } return GuiComponent::input(config, input);