ES-DE/src/components/GuiMenu.cpp

100 lines
2.7 KiB
C++
Raw Normal View History

#include "GuiMenu.h"
#include <iostream>
#include <SDL.h>
#include "../Log.h"
#include "../SystemData.h"
#include "GuiGameList.h"
#include "../Settings.h"
#include "GuiSettingsMenu.h"
2013-06-02 15:08:32 +00:00
GuiMenu::GuiMenu(Window* window, GuiGameList* parent) : GuiComponent(window)
{
mParent = parent;
std::shared_ptr<Font> font = Font::get(*mWindow->getResourceManager(), Font::getDefaultPath(), FONT_SIZE_LARGE);
mList = new TextListComponent<std::string>(mWindow, 0, font->getHeight() + 2, font);
mList->setSelectedTextColor(0x0000FFFF);
populateList();
}
GuiMenu::~GuiMenu()
{
delete mList;
}
2013-06-02 15:08:32 +00:00
bool GuiMenu::input(InputConfig* config, Input input)
{
mList->input(config, input);
2013-04-08 16:52:40 +00:00
if(config->isMappedTo("menu", input) && input.value != 0)
{
2013-04-08 16:52:40 +00:00
delete this;
2013-06-02 15:08:32 +00:00
return true;
}
2012-08-02 04:50:18 +00:00
2013-04-08 16:52:40 +00:00
if(config->isMappedTo("a", input) && input.value != 0)
2012-08-02 04:50:18 +00:00
{
2012-11-14 15:07:09 +00:00
executeCommand(mList->getSelectedObject());
2013-06-02 15:08:32 +00:00
return true;
2012-11-14 15:07:09 +00:00
}
2013-06-02 15:08:32 +00:00
return false;
2012-11-14 15:07:09 +00:00
}
void GuiMenu::executeCommand(std::string command)
{
if(command == "exit")
{
//push SDL quit event
SDL_Event* event = new SDL_Event();
event->type = SDL_QUIT;
SDL_PushEvent(event);
}else if(command == "es_reload")
{
//reload the game list
2013-07-09 10:37:37 +00:00
SystemData::loadConfig(SystemData::getConfigPath(), false);
mParent->setSystemId(0);
}else if(command == "es_settings")
{
mWindow->pushGui(new GuiSettingsMenu(mWindow));
delete this;
2012-11-14 15:07:09 +00:00
}else{
if(system(command.c_str()) != 0)
{
LOG(LogWarning) << "(warning: command terminated with nonzero result!)";
}
2012-08-02 04:50:18 +00:00
}
}
void GuiMenu::populateList()
{
2012-08-02 04:50:18 +00:00
mList->clear();
//if you want to add your own commands to the menu, here is where you need to change!
//commands added here are called with system() when selected (so are executed as shell commands)
//the method is GuiList::addObject(std::string displayString, std::string commandString, unsigned int displayHexColor);
//the list will automatically adjust as items are added to it, this should be the only area you need to change
2012-11-14 15:07:09 +00:00
//if you want to do something special within ES, override your command in the executeComand() method
mList->addObject("Settings", "es_settings", 0x0000FFFF);
mList->addObject("Restart", "sudo shutdown -r now", 0x0000FFFF);
mList->addObject("Shutdown", "sudo shutdown -h now", 0x0000FFFF);
mList->addObject("Reload", "es_reload", 0x0000FFFF);
if(!Settings::getInstance()->getBool("DONTSHOWEXIT"))
mList->addObject("Exit", "exit", 0xFF0000FF); //a special case; pushes an SDL quit event to the event stack instead of being called by system()
}
2013-04-08 16:52:40 +00:00
void GuiMenu::update(int deltaTime)
{
mList->update(deltaTime);
}
void GuiMenu::render()
{
Renderer::drawRect(Renderer::getScreenWidth() / 4, 0, Renderer::getScreenWidth() / 2, Renderer::getScreenHeight(), 0x999999);
2013-04-08 16:52:40 +00:00
mList->render();
}