For ticket #82 : start adding the infrastructure to show in the UI which gamepad is which

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8566 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-05-14 00:30:30 +00:00
parent 922eb14a22
commit 15cdaf04bd
10 changed files with 72 additions and 15 deletions

View File

@ -171,6 +171,7 @@ bool EventHandler::OnEvent (const SEvent &event)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void EventHandler::processGUIAction(const PlayerAction action, void EventHandler::processGUIAction(const PlayerAction action,
int deviceID,
const unsigned int value, const unsigned int value,
Input::InputType type, Input::InputType type,
const int playerID) const int playerID)
@ -178,7 +179,7 @@ void EventHandler::processGUIAction(const PlayerAction action,
Screen* screen = GUIEngine::getCurrentScreen(); Screen* screen = GUIEngine::getCurrentScreen();
if (screen != NULL) if (screen != NULL)
{ {
EventPropagation propg = screen->filterActions(action, value, EventPropagation propg = screen->filterActions(action, deviceID, value,
type, playerID); type, playerID);
if (propg == EVENT_BLOCK) return; if (propg == EVENT_BLOCK) return;
} }

View File

@ -80,7 +80,7 @@ namespace GUIEngine
* and this action needs to be applied to the GUI (e.g. fire pressed, left * and this action needs to be applied to the GUI (e.g. fire pressed, left
* pressed, etc.) this method is called back by the input module. * pressed, etc.) this method is called back by the input module.
*/ */
void processGUIAction(const PlayerAction action, const unsigned int value, void processGUIAction(const PlayerAction action, int deviceID, const unsigned int value,
Input::InputType type, const int playerID); Input::InputType type, const int playerID);
/** singleton access */ /** singleton access */

View File

@ -264,7 +264,7 @@ namespace GUIEngine
/** /**
* \brief override this if you need to be notified of player actions in subclasses * \brief override this if you need to be notified of player actions in subclasses
*/ */
virtual EventPropagation filterActions(PlayerAction action, const unsigned int value, virtual EventPropagation filterActions(PlayerAction action, int deviceID, const unsigned int value,
Input::InputType type, int playerId) { return EVENT_LET; } Input::InputType type, int playerId) { return EVENT_LET; }
}; };

View File

@ -247,15 +247,23 @@ int ListWidget::getItemID(const std::string internalName) const
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void ListWidget::markItemRed(const int id) void ListWidget::markItemRed(const int id, bool red)
{ {
// May only be called AFTER this widget has been add()ed // May only be called AFTER this widget has been add()ed
assert(m_element != NULL); assert(m_element != NULL);
IGUIListBox* irritem = getIrrlichtElement<IGUIListBox>(); IGUIListBox* irritem = getIrrlichtElement<IGUIListBox>();
if (red)
{
irritem->setItemOverrideColor( id, EGUI_LBC_TEXT, video::SColor(255,255,0,0) ); irritem->setItemOverrideColor( id, EGUI_LBC_TEXT, video::SColor(255,255,0,0) );
irritem->setItemOverrideColor( id, EGUI_LBC_TEXT_HIGHLIGHT, video::SColor(255,255,0,0) ); irritem->setItemOverrideColor( id, EGUI_LBC_TEXT_HIGHLIGHT, video::SColor(255,255,0,0) );
}
else
{
irritem->setItemOverrideColor( id, EGUI_LBC_TEXT, video::SColor(255,0,0,0) );
irritem->setItemOverrideColor( id, EGUI_LBC_TEXT_HIGHLIGHT, video::SColor(255,255,255,255) );
}
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -149,17 +149,17 @@ namespace GUIEngine
* \brief Make an item red to mark an error, for instance * \brief Make an item red to mark an error, for instance
* \pre may only be called after the widget has been added to the screen with add() * \pre may only be called after the widget has been added to the screen with add()
*/ */
void markItemRed(const int id); void markItemRed(const int id, bool red=true);
/** /**
* \brief Make an item red to mark an error, for instance * \brief Make an item red to mark an error, for instance
* \pre may only be called after the widget has been added to the screen with add() * \pre may only be called after the widget has been added to the screen with add()
*/ */
void markItemRed(const std::string internalName) void markItemRed(const std::string internalName, bool red=true)
{ {
const int id = getItemID(internalName); const int id = getItemID(internalName);
assert(id != -1); assert(id != -1);
markItemRed( id ); markItemRed( id, red );
} }
}; };
} }

View File

@ -552,7 +552,7 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID, int button
} }
// all is good, pass the translated input event on to the event handler // all is good, pass the translated input event on to the event handler
GUIEngine::EventHandler::get()->processGUIAction(action, abs(value), type, playerID); GUIEngine::EventHandler::get()->processGUIAction(action, deviceID, abs(value), type, playerID);
} }
} }
} }

View File

@ -244,3 +244,44 @@ void OptionsScreenInput::unloaded()
m_icon_bank = NULL; m_icon_bank = NULL;
} // unloaded } // unloaded
// -----------------------------------------------------------------------------
EventPropagation OptionsScreenInput::filterActions(PlayerAction action, int deviceID,
const unsigned int value,
Input::InputType type, int playerId)
{
/*
if (type == Input::IT_STICKMOTION || type == Input::IT_STICKBUTTON)
{
GamePadDevice* gamepad = input_manager->getDeviceList()->getGamePadFromIrrID(deviceID);
if (gamepad != NULL && gamepad->getConfiguration() != NULL)
{
//printf("'%s'\n", gamepad->getConfiguration()->getName().c_str());
ListWidget* devices = this->getWidget<ListWidget>("devices");
assert(devices != NULL);
std::string internal_name;
const int gpad_config_count = input_manager->getDeviceList()->getGamePadConfigAmount();
for (int i = 0; i < gpad_config_count; i++)
{
GamepadConfig *config = input_manager->getDeviceList()->getGamepadConfig(i);
// Don't display the configuration if a matching device is not available
if (config == gamepad->getConfiguration())
{
std::ostringstream gpname;
gpname << "gamepad" << i;
internal_name = gpname.str();
}
}
if (internal_name.size() > 0)
{
devices->markItemRed(internal_name.c_str(), value > Input::MAX_VALUE*2/3);
}
}
}
*/
return EVENT_LET;
}

View File

@ -65,6 +65,12 @@ public:
*/ */
void rebuildDeviceList(); void rebuildDeviceList();
/** \brief Override callback from base class */
virtual GUIEngine::EventPropagation filterActions(PlayerAction action,
int deviceID,
const unsigned int value,
Input::InputType type,
int playerId);
}; };
#endif #endif

View File

@ -351,6 +351,7 @@ bool RaceResultGUI::onEscapePressed()
* here and trigger the next phase. * here and trigger the next phase.
*/ */
GUIEngine::EventPropagation RaceResultGUI::filterActions(PlayerAction action, GUIEngine::EventPropagation RaceResultGUI::filterActions(PlayerAction action,
int deviceID,
const unsigned int value, const unsigned int value,
Input::InputType type, Input::InputType type,
int playerId) int playerId)

View File

@ -178,7 +178,7 @@ public:
virtual void tearDown(); virtual void tearDown();
virtual bool onEscapePressed(); virtual bool onEscapePressed();
virtual GUIEngine::EventPropagation virtual GUIEngine::EventPropagation
filterActions(PlayerAction action, const unsigned int value, filterActions(PlayerAction action, int deviceID, const unsigned int value,
Input::InputType type, int playerId); Input::InputType type, int playerId);
void eventCallback(GUIEngine::Widget* widget, const std::string& name, void eventCallback(GUIEngine::Widget* widget, const std::string& name,
const int playerID); const int playerID);