diff --git a/src/guiengine/event_handler.cpp b/src/guiengine/event_handler.cpp index 30ac80f76..3a22b1f62 100644 --- a/src/guiengine/event_handler.cpp +++ b/src/guiengine/event_handler.cpp @@ -192,7 +192,7 @@ void EventHandler::processGUIAction(const PlayerAction action, { Widget* w = GUIEngine::getFocusForPlayer(playerID); if (w == NULL) break; - + // FIXME : consider returned value? onWidgetActivated( w, playerID ); } @@ -475,7 +475,7 @@ EventPropagation EventHandler::onWidgetActivated(GUIEngine::Widget* w, const int } //std::cout << "**** widget activated : " << w->m_properties[PROP_ID].c_str() << " ****" << std::endl; - + Widget* parent = w->m_event_handler; if (w->m_event_handler != NULL) { @@ -509,7 +509,10 @@ EventPropagation EventHandler::onWidgetActivated(GUIEngine::Widget* w, const int } else { - sendEventToUser(w, w->m_properties[PROP_ID], playerID); + if (w->transmitEvent(w, w->m_properties[PROP_ID], playerID) == EVENT_LET) + { + sendEventToUser(w, w->m_properties[PROP_ID], playerID); + } } return EVENT_BLOCK; diff --git a/src/guiengine/widgets/spinner_widget.cpp b/src/guiengine/widgets/spinner_widget.cpp index f6fdb9928..ce32e3e06 100644 --- a/src/guiengine/widgets/spinner_widget.cpp +++ b/src/guiengine/widgets/spinner_widget.cpp @@ -34,6 +34,8 @@ SpinnerWidget::SpinnerWidget(const bool gauge) : Widget(WTYPE_SPINNER) { m_gauge = gauge; + m_listener = NULL; + m_check_inside_me = true; //FIXME: not sure this is necessary m_supports_multiplayer = true; @@ -135,6 +137,7 @@ void SpinnerWidget::add() m_children[1].m_element = subbtn; m_children[1].m_id = subbtn->getID(); m_children[1].m_event_handler = this; + m_children[1].m_properties[PROP_ID] = "spinnerbody"; subbtn->setUseAlphaChannel(true); subbtn->setImage(texture); @@ -149,6 +152,7 @@ void SpinnerWidget::add() m_children[1].m_element = label; m_children[1].m_event_handler = this; m_children[1].m_id = label->getID(); + m_children[1].m_properties[PROP_ID] = "spinnerbody"; label->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); label->setTabStop(false); label->setNotClipped(true); @@ -260,9 +264,23 @@ EventPropagation SpinnerWidget::transmitEvent(Widget* w, std::string& originator { // if widget is deactivated, do nothing if (m_deactivated) return EVENT_BLOCK; + + if (originator == "left") + { + leftPressed(playerID); + } + else if (originator == "right") + { + rightPressed(playerID); + } + else if (originator == "spinnerbody" || originator == m_properties[PROP_ID]) + { + if (m_listener != NULL) + { + m_listener->onSpinnerConfirmed(); + } + } - if (originator == "left") leftPressed(playerID); - else if (originator == "right") rightPressed(playerID); this->setFocusForPlayer( playerID ); return EVENT_LET; diff --git a/src/guiengine/widgets/spinner_widget.hpp b/src/guiengine/widgets/spinner_widget.hpp index 739ebc2ec..a0c79b921 100644 --- a/src/guiengine/widgets/spinner_widget.hpp +++ b/src/guiengine/widgets/spinner_widget.hpp @@ -27,11 +27,26 @@ namespace GUIEngine { + /** \brief A spinner or gauge widget (to select numbers / percentages). * \ingroup widgets */ class SpinnerWidget : public Widget { + public: + class ISpinnerConfirmListener + { + public: + virtual ~ISpinnerConfirmListener() {} + + /** \brief Invoked when the spinner is selected and "fire" is pressed */ + virtual void onSpinnerConfirmed() = 0; + }; + + protected: + + ISpinnerConfirmListener* m_listener; + int m_value, m_min, m_max; /** If each value the spinner can take has an associated text, this vector will be non-empty */ @@ -78,6 +93,7 @@ namespace GUIEngine void addLabel(irr::core::stringw label); void clearLabels(); + void setListener(ISpinnerConfirmListener* listener) { m_listener = listener; } /** \brief implement method from base class Widget */ virtual void add(); diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 86537f05f..7f52e30d0 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -173,7 +173,7 @@ public: // ----------------------------------------------------------------------------- /** A widget representing the kart selection for a player (i.e. the player's number, name, the kart view, the kart's name) */ -class PlayerKartWidget : public Widget +class PlayerKartWidget : public Widget, public SpinnerWidget::ISpinnerConfirmListener { /** Whether this player confirmed their selection */ bool m_ready; @@ -364,7 +364,10 @@ public: m_player_ID_label->getIrrlichtElement()->remove(); if (m_player_ident_spinner != NULL && m_player_ident_spinner->getIrrlichtElement() != NULL) + { + m_player_ident_spinner->setListener(NULL); m_player_ident_spinner->getIrrlichtElement()->remove(); + } if (m_model_view->getIrrlichtElement() != NULL) m_model_view->getIrrlichtElement()->remove(); @@ -446,6 +449,7 @@ public: m_player_ident_spinner->add(); m_player_ident_spinner->getIrrlichtElement()->setTabStop(false); + m_player_ident_spinner->setListener(this); m_model_view->add(); m_kart_name->add(); @@ -699,6 +703,15 @@ public: assert(m_magic_number == 0x33445566); return m_kartInternalName; } + + // ------------------------------------------------------------------------- + + /** \brief Event callback from ISpinnerConfirmListener */ + virtual void onSpinnerConfirmed() + { + printf("onSpinnerConfirmed\n"); + KartSelectionScreen::getInstance()->playerConfirm(m_playerID); + } }; /** Small utility function that returns whether the two given players chose the same kart. @@ -1187,6 +1200,69 @@ void KartSelectionScreen::onUpdate(float delta, irr::video::IVideoDriver*) } } +void KartSelectionScreen::playerConfirm(const int playerID) +{ + DynamicRibbonWidget* w = getWidget("karts"); + assert(w != NULL); + const std::string selection = w->getSelectionIDString(playerID); + if (selection == "locked") + { + unlock_manager->playLockSound(); + return; + } + + // make sure no other player selected the same identity or kart + const int amount = m_kart_widgets.size(); + for (int n=0; ngetProfile()->isGuestAccount() && + m_kart_widgets[n].getAssociatedPlayer()->getProfile() == + m_kart_widgets[playerID].getAssociatedPlayer()->getProfile(); + const bool kart_conflict = sameKart(m_kart_widgets[n], m_kart_widgets[playerID]); + + if (player_ready && (ident_conflict || kart_conflict)) + { + printf("\n***\n*** You can't select this identity or kart, someone already took it!! ***\n***\n\n"); + + sfx_manager->quickSound( "use_anvil" ); + return; + } + + // If two PlayerKart entries are associated to the same ActivePlayer, something went wrong + assert(m_kart_widgets[n].getAssociatedPlayer() != m_kart_widgets[playerID].getAssociatedPlayer()); + } + + // Mark this player as ready to start + m_kart_widgets[playerID].markAsReady(); + m_player_confirmed = true; + + RibbonWidget* tabs = getWidget("kartgroups"); + assert( tabs != NULL ); + tabs->setDeactivated(); + + // validate choices to notify player of duplicates + const bool names_ok = validateIdentChoices(); + const bool karts_ok = validateKartChoices(); + + if (!names_ok || !karts_ok) return; + + // check if all players are ready + bool allPlayersReady = true; + for (int n=0; n("karts"); - assert(w != NULL); - const std::string selection = w->getSelectionIDString(playerID); - if (selection == "locked") - { - unlock_manager->playLockSound(); - return; - } - - // make sure no other player selected the same identity or kart - const int amount = m_kart_widgets.size(); - for (int n=0; ngetProfile()->isGuestAccount() && - m_kart_widgets[n].getAssociatedPlayer()->getProfile() == - m_kart_widgets[playerID].getAssociatedPlayer()->getProfile(); - const bool kart_conflict = sameKart(m_kart_widgets[n], m_kart_widgets[playerID]); - - if (player_ready && (ident_conflict || kart_conflict)) - { - printf("\n***\n*** You can't select this identity or kart, someone already took it!! ***\n***\n\n"); - - sfx_manager->quickSound( "use_anvil" ); - return; - } - - // If two PlayerKart entries are associated to the same ActivePlayer, something went wrong - assert(m_kart_widgets[n].getAssociatedPlayer() != m_kart_widgets[playerID].getAssociatedPlayer()); - } - - // Mark this player as ready to start - m_kart_widgets[playerID].markAsReady(); - m_player_confirmed = true; - - RibbonWidget* tabs = getWidget("kartgroups"); - assert( tabs != NULL ); - tabs->setDeactivated(); - - // validate choices to notify player of duplicates - const bool names_ok = validateIdentChoices(); - const bool karts_ok = validateKartChoices(); - - if (!names_ok || !karts_ok) return; - - // check if all players are ready - bool allPlayersReady = true; - for (int n=0; n