From f89cacbf5f0cfcb53af79da9030aa446e1c26512 Mon Sep 17 00:00:00 2001 From: auria Date: Fri, 28 Aug 2009 22:58:32 +0000 Subject: [PATCH] Improved vertical navigation in kart selection screen for players > 0 git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3943 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/guiengine/event_handler.cpp | 5 +++-- src/guiengine/widget.cpp | 2 ++ src/guiengine/widget.hpp | 2 +- src/guiengine/widgets/ribbon_grid_widget.cpp | 10 +++------- src/guiengine/widgets/ribbon_grid_widget.hpp | 4 ++-- src/guiengine/widgets/ribbon_widget.cpp | 10 +++++----- src/guiengine/widgets/ribbon_widget.hpp | 2 +- src/guiengine/widgets/text_box_widget.hpp | 2 +- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/guiengine/event_handler.cpp b/src/guiengine/event_handler.cpp index c420dfc5c..c475e0d84 100644 --- a/src/guiengine/event_handler.cpp +++ b/src/guiengine/event_handler.cpp @@ -116,9 +116,10 @@ bool EventHandler::onGUIEvent(const SEvent& event) case EGET_ELEMENT_FOCUSED: { Widget* el = GUIEngine::getCurrentScreen()->getWidget(id); - if(el == NULL) break; + if (el == NULL) break; - el->focused(); + // FIXME: don't hardcode player 0 + el->focused(0); break; } diff --git a/src/guiengine/widget.cpp b/src/guiengine/widget.cpp index 6a85ab64c..ebaa3d8a6 100644 --- a/src/guiengine/widget.cpp +++ b/src/guiengine/widget.cpp @@ -110,6 +110,8 @@ void Widget::setFocusForPlayer(const int playerID) m_player_focus[playerID] = true; GUIEngine::g_focus_for_player[playerID] = this; + + this->focused(playerID); } void Widget::unsetFocusForPlayer(const int playerID) diff --git a/src/guiengine/widget.hpp b/src/guiengine/widget.hpp index 66e7aacdf..c994dc0e2 100644 --- a/src/guiengine/widget.hpp +++ b/src/guiengine/widget.hpp @@ -128,7 +128,7 @@ namespace GUIEngine virtual bool mouseHovered(Widget* child) { return false; } /** override in children if you need to know when the widget is focused */ - virtual void focused() { isWithinATextBox = false; } + virtual void focused(const int playerID) { isWithinATextBox = false; } /** * The XML loader stored coords in their raw string form inside this widget. diff --git a/src/guiengine/widgets/ribbon_grid_widget.cpp b/src/guiengine/widgets/ribbon_grid_widget.cpp index d31c80749..df4960c62 100644 --- a/src/guiengine/widgets/ribbon_grid_widget.cpp +++ b/src/guiengine/widgets/ribbon_grid_widget.cpp @@ -413,29 +413,25 @@ bool RibbonGridWidget::mouseHovered(Widget* child) return false; } // ----------------------------------------------------------------------------- -void RibbonGridWidget::focused() +void RibbonGridWidget::focused(const int playerID) { - Widget::focused(); + Widget::focused(playerID); updateLabel(); const int listenerAmount = m_hover_listeners.size(); for(int n=0; ngetSelectionIDString(playerID), playerID); } } // ----------------------------------------------------------------------------- -void RibbonGridWidget::onRowChange(RibbonWidget* row) +void RibbonGridWidget::onRowChange(RibbonWidget* row, const int playerID) { updateLabel(row); const int listenerAmount = m_hover_listeners.size(); for (int n=0; ngetSelectionIDString(playerID), playerID); } } diff --git a/src/guiengine/widgets/ribbon_grid_widget.hpp b/src/guiengine/widgets/ribbon_grid_widget.hpp index d47544e24..1c0115a79 100644 --- a/src/guiengine/widgets/ribbon_grid_widget.hpp +++ b/src/guiengine/widgets/ribbon_grid_widget.hpp @@ -121,7 +121,7 @@ namespace GUIEngine void propagateSelection(); /** Callback called widget is focused */ - void focused(); + void focused(const int playerID); bool transmitEvent(Widget* w, std::string& originator, const int playerID); @@ -135,7 +135,7 @@ namespace GUIEngine int m_selected_item[32]; // FIXME: 32 is arbitrary, settle for a max number of players /** Callbacks */ - void onRowChange(RibbonWidget* row); + void onRowChange(RibbonWidget* row, const int playerID); void add(); bool mouseHovered(Widget* child); diff --git a/src/guiengine/widgets/ribbon_widget.cpp b/src/guiengine/widgets/ribbon_widget.cpp index 99bdd9b12..ab2e20ccb 100644 --- a/src/guiengine/widgets/ribbon_widget.cpp +++ b/src/guiengine/widgets/ribbon_widget.cpp @@ -254,20 +254,20 @@ bool RibbonWidget::leftPressed(const int playerID) return m_ribbon_type != RIBBON_TOOLBAR; } // ----------------------------------------------------------------------------- -void RibbonWidget::focused() +void RibbonWidget::focused(const int playerID) { - Widget::focused(); + Widget::focused(playerID); if (m_children.size() < 1) return; // empty ribbon - if (m_focus == NULL) m_focus = m_children.get(m_selection[0]); // FIXME : don't hardcode player 0 here + if (m_focus == NULL) m_focus = m_children.get(m_selection[playerID]); if (m_event_handler != NULL) { - GUIEngine::getGUIEnv()->setFocus(m_focus->m_element); + if (playerID == 0) GUIEngine::getGUIEnv()->setFocus(m_focus->m_element); // FIXME : unclean, children ribbons shouldn't need to know about their parent - ((RibbonGridWidget*)m_event_handler)->onRowChange( this ); + ((RibbonGridWidget*)m_event_handler)->onRowChange( this, playerID ); } } // ----------------------------------------------------------------------------- diff --git a/src/guiengine/widgets/ribbon_widget.hpp b/src/guiengine/widgets/ribbon_widget.hpp index d72a6a291..a95085f0b 100644 --- a/src/guiengine/widgets/ribbon_widget.hpp +++ b/src/guiengine/widgets/ribbon_widget.hpp @@ -62,7 +62,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(); + void focused(const int playerID); ptr_vector m_labels; diff --git a/src/guiengine/widgets/text_box_widget.hpp b/src/guiengine/widgets/text_box_widget.hpp index 380f85088..68c72ef4b 100644 --- a/src/guiengine/widgets/text_box_widget.hpp +++ b/src/guiengine/widgets/text_box_widget.hpp @@ -43,7 +43,7 @@ namespace GUIEngine void add(); void addItem(const char* item); - virtual void focused() { isWithinATextBox = true; } + virtual void focused(const int playerID) { isWithinATextBox = true; } core::stringw getText() const; };