Split GamepadDevice and KeyboarDevice from input_device into their
own files. Renamed InputManager::getDeviceList() to getDeviceManager().
This commit is contained in:
parent
d63a5dba45
commit
ec908d85c6
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include "config/user_config.hpp"
|
#include "config/user_config.hpp"
|
||||||
#include "graphics/irr_driver.hpp"
|
#include "graphics/irr_driver.hpp"
|
||||||
|
#include "input/gamepad_device.hpp"
|
||||||
|
#include "input/keyboard_device.hpp"
|
||||||
#include "input/wiimote_manager.hpp"
|
#include "input/wiimote_manager.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "states_screens/kart_selection.hpp"
|
#include "states_screens/kart_selection.hpp"
|
||||||
@ -139,6 +141,18 @@ bool DeviceManager::initialize()
|
|||||||
return created;
|
return created;
|
||||||
} // initialize
|
} // initialize
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
void DeviceManager::clearKeyboard()
|
||||||
|
{
|
||||||
|
m_keyboards.clearAndDeleteAll();
|
||||||
|
} // clearKeyboard
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
void DeviceManager::clearGamepads()
|
||||||
|
{
|
||||||
|
m_gamepads.clearAndDeleteAll();
|
||||||
|
} // clearGamepads
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
void DeviceManager::setAssignMode(const PlayerAssignMode assignMode)
|
void DeviceManager::setAssignMode(const PlayerAssignMode assignMode)
|
||||||
{
|
{
|
||||||
|
@ -26,6 +26,9 @@
|
|||||||
|
|
||||||
#include <irrArray.h>
|
#include <irrArray.h>
|
||||||
|
|
||||||
|
class GamePadDevice;
|
||||||
|
class KeyboardDevice;
|
||||||
|
|
||||||
enum PlayerAssignMode
|
enum PlayerAssignMode
|
||||||
{
|
{
|
||||||
NO_ASSIGN, //!< react to all devices
|
NO_ASSIGN, //!< react to all devices
|
||||||
@ -118,14 +121,14 @@ public:
|
|||||||
GamePadDevice* getGamePad(const int i) { return m_gamepads.get(i); }
|
GamePadDevice* getGamePad(const int i) { return m_gamepads.get(i); }
|
||||||
GamepadConfig* getGamepadConfig(const int i) { return m_gamepad_configs.get(i); }
|
GamepadConfig* getGamepadConfig(const int i) { return m_gamepad_configs.get(i); }
|
||||||
GamePadDevice* getGamePadFromIrrID(const int i);
|
GamePadDevice* getGamePadFromIrrID(const int i);
|
||||||
void clearGamepads() { m_gamepads.clearAndDeleteAll(); }
|
void clearGamepads();
|
||||||
/** Returns the keyboard that has a binding for this button, or NULL if none */
|
/** Returns the keyboard that has a binding for this button, or NULL if none */
|
||||||
bool getConfigForGamepad(const int sdl_id, const core::stringc& pname, GamepadConfig **config);
|
bool getConfigForGamepad(const int sdl_id, const core::stringc& pname, GamepadConfig **config);
|
||||||
|
|
||||||
// ---- Keyboard(s) ----
|
// ---- Keyboard(s) ----
|
||||||
void addEmptyKeyboard();
|
void addEmptyKeyboard();
|
||||||
void addKeyboard(KeyboardDevice* d);
|
void addKeyboard(KeyboardDevice* d);
|
||||||
void clearKeyboard() { m_keyboards.clearAndDeleteAll(); }
|
void clearKeyboard();
|
||||||
int getKeyboardAmount() { return m_keyboards.size(); }
|
int getKeyboardAmount() { return m_keyboards.size(); }
|
||||||
int getKeyboardConfigAmount() const { return m_keyboard_configs.size(); }
|
int getKeyboardConfigAmount() const { return m_keyboard_configs.size(); }
|
||||||
KeyboardDevice* getKeyboard(const int i) { return m_keyboards.get(i); }
|
KeyboardDevice* getKeyboard(const int i) { return m_keyboards.get(i); }
|
||||||
|
207
src/input/gamepad_device.cpp
Normal file
207
src/input/gamepad_device.cpp
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2013 Marianne Gagnon
|
||||||
|
// 2014 Joerg Henrichs
|
||||||
|
//
|
||||||
|
// 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_device.hpp"
|
||||||
|
|
||||||
|
#include "karts/abstract_kart.hpp"
|
||||||
|
#include "karts/controller/player_controller.hpp"
|
||||||
|
|
||||||
|
GamePadDevice::GamePadDevice(const int irrIndex, const std::string name,
|
||||||
|
const int axis_count, const int button_count,
|
||||||
|
GamepadConfig *configuration)
|
||||||
|
{
|
||||||
|
m_type = DT_GAMEPAD;
|
||||||
|
m_deadzone = DEADZONE_JOYSTICK;
|
||||||
|
m_prev_axis_directions = NULL;
|
||||||
|
m_configuration = configuration;
|
||||||
|
m_axis_count = axis_count;
|
||||||
|
m_prev_axis_directions = new Input::AxisDirection[axis_count];
|
||||||
|
m_prev_axis_value = new int[axis_count];
|
||||||
|
m_axis_ok = new bool[axis_count];
|
||||||
|
m_button_count = button_count;
|
||||||
|
m_index = irrIndex;
|
||||||
|
m_name = name;
|
||||||
|
|
||||||
|
for (int i = 0; i < axis_count; i++)
|
||||||
|
{
|
||||||
|
m_prev_axis_directions[i] = Input::AD_NEUTRAL;
|
||||||
|
m_prev_axis_value[i] = -1;
|
||||||
|
m_axis_ok[i] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int n=0; n<SEvent::SJoystickEvent::NUMBER_OF_BUTTONS; n++)
|
||||||
|
m_buttonPressed[n] = false;
|
||||||
|
} // GamePadDevice
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
/** Destructor for GamePadDevice.
|
||||||
|
*/
|
||||||
|
GamePadDevice::~GamePadDevice()
|
||||||
|
{
|
||||||
|
delete[] m_prev_axis_directions;
|
||||||
|
delete[] m_prev_axis_value;
|
||||||
|
delete[] m_axis_ok;
|
||||||
|
|
||||||
|
// FIXME - any need to close devices?
|
||||||
|
} // ~GamePadDevice
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool GamePadDevice::isButtonPressed(const int i)
|
||||||
|
{
|
||||||
|
return m_buttonPressed[i];
|
||||||
|
} // isButtonPressed
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void GamePadDevice::setButtonPressed(const int i, bool isButtonPressed)
|
||||||
|
{
|
||||||
|
m_buttonPressed[i] = isButtonPressed;
|
||||||
|
} // setButtonPressed
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void GamePadDevice::resetAxisDirection(const int axis,
|
||||||
|
Input::AxisDirection direction,
|
||||||
|
StateManager::ActivePlayer* player)
|
||||||
|
{
|
||||||
|
// ignore this while in menus
|
||||||
|
if (StateManager::get()->getGameState() != GUIEngine::GAME) return;
|
||||||
|
|
||||||
|
AbstractKart* pk = player->getKart();
|
||||||
|
if (pk == NULL)
|
||||||
|
{
|
||||||
|
Log::error("Binding", "Trying to reset axis for an unknown player.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int n=0; n<PA_COUNT; n++)
|
||||||
|
{
|
||||||
|
Binding& bind = m_configuration->getBinding(n);
|
||||||
|
if(bind.getType() == Input::IT_STICKMOTION &&
|
||||||
|
bind.getId() == axis &&
|
||||||
|
bind.getDirection()== direction &&
|
||||||
|
pk->getController() != NULL)
|
||||||
|
{
|
||||||
|
((PlayerController*)(pk->getController()))
|
||||||
|
->action((PlayerAction)n, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // resetAxisDirection
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool GamePadDevice::processAndMapInput(Input::InputType type, const int id,
|
||||||
|
int* value, /* inout */
|
||||||
|
InputManager::InputDriverMode mode,
|
||||||
|
StateManager::ActivePlayer* player,
|
||||||
|
PlayerAction* action /* out */)
|
||||||
|
{
|
||||||
|
if (!m_configuration->isEnabled()) return false;
|
||||||
|
|
||||||
|
bool success = false;
|
||||||
|
if(m_prev_axis_directions == NULL) return false; // device not open
|
||||||
|
|
||||||
|
if (type == Input::IT_STICKMOTION)
|
||||||
|
{
|
||||||
|
// this gamepad doesn't even have that many axes
|
||||||
|
if (id >= m_axis_count) return false;
|
||||||
|
|
||||||
|
if (player != NULL)
|
||||||
|
{
|
||||||
|
// going to negative from positive
|
||||||
|
if (*value < 0 && m_prev_axis_directions[id] == Input::AD_POSITIVE)
|
||||||
|
{
|
||||||
|
// set positive id to 0
|
||||||
|
resetAxisDirection(id, Input::AD_POSITIVE, player);
|
||||||
|
}
|
||||||
|
// going to positive from negative
|
||||||
|
else if (*value > 0 &&
|
||||||
|
m_prev_axis_directions[id] == Input::AD_NEGATIVE)
|
||||||
|
{
|
||||||
|
// set negative id to 0
|
||||||
|
resetAxisDirection(id, Input::AD_NEGATIVE, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*value > 0) m_prev_axis_directions[id] = Input::AD_POSITIVE;
|
||||||
|
else if(*value < 0) m_prev_axis_directions[id] = Input::AD_NEGATIVE;
|
||||||
|
|
||||||
|
if (!m_axis_ok[id])
|
||||||
|
{
|
||||||
|
if (m_prev_axis_value[id] == -1)
|
||||||
|
{
|
||||||
|
// first value we get from this axis
|
||||||
|
m_prev_axis_value[id] = *value;
|
||||||
|
}
|
||||||
|
else if (m_prev_axis_value[id] != *value)
|
||||||
|
{
|
||||||
|
// second different value we get from this axis, consider it OK
|
||||||
|
m_axis_ok[id] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if within deadzone
|
||||||
|
if(*value > -m_deadzone && *value < m_deadzone && player != NULL)
|
||||||
|
{
|
||||||
|
// Axis stands still: This is reported once for digital axes and
|
||||||
|
// can be called multipled times for analog ones. Uses the
|
||||||
|
// previous direction in which the id was triggered to
|
||||||
|
// determine which one has to be brought into the released
|
||||||
|
// state. This allows us to regard two directions of an id
|
||||||
|
// as completely independent input variants (as if they where
|
||||||
|
// two buttons).
|
||||||
|
|
||||||
|
if(m_prev_axis_directions[id] == Input::AD_NEGATIVE)
|
||||||
|
{
|
||||||
|
// set negative id to 0
|
||||||
|
resetAxisDirection(id, Input::AD_NEGATIVE, player);
|
||||||
|
}
|
||||||
|
else if(m_prev_axis_directions[id] == Input::AD_POSITIVE)
|
||||||
|
{
|
||||||
|
// set positive id to 0
|
||||||
|
resetAxisDirection(id, Input::AD_POSITIVE, player);
|
||||||
|
}
|
||||||
|
m_prev_axis_directions[id] = Input::AD_NEUTRAL;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If axis did not send proper values yet, ignore it.
|
||||||
|
if (!m_axis_ok[id]) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (mode == InputManager::INGAME)
|
||||||
|
{
|
||||||
|
success = m_configuration->getGameAction(type, id, value, action);
|
||||||
|
}
|
||||||
|
else if (abs(*value) > Input::MAX_VALUE/2)
|
||||||
|
{
|
||||||
|
// bindings can only be accessed in game and menu modes
|
||||||
|
assert(mode == InputManager::MENU);
|
||||||
|
success = m_configuration->getMenuAction(type, id, value, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
} // processAndMapInput
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
92
src/input/gamepad_device.hpp
Normal file
92
src/input/gamepad_device.hpp
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2013 Marianne Gagnon
|
||||||
|
//
|
||||||
|
// 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_DEVICE_HPP
|
||||||
|
#define HEADER_GAMEPAD_DEVICE_HPP
|
||||||
|
|
||||||
|
#include "input/input_device.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief specialisation of Inputdevice for gamepad type devices
|
||||||
|
* \ingroup input
|
||||||
|
*/
|
||||||
|
class GamePadDevice : public InputDevice
|
||||||
|
{
|
||||||
|
void resetAxisDirection(const int axis, Input::AxisDirection direction,
|
||||||
|
StateManager::ActivePlayer* player);
|
||||||
|
bool m_buttonPressed[SEvent::SJoystickEvent::NUMBER_OF_BUTTONS];
|
||||||
|
|
||||||
|
public:
|
||||||
|
Input::AxisDirection *m_prev_axis_directions;
|
||||||
|
|
||||||
|
/** used to determine if an axis is valid; an axis is considered valid
|
||||||
|
* when at least 2 different values are read from this axis (if an axis
|
||||||
|
* keeps on sending the exact same value continuously, chances are that
|
||||||
|
* it's not meant by the user - for instance some gamepads have hats or
|
||||||
|
* analog switches that get reported as axis, we even had a report that
|
||||||
|
* on linux some hard disks may be reported as gamepads with
|
||||||
|
* uninteresting axis values)
|
||||||
|
*/
|
||||||
|
int *m_prev_axis_value;
|
||||||
|
/** \see m_prev_axis_value */
|
||||||
|
bool *m_axis_ok;
|
||||||
|
|
||||||
|
int m_deadzone;
|
||||||
|
int m_index;
|
||||||
|
int m_axis_count;
|
||||||
|
int m_button_count;
|
||||||
|
|
||||||
|
/** 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);
|
||||||
|
virtual ~GamePadDevice();
|
||||||
|
|
||||||
|
bool isButtonPressed(const int i);
|
||||||
|
void setButtonPressed(const int i, bool isButtonPressed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked when this device it used. Verifies if the key/button that
|
||||||
|
* was pressed is associated with a binding. 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)
|
||||||
|
*
|
||||||
|
* \return Whether the pressed key/button is bound with an action
|
||||||
|
*/
|
||||||
|
bool processAndMapInput(Input::InputType type, const int id,
|
||||||
|
int* value,
|
||||||
|
InputManager::InputDriverMode mode,
|
||||||
|
StateManager::ActivePlayer* player,
|
||||||
|
PlayerAction* action);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -32,6 +32,11 @@ InputDevice::InputDevice()
|
|||||||
m_player = NULL;
|
m_player = NULL;
|
||||||
m_configuration = NULL;
|
m_configuration = NULL;
|
||||||
}
|
}
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
InputDevice::~InputDevice()
|
||||||
|
{
|
||||||
|
} // ~InputDevice
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* Sets which players uses this device; or pass NULL to say no player uses it.
|
* Sets which players uses this device; or pass NULL to say no player uses it.
|
||||||
@ -40,237 +45,3 @@ void InputDevice::setPlayer(StateManager::ActivePlayer* owner)
|
|||||||
{
|
{
|
||||||
m_player = owner;
|
m_player = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark Keyboard
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
KeyboardDevice::KeyboardDevice(KeyboardConfig *configuration)
|
|
||||||
{
|
|
||||||
m_configuration = configuration;
|
|
||||||
m_type = DT_KEYBOARD;
|
|
||||||
m_name = "Keyboard";
|
|
||||||
m_player = NULL;
|
|
||||||
} // KeyboardDevice
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
KeyboardDevice::KeyboardDevice()
|
|
||||||
{
|
|
||||||
m_configuration = new KeyboardConfig();
|
|
||||||
m_type = DT_KEYBOARD;
|
|
||||||
m_player = NULL;
|
|
||||||
} // KeyboardDevice
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool KeyboardDevice::processAndMapInput(const int id,
|
|
||||||
InputManager::InputDriverMode mode,
|
|
||||||
PlayerAction* action /* out */)
|
|
||||||
{
|
|
||||||
if (mode == InputManager::INGAME)
|
|
||||||
{
|
|
||||||
return m_configuration->getGameAction(Input::IT_KEYBOARD, id, 0,
|
|
||||||
action);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// bindings can only be accessed in game and menu modes
|
|
||||||
assert(mode == InputManager::MENU);
|
|
||||||
return m_configuration->getMenuAction(Input::IT_KEYBOARD, id, 0,
|
|
||||||
action);
|
|
||||||
}
|
|
||||||
} // processAndMapInput
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark Gamepad
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
GamePadDevice::GamePadDevice(const int irrIndex, const std::string name,
|
|
||||||
const int axis_count, const int button_count,
|
|
||||||
GamepadConfig *configuration)
|
|
||||||
{
|
|
||||||
m_type = DT_GAMEPAD;
|
|
||||||
m_deadzone = DEADZONE_JOYSTICK;
|
|
||||||
m_prevAxisDirections = NULL;
|
|
||||||
m_configuration = configuration;
|
|
||||||
m_axis_count = axis_count;
|
|
||||||
m_prevAxisDirections = new Input::AxisDirection[axis_count];
|
|
||||||
m_prevAxisValue = new int[axis_count];
|
|
||||||
m_axis_ok = new bool[axis_count];
|
|
||||||
m_button_count = button_count;
|
|
||||||
m_index = irrIndex;
|
|
||||||
m_name = name;
|
|
||||||
|
|
||||||
for (int i = 0; i < axis_count; i++)
|
|
||||||
{
|
|
||||||
m_prevAxisDirections[i] = Input::AD_NEUTRAL;
|
|
||||||
m_prevAxisValue[i] = -1;
|
|
||||||
m_axis_ok[i] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int n=0; n<SEvent::SJoystickEvent::NUMBER_OF_BUTTONS; n++)
|
|
||||||
m_buttonPressed[n] = false;
|
|
||||||
} // GamePadDevice
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
/** Destructor for GamePadDevice.
|
|
||||||
*/
|
|
||||||
GamePadDevice::~GamePadDevice()
|
|
||||||
{
|
|
||||||
delete[] m_prevAxisDirections;
|
|
||||||
delete[] m_prevAxisValue;
|
|
||||||
delete[] m_axis_ok;
|
|
||||||
|
|
||||||
// FIXME - any need to close devices?
|
|
||||||
} // ~GamePadDevice
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool GamePadDevice::isButtonPressed(const int i)
|
|
||||||
{
|
|
||||||
return m_buttonPressed[i];
|
|
||||||
} // isButtonPressed
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void GamePadDevice::setButtonPressed(const int i, bool isButtonPressed)
|
|
||||||
{
|
|
||||||
m_buttonPressed[i] = isButtonPressed;
|
|
||||||
} // setButtonPressed
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void GamePadDevice::resetAxisDirection(const int axis,
|
|
||||||
Input::AxisDirection direction,
|
|
||||||
StateManager::ActivePlayer* player)
|
|
||||||
{
|
|
||||||
// ignore this while in menus
|
|
||||||
if (StateManager::get()->getGameState() != GUIEngine::GAME) return;
|
|
||||||
|
|
||||||
AbstractKart* pk = player->getKart();
|
|
||||||
if (pk == NULL)
|
|
||||||
{
|
|
||||||
Log::error("Binding", "Trying to reset axis for an unknown player.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int n=0; n<PA_COUNT; n++)
|
|
||||||
{
|
|
||||||
Binding& bind = m_configuration->getBinding(n);
|
|
||||||
if(bind.getType() == Input::IT_STICKMOTION &&
|
|
||||||
bind.getId() == axis &&
|
|
||||||
bind.getDirection()== direction &&
|
|
||||||
pk->getController() != NULL)
|
|
||||||
{
|
|
||||||
((PlayerController*)(pk->getController()))
|
|
||||||
->action((PlayerAction)n, 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // resetAxisDirection
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool GamePadDevice::processAndMapInput(Input::InputType type, const int id,
|
|
||||||
int* value, /* inout */
|
|
||||||
InputManager::InputDriverMode mode,
|
|
||||||
StateManager::ActivePlayer* player,
|
|
||||||
PlayerAction* action /* out */)
|
|
||||||
{
|
|
||||||
if (!m_configuration->isEnabled()) return false;
|
|
||||||
|
|
||||||
bool success = false;
|
|
||||||
if(m_prevAxisDirections == NULL) return false; // device not open
|
|
||||||
|
|
||||||
if (type == Input::IT_STICKMOTION)
|
|
||||||
{
|
|
||||||
// this gamepad doesn't even have that many axes
|
|
||||||
if (id >= m_axis_count) return false;
|
|
||||||
|
|
||||||
if (player != NULL)
|
|
||||||
{
|
|
||||||
// going to negative from positive
|
|
||||||
if (*value < 0 && m_prevAxisDirections[id] == Input::AD_POSITIVE)
|
|
||||||
{
|
|
||||||
// set positive id to 0
|
|
||||||
resetAxisDirection(id, Input::AD_POSITIVE, player);
|
|
||||||
}
|
|
||||||
// going to positive from negative
|
|
||||||
else if (*value > 0 &&
|
|
||||||
m_prevAxisDirections[id] == Input::AD_NEGATIVE)
|
|
||||||
{
|
|
||||||
// set negative id to 0
|
|
||||||
resetAxisDirection(id, Input::AD_NEGATIVE, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*value > 0) m_prevAxisDirections[id] = Input::AD_POSITIVE;
|
|
||||||
else if(*value < 0) m_prevAxisDirections[id] = Input::AD_NEGATIVE;
|
|
||||||
|
|
||||||
if (!m_axis_ok[id])
|
|
||||||
{
|
|
||||||
if (m_prevAxisValue[id] == -1)
|
|
||||||
{
|
|
||||||
// first value we get from this axis
|
|
||||||
m_prevAxisValue[id] = *value;
|
|
||||||
}
|
|
||||||
else if (m_prevAxisValue[id] != *value)
|
|
||||||
{
|
|
||||||
// second different value we get from this axis, consider it OK
|
|
||||||
m_axis_ok[id] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if within deadzone
|
|
||||||
if(*value > -m_deadzone && *value < m_deadzone && player != NULL)
|
|
||||||
{
|
|
||||||
// Axis stands still: This is reported once for digital axes and
|
|
||||||
// can be called multipled times for analog ones. Uses the
|
|
||||||
// previous direction in which the id was triggered to
|
|
||||||
// determine which one has to be brought into the released
|
|
||||||
// state. This allows us to regard two directions of an id
|
|
||||||
// as completely independent input variants (as if they where
|
|
||||||
// two buttons).
|
|
||||||
|
|
||||||
if(m_prevAxisDirections[id] == Input::AD_NEGATIVE)
|
|
||||||
{
|
|
||||||
// set negative id to 0
|
|
||||||
resetAxisDirection(id, Input::AD_NEGATIVE, player);
|
|
||||||
}
|
|
||||||
else if(m_prevAxisDirections[id] == Input::AD_POSITIVE)
|
|
||||||
{
|
|
||||||
// set positive id to 0
|
|
||||||
resetAxisDirection(id, Input::AD_POSITIVE, player);
|
|
||||||
}
|
|
||||||
m_prevAxisDirections[id] = Input::AD_NEUTRAL;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If axis did not send proper values yet, ignore it.
|
|
||||||
if (!m_axis_ok[id]) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (mode == InputManager::INGAME)
|
|
||||||
{
|
|
||||||
success = m_configuration->getGameAction(type, id, value, action);
|
|
||||||
}
|
|
||||||
else if (abs(*value) > Input::MAX_VALUE/2)
|
|
||||||
{
|
|
||||||
// bindings can only be accessed in game and menu modes
|
|
||||||
assert(mode == InputManager::MENU);
|
|
||||||
success = m_configuration->getMenuAction(type, id, value, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
} // processAndMapInput
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
@ -54,6 +54,8 @@ public:
|
|||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
|
||||||
InputDevice();
|
InputDevice();
|
||||||
|
~InputDevice();
|
||||||
|
|
||||||
void setConfiguration(DeviceConfig *config) {m_configuration = config;}
|
void setConfiguration(DeviceConfig *config) {m_configuration = config;}
|
||||||
DeviceConfig *getConfiguration() {return m_configuration;}
|
DeviceConfig *getConfiguration() {return m_configuration;}
|
||||||
|
|
||||||
@ -63,99 +65,4 @@ public:
|
|||||||
StateManager::ActivePlayer *getPlayer() { return m_player; }
|
StateManager::ActivePlayer *getPlayer() { return m_player; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief specialisation of InputDevice for keyboard type devices
|
|
||||||
* \ingroup input
|
|
||||||
*/
|
|
||||||
class KeyboardDevice : public InputDevice
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
KeyboardDevice();
|
|
||||||
KeyboardDevice(KeyboardConfig *configuration);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 processAndMapInput(const int id, InputManager::InputDriverMode mode,
|
|
||||||
PlayerAction* action);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief specialisation of Inputdevice for gamepad type devices
|
|
||||||
* \ingroup input
|
|
||||||
*/
|
|
||||||
class GamePadDevice : public InputDevice
|
|
||||||
{
|
|
||||||
void resetAxisDirection(const int axis, Input::AxisDirection direction,
|
|
||||||
StateManager::ActivePlayer* player);
|
|
||||||
bool m_buttonPressed[SEvent::SJoystickEvent::NUMBER_OF_BUTTONS];
|
|
||||||
|
|
||||||
public:
|
|
||||||
Input::AxisDirection *m_prevAxisDirections;
|
|
||||||
|
|
||||||
/** used to determine if an axis is valid; an axis is considered valid
|
|
||||||
* when at least 2 different values are read from this axis (if an axis
|
|
||||||
* keeps on sending the exact same value continuously, chances are that
|
|
||||||
* it's not meant by the user - for instance some gamepads have hats or
|
|
||||||
* analog switches that get reported as axis, we even had a report that
|
|
||||||
* on linux some hard disks may be reported as gamepads with
|
|
||||||
* uninteresting axis values)
|
|
||||||
*/
|
|
||||||
int *m_prevAxisValue;
|
|
||||||
/** \see m_prevAxisValue */
|
|
||||||
bool *m_axis_ok;
|
|
||||||
|
|
||||||
int m_deadzone;
|
|
||||||
int m_index;
|
|
||||||
int m_axis_count;
|
|
||||||
int m_button_count;
|
|
||||||
|
|
||||||
/** 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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invoked when this device it used. Verifies if the key/button that
|
|
||||||
* was pressed is associated with a binding. 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)
|
|
||||||
*
|
|
||||||
* \return Whether the pressed key/button is bound with an action
|
|
||||||
*/
|
|
||||||
bool processAndMapInput(Input::InputType type, const int id,
|
|
||||||
int* value,
|
|
||||||
InputManager::InputDriverMode mode,
|
|
||||||
StateManager::ActivePlayer* player,
|
|
||||||
PlayerAction* action);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
#include "guiengine/modaldialog.hpp"
|
#include "guiengine/modaldialog.hpp"
|
||||||
#include "guiengine/screen.hpp"
|
#include "guiengine/screen.hpp"
|
||||||
#include "input/device_manager.hpp"
|
#include "input/device_manager.hpp"
|
||||||
|
#include "input/gamepad_device.hpp"
|
||||||
|
#include "input/keyboard_device.hpp"
|
||||||
#include "input/input.hpp"
|
#include "input/input.hpp"
|
||||||
#include "karts/controller/controller.hpp"
|
#include "karts/controller/controller.hpp"
|
||||||
#include "karts/abstract_kart.hpp"
|
#include "karts/abstract_kart.hpp"
|
||||||
@ -635,7 +637,7 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID,
|
|||||||
type == Input::IT_STICKBUTTON)
|
type == Input::IT_STICKBUTTON)
|
||||||
{
|
{
|
||||||
GamePadDevice* gp =
|
GamePadDevice* gp =
|
||||||
getDeviceList()->getGamePadFromIrrID(deviceID);
|
getDeviceManager()->getGamePadFromIrrID(deviceID);
|
||||||
|
|
||||||
if (gp != NULL &&
|
if (gp != NULL &&
|
||||||
abs(value)>gp->m_deadzone)
|
abs(value)>gp->m_deadzone)
|
||||||
@ -768,7 +770,7 @@ EventPropagation InputManager::input(const SEvent& event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GamePadDevice* gp =
|
GamePadDevice* gp =
|
||||||
getDeviceList()->getGamePadFromIrrID(event.JoystickEvent.Joystick);
|
getDeviceManager()->getGamePadFromIrrID(event.JoystickEvent.Joystick);
|
||||||
|
|
||||||
if (gp == NULL)
|
if (gp == NULL)
|
||||||
{
|
{
|
||||||
@ -805,7 +807,7 @@ EventPropagation InputManager::input(const SEvent& event)
|
|||||||
// Key value, but do have a value defined in the Char field.
|
// Key value, but do have a value defined in the Char field.
|
||||||
// So to distinguish them (otherwise [] would both be mapped to
|
// So to distinguish them (otherwise [] would both be mapped to
|
||||||
// the same value 0, which means we can't distinguish which key
|
// the same value 0, which means we can't distinguish which key
|
||||||
// was actually pressed anymore). We set bit 10 which should
|
// was actually pressed anymore), we set bit 10 which should
|
||||||
// allow us to distinguish those artifical keys from the
|
// allow us to distinguish those artifical keys from the
|
||||||
// 'real' keys.
|
// 'real' keys.
|
||||||
const int key = event.KeyInput.Key ? event.KeyInput.Key
|
const int key = event.KeyInput.Key ? event.KeyInput.Key
|
||||||
@ -902,7 +904,7 @@ EventPropagation InputManager::input(const SEvent& event)
|
|||||||
// allow typing, and except in modal dialogs in-game)
|
// allow typing, and except in modal dialogs in-game)
|
||||||
// FIXME: 1) that's awful logic 2) that's not what the code below does,
|
// FIXME: 1) that's awful logic 2) that's not what the code below does,
|
||||||
// events are never blocked in menus
|
// events are never blocked in menus
|
||||||
if (getDeviceList()->getAssignMode() != NO_ASSIGN &&
|
if (getDeviceManager()->getAssignMode() != NO_ASSIGN &&
|
||||||
!GUIEngine::isWithinATextBox() &&
|
!GUIEngine::isWithinATextBox() &&
|
||||||
(!GUIEngine::ModalDialog::isADialogActive() &&
|
(!GUIEngine::ModalDialog::isADialogActive() &&
|
||||||
StateManager::get()->getGameState() == GUIEngine::GAME))
|
StateManager::get()->getGameState() == GUIEngine::GAME))
|
||||||
|
@ -43,9 +43,6 @@ public:
|
|||||||
INGAME,
|
INGAME,
|
||||||
INPUT_SENSE_KEYBOARD,
|
INPUT_SENSE_KEYBOARD,
|
||||||
INPUT_SENSE_GAMEPAD,
|
INPUT_SENSE_GAMEPAD,
|
||||||
//INPUT_SENSE_PREFER_AXIS,
|
|
||||||
//INPUT_SENSE_PREFER_BUTTON,
|
|
||||||
//LOWLEVEL,
|
|
||||||
BOOTSTRAP
|
BOOTSTRAP
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -71,9 +68,11 @@ private:
|
|||||||
*/
|
*/
|
||||||
int m_mouse_val_x, m_mouse_val_y;
|
int m_mouse_val_x, m_mouse_val_y;
|
||||||
|
|
||||||
void dispatchInput(Input::InputType, int deviceID, int btnID, Input::AxisDirection direction, int value);
|
void dispatchInput(Input::InputType, int deviceID, int btnID,
|
||||||
|
Input::AxisDirection direction, int value);
|
||||||
void handleStaticAction(int id0, int value);
|
void handleStaticAction(int id0, int value);
|
||||||
void inputSensing(Input::InputType type, int deviceID, int btnID, Input::AxisDirection axisDirection, int value);
|
void inputSensing(Input::InputType type, int deviceID, int btnID,
|
||||||
|
Input::AxisDirection axisDirection, int value);
|
||||||
public:
|
public:
|
||||||
InputManager();
|
InputManager();
|
||||||
~InputManager();
|
~InputManager();
|
||||||
@ -82,21 +81,24 @@ public:
|
|||||||
//void input();
|
//void input();
|
||||||
GUIEngine::EventPropagation input(const irr::SEvent& event);
|
GUIEngine::EventPropagation input(const irr::SEvent& event);
|
||||||
|
|
||||||
DeviceManager* getDeviceList() { return m_device_manager; }
|
DeviceManager* getDeviceManager() { return m_device_manager; }
|
||||||
|
|
||||||
void setMode(InputDriverMode);
|
void setMode(InputDriverMode);
|
||||||
bool isInMode(InputDriverMode);
|
bool isInMode(InputDriverMode);
|
||||||
InputDriverMode getMode() { return m_mode; }
|
InputDriverMode getMode() { return m_mode; }
|
||||||
|
|
||||||
/** When this mode is enabled, only the master player will be able to play with menus (only works in 'assign' mode) */
|
/** When this mode is enabled, only the master player will be able to play
|
||||||
|
* with menus (only works in 'assign' mode) */
|
||||||
void setMasterPlayerOnly(bool enabled);
|
void setMasterPlayerOnly(bool enabled);
|
||||||
|
|
||||||
/** Returns whether only the master player should be allowed to perform changes in menus */
|
/** Returns whether only the master player should be allowed to perform
|
||||||
|
* changes in menus. */
|
||||||
bool masterPlayerOnly() const;
|
bool masterPlayerOnly() const;
|
||||||
|
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
||||||
/** Returns the ID of the player that plays with the keyboard, or -1 if none */
|
/** Returns the ID of the player that plays with the keyboard,
|
||||||
|
* or -1 if none. */
|
||||||
int getPlayerKeyboardID() const;
|
int getPlayerKeyboardID() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
59
src/input/keyboard_device.cpp
Normal file
59
src/input/keyboard_device.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2013 Marianne Gagnon
|
||||||
|
// 2014 Joerg Henrichs
|
||||||
|
//
|
||||||
|
// 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/keyboard_device.hpp"
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
KeyboardDevice::KeyboardDevice(KeyboardConfig *configuration)
|
||||||
|
{
|
||||||
|
m_configuration = configuration;
|
||||||
|
m_type = DT_KEYBOARD;
|
||||||
|
m_name = "Keyboard";
|
||||||
|
m_player = NULL;
|
||||||
|
} // KeyboardDevice
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
KeyboardDevice::KeyboardDevice()
|
||||||
|
{
|
||||||
|
m_configuration = new KeyboardConfig();
|
||||||
|
m_type = DT_KEYBOARD;
|
||||||
|
m_player = NULL;
|
||||||
|
} // KeyboardDevice
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool KeyboardDevice::processAndMapInput(const int id,
|
||||||
|
InputManager::InputDriverMode mode,
|
||||||
|
PlayerAction* action /* out */)
|
||||||
|
{
|
||||||
|
if (mode == InputManager::INGAME)
|
||||||
|
{
|
||||||
|
return m_configuration->getGameAction(Input::IT_KEYBOARD, id, 0,
|
||||||
|
action);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// bindings can only be accessed in game and menu modes
|
||||||
|
assert(mode == InputManager::MENU);
|
||||||
|
return m_configuration->getMenuAction(Input::IT_KEYBOARD, id, 0,
|
||||||
|
action);
|
||||||
|
}
|
||||||
|
} // processAndMapInput
|
||||||
|
|
||||||
|
// ============================================================================
|
52
src/input/keyboard_device.hpp
Normal file
52
src/input/keyboard_device.hpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2014 Marianne Gagnon
|
||||||
|
// 2014 Joerg Henrichs
|
||||||
|
//
|
||||||
|
// 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_KEYBOARD_DEVICE_HPP
|
||||||
|
#define HEADER_KEYBOARD_DEVICE_HPP
|
||||||
|
|
||||||
|
#include "input/input_device.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief specialisation of InputDevice for keyboard type devices
|
||||||
|
* \ingroup input
|
||||||
|
*/
|
||||||
|
class KeyboardDevice : public InputDevice
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KeyboardDevice();
|
||||||
|
KeyboardDevice(KeyboardConfig *configuration);
|
||||||
|
|
||||||
|
virtual ~KeyboardDevice() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 processAndMapInput(const int id, InputManager::InputDriverMode mode,
|
||||||
|
PlayerAction* action);
|
||||||
|
|
||||||
|
}; // KeyboardDevice
|
||||||
|
|
||||||
|
#endif
|
@ -21,6 +21,7 @@
|
|||||||
#include "input/wiimote.hpp"
|
#include "input/wiimote.hpp"
|
||||||
|
|
||||||
#include "config/user_config.hpp"
|
#include "config/user_config.hpp"
|
||||||
|
#include "input/gamepad_device.hpp"
|
||||||
#include "input/device_manager.hpp"
|
#include "input/device_manager.hpp"
|
||||||
#include "utils/string_utils.hpp"
|
#include "utils/string_utils.hpp"
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ Wiimote::Wiimote(wiimote_t* wiimote_handle, int wiimote_id,
|
|||||||
/*num axes*/ 1,
|
/*num axes*/ 1,
|
||||||
button_count,
|
button_count,
|
||||||
gamepad_config );
|
gamepad_config );
|
||||||
DeviceManager* device_manager = input_manager->getDeviceList();
|
DeviceManager* device_manager = input_manager->getDeviceManager();
|
||||||
device_manager->addGamepad(m_gamepad_device);
|
device_manager->addGamepad(m_gamepad_device);
|
||||||
|
|
||||||
} // Wiimote
|
} // Wiimote
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "graphics/irr_driver.hpp"
|
#include "graphics/irr_driver.hpp"
|
||||||
#include "guiengine/modaldialog.hpp"
|
#include "guiengine/modaldialog.hpp"
|
||||||
|
#include "gamepad_device.hpp"
|
||||||
#include "input/input_manager.hpp"
|
#include "input/input_manager.hpp"
|
||||||
#include "input/device_manager.hpp"
|
#include "input/device_manager.hpp"
|
||||||
#include "input/wiimote.hpp"
|
#include "input/wiimote.hpp"
|
||||||
@ -158,7 +159,7 @@ void WiimoteManager::launchDetection(int timeout)
|
|||||||
|
|
||||||
// ---------------------------------------------------
|
// ---------------------------------------------------
|
||||||
// Create or find a GamepadConfig for all wiimotes
|
// Create or find a GamepadConfig for all wiimotes
|
||||||
DeviceManager* device_manager = input_manager->getDeviceList();
|
DeviceManager* device_manager = input_manager->getDeviceManager();
|
||||||
GamepadConfig* gamepad_config = NULL;
|
GamepadConfig* gamepad_config = NULL;
|
||||||
|
|
||||||
device_manager->getConfigForGamepad(WIIMOTE_START_IRR_ID, "Wiimote",
|
device_manager->getConfigForGamepad(WIIMOTE_START_IRR_ID, "Wiimote",
|
||||||
@ -245,7 +246,7 @@ void WiimoteManager::cleanup()
|
|||||||
{
|
{
|
||||||
if(m_wiimotes.size() > 0)
|
if(m_wiimotes.size() > 0)
|
||||||
{
|
{
|
||||||
DeviceManager* device_manager = input_manager->getDeviceList();
|
DeviceManager* device_manager = input_manager->getDeviceManager();
|
||||||
|
|
||||||
GamePadDevice* first_gamepad_device =
|
GamePadDevice* first_gamepad_device =
|
||||||
device_manager->getGamePadFromIrrID(WIIMOTE_START_IRR_ID);
|
device_manager->getGamePadFromIrrID(WIIMOTE_START_IRR_ID);
|
||||||
|
@ -162,6 +162,7 @@
|
|||||||
#include "guiengine/dialog_queue.hpp"
|
#include "guiengine/dialog_queue.hpp"
|
||||||
#include "input/device_manager.hpp"
|
#include "input/device_manager.hpp"
|
||||||
#include "input/input_manager.hpp"
|
#include "input/input_manager.hpp"
|
||||||
|
#include "input/keyboard_device.hpp"
|
||||||
#include "input/wiimote_manager.hpp"
|
#include "input/wiimote_manager.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "items/attachment_manager.hpp"
|
#include "items/attachment_manager.hpp"
|
||||||
@ -400,7 +401,7 @@ void setupRaceStart()
|
|||||||
InputDevice *device;
|
InputDevice *device;
|
||||||
|
|
||||||
// Use keyboard 0 by default in --no-start-screen
|
// Use keyboard 0 by default in --no-start-screen
|
||||||
device = input_manager->getDeviceList()->getKeyboard(0);
|
device = input_manager->getDeviceManager()->getKeyboard(0);
|
||||||
|
|
||||||
// Create player and associate player with keyboard
|
// Create player and associate player with keyboard
|
||||||
StateManager::get()->createActivePlayer(
|
StateManager::get()->createActivePlayer(
|
||||||
@ -421,7 +422,7 @@ void setupRaceStart()
|
|||||||
|
|
||||||
// ASSIGN should make sure that only input from assigned devices
|
// ASSIGN should make sure that only input from assigned devices
|
||||||
// is read.
|
// is read.
|
||||||
input_manager->getDeviceList()->setAssignMode(ASSIGN);
|
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
|
||||||
} // setupRaceStart
|
} // setupRaceStart
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "config/user_config.hpp"
|
#include "config/user_config.hpp"
|
||||||
#include "guiengine/modaldialog.hpp"
|
#include "guiengine/modaldialog.hpp"
|
||||||
#include "input/device_manager.hpp"
|
#include "input/device_manager.hpp"
|
||||||
|
#include "input/keyboard_device.hpp"
|
||||||
#include "input/input_manager.hpp"
|
#include "input/input_manager.hpp"
|
||||||
#include "race/race_manager.hpp"
|
#include "race/race_manager.hpp"
|
||||||
#include "tracks/track.hpp"
|
#include "tracks/track.hpp"
|
||||||
@ -140,12 +141,12 @@ bool DemoWorld::updateIdleTimeAndStartDemo(float dt)
|
|||||||
InputDevice *device;
|
InputDevice *device;
|
||||||
|
|
||||||
// Use keyboard 0 by default in --no-start-screen
|
// Use keyboard 0 by default in --no-start-screen
|
||||||
device = input_manager->getDeviceList()->getKeyboard(0);
|
device = input_manager->getDeviceManager()->getKeyboard(0);
|
||||||
StateManager::get()->createActivePlayer(
|
StateManager::get()->createActivePlayer(
|
||||||
PlayerManager::get()->getPlayer(0), device);
|
PlayerManager::get()->getPlayer(0), device);
|
||||||
// ASSIGN should make sure that only input from assigned devices
|
// ASSIGN should make sure that only input from assigned devices
|
||||||
// is read.
|
// is read.
|
||||||
input_manager->getDeviceList()->setAssignMode(ASSIGN);
|
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
|
||||||
|
|
||||||
m_do_demo = true;
|
m_do_demo = true;
|
||||||
race_manager->setNumKarts(m_num_karts);
|
race_manager->setNumKarts(m_num_karts);
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "input/device_manager.hpp"
|
#include "input/device_manager.hpp"
|
||||||
#include "input/input.hpp"
|
#include "input/input.hpp"
|
||||||
#include "input/input_manager.hpp"
|
#include "input/input_manager.hpp"
|
||||||
|
#include "input/keyboard_device.hpp"
|
||||||
#include "karts/abstract_kart.hpp"
|
#include "karts/abstract_kart.hpp"
|
||||||
#include "karts/kart_properties.hpp"
|
#include "karts/kart_properties.hpp"
|
||||||
#include "karts/kart_properties_manager.hpp"
|
#include "karts/kart_properties_manager.hpp"
|
||||||
@ -63,7 +64,7 @@ void OverWorld::enterOverWorld()
|
|||||||
race_manager->setDifficulty(RaceManager::DIFFICULTY_HARD);
|
race_manager->setDifficulty(RaceManager::DIFFICULTY_HARD);
|
||||||
|
|
||||||
// Use keyboard 0 by default (FIXME: let player choose?)
|
// Use keyboard 0 by default (FIXME: let player choose?)
|
||||||
InputDevice* device = input_manager->getDeviceList()->getKeyboard(0);
|
InputDevice* device = input_manager->getDeviceManager()->getKeyboard(0);
|
||||||
|
|
||||||
// Create player and associate player with keyboard
|
// Create player and associate player with keyboard
|
||||||
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(),
|
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(),
|
||||||
@ -81,8 +82,8 @@ void OverWorld::enterOverWorld()
|
|||||||
|
|
||||||
// ASSIGN should make sure that only input from assigned devices
|
// ASSIGN should make sure that only input from assigned devices
|
||||||
// is read.
|
// is read.
|
||||||
input_manager->getDeviceList()->setAssignMode(ASSIGN);
|
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
|
||||||
input_manager->getDeviceList()
|
input_manager->getDeviceManager()
|
||||||
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
||||||
|
|
||||||
StateManager::get()->enterGameState();
|
StateManager::get()->enterGameState();
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "graphics/hardware_skinning.hpp"
|
#include "graphics/hardware_skinning.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "input/device_manager.hpp"
|
#include "input/device_manager.hpp"
|
||||||
|
#include "input/keyboard_device.hpp"
|
||||||
#include "items/projectile_manager.hpp"
|
#include "items/projectile_manager.hpp"
|
||||||
#include "karts/controller/player_controller.hpp"
|
#include "karts/controller/player_controller.hpp"
|
||||||
#include "karts/controller/end_controller.hpp"
|
#include "karts/controller/end_controller.hpp"
|
||||||
@ -842,7 +843,7 @@ void World::updateWorld(float dt)
|
|||||||
race_manager->setReverseTrack(false);
|
race_manager->setReverseTrack(false);
|
||||||
|
|
||||||
// Use keyboard 0 by default (FIXME: let player choose?)
|
// Use keyboard 0 by default (FIXME: let player choose?)
|
||||||
InputDevice* device = input_manager->getDeviceList()->getKeyboard(0);
|
InputDevice* device = input_manager->getDeviceManager()->getKeyboard(0);
|
||||||
|
|
||||||
// Create player and associate player with keyboard
|
// Create player and associate player with keyboard
|
||||||
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(),
|
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(),
|
||||||
@ -859,8 +860,8 @@ void World::updateWorld(float dt)
|
|||||||
|
|
||||||
// ASSIGN should make sure that only input from assigned devices
|
// ASSIGN should make sure that only input from assigned devices
|
||||||
// is read.
|
// is read.
|
||||||
input_manager->getDeviceList()->setAssignMode(ASSIGN);
|
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
|
||||||
input_manager->getDeviceList()
|
input_manager->getDeviceManager()
|
||||||
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
||||||
|
|
||||||
StateManager::get()->enterGameState();
|
StateManager::get()->enterGameState();
|
||||||
|
@ -116,14 +116,14 @@ void StartGameProtocol::update()
|
|||||||
rki.setHostId(profile->race_id);
|
rki.setHostId(profile->race_id);
|
||||||
PlayerProfile* profile_to_use = PlayerManager::getCurrentPlayer();
|
PlayerProfile* profile_to_use = PlayerManager::getCurrentPlayer();
|
||||||
assert(profile_to_use);
|
assert(profile_to_use);
|
||||||
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
|
InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice();
|
||||||
int new_player_id = 0;
|
int new_player_id = 0;
|
||||||
if (StateManager::get()->getActivePlayers().size() >= 1) // more than one player, we're the first
|
if (StateManager::get()->getActivePlayers().size() >= 1) // more than one player, we're the first
|
||||||
new_player_id = 0;
|
new_player_id = 0;
|
||||||
else
|
else
|
||||||
new_player_id = StateManager::get()->createActivePlayer( profile_to_use, device);
|
new_player_id = StateManager::get()->createActivePlayer( profile_to_use, device);
|
||||||
device->setPlayer(StateManager::get()->getActivePlayer(new_player_id));
|
device->setPlayer(StateManager::get()->getActivePlayer(new_player_id));
|
||||||
input_manager->getDeviceList()->setSinglePlayer(StateManager::get()->getActivePlayer(new_player_id));
|
input_manager->getDeviceManager()->setSinglePlayer(StateManager::get()->getActivePlayer(new_player_id));
|
||||||
|
|
||||||
race_manager->setPlayerKart(i, rki);
|
race_manager->setPlayerKart(i, rki);
|
||||||
race_manager->setLocalKartInfo(new_player_id, profile->kart_name);
|
race_manager->setLocalKartInfo(new_player_id, profile->kart_name);
|
||||||
|
@ -165,8 +165,8 @@ GUIEngine::EventPropagation AddDeviceDialog::processEvent
|
|||||||
}
|
}
|
||||||
else if (eventSource == "addkeyboard")
|
else if (eventSource == "addkeyboard")
|
||||||
{
|
{
|
||||||
input_manager->getDeviceList()->addEmptyKeyboard();
|
input_manager->getDeviceManager()->addEmptyKeyboard();
|
||||||
input_manager->getDeviceList()->serialize();
|
input_manager->getDeviceManager()->serialize();
|
||||||
ModalDialog::dismiss();
|
ModalDialog::dismiss();
|
||||||
|
|
||||||
((OptionsScreenInput*)GUIEngine::getCurrentScreen())->rebuildDeviceList();
|
((OptionsScreenInput*)GUIEngine::getCurrentScreen())->rebuildDeviceList();
|
||||||
|
@ -187,7 +187,7 @@ GUIEngine::EventPropagation SelectChallengeDialog::processEvent(const std::strin
|
|||||||
//StateManager::get()->resetActivePlayers();
|
//StateManager::get()->resetActivePlayers();
|
||||||
|
|
||||||
// Use latest used device
|
// Use latest used device
|
||||||
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
|
InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice();
|
||||||
assert(device != NULL);
|
assert(device != NULL);
|
||||||
|
|
||||||
// Set up race manager appropriately
|
// Set up race manager appropriately
|
||||||
@ -196,10 +196,10 @@ GUIEngine::EventPropagation SelectChallengeDialog::processEvent(const std::strin
|
|||||||
race_manager->setReverseTrack(false);
|
race_manager->setReverseTrack(false);
|
||||||
|
|
||||||
//int id = StateManager::get()->createActivePlayer( unlock_manager->getCurrentPlayer(), device );
|
//int id = StateManager::get()->createActivePlayer( unlock_manager->getCurrentPlayer(), device );
|
||||||
input_manager->getDeviceList()->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
input_manager->getDeviceManager()->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
||||||
|
|
||||||
// ASSIGN should make sure that only input from assigned devices is read.
|
// ASSIGN should make sure that only input from assigned devices is read.
|
||||||
input_manager->getDeviceList()->setAssignMode(ASSIGN);
|
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
|
||||||
|
|
||||||
// Go straight to the race
|
// Go straight to the race
|
||||||
StateManager::get()->enterGameState();
|
StateManager::get()->enterGameState();
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||||
#include "input/device_manager.hpp"
|
#include "input/device_manager.hpp"
|
||||||
#include "input/input_manager.hpp"
|
#include "input/input_manager.hpp"
|
||||||
|
#include "input/keyboard_device.hpp"
|
||||||
#include "karts/kart_properties_manager.hpp"
|
#include "karts/kart_properties_manager.hpp"
|
||||||
#include "race/race_manager.hpp"
|
#include "race/race_manager.hpp"
|
||||||
#include "states_screens/help_screen_2.hpp"
|
#include "states_screens/help_screen_2.hpp"
|
||||||
@ -63,7 +64,7 @@ void HelpScreen1::eventCallback(Widget* widget, const std::string& name, const i
|
|||||||
race_manager->setReverseTrack(false);
|
race_manager->setReverseTrack(false);
|
||||||
|
|
||||||
// Use keyboard 0 by default (FIXME: let player choose?)
|
// Use keyboard 0 by default (FIXME: let player choose?)
|
||||||
InputDevice* device = input_manager->getDeviceList()->getKeyboard(0);
|
InputDevice* device = input_manager->getDeviceManager()->getKeyboard(0);
|
||||||
|
|
||||||
// Create player and associate player with keyboard
|
// Create player and associate player with keyboard
|
||||||
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(),
|
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(),
|
||||||
@ -79,8 +80,8 @@ void HelpScreen1::eventCallback(Widget* widget, const std::string& name, const i
|
|||||||
|
|
||||||
// ASSIGN should make sure that only input from assigned devices
|
// ASSIGN should make sure that only input from assigned devices
|
||||||
// is read.
|
// is read.
|
||||||
input_manager->getDeviceList()->setAssignMode(ASSIGN);
|
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
|
||||||
input_manager->getDeviceList()
|
input_manager->getDeviceManager()
|
||||||
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
||||||
|
|
||||||
StateManager::get()->enterGameState();
|
StateManager::get()->enterGameState();
|
||||||
|
@ -1031,7 +1031,7 @@ void KartSelectionScreen::init()
|
|||||||
|
|
||||||
m_kart_widgets.clearAndDeleteAll();
|
m_kart_widgets.clearAndDeleteAll();
|
||||||
StateManager::get()->resetActivePlayers();
|
StateManager::get()->resetActivePlayers();
|
||||||
input_manager->getDeviceList()->setAssignMode(DETECT_NEW);
|
input_manager->getDeviceManager()->setAssignMode(DETECT_NEW);
|
||||||
|
|
||||||
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
|
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
|
||||||
assert( w != NULL );
|
assert( w != NULL );
|
||||||
@ -1069,7 +1069,7 @@ void KartSelectionScreen::init()
|
|||||||
else */
|
else */
|
||||||
// For now this is what will happen
|
// For now this is what will happen
|
||||||
{
|
{
|
||||||
joinPlayer( input_manager->getDeviceList()->getLatestUsedDevice(),
|
joinPlayer( input_manager->getDeviceManager()->getLatestUsedDevice(),
|
||||||
true );
|
true );
|
||||||
w->updateItemDisplay();
|
w->updateItemDisplay();
|
||||||
}
|
}
|
||||||
@ -1083,7 +1083,7 @@ void KartSelectionScreen::init()
|
|||||||
// This flag will cause that a 'fire' event will be mapped to 'select' (if
|
// This flag will cause that a 'fire' event will be mapped to 'select' (if
|
||||||
// 'fire' is not assigned to a GUI event). This is done to support the old
|
// 'fire' is not assigned to a GUI event). This is done to support the old
|
||||||
// way of player joining by pressing 'fire' instead of 'select'.
|
// way of player joining by pressing 'fire' instead of 'select'.
|
||||||
input_manager->getDeviceList()->mapFireToSelect(true);
|
input_manager->getDeviceManager()->mapFireToSelect(true);
|
||||||
|
|
||||||
} // init
|
} // init
|
||||||
|
|
||||||
@ -1092,7 +1092,7 @@ void KartSelectionScreen::init()
|
|||||||
void KartSelectionScreen::tearDown()
|
void KartSelectionScreen::tearDown()
|
||||||
{
|
{
|
||||||
// Reset the 'map fire to select' option of the device manager
|
// Reset the 'map fire to select' option of the device manager
|
||||||
input_manager->getDeviceList()->mapFireToSelect(false);
|
input_manager->getDeviceManager()->mapFireToSelect(false);
|
||||||
|
|
||||||
// if a removed widget is currently shrinking down, remove it upon leaving
|
// if a removed widget is currently shrinking down, remove it upon leaving
|
||||||
// the screen
|
// the screen
|
||||||
@ -1263,7 +1263,7 @@ bool KartSelectionScreen::joinPlayer(InputDevice* device, bool first_player)
|
|||||||
|
|
||||||
if (!m_multiplayer)
|
if (!m_multiplayer)
|
||||||
{
|
{
|
||||||
input_manager->getDeviceList()->setSinglePlayer( StateManager::get()
|
input_manager->getDeviceManager()->setSinglePlayer( StateManager::get()
|
||||||
->getActivePlayer(0));
|
->getActivePlayer(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1866,16 +1866,16 @@ void KartSelectionScreen::allPlayersDone()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---- Switch to assign mode
|
// ---- Switch to assign mode
|
||||||
input_manager->getDeviceList()->setAssignMode(ASSIGN);
|
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
|
||||||
|
|
||||||
if (!m_multiplayer)
|
if (!m_multiplayer)
|
||||||
{
|
{
|
||||||
input_manager->getDeviceList()
|
input_manager->getDeviceManager()
|
||||||
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
input_manager->getDeviceList()->setSinglePlayer( NULL );
|
input_manager->getDeviceManager()->setSinglePlayer( NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Go to next screen or return to overworld
|
// ---- Go to next screen or return to overworld
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||||
#include "input/device_manager.hpp"
|
#include "input/device_manager.hpp"
|
||||||
#include "input/input_manager.hpp"
|
#include "input/input_manager.hpp"
|
||||||
|
#include "input/keyboard_device.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "karts/kart_properties_manager.hpp"
|
#include "karts/kart_properties_manager.hpp"
|
||||||
#include "main_loop.hpp"
|
#include "main_loop.hpp"
|
||||||
@ -102,8 +103,8 @@ void MainMenuScreen::init()
|
|||||||
|
|
||||||
// reset in case we're coming back from a race
|
// reset in case we're coming back from a race
|
||||||
StateManager::get()->resetActivePlayers();
|
StateManager::get()->resetActivePlayers();
|
||||||
input_manager->getDeviceList()->setAssignMode(NO_ASSIGN);
|
input_manager->getDeviceManager()->setAssignMode(NO_ASSIGN);
|
||||||
input_manager->getDeviceList()->setSinglePlayer( NULL );
|
input_manager->getDeviceManager()->setSinglePlayer( NULL );
|
||||||
input_manager->setMasterPlayerOnly(false);
|
input_manager->setMasterPlayerOnly(false);
|
||||||
|
|
||||||
// Avoid incorrect behaviour in certain race circumstances:
|
// Avoid incorrect behaviour in certain race circumstances:
|
||||||
@ -117,7 +118,7 @@ void MainMenuScreen::init()
|
|||||||
// select will add a new player). See bug 3090931
|
// select will add a new player). See bug 3090931
|
||||||
// To avoid this, we will clean the last used device, making
|
// To avoid this, we will clean the last used device, making
|
||||||
// the key bindings for the first player the default again.
|
// the key bindings for the first player the default again.
|
||||||
input_manager->getDeviceList()->clearLatestUsedDevice();
|
input_manager->getDeviceManager()->clearLatestUsedDevice();
|
||||||
|
|
||||||
if (addons_manager->isLoading())
|
if (addons_manager->isLoading())
|
||||||
{
|
{
|
||||||
@ -389,7 +390,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
|
|||||||
race_manager->setReverseTrack(false);
|
race_manager->setReverseTrack(false);
|
||||||
|
|
||||||
// Use keyboard 0 by default (FIXME: let player choose?)
|
// Use keyboard 0 by default (FIXME: let player choose?)
|
||||||
InputDevice* device = input_manager->getDeviceList()->getKeyboard(0);
|
InputDevice* device = input_manager->getDeviceManager()->getKeyboard(0);
|
||||||
|
|
||||||
// Create player and associate player with keyboard
|
// Create player and associate player with keyboard
|
||||||
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(),
|
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(),
|
||||||
@ -405,8 +406,8 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
|
|||||||
|
|
||||||
// ASSIGN should make sure that only input from assigned devices
|
// ASSIGN should make sure that only input from assigned devices
|
||||||
// is read.
|
// is read.
|
||||||
input_manager->getDeviceList()->setAssignMode(ASSIGN);
|
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
|
||||||
input_manager->getDeviceList()
|
input_manager->getDeviceManager()
|
||||||
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
||||||
|
|
||||||
StateManager::get()->enterGameState();
|
StateManager::get()->enterGameState();
|
||||||
|
@ -24,8 +24,9 @@
|
|||||||
#include "guiengine/widgets/button_widget.hpp"
|
#include "guiengine/widgets/button_widget.hpp"
|
||||||
#include "guiengine/widgets/list_widget.hpp"
|
#include "guiengine/widgets/list_widget.hpp"
|
||||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||||
#include "input/input_manager.hpp"
|
|
||||||
#include "input/device_manager.hpp"
|
#include "input/device_manager.hpp"
|
||||||
|
#include "input/gamepad_device.hpp"
|
||||||
|
#include "input/input_manager.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "states_screens/options_screen_input2.hpp"
|
#include "states_screens/options_screen_input2.hpp"
|
||||||
#include "states_screens/options_screen_audio.hpp"
|
#include "states_screens/options_screen_audio.hpp"
|
||||||
@ -81,7 +82,7 @@ void OptionsScreenInput::buildDeviceList()
|
|||||||
assert( m_icon_bank != NULL );
|
assert( m_icon_bank != NULL );
|
||||||
devices->setIcons(m_icon_bank);
|
devices->setIcons(m_icon_bank);
|
||||||
|
|
||||||
const int keyboard_config_count = input_manager->getDeviceList()->getKeyboardConfigAmount();
|
const int keyboard_config_count = input_manager->getDeviceManager()->getKeyboardConfigAmount();
|
||||||
|
|
||||||
for (int i=0; i<keyboard_config_count; i++)
|
for (int i=0; i<keyboard_config_count; i++)
|
||||||
{
|
{
|
||||||
@ -96,11 +97,11 @@ void OptionsScreenInput::buildDeviceList()
|
|||||||
devices->addItem(internal_name, (core::stringw(" ") + _("Keyboard %i", i)).c_str(), 0 /* icon */);
|
devices->addItem(internal_name, (core::stringw(" ") + _("Keyboard %i", i)).c_str(), 0 /* icon */);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int gpad_config_count = input_manager->getDeviceList()->getGamePadConfigAmount();
|
const int gpad_config_count = input_manager->getDeviceManager()->getGamePadConfigAmount();
|
||||||
|
|
||||||
for (int i = 0; i < gpad_config_count; i++)
|
for (int i = 0; i < gpad_config_count; i++)
|
||||||
{
|
{
|
||||||
GamepadConfig *config = input_manager->getDeviceList()->getGamepadConfig(i);
|
GamepadConfig *config = input_manager->getDeviceManager()->getGamepadConfig(i);
|
||||||
|
|
||||||
// Don't display the configuration if a matching device is not available
|
// Don't display the configuration if a matching device is not available
|
||||||
if (config->isPlugged())
|
if (config->isPlugged())
|
||||||
@ -229,7 +230,7 @@ void OptionsScreenInput::eventCallback(Widget* widget, const std::string& name,
|
|||||||
read = sscanf( selection.c_str(), "gamepad%i", &i );
|
read = sscanf( selection.c_str(), "gamepad%i", &i );
|
||||||
if (read == 1 && i != -1)
|
if (read == 1 && i != -1)
|
||||||
{
|
{
|
||||||
OptionsScreenInput2::getInstance()->setDevice( input_manager->getDeviceList()->getGamepadConfig(i) );
|
OptionsScreenInput2::getInstance()->setDevice( input_manager->getDeviceManager()->getGamepadConfig(i) );
|
||||||
StateManager::get()->replaceTopMostScreen(OptionsScreenInput2::getInstance());
|
StateManager::get()->replaceTopMostScreen(OptionsScreenInput2::getInstance());
|
||||||
//updateInputButtons( input_manager->getDeviceList()->getGamepadConfig(i) );
|
//updateInputButtons( input_manager->getDeviceList()->getGamepadConfig(i) );
|
||||||
}
|
}
|
||||||
@ -246,7 +247,7 @@ void OptionsScreenInput::eventCallback(Widget* widget, const std::string& name,
|
|||||||
if (read == 1 && i != -1)
|
if (read == 1 && i != -1)
|
||||||
{
|
{
|
||||||
// updateInputButtons( input_manager->getDeviceList()->getKeyboardConfig(i) );
|
// updateInputButtons( input_manager->getDeviceList()->getKeyboardConfig(i) );
|
||||||
OptionsScreenInput2::getInstance()->setDevice( input_manager->getDeviceList()->getKeyboardConfig(i) );
|
OptionsScreenInput2::getInstance()->setDevice( input_manager->getDeviceManager()->getKeyboardConfig(i) );
|
||||||
StateManager::get()->replaceTopMostScreen(OptionsScreenInput2::getInstance());
|
StateManager::get()->replaceTopMostScreen(OptionsScreenInput2::getInstance());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -282,7 +283,7 @@ void OptionsScreenInput::filterInput(Input::InputType type,
|
|||||||
{
|
{
|
||||||
if (type == Input::IT_STICKMOTION || type == Input::IT_STICKBUTTON)
|
if (type == Input::IT_STICKMOTION || type == Input::IT_STICKBUTTON)
|
||||||
{
|
{
|
||||||
GamePadDevice* gamepad = input_manager->getDeviceList()->getGamePadFromIrrID(deviceID);
|
GamePadDevice* gamepad = input_manager->getDeviceManager()->getGamePadFromIrrID(deviceID);
|
||||||
if (gamepad != NULL && gamepad->getConfiguration() != NULL)
|
if (gamepad != NULL && gamepad->getConfiguration() != NULL)
|
||||||
{
|
{
|
||||||
//printf("'%s'\n", gamepad->getConfiguration()->getName().c_str());
|
//printf("'%s'\n", gamepad->getConfiguration()->getName().c_str());
|
||||||
@ -291,10 +292,10 @@ void OptionsScreenInput::filterInput(Input::InputType type,
|
|||||||
assert(devices != NULL);
|
assert(devices != NULL);
|
||||||
|
|
||||||
std::string internal_name;
|
std::string internal_name;
|
||||||
const int gpad_config_count = input_manager->getDeviceList()->getGamePadConfigAmount();
|
const int gpad_config_count = input_manager->getDeviceManager()->getGamePadConfigAmount();
|
||||||
for (int i = 0; i < gpad_config_count; i++)
|
for (int i = 0; i < gpad_config_count; i++)
|
||||||
{
|
{
|
||||||
GamepadConfig *config = input_manager->getDeviceList()->getGamepadConfig(i);
|
GamepadConfig *config = input_manager->getDeviceManager()->getGamepadConfig(i);
|
||||||
|
|
||||||
// Don't display the configuration if a matching device is not available
|
// Don't display the configuration if a matching device is not available
|
||||||
if (config == gamepad->getConfiguration())
|
if (config == gamepad->getConfiguration())
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||||
#include "input/input_manager.hpp"
|
#include "input/input_manager.hpp"
|
||||||
#include "input/device_manager.hpp"
|
#include "input/device_manager.hpp"
|
||||||
|
#include "input/gamepad_device.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "states_screens/dialogs/press_a_key_dialog.hpp"
|
#include "states_screens/dialogs/press_a_key_dialog.hpp"
|
||||||
#include "states_screens/options_screen_audio.hpp"
|
#include "states_screens/options_screen_audio.hpp"
|
||||||
@ -109,7 +110,7 @@ void OptionsScreenInput2::init()
|
|||||||
{
|
{
|
||||||
deleteBtn->setLabel(_("Delete Configuration"));
|
deleteBtn->setLabel(_("Delete Configuration"));
|
||||||
|
|
||||||
if (input_manager->getDeviceList()->getKeyboardAmount() < 2)
|
if (input_manager->getDeviceManager()->getKeyboardAmount() < 2)
|
||||||
{
|
{
|
||||||
// don't allow deleting the last config
|
// don't allow deleting the last config
|
||||||
deleteBtn->setDeactivated();
|
deleteBtn->setDeactivated();
|
||||||
@ -430,7 +431,9 @@ void OptionsScreenInput2::gotSensedInput(const Input& sensed_input)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string gamepad_name = input_manager->getDeviceList()->getGamePadFromIrrID(sensed_input.m_device_id)->m_name;
|
std::string gamepad_name = input_manager->getDeviceManager()
|
||||||
|
->getGamePadFromIrrID(sensed_input.m_device_id)
|
||||||
|
->m_name;
|
||||||
if (m_config->getName() == gamepad_name)
|
if (m_config->getName() == gamepad_name)
|
||||||
{
|
{
|
||||||
GamepadConfig* config = (GamepadConfig*)m_config;
|
GamepadConfig* config = (GamepadConfig*)m_config;
|
||||||
@ -484,7 +487,7 @@ void OptionsScreenInput2::gotSensedInput(const Input& sensed_input)
|
|||||||
//if(btn != NULL) btn->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
//if(btn != NULL) btn->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||||
|
|
||||||
// save new binding to file
|
// save new binding to file
|
||||||
input_manager->getDeviceList()->serialize();
|
input_manager->getDeviceManager()->serialize();
|
||||||
} // gotSensedInput
|
} // gotSensedInput
|
||||||
|
|
||||||
|
|
||||||
@ -583,7 +586,7 @@ void OptionsScreenInput2::eventCallback(Widget* widget,
|
|||||||
deleteBtn->setLabel(m_config->isEnabled() ? _("Disable Device")
|
deleteBtn->setLabel(m_config->isEnabled() ? _("Disable Device")
|
||||||
: _("Enable Device") );
|
: _("Enable Device") );
|
||||||
|
|
||||||
input_manager->getDeviceList()->serialize();
|
input_manager->getDeviceManager()->serialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -610,13 +613,13 @@ bool OptionsScreenInput2::onEscapePressed()
|
|||||||
void OptionsScreenInput2::onConfirm()
|
void OptionsScreenInput2::onConfirm()
|
||||||
{
|
{
|
||||||
const bool success =
|
const bool success =
|
||||||
input_manager->getDeviceList()->deleteConfig(m_config);
|
input_manager->getDeviceManager()->deleteConfig(m_config);
|
||||||
assert(success);
|
assert(success);
|
||||||
if (!success)
|
if (!success)
|
||||||
Log::error("OptionsScreenInput2", "Failed to delete config!");
|
Log::error("OptionsScreenInput2", "Failed to delete config!");
|
||||||
|
|
||||||
m_config = NULL;
|
m_config = NULL;
|
||||||
input_manager->getDeviceList()->serialize();
|
input_manager->getDeviceManager()->serialize();
|
||||||
ModalDialog::dismiss();
|
ModalDialog::dismiss();
|
||||||
StateManager::get()
|
StateManager::get()
|
||||||
->replaceTopMostScreen(OptionsScreenInput::getInstance());
|
->replaceTopMostScreen(OptionsScreenInput::getInstance());
|
||||||
@ -630,10 +633,10 @@ bool OptionsScreenInput2::conflictsBetweenKbdConfig(PlayerAction action,
|
|||||||
{
|
{
|
||||||
KeyboardConfig* other_kbd_config;
|
KeyboardConfig* other_kbd_config;
|
||||||
int id = m_config->getBinding(action).getId();
|
int id = m_config->getBinding(action).getId();
|
||||||
for (int i=0; i < input_manager->getDeviceList()->getKeyboardAmount(); i++)
|
for (int i=0; i < input_manager->getDeviceManager()->getKeyboardAmount(); i++)
|
||||||
{
|
{
|
||||||
other_kbd_config =
|
other_kbd_config =
|
||||||
input_manager->getDeviceList()->getKeyboardConfig(i);
|
input_manager->getDeviceManager()->getKeyboardConfig(i);
|
||||||
|
|
||||||
if (m_config != other_kbd_config &&
|
if (m_config != other_kbd_config &&
|
||||||
other_kbd_config->hasBindingFor(id, from, to)
|
other_kbd_config->hasBindingFor(id, from, to)
|
||||||
|
@ -227,7 +227,7 @@ void SoccerSetupScreen::init()
|
|||||||
// This flag will cause that a 'fire' event will be mapped to 'select' (if
|
// This flag will cause that a 'fire' event will be mapped to 'select' (if
|
||||||
// 'fire' is not assigned to a GUI event). This is done to support the old
|
// 'fire' is not assigned to a GUI event). This is done to support the old
|
||||||
// way of player joining by pressing 'fire' instead of 'select'.
|
// way of player joining by pressing 'fire' instead of 'select'.
|
||||||
input_manager->getDeviceList()->mapFireToSelect(true);
|
input_manager->getDeviceManager()->mapFireToSelect(true);
|
||||||
} // init
|
} // init
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@ -236,7 +236,7 @@ void SoccerSetupScreen::tearDown()
|
|||||||
Widget* central_div = getWidget<Widget>("central_div");
|
Widget* central_div = getWidget<Widget>("central_div");
|
||||||
|
|
||||||
// Reset the 'map fire to select' option of the device manager
|
// Reset the 'map fire to select' option of the device manager
|
||||||
input_manager->getDeviceList()->mapFireToSelect(false);
|
input_manager->getDeviceManager()->mapFireToSelect(false);
|
||||||
|
|
||||||
UserConfigParams::m_num_goals = getWidget<SpinnerWidget>("goalamount")->getValue();
|
UserConfigParams::m_num_goals = getWidget<SpinnerWidget>("goalamount")->getValue();
|
||||||
UserConfigParams::m_soccer_time_limit = getWidget<SpinnerWidget>("timeamount")->getValue();
|
UserConfigParams::m_soccer_time_limit = getWidget<SpinnerWidget>("timeamount")->getValue();
|
||||||
|
@ -812,7 +812,7 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
|
|||||||
m_action_active = false;
|
m_action_active = false;
|
||||||
//World::getWorld()->getRaceGUI()->clearAllMessages();
|
//World::getWorld()->getRaceGUI()->clearAllMessages();
|
||||||
|
|
||||||
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
|
InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice();
|
||||||
DeviceConfig* config = device->getConfiguration();
|
DeviceConfig* config = device->getConfiguration();
|
||||||
irr::core::stringw accel = config->getBindingAsString(PA_ACCEL);
|
irr::core::stringw accel = config->getBindingAsString(PA_ACCEL);
|
||||||
irr::core::stringw left = config->getBindingAsString(PA_STEER_LEFT);
|
irr::core::stringw left = config->getBindingAsString(PA_STEER_LEFT);
|
||||||
@ -831,7 +831,7 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
|
|||||||
else if (m_action == "tutorial_giftboxes")
|
else if (m_action == "tutorial_giftboxes")
|
||||||
{
|
{
|
||||||
m_action_active = false;
|
m_action_active = false;
|
||||||
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
|
InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice();
|
||||||
DeviceConfig* config = device->getConfiguration();
|
DeviceConfig* config = device->getConfiguration();
|
||||||
irr::core::stringw fire = config->getBindingAsString(PA_FIRE);
|
irr::core::stringw fire = config->getBindingAsString(PA_FIRE);
|
||||||
|
|
||||||
@ -841,7 +841,7 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
|
|||||||
else if (m_action == "tutorial_backgiftboxes")
|
else if (m_action == "tutorial_backgiftboxes")
|
||||||
{
|
{
|
||||||
m_action_active = false;
|
m_action_active = false;
|
||||||
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
|
InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice();
|
||||||
DeviceConfig* config = device->getConfiguration();
|
DeviceConfig* config = device->getConfiguration();
|
||||||
irr::core::stringw fire = config->getBindingAsString(PA_FIRE);
|
irr::core::stringw fire = config->getBindingAsString(PA_FIRE);
|
||||||
|
|
||||||
@ -858,7 +858,7 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
|
|||||||
else if (m_action == "tutorial_nitro_use")
|
else if (m_action == "tutorial_nitro_use")
|
||||||
{
|
{
|
||||||
m_action_active = false;
|
m_action_active = false;
|
||||||
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
|
InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice();
|
||||||
DeviceConfig* config = device->getConfiguration();
|
DeviceConfig* config = device->getConfiguration();
|
||||||
irr::core::stringw nitro = config->getBindingAsString(PA_NITRO);
|
irr::core::stringw nitro = config->getBindingAsString(PA_NITRO);
|
||||||
|
|
||||||
@ -868,7 +868,7 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
|
|||||||
else if (m_action == "tutorial_rescue")
|
else if (m_action == "tutorial_rescue")
|
||||||
{
|
{
|
||||||
m_action_active = false;
|
m_action_active = false;
|
||||||
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
|
InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice();
|
||||||
DeviceConfig* config = device->getConfiguration();
|
DeviceConfig* config = device->getConfiguration();
|
||||||
irr::core::stringw rescue = config->getBindingAsString(PA_RESCUE);
|
irr::core::stringw rescue = config->getBindingAsString(PA_RESCUE);
|
||||||
|
|
||||||
@ -880,7 +880,7 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
|
|||||||
m_action_active = false;
|
m_action_active = false;
|
||||||
//World::getWorld()->getRaceGUI()->clearAllMessages();
|
//World::getWorld()->getRaceGUI()->clearAllMessages();
|
||||||
|
|
||||||
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
|
InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice();
|
||||||
DeviceConfig* config = device->getConfiguration();
|
DeviceConfig* config = device->getConfiguration();
|
||||||
irr::core::stringw skid = config->getBindingAsString(PA_DRIFT);
|
irr::core::stringw skid = config->getBindingAsString(PA_DRIFT);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user