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

@ -188,11 +188,18 @@ void EventHandler::processAction(const int action, const unsigned int value, Inp
/* Find topmost parent. Stop looping if a widget event handler's is itself, to not fall /* 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 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. )
while(widget_to_call->m_event_handler != NULL && widget_to_call->m_event_handler != widget_to_call) On the way, also notify everyone in the chain of the left press. */
widget_to_call = widget_to_call->m_event_handler; 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]);
if(widget_to_call->leftPressed()) widget_to_call = widget_to_call->m_event_handler;
}
if (widget_to_call->leftPressed())
transmitEvent(w, w->m_properties[PROP_ID]); transmitEvent(w, w->m_properties[PROP_ID]);
} }
break; break;
@ -207,9 +214,15 @@ void EventHandler::processAction(const int action, const unsigned int value, Inp
Widget* widget_to_call = w; Widget* widget_to_call = w;
/* Find topmost parent. Stop looping if a widget event handler's is itself, to not fall /* 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 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) 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; widget_to_call = widget_to_call->m_event_handler;
}
if(widget_to_call->rightPressed()) if(widget_to_call->rightPressed())
transmitEvent(widget_to_call, w->m_properties[PROP_ID]); transmitEvent(widget_to_call, w->m_properties[PROP_ID]);

View File

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

View File

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

View File

@ -295,11 +295,7 @@ namespace KartSelectionScreen
virtual bool transmitEvent(Widget* w, std::string& originator) virtual bool transmitEvent(Widget* w, std::string& originator)
{ {
if (w->m_event_handler != NULL && w->m_event_handler != this) std::cout << "= kart selection :: transmitEvent " << originator << "=\n";
{
if (!w->m_event_handler->transmitEvent(w, originator)) return false;
}
Widget* topmost = w; Widget* topmost = w;
/* Find topmost parent. Stop looping if a widget event handler's is itself, to not fall /* 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 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) 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; topmost = topmost->m_event_handler;
std::string name = topmost->m_properties[PROP_ID]; std::string name = topmost->m_properties[PROP_ID];
@ -314,6 +313,11 @@ namespace KartSelectionScreen
if (name == spinnerID) if (name == spinnerID)
{ {
m_associatedPlayer->setPlayerProfile( UserConfigParams::m_all_players.get(playerName->getValue()) ); 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 return false; // do not continue propagating the event
} }