From 2f02ebeada96abe7aded06271a509d57e4064630 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Fri, 16 May 2014 17:40:58 -0500 Subject: [PATCH] Fixed crash when gamelist view gets recreated while GuiGamelistOptions is open. Ugly hack to fix it, but it will probably get rewritten in the future anyway. --- src/guis/GuiGamelistOptions.cpp | 20 +++++++++++++------- src/guis/GuiGamelistOptions.h | 5 +++-- src/views/SystemView.cpp | 2 +- src/views/ViewController.h | 6 +++--- src/views/gamelist/IGameListView.cpp | 9 ++------- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/guis/GuiGamelistOptions.cpp b/src/guis/GuiGamelistOptions.cpp index f1287e856..1b18d0c49 100644 --- a/src/guis/GuiGamelistOptions.cpp +++ b/src/guis/GuiGamelistOptions.cpp @@ -1,9 +1,10 @@ #include "GuiGamelistOptions.h" #include "GuiMetaDataEd.h" #include "../views/gamelist/IGameListView.h" +#include "../views/ViewController.h" -GuiGamelistOptions::GuiGamelistOptions(Window* window, IGameListView* gamelist) : GuiComponent(window), - mGamelist(gamelist), +GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : GuiComponent(window), + mSystem(system), mMenu(window, "OPTIONS") { addChild(&mMenu); @@ -33,25 +34,25 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, IGameListView* gamelist) GuiGamelistOptions::~GuiGamelistOptions() { // apply sort - FileData* root = mGamelist->getCursor()->getSystem()->getRootFolder(); + FileData* root = getGamelist()->getCursor()->getSystem()->getRootFolder(); root->sort(*mListSort->getSelected()); // will also recursively sort children // notify that the root folder was sorted - mGamelist->onFileChanged(root, FILE_SORTED); + getGamelist()->onFileChanged(root, FILE_SORTED); } void GuiGamelistOptions::openMetaDataEd() { // open metadata editor - FileData* file = mGamelist->getCursor(); + FileData* file = getGamelist()->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] { + std::bind(&IGameListView::onFileChanged, getGamelist(), 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 + getGamelist()->onFileChanged(file, FILE_REMOVED); //tell the view delete file; //free it })); } @@ -73,3 +74,8 @@ std::vector GuiGamelistOptions::getHelpPrompts() prompts.push_back(HelpPrompt("b", "close")); return prompts; } + +IGameListView* GuiGamelistOptions::getGamelist() +{ + return mWindow->getViewController()->getGameListView(mSystem).get(); +} diff --git a/src/guis/GuiGamelistOptions.h b/src/guis/GuiGamelistOptions.h index eef60bd7e..fe9b477ba 100644 --- a/src/guis/GuiGamelistOptions.h +++ b/src/guis/GuiGamelistOptions.h @@ -9,7 +9,7 @@ class IGameListView; class GuiGamelistOptions : public GuiComponent { public: - GuiGamelistOptions(Window* window, IGameListView* gamelist); + GuiGamelistOptions(Window* window, SystemData* system); virtual ~GuiGamelistOptions(); virtual bool input(InputConfig* config, Input input) override; @@ -23,5 +23,6 @@ private: typedef OptionListComponent SortList; std::shared_ptr mListSort; - IGameListView* mGamelist; + SystemData* mSystem; + IGameListView* getGamelist(); }; diff --git a/src/views/SystemView.cpp b/src/views/SystemView.cpp index db1a5fa6c..a512683ca 100644 --- a/src/views/SystemView.cpp +++ b/src/views/SystemView.cpp @@ -19,7 +19,7 @@ SystemView::SystemView(Window* window) : IList(wind setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); - mSystemInfo.setSize(mSize.x(), mSystemInfo.getSize().y() * 2.f); + mSystemInfo.setSize(mSize.x(), mSystemInfo.getSize().y() * 1.333f); mSystemInfo.setPosition(0, (mSize.y() + BAND_HEIGHT) / 2); populate(); diff --git a/src/views/ViewController.h b/src/views/ViewController.h index ad7882c8e..1eff1696c 100644 --- a/src/views/ViewController.h +++ b/src/views/ViewController.h @@ -61,12 +61,12 @@ public: virtual std::vector getHelpPrompts() override; + std::shared_ptr getGameListView(SystemData* system); + std::shared_ptr getSystemListView(); + private: void playViewTransition(); int getSystemId(SystemData* system); - - std::shared_ptr getGameListView(SystemData* system); - std::shared_ptr getSystemListView(); std::shared_ptr mCurrentView; std::map< SystemData*, std::shared_ptr > mGameListViews; diff --git a/src/views/gamelist/IGameListView.cpp b/src/views/gamelist/IGameListView.cpp index 8a46bef29..dc2c39d62 100644 --- a/src/views/gamelist/IGameListView.cpp +++ b/src/views/gamelist/IGameListView.cpp @@ -10,16 +10,11 @@ bool IGameListView::input(InputConfig* config, Input input) { - // F3 to open metadata editor - if(config->getDeviceId() == DEVICE_KEYBOARD && input.id == SDLK_F3 && input.value != 0) - { - - // select to open GuiGamelistOptions - }else if(config->isMappedTo("select", input) && input.value) + if(config->isMappedTo("select", input) && input.value) { Sound::getFromTheme(mTheme, getName(), "menuOpen")->play(); - mWindow->pushGui(new GuiGamelistOptions(mWindow, this)); + mWindow->pushGui(new GuiGamelistOptions(mWindow, this->mRoot->getSystem())); return true; // Ctrl-R to reload a view when debugging