From: <au...@us...> - 2009-05-31 01:01:14
|
Revision: 3561 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=3561&view=rev Author: auria Date: 2009-05-31 00:40:42 +0000 (Sun, 31 May 2009) Log Message: ----------- playing around a bit more with input. added debug prints to corner what's happening on Arthur's computer Modified Paths: -------------- main/branches/irrlicht/src/gui/options_screen.cpp main/branches/irrlicht/src/input/device_manager.cpp main/branches/irrlicht/src/input/device_manager.hpp main/branches/irrlicht/src/input/input.cpp main/branches/irrlicht/src/input/input_device.cpp main/branches/irrlicht/src/input/input_device.hpp Modified: main/branches/irrlicht/src/gui/options_screen.cpp =================================================================== --- main/branches/irrlicht/src/gui/options_screen.cpp 2009-05-30 23:45:51 UTC (rev 3560) +++ main/branches/irrlicht/src/gui/options_screen.cpp 2009-05-31 00:40:42 UTC (rev 3561) @@ -349,11 +349,25 @@ 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 @@ 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"); - - // 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) + else if(sensedInput->type == Input::IT_STICKMOTION || sensedInput->type == Input::IT_STICKBUTTON + && devices->getSelectionName().find("gamepad") != std::string::npos) { - std::cout << "gamepad " << sensedInput->deviceID << "axis " << sensedInput->btnID << " direction=" << sensedInput->axisDirection << std::endl; + 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); + } - 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(); } Modified: main/branches/irrlicht/src/input/device_manager.cpp =================================================================== --- main/branches/irrlicht/src/input/device_manager.cpp 2009-05-30 23:45:51 UTC (rev 3560) +++ main/branches/irrlicht/src/input/device_manager.cpp 2009-05-31 00:40:42 UTC (rev 3561) @@ -39,6 +39,16 @@ 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. Modified: main/branches/irrlicht/src/input/device_manager.hpp =================================================================== --- main/branches/irrlicht/src/input/device_manager.hpp 2009-05-30 23:45:51 UTC (rev 3560) +++ main/branches/irrlicht/src/input/device_manager.hpp 2009-05-31 00:40:42 UTC (rev 3561) @@ -20,11 +20,12 @@ 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 */ Modified: main/branches/irrlicht/src/input/input.cpp =================================================================== --- main/branches/irrlicht/src/input/input.cpp 2009-05-30 23:45:51 UTC (rev 3560) +++ main/branches/irrlicht/src/input/input.cpp 2009-05-31 00:40:42 UTC (rev 3561) @@ -480,20 +480,20 @@ 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; Modified: main/branches/irrlicht/src/input/input_device.cpp =================================================================== --- main/branches/irrlicht/src/input/input_device.cpp 2009-05-30 23:45:51 UTC (rev 3560) +++ main/branches/irrlicht/src/input/input_device.cpp 2009-05-31 00:40:42 UTC (rev 3561) @@ -263,6 +263,13 @@ */ } // ----------------------------------------------------------------------------- +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 Modified: main/branches/irrlicht/src/input/input_device.hpp =================================================================== --- main/branches/irrlicht/src/input/input_device.hpp 2009-05-30 23:45:51 UTC (rev 3560) +++ main/branches/irrlicht/src/input/input_device.hpp 2009-05-31 00:40:42 UTC (rev 3561) @@ -74,6 +74,9 @@ 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(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |