Fixed player identity not changeable by improving event handling in the GUI

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3793 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-08-02 18:53:50 +00:00
parent 8623a4a49a
commit 1653ae14d7
4 changed files with 33 additions and 16 deletions

View File

@ -180,19 +180,26 @@ void EventHandler::processAction(const int action, const unsigned int value, Inp
{
IGUIElement *el = GUIEngine::getGUIEnv()->getFocus();
if(el == NULL) break;
Widget* w = GUIEngine::getCurrentScreen()->getWidget( el->getID() );
if(w == NULL) break;
Widget* widget_to_call = w;
/* Find topmost parent. Stop looping if a widget event handler's is itself, to not fall
in an infinite loop (this can happen e.g. in checkboxes, where they need to be
notified of clicks onto themselves so they can toggle their state. ) */
while(widget_to_call->m_event_handler != NULL && widget_to_call->m_event_handler != widget_to_call)
notified of clicks onto themselves so they can toggle their state. )
On the way, also notify everyone in the chain of the left press. */
while (widget_to_call->m_event_handler != NULL && widget_to_call->m_event_handler != widget_to_call)
{
if (widget_to_call->leftPressed())
transmitEvent(w, w->m_properties[PROP_ID]);
widget_to_call = widget_to_call->m_event_handler;
}
if(widget_to_call->leftPressed())
if (widget_to_call->leftPressed())
transmitEvent(w, w->m_properties[PROP_ID]);
}
break;
@ -207,9 +214,15 @@ void EventHandler::processAction(const int action, const unsigned int value, Inp
Widget* widget_to_call = w;
/* Find topmost parent. Stop looping if a widget event handler's is itself, to not fall
in an infinite loop (this can happen e.g. in checkboxes, where they need to be
notified of clicks onto themselves so they can toggle their state. ) */
notified of clicks onto themselves so they can toggle their state. )
On the way, also notify everyone in the chain of the right press */
while(widget_to_call->m_event_handler != NULL && widget_to_call->m_event_handler != widget_to_call)
{
if(widget_to_call->rightPressed())
transmitEvent(widget_to_call, w->m_properties[PROP_ID]);
widget_to_call = widget_to_call->m_event_handler;
}
if(widget_to_call->rightPressed())
transmitEvent(widget_to_call, w->m_properties[PROP_ID]);

View File

@ -171,8 +171,6 @@ bool RibbonGridWidget::rightPressed()
RibbonWidget* w = getSelectedRibbon();
if(w != NULL)
{
w->rightPressed();
updateLabel();
propagateSelection();
}
@ -193,8 +191,6 @@ bool RibbonGridWidget::leftPressed()
RibbonWidget* w = getSelectedRibbon();
if(w != NULL)
{
w->leftPressed();
updateLabel();
propagateSelection();
}

View File

@ -29,7 +29,6 @@ SpinnerWidget::SpinnerWidget(const bool gauge)
{
m_gauge = gauge;
m_type = WTYPE_SPINNER;
}
void SpinnerWidget::add()
@ -100,6 +99,7 @@ void SpinnerWidget::add()
m_children[1].m_element = subbtn;
m_children[1].m_type = WTYPE_ICON_BUTTON;
m_children[1].id = subbtn->getID();
m_children[1].m_event_handler = this;
subbtn->setUseAlphaChannel(true);
subbtn->setImage(texture);
@ -113,6 +113,7 @@ void SpinnerWidget::add()
btn, getNewNoFocusID());
m_children[1].m_element = label;
m_children[1].m_type = WTYPE_LABEL;
m_children[1].m_event_handler = this;
m_children[1].id = label->getID();
label->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
label->setTabStop(false);
@ -129,7 +130,10 @@ void SpinnerWidget::add()
m_children[2].m_event_handler = this;
m_children[2].m_properties[PROP_ID] = "right";
m_children[2].id = m_children[2].m_element->getID();
std::cout << "Adding spinner with m_event_handler=" << m_event_handler << std::endl;
}
void SpinnerWidget::move(const int x, const int y, const int w, const int h)
{
Widget::move(x, y, w, h);

View File

@ -295,11 +295,7 @@ namespace KartSelectionScreen
virtual bool transmitEvent(Widget* w, std::string& originator)
{
if (w->m_event_handler != NULL && w->m_event_handler != this)
{
if (!w->m_event_handler->transmitEvent(w, originator)) return false;
}
std::cout << "= kart selection :: transmitEvent " << originator << "=\n";
Widget* topmost = w;
/* Find topmost parent. Stop looping if a widget event handler's is itself, to not fall
in an infinite loop (this can happen e.g. in checkboxes, where they need to be
@ -307,6 +303,9 @@ namespace KartSelectionScreen
*/
while(topmost->m_event_handler != NULL && topmost->m_event_handler != topmost)
{
// transmit events to all listeners in the chain
std::cout << "transmitting event to widget " << topmost->m_type << std::endl;
if (!topmost->transmitEvent(w, originator)) return false;
topmost = topmost->m_event_handler;
std::string name = topmost->m_properties[PROP_ID];
@ -314,6 +313,11 @@ namespace KartSelectionScreen
if (name == spinnerID)
{
m_associatedPlayer->setPlayerProfile( UserConfigParams::m_all_players.get(playerName->getValue()) );
// transmit events to all listeners in the chain
std::cout << "transmitting event to widget " << topmost->m_type << std::endl;
if (!topmost->transmitEvent(w, originator)) return false;
return false; // do not continue propagating the event
}