hopefully fixed Arthur's issue + more code work towards gamepad support
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3563 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
11703a68bd
commit
1f7ec5ae58
@ -374,13 +374,19 @@ namespace StateManager
|
||||
// -----------------------------------------------------------------------------
|
||||
void gotSensedInput(Input* sensedInput)
|
||||
{
|
||||
getCurrentScreen()->dismissModalDialog();
|
||||
input_manager->setMode(InputManager::MENU);
|
||||
|
||||
RibbonGridWidget* devices = getCurrentScreen()->getWidget<RibbonGridWidget>("devices");
|
||||
assert( devices != NULL );
|
||||
|
||||
if(sensedInput->type == Input::IT_KEYBOARD && devices->getSelectionName() == "keyboard")
|
||||
const bool keyboard = sensedInput->type == Input::IT_KEYBOARD && devices->getSelectionName() == "keyboard";
|
||||
const bool gamepad = sensedInput->type == (Input::IT_STICKMOTION || sensedInput->type == Input::IT_STICKBUTTON) &&
|
||||
devices->getSelectionName().find("gamepad") != std::string::npos;
|
||||
|
||||
if(!keyboard && !gamepad) return;
|
||||
|
||||
getCurrentScreen()->dismissModalDialog();
|
||||
input_manager->setMode(InputManager::MENU);
|
||||
|
||||
if(keyboard)
|
||||
{
|
||||
std::cout << "received some keyboard input\n";
|
||||
|
||||
@ -390,8 +396,7 @@ namespace StateManager
|
||||
// refresh display
|
||||
initInput(NULL, "init");
|
||||
}
|
||||
else if(sensedInput->type == Input::IT_STICKMOTION || sensedInput->type == Input::IT_STICKBUTTON
|
||||
&& devices->getSelectionName().find("gamepad") != std::string::npos)
|
||||
else if(gamepad)
|
||||
{
|
||||
std::cout << "received some gamepad input\n";
|
||||
|
||||
|
@ -393,7 +393,7 @@ void Screen::processAction(const int action, const unsigned int value, Input::In
|
||||
{
|
||||
const bool pressedDown = value > MAX_VALUE*2/3;
|
||||
|
||||
if(!pressedDown) return;
|
||||
if(!pressedDown && type == Input::IT_STICKMOTION) return;
|
||||
|
||||
switch(action)
|
||||
{
|
||||
@ -402,7 +402,7 @@ void Screen::processAction(const int action, const unsigned int value, Input::In
|
||||
{
|
||||
// simulate a key press
|
||||
irr::SEvent::SKeyInput evt;
|
||||
evt.PressedDown = true;
|
||||
evt.PressedDown = pressedDown;
|
||||
evt.Key = KEY_LEFT;
|
||||
irr::SEvent wrapper;
|
||||
wrapper.KeyInput = evt;
|
||||
@ -433,7 +433,7 @@ void Screen::processAction(const int action, const unsigned int value, Input::In
|
||||
{
|
||||
// simulate a key press
|
||||
irr::SEvent::SKeyInput evt;
|
||||
evt.PressedDown = true;
|
||||
evt.PressedDown = pressedDown;
|
||||
evt.Key = KEY_RIGHT;
|
||||
irr::SEvent wrapper;
|
||||
wrapper.KeyInput = evt;
|
||||
@ -480,7 +480,7 @@ void Screen::processAction(const int action, const unsigned int value, Input::In
|
||||
{
|
||||
// simulate a key press
|
||||
irr::SEvent::SKeyInput evt;
|
||||
evt.PressedDown = true;
|
||||
evt.PressedDown = pressedDown;
|
||||
evt.Key = KEY_UP;
|
||||
irr::SEvent wrapper;
|
||||
wrapper.KeyInput = evt;
|
||||
@ -527,7 +527,7 @@ void Screen::processAction(const int action, const unsigned int value, Input::In
|
||||
{
|
||||
// simulate a key press
|
||||
irr::SEvent::SKeyInput evt;
|
||||
evt.PressedDown = true;
|
||||
evt.PressedDown = pressedDown;
|
||||
evt.Key = KEY_DOWN;
|
||||
irr::SEvent wrapper;
|
||||
wrapper.KeyInput = evt;
|
||||
@ -554,23 +554,25 @@ void Screen::processAction(const int action, const unsigned int value, Input::In
|
||||
break;
|
||||
|
||||
case PA_RESCUE:
|
||||
StateManager::escapePressed();
|
||||
if(pressedDown)
|
||||
StateManager::escapePressed();
|
||||
break;
|
||||
|
||||
case PA_FIRE:
|
||||
if(type == Input::IT_STICKBUTTON)
|
||||
{
|
||||
/*
|
||||
|
||||
std::cout << "sending event, pressedDown=" << pressedDown << "\n";
|
||||
// simulate a 'enter' key press. doesn't seem to work
|
||||
irr::SEvent::SKeyInput evt;
|
||||
evt.PressedDown = true;
|
||||
evt.Key = KEY_RETURN;
|
||||
evt.PressedDown = pressedDown;
|
||||
evt.Key = KEY_SPACE; // KEY_RETURN
|
||||
irr::SEvent wrapper;
|
||||
wrapper.KeyInput = evt;
|
||||
wrapper.EventType = EET_KEY_INPUT_EVENT;
|
||||
GUIEngine::getDevice()->postEventFromUser(wrapper);
|
||||
*/
|
||||
|
||||
/*
|
||||
irr::SEvent::SGUIEvent evt;
|
||||
evt.EventType = EGET_BUTTON_CLICKED;
|
||||
evt.Element = GUIEngine::getGUIEnv()->getFocus();
|
||||
@ -581,6 +583,7 @@ void Screen::processAction(const int action, const unsigned int value, Input::In
|
||||
// GUIEngine::getDevice()->postEventFromUser(wrapper);
|
||||
this->OnEvent(wrapper);
|
||||
// std::cout << "posting event to simulate 'enter'\n";
|
||||
*/
|
||||
|
||||
}
|
||||
break;
|
||||
|
@ -67,13 +67,13 @@ bool DeviceManager::checkForGamePad(const int irr_id)
|
||||
if(m_gamepads[n].m_name == name)
|
||||
{
|
||||
std::cout << "--> that's the one currently connected\n";
|
||||
m_gamepads[n].open(irr_id, m_gamepads[n].m_name, m_irrlicht_gamepads[irr_id].Axes );
|
||||
m_gamepads[n].open(irr_id, m_gamepads[n].m_name, m_irrlicht_gamepads[irr_id].Axes, m_irrlicht_gamepads[irr_id].Buttons);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "couldn't find this joystick, so creating a new one" << std::endl;
|
||||
add(new GamePadDevice(irr_id, m_irrlicht_gamepads[irr_id].Name.c_str(), m_irrlicht_gamepads[irr_id].Axes ));
|
||||
add(new GamePadDevice(irr_id, m_irrlicht_gamepads[irr_id].Name.c_str(), m_irrlicht_gamepads[irr_id].Axes, m_irrlicht_gamepads[irr_id].Buttons ));
|
||||
return true;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -182,30 +182,37 @@ GamePadDevice::GamePadDevice(irr::io::IrrXMLReader* xml)
|
||||
std::cerr << "Warning, joystick without name in config file, making it undetectable\n";
|
||||
}
|
||||
else m_name = name_string;
|
||||
|
||||
for(int n=0; n<SEvent::SJoystickEvent::NUMBER_OF_BUTTONS; n++)
|
||||
m_buttonPressed[n] = false;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
/** 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)
|
||||
GamePadDevice::GamePadDevice(const int irrIndex, const std::string name, const int axis_count, const int btnAmount)
|
||||
{
|
||||
m_type = DT_GAMEPAD;
|
||||
m_deadzone = DEADZONE_JOYSTICK;
|
||||
m_prevAxisDirections = NULL;
|
||||
|
||||
open(irrIndex, name, axis_count);
|
||||
open(irrIndex, name, axis_count, btnAmount);
|
||||
m_name = name;
|
||||
|
||||
loadDefaults();
|
||||
|
||||
for(int n=0; n<SEvent::SJoystickEvent::NUMBER_OF_BUTTONS; n++)
|
||||
m_buttonPressed[n] = false;
|
||||
} // GamePadDevice
|
||||
// -----------------------------------------------------------------------------
|
||||
void GamePadDevice::open(const int irrIndex, const std::string name, const int axis_count)
|
||||
void GamePadDevice::open(const int irrIndex, const std::string name, const int axis_count, const int btnCount)
|
||||
{
|
||||
m_axis_count = axis_count;
|
||||
m_prevAxisDirections = new Input::AxisDirection[axis_count];
|
||||
|
||||
std::cout << "(i) This gamepad has " << axis_count << " axes\n";
|
||||
m_button_count = btnCount;
|
||||
|
||||
std::cout << "(i) This gamepad has " << axis_count << " axes and " << m_button_count << " buttons\n";
|
||||
|
||||
for (int i = 0; i < axis_count; i++)
|
||||
m_prevAxisDirections[i] = Input::AD_NEUTRAL;
|
||||
@ -263,6 +270,15 @@ void GamePadDevice::loadDefaults()
|
||||
*/
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
bool GamePadDevice::isButtonPressed(const int i)
|
||||
{
|
||||
return m_buttonPressed[i];
|
||||
}
|
||||
void GamePadDevice::setButtonPressed(const int i, bool isButtonPressed)
|
||||
{
|
||||
m_buttonPressed[i] = isButtonPressed;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void GamePadDevice::editBinding(const PlayerAction action, const Input::InputType type, const int id, Input::AxisDirection direction)
|
||||
{
|
||||
m_bindings[action].type = type;
|
||||
|
@ -64,10 +64,12 @@ public:
|
||||
class GamePadDevice : public InputDevice
|
||||
{
|
||||
void resetAxisDirection(const int axis, Input::AxisDirection direction, const int player);
|
||||
bool m_buttonPressed[SEvent::SJoystickEvent::NUMBER_OF_BUTTONS];
|
||||
public:
|
||||
int m_deadzone;
|
||||
int m_index;
|
||||
int m_axis_count;
|
||||
int m_button_count;
|
||||
Input::AxisDirection *m_prevAxisDirections;
|
||||
|
||||
/** checks if this key belongs to this belongs. if yes, sets action and returns true; otherwise returns false.
|
||||
@ -77,13 +79,16 @@ public:
|
||||
void editBinding(const PlayerAction action, const Input::InputType type, const int id,
|
||||
Input::AxisDirection direction=Input::AD_NEUTRAL);
|
||||
|
||||
void open(const int irrIndex, const std::string name, const int axis_count);
|
||||
void open(const int irrIndex, const std::string name, const int axis_count, const int btnCount);
|
||||
|
||||
void loadDefaults();
|
||||
|
||||
GamePadDevice(const int irrIndex, const std::string name, const int axis_number);
|
||||
GamePadDevice(const int irrIndex, const std::string name, const int axis_number, const int btnAmount);
|
||||
GamePadDevice(irr::io::IrrXMLReader* xml);
|
||||
|
||||
bool isButtonPressed(const int i);
|
||||
void setButtonPressed(const int i, bool isButtonPressed);
|
||||
|
||||
~GamePadDevice();
|
||||
};
|
||||
|
||||
|
@ -262,8 +262,11 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
|
||||
else
|
||||
{
|
||||
// reset timer when released
|
||||
if( abs(value) == 0 && type == Input::IT_KEYBOARD)
|
||||
if( abs(value) == 0 && (/*type == Input::IT_KEYBOARD ||*/ type == Input::IT_STICKBUTTON) )
|
||||
{
|
||||
if(type == Input::IT_STICKBUTTON) std::cout << "resetting because type == Input::IT_STICKBUTTON\n";
|
||||
else std::cout << "resetting for another reason\n";
|
||||
|
||||
m_timer_in_use = false;
|
||||
m_timer = 0;
|
||||
}
|
||||
@ -318,7 +321,7 @@ bool InputManager::input(const SEvent& event)
|
||||
printf("axis motion: gamepad_id=%d axis=%d value=%d\n",
|
||||
event.JoystickEvent.Joystick, axis_id, value);
|
||||
}
|
||||
|
||||
|
||||
// FIXME - AD_NEGATIVE/AD_POSITIVE are probably useless since value contains that info too
|
||||
if(value < 0)
|
||||
input(Input::IT_STICKMOTION, event.JoystickEvent.Joystick , axis_id, Input::AD_NEGATIVE, value);
|
||||
@ -326,10 +329,16 @@ bool InputManager::input(const SEvent& event)
|
||||
input(Input::IT_STICKMOTION, event.JoystickEvent.Joystick, axis_id, Input::AD_POSITIVE, value);
|
||||
}
|
||||
|
||||
GamePadDevice* gp = getDeviceList()->getGamePadFromIrrID(event.JoystickEvent.Joystick);
|
||||
|
||||
// Buttons - FIXME, instead of checking all of them, ask the bindings which ones to poll
|
||||
for(int i=0; i<SEvent::SJoystickEvent::NUMBER_OF_BUTTONS; i++)
|
||||
for(int i=0; i<gp->m_button_count; i++)
|
||||
{
|
||||
input(Input::IT_STICKBUTTON, event.JoystickEvent.Joystick, i, 0, event.JoystickEvent.IsButtonPressed(i) ? MAX_VALUE : 0);
|
||||
const bool isButtonPressed = event.JoystickEvent.IsButtonPressed(i);
|
||||
|
||||
if(gp->isButtonPressed(i) || isButtonPressed)
|
||||
input(Input::IT_STICKBUTTON, event.JoystickEvent.Joystick, i, 0, isButtonPressed ? MAX_VALUE : 0);
|
||||
gp->setButtonPressed(i, isButtonPressed);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user