May now confirm kart selection by pressing fire on player name (in case someone selects a kart first, their identity second, this is more natural)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6192 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
5eb4aaf4ef
commit
ddc2a3dab2
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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<DynamicRibbonWidget>("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; n<amount; n++)
|
||||
{
|
||||
if (n == playerID) continue; // don't check a kart against itself
|
||||
|
||||
const bool player_ready = m_kart_widgets[n].isReady();
|
||||
const bool ident_conflict = !m_kart_widgets[n].getAssociatedPlayer()->getProfile()->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<RibbonWidget>("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<amount; n++)
|
||||
{
|
||||
if (!m_kart_widgets[n].isReady())
|
||||
{
|
||||
allPlayersReady = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allPlayersReady) allPlayersDone();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/**
|
||||
* Callback handling events from the kart selection menu
|
||||
@ -1244,65 +1320,7 @@ void KartSelectionScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
}
|
||||
else if (name == "karts")
|
||||
{
|
||||
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("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; n<amount; n++)
|
||||
{
|
||||
if (n == playerID) continue; // don't check a kart against itself
|
||||
|
||||
const bool player_ready = m_kart_widgets[n].isReady();
|
||||
const bool ident_conflict = !m_kart_widgets[n].getAssociatedPlayer()->getProfile()->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<RibbonWidget>("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<amount; n++)
|
||||
{
|
||||
if (!m_kart_widgets[n].isReady())
|
||||
{
|
||||
allPlayersReady = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allPlayersReady) allPlayersDone();
|
||||
playerConfirm(playerID);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -75,6 +75,8 @@ class KartSelectionScreen : public GUIEngine::Screen, public GUIEngine::ScreenSi
|
||||
/** Fill the ribbon with the karts from the currently selected group */
|
||||
void setKartsFromCurrentGroup();
|
||||
|
||||
void playerConfirm(const int playerID);
|
||||
|
||||
public:
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
|
Loading…
Reference in New Issue
Block a user