From 6f442556c082fac778f456b560f868cd3c3712d9 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Tue, 24 Dec 2013 11:50:26 -0600 Subject: [PATCH] Refactored SystemListView directly into ViewController. Made system views match up with their gamelist views. Pressing "back" on a gamelist view now takes you to the correct system view. --- CMakeLists.txt | 2 - src/SystemData.h | 19 +++ src/components/GuiInputConfig.cpp | 2 +- src/main.cpp | 2 +- src/views/SystemListView.cpp | 79 ------------- src/views/SystemListView.h | 23 ---- src/views/SystemView.cpp | 26 ++++ src/views/SystemView.h | 2 + src/views/ViewController.cpp | 131 ++++++++++----------- src/views/ViewController.h | 12 +- src/views/gamelist/ISimpleGameListView.cpp | 2 +- 11 files changed, 118 insertions(+), 182 deletions(-) delete mode 100644 src/views/SystemListView.cpp delete mode 100644 src/views/SystemListView.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a23c16793..dafd0fd26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,7 +198,6 @@ set(ES_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/views/gamelist/IGameListView.h ${CMAKE_CURRENT_SOURCE_DIR}/src/views/gamelist/ISimpleGameListView.h ${CMAKE_CURRENT_SOURCE_DIR}/src/views/gamelist/GridGameListView.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/views/SystemListView.h ${CMAKE_CURRENT_SOURCE_DIR}/src/views/SystemView.h ${CMAKE_CURRENT_SOURCE_DIR}/src/views/ViewController.h @@ -277,7 +276,6 @@ set(ES_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/views/gamelist/IGameListView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/views/gamelist/ISimpleGameListView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/views/gamelist/GridGameListView.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/views/SystemListView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/views/SystemView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/views/ViewController.cpp diff --git a/src/SystemData.h b/src/SystemData.h index ca6e5bed0..901b3756d 100644 --- a/src/SystemData.h +++ b/src/SystemData.h @@ -39,6 +39,25 @@ public: static std::vector sSystemVector; + inline std::vector::const_iterator getIterator() const { return std::find(sSystemVector.begin(), sSystemVector.end(), this); }; + inline std::vector::const_reverse_iterator getRevIterator() const { return std::find(sSystemVector.rbegin(), sSystemVector.rend(), this); }; + + inline SystemData* getNext() const + { + auto it = getIterator(); + it++; + if(it == sSystemVector.end()) it = sSystemVector.begin(); + return *it; + } + + inline SystemData* getPrev() const + { + auto it = getRevIterator(); + it++; + if(it == sSystemVector.rend()) it = sSystemVector.rbegin(); + return *it; + } + private: std::string mName; std::string mFullName; diff --git a/src/components/GuiInputConfig.cpp b/src/components/GuiInputConfig.cpp index c09fbad05..b57cfac52 100644 --- a/src/components/GuiInputConfig.cpp +++ b/src/components/GuiInputConfig.cpp @@ -38,7 +38,7 @@ bool GuiInputConfig::input(InputConfig* config, Input input) mWindow->pushGui(new GuiInputConfig(mWindow, mWindow->getInputManager()->getInputConfigByPlayer(mTargetConfig->getPlayerNum() + 1))); }else{ mWindow->getInputManager()->writeConfig(); - mWindow->getViewController()->goToSystemSelect(); + mWindow->getViewController()->goToStart(); } delete this; return true; diff --git a/src/main.cpp b/src/main.cpp index 0f6524b6c..2a43f2e18 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -172,7 +172,7 @@ int main(int argc, char* argv[]) //choose which GUI to open depending on if an input configuration already exists if(fs::exists(InputManager::getConfigPath())) { - window.getViewController()->goToSystemSelect(); + window.getViewController()->goToStart(); }else{ window.pushGui(new GuiDetectDevice(&window)); } diff --git a/src/views/SystemListView.cpp b/src/views/SystemListView.cpp deleted file mode 100644 index 424fdc43a..000000000 --- a/src/views/SystemListView.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "SystemListView.h" -#include "../Renderer.h" -#include "../SystemData.h" -#include "../animations/MoveCameraAnimation.h" -#include "../Window.h" -#include "ViewController.h" - -SystemListView::SystemListView(Window* window) : GuiComponent(window), mCamera(Eigen::Affine3f::Identity()), mCurrentSystem(NULL) -{ - setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); - - goToSystem(SystemData::sSystemVector.at(0)); -} - -void SystemListView::goToSystem(SystemData* system) -{ - std::shared_ptr view = getSystemView(system); - mCurrentView = view; - mCurrentSystem = system; - setAnimation(new MoveCameraAnimation(mCamera, view->getPosition())); -} - - -std::shared_ptr SystemListView::getSystemView(SystemData* system) -{ - auto exists = mSystemViews.find(system); - if(exists != mSystemViews.end()) - return exists->second; - - const std::vector& sysVec = SystemData::sSystemVector; - int id = std::find(sysVec.begin(), sysVec.end(), system) - sysVec.begin(); - - std::shared_ptr view = std::shared_ptr(new SystemView(mWindow, system)); - view->setPosition(id * (float)Renderer::getScreenWidth(), 0); - - mSystemViews[system] = view; - - return view; -} - -bool SystemListView::input(InputConfig* config, Input input) -{ - if(input.value != 0) - { - int id = std::find(SystemData::sSystemVector.begin(), SystemData::sSystemVector.end(), mCurrentSystem) - SystemData::sSystemVector.begin(); - if(config->isMappedTo("left", input)) - { - id--; - if(id < 0) - id += SystemData::sSystemVector.size(); - goToSystem(SystemData::sSystemVector.at(id)); - return true; - } - if(config->isMappedTo("right", input)) - { - id = (id + 1) % SystemData::sSystemVector.size(); - goToSystem(SystemData::sSystemVector.at(id)); - return true; - } - if(config->isMappedTo("a", input)) - { - mWindow->getViewController()->goToGameList(mCurrentSystem); - return true; - } - } - - return GuiComponent::input(config, input); -} - -void SystemListView::render(const Eigen::Affine3f& parentTrans) -{ - Eigen::Affine3f trans = mCamera * getTransform() * parentTrans; - - // TODO: clipping - for(auto it = mSystemViews.begin(); it != mSystemViews.end(); it++) - { - it->second->render(trans); - } -} diff --git a/src/views/SystemListView.h b/src/views/SystemListView.h deleted file mode 100644 index 7fe685c89..000000000 --- a/src/views/SystemListView.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "SystemView.h" - -class SystemListView : public GuiComponent -{ -public: - SystemListView(Window* window); - - void goToSystem(SystemData* system); - - bool input(InputConfig* config, Input input) override; - void render(const Eigen::Affine3f& parentTrans) override; - -private: - Eigen::Affine3f mCamera; - - std::shared_ptr mCurrentView; - SystemData* mCurrentSystem; - std::shared_ptr getSystemView(SystemData* system); - - std::map< SystemData*, std::shared_ptr > mSystemViews; -}; diff --git a/src/views/SystemView.cpp b/src/views/SystemView.cpp index b1f0a5902..e1501d140 100644 --- a/src/views/SystemView.cpp +++ b/src/views/SystemView.cpp @@ -2,6 +2,8 @@ #include "../SystemData.h" #include "../Renderer.h" #include "../Log.h" +#include "../Window.h" +#include "ViewController.h" SystemView::SystemView(Window* window, SystemData* system) : GuiComponent(window), mSystem(system), @@ -47,3 +49,27 @@ void SystemView::updateData() mImage.setImage(mSystem->getTheme()->getImage("systemImage").getTexture()); } + +bool SystemView::input(InputConfig* config, Input input) +{ + if(input.value != 0) + { + if(config->isMappedTo("left", input)) + { + mWindow->getViewController()->goToSystemView(mSystem->getPrev()); + return true; + } + if(config->isMappedTo("right", input)) + { + mWindow->getViewController()->goToSystemView(mSystem->getNext()); + return true; + } + if(config->isMappedTo("a", input)) + { + mWindow->getViewController()->goToGameList(mSystem); + return true; + } + } + + return GuiComponent::input(config, input); +} diff --git a/src/views/SystemView.h b/src/views/SystemView.h index 762591cac..a926285c0 100644 --- a/src/views/SystemView.h +++ b/src/views/SystemView.h @@ -14,6 +14,8 @@ public: void updateData(); + bool input(InputConfig* config, Input input) override; + private: SystemData* mSystem; diff --git a/src/views/ViewController.cpp b/src/views/ViewController.cpp index ddb09f383..fc84b8e94 100644 --- a/src/views/ViewController.cpp +++ b/src/views/ViewController.cpp @@ -15,58 +15,39 @@ ViewController::ViewController(Window* window) { // slot 1 so the fade carries over setAnimation(new LambdaAnimation([&] (float t) { mFadeOpacity = lerp(1.0f, 0.0f, t); }, 900), nullptr, false, 1); - mState.viewing = START_SCREEN; + mState.viewing = NOTHING; } -void ViewController::goToSystemSelect() +void ViewController::goToStart() +{ + // TODO + /* mState.viewing = START_SCREEN; + mCurrentView.reset(); + playViewTransition(); */ + goToSystemView(SystemData::sSystemVector.at(0)); +} + +void ViewController::goToSystemView(SystemData* system) { mState.viewing = SYSTEM_SELECT; - mCurrentView = getSystemListView(); + mCurrentView = getSystemView(system); playViewTransition(); } -SystemData* getSystemCyclic(SystemData* from, bool reverse) -{ - std::vector& sysVec = SystemData::sSystemVector; - - if(reverse) - { - auto it = std::find(sysVec.rbegin(), sysVec.rend(), from); - assert(it != sysVec.rend()); - it++; - if(it == sysVec.rend()) - it = sysVec.rbegin(); - return *it; - }else{ - auto it = std::find(sysVec.begin(), sysVec.end(), from); - assert(it != sysVec.end()); - it++; - if(it == sysVec.end()) - it = sysVec.begin(); - return *it; - } -} - void ViewController::goToNextGameList() { assert(mState.viewing == GAME_LIST); - - SystemData* system = mState.data.system; - if(system == NULL) - return; - - goToGameList(getSystemCyclic(system, false)); + SystemData* system = getState().getSystem(); + assert(system); + goToGameList(system->getNext()); } void ViewController::goToPrevGameList() { assert(mState.viewing == GAME_LIST); - - SystemData* system = mState.data.system; - if(system == NULL) - return; - - goToGameList(getSystemCyclic(system, true)); + SystemData* system = getState().getSystem(); + assert(system); + goToGameList(system->getPrev()); } void ViewController::goToGameList(SystemData* system) @@ -80,7 +61,10 @@ void ViewController::goToGameList(SystemData* system) void ViewController::playViewTransition() { - setAnimation(new MoveCameraAnimation(mCamera, mCurrentView->getPosition())); + Eigen::Vector3f target(Eigen::Vector3f::Identity()); + if(mCurrentView) + target = mCurrentView->getPosition(); + setAnimation(new MoveCameraAnimation(mCamera, target)); } void ViewController::onFileChanged(FileData* file, FileChangeType change) @@ -126,32 +110,27 @@ std::shared_ptr ViewController::getGameListView(SystemData* syste //if we didn't, make it, remember it, and return it std::shared_ptr view; - if(system != NULL) + //decide type + bool detailed = false; + std::vector files = system->getRootFolder()->getFilesRecursive(GAME | FOLDER); + for(auto it = files.begin(); it != files.end(); it++) { - //decide type - bool detailed = false; - std::vector files = system->getRootFolder()->getFilesRecursive(GAME | FOLDER); - for(auto it = files.begin(); it != files.end(); it++) + if(!(*it)->getThumbnailPath().empty()) { - if(!(*it)->getThumbnailPath().empty()) - { - detailed = true; - break; - } + detailed = true; + break; } - - if(detailed) - view = std::shared_ptr(new DetailedGameListView(mWindow, system->getRootFolder())); - else - view = std::shared_ptr(new BasicGameListView(mWindow, system->getRootFolder())); - - // uncomment for experimental "image grid" view - //view = std::shared_ptr(new GridGameListView(mWindow, system->getRootFolder())); - - view->setTheme(system->getTheme()); - }else{ - LOG(LogError) << "null system"; // should eventually return an "all games" gamelist view } + + if(detailed) + view = std::shared_ptr(new DetailedGameListView(mWindow, system->getRootFolder())); + else + view = std::shared_ptr(new BasicGameListView(mWindow, system->getRootFolder())); + + // uncomment for experimental "image grid" view + //view = std::shared_ptr(new GridGameListView(mWindow, system->getRootFolder())); + + view->setTheme(system->getTheme()); std::vector& sysVec = SystemData::sSystemVector; int id = std::find(sysVec.begin(), sysVec.end(), system) - sysVec.begin(); @@ -161,15 +140,18 @@ std::shared_ptr ViewController::getGameListView(SystemData* syste return view; } -std::shared_ptr ViewController::getSystemListView() +std::shared_ptr ViewController::getSystemView(SystemData* system) { - if(!mSystemListView) - { - mSystemListView = std::shared_ptr(new SystemListView(mWindow)); - mSystemListView->setPosition(0, (float)Renderer::getScreenHeight()); - } + //if we already made one, return that one + auto exists = mSystemViews.find(system); + if(exists != mSystemViews.end()) + return exists->second; - return mSystemListView; + //if we didn't, make it, remember it, and return it + std::shared_ptr view = std::shared_ptr(new SystemView(mWindow, system)); + view->setPosition((system->getIterator() - SystemData::sSystemVector.begin()) * (float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); + mSystemViews[system] = view; + return view; } @@ -211,8 +193,12 @@ void ViewController::render(const Eigen::Affine3f& parentTrans) Eigen::Vector3f viewStart = trans.inverse().translation(); Eigen::Vector3f viewEnd = trans.inverse() * Eigen::Vector3f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight(), 0); - // draw systemlist - if(mSystemListView) mSystemListView->render(trans); + // draw systemviews + for(auto it = mSystemViews.begin(); it != mSystemViews.end(); it++) + { + // should do clipping + it->second->render(trans); + } // draw gamelists for(auto it = mGameListViews.begin(); it != mGameListViews.end(); it++) @@ -238,6 +224,7 @@ void ViewController::preload() { for(auto it = SystemData::sSystemVector.begin(); it != SystemData::sSystemVector.end(); it++) { + getSystemView(*it); getGameListView(*it); } } @@ -248,13 +235,17 @@ void ViewController::reloadGameListView(IGameListView* view) { if(it->second.get() == view) { + bool isCurrent = (mCurrentView == it->second); SystemData* system = it->first; FileData* cursor = view->getCursor(); mGameListViews.erase(it); std::shared_ptr newView = getGameListView(system); newView->setCursor(cursor); - mCurrentView = newView; + + if(isCurrent) + mCurrentView = newView; + break; } } diff --git a/src/views/ViewController.h b/src/views/ViewController.h index c9f82363e..a924d9f58 100644 --- a/src/views/ViewController.h +++ b/src/views/ViewController.h @@ -1,7 +1,7 @@ #pragma once #include "gamelist/IGameListView.h" -#include "SystemListView.h" +#include "SystemView.h" class SystemData; @@ -22,8 +22,9 @@ public: void goToNextGameList(); void goToPrevGameList(); void goToGameList(SystemData* system); - void goToSystemSelect(); - + void goToSystemView(SystemData* system); + void goToStart(); + void onFileChanged(FileData* file, FileChangeType change); // Plays a nice launch effect and launches the game at the end of it. @@ -36,6 +37,7 @@ public: enum ViewMode { + NOTHING, START_SCREEN, SYSTEM_SELECT, GAME_LIST @@ -60,11 +62,11 @@ public: private: void playViewTransition(); std::shared_ptr getGameListView(SystemData* system); - std::shared_ptr getSystemListView(); + std::shared_ptr getSystemView(SystemData* system); std::shared_ptr mCurrentView; std::map< SystemData*, std::shared_ptr > mGameListViews; - std::shared_ptr mSystemListView; + std::map< SystemData*, std::shared_ptr > mSystemViews; Eigen::Affine3f mCamera; float mFadeOpacity; diff --git a/src/views/gamelist/ISimpleGameListView.cpp b/src/views/gamelist/ISimpleGameListView.cpp index f2913b20f..1f986644a 100644 --- a/src/views/gamelist/ISimpleGameListView.cpp +++ b/src/views/gamelist/ISimpleGameListView.cpp @@ -80,7 +80,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) getTheme()->playSound("backSound"); }else{ onFocusLost(); - mWindow->getViewController()->goToSystemSelect(); + mWindow->getViewController()->goToSystemView(getCursor()->getSystem()); } return true;