SuperTuxKart
kart_selection.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 //
3 // Copyright (C) 2006-2015 SuperTuxKart-Team
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef KART_SELECTION_INCLUDED
20 #define KART_SELECTION_INCLUDED
21 
22 #include "guiengine/screen.hpp"
23 #include "guiengine/widgets/dynamic_ribbon_widget.hpp"
24 #include "guiengine/widgets/player_kart_widget.hpp"
25 #include "states_screens/state_manager.hpp"
26 
27 namespace GUIEngine
28 {
29  class Widget;
30  class BubbleWidget;
31  enum EventPropagation;
32 }
33 namespace Online
34 {
35  class User;
36  class OnlineProfile;
37 }
38 
39 class FocusDispatcher;
40 class InputDevice;
41 class PlayerProfile;
42 class KartHoverListener;
43 
44 extern int g_root_id;
45 
51 {
52  friend class KartHoverListener;
53  friend class PlayerNameSpinner;
54  friend class FocusDispatcher;
55 protected:
61 
63  friend class GUIEngine::PlayerKartWidget;
64 
65  bool m_multiplayer;
66 
69 
70  bool m_go_to_overworld_next;
71 
73 
78 
79  GUIEngine::PlayerKartWidget* m_removed_widget;
80 
83 
84  FocusDispatcher *m_dispatcher;
85 
86  KartSelectionScreen(const char* filename);
87 
89  virtual void allPlayersDone();
90 
93  void renumberKarts();
94 
99  bool validateIdentChoices();
100 
104  bool validateKartChoices();
105 
108 
109  void playerConfirm(const int playerID);
110 
111  void updateKartStats(uint8_t widget_id,
112  const std::string& selection);
113 
116  void updateKartWidgetModel(int widget_id,
117  const std::string& selection,
118  const irr::core::stringw& selectionText,
119  float kart_color);
120 
122  void addMultiplayerMessage();
123 
126 
127  virtual bool isIgnored(const std::string& ident) const { return false; }
128 
131 private:
133  const std::string& selected_kart_group);
134 public:
137 
139  virtual void loadedFromFile() OVERRIDE;
140 
141  void setMultiplayer(bool multiplayer);
142 
144  void setFromOverworld(bool from_overworld) { m_from_overworld = from_overworld; }
145 
146  void setGoToOverworldNext() { m_go_to_overworld_next = true; }
147 
150  bool joinPlayer(InputDevice* device, PlayerProfile* p);
151 
157  virtual bool playerQuit(StateManager::ActivePlayer* player);
158 
160  virtual void init() OVERRIDE;
161 
162  virtual void beforeAddingWidget() OVERRIDE;
163 
165  virtual void tearDown() OVERRIDE;
166 
168  virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name,
169  const int playerID) OVERRIDE;
170 
172  virtual void onUpdate(float dt) OVERRIDE;
173 
176  virtual void unloaded() OVERRIDE;
177 
180  virtual bool onEscapePressed() OVERRIDE;
181 
182 }; // KartSelectionScreen
183 
186 
192 class FocusDispatcher : public GUIEngine::Widget
193 {
194 protected:
196  int m_reserved_id;
197 
198  bool m_is_initialised;
199 
200 public:
201 
202  LEAK_CHECK()
203 
204  // ------------------------------------------------------------------------
206  // ------------------------------------------------------------------------
207  void setRootID(const int reservedID);
208 
209  // ------------------------------------------------------------------------
210  virtual void add();
211 
212  // ------------------------------------------------------------------------
213 
214  virtual GUIEngine::EventPropagation focused(const int playerID);
215 }; // FocusDispatcher
216 
220 {
221  KartSelectionScreen* m_parent;
222 public:
223  unsigned int m_magic_number;
224 
226 
227  // ------------------------------------------------------------------------
228  virtual ~KartHoverListener();
229 
230  // ------------------------------------------------------------------------
231  void onSelectionChanged(GUIEngine::DynamicRibbonWidget* theWidget,
232  const std::string& selectionID,
233  const irr::core::stringw& selectionText,
234  const int playerID);
235 }; // KartHoverListener
236 
237 #endif
238 
Represents a player that is currently playing.
Definition: state_manager.hpp:75
virtual void init() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: kart_selection.cpp:313
A widget representing the kart selection for a player (i.e.
Definition: player_kart_widget.hpp:40
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
bool m_from_overworld
Whether this screen is being visited from overworld or not.
Definition: kart_selection.hpp:68
A text widget that can expand when focused.
Definition: bubble_widget.hpp:35
virtual void add()
Add the widgets to the current screen.
Definition: player_kart_widget.cpp:329
void setFromOverworld(bool from_overworld)
Set whether this screen is being visited from overworld or not.
Definition: kart_selection.hpp:144
static KartSelectionScreen * getRunningInstance()
Returns the current instance.
Definition: kart_selection.cpp:247
Definition: kart_selection.hpp:219
bool validateIdentChoices()
Checks identities chosen by players, making sure no duplicates are used.
Definition: kart_selection.cpp:1291
static KartSelectionScreen * m_instance_ptr
Stores a pointer to the current selection screen.
Definition: kart_selection.hpp:130
virtual void onUpdate(float dt) OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: kart_selection.cpp:709
Currently, navigation for multiple players at the same time is implemented in a somewhat clunky way.
Definition: kart_selection.hpp:192
void updateKartWidgetModel(int widget_id, const std::string &selection, const irr::core::stringw &selectionText, float kart_color)
updates model of a kart widget, to have the good selection when the user validates
Definition: kart_selection.cpp:848
virtual void unloaded() OVERRIDE
implement optional callback from parent class GUIEngine::Screen
Definition: kart_selection.cpp:439
int m_reserved_id
Used in two cases : 1) For 'placeholder' divisions; at the time the layout is created,...
Definition: widget.hpp:328
virtual void beforeAddingWidget() OVERRIDE
Optional callback invoked very early, before widgets have been added (contrast with init(),...
Definition: kart_selection.cpp:269
void removeMultiplayerMessage()
Remove the multiplayer message.
Definition: kart_selection.cpp:1010
base class for input devices
Definition: input_device.hpp:47
PtrVector< GUIEngine::PlayerKartWidget, REF > m_kart_widgets
Contains the custom widget shown for every player.
Definition: kart_selection.hpp:60
Class for managing player profiles (name, usage frequency, etc.).
Definition: player_profile.hpp:53
void renumberKarts()
Called when number/order of karts changed, so that all will keep an up-to-date ID.
Definition: kart_selection.cpp:1450
bool validateKartChoices()
Checks karts chosen by players, making sure no duplicates are used.
Definition: kart_selection.cpp:1372
void addMultiplayerMessage()
Adds a message to the screen which indicates that players must press fire to join.
Definition: kart_selection.cpp:975
irr::gui::IGUIElement * m_parent
An irrlicht parent (most often used to put widgets in dialogs)
Definition: widget.hpp:227
virtual void allPlayersDone()
Called when all players selected their kart.
Definition: kart_selection.cpp:1156
virtual bool playerQuit(StateManager::ActivePlayer *player)
Called when a player hits 'rescue'/'cancel' on his device to leave the game.
Definition: kart_selection.cpp:583
Represents a single GUI screen.
Definition: screen.hpp:94
Declares a class to be a singleton.
Definition: screen.hpp:57
bool joinPlayer(InputDevice *device, PlayerProfile *p)
Called when a player hits 'fire'/'select' on his device to join the game.
Definition: kart_selection.cpp:447
virtual EventPropagation focused(const int playerID)
override in children if you need to know when the widget is focused.
Definition: widget.hpp:219
GUIEngine::BubbleWidget * m_multiplayer_message
Message shown in multiplayer mode.
Definition: kart_selection.hpp:82
screen where players can choose their kart
Definition: kart_selection.hpp:50
void setKartsFromCurrentGroup()
Fill the ribbon with the karts from the currently selected group.
Definition: kart_selection.cpp:1489
Even if you have a ribbon that only acts on click/enter, you may wish to know which item is currently...
Definition: dynamic_ribbon_widget.hpp:40
virtual void tearDown() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: kart_selection.cpp:413
bool m_must_delete_on_back
To delete the screen if back is pressed.
Definition: kart_selection.hpp:72
virtual void eventCallback(GUIEngine::Widget *widget, const std::string &name, const int playerID) OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: kart_selection.cpp:1026
unsigned int m_magic_number
to catch errors as early as possible, for debugging purposes only
Definition: screen.hpp:114
virtual bool onEscapePressed() OVERRIDE
implement optional callback from parent class GUIEngine::Screen
Definition: kart_selection.cpp:1133
virtual void loadedFromFile() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: kart_selection.cpp:254
bool m_game_master_confirmed
Stores whether any player confirmed their choice; then, some things are "frozen", for instance the se...
Definition: kart_selection.hpp:77