Updated input configuration GUI to work correctly with recent changes to the input system.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3826 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
rforder 2009-08-09 18:12:35 +00:00
parent 3ef3c67213
commit aee48faca8
5 changed files with 45 additions and 30 deletions

View File

@ -201,6 +201,8 @@ void KeyboardConfig::setDefaultBinds()
KeyboardConfig::KeyboardConfig()
{
m_name = "Keyboard";
setInUse(true);
setDefaultBinds();
}
@ -238,6 +240,7 @@ GamepadConfig::GamepadConfig ( const std::string name,
m_name = name;
m_axis_count = axis_count;
m_button_count = btnCount;
setInUse(false);
setDefaultBinds();
}
@ -254,6 +257,7 @@ GamepadConfig::GamepadConfig(irr::io::IrrXMLReader* xml)
{
m_name = name_string;
}
setInUse(false);
setDefaultBinds();
}

View File

@ -25,11 +25,16 @@ class DeviceConfig
private:
KeyBinding m_bindings[PA_COUNT];
bool m_inuse; // Is there a device connected to the system
// which uses this config?
protected:
std::string m_name;
public:
std::string getName() const { return m_name; };
std::string getBindingAsString (const PlayerAction action) const;
std::string toString ();
@ -41,6 +46,9 @@ class DeviceConfig
const int id,
Input::AxisDirection direction = Input::AD_NEUTRAL);
void setInUse (bool inuse) {m_inuse = inuse;}
bool isInUse () {return m_inuse;}
// Don't call this directly unless you are KeyboardDevice or GamepadDevice
bool getAction (Input::InputType type,
const int id,
@ -75,14 +83,12 @@ class GamepadConfig : public DeviceConfig
private:
std::string m_name;
int m_axis_count;
int m_button_count;
public:
std::string toString ();
std::string getName() const { return m_name; };
int getAxisCount() const { return m_axis_count; };
int getButtonCount() const { return m_button_count; };
void serialize (std::ofstream& stream);

View File

@ -43,11 +43,14 @@ bool DeviceManager::initialize()
created = true;
}
m_keyboard = new KeyboardDevice(m_keyboard_configs.get(0));
// TODO: Detect keyboard presence, if there is no keyboard, this should be false
m_keyboard_configs.get(0)->setInUse(true);
printf("Initializing gamepad support.\n");
irr_driver->getDevice()->activateJoysticks(m_irrlicht_gamepads);
numGamepads = m_irrlicht_gamepads.size();
printf("Irrlicht reports %d gamepads are attached to the system.\n", numGamepads);
// Create GamePadDevice for each physical gamepad and find a GamepadConfig to match
for (int id = 0; id < numGamepads; id++)
@ -64,6 +67,7 @@ bool DeviceManager::initialize()
printf("using existing configuration.\n");
}
gamepadConfig->setInUse(true);
gamepadDevice = new GamePadDevice( id,
m_irrlicht_gamepads[id].Name.c_str(),
m_irrlicht_gamepads[id].Axes,

View File

@ -61,7 +61,9 @@ public:
void addGamepad(GamePadDevice* d);
int getGamePadAmount() const { return m_gamepads.size(); }
int getGamePadConfigAmount() const { return m_gamepad_configs.size(); }
GamePadDevice* getGamePad(const int i) { return m_gamepads.get(i); }
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; }
GamePadDevice* getGamePadFromIrrID(const int i);

View File

@ -223,18 +223,8 @@ namespace OptionsScreen
}
// -----------------------------------------------------------------------------
void updateInputButtons(InputDevice* device)
void updateInputButtons(DeviceConfig* config)
{
DeviceConfig *config;
// Should never happen
if (device == NULL)
{
printf("updateInputButtons: passed NULL pointer\n");
abort();
}
config = device->getConfiguration();
// Should never happen
if (config == NULL)
@ -265,19 +255,19 @@ namespace OptionsScreen
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_nitro");
btn->setLabel( device->getConfiguration()->getBindingAsString(PA_NITRO).c_str() );
btn->setLabel( config->getBindingAsString(PA_NITRO).c_str() );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_drift");
btn->setLabel( device->getConfiguration()->getBindingAsString(PA_DRIFT).c_str() );
btn->setLabel( config->getBindingAsString(PA_DRIFT).c_str() );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_rescue");
btn->setLabel( device->getConfiguration()->getBindingAsString(PA_RESCUE).c_str() );
btn->setLabel( config->getBindingAsString(PA_RESCUE).c_str() );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_look_back");
btn->setLabel( device->getConfiguration()->getBindingAsString(PA_LOOK_BACK).c_str() );
btn->setLabel( config->getBindingAsString(PA_LOOK_BACK).c_str() );
}
}
@ -292,14 +282,19 @@ namespace OptionsScreen
{
devices->addItem("Keyboard","keyboard", file_manager->getDataDir() + "/gui/keyboard.png");
const int gamepad_count = input_manager->getDeviceList()->getGamePadAmount();
const int gpad_config_count = input_manager->getDeviceList()->getGamePadConfigAmount();
for(int i=0; i<gamepad_count; i++)
for(int i = 0; i < gpad_config_count; i++)
{
std::string name = input_manager->getDeviceList()->getGamePad(i)->m_name;
char internal_name[32];
sprintf(internal_name, "gamepad%i", i);
devices->addItem(name,internal_name, file_manager->getDataDir() + "/gui/gamepad.png");
GamepadConfig *config = input_manager->getDeviceList()->getGamepadConfig(i);
// Don't display the configuration if a matching device is not available
if (config->isInUse())
{
std::string name = config->getName();
char internal_name[32];
sprintf(internal_name, "gamepad%i", i);
devices->addItem(name,internal_name, file_manager->getDataDir() + "/gui/gamepad.png");
}
}
getCurrentScreen()->m_inited = true;
@ -369,7 +364,7 @@ namespace OptionsScreen
read = sscanf( selection.c_str(), "gamepad%i", &i );
if(read == 1 && i != -1)
{
updateInputButtons( input_manager->getDeviceList()->getGamePad(i) );
updateInputButtons( input_manager->getDeviceList()->getGamepadConfig(i) );
}
else
{
@ -378,7 +373,7 @@ namespace OptionsScreen
}
else if(selection == "keyboard")
{
updateInputButtons( input_manager->getDeviceList()->getKeyboard(0) );
updateInputButtons( input_manager->getDeviceList()->getKeyboard(0)->getConfiguration() );
}
else
{
@ -480,7 +475,7 @@ namespace OptionsScreen
std::cout << "% Binding " << KartActionStrings[binding_to_set] << " : setting to keyboard key " << sensedInput->btnID << " \n\n";
KeyboardDevice* keyboard = input_manager->getDeviceList()->getKeyboard(0);
//keyboard->getConfiguration()->setBinding(binding_to_set, Input::IT_KEYBOARD, sensedInput->btnID, Input::AD_NEUTRAL);
keyboard->getConfiguration()->setBinding(binding_to_set, Input::IT_KEYBOARD, sensedInput->btnID, Input::AD_NEUTRAL);
// refresh display
initInput(NULL, "init");
@ -500,8 +495,10 @@ namespace OptionsScreen
else
std::cout << "Sensed unknown gamepad event type??\n";
int gamepadID = -1;
int configID = -1;
sscanf( devices->getSelectionIDString().c_str(), "gamepad%i", &configID );
/*
if(sscanf( devices->getSelectionIDString().c_str(), "gamepad%i", &gamepadID ) != 1 ||
gamepadID >= input_manager->getDeviceList()->getGamePadAmount())
{
@ -511,7 +508,7 @@ namespace OptionsScreen
gamepadID = sensedInput->deviceID;
}
if(input_manager->getDeviceList()->getGamePad(gamepadID)->m_index != sensedInput->deviceID)
if(input_manager->getDeviceList()->getGamepadConfig(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 <<
@ -520,8 +517,10 @@ namespace OptionsScreen
}
}
GamePadDevice* gamepad = input_manager->getDeviceList()->getGamePad(gamepadID);
gamepad->getConfiguration()->setBinding(binding_to_set, sensedInput->type, sensedInput->btnID,
*/
GamepadConfig* config = input_manager->getDeviceList()->getGamepadConfig(configID);
config->setBinding(binding_to_set, sensedInput->type, sensedInput->btnID,
(Input::AxisDirection)sensedInput->axisDirection);
// refresh display