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-05-23 09:43:50 +00:00
|
|
|
static int inputCount = 12;
|
|
|
|
static std::string inputName[12] = { "Up", "Down", "Left", "Right", "A", "B", "Menu", "Select", "PageUp", "PageDown", "MasterVolUp", "MasterVolDown" };
|
|
|
|
static std::string inputDispName[12] = { "Up", "Down", "Left", "Right", "Accept", "Back", "Menu", "Jump to Letter", "Page Up", "Page Down", "Master volume up", "Master volume down" };
|
2012-07-22 21:15:55 +00:00
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target) : GuiComponent(window), mTargetConfig(target)
|
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;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
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
|
|
|
|
|
|
|
//if the controller doesn't have enough buttons for Page Up/Page Down, skip to done
|
|
|
|
if(mWindow->getInputManager()->getButtonCountByDevice(config->getDeviceId()) <= 4 && mCurInputId >= 8)
|
|
|
|
{
|
|
|
|
mCurInputId = inputCount;
|
|
|
|
}
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
2013-06-02 15:08:32 +00:00
|
|
|
|
|
|
|
return true;
|
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)
|
|
|
|
{
|
|
|
|
Renderer::drawCenteredText("Basic config done!", 0, (int)(Renderer::getScreenHeight() * 0.6), 0x00CC00FF, font);
|
|
|
|
Renderer::drawCenteredText("Press any button to continue.", 0, (int)(Renderer::getScreenHeight() * 0.6) + font->getHeight() + 4, 0x000000FF, font);
|
|
|
|
}else{
|
2013-04-18 21:44:43 +00:00
|
|
|
Renderer::drawText(inputDispName[mCurInputId], 10, y, 0x000000FF, font);
|
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
|
|
|
}
|