More work in the multiplayer kart selection screen. Now all players can reach their name (but maybe not return from there :P)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4050 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
64958b0edf
commit
e0d66bf543
@ -115,11 +115,11 @@ bool EventHandler::onGUIEvent(const SEvent& event)
|
||||
*/
|
||||
case EGET_ELEMENT_FOCUSED:
|
||||
{
|
||||
Widget* el = GUIEngine::getWidget(id);
|
||||
if (el == NULL) break;
|
||||
Widget* w = GUIEngine::getWidget(id);
|
||||
if (w == NULL) break;
|
||||
|
||||
// FIXME: don't hardcode player 0
|
||||
el->focused(0);
|
||||
return w->focused(0);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -115,7 +115,15 @@ void Widget::setFocusForPlayer(const int playerID)
|
||||
m_player_focus[playerID] = true;
|
||||
GUIEngine::g_focus_for_player[playerID] = this;
|
||||
|
||||
this->focused(playerID);
|
||||
// Player 0 uses irrLicht focus - FIXME : unify focus handling to remove this branching
|
||||
if (playerID == 0)
|
||||
{
|
||||
requestFocus();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->focused(playerID);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::unsetFocusForPlayer(const int playerID)
|
||||
|
@ -128,8 +128,8 @@ namespace GUIEngine
|
||||
Returns 'true' if main event handler should be notified of a change. */
|
||||
virtual bool mouseHovered(Widget* child) { return false; }
|
||||
|
||||
/** override in children if you need to know when the widget is focused */
|
||||
virtual void focused(const int playerID) { isWithinATextBox = false; }
|
||||
/** override in children if you need to know when the widget is focused. return whether to block event */
|
||||
virtual bool focused(const int playerID) { isWithinATextBox = false; return false; }
|
||||
|
||||
/**
|
||||
* The XML loader stored coords in their raw string form inside this widget.
|
||||
|
@ -416,7 +416,7 @@ bool DynamicRibbonWidget::mouseHovered(Widget* child)
|
||||
return false;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void DynamicRibbonWidget::focused(const int playerID)
|
||||
bool DynamicRibbonWidget::focused(const int playerID)
|
||||
{
|
||||
Widget::focused(playerID);
|
||||
updateLabel();
|
||||
@ -427,6 +427,8 @@ void DynamicRibbonWidget::focused(const int playerID)
|
||||
m_hover_listeners[n].onSelectionChanged(this, getSelectedRibbon(playerID)->getSelectionIDString(playerID),
|
||||
getSelectedRibbon(playerID)->getSelectionText(playerID), playerID);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void DynamicRibbonWidget::onRowChange(RibbonWidget* row, const int playerID)
|
||||
|
@ -124,7 +124,7 @@ namespace GUIEngine
|
||||
void propagateSelection();
|
||||
|
||||
/** Callback called widget is focused */
|
||||
void focused(const int playerID);
|
||||
bool focused(const int playerID);
|
||||
|
||||
/** Removes all previously added contents icons, and re-adds them (calculating the new amount) */
|
||||
void setSubElements();
|
||||
|
@ -254,11 +254,11 @@ bool RibbonWidget::leftPressed(const int playerID)
|
||||
return m_ribbon_type != RIBBON_TOOLBAR;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void RibbonWidget::focused(const int playerID)
|
||||
bool RibbonWidget::focused(const int playerID)
|
||||
{
|
||||
Widget::focused(playerID);
|
||||
|
||||
if (m_children.size() < 1) return; // empty ribbon
|
||||
if (m_children.size() < 1) return false; // empty ribbon
|
||||
|
||||
if (m_focus == NULL && m_selection[playerID] != -1)
|
||||
{
|
||||
@ -272,6 +272,8 @@ void RibbonWidget::focused(const int playerID)
|
||||
// FIXME : unclean, children ribbons shouldn't need to know about their parent
|
||||
((DynamicRibbonWidget*)m_event_handler)->onRowChange( this, playerID );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
bool RibbonWidget::mouseHovered(Widget* child)
|
||||
|
@ -60,7 +60,7 @@ namespace GUIEngine
|
||||
bool leftPressed(const int playerID=0);
|
||||
bool mouseHovered(Widget* child);
|
||||
bool transmitEvent(Widget* w, std::string& originator, const int playerID=0);
|
||||
void focused(const int playerID);
|
||||
bool focused(const int playerID);
|
||||
|
||||
ptr_vector<IGUIStaticText, REF> m_labels;
|
||||
|
||||
|
@ -43,7 +43,7 @@ namespace GUIEngine
|
||||
void add();
|
||||
void addItem(const char* item);
|
||||
|
||||
virtual void focused(const int playerID) { isWithinATextBox = true; }
|
||||
virtual bool focused(const int playerID) { isWithinATextBox = true; return false; }
|
||||
|
||||
core::stringw getText() const;
|
||||
};
|
||||
|
@ -48,7 +48,6 @@ namespace KartSelectionScreen
|
||||
class PlayerKartWidget;
|
||||
|
||||
// ref only since we're adding them to a Screen, and the Screen will take ownership of these widgets
|
||||
// FIXME : delete these objects when leaving the screen (especially when using escape)
|
||||
ptr_vector<PlayerKartWidget, REF> g_player_karts;
|
||||
|
||||
#if 0
|
||||
@ -56,13 +55,30 @@ namespace KartSelectionScreen
|
||||
#pragma mark PlayerKartWidget
|
||||
#endif
|
||||
|
||||
class PlayerNameSpinner : public SpinnerWidget
|
||||
{
|
||||
int playerID;
|
||||
|
||||
virtual bool focused(const int playerID) ;
|
||||
|
||||
public:
|
||||
PlayerNameSpinner(const int playerID)
|
||||
{
|
||||
PlayerNameSpinner::playerID = playerID;
|
||||
}
|
||||
void setID(const int playerID)
|
||||
{
|
||||
PlayerNameSpinner::playerID = playerID;
|
||||
}
|
||||
};
|
||||
|
||||
class PlayerKartWidget : public Widget
|
||||
{
|
||||
float x_speed, y_speed, w_speed, h_speed;
|
||||
|
||||
public:
|
||||
LabelWidget* playerIDLabel;
|
||||
SpinnerWidget* playerName;
|
||||
PlayerNameSpinner* playerName;
|
||||
ModelViewWidget* modelView;
|
||||
LabelWidget* kartName;
|
||||
|
||||
@ -126,7 +142,7 @@ namespace KartSelectionScreen
|
||||
//playerID->setParent(this);
|
||||
m_children.push_back(playerIDLabel);
|
||||
|
||||
playerName = new SpinnerWidget();
|
||||
playerName = new PlayerNameSpinner(playerID);
|
||||
playerName->x = player_name_x;
|
||||
playerName->y = player_name_y;
|
||||
playerName->w = player_name_w;
|
||||
@ -209,6 +225,7 @@ namespace KartSelectionScreen
|
||||
irr::core::stringw newLabel = StringUtils::insertValues(_("Player %i (%s)"), playerID + 1, deviceName.c_str());
|
||||
playerIDLabel->setText( newLabel );
|
||||
playerIDLabel->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_label", playerID);
|
||||
playerName->setID(playerID);
|
||||
}
|
||||
|
||||
virtual void add()
|
||||
@ -485,7 +502,7 @@ bool playerJoin(InputDevice* device, bool firstPlayer)
|
||||
// FIXME : player ID needs to be synced with active player list
|
||||
PlayerKartWidget* newPlayer;
|
||||
if (firstPlayer)
|
||||
newPlayer = new PlayerKartWidget(aplayer, &rightarea, g_player_karts.size(), rightarea.m_reserved_id);
|
||||
newPlayer = new PlayerKartWidget(aplayer, &rightarea, g_player_karts.size());//, rightarea.m_reserved_id);
|
||||
else
|
||||
newPlayer = new PlayerKartWidget(aplayer, &rightarea, g_player_karts.size());
|
||||
|
||||
@ -795,4 +812,46 @@ void renumberKarts()
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
// FIXME : clean this mess, this file should not contain so many classes
|
||||
bool PlayerNameSpinner::focused(const int playerID)
|
||||
{
|
||||
std::cout << "Player name spinner " << this->playerID << " focused by " << playerID << std::endl;
|
||||
|
||||
// since this screen is multiplayer, redirect focus to the right widget
|
||||
if (this->playerID != playerID)
|
||||
{
|
||||
const int amount = g_player_karts.size();
|
||||
for (int n=0; n<amount; n++)
|
||||
{
|
||||
if (g_player_karts[n].playerID == playerID)
|
||||
{
|
||||
std::cout << "--> Redirecting focus for player " << playerID << " from spinner " << this->playerID <<
|
||||
" (ID " << m_element->getID() <<
|
||||
") to spinner " << n << " (ID " << g_player_karts[n].playerName->m_element->getID() << ")" << std::endl;
|
||||
|
||||
int IDbefore = GUIEngine::getGUIEnv()->getFocus()->getID();
|
||||
|
||||
g_player_karts[n].playerName->setFocusForPlayer(playerID);
|
||||
|
||||
int IDafter = GUIEngine::getGUIEnv()->getFocus()->getID();
|
||||
|
||||
std::cout << "--> ID before : " << IDbefore << "; ID after : " << IDafter << std::endl;
|
||||
|
||||
return true; // block event
|
||||
}
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "--> right spinner nothing to do\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user