Some fixes for gamepad on android

This commit is contained in:
Deve 2018-03-06 23:23:15 +01:00
parent e00074cb14
commit 022dd68a17
11 changed files with 114 additions and 48 deletions

View File

@ -179,23 +179,27 @@ namespace irr
IRR_KEY_PA1 = 0xFD, // PA1 key
IRR_KEY_OEM_CLEAR = 0xFE, // Clear key
IRR_KEY_BUTTON_A = 0x100,
IRR_KEY_BUTTON_B = 0x101,
IRR_KEY_BUTTON_C = 0x102,
IRR_KEY_BUTTON_X = 0x103,
IRR_KEY_BUTTON_Y = 0x104,
IRR_KEY_BUTTON_Z = 0x105,
IRR_KEY_BUTTON_L1 = 0x106,
IRR_KEY_BUTTON_R1 = 0x107,
IRR_KEY_BUTTON_L2 = 0x108,
IRR_KEY_BUTTON_R2 = 0x109,
IRR_KEY_BUTTON_THUMBL = 0x10A,
IRR_KEY_BUTTON_THUMBR = 0x11B,
IRR_KEY_BUTTON_START = 0x11C,
IRR_KEY_BUTTON_SELECT = 0x11D,
IRR_KEY_BUTTON_MODE = 0x11E,
IRR_KEY_BUTTON_LEFT = 0x100,
IRR_KEY_BUTTON_RIGHT = 0x101,
IRR_KEY_BUTTON_UP = 0x102,
IRR_KEY_BUTTON_DOWN = 0x103,
IRR_KEY_BUTTON_A = 0x104,
IRR_KEY_BUTTON_B = 0x105,
IRR_KEY_BUTTON_C = 0x106,
IRR_KEY_BUTTON_X = 0x107,
IRR_KEY_BUTTON_Y = 0x108,
IRR_KEY_BUTTON_Z = 0x109,
IRR_KEY_BUTTON_L1 = 0x10A,
IRR_KEY_BUTTON_R1 = 0x10B,
IRR_KEY_BUTTON_L2 = 0x10C,
IRR_KEY_BUTTON_R2 = 0x10D,
IRR_KEY_BUTTON_THUMBL = 0x10E,
IRR_KEY_BUTTON_THUMBR = 0x10F,
IRR_KEY_BUTTON_START = 0x110,
IRR_KEY_BUTTON_SELECT = 0x111,
IRR_KEY_BUTTON_MODE = 0x112,
IRR_KEY_CODES_COUNT = 0x11F // this is not a key, but the amount of keycodes there are.
IRR_KEY_CODES_COUNT = 0x113 // this is not a key, but the amount of keycodes there are.
};
} // end namespace irr

View File

@ -760,15 +760,16 @@ s32 CIrrDeviceAndroid::handleGamepad(AInputEvent* androidEvent)
if (GamepadAxisX != 0)
{
event.KeyInput.PressedDown = false;
event.KeyInput.Key = GamepadAxisX < 0 ? IRR_KEY_LEFT
: IRR_KEY_RIGHT;
event.KeyInput.Key = GamepadAxisX < 0 ? IRR_KEY_BUTTON_LEFT
: IRR_KEY_BUTTON_RIGHT;
postEventFromUser(event);
}
if (axis_x != 0)
{
event.KeyInput.PressedDown = true;
event.KeyInput.Key = axis_x < 0 ? IRR_KEY_LEFT : IRR_KEY_RIGHT;
event.KeyInput.Key = axis_x < 0 ? IRR_KEY_BUTTON_LEFT
: IRR_KEY_BUTTON_RIGHT;
postEventFromUser(event);
}
@ -780,15 +781,16 @@ s32 CIrrDeviceAndroid::handleGamepad(AInputEvent* androidEvent)
if (GamepadAxisY != 0)
{
event.KeyInput.PressedDown = false;
event.KeyInput.Key = GamepadAxisY < 0 ? IRR_KEY_UP
: IRR_KEY_DOWN;
event.KeyInput.Key = GamepadAxisY < 0 ? IRR_KEY_BUTTON_UP
: IRR_KEY_BUTTON_DOWN;
postEventFromUser(event);
}
if (axis_y != 0)
{
event.KeyInput.PressedDown = true;
event.KeyInput.Key = axis_y < 0 ? IRR_KEY_UP : IRR_KEY_DOWN;
event.KeyInput.Key = axis_y < 0 ? IRR_KEY_BUTTON_UP
: IRR_KEY_BUTTON_DOWN;
postEventFromUser(event);
}

View File

@ -95,6 +95,7 @@ public:
irr::core::stringw getMappingIdString (const PlayerAction action) const;
virtual irr::core::stringw getBindingAsString(const PlayerAction action) const;
virtual bool isGamePad() const = 0;
virtual bool isGamePadAndroid() const = 0;
virtual bool isKeyboard() const = 0;
virtual void save(std::ofstream& stream);

View File

@ -82,11 +82,26 @@ bool DeviceManager::initialize()
Log::info("Device manager","No keyboard configuration exists, creating one.");
m_keyboard_configs.push_back(new KeyboardConfig());
#ifdef ANDROID
m_keyboard_configs.push_back(new GamepadAndroidConfig());
#endif
created = true;
}
#ifdef ANDROID
bool has_gamepad_android_config = false;
for (unsigned int i = 0; i < m_keyboard_configs.size(); i++)
{
if (m_keyboard_configs[i].isGamePadAndroid())
{
has_gamepad_android_config = true;
}
}
if (!has_gamepad_android_config)
{
m_keyboard_configs.push_back(new GamepadAndroidConfig());
created = true;
}
#endif
const int keyboard_amount = m_keyboard_configs.size();
for (int n = 0; n < keyboard_amount; n++)

View File

@ -53,6 +53,18 @@ irr::core::stringw GamepadAndroidConfig::getBindingAsString(const PlayerAction a
switch (id)
{
case IRR_KEY_BUTTON_LEFT:
button_name = _C("input_key", "Left");
break;
case IRR_KEY_BUTTON_RIGHT:
button_name = _C("input_key", "Right");
break;
case IRR_KEY_BUTTON_UP:
button_name = _C("input_key", "Up");
break;
case IRR_KEY_BUTTON_DOWN:
button_name = _C("input_key", "Down");
break;
case IRR_KEY_BUTTON_A:
button_name = "A";
break;
@ -111,20 +123,20 @@ irr::core::stringw GamepadAndroidConfig::getBindingAsString(const PlayerAction a
void GamepadAndroidConfig::setDefaultBinds()
{
setBinding(PA_NITRO, Input::IT_KEYBOARD, IRR_KEY_BUTTON_X);
setBinding(PA_ACCEL, Input::IT_KEYBOARD, IRR_KEY_UP);
setBinding(PA_BRAKE, Input::IT_KEYBOARD, IRR_KEY_DOWN);
setBinding(PA_STEER_LEFT, Input::IT_KEYBOARD, IRR_KEY_LEFT);
setBinding(PA_STEER_RIGHT, Input::IT_KEYBOARD, IRR_KEY_RIGHT);
setBinding(PA_ACCEL, Input::IT_KEYBOARD, IRR_KEY_BUTTON_UP);
setBinding(PA_BRAKE, Input::IT_KEYBOARD, IRR_KEY_BUTTON_DOWN);
setBinding(PA_STEER_LEFT, Input::IT_KEYBOARD, IRR_KEY_BUTTON_LEFT);
setBinding(PA_STEER_RIGHT, Input::IT_KEYBOARD, IRR_KEY_BUTTON_RIGHT);
setBinding(PA_DRIFT, Input::IT_KEYBOARD, IRR_KEY_BUTTON_Y);
setBinding(PA_RESCUE, Input::IT_KEYBOARD, IRR_KEY_BUTTON_L1);
setBinding(PA_FIRE, Input::IT_KEYBOARD, IRR_KEY_BUTTON_A);
setBinding(PA_LOOK_BACK, Input::IT_KEYBOARD, IRR_KEY_BUTTON_R1);
setBinding(PA_PAUSE_RACE, Input::IT_KEYBOARD, IRR_KEY_BUTTON_B);
setBinding(PA_MENU_UP, Input::IT_KEYBOARD, IRR_KEY_UP);
setBinding(PA_MENU_DOWN, Input::IT_KEYBOARD, IRR_KEY_DOWN);
setBinding(PA_MENU_LEFT, Input::IT_KEYBOARD, IRR_KEY_LEFT);
setBinding(PA_MENU_RIGHT, Input::IT_KEYBOARD, IRR_KEY_RIGHT);
setBinding(PA_MENU_UP, Input::IT_KEYBOARD, IRR_KEY_BUTTON_UP);
setBinding(PA_MENU_DOWN, Input::IT_KEYBOARD, IRR_KEY_BUTTON_DOWN);
setBinding(PA_MENU_LEFT, Input::IT_KEYBOARD, IRR_KEY_BUTTON_LEFT);
setBinding(PA_MENU_RIGHT, Input::IT_KEYBOARD, IRR_KEY_BUTTON_RIGHT);
setBinding(PA_MENU_SELECT, Input::IT_KEYBOARD, IRR_KEY_BUTTON_A);
setBinding(PA_MENU_CANCEL, Input::IT_KEYBOARD, IRR_KEY_BUTTON_B);
}

View File

@ -46,6 +46,8 @@ public:
// ------------------------------------------------------------------------
virtual bool isGamePad() const { return false; }
// ------------------------------------------------------------------------
virtual bool isGamePadAndroid() const { return true; }
// ------------------------------------------------------------------------
virtual bool isKeyboard() const { return true; }
}; // class GamepadAndroidConfig

View File

@ -105,6 +105,8 @@ public:
// ------------------------------------------------------------------------
virtual bool isGamePad() const OVERRIDE { return true; }
// ------------------------------------------------------------------------
virtual bool isGamePadAndroid() const OVERRIDE { return false; }
// ------------------------------------------------------------------------
virtual bool isKeyboard() const OVERRIDE { return false; }
}; // class GamepadConfig

View File

@ -109,7 +109,8 @@ void InputManager::handleStaticAction(int key, int value)
// When no players... a cutscene
if (race_manager->getNumPlayers() == 0 && world != NULL && value > 0 &&
(key == IRR_KEY_SPACE || key == IRR_KEY_RETURN))
(key == IRR_KEY_SPACE || key == IRR_KEY_RETURN ||
key == IRR_KEY_BUTTON_A))
{
world->onFirePressed(NULL);
}
@ -658,12 +659,17 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID,
{
action = PA_BEFORE_FIRST;
if (button == IRR_KEY_UP) action = PA_MENU_UP;
else if (button == IRR_KEY_DOWN) action = PA_MENU_DOWN;
else if (button == IRR_KEY_LEFT) action = PA_MENU_LEFT;
else if (button == IRR_KEY_RIGHT) action = PA_MENU_RIGHT;
else if (button == IRR_KEY_SPACE) action = PA_MENU_SELECT;
else if (button == IRR_KEY_RETURN) action = PA_MENU_SELECT;
if (button == IRR_KEY_UP) action = PA_MENU_UP;
else if (button == IRR_KEY_DOWN) action = PA_MENU_DOWN;
else if (button == IRR_KEY_LEFT) action = PA_MENU_LEFT;
else if (button == IRR_KEY_RIGHT) action = PA_MENU_RIGHT;
else if (button == IRR_KEY_SPACE) action = PA_MENU_SELECT;
else if (button == IRR_KEY_RETURN) action = PA_MENU_SELECT;
else if (button == IRR_KEY_BUTTON_UP) action = PA_MENU_DOWN;
else if (button == IRR_KEY_BUTTON_DOWN) action = PA_MENU_UP;
else if (button == IRR_KEY_BUTTON_LEFT) action = PA_MENU_LEFT;
else if (button == IRR_KEY_BUTTON_RIGHT) action = PA_MENU_RIGHT;
else if (button == IRR_KEY_BUTTON_A) action = PA_MENU_SELECT;
else if (button == IRR_KEY_TAB)
{
if (shift_mask)
@ -676,7 +682,7 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID,
}
}
if (button == IRR_KEY_RETURN)
if (button == IRR_KEY_RETURN || button == IRR_KEY_BUTTON_A)
{
if (GUIEngine::ModalDialog::isADialogActive() &&
!GUIEngine::ScreenKeyboard::isActive())

View File

@ -45,6 +45,8 @@ public:
// ------------------------------------------------------------------------
virtual bool isGamePad() const { return false; }
// ------------------------------------------------------------------------
virtual bool isGamePadAndroid() const { return false; }
// ------------------------------------------------------------------------
virtual bool isKeyboard() const { return true; }
}; // class KeyboardConfig

View File

@ -106,6 +106,11 @@ void OptionsScreenDevice::init()
delete_button->setLabel(label);
}
else if (m_config->isGamePadAndroid())
{
delete_button->setLabel(_("Delete Configuration"));
delete_button->setActive(false);
}
else
{
delete_button->setLabel(_("Delete Configuration"));
@ -160,7 +165,11 @@ void OptionsScreenDevice::init()
// Disable deletion keyboard configurations
bool in_game = StateManager::get()->getGameState() == GUIEngine::INGAME_MENU;
getWidget<ButtonWidget>("delete")->setActive(!in_game);
if (in_game)
{
getWidget<ButtonWidget>("delete")->setActive(false);
}
} // init
// -----------------------------------------------------------------------------

View File

@ -89,15 +89,26 @@ void OptionsScreenInput::buildDeviceList()
for (int i=0; i<keyboard_config_count; i++)
{
//KeyboardConfig *config = input_manager->getDeviceList()->getKeyboardConfig(i);
KeyboardConfig *config = device_manager->getKeyboardConfig(i);
std::ostringstream kbname;
kbname << "keyboard" << i;
const std::string internal_name = kbname.str();
// since irrLicht's list widget has the nasty tendency to put the
// icons very close to the text, I'm adding spaces to compensate.
devices->addItem(internal_name, (core::stringw(" ") + _("Keyboard %i", i)).c_str(), 0 /* icon */);
if (config->isGamePadAndroid())
{
// since irrLicht's list widget has the nasty tendency to put the
// icons very close to the text, I'm adding spaces to compensate.
devices->addItem(internal_name, (core::stringw(" ") +
_("Gamepad")).c_str(), 1 /* icon */);
}
else
{
// since irrLicht's list widget has the nasty tendency to put the
// icons very close to the text, I'm adding spaces to compensate.
devices->addItem(internal_name, (core::stringw(" ") +
_("Keyboard %i", i)).c_str(), 0 /* icon */);
}
}
const int gpad_config_count = device_manager->getGamePadConfigAmount();