Commit 9a54da6e authored by digitalLumberjack's avatar digitalLumberjack

added second joystick configuration

parent d09d6f29
......@@ -173,7 +173,13 @@ int InputManager::getButtonCountByDevice(SDL_JoystickID id)
else
return SDL_JoystickNumButtons(mJoysticks[id]);
}
int InputManager::getAxisCountByDevice(SDL_JoystickID id)
{
if(id == DEVICE_KEYBOARD)
return 0; //it's zero, okay.
else
return SDL_JoystickNumAxes(mJoysticks[id]);
}
InputConfig* InputManager::getInputConfigByDevice(int device)
{
if(device == DEVICE_KEYBOARD)
......
......@@ -49,6 +49,8 @@ public:
int getNumJoysticks();
int getButtonCountByDevice(int deviceId);
int getAxisCountByDevice(int deviceId);
int getNumConfiguredDevices();
std::string getDeviceGUIDString(int deviceId);
......
......@@ -6,17 +6,22 @@
#include "components/MenuComponent.h"
#include "components/ButtonComponent.h"
#include "Util.h"
#include "InputManager.h"
#include <boost/locale.hpp>
using namespace boost::locale;
static const int inputCount = 17;
static const char* inputName[inputCount] = { "Up", "Down", "Left", "Right", "JoystickUp" , "JoystickLeft", "A", "B", "X", "Y", "Start", "Select", "PageUp", "PageDown", "L2", "R2", "HotKey" };
static const bool inputSkippable[inputCount] = { false, false, false, false, true, true, false, false, true, true, false, false, true, true, true, true, false};
static const char* inputDispName[inputCount] = { gettext("UP"), gettext("DOWN"), gettext("LEFT"), gettext("RIGHT"), gettext("JOYSTICK UP"), gettext("JOYSTICK LEFT"),
static const int AXIS = 0;
static const int BTN = 1;
static const int HAT = 2;
static const int inputCount = 19;
static const char* inputName[inputCount] = { "Up", "Down", "Left", "Right", "Joystick1Up" , "Joystick1Left", "Joystick2Up" , "Joystick2Left", "A", "B", "X", "Y", "Start", "Select", "PageUp", "PageDown", "L2", "R2", "HotKey" };
static const bool inputSkippable[inputCount] = { false, false, false, false, true, true, true, true, false, false, true, true, false, false, true, true, true, true, false};
static const bool inputTypes[inputCount] = { HAT, HAT, HAT, HAT , AXIS, AXIS, AXIS, AXIS, BTN, BTN, BTN, BTN, BTN, BTN, BTN, BTN, BTN, BTN, BTN};
static const char* inputDispName[inputCount] = { gettext("UP"), gettext("DOWN"), gettext("LEFT"), gettext("RIGHT"), gettext("JOYSTICK 1 UP"), gettext("JOYSTICK 1 LEFT"),gettext("JOYSTICK 2 UP"), gettext("JOYSTICK 2 LEFT"),
"A", "B", "X", "Y", "START", "SELECT ", gettext("PAGE UP"), gettext("PAGE DOWN"), "L2", "R2", gettext("HOTKEY") };
static const char* inputIcon[inputCount] = { ":/help/dpad_up.svg", ":/help/dpad_down.svg", ":/help/dpad_left.svg", ":/help/dpad_right.svg", ":/help/joystick_left.svg", ":/help/joystick_right.svg",
":/help/button_a.svg", ":/help/button_b.svg", ":/help/button_x.svg", ":/help/button_y.svg", ":/help/button_start.svg", ":/help/button_select.svg",
static const char* inputIcon[inputCount] = { ":/help/dpad_up.svg", ":/help/dpad_down.svg", ":/help/dpad_left.svg", ":/help/dpad_right.svg", ":/help/joystick_left.svg", ":/help/joystick_right.svg", ":/help/joystick_left.svg", ":/help/joystick_right.svg",
":/help/button_a.svg", ":/help/button_b.svg", ":/help/button_x.svg", ":/help/button_y.svg", ":/help/button_start.svg", ":/help/button_select.svg",
":/help/button_l.svg", ":/help/button_r.svg", ":/help/button_l2.svg", ":/help/button_r2.svg", ":/help/button_hotkey.svg" };
//MasterVolUp and MasterVolDown are also hooked up, but do not appear on this screen.
......@@ -24,7 +29,7 @@ static const char* inputIcon[inputCount] = { ":/help/dpad_up.svg", ":/help/dpad_
using namespace Eigen;
#define HOLD_TO_SKIP_MS 5000
#define HOLD_TO_SKIP_MS 2000
GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfigureAll, const std::function<void()>& okCallback) : GuiComponent(window),
mBackground(window, ":/frame.png"), mGrid(window, Vector2i(1, 7)),
......@@ -62,10 +67,18 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi
mList = std::make_shared<ComponentList>(mWindow);
mGrid.setEntry(mList, Vector2i(0, 5), true, true);
int nbAxis = InputManager::getInstance()->getAxisCountByDevice(target->getDeviceId());
int nbButtons = InputManager::getInstance()->getButtonCountByDevice(target->getDeviceId());
int inputRowIndex = 0;
for(int i = 0; i < inputCount; i++)
{
if(inputTypes[i] == AXIS && --nbAxis <= 0){
continue;
}
/*if(inputTypes[i] == BTN && --nbButtons <= 0 && inputSkippable[i] == true){
continue;
}*/
ComponentListRow row;
// icon
auto icon = std::make_shared<ImageComponent>(mWindow);
icon->setImage(inputIcon[i]);
......@@ -86,7 +99,7 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi
row.addElement(mapping, true);
mMappings.push_back(mapping);
row.input_handler = [this, i, mapping](InputConfig* config, Input input) -> bool
row.input_handler = [this, i, inputRowIndex, mapping](InputConfig* config, Input input) -> bool
{
// ignore input not from our target device
if(config != mTargetConfig)
......@@ -118,6 +131,7 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi
mHoldingInput = true;
mHeldInput = input;
mHeldTime = 0;
mHeldInputRowIndex = inputRowIndex;
mHeldInputId = i;
return true;
......@@ -129,7 +143,7 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi
mHoldingInput = false;
if(assign(mHeldInput, i))
if(assign(mHeldInput, i, inputRowIndex))
rowDone(); // if successful, move cursor/stop configuring - if not, we'll just try again
return true;
......@@ -137,6 +151,7 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi
};
mList->addRow(row);
inputRowIndex++;
}
// only show "HOLD TO SKIP" if this input is skippable
......@@ -190,7 +205,7 @@ void GuiInputConfig::update(int deltaTime)
if(mHeldTime >= HOLD_TO_SKIP_MS)
{
setNotDefined(mMappings.at(mHeldInputId));
setNotDefined(mMappings.at(mHeldInputRowIndex));
clearAssignment(mHeldInputId);
mHoldingInput = false;
rowDone();
......@@ -198,7 +213,7 @@ void GuiInputConfig::update(int deltaTime)
if(prevSec != curSec)
{
// crossed the second boundary, update text
const auto& text = mMappings.at(mHeldInputId);
const auto& text = mMappings.at(mHeldInputRowIndex);
std::stringstream ss;
ss << gettext("HOLD FOR ") << HOLD_TO_SKIP_MS/1000 - curSec << gettext("S TO SKIP");
text->setText(ss.str());
......@@ -254,7 +269,7 @@ void GuiInputConfig::error(const std::shared_ptr<TextComponent>& text, const std
text->setColor(0x656565FF);
}
bool GuiInputConfig::assign(Input input, int inputId)
bool GuiInputConfig::assign(Input input, int inputId, int inputIndex)
{
// input is from InputConfig* mTargetConfig
......@@ -263,11 +278,11 @@ bool GuiInputConfig::assign(Input input, int inputId)
if(std::string("HotKey").compare(inputName[inputId]) != 0)
if(mTargetConfig->getMappedTo(input).size() > 0 && !mTargetConfig->isMappedTo(inputName[inputId], input))
{
error(mMappings.at(inputId), "Already mapped!");
error(mMappings.at(inputIndex), "Already mapped!");
return false;
}
setAssignedTo(mMappings.at(inputId), input);
setAssignedTo(mMappings.at(inputIndex), input);
input.configured = true;
mTargetConfig->mapInput(inputName[inputId], input);
......
......@@ -23,7 +23,7 @@ private:
void setNotDefined(const std::shared_ptr<TextComponent>& text); // set text to -NOT DEFINED- + greyed out
void setAssignedTo(const std::shared_ptr<TextComponent>& text, Input input); // set text to "BUTTON 2"/"AXIS 2+", etc.
bool assign(Input input, int inputId);
bool assign(Input input, int inputId, int inputIndex);
void clearAssignment(int inputId);
void rowDone();
......@@ -46,4 +46,5 @@ private:
Input mHeldInput;
int mHeldTime;
int mHeldInputId;
int mHeldInputRowIndex;
};
......@@ -437,11 +437,17 @@ msgstr "S PARA SALTAR"
msgid "HOLD ANY BUTTON TO SKIP"
msgstr "MANTEN CUALQUIER BOTÓN PARA SALTAR"
msgid "JOYSTICK UP"
msgstr "JOYSTICK ARRIBA"
msgid "JOYSTICK 1 UP"
msgstr "JOYSTICK 1 ARRIBA"
msgid "JOYSTICK LEFT"
msgstr "JOYSTICK IZQUIERDA"
msgid "JOYSTICK 1 LEFT"
msgstr "JOYSTICK 1 IZQUIERDA"
msgid "JOYSTICK 2 UP"
msgstr "JOYSTICK 2 ARRIBA"
msgid "JOYSTICK 2 LEFT"
msgstr "JOYSTICK 2 IZQUIERDA"
msgid "I18NMESSAGECONTROLLERS"
msgstr ""
......
......@@ -340,10 +340,14 @@ msgid "S TO SKIP"
msgstr "S POUR PASSER"
msgid "HOLD ANY BUTTON TO SKIP"
msgstr "RESTER APPUYÉ SUR UN BOUTTON POUR PASSER"
msgid "JOYSTICK UP"
msgstr "JOYSTICK HAUT"
msgid "JOYSTICK LEFT"
msgstr "JOYSTICK GAUCHE"
msgid "JOYSTICK 1 UP"
msgstr "JOYSTICK 1 HAUT"
msgid "JOYSTICK 1 LEFT"
msgstr "JOYSTICK 1 GAUCHE"
msgid "JOYSTICK 2 UP"
msgstr "JOYSTICK 2 HAUT"
msgid "JOYSTICK 2 LEFT"
msgstr "JOYSTICK 2 GAUCHE"
msgid "I18NMESSAGECONTROLLERS"
msgstr "VOUS ALLEZ CONFIGURER UNE MANETTE. SI VOUS N'AVEZ QU'UN JOYSTICK OU JUSTE UNE CROIX DIRECTIONNELLE, CONFIGUREZ SEULEMENT LES DIRECTIONS ET PASSEZ LES JOYSTICKS EN RESTANT APPUYÉ SUR UN BOUTON. SI VOUS N'AVEZ PAS DE BOUTON SPECIAL POUR HOTKEY, UTILISEZ SELECT. IGNOREZ UN BOUTON QUE VOTRE MANETTE N'A PAS EN RESTANT APPUYÉ SUR UN BOUTTON DEJA CONFIGURÉ."
......
......@@ -340,10 +340,14 @@ msgid "S TO SKIP"
msgstr "S PER SALTARE"
msgid "HOLD ANY BUTTON TO SKIP"
msgstr "TIENI PREMUTO UN PULSANTE PER SALTARE"
msgid "JOYSTICK UP"
msgstr "JOYSTICK SU"
msgid "JOYSTICK LEFT"
msgstr "JOYSTICK SINISTRA"
msgid "JOYSTICK 1 UP"
msgstr "JOYSTICK 1 SU"
msgid "JOYSTICK 1 LEFT"
msgstr "JOYSTICK 1 SINISTRA"
msgid "JOYSTICK 2 UP"
msgstr "JOYSTICK 2 SU"
msgid "JOYSTICK 2 LEFT"
msgstr "JOYSTICK 2 SINISTRA"
msgid "I18NMESSAGECONTROLLERS"
msgstr "STAI PER CONFIGURARE UN GAMEPAD. SE POSSIEDI UN GAMEPAD DOTATO SOLTANTO DI UNA CROCE DIREZIONALE, CONFIGURA SOLAMENTE LE DIREZIONI E SALTA IL RESTO TENENDO PREMUTO UN PULSANTE. SE NON PUOI CONFIGURARE UN PULSANTE APPOSITO PER L'HOTKEY, UTILIZZA SELECT. PUOI IGNORARE UN PULSANTE NON PRESENTE SUL TUO GAMEPAD PREMENDO UN PULSANTE GIA' CONFIGURATO IN PRECEDENZA."
......
......@@ -331,10 +331,14 @@ msgid "S TO SKIP"
msgstr "S PARA PULAR"
msgid "HOLD ANY BUTTON TO SKIP"
msgstr "MANTENHA PRESSIONADO QUALQUER BOTÃO PARA PULAR CONFIGURAÇÃO"
msgid "JOYSTICK UP"
msgstr "ANALÓGICO PARA CIMA"
msgid "JOYSTICK LEFT"
msgstr "ANALÓGICO PARA ESQUERDA"
msgid "JOYSTICK 1 UP"
msgstr "ANALÓGICO 1 PARA CIMA"
msgid "JOYSTICK 1 LEFT"
msgstr "ANALÓGICO 1 PARA ESQUERDA"
msgid "JOYSTICK 2 UP"
msgstr "ANALÓGICO 2 PARA CIMA"
msgid "JOYSTICK 2 LEFT"
msgstr "ANALÓGICO 2 PARA ESQUERDA"
#TEXT EDITING
msgid "EDIT"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment