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-08-02 04:03:15 +00:00
|
|
|
#include "GuiMenu.h"
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
#define SCREENSHOTWIDTH 256
|
|
|
|
#define SCREENSHOTHEIGHT 256
|
|
|
|
|
|
|
|
GuiGameList::GuiGameList(bool useDetail)
|
2012-07-20 01:08:29 +00:00
|
|
|
{
|
2012-07-21 20:57:53 +00:00
|
|
|
std::cout << "Creating GuiGameList\n";
|
2012-08-02 01:43:55 +00:00
|
|
|
mDetailed = useDetail;
|
|
|
|
|
|
|
|
//The GuiGameList can use the older, simple game list if so desired.
|
|
|
|
//The old view only shows a list in the center of the screen; the new view can display a screenshto and description.
|
|
|
|
//Those with smaller displays may prefer the older view.
|
|
|
|
if(mDetailed)
|
|
|
|
{
|
2012-08-02 04:50:18 +00:00
|
|
|
mList = new GuiList<FileData*>(Renderer::getScreenWidth() * 0.4, Renderer::getFontHeight(Renderer::LARGE) + 2);
|
2012-08-02 01:43:55 +00:00
|
|
|
|
|
|
|
mScreenshot = new GuiImage(Renderer::getScreenWidth() * 0.2 - (SCREENSHOTWIDTH / 2), Renderer::getFontHeight(Renderer::LARGE) + 2);
|
|
|
|
addChild(mScreenshot);
|
|
|
|
}else{
|
2012-08-02 04:50:18 +00:00
|
|
|
mList = new GuiList<FileData*>(0, Renderer::getFontHeight(Renderer::LARGE) + 2);
|
2012-08-02 01:43:55 +00:00
|
|
|
mScreenshot = NULL;
|
|
|
|
}
|
2012-07-20 01:08:29 +00:00
|
|
|
|
|
|
|
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-08-02 01:43:55 +00:00
|
|
|
if(mDetailed)
|
|
|
|
{
|
|
|
|
delete mScreenshot;
|
|
|
|
}
|
|
|
|
|
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-08-02 01:43:55 +00:00
|
|
|
Renderer::drawCenteredText(mSystem->getName(), 0, 1, 0x0000FF, Renderer::LARGE);
|
|
|
|
|
|
|
|
|
|
|
|
if(mDetailed)
|
|
|
|
{
|
|
|
|
Renderer::drawRect(Renderer::getScreenWidth() * 0.4, Renderer::getFontHeight(Renderer::LARGE) + 2, 8, Renderer::getScreenHeight(), 0x0000FF);
|
|
|
|
|
|
|
|
//if we have selected a non-folder
|
2012-08-02 04:50:18 +00:00
|
|
|
if(mList->getSelectedObject() && !mList->getSelectedObject()->isFolder())
|
2012-08-02 01:43:55 +00:00
|
|
|
{
|
|
|
|
GameData* game = (GameData*)mList->getSelectedObject();
|
|
|
|
|
|
|
|
std::string desc = game->getDescription();
|
|
|
|
if(!desc.empty())
|
|
|
|
Renderer::drawWrappedText(desc, 2, Renderer::getFontHeight(Renderer::LARGE) + SCREENSHOTHEIGHT + 12, Renderer::getScreenWidth() * 0.4, 0xFF0000);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2012-08-02 04:50:18 +00:00
|
|
|
FileData* file = mList->getSelectedObject();
|
2012-07-27 16:58:27 +00:00
|
|
|
if(file->isFolder())
|
|
|
|
{
|
|
|
|
//set current directory to this or something
|
|
|
|
mFolderStack.push(mFolder);
|
|
|
|
mFolder = (FolderData*)file;
|
|
|
|
updateList();
|
|
|
|
}else{
|
|
|
|
mSystem->launchGame((GameData*)file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-08-02 01:43:55 +00:00
|
|
|
|
2012-08-02 04:03:15 +00:00
|
|
|
if(button == InputManager::MENU && keyDown)
|
|
|
|
{
|
|
|
|
new GuiMenu(this);
|
|
|
|
}
|
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
if(mDetailed)
|
|
|
|
{
|
|
|
|
if(!keyDown && (button == InputManager::UP || button == InputManager::DOWN))
|
|
|
|
{
|
2012-08-02 04:50:18 +00:00
|
|
|
if(mList->getSelectedObject() && !mList->getSelectedObject()->isFolder())
|
2012-08-02 01:43:55 +00:00
|
|
|
{
|
|
|
|
mScreenshot->setImage(((GameData*)mList->getSelectedObject())->getImagePath());
|
|
|
|
}else{
|
|
|
|
mScreenshot->setImage("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-21 19:06:24 +00:00
|
|
|
}
|
|
|
|
|
2012-07-20 16:14:09 +00:00
|
|
|
void GuiGameList::updateList()
|
|
|
|
{
|
2012-08-02 01:43:55 +00:00
|
|
|
if(mDetailed)
|
|
|
|
mScreenshot->setImage("");
|
|
|
|
|
2012-07-20 16:14:09 +00:00
|
|
|
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
|
|
|
}
|
2012-08-02 04:03:15 +00:00
|
|
|
|
|
|
|
//these are called when the menu opens/closes
|
2012-08-02 04:50:18 +00:00
|
|
|
//the second bit should be moved to GuiList
|
2012-08-02 04:03:15 +00:00
|
|
|
void GuiGameList::onPause()
|
|
|
|
{
|
|
|
|
InputManager::unregisterComponent(this);
|
|
|
|
InputManager::unregisterComponent(mList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiGameList::onResume()
|
|
|
|
{
|
|
|
|
InputManager::registerComponent(this);
|
|
|
|
InputManager::registerComponent(mList);
|
|
|
|
}
|