2013-04-09 18:13:47 +00:00
|
|
|
#include "GuiDetectDevice.h"
|
|
|
|
#include "../Window.h"
|
|
|
|
#include "../Renderer.h"
|
2013-10-04 23:24:41 +00:00
|
|
|
#include "../resources/Font.h"
|
2013-04-09 18:13:47 +00:00
|
|
|
#include "GuiInputConfig.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
GuiDetectDevice::GuiDetectDevice(Window* window) : GuiComponent(window)
|
2013-04-09 18:13:47 +00:00
|
|
|
{
|
|
|
|
//clear any player information from the InputManager
|
|
|
|
for(int i = 0; i < mWindow->getInputManager()->getNumPlayers(); i++)
|
|
|
|
{
|
|
|
|
InputConfig* cfg = mWindow->getInputManager()->getInputConfigByPlayer(i);
|
|
|
|
cfg->setPlayerNum(-1);
|
|
|
|
cfg->clear();
|
|
|
|
}
|
|
|
|
mWindow->getInputManager()->setNumPlayers(0);
|
|
|
|
|
|
|
|
mCurrentPlayer = 0;
|
|
|
|
mHoldingFinish = false;
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
bool GuiDetectDevice::input(InputConfig* config, Input input)
|
2013-04-09 18:13:47 +00:00
|
|
|
{
|
|
|
|
if((input.type == TYPE_BUTTON || input.type == TYPE_KEY))
|
|
|
|
{
|
|
|
|
if(config->getPlayerNum() != -1)
|
|
|
|
{
|
|
|
|
if(config->getPlayerNum() == 0)
|
|
|
|
{
|
|
|
|
if(input.value)
|
|
|
|
{
|
|
|
|
mFinishTimer = 0;
|
|
|
|
mHoldingFinish = true;
|
|
|
|
}else{
|
|
|
|
mHoldingFinish = false;
|
|
|
|
}
|
|
|
|
}
|
2013-06-02 15:08:32 +00:00
|
|
|
return true;
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!input.value)
|
2013-06-02 15:08:32 +00:00
|
|
|
return false;
|
2013-04-09 18:13:47 +00:00
|
|
|
|
|
|
|
config->setPlayerNum(mCurrentPlayer);
|
|
|
|
mWindow->getInputManager()->setNumPlayers(mWindow->getInputManager()->getNumPlayers() + 1); //inc total number of players
|
|
|
|
mCurrentPlayer++;
|
|
|
|
|
|
|
|
//mapped everything we possibly can?
|
|
|
|
if(mCurrentPlayer >= mWindow->getInputManager()->getNumJoysticks() + 1) //+1 for keyboard
|
|
|
|
{
|
|
|
|
done();
|
|
|
|
}
|
2013-06-02 15:08:32 +00:00
|
|
|
|
|
|
|
return true;
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
2013-06-02 15:08:32 +00:00
|
|
|
|
|
|
|
return false;
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiDetectDevice::done()
|
|
|
|
{
|
|
|
|
mWindow->pushGui(new GuiInputConfig(mWindow, mWindow->getInputManager()->getInputConfigByPlayer(0)));
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiDetectDevice::update(int deltaTime)
|
|
|
|
{
|
|
|
|
if(mHoldingFinish)
|
|
|
|
{
|
|
|
|
mFinishTimer += deltaTime;
|
|
|
|
|
|
|
|
if(mFinishTimer > 1000)
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-26 23:28:51 +00:00
|
|
|
void GuiDetectDevice::render(const Eigen::Affine3f& parentTrans)
|
2013-04-09 18:13:47 +00:00
|
|
|
{
|
2013-07-26 23:28:51 +00:00
|
|
|
Eigen::Affine3f trans = parentTrans * getTransform();
|
|
|
|
Renderer::setMatrix(trans);
|
|
|
|
|
2013-10-04 23:09:54 +00:00
|
|
|
std::shared_ptr<Font> font = Font::get(FONT_SIZE_MEDIUM);
|
2013-04-09 18:13:47 +00:00
|
|
|
|
|
|
|
std::string playerString;
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << (mCurrentPlayer + 1);
|
|
|
|
stream >> playerString;
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
font->drawCenteredText("Press a button on the device for", 0, Renderer::getScreenHeight() / 3.0f, 0x000000FF);
|
|
|
|
font->drawCenteredText("PLAYER " + playerString, 0, (Renderer::getScreenHeight()*1.5f) / 3.0f, 0x333333FF);
|
2013-04-09 18:13:47 +00:00
|
|
|
|
|
|
|
if(mWindow->getInputManager()->getNumPlayers() > 0)
|
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
font->drawCenteredText("(P1 - hold a button to finish)", 0, (Renderer::getScreenHeight()*2) / 3.0f, (mHoldingFinish ? 0x0000FFFF : 0x000066FF));
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(mWindow->getInputManager()->getNumJoysticks() == 0)
|
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
font->drawCenteredText("No joysticks detected!", 0, Renderer::getScreenHeight() - (font->getHeight()*2.0f)-10, 0xFF0000FF);
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
font->drawCenteredText("Press F4 to quit.", 0, Renderer::getScreenHeight() - font->getHeight() - 2.0f , 0x000000FF);
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|