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.
This commit is contained in:
Aloshi 2013-12-24 11:50:26 -06:00
parent b6577e630d
commit 6f442556c0
11 changed files with 118 additions and 182 deletions

View file

@ -198,7 +198,6 @@ set(ES_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/views/gamelist/IGameListView.h ${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/ISimpleGameListView.h
${CMAKE_CURRENT_SOURCE_DIR}/src/views/gamelist/GridGameListView.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/SystemView.h
${CMAKE_CURRENT_SOURCE_DIR}/src/views/ViewController.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/IGameListView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/views/gamelist/ISimpleGameListView.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/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/SystemView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/views/ViewController.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/views/ViewController.cpp

View file

@ -39,6 +39,25 @@ public:
static std::vector<SystemData*> sSystemVector; static std::vector<SystemData*> sSystemVector;
inline std::vector<SystemData*>::const_iterator getIterator() const { return std::find(sSystemVector.begin(), sSystemVector.end(), this); };
inline std::vector<SystemData*>::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: private:
std::string mName; std::string mName;
std::string mFullName; std::string mFullName;

View file

@ -38,7 +38,7 @@ bool GuiInputConfig::input(InputConfig* config, Input input)
mWindow->pushGui(new GuiInputConfig(mWindow, mWindow->getInputManager()->getInputConfigByPlayer(mTargetConfig->getPlayerNum() + 1))); mWindow->pushGui(new GuiInputConfig(mWindow, mWindow->getInputManager()->getInputConfigByPlayer(mTargetConfig->getPlayerNum() + 1)));
}else{ }else{
mWindow->getInputManager()->writeConfig(); mWindow->getInputManager()->writeConfig();
mWindow->getViewController()->goToSystemSelect(); mWindow->getViewController()->goToStart();
} }
delete this; delete this;
return true; return true;

View file

@ -172,7 +172,7 @@ int main(int argc, char* argv[])
//choose which GUI to open depending on if an input configuration already exists //choose which GUI to open depending on if an input configuration already exists
if(fs::exists(InputManager::getConfigPath())) if(fs::exists(InputManager::getConfigPath()))
{ {
window.getViewController()->goToSystemSelect(); window.getViewController()->goToStart();
}else{ }else{
window.pushGui(new GuiDetectDevice(&window)); window.pushGui(new GuiDetectDevice(&window));
} }

View file

@ -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<SystemView> view = getSystemView(system);
mCurrentView = view;
mCurrentSystem = system;
setAnimation(new MoveCameraAnimation(mCamera, view->getPosition()));
}
std::shared_ptr<SystemView> SystemListView::getSystemView(SystemData* system)
{
auto exists = mSystemViews.find(system);
if(exists != mSystemViews.end())
return exists->second;
const std::vector<SystemData*>& sysVec = SystemData::sSystemVector;
int id = std::find(sysVec.begin(), sysVec.end(), system) - sysVec.begin();
std::shared_ptr<SystemView> view = std::shared_ptr<SystemView>(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);
}
}

View file

@ -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<SystemView> mCurrentView;
SystemData* mCurrentSystem;
std::shared_ptr<SystemView> getSystemView(SystemData* system);
std::map< SystemData*, std::shared_ptr<SystemView> > mSystemViews;
};

View file

@ -2,6 +2,8 @@
#include "../SystemData.h" #include "../SystemData.h"
#include "../Renderer.h" #include "../Renderer.h"
#include "../Log.h" #include "../Log.h"
#include "../Window.h"
#include "ViewController.h"
SystemView::SystemView(Window* window, SystemData* system) : GuiComponent(window), SystemView::SystemView(Window* window, SystemData* system) : GuiComponent(window),
mSystem(system), mSystem(system),
@ -47,3 +49,27 @@ void SystemView::updateData()
mImage.setImage(mSystem->getTheme()->getImage("systemImage").getTexture()); 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);
}

View file

@ -14,6 +14,8 @@ public:
void updateData(); void updateData();
bool input(InputConfig* config, Input input) override;
private: private:
SystemData* mSystem; SystemData* mSystem;

View file

@ -15,58 +15,39 @@ ViewController::ViewController(Window* window)
{ {
// slot 1 so the fade carries over // slot 1 so the fade carries over
setAnimation(new LambdaAnimation([&] (float t) { mFadeOpacity = lerp<float>(1.0f, 0.0f, t); }, 900), nullptr, false, 1); setAnimation(new LambdaAnimation([&] (float t) { mFadeOpacity = lerp<float>(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; mState.viewing = SYSTEM_SELECT;
mCurrentView = getSystemListView(); mCurrentView = getSystemView(system);
playViewTransition(); playViewTransition();
} }
SystemData* getSystemCyclic(SystemData* from, bool reverse)
{
std::vector<SystemData*>& 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() void ViewController::goToNextGameList()
{ {
assert(mState.viewing == GAME_LIST); assert(mState.viewing == GAME_LIST);
SystemData* system = getState().getSystem();
SystemData* system = mState.data.system; assert(system);
if(system == NULL) goToGameList(system->getNext());
return;
goToGameList(getSystemCyclic(system, false));
} }
void ViewController::goToPrevGameList() void ViewController::goToPrevGameList()
{ {
assert(mState.viewing == GAME_LIST); assert(mState.viewing == GAME_LIST);
SystemData* system = getState().getSystem();
SystemData* system = mState.data.system; assert(system);
if(system == NULL) goToGameList(system->getPrev());
return;
goToGameList(getSystemCyclic(system, true));
} }
void ViewController::goToGameList(SystemData* system) void ViewController::goToGameList(SystemData* system)
@ -80,7 +61,10 @@ void ViewController::goToGameList(SystemData* system)
void ViewController::playViewTransition() 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) void ViewController::onFileChanged(FileData* file, FileChangeType change)
@ -126,32 +110,27 @@ std::shared_ptr<IGameListView> ViewController::getGameListView(SystemData* syste
//if we didn't, make it, remember it, and return it //if we didn't, make it, remember it, and return it
std::shared_ptr<IGameListView> view; std::shared_ptr<IGameListView> view;
if(system != NULL) //decide type
bool detailed = false;
std::vector<FileData*> files = system->getRootFolder()->getFilesRecursive(GAME | FOLDER);
for(auto it = files.begin(); it != files.end(); it++)
{ {
//decide type if(!(*it)->getThumbnailPath().empty())
bool detailed = false;
std::vector<FileData*> files = system->getRootFolder()->getFilesRecursive(GAME | FOLDER);
for(auto it = files.begin(); it != files.end(); it++)
{ {
if(!(*it)->getThumbnailPath().empty()) detailed = true;
{ break;
detailed = true;
break;
}
} }
if(detailed)
view = std::shared_ptr<IGameListView>(new DetailedGameListView(mWindow, system->getRootFolder()));
else
view = std::shared_ptr<IGameListView>(new BasicGameListView(mWindow, system->getRootFolder()));
// uncomment for experimental "image grid" view
//view = std::shared_ptr<IGameListView>(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<IGameListView>(new DetailedGameListView(mWindow, system->getRootFolder()));
else
view = std::shared_ptr<IGameListView>(new BasicGameListView(mWindow, system->getRootFolder()));
// uncomment for experimental "image grid" view
//view = std::shared_ptr<IGameListView>(new GridGameListView(mWindow, system->getRootFolder()));
view->setTheme(system->getTheme());
std::vector<SystemData*>& sysVec = SystemData::sSystemVector; std::vector<SystemData*>& sysVec = SystemData::sSystemVector;
int id = std::find(sysVec.begin(), sysVec.end(), system) - sysVec.begin(); int id = std::find(sysVec.begin(), sysVec.end(), system) - sysVec.begin();
@ -161,15 +140,18 @@ std::shared_ptr<IGameListView> ViewController::getGameListView(SystemData* syste
return view; return view;
} }
std::shared_ptr<SystemListView> ViewController::getSystemListView() std::shared_ptr<SystemView> ViewController::getSystemView(SystemData* system)
{ {
if(!mSystemListView) //if we already made one, return that one
{ auto exists = mSystemViews.find(system);
mSystemListView = std::shared_ptr<SystemListView>(new SystemListView(mWindow)); if(exists != mSystemViews.end())
mSystemListView->setPosition(0, (float)Renderer::getScreenHeight()); return exists->second;
}
return mSystemListView; //if we didn't, make it, remember it, and return it
std::shared_ptr<SystemView> view = std::shared_ptr<SystemView>(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 viewStart = trans.inverse().translation();
Eigen::Vector3f viewEnd = trans.inverse() * Eigen::Vector3f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight(), 0); Eigen::Vector3f viewEnd = trans.inverse() * Eigen::Vector3f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight(), 0);
// draw systemlist // draw systemviews
if(mSystemListView) mSystemListView->render(trans); for(auto it = mSystemViews.begin(); it != mSystemViews.end(); it++)
{
// should do clipping
it->second->render(trans);
}
// draw gamelists // draw gamelists
for(auto it = mGameListViews.begin(); it != mGameListViews.end(); it++) 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++) for(auto it = SystemData::sSystemVector.begin(); it != SystemData::sSystemVector.end(); it++)
{ {
getSystemView(*it);
getGameListView(*it); getGameListView(*it);
} }
} }
@ -248,13 +235,17 @@ void ViewController::reloadGameListView(IGameListView* view)
{ {
if(it->second.get() == view) if(it->second.get() == view)
{ {
bool isCurrent = (mCurrentView == it->second);
SystemData* system = it->first; SystemData* system = it->first;
FileData* cursor = view->getCursor(); FileData* cursor = view->getCursor();
mGameListViews.erase(it); mGameListViews.erase(it);
std::shared_ptr<IGameListView> newView = getGameListView(system); std::shared_ptr<IGameListView> newView = getGameListView(system);
newView->setCursor(cursor); newView->setCursor(cursor);
mCurrentView = newView;
if(isCurrent)
mCurrentView = newView;
break; break;
} }
} }

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "gamelist/IGameListView.h" #include "gamelist/IGameListView.h"
#include "SystemListView.h" #include "SystemView.h"
class SystemData; class SystemData;
@ -22,8 +22,9 @@ public:
void goToNextGameList(); void goToNextGameList();
void goToPrevGameList(); void goToPrevGameList();
void goToGameList(SystemData* system); void goToGameList(SystemData* system);
void goToSystemSelect(); void goToSystemView(SystemData* system);
void goToStart();
void onFileChanged(FileData* file, FileChangeType change); void onFileChanged(FileData* file, FileChangeType change);
// Plays a nice launch effect and launches the game at the end of it. // Plays a nice launch effect and launches the game at the end of it.
@ -36,6 +37,7 @@ public:
enum ViewMode enum ViewMode
{ {
NOTHING,
START_SCREEN, START_SCREEN,
SYSTEM_SELECT, SYSTEM_SELECT,
GAME_LIST GAME_LIST
@ -60,11 +62,11 @@ public:
private: private:
void playViewTransition(); void playViewTransition();
std::shared_ptr<IGameListView> getGameListView(SystemData* system); std::shared_ptr<IGameListView> getGameListView(SystemData* system);
std::shared_ptr<SystemListView> getSystemListView(); std::shared_ptr<SystemView> getSystemView(SystemData* system);
std::shared_ptr<GuiComponent> mCurrentView; std::shared_ptr<GuiComponent> mCurrentView;
std::map< SystemData*, std::shared_ptr<IGameListView> > mGameListViews; std::map< SystemData*, std::shared_ptr<IGameListView> > mGameListViews;
std::shared_ptr<SystemListView> mSystemListView; std::map< SystemData*, std::shared_ptr<SystemView> > mSystemViews;
Eigen::Affine3f mCamera; Eigen::Affine3f mCamera;
float mFadeOpacity; float mFadeOpacity;

View file

@ -80,7 +80,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
getTheme()->playSound("backSound"); getTheme()->playSound("backSound");
}else{ }else{
onFocusLost(); onFocusLost();
mWindow->getViewController()->goToSystemSelect(); mWindow->getViewController()->goToSystemView(getCursor()->getSystem());
} }
return true; return true;