2013-11-12 23:28:15 +00:00
|
|
|
#include "ViewController.h"
|
|
|
|
#include "../Log.h"
|
|
|
|
#include "../SystemData.h"
|
|
|
|
|
|
|
|
#include "BasicGameListView.h"
|
|
|
|
#include "DetailedGameListView.h"
|
2013-12-01 01:04:46 +00:00
|
|
|
#include "GridGameListView.h"
|
2013-12-08 17:35:43 +00:00
|
|
|
#include "../animations/LaunchAnimation.h"
|
|
|
|
#include "../animations/MoveCameraAnimation.h"
|
2013-11-12 23:28:15 +00:00
|
|
|
|
|
|
|
ViewController::ViewController(Window* window)
|
2013-12-08 17:35:43 +00:00
|
|
|
: GuiComponent(window), mCurrentView(nullptr), mCamera(Eigen::Affine3f::Identity()), mFadeOpacity(0)
|
2013-11-12 23:28:15 +00:00
|
|
|
{
|
|
|
|
mState.viewing = START_SCREEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::goToSystemSelect()
|
|
|
|
{
|
|
|
|
mState.viewing = SYSTEM_SELECT;
|
|
|
|
goToSystem(SystemData::sSystemVector.at(0));
|
2013-12-08 17:35:43 +00:00
|
|
|
//playViewTransition();
|
2013-11-12 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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::goToNextSystem()
|
|
|
|
{
|
|
|
|
assert(mState.viewing == SYSTEM);
|
|
|
|
|
|
|
|
SystemData* system = mState.data.system;
|
|
|
|
if(system == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
goToSystem(getSystemCyclic(system, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::goToPrevSystem()
|
|
|
|
{
|
|
|
|
assert(mState.viewing == SYSTEM);
|
|
|
|
|
|
|
|
SystemData* system = mState.data.system;
|
|
|
|
if(system == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
goToSystem(getSystemCyclic(system, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::goToSystem(SystemData* system)
|
|
|
|
{
|
|
|
|
mState.viewing = SYSTEM;
|
|
|
|
mState.data.system = system;
|
|
|
|
|
|
|
|
mCurrentView = getSystemView(system);
|
2013-12-08 17:35:43 +00:00
|
|
|
playViewTransition();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::playViewTransition()
|
|
|
|
{
|
|
|
|
setAnimation(new MoveCameraAnimation(mCamera, mCurrentView->getPosition()));
|
2013-11-12 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::onFileChanged(FileData* file, FileChangeType change)
|
|
|
|
{
|
|
|
|
for(auto it = mSystemViews.begin(); it != mSystemViews.end(); it++)
|
|
|
|
{
|
|
|
|
it->second->onFileChanged(file, change);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-08 17:35:43 +00:00
|
|
|
void ViewController::launch(FileData* game, const Eigen::Vector3f& center)
|
2013-11-12 23:28:15 +00:00
|
|
|
{
|
|
|
|
if(game->getType() != GAME)
|
|
|
|
{
|
|
|
|
LOG(LogError) << "tried to launch something that isn't a game";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-08 17:35:43 +00:00
|
|
|
|
2013-11-28 19:52:21 +00:00
|
|
|
game->getSystem()->getTheme()->playSound("gameSelectSound");
|
2013-12-08 17:35:43 +00:00
|
|
|
|
|
|
|
Eigen::Affine3f origCamera = mCamera;
|
|
|
|
setAnimation(new LaunchAnimation(mCamera, mFadeOpacity, center, 1500), [this, origCamera, center, game]
|
|
|
|
{
|
|
|
|
game->getSystem()->launchGame(mWindow, game);
|
|
|
|
mCamera = origCamera;
|
|
|
|
setAnimation(new LaunchAnimation(mCamera, mFadeOpacity, center, 600), nullptr, true);
|
|
|
|
});
|
2013-11-12 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<GameListView> ViewController::getSystemView(SystemData* system)
|
|
|
|
{
|
|
|
|
//if we already made one, return that one
|
|
|
|
auto exists = mSystemViews.find(system);
|
|
|
|
if(exists != mSystemViews.end())
|
|
|
|
return exists->second;
|
|
|
|
|
|
|
|
//if we didn't, make it, remember it, and return it
|
|
|
|
std::shared_ptr<GameListView> view;
|
|
|
|
|
|
|
|
if(system != NULL)
|
|
|
|
{
|
2013-11-21 20:06:01 +00:00
|
|
|
//decide type
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2013-12-01 01:04:46 +00:00
|
|
|
|
2013-11-21 20:06:01 +00:00
|
|
|
if(detailed)
|
|
|
|
view = std::shared_ptr<GameListView>(new DetailedGameListView(mWindow, system->getRootFolder()));
|
|
|
|
else
|
|
|
|
view = std::shared_ptr<GameListView>(new BasicGameListView(mWindow, system->getRootFolder()));
|
2013-12-01 01:04:46 +00:00
|
|
|
|
|
|
|
//view = std::shared_ptr<GameListView>(new GridGameListView(mWindow, system->getRootFolder()));
|
2013-11-21 20:06:01 +00:00
|
|
|
|
2013-11-12 23:28:15 +00:00
|
|
|
view->setTheme(system->getTheme());
|
|
|
|
}else{
|
|
|
|
LOG(LogError) << "null system"; // should eventually return an "all games" gamelist view
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<SystemData*>& sysVec = SystemData::sSystemVector;
|
|
|
|
int id = std::find(sysVec.begin(), sysVec.end(), system) - sysVec.begin();
|
|
|
|
view->setPosition(id * (float)Renderer::getScreenWidth(), 0);
|
|
|
|
|
|
|
|
mSystemViews[system] = view;
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ViewController::input(InputConfig* config, Input input)
|
|
|
|
{
|
|
|
|
if(mCurrentView)
|
|
|
|
return mCurrentView->input(config, input);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::update(int deltaTime)
|
|
|
|
{
|
|
|
|
if(mCurrentView)
|
|
|
|
{
|
|
|
|
mCurrentView->update(deltaTime);
|
|
|
|
}
|
2013-12-08 17:35:43 +00:00
|
|
|
|
|
|
|
GuiComponent::update(deltaTime);
|
2013-11-12 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::render(const Eigen::Affine3f& parentTrans)
|
|
|
|
{
|
2013-12-08 17:35:43 +00:00
|
|
|
Eigen::Affine3f trans = mCamera * parentTrans;
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2013-12-08 17:35:43 +00:00
|
|
|
// draw systems
|
2013-11-12 23:28:15 +00:00
|
|
|
for(auto it = mSystemViews.begin(); it != mSystemViews.end(); it++)
|
2013-11-21 22:39:02 +00:00
|
|
|
{
|
2013-12-08 17:35:43 +00:00
|
|
|
// clipping
|
2013-11-21 22:39:02 +00:00
|
|
|
Eigen::Vector3f pos = it->second->getPosition();
|
|
|
|
Eigen::Vector2f size = it->second->getSize();
|
|
|
|
|
|
|
|
Eigen::Vector3f camPos = -trans.translation();
|
|
|
|
Eigen::Vector2f camSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
|
|
|
|
|
|
|
if(pos.x() + size.x() >= camPos.x() && pos.y() + size.y() >= camPos.y() &&
|
|
|
|
pos.x() <= camPos.x() + camSize.x() && pos.y() <= camPos.y() + camSize.y())
|
|
|
|
it->second->render(trans);
|
|
|
|
}
|
2013-12-08 17:35:43 +00:00
|
|
|
|
|
|
|
// fade out
|
|
|
|
if(mFadeOpacity)
|
|
|
|
{
|
|
|
|
Renderer::setMatrix(Eigen::Affine3f::Identity());
|
|
|
|
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x00000000 | (unsigned char)(mFadeOpacity * 255));
|
|
|
|
}
|
2013-11-12 23:28:15 +00:00
|
|
|
}
|