2014-06-25 16:29:58 +00:00
|
|
|
#include "GuiGamelistOptions.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
|
|
|
#include "guis/GuiGamelistFilter.h"
|
|
|
|
#include "scrapers/Scraper.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "views/gamelist/IGameListView.h"
|
2017-11-18 22:23:56 +00:00
|
|
|
#include "views/UIModeController.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "views/ViewController.h"
|
2017-06-12 16:38:59 +00:00
|
|
|
#include "CollectionSystemManager.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "FileFilterIndex.h"
|
|
|
|
#include "FileSorts.h"
|
|
|
|
#include "GuiMetaDataEd.h"
|
|
|
|
#include "SystemData.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2017-05-18 10:16:57 +00:00
|
|
|
GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : GuiComponent(window),
|
2017-03-18 17:54:39 +00:00
|
|
|
mSystem(system), mMenu(window, "OPTIONS"), fromPlaceholder(false), mFiltersChanged(false)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
addChild(&mMenu);
|
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
// check it's not a placeholder folder - if it is, only show "Filter Options"
|
|
|
|
FileData* file = getGamelist()->getCursor();
|
|
|
|
fromPlaceholder = file->isPlaceHolder();
|
2014-07-27 22:49:43 +00:00
|
|
|
ComponentListRow row;
|
2017-03-18 17:54:39 +00:00
|
|
|
|
|
|
|
if (!fromPlaceholder) {
|
2017-11-03 11:11:11 +00:00
|
|
|
// jump to letter
|
|
|
|
row.elements.clear();
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2017-11-03 11:11:11 +00:00
|
|
|
// define supported character range
|
|
|
|
// this range includes all numbers, capital letters, and most reasonable symbols
|
|
|
|
char startChar = '!';
|
|
|
|
char endChar = '_';
|
|
|
|
|
2017-11-17 14:58:52 +00:00
|
|
|
char curChar = (char)toupper(getGamelist()->getCursor()->getName()[0]);
|
2017-11-03 11:11:11 +00:00
|
|
|
if(curChar < startChar || curChar > endChar)
|
|
|
|
curChar = startChar;
|
|
|
|
|
|
|
|
mJumpToLetterList = std::make_shared<LetterList>(mWindow, "JUMP TO...", false);
|
|
|
|
for (char c = startChar; c <= endChar; c++)
|
|
|
|
{
|
|
|
|
// check if c is a valid first letter in current list
|
|
|
|
const std::vector<FileData*>& files = getGamelist()->getCursor()->getParent()->getChildrenListToDisplay();
|
|
|
|
for (auto file : files)
|
|
|
|
{
|
2017-11-17 14:58:52 +00:00
|
|
|
char candidate = (char)toupper(file->getName()[0]);
|
2017-11-03 11:11:11 +00:00
|
|
|
if (c == candidate)
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
2017-11-03 11:11:11 +00:00
|
|
|
mJumpToLetterList->add(std::string(1, c), c, c == curChar);
|
|
|
|
break;
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
2017-11-03 11:11:11 +00:00
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 11:11:11 +00:00
|
|
|
row.addElement(std::make_shared<TextComponent>(mWindow, "JUMP TO...", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
|
|
|
row.addElement(mJumpToLetterList, false);
|
|
|
|
row.input_handler = [&](InputConfig* config, Input input) {
|
|
|
|
if(config->isMappedTo("a", input) && input.value)
|
|
|
|
{
|
|
|
|
jumpToLetter();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(mJumpToLetterList->input(config, input))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
mMenu.addRow(row);
|
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
// sort list by
|
|
|
|
mListSort = std::make_shared<SortList>(mWindow, "SORT GAMES BY", false);
|
|
|
|
for(unsigned int i = 0; i < FileSorts::SortTypes.size(); i++)
|
|
|
|
{
|
|
|
|
const FileData::SortType& sort = FileSorts::SortTypes.at(i);
|
|
|
|
mListSort->add(sort.description, &sort, i == 0); // TODO - actually make the sort type persistent
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
mMenu.addWithLabel("SORT GAMES BY", mListSort);
|
|
|
|
}
|
2017-07-05 10:50:01 +00:00
|
|
|
// show filtered menu
|
|
|
|
row.elements.clear();
|
|
|
|
row.addElement(std::make_shared<TextComponent>(mWindow, "FILTER GAMELIST", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
|
|
|
row.addElement(makeArrow(mWindow), false);
|
|
|
|
row.makeAcceptInputHandler(std::bind(&GuiGamelistOptions::openGamelistFilter, this));
|
|
|
|
mMenu.addRow(row);
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
std::map<std::string, CollectionSystemData> customCollections = CollectionSystemManager::get()->getCustomCollectionSystems();
|
2017-09-08 14:49:47 +00:00
|
|
|
|
2017-11-18 22:23:56 +00:00
|
|
|
if(UIModeController::getInstance()->isUIModeFull() &&
|
2017-11-11 14:56:22 +00:00
|
|
|
((customCollections.find(system->getName()) != customCollections.cend() && CollectionSystemManager::get()->getEditingCollection() != system->getName()) ||
|
2017-09-08 14:49:47 +00:00
|
|
|
CollectionSystemManager::get()->getCustomCollectionsBundle()->getName() == system->getName()))
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
row.elements.clear();
|
|
|
|
row.addElement(std::make_shared<TextComponent>(mWindow, "ADD/REMOVE GAMES TO THIS GAME COLLECTION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
|
|
|
row.makeAcceptInputHandler(std::bind(&GuiGamelistOptions::startEditMode, this));
|
|
|
|
mMenu.addRow(row);
|
|
|
|
}
|
|
|
|
|
2017-11-18 22:23:56 +00:00
|
|
|
if(UIModeController::getInstance()->isUIModeFull() && CollectionSystemManager::get()->isEditing())
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
row.elements.clear();
|
|
|
|
row.addElement(std::make_shared<TextComponent>(mWindow, "FINISH EDITING '" + strToUpper(CollectionSystemManager::get()->getEditingCollection()) + "' COLLECTION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
|
|
|
row.makeAcceptInputHandler(std::bind(&GuiGamelistOptions::exitEditMode, this));
|
|
|
|
mMenu.addRow(row);
|
|
|
|
}
|
|
|
|
|
2017-11-18 22:23:56 +00:00
|
|
|
if (UIModeController::getInstance()->isUIModeFull() && !fromPlaceholder && !(mSystem->isCollection() && file->getType() == FOLDER))
|
2017-09-08 14:49:47 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
row.elements.clear();
|
|
|
|
row.addElement(std::make_shared<TextComponent>(mWindow, "EDIT THIS GAME'S METADATA", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
|
|
|
row.addElement(makeArrow(mWindow), false);
|
|
|
|
row.makeAcceptInputHandler(std::bind(&GuiGamelistOptions::openMetaDataEd, this));
|
|
|
|
mMenu.addRow(row);
|
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
// center the menu
|
|
|
|
setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
|
|
|
mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, (mSize.y() - mMenu.getSize().y()) / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiGamelistOptions::~GuiGamelistOptions()
|
|
|
|
{
|
|
|
|
// apply sort
|
2017-03-18 17:54:39 +00:00
|
|
|
if (!fromPlaceholder) {
|
2017-07-18 09:45:50 +00:00
|
|
|
FileData* root = mSystem->getRootFolder();
|
2017-03-18 17:54:39 +00:00
|
|
|
root->sort(*mListSort->getSelected()); // will also recursively sort children
|
|
|
|
|
|
|
|
// notify that the root folder was sorted
|
|
|
|
getGamelist()->onFileChanged(root, FILE_SORTED);
|
2017-05-18 10:16:57 +00:00
|
|
|
}
|
|
|
|
if (mFiltersChanged)
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
// only reload full view if we came from a placeholder
|
|
|
|
// as we need to re-display the remaining elements for whatever new
|
|
|
|
// game is selected
|
|
|
|
ViewController::get()->reloadGameListView(mSystem);
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
void GuiGamelistOptions::openGamelistFilter()
|
|
|
|
{
|
|
|
|
mFiltersChanged = true;
|
|
|
|
GuiGamelistFilter* ggf = new GuiGamelistFilter(mWindow, mSystem);
|
|
|
|
mWindow->pushGui(ggf);
|
2017-05-18 10:16:57 +00:00
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
void GuiGamelistOptions::startEditMode()
|
|
|
|
{
|
|
|
|
std::string editingSystem = mSystem->getName();
|
|
|
|
// need to check if we're editing the collections bundle, as we will want to edit the selected collection within
|
|
|
|
if(editingSystem == CollectionSystemManager::get()->getCustomCollectionsBundle()->getName())
|
|
|
|
{
|
|
|
|
FileData* file = getGamelist()->getCursor();
|
|
|
|
// do we have the cursor on a specific collection?
|
|
|
|
if (file->getType() == FOLDER)
|
|
|
|
{
|
|
|
|
editingSystem = file->getName();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// we are inside a specific collection. We want to edit that one.
|
|
|
|
editingSystem = file->getSystem()->getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CollectionSystemManager::get()->setEditMode(editingSystem);
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiGamelistOptions::exitEditMode()
|
|
|
|
{
|
|
|
|
CollectionSystemManager::get()->exitEditMode();
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
void GuiGamelistOptions::openMetaDataEd()
|
|
|
|
{
|
|
|
|
// open metadata editor
|
2017-06-12 16:38:59 +00:00
|
|
|
// get the FileData that hosts the original metadata
|
|
|
|
FileData* file = getGamelist()->getCursor()->getSourceFileData();
|
2014-06-25 16:29:58 +00:00
|
|
|
ScraperSearchParams p;
|
|
|
|
p.game = file;
|
|
|
|
p.system = file->getSystem();
|
2017-04-03 07:08:14 +00:00
|
|
|
|
|
|
|
std::function<void()> deleteBtnFunc;
|
|
|
|
|
|
|
|
if (file->getType() == FOLDER)
|
|
|
|
{
|
|
|
|
deleteBtnFunc = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
deleteBtnFunc = [this, file] {
|
2017-06-12 16:38:59 +00:00
|
|
|
CollectionSystemManager::get()->deleteCollectionFiles(file);
|
|
|
|
ViewController::get()->getGameListView(file->getSystem()).get()->remove(file, true);
|
2017-04-03 07:08:14 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-05-18 10:16:57 +00:00
|
|
|
mWindow->pushGui(new GuiMetaDataEd(mWindow, &file->metadata, file->metadata.getMDD(), p, file->getPath().filename().string(),
|
2017-06-12 16:38:59 +00:00
|
|
|
std::bind(&IGameListView::onFileChanged, ViewController::get()->getGameListView(file->getSystem()).get(), file, FILE_METADATA_CHANGED), deleteBtnFunc));
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2014-07-27 22:49:43 +00:00
|
|
|
void GuiGamelistOptions::jumpToLetter()
|
|
|
|
{
|
|
|
|
char letter = mJumpToLetterList->getSelected();
|
|
|
|
IGameListView* gamelist = getGamelist();
|
|
|
|
|
|
|
|
// this is a really shitty way to get a list of files
|
2017-11-03 11:11:11 +00:00
|
|
|
const std::vector<FileData*>& files = gamelist->getCursor()->getParent()->getChildrenListToDisplay();
|
2017-05-18 10:16:57 +00:00
|
|
|
|
2014-07-27 22:49:43 +00:00
|
|
|
long min = 0;
|
2017-11-17 14:58:52 +00:00
|
|
|
long max = (long)files.size() - 1;
|
2014-07-27 22:49:43 +00:00
|
|
|
long mid = 0;
|
|
|
|
|
|
|
|
while(max >= min)
|
|
|
|
{
|
|
|
|
mid = ((max - min) / 2) + min;
|
|
|
|
|
|
|
|
// game somehow has no first character to check
|
|
|
|
if(files.at(mid)->getName().empty())
|
|
|
|
continue;
|
|
|
|
|
2017-11-17 14:58:52 +00:00
|
|
|
char checkLetter = (char)toupper(files.at(mid)->getName()[0]);
|
2014-07-27 22:49:43 +00:00
|
|
|
|
|
|
|
if(checkLetter < letter)
|
|
|
|
min = mid + 1;
|
2017-03-13 18:16:57 +00:00
|
|
|
else if(checkLetter > letter || (mid > 0 && (letter == toupper(files.at(mid - 1)->getName()[0]))))
|
2014-07-27 22:49:43 +00:00
|
|
|
max = mid - 1;
|
|
|
|
else
|
|
|
|
break; //exact match found
|
|
|
|
}
|
|
|
|
|
|
|
|
gamelist->setCursor(files.at(mid));
|
|
|
|
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
bool GuiGamelistOptions::input(InputConfig* config, Input input)
|
|
|
|
{
|
|
|
|
if((config->isMappedTo("b", input) || config->isMappedTo("select", input)) && input.value)
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mMenu.input(config, input);
|
|
|
|
}
|
|
|
|
|
2017-05-28 18:13:00 +00:00
|
|
|
HelpStyle GuiGamelistOptions::getHelpStyle()
|
|
|
|
{
|
|
|
|
HelpStyle style = HelpStyle();
|
|
|
|
style.applyTheme(mSystem->getTheme(), "system");
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
std::vector<HelpPrompt> GuiGamelistOptions::getHelpPrompts()
|
|
|
|
{
|
|
|
|
auto prompts = mMenu.getHelpPrompts();
|
|
|
|
prompts.push_back(HelpPrompt("b", "close"));
|
|
|
|
return prompts;
|
|
|
|
}
|
|
|
|
|
|
|
|
IGameListView* GuiGamelistOptions::getGamelist()
|
|
|
|
{
|
|
|
|
return ViewController::get()->getGameListView(mSystem).get();
|
|
|
|
}
|