From b4feb6998070d7d8429a4b5924e15547680188aa Mon Sep 17 00:00:00 2001 From: Koerty Date: Thu, 22 Mar 2018 08:03:12 +0100 Subject: [PATCH] Enable the grid view for developers - Add the remove function to GridGameListView - Enable the grid view in ViewController - The grid view will not be available in the menu yet, but can be enable by tweaking es_settings.cfg --- es-app/src/guis/GuiMenu.cpp | 5 +++ es-app/src/views/ViewController.cpp | 9 +++-- es-app/src/views/ViewController.h | 2 +- .../src/views/gamelist/GridGameListView.cpp | 37 +++++++++++++++++++ es-app/src/views/gamelist/GridGameListView.h | 2 + es-core/src/ThemeData.cpp | 2 +- 6 files changed, 52 insertions(+), 5 deletions(-) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 86fd9538b..52aee19ae 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -273,6 +273,11 @@ void GuiMenu::openUISettings() styles.push_back("basic"); styles.push_back("detailed"); styles.push_back("video"); + + // Temporary "hack" so ES don't crash when leaving this menu after he enabled the grid by tweaking config file + if (Settings::getInstance()->getString("GamelistViewStyle") == "grid") + styles.push_back("grid"); + for (auto it = styles.cbegin(); it != styles.cend(); it++) gamelist_style->add(*it, *it, Settings::getInstance()->getString("GamelistViewStyle") == *it); s->addWithLabel("GAMELIST VIEW STYLE", gamelist_style); diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 0647f9193..44aeee195 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -7,6 +7,7 @@ #include "guis/GuiMenu.h" #include "views/gamelist/DetailedGameListView.h" #include "views/gamelist/IGameListView.h" +#include "views/gamelist/GridGameListView.h" #include "views/gamelist/VideoGameListView.h" #include "views/SystemView.h" #include "views/UIModeController.h" @@ -283,6 +284,8 @@ std::shared_ptr ViewController::getGameListView(SystemData* syste selectedViewType = BASIC; if (viewPreference.compare("detailed") == 0) selectedViewType = DETAILED; + if (viewPreference.compare("grid") == 0) + selectedViewType = GRID; if (viewPreference.compare("video") == 0) selectedViewType = VIDEO; @@ -313,9 +316,9 @@ std::shared_ptr ViewController::getGameListView(SystemData* syste case DETAILED: view = std::shared_ptr(new DetailedGameListView(mWindow, system->getRootFolder())); break; - // case GRID placeholder for future implementation. - // view = std::shared_ptr(new GridGameListView(mWindow, system->getRootFolder())); - // break; + case GRID: + view = std::shared_ptr(new GridGameListView(mWindow, system->getRootFolder())); + break; case BASIC: default: view = std::shared_ptr(new BasicGameListView(mWindow, system->getRootFolder())); diff --git a/es-app/src/views/ViewController.h b/es-app/src/views/ViewController.h index 10210ee7c..eec5e9fdb 100644 --- a/es-app/src/views/ViewController.h +++ b/es-app/src/views/ViewController.h @@ -61,8 +61,8 @@ public: AUTOMATIC, BASIC, DETAILED, + GRID, VIDEO - // GRID TODO! }; struct State diff --git a/es-app/src/views/gamelist/GridGameListView.cpp b/es-app/src/views/gamelist/GridGameListView.cpp index 82a916f3e..b7fa1d032 100644 --- a/es-app/src/views/gamelist/GridGameListView.cpp +++ b/es-app/src/views/gamelist/GridGameListView.cpp @@ -1,6 +1,7 @@ #include "views/gamelist/GridGameListView.h" #include "views/ViewController.h" +#include "SystemData.h" GridGameListView::GridGameListView(Window* window, FileData* root) : ISimpleGameListView(window, root), mGrid(window) @@ -43,11 +44,47 @@ void GridGameListView::populateList(const std::vector& files) } } +void GridGameListView::addPlaceholder() +{ + // empty grid - add a placeholder + FileData* placeholder = new FileData(PLACEHOLDER, "", this->mRoot->getSystem()->getSystemEnvData(), this->mRoot->getSystem()); + mGrid.add(placeholder->getName(), "", placeholder); +} + void GridGameListView::launch(FileData* game) { ViewController::get()->launch(game); } +void GridGameListView::remove(FileData *game, bool deleteFile) +{ + if (deleteFile) + Utils::FileSystem::removeFile(game->getPath()); // actually delete the file on the filesystem + FileData* parent = game->getParent(); + if (getCursor() == game) // Select next element in list, or prev if none + { + std::vector siblings = parent->getChildrenListToDisplay(); + auto gameIter = std::find(siblings.cbegin(), siblings.cend(), game); + int gamePos = (int)std::distance(siblings.cbegin(), gameIter); + if (gameIter != siblings.cend()) + { + if ((gamePos + 1) < siblings.size()) + { + setCursor(siblings.at(gamePos + 1)); + } else if ((gamePos - 1) > 0) { + setCursor(siblings.at(gamePos - 1)); + } + } + } + mGrid.remove(game); + if(mGrid.size() == 0) + { + addPlaceholder(); + } + delete game; // remove before repopulating (removes from parent) + onFileChanged(parent, FILE_REMOVED); // update the view, with game removed +} + std::vector GridGameListView::getHelpPrompts() { std::vector prompts; diff --git a/es-app/src/views/gamelist/GridGameListView.h b/es-app/src/views/gamelist/GridGameListView.h index b5072cdfe..a6ded9028 100644 --- a/es-app/src/views/gamelist/GridGameListView.h +++ b/es-app/src/views/gamelist/GridGameListView.h @@ -24,6 +24,8 @@ public: protected: virtual void populateList(const std::vector& files) override; + virtual void remove(FileData* game, bool deleteFile) override; + virtual void addPlaceholder(); ImageGridComponent mGrid; }; diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 63dc72b23..5ce54cf9a 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -9,7 +9,7 @@ #include #include -std::vector ThemeData::sSupportedViews { { "system" }, { "basic" }, { "detailed" }, { "video" } }; +std::vector ThemeData::sSupportedViews { { "system" }, { "basic" }, { "detailed" }, { "grid" }, { "video" } }; std::vector ThemeData::sSupportedFeatures { { "video" }, { "carousel" }, { "z-index" } }; std::map> ThemeData::sElementMap {