2014-06-25 16:29:58 +00:00
|
|
|
#include "views/gamelist/BasicGameListView.h"
|
|
|
|
#include "views/ViewController.h"
|
|
|
|
#include "Renderer.h"
|
|
|
|
#include "Window.h"
|
|
|
|
#include "ThemeData.h"
|
|
|
|
#include "SystemData.h"
|
|
|
|
#include "Settings.h"
|
2017-03-18 17:54:39 +00:00
|
|
|
#include "FileFilterIndex.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
BasicGameListView::BasicGameListView(Window* window, FileData* root)
|
|
|
|
: ISimpleGameListView(window, root), mList(window)
|
|
|
|
{
|
|
|
|
mList.setSize(mSize.x(), mSize.y() * 0.8f);
|
|
|
|
mList.setPosition(0, mSize.y() * 0.2f);
|
2017-04-22 14:15:16 +00:00
|
|
|
mList.setDefaultZIndex(20);
|
2014-06-25 16:29:58 +00:00
|
|
|
addChild(&mList);
|
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
populateList(root->getChildrenListToDisplay());
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BasicGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
|
|
|
|
{
|
|
|
|
ISimpleGameListView::onThemeChanged(theme);
|
|
|
|
using namespace ThemeFlags;
|
|
|
|
mList.applyTheme(theme, getName(), "gamelist", ALL);
|
2017-04-22 14:15:16 +00:00
|
|
|
|
|
|
|
sortChildren();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BasicGameListView::onFileChanged(FileData* file, FileChangeType change)
|
|
|
|
{
|
|
|
|
if(change == FILE_METADATA_CHANGED)
|
|
|
|
{
|
|
|
|
// might switch to a detailed view
|
|
|
|
ViewController::get()->reloadGameListView(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ISimpleGameListView::onFileChanged(file, change);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasicGameListView::populateList(const std::vector<FileData*>& files)
|
|
|
|
{
|
|
|
|
mList.clear();
|
2017-07-18 09:45:50 +00:00
|
|
|
mHeaderText.setText(mRoot->getSystem()->getFullName());
|
2017-03-18 17:54:39 +00:00
|
|
|
if (files.size() > 0)
|
|
|
|
{
|
|
|
|
for(auto it = files.begin(); it != files.end(); it++)
|
|
|
|
{
|
|
|
|
mList.add((*it)->getName(), *it, ((*it)->getType() == FOLDER));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2017-06-12 16:38:59 +00:00
|
|
|
addPlaceholder();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileData* BasicGameListView::getCursor()
|
|
|
|
{
|
|
|
|
return mList.getSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasicGameListView::setCursor(FileData* cursor)
|
|
|
|
{
|
2017-06-12 16:38:59 +00:00
|
|
|
if(!mList.setCursor(cursor) && (!cursor->isPlaceHolder()))
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2017-03-18 17:54:39 +00:00
|
|
|
populateList(cursor->getParent()->getChildrenListToDisplay());
|
2014-06-25 16:29:58 +00:00
|
|
|
mList.setCursor(cursor);
|
|
|
|
|
|
|
|
// update our cursor stack in case our cursor just got set to some folder we weren't in before
|
|
|
|
if(mCursorStack.empty() || mCursorStack.top() != cursor->getParent())
|
|
|
|
{
|
|
|
|
std::stack<FileData*> tmp;
|
|
|
|
FileData* ptr = cursor->getParent();
|
|
|
|
while(ptr && ptr != mRoot)
|
|
|
|
{
|
|
|
|
tmp.push(ptr);
|
|
|
|
ptr = ptr->getParent();
|
|
|
|
}
|
2017-05-18 10:16:57 +00:00
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
// flip the stack and put it in mCursorStack
|
|
|
|
mCursorStack = std::stack<FileData*>();
|
|
|
|
while(!tmp.empty())
|
|
|
|
{
|
|
|
|
mCursorStack.push(tmp.top());
|
|
|
|
tmp.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
void BasicGameListView::addPlaceholder()
|
|
|
|
{
|
|
|
|
// empty list - add a placeholder
|
|
|
|
FileData* placeholder = new FileData(PLACEHOLDER, "<No Entries Found>", this->mRoot->getSystem()->getSystemEnvData(), this->mRoot->getSystem());
|
|
|
|
mList.add(placeholder->getName(), placeholder, (placeholder->getType() == PLACEHOLDER));
|
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
void BasicGameListView::launch(FileData* game)
|
|
|
|
{
|
|
|
|
ViewController::get()->launch(game);
|
|
|
|
}
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
void BasicGameListView::remove(FileData *game, bool deleteFile)
|
2015-01-12 20:06:11 +00:00
|
|
|
{
|
2017-06-12 16:38:59 +00:00
|
|
|
if (deleteFile)
|
|
|
|
boost::filesystem::remove(game->getPath()); // actually delete the file on the filesystem
|
|
|
|
FileData* parent = game->getParent();
|
2015-01-12 20:06:11 +00:00
|
|
|
if (getCursor() == game) // Select next element in list, or prev if none
|
|
|
|
{
|
2017-06-12 16:38:59 +00:00
|
|
|
std::vector<FileData*> siblings = parent->getChildrenListToDisplay();
|
2015-01-12 20:06:11 +00:00
|
|
|
auto gameIter = std::find(siblings.begin(), siblings.end(), game);
|
|
|
|
auto gamePos = std::distance(siblings.begin(), gameIter);
|
|
|
|
if (gameIter != siblings.end())
|
|
|
|
{
|
|
|
|
if ((gamePos + 1) < siblings.size())
|
|
|
|
{
|
|
|
|
setCursor(siblings.at(gamePos + 1));
|
|
|
|
} else if ((gamePos - 1) > 0) {
|
|
|
|
setCursor(siblings.at(gamePos - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
mList.remove(game);
|
|
|
|
if(mList.size() == 0)
|
|
|
|
{
|
|
|
|
addPlaceholder();
|
|
|
|
}
|
2015-01-12 20:06:11 +00:00
|
|
|
delete game; // remove before repopulating (removes from parent)
|
2017-06-12 16:38:59 +00:00
|
|
|
onFileChanged(parent, FILE_REMOVED); // update the view, with game removed
|
2015-01-12 20:06:11 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
std::vector<HelpPrompt> BasicGameListView::getHelpPrompts()
|
|
|
|
{
|
|
|
|
std::vector<HelpPrompt> prompts;
|
|
|
|
|
|
|
|
if(Settings::getInstance()->getBool("QuickSystemSelect"))
|
|
|
|
prompts.push_back(HelpPrompt("left/right", "system"));
|
|
|
|
prompts.push_back(HelpPrompt("up/down", "choose"));
|
|
|
|
prompts.push_back(HelpPrompt("a", "launch"));
|
|
|
|
prompts.push_back(HelpPrompt("b", "back"));
|
|
|
|
prompts.push_back(HelpPrompt("select", "options"));
|
2016-12-20 20:25:35 +00:00
|
|
|
prompts.push_back(HelpPrompt("x", "random"));
|
2017-07-18 09:45:50 +00:00
|
|
|
if(mRoot->getSystem()->isGameSystem())
|
|
|
|
{
|
2017-08-29 14:04:23 +00:00
|
|
|
prompts.push_back(HelpPrompt("y", "toggle"));
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
return prompts;
|
|
|
|
}
|