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"
|
|
|
|
#include "../Font.h"
|
|
|
|
#include "GuiGameList.h"
|
2013-04-13 18:19:06 +00:00
|
|
|
#include "../Log.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-04-09 18:13:47 +00:00
|
|
|
GuiGameList::create(mWindow);
|
|
|
|
}
|
|
|
|
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-04-09 18:13:47 +00:00
|
|
|
void GuiInputConfig::render()
|
2012-07-22 21:15:55 +00:00
|
|
|
{
|
2013-04-09 18:13:47 +00:00
|
|
|
Font* font = Renderer::getDefaultFont(Renderer::MEDIUM);
|
|
|
|
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << "PLAYER " << mTargetConfig->getPlayerNum() + 1 << ", press...";
|
|
|
|
Renderer::drawText(stream.str(), 10, 10, 0x000000FF, font);
|
|
|
|
|
|
|
|
int y = 14 + font->getHeight();
|
|
|
|
for(int i = 0; i < mCurInputId; i++)
|
|
|
|
{
|
2013-04-18 21:44:43 +00:00
|
|
|
Renderer::drawText(inputDispName[i], 10, y, 0x00CC00FF, font);
|
2013-04-09 18:13:47 +00:00
|
|
|
y += font->getHeight() + 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mCurInputId >= inputCount)
|
|
|
|
{
|
2013-06-03 00:18:26 +00:00
|
|
|
Renderer::drawCenteredText("Basic config done!", 0, (int)(Renderer::getScreenHeight() * 0.4), 0x00CC00FF, font);
|
|
|
|
Renderer::drawCenteredText("Press any button to continue.", 0, (int)(Renderer::getScreenHeight() * 0.4) + font->getHeight() + 4, 0x000000FF, font);
|
2013-04-09 18:13:47 +00:00
|
|
|
}else{
|
2013-04-18 21:44:43 +00:00
|
|
|
Renderer::drawText(inputDispName[mCurInputId], 10, y, 0x000000FF, font);
|
2013-06-03 00:18:26 +00:00
|
|
|
if(mCanSkip)
|
|
|
|
{
|
|
|
|
int textWidth = 0;
|
|
|
|
font->sizeText(inputDispName[mCurInputId], &textWidth, NULL);
|
|
|
|
textWidth += 14;
|
|
|
|
|
|
|
|
if(Renderer::getScreenWidth() / 2.5f > textWidth)
|
|
|
|
textWidth = (int)(Renderer::getScreenWidth() / 2.5f);
|
|
|
|
|
2013-06-14 12:34:12 +00:00
|
|
|
Renderer::drawText("press Accept to skip", textWidth, y, 0x0000AAFF, font);
|
2013-06-03 00:18:26 +00:00
|
|
|
}
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!mErrorMsg.empty())
|
|
|
|
Renderer::drawCenteredText(mErrorMsg, 0, Renderer::getScreenHeight() - font->getHeight() - 10, 0xFF0000FF, font);
|
2012-07-22 21:15:55 +00:00
|
|
|
}
|