playing around a bit more with input. added debug prints to corner what's happening on Arthur's computer

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3561 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2009-05-31 00:40:42 +00:00
parent 99ab952a5f
commit 72c4ac468a
6 changed files with 90 additions and 26 deletions

View File

@@ -349,11 +349,25 @@ namespace StateManager
return;
}
RibbonGridWidget* devices = getCurrentScreen()->getWidget<RibbonGridWidget>("devices");
assert( devices != NULL );
std::cout << "-------\nentering sensing mode for " << devices->getSelectionName().c_str() << std::endl;
getCurrentScreen()->showModalDialog();
//INPUT_SENSE_PREFER_AXIS,
//INPUT_SENSE_PREFER_BUTTON,
input_manager->setMode(InputManager::INPUT_SENSE_KEYBOARD);
std::cout << "in sensing mode\n";
if(devices->getSelectionName() == "keyboard")
{
input_manager->setMode(InputManager::INPUT_SENSE_KEYBOARD);
}
else if(devices->getSelectionName().find("gamepad") != std::string::npos)
{
input_manager->setMode(InputManager::INPUT_SENSE_GAMEPAD);
}
else
{
std::cerr << "unknown selection device in options : " << devices->getSelectionName() << std::endl;
}
}
}
@@ -363,28 +377,57 @@ namespace StateManager
getCurrentScreen()->dismissModalDialog();
input_manager->setMode(InputManager::MENU);
if(sensedInput->type == Input::IT_KEYBOARD)
{
RibbonGridWidget* devices = getCurrentScreen()->getWidget<RibbonGridWidget>("devices");
assert( devices != NULL );
if(sensedInput->type == Input::IT_KEYBOARD && devices->getSelectionName() == "keyboard")
{
std::cout << "received some keyboard input\n";
KeyboardDevice* keyboard = input_manager->getDeviceList()->getKeyboard(0);
keyboard->editBinding(binding_to_set, sensedInput->btnID);
// refresh display
initInput(NULL, "init");
}
else if(sensedInput->type == Input::IT_STICKMOTION || sensedInput->type == Input::IT_STICKBUTTON
&& devices->getSelectionName().find("gamepad") != std::string::npos)
{
std::cout << "received some gamepad input\n";
int gamepadID = -1;
if(sscanf( devices->getSelectionName().c_str(), "gamepad%i", &gamepadID ) != 1 ||
gamepadID >= input_manager->getDeviceList()->getGamePadAmount())
{
if(gamepadID >= input_manager->getDeviceList()->getGamePadAmount() || gamepadID == -1 )
{
std::cerr << "gamepad ID does not exist (or failed to read it) : " << gamepadID << "\n";
gamepadID = sensedInput->deviceID;
}
if(input_manager->getDeviceList()->getGamePad(gamepadID)->m_index != sensedInput->deviceID)
{
// should not happen, but let's try to be bulletproof...
std::cerr << "The key that was pressed is not on the gamepad we're trying to configure! ID in list=" << gamepadID <<
" which has irrID " << input_manager->getDeviceList()->getGamePad(gamepadID)->m_index <<
" and we got input from " << sensedInput->deviceID << "\n";
}
}
GamePadDevice* gamepad = input_manager->getDeviceList()->getGamePad(gamepadID);
gamepad->editBinding(binding_to_set, sensedInput->type, sensedInput->btnID,
(Input::AxisDirection)sensedInput->axisDirection);
//std::cout << "gamepad " << sensedInput->deviceID << "axis " << sensedInput->btnID << " direction=" << sensedInput->axisDirection << std::endl;
//void editBinding(const PlayerAction action, const InputType type, const int id, Input::AxisDirection direction=AD_NEUTRAL);
// re-select the previous button
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>(binding_to_set_button.c_str());
assert( btn != NULL );
GUIEngine::getGUIEnv()->setFocus( btn->m_element );
}
else if(sensedInput->type == Input::IT_STICKMOTION)
{
std::cout << "gamepad " << sensedInput->deviceID << "axis " << sensedInput->btnID << " direction=" << sensedInput->axisDirection << std::endl;
}
else if(sensedInput->type == Input::IT_STICKBUTTON)
{
std::cout << "gamepad " << sensedInput->deviceID << " button " << sensedInput->btnID << std::endl;
}
// re-select the previous button
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>(binding_to_set_button.c_str());
if(btn != NULL) GUIEngine::getGUIEnv()->setFocus( btn->m_element );
// save new binding to file
input_manager->getDeviceList()->serialize();
}

View File

@@ -39,6 +39,16 @@ bool DeviceManager::initGamePadSupport()
return something_new_to_write;
}
// -----------------------------------------------------------------------------
GamePadDevice* DeviceManager::getGamePadFromIrrID(const int id)
{
for(unsigned int i=0; i<m_gamepad_amount; i++)
{
if(m_gamepads[i].m_index == id)
return m_gamepads.get(i);
}
return NULL;
}
// -----------------------------------------------------------------------------
/**
* Check if we already have a config object for joystick 'irr_id' as reported by irrLicht
* If yes, 'open' the gamepad. If no, create one. Returns whether a new gamepad was created.

View File

@@ -20,11 +20,12 @@ public:
void add(KeyboardDevice* d);
void add(GamePadDevice* d);
int getGamePadAmount() const{ return m_gamepad_amount; }
GamePadDevice* getGamePad(const int i) { return m_gamepads.get(i); }
int getGamePadAmount() const { return m_gamepad_amount; }
GamePadDevice* getGamePad(const int i) { return m_gamepads.get(i); }
GamePadDevice* getGamePadFromIrrID(const int i);
int getKeyboardAmount() const{ return m_keyboard_amount; }
KeyboardDevice* getKeyboard(const int i) { return m_keyboards.get(i); }
int getKeyboardAmount() const { return m_keyboard_amount; }
KeyboardDevice* getKeyboard(const int i) { return m_keyboards.get(i); }
/** Given some input, finds to which device it belongs and, using the corresponding device object,
maps this input to the corresponding player and game action. returns false if player/action could not be set */

View File

@@ -480,20 +480,20 @@ std::string Input::getInputAsString(const Input::InputType type, const int id, c
break;
case Input::IT_STICKBUTTON:
//I18N : to appear in input configuration screen, for gamepad buttons
s = StringUtils::insert_values( _("Gamepad button %d"), id);
s = StringUtils::insert_values( _("Gamepad button %d"), (id+1));
break;
case Input::IT_STICKHAT:
//I18N : to appear in input configuration screen, for gamepad hats
s = StringUtils::insert_values( _("Gamepad hat %d"), id);
s = StringUtils::insert_values( _("Gamepad hat %d"), (id+1));
break;
case Input::IT_MOUSEBUTTON:
//I18N : to appear in input configuration screen, for mouse (might not be used at all)
s = StringUtils::insert_values( _("Mouse button %d"), id);
s = StringUtils::insert_values( _("Mouse button %d"), (id+1));
break;
case Input::IT_MOUSEMOTION: // FIXME : I don't reckon this is used at all
//I18N : to appear in input configuration screen, for mouse (might not be used at all)
s = StringUtils::insert_values( _("Mouse axis %d %s"),
id,
(id+1),
(dir == Input::AD_NEGATIVE)
? '-': '+' );
break;

View File

@@ -263,6 +263,13 @@ void GamePadDevice::loadDefaults()
*/
}
// -----------------------------------------------------------------------------
void GamePadDevice::editBinding(const PlayerAction action, const Input::InputType type, const int id, Input::AxisDirection direction)
{
m_bindings[action].type = type;
m_bindings[action].id = id;
m_bindings[PA_ACCEL].dir = direction;
}
// -----------------------------------------------------------------------------
void GamePadDevice::resetAxisDirection(const int axis, Input::AxisDirection direction, const int player)
{
if(!StateManager::isGameState()) return; // ignore this while in menus

View File

@@ -74,6 +74,9 @@ public:
The 'player' id passed is simply to know where to send 'axis reset's when necessary*/
bool hasBinding(Input::InputType type, const int id, const int value, const int player, PlayerAction* action /* out */);
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 loadDefaults();