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);
|
|
|
|
|
2012-07-27 16:58:27 +00:00
|
|
|
//clear the folder stack (I can't look up the proper method right now)
|
|
|
|
while(mFolderStack.size()){ mFolderStack.pop(); }
|
|
|
|
|
|
|
|
mFolder = mSystem->getRootFolder();
|
|
|
|
|
2012-07-21 20:57:53 +00:00
|
|
|
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-27 16:58:27 +00:00
|
|
|
if(button == InputManager::BUTTON1 && mFolder->getFileCount() > 0)
|
2012-07-21 20:57:53 +00:00
|
|
|
{
|
|
|
|
if(!keyDown)
|
2012-07-27 16:58:27 +00:00
|
|
|
{
|
|
|
|
FileData* file = (FileData*)mList->getSelectedObject();
|
|
|
|
if(file->isFolder())
|
|
|
|
{
|
|
|
|
//set current directory to this or something
|
|
|
|
mFolderStack.push(mFolder);
|
|
|
|
mFolder = (FolderData*)file;
|
|
|
|
updateList();
|
|
|
|
}else{
|
|
|
|
mSystem->launchGame((GameData*)file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//std::cout << "mFolderStack.size(): " << mFolderStack.size() << "\n";
|
|
|
|
if(button == InputManager::BUTTON2 && keyDown && mFolderStack.size())
|
|
|
|
{
|
|
|
|
mFolder = mFolderStack.top();
|
|
|
|
mFolderStack.pop();
|
|
|
|
updateList();
|
2012-07-21 20:57:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2012-07-27 16:58:27 +00:00
|
|
|
for(unsigned int i = 0; i < mFolder->getFileCount(); i++)
|
2012-07-20 16:14:09 +00:00
|
|
|
{
|
2012-07-27 16:58:27 +00:00
|
|
|
FileData* file = mFolder->getFile(i);
|
2012-07-21 20:57:53 +00:00
|
|
|
|
2012-07-27 16:58:27 +00:00
|
|
|
if(file->isFolder())
|
|
|
|
mList->addObject(file->getName(), file, 0x00C000);
|
|
|
|
else
|
|
|
|
mList->addObject(file->getName(), file);
|
2012-07-20 16:14:09 +00:00
|
|
|
}
|
2012-07-20 01:08:29 +00:00
|
|
|
}
|