SuperTuxKart
player_kart_widget.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 PLAYER_KART_WIDGET_HPP
20 #define PLAYER_KART_WIDGET_HPP
21 
22 #include "guiengine/widgets/spinner_widget.hpp"
23 #include "states_screens/state_manager.hpp"
24 #include <IGUIStaticText.h>
25 #include <IGUIImage.h>
26 #include <string>
27 
28 
30 
31 namespace GUIEngine
32 {
33  class KartStatsWidget;
34  class ModelViewWidget;
35  class LabelWidget;
36  class SpinnerWidget;
37  class IconButtonWidget;
38 
43  {
45  bool m_ready;
48 
50  int player_name_x, player_name_y, player_name_w, player_name_h;
51  int model_x, model_y, model_w, model_h;
52  int kart_name_x, kart_name_y, kart_name_w, kart_name_h;
53  int m_crown_icon_x, m_crown_icon_y, m_crown_icon_w, m_crown_icon_h;
54  int m_kart_stats_x, m_kart_stats_y, m_kart_stats_w, m_kart_stats_h;
55  int m_left_arrow_width;
56 
60 
62  int target_x, target_y, target_w, target_h;
63  float x_speed, y_speed, w_speed, h_speed;
64 
68  int m_player_id;
69 
72  std::string spinnerID;
73 
74 #ifdef DEBUG
75  long m_magic_number;
76 #endif
77 
78  // -------------------------------------------------------------------------
79  void updateSize();
80  public:
81 
82  LEAK_CHECK()
83 
84 
86  KartStatsWidget* m_kart_stats;
87  ModelViewWidget* m_model_view;
88  LabelWidget* m_kart_name;
89  IconButtonWidget* m_crown_icon;
90 
91  KartSelectionScreen* m_parent_screen;
92 
93  irr::gui::IGUIStaticText* m_ready_text;
94 
95  core::stringw deviceName;
96  std::string m_kart_internal_name;
97 
98  bool m_not_updated_yet;
99 
101  StateManager::ActivePlayer* associated_player,
102  core::recti area, const int player_id,
103  std::string kart_group,
104  const int irrlicht_idget_id=-1);
105  // ------------------------------------------------------------------------
106 
107  ~PlayerKartWidget();
108 
109  // ------------------------------------------------------------------------
111  void setPlayerID(const int newPlayerID);
112  // ------------------------------------------------------------------------
113  SpinnerWidget* getPlayerNameSpinner() const
114  { return m_player_ident_spinner; }
115  // ------------------------------------------------------------------------
117  int getPlayerID() const;
118 
119  // ------------------------------------------------------------------------
121  virtual void add();
122 
123  // ------------------------------------------------------------------------
126 
127  // ------------------------------------------------------------------------
130  void move(const int x, const int y, const int w, const int h);
131 
132  // ------------------------------------------------------------------------
134  void markAsReady();
135 
136  // ------------------------------------------------------------------------
138  bool isReady();
139 
140  // ------------------------------------------------------------------------
143 
144  // -------------------------------------------------------------------------
146  void onUpdate(float delta);
147 
148  // -------------------------------------------------------------------------
150  virtual GUIEngine::EventPropagation transmitEvent(
152  const std::string& originator,
153  const int m_player_id);
154 
155  // -------------------------------------------------------------------------
158  void setSize(const int x, const int y, const int w, const int h);
159 
160  // -------------------------------------------------------------------------
161 
163  void setKartInternalName(const std::string& whichKart);
164 
165  // -------------------------------------------------------------------------
166 
167  const std::string& getKartInternalName() const;
168 
169  // -------------------------------------------------------------------------
170 
172  virtual GUIEngine::EventPropagation onSpinnerConfirmed();
173  // -------------------------------------------------------------------------
174  void enableHandicapForNetwork();
175  // -------------------------------------------------------------------------
176  void updateSizeNow(int x, int y, int w, int h)
177  {
178  target_x = m_x = x;
179  target_y = m_y = y;
180  target_w = m_w = w;
181  target_h = m_h = h;
182  updateSize();
183  }
184  }; // PlayerKartWidget
185 }
186 
187 #endif
188 
A button widget with an icon and optionnaly a label beneath.
Definition: icon_button_widget.hpp:44
A progress bar widget.
Definition: kart_stats_widget.hpp:43
A simple label widget.
Definition: label_widget.hpp:41
A model view widget.
Definition: model_view_widget.hpp:37
A widget representing the kart selection for a player (i.e.
Definition: player_kart_widget.hpp:43
HandicapLevel m_handicap
If the player is handicapped.
Definition: player_kart_widget.hpp:47
void markAsReady()
Call when player confirmed his identity and kart.
Definition: player_kart_widget.cpp:457
virtual GUIEngine::EventPropagation transmitEvent(GUIEngine::Widget *w, const std::string &originator, const int m_player_id)
Event callback.
Definition: player_kart_widget.cpp:639
bool m_ready
Whether this player confirmed their selection.
Definition: player_kart_widget.hpp:45
virtual GUIEngine::EventPropagation onSpinnerConfirmed()
Event callback from ISpinnerConfirmListener.
Definition: player_kart_widget.cpp:799
SpinnerWidget * m_player_ident_spinner
Sub-widgets created by this widget.
Definition: player_kart_widget.hpp:85
bool isReady()
Definition: player_kart_widget.cpp:499
void setSize(const int x, const int y, const int w, const int h)
Sets the size of the widget as a whole, and placed children widgets inside itself.
Definition: player_kart_widget.cpp:700
int target_x
For animation purposes (see method 'move')
Definition: player_kart_widget.hpp:62
virtual void add()
Add the widgets to the current screen.
Definition: player_kart_widget.cpp:348
int m_irrlicht_widget_id
A reserved ID for this widget if any, -1 otherwise.
Definition: player_kart_widget.hpp:59
int getPlayerID() const
Returns the ID of this player.
Definition: player_kart_widget.cpp:340
void setKartInternalName(const std::string &whichKart)
Sets which kart was selected for this player.
Definition: player_kart_widget.cpp:782
void onUpdate(float delta)
Updates the animation (moving/shrinking/etc.)
Definition: player_kart_widget.cpp:515
int player_name_x
widget coordinates
Definition: player_kart_widget.hpp:50
std::string spinnerID
Internal name of the spinner; useful to interpret spinner events, which contain the name of the activ...
Definition: player_kart_widget.hpp:72
StateManager::ActivePlayer * m_associated_player
Object representing this player.
Definition: player_kart_widget.hpp:67
void move(const int x, const int y, const int w, const int h)
Starts a 'move/resize' animation, by simply passing destination coords.
Definition: player_kart_widget.cpp:441
HandicapLevel getHandicap()
Definition: player_kart_widget.cpp:507
void setPlayerID(const int newPlayerID)
Called when players are renumbered (changes the player ID)
Definition: player_kart_widget.cpp:305
StateManager::ActivePlayer * getAssociatedPlayer()
Get the associated ActivePlayer object.
Definition: player_kart_widget.cpp:432
Definition: spinner_widget.hpp:47
A spinner or gauge widget (to select numbers / percentages).
Definition: spinner_widget.hpp:44
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_x
Coordinates of the widget once added (the difference between those x/h and PROP_WIDTH/PROP_HEIGHT is ...
Definition: widget.hpp:326
screen where players can choose their kart
Definition: kart_selection.hpp:53
Represents a player that is currently playing.
Definition: state_manager.hpp:76
A concrete scene manager, derived from GUIEngine's AbastractSceneManager.
Definition: state_manager.hpp:60
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33
HandicapLevel
Handicap per player.
Definition: remote_kart_info.hpp:43