New "GuiGamelistOptions" to replace fast select.

This commit is contained in:
Aloshi 2014-04-05 00:41:08 -05:00
parent c1385d4834
commit 9acfda6e1a
5 changed files with 115 additions and 22 deletions

View file

@ -187,6 +187,7 @@ set(ES_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMetaDataEd.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMsgBox.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiGameScraper.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiGamelistOptions.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInputConfig.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMenu.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiSettings.h
@ -272,6 +273,7 @@ set(ES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMetaDataEd.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMsgBox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiGameScraper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiGamelistOptions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInputConfig.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMenu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiSettings.cpp

View file

@ -0,0 +1,76 @@
#include "GuiGamelistOptions.h"
#include "GuiMetaDataEd.h"
#include "../views/gamelist/IGameListView.h"
GuiGamelistOptions::GuiGamelistOptions(Window* window, IGameListView* gamelist) : GuiComponent(window),
mGamelist(gamelist),
mMenu(window, "OPTIONS")
{
addChild(&mMenu);
// 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
}
mMenu.addWithLabel("SORT GAMES BY", mListSort);
// edit game metadata
ComponentListRow row;
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);
// 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
FileData* root = mGamelist->getCursor()->getSystem()->getRootFolder();
root->sort(*mListSort->getSelected()); // will also recursively sort children
// notify that the root folder was sorted
mGamelist->onFileChanged(root, FILE_SORTED);
}
void GuiGamelistOptions::openMetaDataEd()
{
// open metadata editor
FileData* file = mGamelist->getCursor();
ScraperSearchParams p;
p.game = file;
p.system = file->getSystem();
mWindow->pushGui(new GuiMetaDataEd(mWindow, &file->metadata, file->metadata.getMDD(), p, file->getPath().filename().string(),
std::bind(&IGameListView::onFileChanged, mGamelist, file, FILE_METADATA_CHANGED), [this, file] {
boost::filesystem::remove(file->getPath()); //actually delete the file on the filesystem
file->getParent()->removeChild(file); //unlink it so list repopulations triggered from onFileChanged won't see it
mGamelist->onFileChanged(file, FILE_REMOVED); //tell the view
delete file; //free it
}));
delete this;
}
bool GuiGamelistOptions::input(InputConfig* config, Input input)
{
if(config->isMappedTo("b", input) && input.value)
{
delete this;
return true;
}
return mMenu.input(config, input);
}
std::vector<HelpPrompt> GuiGamelistOptions::getHelpPrompts()
{
auto prompts = mMenu.getHelpPrompts();
prompts.push_back(HelpPrompt("b", "close"));
return prompts;
}

View file

@ -0,0 +1,27 @@
#include "../GuiComponent.h"
#include "../components/MenuComponent.h"
#include "../components/OptionListComponent.h"
#include "../FileSorts.h"
class IGameListView;
class GuiGamelistOptions : public GuiComponent
{
public:
GuiGamelistOptions(Window* window, IGameListView* gamelist);
virtual ~GuiGamelistOptions();
virtual bool input(InputConfig* config, Input input) override;
virtual std::vector<HelpPrompt> getHelpPrompts() override;
private:
void openMetaDataEd();
MenuComponent mMenu;
typedef OptionListComponent<const FileData::SortType*> SortList;
std::shared_ptr<SortList> mListSort;
IGameListView* mGamelist;
};

View file

@ -68,9 +68,10 @@ void BasicGameListView::launch(FileData* game)
std::vector<HelpPrompt> BasicGameListView::getHelpPrompts()
{
std::vector<HelpPrompt> prompts;
prompts.push_back(HelpPrompt("left/right", "switch"));
prompts.push_back(HelpPrompt("left/right", "system"));
prompts.push_back(HelpPrompt("up/down", "choose"));
prompts.push_back(HelpPrompt("a", "play"));
prompts.push_back(HelpPrompt("a", "launch"));
prompts.push_back(HelpPrompt("b", "back"));
prompts.push_back(HelpPrompt("select", "options"));
return prompts;
}

View file

@ -2,7 +2,7 @@
#include "../../Window.h"
#include "../../guis/GuiMetaDataEd.h"
#include "../../guis/GuiMenu.h"
#include "../../guis/GuiFastSelect.h"
#include "../../guis/GuiGamelistOptions.h"
#include "../ViewController.h"
#include "../../Settings.h"
#include "../../Log.h"
@ -13,19 +13,13 @@ bool IGameListView::input(InputConfig* config, Input input)
// F3 to open metadata editor
if(config->getDeviceId() == DEVICE_KEYBOARD && input.id == SDLK_F3 && input.value != 0)
{
// open metadata editor
FileData* file = getCursor();
ScraperSearchParams p;
p.game = file;
p.system = file->getSystem();
mWindow->pushGui(new GuiMetaDataEd(mWindow, &file->metadata, file->metadata.getMDD(), p, file->getPath().filename().string(),
std::bind(&IGameListView::onFileChanged, this, file, FILE_METADATA_CHANGED), [file, this] {
boost::filesystem::remove(file->getPath()); //actually delete the file on the filesystem
file->getParent()->removeChild(file); //unlink it so list repopulations triggered from onFileChanged won't see it
onFileChanged(file, FILE_REMOVED); //tell the view
delete file; //free it
}));
// select to open GuiGamelistOptions
}else if(config->isMappedTo("select", input) && input.value)
{
Sound::getFromTheme(mTheme, getName(), "menuOpen")->play();
mWindow->pushGui(new GuiGamelistOptions(mWindow, this));
return true;
// Ctrl-R to reload a view when debugging
@ -35,13 +29,6 @@ bool IGameListView::input(InputConfig* config, Input input)
LOG(LogDebug) << "reloading view";
mWindow->getViewController()->reloadGameListView(this, true);
return true;
// select opens the fast select GUI
}else if(config->isMappedTo("select", input) && input.value != 0)
{
// open fast select
Sound::getFromTheme(mTheme, getName(), "menuOpen")->play();
mWindow->pushGui(new GuiFastSelect(mWindow, this));
return true;
}
return GuiComponent::input(config, input);