From 9acfda6e1af1ca73008c9ebf6b9b1d2fd3e09414 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 5 Apr 2014 00:41:08 -0500 Subject: [PATCH] New "GuiGamelistOptions" to replace fast select. --- CMakeLists.txt | 2 + src/guis/GuiGamelistOptions.cpp | 76 ++++++++++++++++++++++++ src/guis/GuiGamelistOptions.h | 27 +++++++++ src/views/gamelist/BasicGameListView.cpp | 5 +- src/views/gamelist/IGameListView.cpp | 27 +++------ 5 files changed, 115 insertions(+), 22 deletions(-) create mode 100644 src/guis/GuiGamelistOptions.cpp create mode 100644 src/guis/GuiGamelistOptions.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a777915f7..7470bd21a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/guis/GuiGamelistOptions.cpp b/src/guis/GuiGamelistOptions.cpp new file mode 100644 index 000000000..658be0d7d --- /dev/null +++ b/src/guis/GuiGamelistOptions.cpp @@ -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(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(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 GuiGamelistOptions::getHelpPrompts() +{ + auto prompts = mMenu.getHelpPrompts(); + prompts.push_back(HelpPrompt("b", "close")); + return prompts; +} diff --git a/src/guis/GuiGamelistOptions.h b/src/guis/GuiGamelistOptions.h new file mode 100644 index 000000000..eef60bd7e --- /dev/null +++ b/src/guis/GuiGamelistOptions.h @@ -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 getHelpPrompts() override; + +private: + void openMetaDataEd(); + + MenuComponent mMenu; + + typedef OptionListComponent SortList; + std::shared_ptr mListSort; + + IGameListView* mGamelist; +}; diff --git a/src/views/gamelist/BasicGameListView.cpp b/src/views/gamelist/BasicGameListView.cpp index 4d4dc8e93..75bf2b8c5 100644 --- a/src/views/gamelist/BasicGameListView.cpp +++ b/src/views/gamelist/BasicGameListView.cpp @@ -68,9 +68,10 @@ void BasicGameListView::launch(FileData* game) std::vector BasicGameListView::getHelpPrompts() { std::vector 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; } diff --git a/src/views/gamelist/IGameListView.cpp b/src/views/gamelist/IGameListView.cpp index f8aad2629..8a46bef29 100644 --- a/src/views/gamelist/IGameListView.cpp +++ b/src/views/gamelist/IGameListView.cpp @@ -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);