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 "guiengine/widgets/text_box_widget.hpp"
26 #include "states_screens/state_manager.hpp"
27 
28 namespace GUIEngine
29 {
30  class Widget;
31  class BubbleWidget;
32  enum EventPropagation;
33 }
34 namespace Online
35 {
36  class User;
37  class OnlineProfile;
38 }
39 
40 class FocusDispatcher;
41 class InputDevice;
42 class PlayerProfile;
43 class KartHoverListener;
44 
45 extern int g_root_id;
46 
53 {
54  friend class KartHoverListener;
55  friend class FocusDispatcher;
56 protected:
62 
64  friend class GUIEngine::PlayerKartWidget;
65 
66  bool m_multiplayer;
67 
70 
71  bool m_go_to_overworld_next;
72 
74 
79 
80  GUIEngine::PlayerKartWidget* m_removed_widget;
81 
82  GUIEngine::TextBoxWidget *m_search_box;
83 
86 
87  FocusDispatcher *m_dispatcher;
88 
89  KartSelectionScreen(const char* filename);
90 
92  virtual void allPlayersDone();
93 
96  void handleKartListFocus();
97 
100  void renumberKarts();
101 
106  bool validateIdentChoices();
107 
111  bool validateKartChoices();
112 
115 
116  void playerConfirm(const int playerID);
117 
118  void updateKartStats(uint8_t widget_id,
119  const std::string& selection);
120 
123  void updateKartWidgetModel(int widget_id,
124  const std::string& selection,
125  const irr::core::stringw& selectionText,
126  float kart_color);
127 
129  void addMultiplayerMessage();
130 
133 
134  virtual bool isIgnored(const std::string& ident) const { return false; }
135 
138 private:
140  const std::string& selected_kart_group);
141  bool useContinueButton() const;
142  void configureChooseKarts(bool enable);
143 public:
146 
148  virtual void loadedFromFile() OVERRIDE;
149 
150  void setMultiplayer(bool multiplayer);
151 
153  void setFromOverworld(bool from_overworld) { m_from_overworld = from_overworld; }
154 
155  void setGoToOverworldNext() { m_go_to_overworld_next = true; }
156 
159  bool joinPlayer(InputDevice* device, PlayerProfile* p);
160 
166  virtual bool playerQuit(StateManager::ActivePlayer* player);
167 
169  virtual void init() OVERRIDE;
170 
171  virtual void beforeAddingWidget() OVERRIDE;
172 
174  virtual void tearDown() OVERRIDE;
175 
177  virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name,
178  const int playerID) OVERRIDE;
179 
181  virtual void onUpdate(float dt) OVERRIDE;
182 
184  virtual void onTextUpdated() OVERRIDE
185  {
187  // After setKartsFromCurrentGroup the m_search_box may be unfocused
188  m_search_box->focused(PLAYER_ID_GAME_MASTER);
189 
191  }
192 
193  virtual void onFocusChanged(GUIEngine::Widget* previous,
194  GUIEngine::Widget* focus, int playerID) OVERRIDE;
195 
198  virtual void unloaded() OVERRIDE;
199 
202  virtual bool onEscapePressed() OVERRIDE;
203 
204  virtual void onResize() OVERRIDE;
205 
206 }; // KartSelectionScreen
207 
210 
216 class FocusDispatcher : public GUIEngine::Widget
217 {
218 protected:
220  int m_reserved_id;
221 
222  bool m_is_initialised;
223 
224 public:
225 
226  LEAK_CHECK()
227 
228  // ------------------------------------------------------------------------
230  // ------------------------------------------------------------------------
231  void setRootID(const int reservedID);
232 
233  // ------------------------------------------------------------------------
234  virtual void add();
235 
236  // ------------------------------------------------------------------------
237 
238  virtual GUIEngine::EventPropagation focused(const int playerID);
239 }; // FocusDispatcher
240 
244 {
245  KartSelectionScreen* m_parent;
246 public:
247  unsigned int m_magic_number;
248 
250 
251  // ------------------------------------------------------------------------
252  virtual ~KartHoverListener();
253 
254  // ------------------------------------------------------------------------
255  void onSelectionChanged(GUIEngine::DynamicRibbonWidget* theWidget,
256  const std::string& selectionID,
257  const irr::core::stringw& selectionText,
258  const int playerID);
259 }; // KartHoverListener
260 
261 #endif
262 
Currently, navigation for multiple players at the same time is implemented in a somewhat clunky way.
Definition: kart_selection.hpp:217
A text widget that can expand when focused.
Definition: bubble_widget.hpp:36
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:41
An extended version of RibbonWidget, with more capabilities.
Definition: dynamic_ribbon_widget.hpp:82
Definition: text_box_widget.hpp:42
A widget representing the kart selection for a player (i.e.
Definition: player_kart_widget.hpp:43
virtual void add()
Add the widgets to the current screen.
Definition: player_kart_widget.cpp:348
Declares a class to be a singleton.
Definition: screen.hpp:59
Represents a single GUI screen.
Definition: screen.hpp:94
unsigned int m_magic_number
to catch errors as early as possible, for debugging purposes only
Definition: screen.hpp:114
A text field widget.
Definition: text_box_widget.hpp:53
virtual EventPropagation focused(const int playerID)
override in children if you need to know when the widget is focused.
Definition: text_box_widget.cpp:178
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:147
int m_reserved_id
Used in two cases : 1) For 'placeholder' divisions; at the time the layout is created,...
Definition: widget.hpp:340
irr::gui::IGUIElement * m_parent
An irrlicht parent (most often used to put widgets in dialogs)
Definition: widget.hpp:239
virtual EventPropagation focused(const int playerID)
override in children if you need to know when the widget is focused.
Definition: widget.hpp:231
base class for input devices
Definition: input_device.hpp:48
Definition: kart_selection.hpp:244
screen where players can choose their kart
Definition: kart_selection.hpp:53
virtual void allPlayersDone()
Called when all players selected their kart.
Definition: kart_selection.cpp:1304
PtrVector< GUIEngine::PlayerKartWidget, REF > m_kart_widgets
Contains the custom widget shown for every player.
Definition: kart_selection.hpp:61
void addMultiplayerMessage()
Adds a message to the screen which indicates that players must press fire to join.
Definition: kart_selection.cpp:1095
virtual void beforeAddingWidget() OVERRIDE
Optional callback invoked very early, before widgets have been added (contrast with init(),...
Definition: kart_selection.cpp:274
virtual void init() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: kart_selection.cpp:382
bool m_from_overworld
Whether this screen is being visited from overworld or not.
Definition: kart_selection.hpp:69
static KartSelectionScreen * getRunningInstance()
Returns the current instance.
Definition: kart_selection.cpp:252
GUIEngine::BubbleWidget * m_multiplayer_message
Message shown in multiplayer mode.
Definition: kart_selection.hpp:85
virtual void unloaded() OVERRIDE
implement optional callback from parent class GUIEngine::Screen
Definition: kart_selection.cpp:536
bool m_must_delete_on_back
To delete the screen if back is pressed.
Definition: kart_selection.hpp:73
virtual void onResize() OVERRIDE
optional callback you can override to be notified at every resize.
Definition: kart_selection.cpp:1790
virtual void loadedFromFile() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: kart_selection.cpp:259
virtual void onTextUpdated() OVERRIDE
Rebuild the list of tracks based on search text.
Definition: kart_selection.hpp:184
void handleKartListFocus()
When kart list has been changed, make sure all players have valid focus.
Definition: kart_selection.cpp:1439
void setKartsFromCurrentGroup()
Fill the ribbon with the karts from the currently selected group.
Definition: kart_selection.cpp:1718
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:965
static KartSelectionScreen * m_instance_ptr
Stores a pointer to the current selection screen.
Definition: kart_selection.hpp:137
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:78
bool validateIdentChoices()
Checks identities chosen by players, making sure no duplicates are used.
Definition: kart_selection.cpp:1501
virtual bool onEscapePressed() OVERRIDE
implement optional callback from parent class GUIEngine::Screen
Definition: kart_selection.cpp:1248
virtual void tearDown() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: kart_selection.cpp:498
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:1146
virtual bool playerQuit(StateManager::ActivePlayer *player)
Called when a player hits 'rescue'/'cancel' on his device to leave the game.
Definition: kart_selection.cpp:689
bool validateKartChoices()
Checks karts chosen by players, making sure no duplicates are used.
Definition: kart_selection.cpp:1584
void removeMultiplayerMessage()
Remove the multiplayer message.
Definition: kart_selection.cpp:1130
void setFromOverworld(bool from_overworld)
Set whether this screen is being visited from overworld or not.
Definition: kart_selection.hpp:153
virtual void onUpdate(float dt) OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: kart_selection.cpp:815
void renumberKarts()
Called when number/order of karts changed, so that all will keep an up-to-date ID.
Definition: kart_selection.cpp:1662
virtual void onFocusChanged(GUIEngine::Widget *previous, GUIEngine::Widget *focus, int playerID) OVERRIDE
Callback called when focus changes.
Definition: kart_selection.cpp:1266
bool joinPlayer(InputDevice *device, PlayerProfile *p)
Called when a player hits 'fire'/'select' on his device to join the game.
Definition: kart_selection.cpp:544
Class for managing player profiles (name, usage frequency, etc.).
Definition: player_profile.hpp:55
Represents a player that is currently playing.
Definition: state_manager.hpp:76
static const int PLAYER_ID_GAME_MASTER
the player ID of the "game master" player the game master is the player that can perform the game set...
Definition: state_manager.hpp:52
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33