Moved the handling for the fire & rescue buttons in the kart selection menu out of the device manager & into the input manager (which makes more sense). No more setting the action to PA_FIRST to signify that it was handled internally (too hackish).

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3842 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
rforder 2009-08-12 18:19:02 +00:00
parent 209d679a56
commit db1c53fa94
3 changed files with 35 additions and 30 deletions

View File

@ -163,20 +163,20 @@ InputDevice *DeviceManager::mapKeyboardInput( int deviceID,
ActivePlayer **player,
PlayerAction *action )
{
InputDevice *device = m_keyboard;
KeyboardDevice *keyboard = m_keyboard;
if (m_keyboard->hasBinding(btnID, action))
if (keyboard->hasBinding(btnID, action))
{
if (m_assign_mode == NO_ASSIGN) // Don't set the player in NO_ASSIGN mode
{
*player = NULL;
if (!progGen) m_latest_used_device = m_keyboard;
if (!progGen) m_latest_used_device = keyboard;
}
else *player = m_keyboard->m_player;
else *player = keyboard->m_player;
}
else device = NULL; // If no appropriate bind was found, return NULL
else keyboard = NULL; // If no appropriate bind was found, return NULL
return device;
return keyboard;
}
//-----------------------------------------------------------------------------
@ -233,8 +233,6 @@ bool DeviceManager::translateInput( Input::InputType type,
device = mapKeyboardInput(deviceID, btnID, programaticallyGenerated, player, action);
break;
case Input::IT_STICKBUTTON:
device = mapGamepadInput(type, deviceID, btnID, axisDir, value, programaticallyGenerated, player, action);
break;
case Input::IT_STICKMOTION:
device = mapGamepadInput(type, deviceID, btnID, axisDir, value, programaticallyGenerated, player, action);
break;
@ -242,27 +240,6 @@ bool DeviceManager::translateInput( Input::InputType type,
break;
};
// If a matching device was found
if (device != NULL)
{
// Handle internal events
/* FIXME: only call when in kart selection screen
if ((*player != NULL) && (*action == PA_RESCUE))
{
KartSelectionScreen::playerPressedRescue( *player );
*action = PA_FIRST; // FIXME: action set to PA_FIRST if handled internally (too hackish)
}
*/
if ((*player == NULL) && (*action == PA_FIRE) && (m_assign_mode == DETECT_NEW))
{
KartSelectionScreen::firePressedOnNewDevice( device );
*action = PA_FIRST;
}
}
// Return true if input was successfully translated to an action and player
return (device != NULL);
}

View File

@ -66,6 +66,7 @@ public:
GamepadConfig* getGamepadConfig(const int i) { return m_gamepad_configs.get(i); }
PlayerAssignMode playerAssignMode() const { return m_assign_mode; }
KeyboardDevice* getKeyboard(const int i) { return m_keyboard; }
PlayerAssignMode getAssignMode() { return m_assign_mode; }
GamePadDevice* getGamePadFromIrrID(const int i);
InputDevice* getLatestUsedDevice();
void setAssignMode(const PlayerAssignMode assignMode);

View File

@ -30,6 +30,7 @@
#include "config/user_config.hpp"
#include "graphics/irr_driver.hpp"
#include "states_screens/options_screen.hpp"
#include "states_screens/kart_selection.hpp"
#include "states_screens/state_manager.hpp"
#include "guiengine/modaldialog.hpp"
#include "guiengine/engine.hpp"
@ -239,7 +240,7 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
ActivePlayer* player = NULL;
PlayerAction action;
bool action_found = m_device_manager->translateInput( type, deviceID, btnID, axisDirection,
value, programaticallyGenerated, &player, &action );
value, programaticallyGenerated, &player, &action);
if (action_found && action == PA_FIRST) return; // input handled internally by the device manager
@ -274,6 +275,32 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
// Otherwise, do something with the key if it matches a binding
else if (action_found)
{
// If we're in the kart menu awaiting new players, do special things
// when a device presses fire or rescue
if( m_device_manager->getAssignMode() == DETECT_NEW )
{
// Player is unjoining
if ((player != NULL) && (action == PA_RESCUE))
{
KartSelectionScreen::playerPressedRescue( player );
return; // we're done here
}
// New player is joining
else if ((player == NULL) && (action == PA_FIRE))
{
InputDevice *device = NULL;
if (type == Input::IT_KEYBOARD)
device = m_device_manager->getKeyboard(0);
else if (type == Input::IT_STICKBUTTON || type == Input::IT_STICKMOTION)
device = m_device_manager->getGamePadFromIrrID(deviceID);
if (device != NULL)
KartSelectionScreen::firePressedOnNewDevice( device );
return; // we're done here
}
}
// ... when in-game
if(StateManager::get()->isGameState())
{