From b0ff13299cfb05be7fa210a15b50b41b62937d35 Mon Sep 17 00:00:00 2001 From: unitraxx Date: Wed, 7 Aug 2013 15:03:33 +0000 Subject: [PATCH] GUI work for profiles. A common inherited base screen for the different tabs. Friends screen added. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13434 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/gui/online/profile_friends.stkgui | 33 +++++++ data/gui/online/profile_overview.stkgui | 1 + sources.cmake | 2 + src/states_screens/online_profile_base.cpp | 86 +++++++++++++++++++ src/states_screens/online_profile_base.hpp | 55 ++++++++++++ src/states_screens/online_profile_friends.cpp | 43 ++-------- src/states_screens/online_profile_friends.hpp | 11 +-- .../online_profile_overview.cpp | 39 ++------- .../online_profile_overview.hpp | 10 +-- 9 files changed, 194 insertions(+), 86 deletions(-) create mode 100644 data/gui/online/profile_friends.stkgui create mode 100644 src/states_screens/online_profile_base.cpp create mode 100644 src/states_screens/online_profile_base.hpp diff --git a/data/gui/online/profile_friends.stkgui b/data/gui/online/profile_friends.stkgui new file mode 100644 index 000000000..469376fa3 --- /dev/null +++ b/data/gui/online/profile_friends.stkgui @@ -0,0 +1,33 @@ + + +
+ +
+ + + + + + + + + +
+
+ + + + +
+
+ + + +
+
+
+
+ + + +
diff --git a/data/gui/online/profile_overview.stkgui b/data/gui/online/profile_overview.stkgui index 299d4b5f4..1b9d1ab14 100644 --- a/data/gui/online/profile_overview.stkgui +++ b/data/gui/online/profile_overview.stkgui @@ -8,6 +8,7 @@ + diff --git a/sources.cmake b/sources.cmake index fd079aae3..f626ee681 100644 --- a/sources.cmake +++ b/sources.cmake @@ -229,6 +229,7 @@ src/states_screens/main_menu_screen.cpp src/states_screens/networking_lobby.cpp src/states_screens/network_kart_selection.cpp src/states_screens/offline_kart_selection.cpp +src/states_screens/online_profile_base.cpp src/states_screens/online_profile_friends.cpp src/states_screens/online_profile_overview.cpp src/states_screens/online_screen.cpp @@ -527,6 +528,7 @@ src/states_screens/main_menu_screen.hpp src/states_screens/networking_lobby.hpp src/states_screens/network_kart_selection.hpp src/states_screens/offline_kart_selection.hpp +src/states_screens/online_profile_base.hpp src/states_screens/online_profile_friends.hpp src/states_screens/online_profile_overview.hpp src/states_screens/online_screen.hpp diff --git a/src/states_screens/online_profile_base.cpp b/src/states_screens/online_profile_base.cpp new file mode 100644 index 000000000..da509f3dc --- /dev/null +++ b/src/states_screens/online_profile_base.cpp @@ -0,0 +1,86 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2013 Glenn De Jonghe +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "states_screens/online_profile_base.hpp" + +#include "guiengine/engine.hpp" +#include "guiengine/scalable_font.hpp" +#include "guiengine/screen.hpp" +#include "guiengine/widget.hpp" +#include "states_screens/state_manager.hpp" +#include "utils/translation.hpp" +#include "states_screens/online_profile_overview.hpp" +#include "states_screens/online_profile_friends.hpp" + +#include +#include + +using namespace GUIEngine; +using namespace irr::core; +using namespace irr::gui; +using namespace Online; + + +OnlineProfileBase::OnlineProfileBase(const char* filename) : Screen(filename) +{ +} // OnlineProfileBase + +// ----------------------------------------------------------------------------- + +void OnlineProfileBase::loadedFromFile() +{ + m_profile_tabs = this->getWidget("profile_tabs"); + assert(m_profile_tabs != NULL); + LabelWidget * header = this->getWidget("title"); + assert(header != NULL); + header->setText(_("Your profile"), false); + + m_overview_tab = (IconButtonWidget *) m_profile_tabs->findWidgetNamed("tab_overview"); + assert(m_overview_tab != NULL); + m_friends_tab = (IconButtonWidget *) m_profile_tabs->findWidgetNamed("tab_friends"); + assert(m_friends_tab != NULL); + +} // loadedFromFile + +// ----------------------------------------------------------------------------- + +void OnlineProfileBase::init() +{ + Screen::init(); + + m_overview_tab->setTooltip( _("Overview") ); + m_friends_tab->setTooltip( _("Friends") ); + +} // init + +// ----------------------------------------------------------------------------- + +void OnlineProfileBase::eventCallback(Widget* widget, const std::string& name, const int playerID) +{ + if (name == m_profile_tabs->m_properties[PROP_ID]) + { + std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER).c_str(); + + if (selection == m_overview_tab->m_properties[PROP_ID]) StateManager::get()->replaceTopMostScreen(OnlineProfileOverview::getInstance()); + else if (selection == m_friends_tab->m_properties[PROP_ID]) StateManager::get()->replaceTopMostScreen(OnlineProfileFriends::getInstance()); + } + else if (name == "back") + { + StateManager::get()->escapePressed(); + } +} // eventCallback + diff --git a/src/states_screens/online_profile_base.hpp b/src/states_screens/online_profile_base.hpp new file mode 100644 index 000000000..a179c4023 --- /dev/null +++ b/src/states_screens/online_profile_base.hpp @@ -0,0 +1,55 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2013 Glenn De Jonghe +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifndef __HEADER_ONLINE_PROFILE_BASE_HPP__ +#define __HEADER_ONLINE_PROFILE_BASE_HPP__ + +#include +#include + +#include "guiengine/screen.hpp" +#include "guiengine/widgets.hpp" + +namespace GUIEngine { class Widget; } + + +/** + * \brief Online profiel overview screen + * \ingroup states_screens + */ +class OnlineProfileBase : public GUIEngine::Screen +{ +protected: + OnlineProfileBase(const char* filename); + GUIEngine::RibbonWidget* m_profile_tabs; + GUIEngine::IconButtonWidget * m_overview_tab; + GUIEngine::IconButtonWidget * m_friends_tab; + +public: + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void loadedFromFile() OVERRIDE; + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name, const int playerID) OVERRIDE; + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void init() OVERRIDE; +}; + +#endif diff --git a/src/states_screens/online_profile_friends.cpp b/src/states_screens/online_profile_friends.cpp index 975e183f9..1816c0db2 100644 --- a/src/states_screens/online_profile_friends.cpp +++ b/src/states_screens/online_profile_friends.cpp @@ -1,5 +1,5 @@ // SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2010 Glenn De Jonghe +// Copyright (C) 2013 Glenn De Jonghe // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -38,59 +38,28 @@ DEFINE_SCREEN_SINGLETON( OnlineProfileFriends ); // ----------------------------------------------------------------------------- -OnlineProfileFriends::OnlineProfileFriends() : Screen("online/profile_overview.stkgui") +OnlineProfileFriends::OnlineProfileFriends() : OnlineProfileBase("online/profile_friends.stkgui") { } // OnlineProfileFriends - - - // ----------------------------------------------------------------------------- void OnlineProfileFriends::loadedFromFile() { - m_profile_tabs = this->getWidget("profile_tabs"); - assert(m_profile_tabs != NULL); - LabelWidget * header = this->getWidget("title"); - assert(header != NULL); - header->setText(_("Your profile"), false); - + OnlineProfileBase::loadedFromFile(); } // loadedFromFile // ----------------------------------------------------------------------------- void OnlineProfileFriends::init() { - Screen::init(); - m_profile_tabs->select( "tab_players", PLAYER_ID_GAME_MASTER ); - - /* - tabBar->getRibbonChildren()[0].setTooltip( _("Graphics") ); - tabBar->getRibbonChildren()[1].setTooltip( _("Audio") ); - tabBar->getRibbonChildren()[2].setTooltip( _("User Interface") ); - tabBar->getRibbonChildren()[4].setTooltip( _("Controls") );*/ + OnlineProfileBase::init(); + m_profile_tabs->select( m_friends_tab->m_properties[PROP_ID], PLAYER_ID_GAME_MASTER ); } // init - -// ----------------------------------------------------------------------------- - -void OnlineProfileFriends::tearDown() -{ - Screen::tearDown(); -} // tearDown - // ----------------------------------------------------------------------------- void OnlineProfileFriends::eventCallback(Widget* widget, const std::string& name, const int playerID) { - if (name == m_profile_tabs->m_properties[PROP_ID]) - { - std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER).c_str(); - - //if (selection == "tab_audio") StateManager::get()->replaceTopMostScreen(OptionsScreenAudio::getInstance()); - } - else if (name == "back") - { - StateManager::get()->escapePressed(); - } + OnlineProfileBase::eventCallback( widget, name, playerID); } // eventCallback diff --git a/src/states_screens/online_profile_friends.hpp b/src/states_screens/online_profile_friends.hpp index 0a9c522b5..fd65d91d9 100644 --- a/src/states_screens/online_profile_friends.hpp +++ b/src/states_screens/online_profile_friends.hpp @@ -24,6 +24,7 @@ #include "guiengine/screen.hpp" #include "guiengine/widgets.hpp" +#include "states_screens/online_profile_base.hpp" namespace GUIEngine { class Widget; } @@ -32,13 +33,11 @@ namespace GUIEngine { class Widget; } * \brief Online profiel overview screen * \ingroup states_screens */ -class OnlineProfileFriends : public GUIEngine::Screen, public GUIEngine::ScreenSingleton +class OnlineProfileFriends : public OnlineProfileBase, public GUIEngine::ScreenSingleton { private: OnlineProfileFriends(); - GUIEngine::RibbonWidget* m_profile_tabs; - public: friend class GUIEngine::ScreenSingleton; @@ -46,14 +45,10 @@ public: virtual void loadedFromFile() OVERRIDE; /** \brief implement callback from parent class GUIEngine::Screen */ - virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name, - const int playerID) OVERRIDE; + virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name, const int playerID) OVERRIDE; /** \brief implement callback from parent class GUIEngine::Screen */ virtual void init() OVERRIDE; - - /** \brief implement callback from parent class GUIEngine::Screen */ - virtual void tearDown() OVERRIDE; }; #endif diff --git a/src/states_screens/online_profile_overview.cpp b/src/states_screens/online_profile_overview.cpp index 29aeed693..128437f47 100644 --- a/src/states_screens/online_profile_overview.cpp +++ b/src/states_screens/online_profile_overview.cpp @@ -38,22 +38,15 @@ DEFINE_SCREEN_SINGLETON( OnlineProfileOverview ); // ----------------------------------------------------------------------------- -OnlineProfileOverview::OnlineProfileOverview() : Screen("online/profile_overview.stkgui") +OnlineProfileOverview::OnlineProfileOverview() : OnlineProfileBase("online/profile_overview.stkgui") { } // OnlineProfileOverview - - - // ----------------------------------------------------------------------------- void OnlineProfileOverview::loadedFromFile() { - m_profile_tabs = this->getWidget("profile_tabs"); - assert(m_profile_tabs != NULL); - LabelWidget * header = this->getWidget("title"); - assert(header != NULL); - header->setText(_("Your profile"), false); + OnlineProfileBase::loadedFromFile(); } // loadedFromFile @@ -61,36 +54,14 @@ void OnlineProfileOverview::loadedFromFile() void OnlineProfileOverview::init() { - Screen::init(); - m_profile_tabs->select( "tab_players", PLAYER_ID_GAME_MASTER ); - - /* - tabBar->getRibbonChildren()[0].setTooltip( _("Graphics") ); - tabBar->getRibbonChildren()[1].setTooltip( _("Audio") ); - tabBar->getRibbonChildren()[2].setTooltip( _("User Interface") ); - tabBar->getRibbonChildren()[4].setTooltip( _("Controls") );*/ + OnlineProfileBase::init(); + m_profile_tabs->select( m_overview_tab->m_properties[PROP_ID], PLAYER_ID_GAME_MASTER ); } // init // ----------------------------------------------------------------------------- -void OnlineProfileOverview::tearDown() -{ - Screen::tearDown(); -} // tearDown - -// ----------------------------------------------------------------------------- - void OnlineProfileOverview::eventCallback(Widget* widget, const std::string& name, const int playerID) { - if (name == m_profile_tabs->m_properties[PROP_ID]) - { - std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER).c_str(); - - //if (selection == "tab_audio") StateManager::get()->replaceTopMostScreen(OptionsScreenAudio::getInstance()); - } - else if (name == "back") - { - StateManager::get()->escapePressed(); - } + OnlineProfileBase::eventCallback( widget, name, playerID); } // eventCallback diff --git a/src/states_screens/online_profile_overview.hpp b/src/states_screens/online_profile_overview.hpp index f20f499ef..6ad7619e1 100644 --- a/src/states_screens/online_profile_overview.hpp +++ b/src/states_screens/online_profile_overview.hpp @@ -24,6 +24,7 @@ #include "guiengine/screen.hpp" #include "guiengine/widgets.hpp" +#include "states_screens/online_profile_base.hpp" namespace GUIEngine { class Widget; } @@ -32,13 +33,11 @@ namespace GUIEngine { class Widget; } * \brief Online profiel overview screen * \ingroup states_screens */ -class OnlineProfileOverview : public GUIEngine::Screen, public GUIEngine::ScreenSingleton +class OnlineProfileOverview : public OnlineProfileBase, public GUIEngine::ScreenSingleton { -private: +protected: OnlineProfileOverview(); - GUIEngine::RibbonWidget* m_profile_tabs; - public: friend class GUIEngine::ScreenSingleton; @@ -51,9 +50,6 @@ public: /** \brief implement callback from parent class GUIEngine::Screen */ virtual void init() OVERRIDE; - - /** \brief implement callback from parent class GUIEngine::Screen */ - virtual void tearDown() OVERRIDE; }; #endif