2012-07-22 21:15:55 +00:00
|
|
|
#include "GuiInputConfig.h"
|
2013-04-09 18:13:47 +00:00
|
|
|
#include "../Window.h"
|
|
|
|
#include "../Renderer.h"
|
2013-10-04 23:24:41 +00:00
|
|
|
#include "../resources/Font.h"
|
2013-04-13 18:19:06 +00:00
|
|
|
#include "../Log.h"
|
2013-11-12 23:28:15 +00:00
|
|
|
#include "../views/ViewController.h"
|
2012-12-20 18:29:05 +00:00
|
|
|
|
2013-06-19 21:07:12 +00:00
|
|
|
static const int inputCount = 10;
|
|
|
|
static std::string inputName[inputCount] = { "Up", "Down", "Left", "Right", "A", "B", "Menu", "Select", "PageUp", "PageDown"};
|
|
|
|
static std::string inputDispName[inputCount] = { "Up", "Down", "Left", "Right", "Accept", "Back", "Menu", "Jump to Letter", "Page Up", "Page Down"};
|
|
|
|
|
|
|
|
//MasterVolUp and MasterVolDown are also hooked up, but do not appear on this screen.
|
|
|
|
//If you want, you can manually add them to es_input.cfg.
|
2012-07-22 21:15:55 +00:00
|
|
|
|
2013-06-03 00:18:26 +00:00
|
|
|
GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target) : GuiComponent(window), mTargetConfig(target), mCanSkip(false)
|
2012-07-22 21:15:55 +00:00
|
|
|
{
|
2013-04-09 18:13:47 +00:00
|
|
|
mCurInputId = 0;
|
2013-04-13 18:19:06 +00:00
|
|
|
LOG(LogInfo) << "Configuring device " << target->getDeviceId();
|
2012-07-22 21:15:55 +00:00
|
|
|
}
|
|
|
|
|
2013-04-09 18:13:47 +00:00
|
|
|
void GuiInputConfig::update(int deltaTime)
|
2012-07-22 21:15:55 +00:00
|
|
|
{
|
2013-04-09 18:13:47 +00:00
|
|
|
|
2012-07-22 21:15:55 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
bool GuiInputConfig::input(InputConfig* config, Input input)
|
2012-07-22 21:15:55 +00:00
|
|
|
{
|
2013-04-09 18:13:47 +00:00
|
|
|
if(config != mTargetConfig || input.value == 0)
|
2013-06-02 15:08:32 +00:00
|
|
|
return false;
|
2013-04-09 18:13:47 +00:00
|
|
|
|
|
|
|
if(mCurInputId >= inputCount)
|
|
|
|
{
|
|
|
|
//done
|
|
|
|
if(input.type == TYPE_BUTTON || input.type == TYPE_KEY)
|
|
|
|
{
|
|
|
|
if(mTargetConfig->getPlayerNum() < mWindow->getInputManager()->getNumPlayers() - 1)
|
|
|
|
{
|
|
|
|
mWindow->pushGui(new GuiInputConfig(mWindow, mWindow->getInputManager()->getInputConfigByPlayer(mTargetConfig->getPlayerNum() + 1)));
|
|
|
|
}else{
|
2013-04-11 22:27:27 +00:00
|
|
|
mWindow->getInputManager()->writeConfig();
|
2013-12-24 17:50:26 +00:00
|
|
|
mWindow->getViewController()->goToStart();
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
|
|
|
delete this;
|
2013-06-03 00:18:26 +00:00
|
|
|
return true;
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
|
|
|
}else{
|
2013-06-03 00:18:26 +00:00
|
|
|
if(mCanSkip && config->isMappedTo("a", input))
|
|
|
|
{
|
|
|
|
mCurInputId++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-09 18:13:47 +00:00
|
|
|
if(config->getMappedTo(input).size() > 0)
|
|
|
|
{
|
|
|
|
mErrorMsg = "Already mapped!";
|
2013-06-02 15:08:32 +00:00
|
|
|
return true;
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
input.configured = true;
|
2013-04-13 18:19:06 +00:00
|
|
|
LOG(LogInfo) << " [" << input.string() << "] -> " << inputName[mCurInputId];
|
2013-04-09 18:13:47 +00:00
|
|
|
|
|
|
|
config->mapInput(inputName[mCurInputId], input);
|
|
|
|
mCurInputId++;
|
|
|
|
mErrorMsg = "";
|
2013-04-13 23:10:23 +00:00
|
|
|
|
2013-06-03 00:18:26 +00:00
|
|
|
//for buttons with not enough buttons, press A to skip
|
|
|
|
if(mCurInputId >= 7)
|
2013-04-13 23:10:23 +00:00
|
|
|
{
|
2013-06-03 00:18:26 +00:00
|
|
|
mCanSkip = true;
|
2013-04-13 23:10:23 +00:00
|
|
|
}
|
2013-06-03 00:18:26 +00:00
|
|
|
return true;
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
2013-06-02 15:08:32 +00:00
|
|
|
|
2013-06-03 00:18:26 +00:00
|
|
|
return false;
|
2012-07-22 21:15:55 +00:00
|
|
|
}
|
|
|
|
|
2013-07-26 23:28:51 +00:00
|
|
|
void GuiInputConfig::render(const Eigen::Affine3f& parentTrans)
|
2012-07-22 21:15:55 +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::stringstream stream;
|
|
|
|
stream << "PLAYER " << mTargetConfig->getPlayerNum() + 1 << ", press...";
|
2013-07-10 11:29:43 +00:00
|
|
|
font->drawText(stream.str(), Eigen::Vector2f(10, 10), 0x000000FF);
|
2013-04-09 18:13:47 +00:00
|
|
|
|
|
|
|
int y = 14 + font->getHeight();
|
|
|
|
for(int i = 0; i < mCurInputId; i++)
|
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
font->drawText(inputDispName[i], Eigen::Vector2f(10, y), 0x00CC00FF);
|
2013-04-09 18:13:47 +00:00
|
|
|
y += font->getHeight() + 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mCurInputId >= inputCount)
|
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
font->drawCenteredText("Basic config done!", 0, Renderer::getScreenHeight() * 0.4f, 0x00CC00FF);
|
|
|
|
font->drawCenteredText("Press any button to continue.", 0, Renderer::getScreenHeight() * 0.4f + font->getHeight() + 4, 0x000000FF);
|
2013-04-09 18:13:47 +00:00
|
|
|
}else{
|
2013-07-10 11:29:43 +00:00
|
|
|
font->drawText(inputDispName[mCurInputId], Eigen::Vector2f(10, y), 0x000000FF);
|
2013-06-03 00:18:26 +00:00
|
|
|
if(mCanSkip)
|
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Vector2f textSize = font->sizeText(inputDispName[mCurInputId]);
|
|
|
|
textSize[0] += 14;
|
2013-06-03 00:18:26 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
if(Renderer::getScreenWidth() / 2.5f > textSize.x())
|
|
|
|
textSize[0] = Renderer::getScreenWidth() / 2.5f;
|
2013-06-03 00:18:26 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
font->drawText("press Accept to skip", Eigen::Vector2f(textSize.x(), y), 0x0000AAFF);
|
2013-06-03 00:18:26 +00:00
|
|
|
}
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!mErrorMsg.empty())
|
2013-07-10 11:29:43 +00:00
|
|
|
font->drawCenteredText(mErrorMsg, 0, (float)Renderer::getScreenHeight() - font->getHeight() - 10, 0xFF0000FF);
|
2012-07-22 21:15:55 +00:00
|
|
|
}
|