SuperTuxKart
user_screen.hpp
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 
49 {
50 protected:
51  BaseUserScreen(const std::string &name);
52 
53 private:
54 
58  enum UserScreenState { STATE_NONE=0, STATE_LOGIN=1, STATE_LOGOUT=2} m_state;
59 
62  irr::core::stringw m_sign_out_name;
63 
66  irr::core::stringw m_sign_in_name;
67 
70 
73 
76 
79 
82 
85 
90 
94 
95  void selectUser(int index);
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:
106  virtual void loadedFromFile() OVERRIDE;
107 
109  virtual void eventCallback(GUIEngine::Widget* widget,
110  const std::string& name, const int playerID) OVERRIDE;
111 
113  virtual void beforeAddingWidget() OVERRIDE;
114 
116  virtual void init() OVERRIDE;
117 
119  virtual void tearDown() OVERRIDE;
120 
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:
144  UserScreen() : BaseUserScreen("user_screen.stkgui")
145  {};
146 public:
148 }; // class UserScreenTabed
149 
150 // ============================================================================
152  public GUIEngine::ScreenSingleton<TabbedUserScreen>
153 {
154 private:
155  TabbedUserScreen() : BaseUserScreen("user_screen_tab.stkgui")
156  {}
157 
158 public:
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
virtual void eventCallback(GUIEngine::Widget *widget, const std::string &name, const int playerID) OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: user_screen.cpp:331
bool m_auto_login
Set from the register screen if the newly created account can be used directly without waiting to con...
Definition: user_screen.hpp:93
An extended version of RibbonWidget, with more capabilities.
Definition: dynamic_ribbon_widget.hpp:81
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:31
irr::core::stringw m_sign_in_name
The user name that is currently being logged out.
Definition: user_screen.hpp:66
void loginError(const irr::core::stringw &error_message)
Callback from player profile if login was unsuccessful.
Definition: user_screen.cpp:607
virtual void tearDown() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: user_screen.cpp:197
void makeEntryFieldsVisible()
Make the entry fields either visible or invisible.
Definition: user_screen.cpp:288
A text field widget.
Definition: text_box_widget.hpp:52
GUIEngine::LabelWidget * m_info_widget
Label field for warning and error messages.
Definition: user_screen.hpp:78
PlayerAction
types of input events / what actions the players can do
Definition: input.hpp:116
virtual void unloaded() OVERRIDE
implement optional callback from parent class GUIEngine::Screen
Definition: user_screen.cpp:720
Definition: input.hpp:34
void selectUser(int index)
Called when a user is selected.
Definition: user_screen.cpp:229
virtual void onUpdate(float dt) OVERRIDE
Called once every frame.
Definition: user_screen.cpp:575
virtual void beforeAddingWidget() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: user_screen.cpp:103
A checkbox widget.
Definition: check_box_widget.hpp:33
Definition: user_screen.hpp:140
void closeScreen()
Closes the BaseUserScreen, and makes sure that the right screen is displayed next.
Definition: user_screen.cpp:469
void login()
Called when OK or OK-and-save is clicked.
Definition: user_screen.cpp:487
void loginSuccessful()
Callback from player profile if login was successful.
Definition: user_screen.cpp:590
UserScreenState
The state of the user screen.
Definition: user_screen.hpp:58
void logoutError(const irr::core::stringw &error_message)
Callback from player profile if login was unsuccessful.
Definition: user_screen.cpp:638
Definition: user_screen.hpp:151
GUIEngine::TextBoxWidget * m_password_tb
Password widget.
Definition: user_screen.hpp:75
GUIEngine::DynamicRibbonWidget * m_players
The dynamic ribbon containing all players.
Definition: user_screen.hpp:84
Class for managing player profiles (name, usage frequency, etc.).
Definition: player_profile.hpp:53
GUIEngine::TextBoxWidget * m_username_tb
User name entry field.
Definition: user_screen.hpp:72
void deletePlayer()
Called when a player will be deleted.
Definition: user_screen.cpp:656
virtual void init() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: user_screen.cpp:112
A static text/icons/tabs bar widget.
Definition: ribbon_widget.hpp:59
A simple label widget.
Definition: label_widget.hpp:35
virtual void loadedFromFile() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: user_screen.cpp:62
irr::core::stringw m_sign_out_name
The user name that is currently being logged out.
Definition: user_screen.hpp:62
Represents a single GUI screen.
Definition: screen.hpp:94
GUIEngine::CheckBoxWidget * m_online_cb
Online check box.
Definition: user_screen.hpp:69
Declares a class to be a singleton.
Definition: screen.hpp:57
GUIEngine::RibbonWidget * m_options_widget
The ribbon with all buttons.
Definition: user_screen.hpp:81
The user management screen.
Definition: user_screen.hpp:48
virtual GUIEngine::EventPropagation filterActions(PlayerAction action, int deviceID, const unsigned int value, Input::InputType type, int playerId) OVERRIDE
Override this if you need to be notified of player actions in subclasses.
Definition: user_screen.cpp:204
void setNewAccountData(bool online, bool auto_login, const core::stringw &online_name="", const core::stringw &password="")
Stores information from the register screen.
Definition: user_screen.cpp:90
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:138
void logoutSuccessful()
Callback from player profile if logout was successful.
Definition: user_screen.cpp:626
bool m_new_registered_data
Set to indicate when the sceen is initialised that new data from a registration are available,...
Definition: user_screen.hpp:89
void doDeletePlayer()
Callback when the user confirms to delete a player.
Definition: user_screen.cpp:696