Major update to input handling code to support our #1 feature request : menu navigation should not be tied to accelerate/brake/steer, there should be keys especially for menu navigation. Note that the code is not yet complete, namely you cannot configure the menu keys
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5369 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
abab119b6d
commit
c5b50e5a5c
@ -48,15 +48,38 @@ void DeviceConfig::setBinding ( const PlayerAction action,
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Don't call this directly unless you are KeyboardDevice or GamepadDevice
|
||||
bool DeviceConfig::getAction ( Input::InputType type,
|
||||
const int id,
|
||||
const int value,
|
||||
PlayerAction* action /* out */ )
|
||||
bool DeviceConfig::getGameAction(Input::InputType type,
|
||||
const int id,
|
||||
const int value,
|
||||
PlayerAction* action /* out */ )
|
||||
{
|
||||
return doGetAction(type, id, value, PA_FIRST_GAME_ACTION, PA_LAST_GAME_ACTION, action);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Don't call this directly unless you are KeyboardDevice or GamepadDevice
|
||||
bool DeviceConfig::getMenuAction(Input::InputType type,
|
||||
const int id,
|
||||
const int value,
|
||||
PlayerAction* action /* out */ )
|
||||
{
|
||||
return doGetAction(type, id, value, PA_FIRST_MENU_ACTION, PA_LAST_MENU_ACTION, action);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
bool DeviceConfig::doGetAction(Input::InputType type,
|
||||
const int id,
|
||||
const int value,
|
||||
const PlayerAction firstActionToCheck,
|
||||
const PlayerAction lastActionToCheck,
|
||||
PlayerAction* action /* out */ )
|
||||
{
|
||||
bool success = false;
|
||||
int n;
|
||||
|
||||
for (n = 0; ((n < PA_COUNT) && (!success)); n++)
|
||||
for (n = firstActionToCheck; ((n <= lastActionToCheck) && (!success)); n++)
|
||||
{
|
||||
if ((m_bindings[n].type == type) && (m_bindings[n].id == id))
|
||||
{
|
||||
@ -64,7 +87,7 @@ bool DeviceConfig::getAction ( Input::InputType type,
|
||||
if (type == Input::IT_STICKMOTION)
|
||||
{
|
||||
if ( ((m_bindings[n].dir == Input::AD_POSITIVE) && (value > 0)) ||
|
||||
((m_bindings[n].dir == Input::AD_NEGATIVE) && (value < 0)) )
|
||||
((m_bindings[n].dir == Input::AD_NEGATIVE) && (value < 0)) )
|
||||
{
|
||||
success = true;
|
||||
*action = (PlayerAction)n;
|
||||
@ -163,6 +186,11 @@ bool DeviceConfig::deserializeAction(irr::io::IrrXMLReader* xml)
|
||||
printf("WARNING: IT_STICKMOTION without direction, ignoring.\n");
|
||||
}
|
||||
} // end if binding_id != -1
|
||||
else
|
||||
{
|
||||
printf("WARNING: DeviceConfig::deserializeAction : action '%s' is unknown\n", name_string);
|
||||
}
|
||||
|
||||
} // end if name_string != NULL ...
|
||||
} // end if xml == NULL ... else
|
||||
|
||||
@ -189,12 +217,20 @@ void KeyboardConfig::setDefaultBinds()
|
||||
setBinding(PA_NITRO, Input::IT_KEYBOARD, KEY_KEY_N);
|
||||
setBinding(PA_ACCEL, Input::IT_KEYBOARD, KEY_UP);
|
||||
setBinding(PA_BRAKE, Input::IT_KEYBOARD, KEY_DOWN);
|
||||
setBinding(PA_LEFT, Input::IT_KEYBOARD, KEY_LEFT);
|
||||
setBinding(PA_RIGHT, Input::IT_KEYBOARD, KEY_RIGHT);
|
||||
setBinding(PA_STEER_LEFT, Input::IT_KEYBOARD, KEY_LEFT);
|
||||
setBinding(PA_STEER_RIGHT, Input::IT_KEYBOARD, KEY_RIGHT);
|
||||
setBinding(PA_DRIFT, Input::IT_KEYBOARD, KEY_KEY_V);
|
||||
setBinding(PA_RESCUE, Input::IT_KEYBOARD, KEY_BACK);
|
||||
setBinding(PA_FIRE, Input::IT_KEYBOARD, KEY_SPACE);
|
||||
setBinding(PA_LOOK_BACK, Input::IT_KEYBOARD, KEY_KEY_B);
|
||||
|
||||
|
||||
setBinding(PA_MENU_UP, Input::IT_KEYBOARD, KEY_UP);
|
||||
setBinding(PA_MENU_DOWN, Input::IT_KEYBOARD, KEY_DOWN);
|
||||
setBinding(PA_MENU_LEFT, Input::IT_KEYBOARD, KEY_LEFT);
|
||||
setBinding(PA_MENU_RIGHT, Input::IT_KEYBOARD, KEY_RIGHT);
|
||||
setBinding(PA_MENU_SELECT, Input::IT_KEYBOARD, KEY_RETURN);
|
||||
setBinding(PA_MENU_CANCEL, Input::IT_KEYBOARD, KEY_BACK);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -219,8 +255,8 @@ void GamepadConfig::serialize (std::ofstream& stream)
|
||||
|
||||
void GamepadConfig::setDefaultBinds ()
|
||||
{
|
||||
setBinding(PA_LEFT, Input::IT_STICKMOTION, 0, Input::AD_NEGATIVE);
|
||||
setBinding(PA_RIGHT, Input::IT_STICKMOTION, 0, Input::AD_POSITIVE);
|
||||
setBinding(PA_STEER_LEFT, Input::IT_STICKMOTION, 0, Input::AD_NEGATIVE);
|
||||
setBinding(PA_STEER_RIGHT, Input::IT_STICKMOTION, 0, Input::AD_POSITIVE);
|
||||
setBinding(PA_ACCEL, Input::IT_STICKMOTION, 1, Input::AD_NEGATIVE);
|
||||
setBinding(PA_BRAKE, Input::IT_STICKMOTION, 1, Input::AD_POSITIVE);
|
||||
setBinding(PA_FIRE, Input::IT_STICKBUTTON, 0);
|
||||
@ -228,6 +264,13 @@ void GamepadConfig::setDefaultBinds ()
|
||||
setBinding(PA_DRIFT, Input::IT_STICKBUTTON, 2);
|
||||
setBinding(PA_RESCUE, Input::IT_STICKBUTTON, 3);
|
||||
setBinding(PA_LOOK_BACK, Input::IT_STICKBUTTON, 4);
|
||||
|
||||
setBinding(PA_MENU_UP, Input::IT_STICKMOTION, 0, Input::AD_NEGATIVE);
|
||||
setBinding(PA_MENU_DOWN, Input::IT_STICKMOTION, 0, Input::AD_POSITIVE);
|
||||
setBinding(PA_MENU_LEFT, Input::IT_STICKMOTION, 1, Input::AD_NEGATIVE);
|
||||
setBinding(PA_MENU_RIGHT, Input::IT_STICKMOTION, 1, Input::AD_POSITIVE);
|
||||
setBinding(PA_MENU_SELECT, Input::IT_STICKBUTTON, 0);
|
||||
setBinding(PA_MENU_CANCEL, Input::IT_STICKBUTTON, 3);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -51,6 +51,16 @@ protected:
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief internal helper method for DeviceConfig::getGameAction and DeviceConfig::getMenuAction
|
||||
*/
|
||||
bool doGetAction(Input::InputType type,
|
||||
const int id,
|
||||
const int value,
|
||||
const PlayerAction firstActionToCheck,
|
||||
const PlayerAction lastActionToCheck,
|
||||
PlayerAction* action /* out */ );
|
||||
|
||||
public:
|
||||
|
||||
std::string getName () const { return m_name; };
|
||||
@ -70,14 +80,27 @@ public:
|
||||
bool isPlugged () {return m_plugged;}
|
||||
|
||||
/**
|
||||
* Don't call this directly unless you are KeyboardDevice or GamepadDevice
|
||||
* \brief Searches for a game actions associated with the given input event
|
||||
* \note Don't call this directly unless you are KeyboardDevice or GamepadDevice
|
||||
* \param[out] action the result, only set if method returned true
|
||||
* \return whether finding an action associated to this input was successful
|
||||
*/
|
||||
bool getAction (Input::InputType type,
|
||||
bool getGameAction (Input::InputType type,
|
||||
const int id,
|
||||
const int value,
|
||||
PlayerAction* action /* out */);
|
||||
|
||||
/**
|
||||
* \brief Searches for a game actions associated with the given input event
|
||||
* \note Don't call this directly unless you are KeyboardDevice or GamepadDevice
|
||||
* \param[out] action the result, only set if method returned true
|
||||
* \return whether finding an action associated to this input was successful
|
||||
*/
|
||||
bool getMenuAction (Input::InputType type,
|
||||
const int id,
|
||||
const int value,
|
||||
PlayerAction* action /* out */);
|
||||
|
||||
KeyBinding getBinding (int i) {return m_bindings[i];}
|
||||
|
||||
bool hasBindingFor(const int buttonID) const;
|
||||
|
@ -724,10 +724,12 @@ void render(float elapsed_time)
|
||||
{
|
||||
(*it).m_time -= dt;
|
||||
|
||||
core::rect<s32> msgRect(core::position2d<s32>(0, y_from - count*text_height),
|
||||
core::dimension2d<s32>(screen_size.Width, text_height) );
|
||||
|
||||
Private::g_driver->draw2DRectangle( SColor(255,252,248,230), msgRect);
|
||||
Private::g_font->draw((*it).m_message.c_str(),
|
||||
core::rect<s32>( core::position2d<s32>(0, y_from - count*text_height),
|
||||
core::dimension2d<s32>(screen_size.Width, text_height) ),
|
||||
msgRect,
|
||||
video::SColor(255, 255, 0, 0),
|
||||
true /* hcenter */, true /* vcenter */);
|
||||
count++;
|
||||
|
@ -104,7 +104,8 @@ void EventHandler::processGUIAction(const PlayerAction action, const unsigned in
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case PA_LEFT:
|
||||
case PA_STEER_LEFT:
|
||||
case PA_MENU_LEFT:
|
||||
{
|
||||
Widget* w = GUIEngine::getFocusForPlayer(playerID);
|
||||
if (w == NULL) break;
|
||||
@ -132,7 +133,8 @@ void EventHandler::processGUIAction(const PlayerAction action, const unsigned in
|
||||
}
|
||||
break;
|
||||
|
||||
case PA_RIGHT:
|
||||
case PA_STEER_RIGHT:
|
||||
case PA_MENU_RIGHT:
|
||||
{
|
||||
Widget* w = GUIEngine::getFocusForPlayer(playerID);
|
||||
if (w == NULL) break;
|
||||
@ -159,18 +161,22 @@ void EventHandler::processGUIAction(const PlayerAction action, const unsigned in
|
||||
break;
|
||||
|
||||
case PA_ACCEL:
|
||||
case PA_MENU_UP:
|
||||
navigateUp(playerID, type, pressedDown);
|
||||
break;
|
||||
|
||||
case PA_BRAKE:
|
||||
case PA_MENU_DOWN:
|
||||
navigateDown(playerID, type, pressedDown);
|
||||
break;
|
||||
|
||||
case PA_RESCUE:
|
||||
case PA_MENU_CANCEL:
|
||||
if (pressedDown) GUIEngine::getStateManager()->escapePressed();
|
||||
break;
|
||||
|
||||
case PA_FIRE:
|
||||
case PA_MENU_SELECT:
|
||||
if (pressedDown && !isWithinATextBox())
|
||||
{
|
||||
Widget* w = GUIEngine::getFocusForPlayer(playerID);
|
||||
|
@ -6,13 +6,15 @@
|
||||
#include "config/player.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "states_screens/kart_selection.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
#define INPUT_MODE_DEBUG 0
|
||||
|
||||
const char* INPUT_FILE_NAME = "input.xml";
|
||||
const char* INPUT_FILE_NAME = "input.xml";
|
||||
const int INPUT_FILE_VERSION = 1;
|
||||
|
||||
DeviceManager::DeviceManager()
|
||||
{
|
||||
@ -195,7 +197,7 @@ void DeviceManager::addGamepad(GamePadDevice* d)
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
InputDevice* DeviceManager::mapKeyboardInput( int btnID,
|
||||
InputDevice* DeviceManager::mapKeyboardInput( int btnID, InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer **player /* out */,
|
||||
PlayerAction *action /* out */ )
|
||||
{
|
||||
@ -207,7 +209,7 @@ InputDevice* DeviceManager::mapKeyboardInput( int btnID,
|
||||
{
|
||||
KeyboardDevice *keyboard = m_keyboards.get(n);
|
||||
|
||||
if (keyboard->hasBinding(btnID, action))
|
||||
if (keyboard->hasBinding(btnID, mode, action))
|
||||
{
|
||||
//std::cout << " binding found in keyboard #" << (n+1) << "; action is " << KartActionStrings[*action] << "\n";
|
||||
if (m_assign_mode == NO_ASSIGN) // Don't set the player in NO_ASSIGN mode
|
||||
@ -231,6 +233,7 @@ InputDevice *DeviceManager::mapGamepadInput( Input::InputType type,
|
||||
int btnID,
|
||||
int axisDir,
|
||||
int value,
|
||||
InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer **player /* out */,
|
||||
PlayerAction *action /* out */)
|
||||
{
|
||||
@ -238,7 +241,7 @@ InputDevice *DeviceManager::mapGamepadInput( Input::InputType type,
|
||||
|
||||
if (gPad != NULL)
|
||||
{
|
||||
if (gPad->hasBinding(type, btnID, value, gPad->getPlayer(), action))
|
||||
if (gPad->hasBinding(type, btnID, value, mode, gPad->getPlayer(), action))
|
||||
{
|
||||
if (m_assign_mode == NO_ASSIGN) // Don't set the player in NO_ASSIGN mode
|
||||
{
|
||||
@ -261,6 +264,7 @@ bool DeviceManager::translateInput( Input::InputType type,
|
||||
int btnID,
|
||||
int axisDir,
|
||||
int value,
|
||||
InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer** player /* out */,
|
||||
PlayerAction* action /* out */ )
|
||||
{
|
||||
@ -270,30 +274,20 @@ bool DeviceManager::translateInput( Input::InputType type,
|
||||
switch (type)
|
||||
{
|
||||
case Input::IT_KEYBOARD:
|
||||
device = mapKeyboardInput(btnID, player, action);
|
||||
device = mapKeyboardInput(btnID, mode, player, action);
|
||||
break;
|
||||
case Input::IT_STICKBUTTON:
|
||||
case Input::IT_STICKMOTION:
|
||||
device = mapGamepadInput(type, deviceID, btnID, axisDir, value, player, action);
|
||||
device = mapGamepadInput(type, deviceID, btnID, axisDir, value, mode, player, action);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
||||
//if (*player != NULL) std::cout << "btn " << btnID << " belongs to player " << (*player)->m_id << std::endl;
|
||||
|
||||
/*
|
||||
if (device != NULL)
|
||||
{
|
||||
std::cout << " binding found; action is " << KartActionStrings[*action] << "\n";
|
||||
}*/
|
||||
|
||||
// Return true if input was successfully translated to an action and player
|
||||
if (device != NULL && abs(value) > Input::MAX_VALUE/2)
|
||||
{
|
||||
//std::cout<< "========== Setting latest device " << (device->getType() == DT_KEYBOARD ? "keyboard" : "gamepad")
|
||||
// << " #" << deviceID << " button=" << btnID << " value=" << value << " ==========\n";
|
||||
|
||||
m_latest_used_device = device;
|
||||
}
|
||||
return (device != NULL);
|
||||
@ -348,6 +342,18 @@ bool DeviceManager::deserialize()
|
||||
|
||||
case irr::io::EXN_ELEMENT:
|
||||
{
|
||||
if (strcmp("input", xml->getNodeName()) == 0)
|
||||
{
|
||||
const char *version_string = xml->getAttributeValue("version");
|
||||
if (version_string == NULL || atoi(version_string) != INPUT_FILE_VERSION)
|
||||
{
|
||||
//I18N: shown when config file is too old
|
||||
GUIEngine::showMessage( _("Please re-configure your key bindings.") );
|
||||
|
||||
GUIEngine::showMessage( _("Your input config file is not compatible with this version of STK.") );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (strcmp("keyboard", xml->getNodeName()) == 0)
|
||||
{
|
||||
keyboard_config = new KeyboardConfig();
|
||||
@ -364,13 +370,13 @@ bool DeviceManager::deserialize()
|
||||
{
|
||||
if(keyboard_config != NULL)
|
||||
if(!keyboard_config->deserializeAction(xml))
|
||||
std::cerr << "Ignoring an ill-formed action in input config.\n";
|
||||
std::cerr << "Ignoring an ill-formed keyboard action in input config.\n";
|
||||
}
|
||||
else if(reading_now == GAMEPAD)
|
||||
{
|
||||
if(gamepad_config != NULL)
|
||||
if(!gamepad_config->deserializeAction(xml))
|
||||
std::cerr << "Ignoring an ill-formed action in input config.\n";
|
||||
std::cerr << "Ignoring an ill-formed gamepad action in input config.\n";
|
||||
}
|
||||
else std::cerr << "Warning: An action is placed in an unexpected area in the input config file.\n";
|
||||
}
|
||||
@ -430,7 +436,7 @@ void DeviceManager::serialize()
|
||||
}
|
||||
|
||||
|
||||
configfile << "<input>\n\n";
|
||||
configfile << "<input version=\"" << INPUT_FILE_VERSION << "\">\n\n";
|
||||
|
||||
for(int n=0; n<m_keyboard_configs.size(); n++)
|
||||
{
|
||||
|
@ -44,6 +44,7 @@ private:
|
||||
*
|
||||
* \param[out] player Which player this input belongs to (only set in ASSIGN mode)
|
||||
* \param[out] action Which action is related to this input trigger
|
||||
* \param mode Used to determine whether to determine menu actions or game actions
|
||||
* \return The device to which this input belongs
|
||||
*/
|
||||
InputDevice *mapGamepadInput ( Input::InputType type,
|
||||
@ -51,6 +52,7 @@ private:
|
||||
int btnID,
|
||||
int axisDir,
|
||||
int value,
|
||||
InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer **player /* out */,
|
||||
PlayerAction *action /* out */);
|
||||
|
||||
@ -59,9 +61,10 @@ private:
|
||||
*
|
||||
* \param[out] player Which player this input belongs to (only set in ASSIGN mode)
|
||||
* \param[out] action Which action is related to this input trigger
|
||||
* \param mode Used to determine whether to determine menu actions or game actions
|
||||
* \return The device to which this input belongs
|
||||
*/
|
||||
InputDevice *mapKeyboardInput ( int btnID,
|
||||
InputDevice *mapKeyboardInput ( int btnID, InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer **player /* out */,
|
||||
PlayerAction *action /* out */);
|
||||
|
||||
@ -102,15 +105,20 @@ public:
|
||||
|
||||
|
||||
/** Given some input, finds to which device it belongs and, using the corresponding device object,
|
||||
* maps this input to the corresponding player and game action. returns false if player/action could not be set.
|
||||
* Special case : can return true but set action to PA_FIRST if the input was used but is not associated to an
|
||||
* action and a player
|
||||
* maps this input to the corresponding player and game action.
|
||||
*
|
||||
* \return false if player/action could not be set.
|
||||
* \note Special case : can return 'true' but set action to PA_BEFORE_FIRST if the input was used but
|
||||
* is not associated to an action and a player
|
||||
*
|
||||
* \param mode used to determine whether to map game actions or menu actions
|
||||
*/
|
||||
bool translateInput( Input::InputType type,
|
||||
int deviceID,
|
||||
int btnID,
|
||||
int axisDir,
|
||||
int value,
|
||||
InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer** player /* out */,
|
||||
PlayerAction* action /* out */ );
|
||||
|
||||
|
@ -106,10 +106,10 @@ struct Input
|
||||
*/
|
||||
enum PlayerAction
|
||||
{
|
||||
PA_FIRST = -1,
|
||||
PA_BEFORE_FIRST = -1,
|
||||
|
||||
PA_LEFT = 0,
|
||||
PA_RIGHT,
|
||||
PA_STEER_LEFT = 0,
|
||||
PA_STEER_RIGHT,
|
||||
PA_ACCEL,
|
||||
PA_BRAKE,
|
||||
PA_NITRO,
|
||||
@ -118,21 +118,40 @@ enum PlayerAction
|
||||
PA_FIRE,
|
||||
PA_LOOK_BACK,
|
||||
|
||||
PA_MENU_UP,
|
||||
PA_MENU_DOWN,
|
||||
PA_MENU_LEFT,
|
||||
PA_MENU_RIGHT,
|
||||
PA_MENU_SELECT,
|
||||
PA_MENU_CANCEL,
|
||||
|
||||
PA_COUNT
|
||||
};
|
||||
|
||||
const PlayerAction PA_FIRST_GAME_ACTION = PA_STEER_LEFT;
|
||||
const PlayerAction PA_LAST_GAME_ACTION = PA_LOOK_BACK;
|
||||
const PlayerAction PA_FIRST_MENU_ACTION = PA_MENU_UP;
|
||||
const PlayerAction PA_LAST_MENU_ACTION = PA_MENU_CANCEL;
|
||||
|
||||
/**
|
||||
* \brief human-readable strings for each PlayerAction
|
||||
* \ingroup input
|
||||
*/
|
||||
static std::string KartActionStrings[PA_COUNT] = {std::string("left"),
|
||||
std::string("right"),
|
||||
static std::string KartActionStrings[PA_COUNT] = {std::string("steerLeft"),
|
||||
std::string("steerRight"),
|
||||
std::string("accel"),
|
||||
std::string("brake"),
|
||||
std::string("nitro"),
|
||||
std::string("drift"),
|
||||
std::string("rescue"),
|
||||
std::string("fire"),
|
||||
std::string("lookBack")};
|
||||
std::string("lookBack"),
|
||||
std::string("menuUp"),
|
||||
std::string("menuDown"),
|
||||
std::string("menuLeft"),
|
||||
std::string("menuRight"),
|
||||
std::string("menuSelect"),
|
||||
std::string("menuCancel")
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -45,12 +45,23 @@ KeyboardDevice::KeyboardDevice()
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
bool KeyboardDevice::hasBinding(const int id, PlayerAction* action /* out */)
|
||||
{
|
||||
return m_configuration->getAction(Input::IT_KEYBOARD, id, 0, action);
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool KeyboardDevice::hasBinding(const int id, InputManager::InputDriverMode mode,
|
||||
PlayerAction* action /* out */)
|
||||
{
|
||||
if (mode == InputManager::INGAME)
|
||||
{
|
||||
return m_configuration->getGameAction(Input::IT_KEYBOARD, id, 0, action);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(mode == InputManager::MENU); // bindings can only be accessed in game and menu modes
|
||||
return m_configuration->getMenuAction(Input::IT_KEYBOARD, id, 0, action);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
@ -58,10 +69,6 @@ bool KeyboardDevice::hasBinding(const int id, PlayerAction* action /* out */)
|
||||
#endif
|
||||
|
||||
|
||||
/** Constructor for GamePadDevice from a connected gamepad for which no configuration existed
|
||||
* (defaults will be used)
|
||||
* \param sdlIndex Index of stick.
|
||||
*/
|
||||
GamePadDevice::GamePadDevice(const int irrIndex, const std::string name, const int axis_count, const int btnAmount, GamepadConfig *configuration)
|
||||
{
|
||||
m_type = DT_GAMEPAD;
|
||||
@ -87,10 +94,14 @@ bool GamePadDevice::isButtonPressed(const int i)
|
||||
{
|
||||
return m_buttonPressed[i];
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void GamePadDevice::setButtonPressed(const int i, bool isButtonPressed)
|
||||
{
|
||||
m_buttonPressed[i] = isButtonPressed;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void GamePadDevice::resetAxisDirection(const int axis,
|
||||
@ -118,15 +129,11 @@ void GamePadDevice::resetAxisDirection(const int axis,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Player ID can either be a player ID or -1. If -1, the method only returns whether a binding exists for this player.
|
||||
* If it's a player name, it also handles axis resets, direction changes, etc.
|
||||
*/
|
||||
|
||||
|
||||
bool GamePadDevice::hasBinding(Input::InputType type, const int id, const int value,
|
||||
InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer* player, PlayerAction* action /* out */)
|
||||
{
|
||||
bool success = false;
|
||||
@ -184,17 +191,27 @@ bool GamePadDevice::hasBinding(Input::InputType type, const int id, const int va
|
||||
|
||||
if (m_configuration != NULL)
|
||||
{
|
||||
success = m_configuration->getAction(type, id, value, action);
|
||||
if (mode == InputManager::INGAME)
|
||||
{
|
||||
success = m_configuration->getGameAction(type, id, value, action);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(mode == InputManager::MENU); // bindings can only be accessed in game and menu modes
|
||||
success = m_configuration->getMenuAction(type, id, value, action);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("hasBinding() called on improperly initialized GamePadDevice\n");
|
||||
fprintf(stderr, "hasBinding() called on improperly initialized GamePadDevice\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/** Destructor for GamePadDevice.
|
||||
*/
|
||||
GamePadDevice::~GamePadDevice()
|
||||
@ -203,3 +220,5 @@ GamePadDevice::~GamePadDevice()
|
||||
|
||||
// FIXME - any need to close devices?
|
||||
} // ~GamePadDevice
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "config/device_config.hpp"
|
||||
#include "input/input.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
|
||||
@ -33,7 +34,7 @@ protected:
|
||||
DeviceConfig* m_configuration;
|
||||
|
||||
public:
|
||||
std::string m_name; // if device has a name; unused for keyboards since AFAIK we can't tell keyboards apart
|
||||
std::string m_name; //!< if device has a name; unused for keyboards since AFAIK we can't tell keyboards apart
|
||||
|
||||
InputDevice();
|
||||
void setConfiguration(DeviceConfig *config) {m_configuration = config;}
|
||||
@ -61,9 +62,10 @@ public:
|
||||
* Checks if this key belongs to this device. if yes, sets action and returns true; otherwise returns false
|
||||
*
|
||||
* \param id ID of the key that was pressed
|
||||
* \param mode Used to determine whether to bind menu actions or game actions
|
||||
* \param[out] action The action associated to this input (only check this value if method returned true)
|
||||
*/
|
||||
bool hasBinding(const int id, PlayerAction* action);
|
||||
bool hasBinding(const int id, InputManager::InputDriverMode mode, PlayerAction* action);
|
||||
|
||||
};
|
||||
|
||||
@ -83,21 +85,28 @@ public:
|
||||
int m_axis_count;
|
||||
int m_button_count;
|
||||
|
||||
GamePadDevice(const int irrIndex, const std::string name, const int axis_number, const int btnAmount, GamepadConfig *configuration);
|
||||
/** Constructor for GamePadDevice from a connected gamepad for which no configuration existed
|
||||
* (defaults will be used)
|
||||
* \param irrIndex Index of stick as given by irrLicht.
|
||||
*/
|
||||
GamePadDevice(const int irrIndex, const std::string name, const int axis_number,
|
||||
const int btnAmount, GamepadConfig *configuration);
|
||||
~GamePadDevice();
|
||||
|
||||
bool isButtonPressed(const int i);
|
||||
void setButtonPressed(const int i, bool isButtonPressed);
|
||||
|
||||
/**
|
||||
* Checks if this key belongs to this device. if yes, sets action and returns true; otherwise returns false.
|
||||
* \return Checks if this key belongs to this device.
|
||||
* If yes, sets action and returns true; otherwise returns false.
|
||||
*
|
||||
* \param player Only passed to know where to send 'axis reset's when necessary
|
||||
* \param id ID of the key that was pressed or of the axis that was triggered (depending on
|
||||
* the value of the 'type' parameter)
|
||||
* \param mode Used to determine whether to map menu actions or game actions
|
||||
* \param[out] action The action associated to this input (only check this value if method returned true)
|
||||
*/
|
||||
bool hasBinding(Input::InputType type, const int id, const int value,
|
||||
bool hasBinding(Input::InputType type, const int id, const int value, InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer* player, PlayerAction* action);
|
||||
|
||||
};
|
||||
|
@ -298,28 +298,29 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID, int btnID,
|
||||
{
|
||||
StateManager::ActivePlayer* player = NULL;
|
||||
PlayerAction action;
|
||||
bool action_found = m_device_manager->translateInput( type, deviceID, btnID, axisDirection, value, &player, &action);
|
||||
bool action_found = m_device_manager->translateInput( type, deviceID, btnID, axisDirection, value,
|
||||
/*m_mode*/INGAME, &player, &action);
|
||||
|
||||
// in menus, some keyboard keys are standard (before each player selected his device)
|
||||
// So if a key could not be mapped to any known binding, fall back to check the defaults.
|
||||
if (!action_found && StateManager::get()->getGameState() != GUIEngine::GAME && type == Input::IT_KEYBOARD &&
|
||||
m_mode == MENU && m_device_manager->getAssignMode() == NO_ASSIGN)
|
||||
{
|
||||
action = PA_FIRST;
|
||||
action = PA_BEFORE_FIRST;
|
||||
|
||||
if (btnID == KEY_UP) action = PA_ACCEL;
|
||||
else if (btnID == KEY_DOWN) action = PA_BRAKE;
|
||||
else if (btnID == KEY_LEFT) action = PA_LEFT;
|
||||
else if (btnID == KEY_RIGHT) action = PA_RIGHT;
|
||||
else if (btnID == KEY_SPACE) action = PA_FIRE;
|
||||
else if (btnID == KEY_RETURN) action = PA_FIRE;
|
||||
if (btnID == KEY_UP) action = PA_MENU_UP;
|
||||
else if (btnID == KEY_DOWN) action = PA_MENU_DOWN;
|
||||
else if (btnID == KEY_LEFT) action = PA_MENU_LEFT;
|
||||
else if (btnID == KEY_RIGHT) action = PA_MENU_RIGHT;
|
||||
else if (btnID == KEY_SPACE) action = PA_MENU_SELECT;
|
||||
else if (btnID == KEY_RETURN) action = PA_MENU_SELECT;
|
||||
|
||||
if (btnID == KEY_RETURN && GUIEngine::ModalDialog::isADialogActive())
|
||||
{
|
||||
GUIEngine::ModalDialog::onEnterPressed();
|
||||
}
|
||||
|
||||
if (action != PA_FIRST)
|
||||
if (action != PA_BEFORE_FIRST)
|
||||
{
|
||||
action_found = true;
|
||||
player = NULL;
|
||||
|
@ -117,7 +117,7 @@ void PlayerController::action(PlayerAction action, int value)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case PA_LEFT:
|
||||
case PA_STEER_LEFT:
|
||||
m_steer_val_l = value;
|
||||
if (value)
|
||||
m_steer_val = value;
|
||||
@ -125,7 +125,7 @@ void PlayerController::action(PlayerAction action, int value)
|
||||
m_steer_val = m_steer_val_r;
|
||||
|
||||
break;
|
||||
case PA_RIGHT:
|
||||
case PA_STEER_RIGHT:
|
||||
m_steer_val_r = -value;
|
||||
if (value)
|
||||
m_steer_val = -value;
|
||||
|
@ -100,7 +100,7 @@ void OptionsScreenInput2::updateInputButtons()
|
||||
}
|
||||
{
|
||||
ButtonWidget* btn = this->getWidget<ButtonWidget>("binding_left");
|
||||
core::stringw binding_name = m_config->getBindingAsString(PA_LEFT);
|
||||
core::stringw binding_name = m_config->getBindingAsString(PA_STEER_LEFT);
|
||||
btn->setLabel( binding_name );
|
||||
|
||||
// check if another binding already uses this key
|
||||
@ -116,7 +116,7 @@ void OptionsScreenInput2::updateInputButtons()
|
||||
}
|
||||
{
|
||||
ButtonWidget* btn = this->getWidget<ButtonWidget>("binding_right");
|
||||
core::stringw binding_name = m_config->getBindingAsString(PA_RIGHT);
|
||||
core::stringw binding_name = m_config->getBindingAsString(PA_STEER_RIGHT);
|
||||
btn->setLabel( binding_name );
|
||||
|
||||
// check if another binding already uses this key
|
||||
@ -352,11 +352,11 @@ void OptionsScreenInput2::eventCallback(Widget* widget, const std::string& name,
|
||||
}
|
||||
else if(name == "binding_left")
|
||||
{
|
||||
binding_to_set = PA_LEFT;
|
||||
binding_to_set = PA_STEER_LEFT;
|
||||
}
|
||||
else if(name == "binding_right")
|
||||
{
|
||||
binding_to_set = PA_RIGHT;
|
||||
binding_to_set = PA_STEER_RIGHT;
|
||||
}
|
||||
else if(name == "binding_fire")
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user