2012-08-02 04:03:15 +00:00
|
|
|
#include "GuiMenu.h"
|
|
|
|
#include <iostream>
|
2013-05-13 19:53:28 +00:00
|
|
|
#include <SDL.h>
|
2013-01-04 23:31:51 +00:00
|
|
|
#include "../Log.h"
|
2013-01-26 17:47:43 +00:00
|
|
|
#include "../SystemData.h"
|
|
|
|
#include "GuiGameList.h"
|
2013-06-17 19:01:03 +00:00
|
|
|
#include "../Settings.h"
|
2013-06-19 01:12:30 +00:00
|
|
|
#include "GuiSettingsMenu.h"
|
2012-12-18 15:20:13 +00:00
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
GuiMenu::GuiMenu(Window* window, GuiGameList* parent) : GuiComponent(window)
|
2012-08-02 04:03:15 +00:00
|
|
|
{
|
|
|
|
mParent = parent;
|
|
|
|
|
2013-07-09 05:44:24 +00:00
|
|
|
std::shared_ptr<Font> font = Font::get(*mWindow->getResourceManager(), Font::getDefaultPath(), FONT_SIZE_LARGE);
|
2013-07-03 07:54:55 +00:00
|
|
|
mList = new TextListComponent<std::string>(mWindow, 0, font->getHeight() + 2, font);
|
2012-10-25 18:03:35 +00:00
|
|
|
mList->setSelectedTextColor(0x0000FFFF);
|
2012-08-04 21:38:37 +00:00
|
|
|
populateList();
|
2012-08-02 04:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GuiMenu::~GuiMenu()
|
|
|
|
{
|
|
|
|
delete mList;
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
bool GuiMenu::input(InputConfig* config, Input input)
|
2012-08-02 04:03:15 +00:00
|
|
|
{
|
2013-04-09 18:13:47 +00:00
|
|
|
mList->input(config, input);
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
if(config->isMappedTo("menu", input) && input.value != 0)
|
2012-08-02 04:03:15 +00:00
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
delete this;
|
2013-06-02 15:08:32 +00:00
|
|
|
return true;
|
2012-08-02 04:03:15 +00:00
|
|
|
}
|
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);
|
2013-01-26 17:47:43 +00:00
|
|
|
}else if(command == "es_reload")
|
|
|
|
{
|
|
|
|
//reload the game list
|
2013-07-09 10:37:37 +00:00
|
|
|
SystemData::loadConfig(SystemData::getConfigPath(), false);
|
2013-01-26 17:47:43 +00:00
|
|
|
mParent->setSystemId(0);
|
2013-06-19 01:12:30 +00:00
|
|
|
}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)
|
2013-01-04 23:31:51 +00:00
|
|
|
{
|
|
|
|
LOG(LogWarning) << "(warning: command terminated with nonzero result!)";
|
|
|
|
}
|
2012-08-02 04:50:18 +00:00
|
|
|
}
|
2012-08-02 04:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiMenu::populateList()
|
|
|
|
{
|
2012-08-02 04:50:18 +00:00
|
|
|
mList->clear();
|
2012-08-02 04:03:15 +00:00
|
|
|
|
2012-10-28 23:07:05 +00:00
|
|
|
//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
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
mList->addObject("Settings", "es_settings", 0x0000FFFF);
|
|
|
|
|
2012-10-17 18:21:56 +00:00
|
|
|
mList->addObject("Restart", "sudo shutdown -r now", 0x0000FFFF);
|
|
|
|
mList->addObject("Shutdown", "sudo shutdown -h now", 0x0000FFFF);
|
2012-12-18 15:20:13 +00:00
|
|
|
|
2013-01-26 17:47:43 +00:00
|
|
|
mList->addObject("Reload", "es_reload", 0x0000FFFF);
|
|
|
|
|
2013-06-17 19:01:03 +00:00
|
|
|
if(!Settings::getInstance()->getBool("DONTSHOWEXIT"))
|
2012-12-18 15:20:13 +00:00
|
|
|
mList->addObject("Exit", "exit", 0xFF0000FF); //a special case; pushes an SDL quit event to the event stack instead of being called by system()
|
2012-08-02 04:03:15 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
void GuiMenu::update(int deltaTime)
|
|
|
|
{
|
|
|
|
mList->update(deltaTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiMenu::render()
|
2012-08-02 04:03:15 +00:00
|
|
|
{
|
2013-05-13 19:53:28 +00:00
|
|
|
Renderer::drawRect(Renderer::getScreenWidth() / 4, 0, Renderer::getScreenWidth() / 2, Renderer::getScreenHeight(), 0x999999);
|
2013-04-08 16:52:40 +00:00
|
|
|
mList->render();
|
2012-08-02 04:03:15 +00:00
|
|
|
}
|