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-10-01 03:29:55 +00:00
|
|
|
#include "GuiFastSelect.h"
|
2012-08-10 19:28:34 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
|
2012-08-14 01:27:39 +00:00
|
|
|
const float GuiGameList::sInfoWidth = 0.5;
|
|
|
|
|
2012-08-16 15:23:23 +00:00
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
GuiGameList::GuiGameList(bool useDetail)
|
2012-07-20 01:08:29 +00:00
|
|
|
{
|
2012-10-07 21:56:33 +00:00
|
|
|
//std::cout << "Creating GuiGameList\n";
|
2012-08-02 01:43:55 +00:00
|
|
|
mDetailed = useDetail;
|
|
|
|
|
2012-09-15 21:24:33 +00:00
|
|
|
mTheme = new GuiTheme(); //not a child because it's rendered manually by GuiGameList::onRender (to make sure it's rendered first)
|
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
//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-09-15 21:24:33 +00:00
|
|
|
mScreenshot = new GuiImage(Renderer::getScreenWidth() * sInfoWidth * 0.5, Renderer::getScreenHeight() * mTheme->getGameImageOffsetY(), "", Renderer::getScreenWidth() * sInfoWidth * 0.7);
|
2012-08-13 18:32:53 +00:00
|
|
|
mScreenshot->setOrigin(0.5, 0.0);
|
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
|
|
|
|
|
|
|
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-10 19:28:34 +00:00
|
|
|
if(mTheme)
|
|
|
|
mTheme->render();
|
2012-08-02 01:43:55 +00:00
|
|
|
|
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
|
|
|
|
2012-08-16 15:23:23 +00:00
|
|
|
//if we're not scrolling and we have selected a non-folder
|
|
|
|
if(!mList->isScrolling() && 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())
|
2012-09-15 21:24:33 +00:00
|
|
|
Renderer::drawWrappedText(desc, Renderer::getScreenWidth() * 0.03, mScreenshot->getOffsetY() + mScreenshot->getHeight() + 8, 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
|
|
|
}
|
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
//only allow switching systems if more than one exists (otherwise it'll reset your position when you switch and it's annoying)
|
|
|
|
if(SystemData::sSystemVector.size() > 1)
|
2012-07-21 19:06:24 +00:00
|
|
|
{
|
2012-09-07 21:44:07 +00:00
|
|
|
if(button == InputManager::RIGHT && keyDown)
|
|
|
|
{
|
|
|
|
setSystemId(mSystemId + 1);
|
|
|
|
}
|
|
|
|
if(button == InputManager::LEFT && keyDown)
|
|
|
|
{
|
|
|
|
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-10-01 03:29:55 +00:00
|
|
|
if(button == InputManager::SELECT && keyDown)
|
|
|
|
{
|
2012-10-05 13:44:18 +00:00
|
|
|
new GuiFastSelect(this, mList, mList->getSelectedObject()->getName()[0]);
|
2012-10-01 03:29:55 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
if(mDetailed)
|
|
|
|
{
|
2012-08-16 15:23:23 +00:00
|
|
|
if(button == InputManager::UP || button == InputManager::DOWN)
|
2012-08-02 01:43:55 +00:00
|
|
|
{
|
2012-08-16 15:23:23 +00:00
|
|
|
if(!keyDown)
|
|
|
|
updateDetailData();
|
|
|
|
else
|
|
|
|
mScreenshot->setImage(""); //clear the image when we start scrolling
|
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-10-01 03:29:55 +00:00
|
|
|
mList->setSelectedTextColor(mTheme->getSelectedTextColor());
|
2012-08-14 01:27:39 +00:00
|
|
|
mList->setCentered(mTheme->getListCentered());
|
2012-09-15 21:24:33 +00:00
|
|
|
|
|
|
|
if(mDetailed)
|
|
|
|
{
|
|
|
|
mList->setOffsetX(mTheme->getListOffsetX() * Renderer::getScreenWidth());
|
|
|
|
mList->setTextOffsetX(mTheme->getListTextOffsetX() * Renderer::getScreenWidth());
|
|
|
|
mScreenshot->setOffsetY(mTheme->getGameImageOffsetY() * Renderer::getScreenHeight());
|
|
|
|
}
|
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()
|
|
|
|
{
|
2012-10-05 20:04:12 +00:00
|
|
|
updateDetailData();
|
2012-08-02 04:03:15 +00:00
|
|
|
InputManager::registerComponent(this);
|
|
|
|
}
|
2012-09-04 16:45:16 +00:00
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
//called when the renderer shuts down/returns
|
|
|
|
//we have to manually call init/deinit on mTheme because it is not our child
|
2012-09-04 16:45:16 +00:00
|
|
|
void GuiGameList::onDeinit()
|
|
|
|
{
|
|
|
|
mTheme->deinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiGameList::onInit()
|
|
|
|
{
|
2012-09-07 21:44:07 +00:00
|
|
|
mTheme->init();
|
2012-09-04 16:45:16 +00:00
|
|
|
}
|
2012-10-05 20:18:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
extern bool IGNOREGAMELIST; //defined in main.cpp (as a command line argument)
|
|
|
|
GuiGameList* GuiGameList::create()
|
|
|
|
{
|
|
|
|
bool detailed = false;
|
|
|
|
|
|
|
|
if(!IGNOREGAMELIST)
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < SystemData::sSystemVector.size(); i++)
|
|
|
|
{
|
|
|
|
if(SystemData::sSystemVector.at(i)->hasGamelist())
|
|
|
|
{
|
|
|
|
detailed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new GuiGameList(detailed);
|
|
|
|
}
|