From 7152ca6246f97351dbe47dffea5bc2d11448f154 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Tue, 10 Dec 2013 21:23:47 -0600 Subject: [PATCH] First version of the system select menu. --- CMakeLists.txt | 4 ++ THEMES.md | 2 + src/ThemeData.cpp | 3 +- src/views/BasicGameListView.cpp | 4 +- src/views/SystemListView.cpp | 78 +++++++++++++++++++++++++++++++++ src/views/SystemListView.h | 23 ++++++++++ src/views/SystemView.cpp | 47 ++++++++++++++++++++ src/views/SystemView.h | 23 ++++++++++ src/views/ViewController.cpp | 48 +++++++++++++------- src/views/ViewController.h | 21 +++++---- 10 files changed, 224 insertions(+), 29 deletions(-) create mode 100644 src/views/SystemListView.cpp create mode 100644 src/views/SystemListView.h create mode 100644 src/views/SystemView.cpp create mode 100644 src/views/SystemView.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0442f7277..895135281 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,6 +197,8 @@ set(ES_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/views/DetailedGameListView.h ${CMAKE_CURRENT_SOURCE_DIR}/src/views/GameListView.h ${CMAKE_CURRENT_SOURCE_DIR}/src/views/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 ${CMAKE_CURRENT_SOURCE_DIR}/src/animations/Animation.h @@ -272,6 +274,8 @@ set(ES_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/views/DetailedGameListView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/views/GameListView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/views/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 ${CMAKE_CURRENT_SOURCE_DIR}/src/animations/AnimationController.cpp diff --git a/THEMES.md b/THEMES.md index 407f15be9..e9fca7010 100644 --- a/THEMES.md +++ b/THEMES.md @@ -122,6 +122,8 @@ Pretty much any image format is supported. `` - No default. +`` - No default. Large image, shown in the system select menu. + `` - Nine patch. Default is the "button.png" resource. Sounds diff --git a/src/ThemeData.cpp b/src/ThemeData.cpp index 06749c476..229dd18fb 100644 --- a/src/ThemeData.cpp +++ b/src/ThemeData.cpp @@ -28,7 +28,8 @@ std::map ThemeData::sDefaultImages = boost::assign::map_l ("headerImage", ImageDef("", false)) ("infoBackgroundImage", ImageDef("", false)) ("verticalDividerImage", ImageDef("", false)) - ("fastSelectBackgroundImage", ImageDef(":/button.png", false)); + ("fastSelectBackgroundImage", ImageDef(":/button.png", false)) + ("systemImage", ImageDef("", false)); std::map ThemeData::sDefaultSounds = boost::assign::map_list_of ("scrollSound", SoundDef("")) diff --git a/src/views/BasicGameListView.cpp b/src/views/BasicGameListView.cpp index bc6a4e829..ee886d837 100644 --- a/src/views/BasicGameListView.cpp +++ b/src/views/BasicGameListView.cpp @@ -169,12 +169,12 @@ bool BasicGameListView::input(InputConfig* config, Input input) }else if(config->isMappedTo("right", input)) { mList.stopScrolling(); - mWindow->getViewController()->goToNextSystem(); + mWindow->getViewController()->goToNextGameList(); return true; }else if(config->isMappedTo("left", input)) { mList.stopScrolling(); - mWindow->getViewController()->goToPrevSystem(); + mWindow->getViewController()->goToPrevGameList(); return true; } } diff --git a/src/views/SystemListView.cpp b/src/views/SystemListView.cpp new file mode 100644 index 000000000..d62faf8a0 --- /dev/null +++ b/src/views/SystemListView.cpp @@ -0,0 +1,78 @@ +#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; + + 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 new file mode 100644 index 000000000..7fe685c89 --- /dev/null +++ b/src/views/SystemListView.h @@ -0,0 +1,23 @@ +#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 new file mode 100644 index 000000000..4b0270363 --- /dev/null +++ b/src/views/SystemView.cpp @@ -0,0 +1,47 @@ +#include "SystemView.h" +#include "../SystemData.h" +#include "../Renderer.h" +#include "../Log.h" + +SystemView::SystemView(Window* window, SystemData* system) : GuiComponent(window), + mSystem(system), + + mHeaderImage(window), + mHeaderText(window), + mImage(window) +{ + setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); + + mHeaderImage.setOrigin(0.5f, 0.0f); + mHeaderImage.setPosition(mSize.x() / 2, 0); + mHeaderImage.setResize(0, mSize.y() * 0.2f, true); + + mHeaderText.setSize(mSize.x(), 0); + mHeaderText.setCentered(true); + + mImage.setOrigin(0.5f, 0.5f); + mImage.setPosition(mSize.x() / 2, mSize.y() / 2); + + addChild(&mImage); + addChild(&mHeaderText); + addChild(&mHeaderImage); + + updateData(); +} + +void SystemView::updateData() +{ + // header + if(mSystem->getTheme()->getImage("headerImage").path.empty()) + { + // use text + mHeaderImage.setImage(""); + mHeaderText.setText(mSystem->getFullName()); + }else{ + // use image + mHeaderText.setText(""); + mHeaderImage.setImage(mSystem->getTheme()->getImage("headerImage").getTexture()); + } + + mImage.setImage(mSystem->getTheme()->getImage("systemImage").getTexture()); +} diff --git a/src/views/SystemView.h b/src/views/SystemView.h new file mode 100644 index 000000000..762591cac --- /dev/null +++ b/src/views/SystemView.h @@ -0,0 +1,23 @@ +#pragma once + +#include "../GuiComponent.h" +#include "../components/ImageComponent.h" +#include "../components/TextComponent.h" +#include "../components/ScrollableContainer.h" + +class SystemData; + +class SystemView : public GuiComponent +{ +public: + SystemView(Window* window, SystemData* system); + + void updateData(); + +private: + SystemData* mSystem; + + TextComponent mHeaderText; + ImageComponent mHeaderImage; + ImageComponent mImage; +}; diff --git a/src/views/ViewController.cpp b/src/views/ViewController.cpp index 84444885f..7eb34c2c3 100644 --- a/src/views/ViewController.cpp +++ b/src/views/ViewController.cpp @@ -17,8 +17,9 @@ ViewController::ViewController(Window* window) void ViewController::goToSystemSelect() { mState.viewing = SYSTEM_SELECT; - goToSystem(SystemData::sSystemVector.at(0)); - //playViewTransition(); + mCurrentView = getSystemListView(); + playViewTransition(); + LOG(LogInfo) << "going to system select"; } SystemData* getSystemCyclic(SystemData* from, bool reverse) @@ -43,7 +44,7 @@ SystemData* getSystemCyclic(SystemData* from, bool reverse) } } -void ViewController::goToNextSystem() +void ViewController::goToNextGameList() { assert(mState.viewing == SYSTEM); @@ -51,10 +52,10 @@ void ViewController::goToNextSystem() if(system == NULL) return; - goToSystem(getSystemCyclic(system, false)); + goToGameList(getSystemCyclic(system, false)); } -void ViewController::goToPrevSystem() +void ViewController::goToPrevGameList() { assert(mState.viewing == SYSTEM); @@ -62,15 +63,15 @@ void ViewController::goToPrevSystem() if(system == NULL) return; - goToSystem(getSystemCyclic(system, true)); + goToGameList(getSystemCyclic(system, true)); } -void ViewController::goToSystem(SystemData* system) +void ViewController::goToGameList(SystemData* system) { - mState.viewing = SYSTEM; + mState.viewing = GAME_LIST; mState.data.system = system; - mCurrentView = getSystemView(system); + mCurrentView = getGameListView(system); playViewTransition(); } @@ -81,7 +82,7 @@ void ViewController::playViewTransition() void ViewController::onFileChanged(FileData* file, FileChangeType change) { - for(auto it = mSystemViews.begin(); it != mSystemViews.end(); it++) + for(auto it = mGameListViews.begin(); it != mGameListViews.end(); it++) { it->second->onFileChanged(file, change); } @@ -108,11 +109,11 @@ void ViewController::launch(FileData* game, Eigen::Vector3f center) }); } -std::shared_ptr ViewController::getSystemView(SystemData* system) +std::shared_ptr ViewController::getGameListView(SystemData* system) { //if we already made one, return that one - auto exists = mSystemViews.find(system); - if(exists != mSystemViews.end()) + auto exists = mGameListViews.find(system); + if(exists != mGameListViews.end()) return exists->second; //if we didn't, make it, remember it, and return it @@ -146,12 +147,22 @@ std::shared_ptr ViewController::getSystemView(SystemData* system) std::vector& sysVec = SystemData::sSystemVector; int id = std::find(sysVec.begin(), sysVec.end(), system) - sysVec.begin(); - view->setPosition(id * (float)Renderer::getScreenWidth(), 0); + view->setPosition(id * (float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight() * 2); - mSystemViews[system] = view; + mGameListViews[system] = view; return view; } +std::shared_ptr ViewController::getSystemListView() +{ + if(!mSystemListView) + { + mSystemListView = std::shared_ptr(new SystemListView(mWindow)); + mSystemListView->setPosition(0, (float)Renderer::getScreenHeight()); + } + + return mSystemListView; +} bool ViewController::input(InputConfig* config, Input input) @@ -180,8 +191,11 @@ 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 systems - for(auto it = mSystemViews.begin(); it != mSystemViews.end(); it++) + // draw systemlist + mSystemListView->render(trans); + + // draw gamelists + for(auto it = mGameListViews.begin(); it != mGameListViews.end(); it++) { // clipping Eigen::Vector3f guiStart = it->second->getPosition(); diff --git a/src/views/ViewController.h b/src/views/ViewController.h index 45a5bb49f..35cd10a7e 100644 --- a/src/views/ViewController.h +++ b/src/views/ViewController.h @@ -1,6 +1,7 @@ #pragma once #include "GameListView.h" +#include "SystemListView.h" class SystemData; @@ -10,9 +11,9 @@ public: ViewController(Window* window); // Navigation. - void goToNextSystem(); - void goToPrevSystem(); - void goToSystem(SystemData* system); + void goToNextGameList(); + void goToPrevGameList(); + void goToGameList(SystemData* system); void goToSystemSelect(); void onFileChanged(FileData* file, FileChangeType change); @@ -29,14 +30,14 @@ public: { START_SCREEN, SYSTEM_SELECT, - SYSTEM + GAME_LIST }; struct State { ViewMode viewing; - inline SystemData* getSystem() const { assert(viewing == SYSTEM); return data.system; } + inline SystemData* getSystem() const { assert(viewing == GAME_LIST); return data.system; } private: friend ViewController; @@ -50,11 +51,13 @@ public: private: void playViewTransition(); - std::shared_ptr getSystemView(SystemData* system); - + std::shared_ptr getGameListView(SystemData* system); + std::shared_ptr getSystemListView(); + std::shared_ptr mCurrentView; - std::map< SystemData*, std::shared_ptr > mSystemViews; - + std::map< SystemData*, std::shared_ptr > mGameListViews; + std::shared_ptr mSystemListView; + Eigen::Affine3f mCamera; float mFadeOpacity;