ES-DE/src/components/GuiInputConfig.cpp

92 lines
2.8 KiB
C++
Raw Normal View History

#include "GuiInputConfig.h"
#include "../Window.h"
#include "../Renderer.h"
#include "../Font.h"
#include "GuiGameList.h"
#include "../Log.h"
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" };
2013-06-02 15:08:32 +00:00
GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target) : GuiComponent(window), mTargetConfig(target)
{
mCurInputId = 0;
LOG(LogInfo) << "Configuring device " << target->getDeviceId();
}
void GuiInputConfig::update(int deltaTime)
{
}
2013-06-02 15:08:32 +00:00
bool GuiInputConfig::input(InputConfig* config, Input input)
{
if(config != mTargetConfig || input.value == 0)
2013-06-02 15:08:32 +00:00
return false;
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();
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;
}
input.configured = true;
LOG(LogInfo) << " [" << input.string() << "] -> " << inputName[mCurInputId];
config->mapInput(inputName[mCurInputId], input);
mCurInputId++;
mErrorMsg = "";
//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-06-02 15:08:32 +00:00
return true;
}
void GuiInputConfig::render()
{
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);
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);
}
if(!mErrorMsg.empty())
Renderer::drawCenteredText(mErrorMsg, 0, Renderer::getScreenHeight() - font->getHeight() - 10, 0xFF0000FF, font);
}