1 //  SuperTuxKart - a fun racing game with go-kart
2 //  Copyright (C) 2009-2015 Marianne Gagnon
3 //
4 //  This program is free software; you can redistribute it and/or
5 //  modify it under the terms of the GNU General Public License
6 //  as published by the Free Software Foundation; either version 3
7 //  of the License, or (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program; if not, write to the Free Software
16 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 
18 
19 #ifndef __HEADER_USER_SCREEN_HPP__
20 #define __HEADER_USER_SCREEN_HPP__
21 
22 #include <string>
23 
24 #include "guiengine/screen.hpp"
25 #include "guiengine/widgets/spinner_widget.hpp"
26 #include "input/input.hpp"
27 namespace GUIEngine
28 {
29     class CheckBoxWidget;
30     class LabelWidget;
31     class RibbonWidget;
32     class TextBoxWidget;
33     class Widget;
34 }
35 
36 class PlayerProfile;
37 
38 
39 /**
40   * \brief The user management screen. The screen cames in two variations:
41   *  either as a stand-alone screen before the main menu (on first time STK
42   *  is started, or it the user is not remembered), but also as tab in the
43   *  options menu. To implement this, we use one common base class that
44   *  implements nearly all functionality, and derive to classes - one for
45   *  the stand alone version, one for the version with tabs.
46   * \ingroup states_screens.
47   */
48 class BaseUserScreen : public GUIEngine::Screen
49 {
50 protected:
51     BaseUserScreen(const std::string &name);
52 
53 private:
54 
55     /** The state of the user screen. Note that this is a bit mask, since the
56      *  current user can be logged out, and the new one logged in at the
57      *  same time. */
58     enum UserScreenState { STATE_NONE=0, STATE_LOGIN=1, STATE_LOGOUT=2} m_state;
59 
60     /** The user name that is currently being logged out. Used to
61      *  display more meaningful sign-out message. */
62     irr::core::stringw m_sign_out_name;
63 
64     /** The user name that is currently being logged out. Used to
65      *  display more meaningful sign-out message. */
66     irr::core::stringw m_sign_in_name;
67 
68     /** Online check box. */
69     GUIEngine::CheckBoxWidget *m_online_cb;
70 
71     /** User name entry field. */
72     GUIEngine::TextBoxWidget *m_username_tb;
73 
74     /** Password widget. */
75     GUIEngine::TextBoxWidget *m_password_tb;
76 
77     /** Label field for warning and error messages. */
78     GUIEngine::LabelWidget * m_info_widget;
79 
80     /** The ribbon with all buttons. */
81     GUIEngine::RibbonWidget *m_options_widget;
82 
83     /** The dynamic ribbon containing all players. */
84     GUIEngine::DynamicRibbonWidget* m_players;
85 
86     /** Set to indicate when the sceen is initialised that new data from a
87      *  registration are available, and therefore entry fields are not
88      *  all cleared. */
89     bool m_new_registered_data;
90 
91     /** Set from the register screen if the newly created account can be
92      *  used directly without waiting to confirm the account. */
93     bool m_auto_login;
94 
95     void selectUser(int index);
96     void makeEntryFieldsVisible();
97     void login();
98     void closeScreen();
99     void deletePlayer();
100     void doDeletePlayer();
101     PlayerProfile* getSelectedPlayer();
102     virtual void onUpdate(float dt) OVERRIDE;
103 
104 public:
105     /** \brief implement callback from parent class GUIEngine::Screen */
106     virtual void loadedFromFile() OVERRIDE;
107 
108     /** \brief implement callback from parent class GUIEngine::Screen */
109     virtual void eventCallback(GUIEngine::Widget* widget,
110                                const std::string& name, const int playerID) OVERRIDE;
111 
112     /** \brief implement callback from parent class GUIEngine::Screen */
113     virtual void beforeAddingWidget() OVERRIDE;
114 
115     /** \brief implement callback from parent class GUIEngine::Screen */
116     virtual void init() OVERRIDE;
117 
118     /** \brief implement callback from parent class GUIEngine::Screen */
119     virtual void tearDown() OVERRIDE;
120 
121     /** \brief implement optional callback from parent class GUIEngine::Screen */
122     virtual void unloaded() OVERRIDE;
123 
124     void setNewAccountData(bool online, bool auto_login,
125                            const core::stringw &online_name="",
126                            const core::stringw &password="");
127     void loginSuccessful();
128     void loginError(const irr::core::stringw &error_message);
129     void logoutSuccessful();
130     void logoutError(const irr::core::stringw &error_message);
131 
132     virtual GUIEngine::EventPropagation filterActions(PlayerAction action,
133         int deviceID,
134         const unsigned int value,
135         Input::InputType type,
136         int playerId) OVERRIDE;
137 };   // class BaseUserScreen
138 
139 // ============================================================================
140 class UserScreen : public BaseUserScreen,
141                    public GUIEngine::ScreenSingleton<UserScreen>
142 {
143 private:
UserScreen()144     UserScreen() : BaseUserScreen("user_screen.stkgui")
145     {};
146 public:
147     friend class GUIEngine::ScreenSingleton<UserScreen>;
148 };   // class UserScreenTabed
149 
150 // ============================================================================
151 class TabbedUserScreen : public BaseUserScreen,
152                          public GUIEngine::ScreenSingleton<TabbedUserScreen>
153 {
154 private:
TabbedUserScreen()155     TabbedUserScreen() : BaseUserScreen("user_screen_tab.stkgui")
156     {}
157 
158 public:
159     friend class GUIEngine::ScreenSingleton<TabbedUserScreen>;
160 
161     virtual void init() OVERRIDE;
162     virtual void eventCallback(GUIEngine::Widget* widget,
163                                const std::string& name, const int playerID) OVERRIDE;
164 };   // class TabbedUserScreen
165 
166 #endif
167