Some work on gamepad support on android.

Still it works only for single gamepad, but at least it's preconfigured and google shouldn't complain about stupid button names.
This commit is contained in:
Deve
2018-03-06 00:19:01 +01:00
parent 8f78d4e891
commit e00074cb14
8 changed files with 233 additions and 20 deletions

View File

@@ -179,7 +179,23 @@ namespace irr
IRR_KEY_PA1 = 0xFD, // PA1 key
IRR_KEY_OEM_CLEAR = 0xFE, // Clear key
IRR_KEY_CODES_COUNT = 0xFF // this is not a key, but the amount of keycodes there are.
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_CODES_COUNT = 0x11F // this is not a key, but the amount of keycodes there are.
};
} // end namespace irr

View File

@@ -944,21 +944,21 @@ void CIrrDeviceAndroid::createKeyMap()
KeyMap[AKEYCODE_SWITCH_CHARSET] = IRR_KEY_UNKNOWN;
// following look like controller inputs
KeyMap[AKEYCODE_BUTTON_A] = IRR_KEY_RETURN;
KeyMap[AKEYCODE_BUTTON_B] = IRR_KEY_ESCAPE;
KeyMap[AKEYCODE_BUTTON_C] = IRR_KEY_2;
KeyMap[AKEYCODE_BUTTON_X] = IRR_KEY_3;
KeyMap[AKEYCODE_BUTTON_Y] = IRR_KEY_4;
KeyMap[AKEYCODE_BUTTON_Z] = IRR_KEY_5;
KeyMap[AKEYCODE_BUTTON_L1] = IRR_KEY_6;
KeyMap[AKEYCODE_BUTTON_R1] = IRR_KEY_7;
KeyMap[AKEYCODE_BUTTON_L2] = IRR_KEY_8;
KeyMap[AKEYCODE_BUTTON_R2] = IRR_KEY_9;
KeyMap[AKEYCODE_BUTTON_THUMBL] = IRR_KEY_RETURN;
KeyMap[AKEYCODE_BUTTON_THUMBR] = IRR_KEY_RETURN;
KeyMap[AKEYCODE_BUTTON_START] = IRR_KEY_RETURN;
KeyMap[AKEYCODE_BUTTON_SELECT] = IRR_KEY_ESCAPE;
KeyMap[AKEYCODE_BUTTON_MODE] = IRR_KEY_MENU;
KeyMap[AKEYCODE_BUTTON_A] = IRR_KEY_BUTTON_A;
KeyMap[AKEYCODE_BUTTON_B] = IRR_KEY_BUTTON_B;
KeyMap[AKEYCODE_BUTTON_C] = IRR_KEY_BUTTON_C;
KeyMap[AKEYCODE_BUTTON_X] = IRR_KEY_BUTTON_X;
KeyMap[AKEYCODE_BUTTON_Y] = IRR_KEY_BUTTON_Y;
KeyMap[AKEYCODE_BUTTON_Z] = IRR_KEY_BUTTON_Z;
KeyMap[AKEYCODE_BUTTON_L1] = IRR_KEY_BUTTON_L1;
KeyMap[AKEYCODE_BUTTON_R1] = IRR_KEY_BUTTON_R1;
KeyMap[AKEYCODE_BUTTON_L2] = IRR_KEY_BUTTON_L2;
KeyMap[AKEYCODE_BUTTON_R2] = IRR_KEY_BUTTON_R2;
KeyMap[AKEYCODE_BUTTON_THUMBL] = IRR_KEY_BUTTON_THUMBL;
KeyMap[AKEYCODE_BUTTON_THUMBR] = IRR_KEY_BUTTON_THUMBR;
KeyMap[AKEYCODE_BUTTON_START] = IRR_KEY_BUTTON_START;
KeyMap[AKEYCODE_BUTTON_SELECT] = IRR_KEY_BUTTON_SELECT;
KeyMap[AKEYCODE_BUTTON_MODE] = IRR_KEY_BUTTON_MODE;
KeyMap[AKEYCODE_ESCAPE] = IRR_KEY_ESCAPE;
KeyMap[AKEYCODE_FORWARD_DEL] = IRR_KEY_DELETE;

View File

@@ -1,4 +1,4 @@
# Modify this file to change the last-modified date when you add/remove a file.
# Modify this file to change the last-modified date when you add/remove a file.
# This will then trigger a new cmake run automatically.
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")

View File

@@ -20,6 +20,7 @@
#include "input/device_config.hpp"
#include "input/gamepad_config.hpp"
#include "input/gamepad_android_config.hpp"
#include "input/keyboard_config.hpp"
#include "io/xml_node.hpp"
#include "utils/log.hpp"
@@ -47,6 +48,10 @@ DeviceConfig* DeviceConfig::create(const XMLNode *config)
{
device_config = new GamepadConfig();
}
else if(config->getName()=="gamepad_android")
{
device_config = new GamepadAndroidConfig();
}
else
{
Log::error("DeviceConfig", "Incorrect type: '%s'.",

View File

@@ -23,6 +23,7 @@
#include "config/user_config.hpp"
#include "graphics/irr_driver.hpp"
#include "input/gamepad_android_config.hpp"
#include "input/gamepad_device.hpp"
#include "input/keyboard_device.hpp"
#include "input/multitouch_device.hpp"
@@ -80,6 +81,10 @@ bool DeviceManager::initialize()
if(UserConfigParams::logMisc())
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;
}
@@ -568,12 +573,13 @@ bool DeviceManager::load()
config->getName().c_str());
continue;
}
if(config->getName()=="keyboard")
if (config->getName() == "keyboard" ||
config->getName() == "gamepad_android")
{
KeyboardConfig *kc = static_cast<KeyboardConfig*>(device_config);
m_keyboard_configs.push_back(kc);
}
else if (config->getName()=="gamepad")
else if (config->getName() == "gamepad")
{
GamepadConfig *gc = static_cast<GamepadConfig*>(device_config);
m_gamepad_configs.push_back(gc);

View File

@@ -0,0 +1,133 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2010-2015 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "input/gamepad_android_config.hpp"
#include "utils/translation.hpp"
#include <SKeyMap.h>
using namespace irr;
GamepadAndroidConfig::GamepadAndroidConfig()
{
setDefaultBinds();
}
// ----------------------------------------------------------------------------
/** Saves the configuration to a file. It writes the name for a gamepad
* config, saves the device specific parameters, and calls
* DeviceConfig::save() to save the rest.
* \param stream The stream to save to.
*/
void GamepadAndroidConfig::save(std::ofstream& stream)
{
stream << "<gamepad_android ";
DeviceConfig::save(stream);
stream << "</gamepad_android>\n\n";
} // save
// ----------------------------------------------------------------------------
irr::core::stringw GamepadAndroidConfig::getBindingAsString(const PlayerAction action) const
{
const Binding &b = getBinding(action);
int id = b.getId();
irr::core::stringw button_name;
switch (id)
{
case IRR_KEY_BUTTON_A:
button_name = "A";
break;
case IRR_KEY_BUTTON_B:
button_name = "B";
break;
case IRR_KEY_BUTTON_C:
button_name = "C";
break;
case IRR_KEY_BUTTON_X:
button_name = "X";
break;
case IRR_KEY_BUTTON_Y:
button_name = "Y";
break;
case IRR_KEY_BUTTON_Z:
button_name = "Z";
break;
case IRR_KEY_BUTTON_L1:
button_name = "L1";
break;
case IRR_KEY_BUTTON_R1:
button_name = "R1";
break;
case IRR_KEY_BUTTON_L2:
button_name = "L2";
break;
case IRR_KEY_BUTTON_R2:
button_name = "R2";
break;
case IRR_KEY_BUTTON_THUMBL:
button_name = _C("input_key", "Thumb Left");
break;
case IRR_KEY_BUTTON_THUMBR:
button_name = _C("input_key", "Thumb Right");
break;
case IRR_KEY_BUTTON_START:
button_name = _C("input_key", "Start");
break;
case IRR_KEY_BUTTON_SELECT:
button_name = _C("input_key", "Select");
break;
case IRR_KEY_BUTTON_MODE:
button_name = _C("input_key", "Mode");
break;
default:
button_name = DeviceConfig::getBindingAsString(action);
break;
}
return button_name;
}
// ----------------------------------------------------------------------------
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_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_SELECT, Input::IT_KEYBOARD, IRR_KEY_BUTTON_A);
setBinding(PA_MENU_CANCEL, Input::IT_KEYBOARD, IRR_KEY_BUTTON_B);
}
//------------------------------------------------------------------------------

View File

@@ -0,0 +1,53 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2010-2015 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_GAMEPAD_ANDROID_CONFIG_HPP
#define HEADER_GAMEPAD_ANDROID_CONFIG_HPP
#include "input/binding.hpp"
#include "input/keyboard_config.hpp"
#include "input/input.hpp"
#include "utils/no_copy.hpp"
#include "utils/cpp2011.hpp"
#include <iosfwd>
/**
* \brief specialisation of DeviceConfig for android gamepad devices
* \ingroup config
*/
class GamepadAndroidConfig : public KeyboardConfig
{
public:
GamepadAndroidConfig();
virtual ~GamepadAndroidConfig() {}
virtual void setDefaultBinds();
virtual void save(std::ofstream& stream);
virtual irr::core::stringw getBindingAsString(const PlayerAction action) const;
// ------------------------------------------------------------------------
virtual bool isGamePad() const { return false; }
// ------------------------------------------------------------------------
virtual bool isKeyboard() const { return true; }
}; // class GamepadAndroidConfig
#endif

View File

@@ -39,7 +39,7 @@ public:
KeyboardConfig();
virtual ~KeyboardConfig() {}
void setDefaultBinds ();
virtual void setDefaultBinds();
virtual void save(std::ofstream& stream);
// ------------------------------------------------------------------------