mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-21 21:55:38 +00:00
Redid GuiMenu.
This commit is contained in:
parent
cad914ab01
commit
94ca712759
|
@ -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
|
||||
|
|
|
@ -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<Font> 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<std::string, ImageDef> sDefaultImages;
|
||||
static std::map<std::string, unsigned int> sDefaultColors;
|
||||
|
|
68
src/components/GuiMenu.cpp
Normal file
68
src/components/GuiMenu.cpp
Normal file
|
@ -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<ThemeData> theme = std::make_shared<ThemeData>();
|
||||
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);
|
||||
}
|
18
src/components/GuiMenu.h
Normal file
18
src/components/GuiMenu.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
#include "TextListComponent.h"
|
||||
#include "NinePatchComponent.h"
|
||||
#include <functional>
|
||||
|
||||
class GuiMenu : public GuiComponent
|
||||
{
|
||||
public:
|
||||
GuiMenu(Window* window);
|
||||
|
||||
bool input(InputConfig* config, Input input) override;
|
||||
|
||||
private:
|
||||
NinePatchComponent mBackground;
|
||||
TextListComponent< std::function<void()> > mList;
|
||||
};
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue