2012-07-20 01:08:29 +00:00
|
|
|
#include "GuiGameList.h"
|
2012-07-21 19:06:24 +00:00
|
|
|
#include "../InputManager.h"
|
2012-07-20 16:14:09 +00:00
|
|
|
#include <iostream>
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2012-07-21 20:57:53 +00:00
|
|
|
GuiGameList::GuiGameList()
|
2012-07-20 01:08:29 +00:00
|
|
|
{
|
2012-07-21 20:57:53 +00:00
|
|
|
std::cout << "Creating GuiGameList\n";
|
2012-07-20 01:08:29 +00:00
|
|
|
|
|
|
|
mList = new GuiList();
|
|
|
|
addChild(mList);
|
2012-07-20 16:14:09 +00:00
|
|
|
|
2012-07-21 20:57:53 +00:00
|
|
|
setSystemId(0);
|
|
|
|
|
2012-07-20 16:14:09 +00:00
|
|
|
Renderer::registerComponent(this);
|
2012-07-21 19:06:24 +00:00
|
|
|
InputManager::registerComponent(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiGameList::~GuiGameList()
|
|
|
|
{
|
|
|
|
Renderer::unregisterComponent(this);
|
2012-07-21 20:57:53 +00:00
|
|
|
delete mList;
|
|
|
|
|
2012-07-21 19:06:24 +00:00
|
|
|
InputManager::unregisterComponent(this);
|
2012-07-20 01:08:29 +00:00
|
|
|
}
|
|
|
|
|
2012-07-21 20:57:53 +00:00
|
|
|
void GuiGameList::setSystemId(int id)
|
|
|
|
{
|
2012-07-23 23:53:33 +00:00
|
|
|
if(SystemData::sSystemVector.size() == 0)
|
|
|
|
{
|
|
|
|
std::cerr << "Error - no systems found!\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-21 20:57:53 +00:00
|
|
|
//make sure the id is within range
|
|
|
|
if(id >= (int)SystemData::sSystemVector.size())
|
|
|
|
id -= SystemData::sSystemVector.size();
|
|
|
|
if(id < 0)
|
|
|
|
id += SystemData::sSystemVector.size();
|
|
|
|
|
|
|
|
mSystemId = id;
|
|
|
|
mSystem = SystemData::sSystemVector.at(mSystemId);
|
|
|
|
|
|
|
|
updateList();
|
|
|
|
}
|
|
|
|
|
2012-07-20 01:08:29 +00:00
|
|
|
void GuiGameList::onRender()
|
|
|
|
{
|
2012-07-21 20:16:07 +00:00
|
|
|
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0xFFFFFF);
|
2012-07-20 16:14:09 +00:00
|
|
|
|
2012-07-21 20:16:07 +00:00
|
|
|
Renderer::drawCenteredText(mSystem->getName(), 2, 0x0000FF);
|
2012-07-20 16:14:09 +00:00
|
|
|
}
|
|
|
|
|
2012-07-21 19:06:24 +00:00
|
|
|
void GuiGameList::onInput(InputManager::InputButton button, bool keyDown)
|
|
|
|
{
|
2012-07-21 20:57:53 +00:00
|
|
|
if(button == InputManager::BUTTON1 && mSystem->getGameCount() > 0)
|
|
|
|
{
|
|
|
|
if(!keyDown)
|
|
|
|
mSystem->launchGame(mList->getSelection());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(button == InputManager::RIGHT && keyDown)
|
|
|
|
{
|
|
|
|
setSystemId(mSystemId + 1);
|
|
|
|
}
|
|
|
|
if(button == InputManager::LEFT && keyDown)
|
2012-07-21 19:06:24 +00:00
|
|
|
{
|
2012-07-21 20:57:53 +00:00
|
|
|
setSystemId(mSystemId - 1);
|
2012-07-21 19:06:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-20 16:14:09 +00:00
|
|
|
void GuiGameList::updateList()
|
|
|
|
{
|
|
|
|
mList->clear();
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < mSystem->getGameCount(); i++)
|
|
|
|
{
|
|
|
|
GameData* game = mSystem->getGame(i);
|
2012-07-21 20:57:53 +00:00
|
|
|
|
2012-07-20 16:14:09 +00:00
|
|
|
mList->addObject(game->getName(), game);
|
|
|
|
}
|
2012-07-20 01:08:29 +00:00
|
|
|
}
|