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>
|
2013-01-04 23:31:51 +00:00
|
|
|
#include "../Log.h"
|
2012-08-16 15:23:23 +00:00
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
GuiGameList::GuiGameList(Window* window, bool useDetail) : Gui(window)
|
2012-07-20 01:08:29 +00:00
|
|
|
{
|
2012-08-02 01:43:55 +00:00
|
|
|
mDetailed = useDetail;
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
mTheme = new GuiTheme(mWindow, mDetailed);
|
2012-09-15 21:24:33 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
mList = new GuiList<FileData*>(mWindow, Renderer::getScreenWidth() * mTheme->getFloat("listOffsetX"), Renderer::getDefaultFont(Renderer::LARGE)->getHeight() + 2, Renderer::getDefaultFont(Renderer::MEDIUM));
|
2012-08-02 01:43:55 +00:00
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
mScreenshot = new GuiImage(mWindow, Renderer::getScreenWidth() * mTheme->getFloat("gameImageOffsetX"), Renderer::getScreenHeight() * mTheme->getFloat("gameImageOffsetY"), "", mTheme->getFloat("gameImageWidth"), mTheme->getFloat("gameImageHeight"), false);
|
2012-11-17 18:39:49 +00:00
|
|
|
mScreenshot->setOrigin(mTheme->getFloat("gameImageOriginX"), mTheme->getFloat("gameImageOriginY"));
|
2012-10-17 17:15:58 +00:00
|
|
|
|
|
|
|
mImageAnimation = new GuiAnimation();
|
|
|
|
mImageAnimation->addChild(mScreenshot);
|
2012-08-02 01:43:55 +00:00
|
|
|
}else{
|
2013-04-08 17:40:15 +00:00
|
|
|
mList = new GuiList<FileData*>(mWindow, 0, Renderer::getDefaultFont(Renderer::LARGE)->getHeight() + 2, Renderer::getDefaultFont(Renderer::MEDIUM));
|
2012-08-02 01:43:55 +00:00
|
|
|
mScreenshot = NULL;
|
2012-10-17 17:15:58 +00:00
|
|
|
mImageAnimation = NULL;
|
2012-08-02 01:43:55 +00:00
|
|
|
}
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2012-07-21 20:57:53 +00:00
|
|
|
setSystemId(0);
|
2012-07-21 19:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GuiGameList::~GuiGameList()
|
|
|
|
{
|
2012-07-21 20:57:53 +00:00
|
|
|
delete mList;
|
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
if(mDetailed)
|
|
|
|
{
|
2012-10-17 17:15:58 +00:00
|
|
|
delete mImageAnimation;
|
2012-08-02 01:43:55 +00:00
|
|
|
delete mScreenshot;
|
2012-08-10 19:28:34 +00:00
|
|
|
delete mTheme;
|
2012-08-02 01:43:55 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2013-01-04 23:31:51 +00:00
|
|
|
LOG(LogError) << "Error - no systems found!";
|
2012-07-23 23:53:33 +00:00
|
|
|
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-10-13 23:37:51 +00:00
|
|
|
//clear the folder stack
|
2012-07-27 16:58:27 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
void GuiGameList::render()
|
2012-07-20 01:08:29 +00:00
|
|
|
{
|
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
|
2012-11-17 18:39:49 +00:00
|
|
|
if(!mTheme->getBool("hideHeader"))
|
2012-12-18 15:08:25 +00:00
|
|
|
Renderer::drawCenteredText(mSystem->getDescName(), 0, 1, 0xFF0000FF, Renderer::getDefaultFont(Renderer::LARGE));
|
2012-08-02 01:43:55 +00:00
|
|
|
|
|
|
|
if(mDetailed)
|
|
|
|
{
|
2012-08-14 01:27:39 +00:00
|
|
|
//divider
|
2012-11-17 18:39:49 +00:00
|
|
|
if(!mTheme->getBool("hideDividers"))
|
|
|
|
Renderer::drawRect(Renderer::getScreenWidth() * mTheme->getFloat("listOffsetX") - 4, Renderer::getDefaultFont(Renderer::LARGE)->getHeight() + 2, 8, Renderer::getScreenHeight(), 0x0000FFFF);
|
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-11-17 18:39:49 +00:00
|
|
|
Renderer::drawWrappedText(desc, Renderer::getScreenWidth() * 0.03, mScreenshot->getOffsetY() + mScreenshot->getHeight() + 12, Renderer::getScreenWidth() * (mTheme->getFloat("listOffsetX") - 0.03), mTheme->getColor("description"), mTheme->getDescriptionFont());
|
2012-08-02 01:43:55 +00:00
|
|
|
}
|
2013-04-08 17:40:15 +00:00
|
|
|
|
|
|
|
mScreenshot->render();
|
2012-08-02 01:43:55 +00:00
|
|
|
}
|
2013-04-08 17:40:15 +00:00
|
|
|
|
|
|
|
mList->render();
|
2012-07-20 16:14:09 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
void GuiGameList::input(InputConfig* config, Input input)
|
2012-07-21 19:06:24 +00:00
|
|
|
{
|
2013-04-09 18:13:47 +00:00
|
|
|
mList->input(config, input);
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
if(config->isMappedTo("a", input) && mFolder->getFileCount() > 0 && input.value != 0)
|
2012-07-21 20:57:53 +00:00
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
//play select sound
|
|
|
|
mTheme->getSound("menuSelect")->play();
|
2012-10-13 20:05:43 +00:00
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
FileData* file = mList->getSelectedObject();
|
|
|
|
if(file->isFolder()) //if you selected a folder, add this directory to the stack, and use the selected one
|
|
|
|
{
|
|
|
|
mFolderStack.push(mFolder);
|
|
|
|
mFolder = (FolderData*)file;
|
|
|
|
updateList();
|
|
|
|
}else{
|
|
|
|
mList->stopScrolling();
|
2012-10-14 17:49:57 +00:00
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
//wait for the sound to finish or we'll never hear it...
|
|
|
|
while(mTheme->getSound("menuSelect")->isPlaying());
|
2012-10-13 20:05:43 +00:00
|
|
|
|
2013-04-08 17:40:15 +00:00
|
|
|
mSystem->launchGame(mWindow, (GameData*)file);
|
2013-04-10 17:29:07 +00:00
|
|
|
return;
|
2012-07-27 16:58:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-14 01:27:39 +00:00
|
|
|
//if there's something on the directory stack, return to it
|
2013-04-08 16:52:40 +00:00
|
|
|
if(config->isMappedTo("b", input) && input.value != 0 && mFolderStack.size())
|
2012-07-27 16:58:27 +00:00
|
|
|
{
|
|
|
|
mFolder = mFolderStack.top();
|
|
|
|
mFolderStack.pop();
|
|
|
|
updateList();
|
2012-08-12 14:43:09 +00:00
|
|
|
updateDetailData();
|
2012-10-13 20:05:43 +00:00
|
|
|
|
|
|
|
//play the back sound
|
2012-11-17 18:39:49 +00:00
|
|
|
mTheme->getSound("menuBack")->play();
|
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)
|
2013-04-08 16:52:40 +00:00
|
|
|
if(SystemData::sSystemVector.size() > 1 && input.value != 0)
|
2012-07-21 19:06:24 +00:00
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
if(config->isMappedTo("right", input))
|
2012-09-07 21:44:07 +00:00
|
|
|
{
|
|
|
|
setSystemId(mSystemId + 1);
|
|
|
|
}
|
2013-04-08 16:52:40 +00:00
|
|
|
if(config->isMappedTo("left", input))
|
2012-09-07 21:44:07 +00:00
|
|
|
{
|
|
|
|
setSystemId(mSystemId - 1);
|
|
|
|
}
|
2012-07-21 19:06:24 +00:00
|
|
|
}
|
2012-08-02 01:43:55 +00:00
|
|
|
|
2012-10-13 20:05:43 +00:00
|
|
|
//open the "start menu"
|
2013-04-08 16:52:40 +00:00
|
|
|
if(config->isMappedTo("menu", input) && input.value != 0)
|
2012-08-02 04:03:15 +00:00
|
|
|
{
|
2013-04-09 18:13:47 +00:00
|
|
|
mWindow->pushGui(new GuiMenu(mWindow, this));
|
2012-08-02 04:03:15 +00:00
|
|
|
}
|
|
|
|
|
2012-10-13 20:05:43 +00:00
|
|
|
//open the fast select menu
|
2013-04-08 16:52:40 +00:00
|
|
|
if(config->isMappedTo("select", input) && input.value != 0)
|
2012-10-01 03:29:55 +00:00
|
|
|
{
|
2013-04-09 18:13:47 +00:00
|
|
|
mWindow->pushGui(new GuiFastSelect(mWindow, this, mList, mList->getSelectedObject()->getName()[0], mTheme->getBoxData(), mTheme->getColor("fastSelect"), mTheme->getSound("menuScroll"), mTheme->getFastSelectFont()));
|
2012-10-01 03:29:55 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
if(mDetailed)
|
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
if(config->isMappedTo("up", input) || config->isMappedTo("down", input) || config->isMappedTo("pageup", input) || config->isMappedTo("pagedown", input))
|
2012-08-02 01:43:55 +00:00
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
if(input.value == 0)
|
2012-08-16 15:23:23 +00:00
|
|
|
updateDetailData();
|
|
|
|
else
|
2012-10-17 17:15:58 +00:00
|
|
|
clearDetailData();
|
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-11-17 18:39:49 +00:00
|
|
|
mList->addObject(file->getName(), file, mTheme->getColor("secondary"));
|
2012-07-27 16:58:27 +00:00
|
|
|
else
|
2012-11-17 18:39:49 +00:00
|
|
|
mList->addObject(file->getName(), file, mTheme->getColor("primary"));
|
2012-07-20 16:14:09 +00:00
|
|
|
}
|
2012-07-20 01:08:29 +00:00
|
|
|
}
|
2012-08-02 04:03:15 +00:00
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
std::string GuiGameList::getThemeFile()
|
|
|
|
{
|
2012-12-17 19:29:43 +00:00
|
|
|
std::string themePath;
|
|
|
|
|
|
|
|
themePath = getenv("HOME");
|
|
|
|
themePath += "/.emulationstation/" + mSystem->getName() + "/theme.xml";
|
|
|
|
if(boost::filesystem::exists(themePath))
|
|
|
|
return themePath;
|
|
|
|
|
|
|
|
themePath = mSystem->getStartPath() + "/theme.xml";
|
|
|
|
if(boost::filesystem::exists(themePath))
|
|
|
|
return themePath;
|
|
|
|
|
|
|
|
themePath = getenv("HOME");
|
|
|
|
themePath += "/.emulationstation/es_theme.xml";
|
|
|
|
if(boost::filesystem::exists(themePath))
|
|
|
|
return themePath;
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2012-08-10 19:28:34 +00:00
|
|
|
void GuiGameList::updateTheme()
|
|
|
|
{
|
2012-08-11 04:17:52 +00:00
|
|
|
if(!mTheme)
|
|
|
|
return;
|
|
|
|
|
2012-12-17 19:29:43 +00:00
|
|
|
mTheme->readXML( getThemeFile() );
|
2012-08-13 18:32:53 +00:00
|
|
|
|
2012-11-17 18:39:49 +00:00
|
|
|
mList->setSelectorColor(mTheme->getColor("selector"));
|
|
|
|
mList->setSelectedTextColor(mTheme->getColor("selected"));
|
|
|
|
mList->setScrollSound(mTheme->getSound("menuScroll"));
|
2012-09-15 21:24:33 +00:00
|
|
|
|
2012-10-31 14:46:06 +00:00
|
|
|
//fonts
|
|
|
|
mList->setFont(mTheme->getListFont());
|
|
|
|
|
2012-09-15 21:24:33 +00:00
|
|
|
if(mDetailed)
|
|
|
|
{
|
2012-11-17 18:39:49 +00:00
|
|
|
mList->setCentered(mTheme->getBool("listCentered"));
|
2012-10-13 23:40:44 +00:00
|
|
|
|
2012-11-17 18:39:49 +00:00
|
|
|
mList->setOffsetX(mTheme->getFloat("listOffsetX") * Renderer::getScreenWidth());
|
|
|
|
mList->setTextOffsetX(mTheme->getFloat("listTextOffsetX") * Renderer::getScreenWidth());
|
2012-10-13 23:37:51 +00:00
|
|
|
|
2012-11-17 18:39:49 +00:00
|
|
|
mScreenshot->setOffsetX(mTheme->getFloat("gameImageOffsetX") * Renderer::getScreenWidth());
|
|
|
|
mScreenshot->setOffsetY(mTheme->getFloat("gameImageOffsetY") * Renderer::getScreenHeight());
|
|
|
|
mScreenshot->setOrigin(mTheme->getFloat("gameImageOriginX"), mTheme->getFloat("gameImageOriginY"));
|
|
|
|
mScreenshot->setResize(mTheme->getFloat("gameImageWidth"), mTheme->getFloat("gameImageHeight"), false);
|
2012-09-15 21:24:33 +00:00
|
|
|
}
|
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())
|
|
|
|
{
|
2012-11-17 18:39:49 +00:00
|
|
|
mScreenshot->setOffset((mTheme->getFloat("gameImageOffsetX") - 0.05) * Renderer::getScreenWidth(), mTheme->getFloat("gameImageOffsetY") * Renderer::getScreenHeight());
|
2012-10-25 17:36:30 +00:00
|
|
|
|
|
|
|
if(((GameData*)mList->getSelectedObject())->getImagePath().empty())
|
2012-11-17 18:39:49 +00:00
|
|
|
mScreenshot->setImage(mTheme->getString("imageNotFoundPath"));
|
2012-10-25 17:36:30 +00:00
|
|
|
else
|
|
|
|
mScreenshot->setImage(((GameData*)mList->getSelectedObject())->getImagePath());
|
|
|
|
|
2012-10-17 17:15:58 +00:00
|
|
|
mImageAnimation->fadeIn(15);
|
|
|
|
mImageAnimation->move((int)(0.05 * Renderer::getScreenWidth()), 0, 5);
|
2012-08-12 14:43:09 +00:00
|
|
|
}else{
|
|
|
|
mScreenshot->setImage("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-17 17:15:58 +00:00
|
|
|
void GuiGameList::clearDetailData()
|
|
|
|
{
|
|
|
|
if(mDetailed)
|
|
|
|
{
|
|
|
|
mImageAnimation->fadeOut(35);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2013-04-10 17:29:07 +00:00
|
|
|
void GuiGameList::deinit()
|
2012-09-04 16:45:16 +00:00
|
|
|
{
|
2013-04-10 17:29:07 +00:00
|
|
|
if(mDetailed)
|
|
|
|
{
|
|
|
|
mScreenshot->deinit();
|
|
|
|
}
|
|
|
|
|
2012-09-04 16:45:16 +00:00
|
|
|
mTheme->deinit();
|
|
|
|
}
|
|
|
|
|
2013-04-10 17:29:07 +00:00
|
|
|
void GuiGameList::init()
|
2012-09-04 16:45:16 +00:00
|
|
|
{
|
2012-09-07 21:44:07 +00:00
|
|
|
mTheme->init();
|
2013-04-10 17:29:07 +00:00
|
|
|
|
|
|
|
if(mDetailed)
|
|
|
|
{
|
|
|
|
mScreenshot->deinit();
|
|
|
|
}
|
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)
|
2013-04-08 16:52:40 +00:00
|
|
|
GuiGameList* GuiGameList::create(Window* window)
|
2012-10-05 20:18:36 +00:00
|
|
|
{
|
|
|
|
bool detailed = false;
|
|
|
|
|
|
|
|
if(!IGNOREGAMELIST)
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < SystemData::sSystemVector.size(); i++)
|
|
|
|
{
|
|
|
|
if(SystemData::sSystemVector.at(i)->hasGamelist())
|
|
|
|
{
|
|
|
|
detailed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-08 17:40:15 +00:00
|
|
|
GuiGameList* list = new GuiGameList(window, detailed);
|
|
|
|
window->pushGui(list);
|
|
|
|
return list;
|
2012-10-05 20:18:36 +00:00
|
|
|
}
|
2013-04-09 18:13:47 +00:00
|
|
|
|
|
|
|
void GuiGameList::update(int deltaTime)
|
|
|
|
{
|
|
|
|
mImageAnimation->update(deltaTime);
|
|
|
|
mList->update(deltaTime);
|
|
|
|
}
|