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-08-10 19:28:34 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2012-08-11 04:17:52 +00:00
|
|
|
#define DRAWFRAMERATE
|
2012-08-10 19:28:34 +00:00
|
|
|
|
|
|
|
#ifdef DRAWFRAMERATE
|
|
|
|
#include <sstream>
|
|
|
|
extern float FRAMERATE;
|
|
|
|
#endif
|
2012-08-02 01:43:55 +00:00
|
|
|
|
2012-08-14 01:27:39 +00:00
|
|
|
const float GuiGameList::sInfoWidth = 0.5;
|
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
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.
|
2012-08-10 19:28:34 +00:00
|
|
|
//The old view only shows a list in the center of the screen; the new view can display an image and description.
|
2012-08-02 01:43:55 +00:00
|
|
|
//Those with smaller displays may prefer the older view.
|
|
|
|
if(mDetailed)
|
|
|
|
{
|
2012-08-14 01:27:39 +00:00
|
|
|
mList = new GuiList<FileData*>(Renderer::getScreenWidth() * sInfoWidth, Renderer::getFontHeight(Renderer::LARGE) + 2);
|
2012-08-02 01:43:55 +00:00
|
|
|
|
2012-08-09 21:19:07 +00:00
|
|
|
mScreenshot = new GuiImage(Renderer::getScreenWidth() * 0.2, Renderer::getFontHeight(Renderer::LARGE) + 2, "", Renderer::getScreenWidth() * 0.3);
|
2012-08-13 18:32:53 +00:00
|
|
|
mScreenshot->setOrigin(0.5, 0.0);
|
2012-08-14 01:27:39 +00:00
|
|
|
mScreenshot->setAlpha(true); //slower, but requested
|
2012-08-02 01:43:55 +00:00
|
|
|
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
|
|
|
|
2012-08-12 14:43:09 +00:00
|
|
|
mTheme = new GuiTheme(); //not a child because it's rendered manually by GuiGameList::onRender (to make sure it's rendered first)
|
|
|
|
|
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-08-10 19:28:34 +00:00
|
|
|
delete mTheme;
|
2012-08-02 01:43:55 +00:00
|
|
|
}
|
|
|
|
|
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-08-11 04:17:52 +00:00
|
|
|
updateTheme();
|
2012-07-21 20:57:53 +00:00
|
|
|
updateList();
|
2012-08-12 14:43:09 +00:00
|
|
|
updateDetailData();
|
2012-07-21 20:57:53 +00:00
|
|
|
}
|
|
|
|
|
2012-07-20 01:08:29 +00:00
|
|
|
void GuiGameList::onRender()
|
|
|
|
{
|
2012-08-11 04:17:52 +00:00
|
|
|
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0xFFFFFF);
|
|
|
|
|
2012-08-10 19:28:34 +00:00
|
|
|
if(mTheme)
|
|
|
|
mTheme->render();
|
2012-08-02 01:43:55 +00:00
|
|
|
|
2012-08-10 19:28:34 +00:00
|
|
|
#ifdef DRAWFRAMERATE
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << FRAMERATE;
|
|
|
|
std::string fps;
|
|
|
|
ss >> fps;
|
|
|
|
Renderer::drawText(fps, 0, 0, 0x00FF00);
|
|
|
|
#endif
|
|
|
|
|
2012-08-13 18:32:53 +00:00
|
|
|
//header
|
|
|
|
if(!mTheme->getHeaderHidden())
|
|
|
|
Renderer::drawCenteredText(mSystem->getName(), 0, 1, 0xFF0000, Renderer::LARGE);
|
2012-08-02 01:43:55 +00:00
|
|
|
|
|
|
|
if(mDetailed)
|
|
|
|
{
|
2012-08-14 01:27:39 +00:00
|
|
|
//divider
|
2012-08-13 18:32:53 +00:00
|
|
|
if(!mTheme->getDividersHidden())
|
2012-08-14 01:27:39 +00:00
|
|
|
Renderer::drawRect(Renderer::getScreenWidth() * sInfoWidth - 4, Renderer::getFontHeight(Renderer::LARGE) + 2, 8, Renderer::getScreenHeight(), 0x0000FF);
|
2012-08-02 01:43:55 +00:00
|
|
|
|
|
|
|
//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();
|
|
|
|
|
2012-08-09 21:19:07 +00:00
|
|
|
//todo: cache this
|
2012-08-02 01:43:55 +00:00
|
|
|
std::string desc = game->getDescription();
|
|
|
|
if(!desc.empty())
|
2012-08-14 01:34:23 +00:00
|
|
|
Renderer::drawWrappedText(desc, Renderer::getScreenWidth() * 0.03, Renderer::getFontHeight(Renderer::LARGE) + mScreenshot->getHeight() + 10, Renderer::getScreenWidth() * (sInfoWidth - 0.03), mTheme->getDescColor(), Renderer::SMALL);
|
2012-08-02 01:43:55 +00:00
|
|
|
}
|
|
|
|
}
|
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-08-14 01:27:39 +00:00
|
|
|
if(file->isFolder()) //if you selected a folder, add this directory to the stack, and use the selected one
|
2012-07-27 16:58:27 +00:00
|
|
|
{
|
|
|
|
mFolderStack.push(mFolder);
|
|
|
|
mFolder = (FolderData*)file;
|
|
|
|
updateList();
|
|
|
|
}else{
|
|
|
|
mSystem->launchGame((GameData*)file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-14 01:27:39 +00:00
|
|
|
//if there's something on the directory stack, return to it
|
2012-07-27 16:58:27 +00:00
|
|
|
if(button == InputManager::BUTTON2 && keyDown && mFolderStack.size())
|
|
|
|
{
|
|
|
|
mFolder = mFolderStack.top();
|
|
|
|
mFolderStack.pop();
|
|
|
|
updateList();
|
2012-08-12 14:43:09 +00:00
|
|
|
updateDetailData();
|
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-12 14:43:09 +00:00
|
|
|
updateDetailData();
|
2012-08-02 01:43:55 +00:00
|
|
|
}
|
|
|
|
}
|
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())
|
2012-08-13 18:32:53 +00:00
|
|
|
mList->addObject(file->getName(), file, mTheme->getSecondaryColor());
|
2012-07-27 16:58:27 +00:00
|
|
|
else
|
2012-08-13 18:32:53 +00:00
|
|
|
mList->addObject(file->getName(), file, mTheme->getPrimaryColor());
|
2012-07-20 16:14:09 +00:00
|
|
|
}
|
2012-07-20 01:08:29 +00:00
|
|
|
}
|
2012-08-02 04:03:15 +00:00
|
|
|
|
2012-08-10 19:28:34 +00:00
|
|
|
void GuiGameList::updateTheme()
|
|
|
|
{
|
2012-08-11 04:17:52 +00:00
|
|
|
if(!mTheme)
|
|
|
|
return;
|
|
|
|
|
2012-08-12 14:43:09 +00:00
|
|
|
std::string defaultPath = getenv("HOME");
|
|
|
|
defaultPath += "/.emulationstation/es_theme.xml";
|
2012-08-11 04:17:52 +00:00
|
|
|
std::string themePath = mSystem->getStartPath() + "/theme.xml";
|
2012-08-10 19:28:34 +00:00
|
|
|
|
|
|
|
if(boost::filesystem::exists(themePath))
|
|
|
|
mTheme->readXML(themePath);
|
2012-08-12 14:43:09 +00:00
|
|
|
else if(boost::filesystem::exists(defaultPath))
|
|
|
|
mTheme->readXML(defaultPath);
|
2012-08-11 04:17:52 +00:00
|
|
|
else
|
|
|
|
mTheme->readXML(""); //clears any current theme
|
2012-08-13 18:32:53 +00:00
|
|
|
|
|
|
|
mList->setSelectorColor(mTheme->getSelectorColor());
|
2012-08-14 01:27:39 +00:00
|
|
|
mList->setCentered(mTheme->getListCentered());
|
2012-08-10 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
2012-08-12 14:43:09 +00:00
|
|
|
void GuiGameList::updateDetailData()
|
|
|
|
{
|
|
|
|
if(!mDetailed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(mList->getSelectedObject() && !mList->getSelectedObject()->isFolder())
|
|
|
|
{
|
|
|
|
mScreenshot->setImage(((GameData*)mList->getSelectedObject())->getImagePath());
|
|
|
|
}else{
|
|
|
|
mScreenshot->setImage("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 04:03:15 +00:00
|
|
|
//these are called when the menu opens/closes
|
|
|
|
void GuiGameList::onPause()
|
|
|
|
{
|
|
|
|
InputManager::unregisterComponent(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiGameList::onResume()
|
|
|
|
{
|
|
|
|
InputManager::registerComponent(this);
|
|
|
|
}
|