Can now configure keyboard bindings from Options screen (gamepad probably doesn't work)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3555 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
4601dfcc8a
commit
ff77ab2184
@ -242,7 +242,6 @@ namespace StateManager
|
||||
// -----------------------------------------------------------------------------
|
||||
void initInput(Widget* widget, const std::string& name)
|
||||
{
|
||||
{
|
||||
RibbonGridWidget* devices = getCurrentScreen()->getWidget<RibbonGridWidget>("devices");
|
||||
assert( devices != NULL );
|
||||
|
||||
@ -264,12 +263,13 @@ namespace StateManager
|
||||
devices->updateItemDisplay();
|
||||
|
||||
// trigger displaying bindings for default selected device
|
||||
const std::string name("devices");
|
||||
eventInput(devices, name);
|
||||
}
|
||||
const std::string name2("devices");
|
||||
eventInput(devices, name2);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
static PlayerAction binding_to_set;
|
||||
|
||||
void eventInput(Widget* widget, const std::string& name)
|
||||
{
|
||||
if(name == "devices")
|
||||
@ -302,6 +302,48 @@ namespace StateManager
|
||||
}
|
||||
else if(name.find("binding_") != std::string::npos)
|
||||
{
|
||||
if(name == "binding_up")
|
||||
{
|
||||
binding_to_set = PA_ACCEL;
|
||||
}
|
||||
else if(name == "binding_down")
|
||||
{
|
||||
binding_to_set = PA_BRAKE;
|
||||
}
|
||||
else if(name == "binding_left")
|
||||
{
|
||||
binding_to_set = PA_LEFT;
|
||||
}
|
||||
else if(name == "binding_right")
|
||||
{
|
||||
binding_to_set = PA_RIGHT;
|
||||
}
|
||||
else if(name == "binding_fire")
|
||||
{
|
||||
binding_to_set = PA_FIRE;
|
||||
}
|
||||
else if(name == "binding_nitro")
|
||||
{
|
||||
binding_to_set = PA_NITRO;
|
||||
}
|
||||
else if(name == "binding_drift")
|
||||
{
|
||||
binding_to_set = PA_DRIFT;
|
||||
}
|
||||
else if(name == "binding_rescue")
|
||||
{
|
||||
binding_to_set = PA_RESCUE;
|
||||
}
|
||||
else if(name == "binding_look_back")
|
||||
{
|
||||
binding_to_set = PA_LOOK_BACK;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Unknown binding name : " << name.c_str() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
getCurrentScreen()->showModalDialog();
|
||||
//INPUT_SENSE_PREFER_AXIS,
|
||||
//INPUT_SENSE_PREFER_BUTTON,
|
||||
@ -310,6 +352,35 @@ namespace StateManager
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void gotSensedInput(Input* sensedInput)
|
||||
{
|
||||
if(sensedInput->type == Input::IT_KEYBOARD)
|
||||
{
|
||||
KeyboardDevice* keyboard = input_manager->getDeviceList()->getKeyboard(0);
|
||||
keyboard->editBinding(binding_to_set, sensedInput->btnID);
|
||||
|
||||
// GUIEngine::getGUIEnv()->setFocus( btn->m_element );
|
||||
|
||||
// refresh display
|
||||
initInput(NULL, "init");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
getCurrentScreen()->dismissModalDialog();
|
||||
input_manager->setMode(InputManager::MENU);
|
||||
|
||||
// save new binding to file
|
||||
input_manager->getDeviceList()->serialize();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// main call (from StateManager); dispatches the call to a specialissed function as needed
|
||||
void menuEventOptions(Widget* widget, const std::string& name)
|
||||
|
@ -8,10 +8,13 @@ namespace GUIEngine
|
||||
class Widget;
|
||||
}
|
||||
|
||||
struct Input;
|
||||
|
||||
namespace StateManager
|
||||
{
|
||||
|
||||
void menuEventOptions(GUIEngine::Widget* widget, const std::string& name);
|
||||
void gotSensedInput(Input* sensedInput);
|
||||
|
||||
}
|
||||
|
||||
|
@ -387,27 +387,6 @@ namespace StateManager
|
||||
popMenu();
|
||||
}
|
||||
}
|
||||
|
||||
void gotSensedInput(Input* sensedInput)
|
||||
{
|
||||
std::cout << "got sensed input\n";
|
||||
|
||||
if(sensedInput->type == Input::IT_KEYBOARD)
|
||||
{
|
||||
std::cout << "key " << Input::getInputAsString(Input::IT_KEYBOARD, sensedInput->btnID) << std::endl;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
getCurrentScreen()->dismissModalDialog();
|
||||
input_manager->setMode(InputManager::MENU);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
|
@ -17,8 +17,6 @@ namespace StateManager
|
||||
bool isGameState();
|
||||
void reshowTopMostMenu();
|
||||
|
||||
void gotSensedInput(Input* sensedInput);
|
||||
|
||||
void escapePressed();
|
||||
}
|
||||
|
||||
|
@ -135,6 +135,11 @@ void KeyboardDevice::loadDefaults()
|
||||
m_bindings[PA_LOOK_BACK].type = Input::IT_KEYBOARD;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void KeyboardDevice::editBinding(PlayerAction action, int key_id)
|
||||
{
|
||||
m_bindings[action].id = key_id;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
/** checks if this key belongs to this belongs. if yes, sets action and returns true; otherwise returns false */
|
||||
bool KeyboardDevice::hasBinding(const int key_id, PlayerAction* action /* out */) const
|
||||
{
|
||||
|
@ -56,6 +56,8 @@ public:
|
||||
/** checks if this key belongs to this belongs. if yes, sets action and returns true; otherwise returns false */
|
||||
bool hasBinding(const int key_id, PlayerAction* action /* out */) const;
|
||||
|
||||
void editBinding(PlayerAction action, int key_id);
|
||||
|
||||
void loadDefaults();
|
||||
};
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "main_loop.hpp"
|
||||
#include "player.hpp"
|
||||
#include "user_config.hpp"
|
||||
#include "gui/options_screen.hpp"
|
||||
#include "gui/state_manager.hpp"
|
||||
#include "gui/engine.hpp"
|
||||
#include "race_manager.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user