gamepads can now be configured! I cannot test if it works when you have mutliple gamepad models, people will need to help me here
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3565 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -176,7 +176,7 @@ namespace StateManager
|
||||
RibbonGridWidget* w1 = getCurrentScreen()->getWidget<RibbonGridWidget>("resolutions");
|
||||
assert(w1 != NULL);
|
||||
|
||||
const std::string& res = w1->getSelectionName();
|
||||
const std::string& res = w1->getSelectionIDString();
|
||||
|
||||
int w = -1, h = -1;
|
||||
if( sscanf(res.c_str(), "%ix%i", &w, &h) != 2 || w == -1 || h == -1 )
|
||||
@@ -280,7 +280,7 @@ namespace StateManager
|
||||
RibbonGridWidget* devices = getCurrentScreen()->getWidget<RibbonGridWidget>("devices");
|
||||
assert(devices != NULL);
|
||||
|
||||
const std::string& selection = devices->getSelectionName();
|
||||
const std::string& selection = devices->getSelectionIDString();
|
||||
if( selection.find("gamepad") != std::string::npos )
|
||||
{
|
||||
int i = -1, read = 0;
|
||||
@@ -351,21 +351,21 @@ namespace StateManager
|
||||
|
||||
RibbonGridWidget* devices = getCurrentScreen()->getWidget<RibbonGridWidget>("devices");
|
||||
assert( devices != NULL );
|
||||
std::cout << "-------\nentering sensing mode for " << devices->getSelectionName().c_str() << std::endl;
|
||||
std::cout << "-------\nentering sensing mode for " << devices->getSelectionIDString().c_str() << std::endl;
|
||||
|
||||
getCurrentScreen()->showModalDialog();
|
||||
|
||||
if(devices->getSelectionName() == "keyboard")
|
||||
if(devices->getSelectionIDString() == "keyboard")
|
||||
{
|
||||
input_manager->setMode(InputManager::INPUT_SENSE_KEYBOARD);
|
||||
}
|
||||
else if(devices->getSelectionName().find("gamepad") != std::string::npos)
|
||||
else if(devices->getSelectionIDString().find("gamepad") != std::string::npos)
|
||||
{
|
||||
input_manager->setMode(InputManager::INPUT_SENSE_GAMEPAD);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "unknown selection device in options : " << devices->getSelectionName() << std::endl;
|
||||
std::cerr << "unknown selection device in options : " << devices->getSelectionIDString() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -379,10 +379,10 @@ namespace StateManager
|
||||
RibbonGridWidget* devices = getCurrentScreen()->getWidget<RibbonGridWidget>("devices");
|
||||
assert( devices != NULL );
|
||||
|
||||
const bool keyboard = sensedInput->type == Input::IT_KEYBOARD && devices->getSelectionName() == "keyboard";
|
||||
const bool gamepad = sensedInput->type == (sensedInput->type == Input::IT_STICKMOTION ||
|
||||
sensedInput->type == Input::IT_STICKBUTTON) &&
|
||||
devices->getSelectionName().find("gamepad") != std::string::npos;
|
||||
const bool keyboard = sensedInput->type == Input::IT_KEYBOARD && devices->getSelectionIDString() == "keyboard";
|
||||
const bool gamepad = (sensedInput->type == Input::IT_STICKMOTION ||
|
||||
sensedInput->type == Input::IT_STICKBUTTON) &&
|
||||
devices->getSelectionIDString().find("gamepad") != std::string::npos;
|
||||
|
||||
if(!keyboard && !gamepad) return;
|
||||
|
||||
@@ -402,10 +402,14 @@ namespace StateManager
|
||||
else if(gamepad)
|
||||
{
|
||||
std::cout << "received some gamepad input\n";
|
||||
if(sensedInput->type == Input::IT_STICKMOTION)
|
||||
std::cout << "axis\n";
|
||||
if(sensedInput->type == Input::IT_STICKBUTTON)
|
||||
std::cout << "button\n";
|
||||
|
||||
int gamepadID = -1;
|
||||
|
||||
if(sscanf( devices->getSelectionName().c_str(), "gamepad%i", &gamepadID ) != 1 ||
|
||||
if(sscanf( devices->getSelectionIDString().c_str(), "gamepad%i", &gamepadID ) != 1 ||
|
||||
gamepadID >= input_manager->getDeviceList()->getGamePadAmount())
|
||||
{
|
||||
if(gamepadID >= input_manager->getDeviceList()->getGamePadAmount() || gamepadID == -1 )
|
||||
@@ -427,9 +431,8 @@ namespace StateManager
|
||||
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);
|
||||
|
||||
// refresh display
|
||||
initInput(NULL, "init");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -469,7 +472,7 @@ namespace StateManager
|
||||
}
|
||||
else if(name == "options_choice")
|
||||
{
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionName().c_str();
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString().c_str();
|
||||
|
||||
if(selection == "audio_video") StateManager::replaceTopMostMenu("options_av.stkgui");
|
||||
else if(selection == "players") StateManager::replaceTopMostMenu("options_players.stkgui");
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace StateManager
|
||||
{
|
||||
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(widget);
|
||||
if(ribbon == NULL) return; // only interesting stuff in main menu is the ribbons
|
||||
std::string selection = ribbon->getSelectionName().c_str();
|
||||
std::string selection = ribbon->getSelectionIDString().c_str();
|
||||
|
||||
|
||||
if(selection == "new")
|
||||
@@ -120,7 +120,7 @@ namespace StateManager
|
||||
RibbonGridWidget* w = getCurrentScreen()->getWidget<RibbonGridWidget>("karts");
|
||||
assert( w != NULL );
|
||||
|
||||
race_manager->setLocalKartInfo(0, w->getSelectionName());
|
||||
race_manager->setLocalKartInfo(0, w->getSelectionIDString());
|
||||
|
||||
StateManager::pushMenu("racesetup.stkgui");
|
||||
}
|
||||
@@ -146,7 +146,7 @@ namespace StateManager
|
||||
{
|
||||
RibbonWidget* w = dynamic_cast<RibbonWidget*>(widget);
|
||||
assert(w != NULL);
|
||||
const std::string& selection = w->getSelectionName();
|
||||
const std::string& selection = w->getSelectionIDString();
|
||||
|
||||
if(selection == "novice")
|
||||
race_manager->setDifficulty(RaceManager::RD_EASY);
|
||||
@@ -159,7 +159,7 @@ namespace StateManager
|
||||
{
|
||||
// TODO - detect more game modes
|
||||
RibbonWidget* w = dynamic_cast<RibbonWidget*>(widget);
|
||||
if(w->getSelectionName() == "normal")
|
||||
if(w->getSelectionIDString() == "normal")
|
||||
{
|
||||
StateManager::pushMenu("tracks.stkgui");
|
||||
}
|
||||
@@ -243,7 +243,7 @@ namespace StateManager
|
||||
RibbonGridWidget* w2 = dynamic_cast<RibbonGridWidget*>(widget);
|
||||
if(w2 != NULL)
|
||||
{
|
||||
std::cout << "Clicked on track " << w2->getSelectionName().c_str() << std::endl;
|
||||
std::cout << "Clicked on track " << w2->getSelectionIDString().c_str() << std::endl;
|
||||
|
||||
StateManager::enterGameState();
|
||||
//race_manager->setDifficulty(RaceManager::RD_HARD);
|
||||
@@ -263,7 +263,7 @@ namespace StateManager
|
||||
{
|
||||
RibbonWidget* w = dynamic_cast<RibbonWidget*>(widget);
|
||||
if(w != NULL)
|
||||
std::cout << "Clicked on GrandPrix " << w->getSelectionName().c_str() << std::endl;
|
||||
std::cout << "Clicked on GrandPrix " << w->getSelectionIDString().c_str() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -290,7 +290,7 @@ namespace StateManager
|
||||
// -- options
|
||||
else if(name == "category")
|
||||
{
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionName().c_str();
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString().c_str();
|
||||
|
||||
if(selection == "page1") replaceTopMostMenu("help1.stkgui");
|
||||
else if(selection == "page2") replaceTopMostMenu("help2.stkgui");
|
||||
|
||||
@@ -1068,7 +1068,7 @@ void RibbonGridWidget::updateLabel(RibbonWidget* from_this_ribbon)
|
||||
if(row == NULL) return;
|
||||
|
||||
|
||||
std::string selection_id = row->getSelectionName();
|
||||
std::string selection_id = row->getSelectionIDString();
|
||||
|
||||
const int amount = m_items.size();
|
||||
for(int n=0; n<amount; n++)
|
||||
@@ -1159,11 +1159,11 @@ void RibbonGridWidget::updateItemDisplay()
|
||||
} // next row
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
const std::string& RibbonGridWidget::getSelectionName()
|
||||
const std::string& RibbonGridWidget::getSelectionIDString()
|
||||
{
|
||||
RibbonWidget* row = (RibbonWidget*)(m_rows.size() == 1 ? m_rows.get(0) : getSelectedRibbon());
|
||||
|
||||
if(row != NULL) return row->getSelectionName();
|
||||
if(row != NULL) return row->getSelectionIDString();
|
||||
|
||||
static const std::string nothing = "";
|
||||
return nothing;
|
||||
|
||||
@@ -246,7 +246,7 @@ namespace GUIEngine
|
||||
void select(std::string item);
|
||||
|
||||
RibbonType getRibbonType() const { return m_ribbon_type; }
|
||||
const std::string& getSelectionName() { return m_children[m_selection].m_properties[PROP_ID]; }
|
||||
const std::string& getSelectionIDString() { return m_children[m_selection].m_properties[PROP_ID]; }
|
||||
void setLabel(const int id, std::string new_name);
|
||||
|
||||
RibbonWidget(const RibbonType type=RIBBON_COMBO);
|
||||
@@ -304,7 +304,7 @@ namespace GUIEngine
|
||||
|
||||
bool mouseHovered(Widget* child);
|
||||
|
||||
const std::string& getSelectionName();
|
||||
const std::string& getSelectionIDString();
|
||||
void setSelection(int item_id);
|
||||
void setSelection(const std::string& code_name);
|
||||
};
|
||||
|
||||
@@ -211,6 +211,12 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
|
||||
if (m_mode == INPUT_SENSE_KEYBOARD ||
|
||||
m_mode == INPUT_SENSE_GAMEPAD)
|
||||
{
|
||||
|
||||
if(type == Input::IT_STICKMOTION)
|
||||
std::cout << "sensing input -- axis binding\n";
|
||||
if(type == Input::IT_STICKBUTTON)
|
||||
std::cout << "sensing input -- button binding\n";
|
||||
|
||||
// Input sensing should be canceled. (TODO)
|
||||
//if (ga == GA_LEAVE && m_sensed_input->type==Input::IT_KEYBOARD)
|
||||
//{
|
||||
@@ -224,19 +230,30 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
|
||||
// See if the new input should be stored. This happens if:
|
||||
// 1) the value is larger
|
||||
// 2) nothing has been saved yet
|
||||
// 3) the new event has the preferred type
|
||||
// 3) the new event has the preferred type : TODO - reimplement
|
||||
// The latter is necessary since some gamepads have analog
|
||||
// buttons that can return two different events when pressed
|
||||
bool store_new = abs(value) > m_max_sensed_input ||
|
||||
m_max_sensed_type == Input::IT_NONE ||
|
||||
( m_mode == INPUT_SENSE_GAMEPAD && type == Input::IT_STICKMOTION &&
|
||||
m_max_sensed_type != Input::IT_STICKMOTION ); /*||
|
||||
( m_mode == INPUT_SENSE_PREFER_BUTTON &&
|
||||
type == Input::IT_STICKBUTTON &&
|
||||
m_max_sensed_type != Input::IT_STICKBUTTON );*/
|
||||
m_max_sensed_type == Input::IT_NONE;
|
||||
|
||||
// (m_mode == INPUT_SENSE_GAMEPAD && (type == Input::IT_STICKMOTION ||
|
||||
// type == Input::IT_STICKBUTTON) &&
|
||||
// abs(value) > m_max_sensed_input);
|
||||
|
||||
// don't store if we're trying to do something like bindings keyboard keys on a gamepad
|
||||
if(m_mode == INPUT_SENSE_KEYBOARD && type != Input::IT_KEYBOARD) store_new = false;
|
||||
if(m_mode == INPUT_SENSE_GAMEPAD && type != Input::IT_STICKMOTION && type != Input::IT_STICKBUTTON) store_new = false;
|
||||
|
||||
// only store axes when they're pushed quite far
|
||||
if(m_mode == INPUT_SENSE_GAMEPAD && type == Input::IT_STICKMOTION && abs(value) < MAX_VALUE *2/3) store_new = false;
|
||||
|
||||
if(store_new)
|
||||
{
|
||||
m_sensed_input->type = type;
|
||||
if(type == Input::IT_STICKMOTION)
|
||||
std::cout << "storing new axis binding\n";
|
||||
if(type == Input::IT_STICKBUTTON)
|
||||
std::cout << "storing new button binding\n";
|
||||
|
||||
m_sensed_input->deviceID = deviceID;
|
||||
m_sensed_input->btnID = btnID;
|
||||
@@ -245,6 +262,7 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
|
||||
m_max_sensed_input = abs(value);
|
||||
m_max_sensed_type = type;
|
||||
}
|
||||
|
||||
// Notify the completion of the input sensing if the key/stick/
|
||||
// ... is released.
|
||||
if(value==0)
|
||||
@@ -331,7 +349,6 @@ bool InputManager::input(const SEvent& event)
|
||||
|
||||
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<gp->m_button_count; i++)
|
||||
{
|
||||
const bool isButtonPressed = event.JoystickEvent.IsButtonPressed(i);
|
||||
|
||||
Reference in New Issue
Block a user