SuperTuxKart
race_gui_base.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2010-2015 Joerg Henrichs
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 HEADER_RACE_GUI_BASE_HPP
20 #define HEADER_RACE_GUI_BASE_HPP
21 
22 #include <vector>
23 
24 #include <irrString.h>
25 #include <vector2d.h>
26 #include <rect.h>
27 #include <dimension2d.h>
28 #include <SColor.h>
29 namespace irr
30 {
31  namespace video { class ITexture; struct S3DVertex; }
32  namespace scene { class IAnimatedMeshSceneNode; }
33 }
34 using namespace irr;
35 
36 #include "utils/vec3.hpp"
37 
38 class AbstractKart;
39 class Camera;
40 class Material;
41 class Referee;
42 class RaceGUIMultitouch;
43 
50 {
51 public:
57  {
59  core::stringw m_text;
60 
62  video::SColor m_color;
63 
65  core::stringw special_title;
66 
68  int lap;
69 
70  bool m_outlined_font = false;
71  }; // KartIconDisplayInfo
72 
73 private:
77 
79  {
80  public:
82  irr::core::stringw m_message;
86  video::SColor m_color;
87 
88  const AbstractKart *m_kart;
91  bool m_big_font;
92 
93  bool m_outline;
94 
95  // -----------------------------------------------------
96  // std::vector needs standard copy-ctor and std-assignment op.
97  // let compiler create defaults .. they'll do the job, no
98  // deep copies here ..
99  TimedMessage(const irr::core::stringw &message,
100  const AbstractKart *kart, float time,
101  const video::SColor &color, const bool important,
102  bool big_font, bool outline)
103  {
104  m_message = message;
105  m_kart = kart;
106  m_remaining_time = ( time < 0.0f ) ? -1.0f : time;
107  m_color = color;
108  m_important = important;
109  m_big_font = big_font;
110  m_outline = outline;
111  } // TimedMessage
112  // -----------------------------------------------------
113  // in follow leader the clock counts backwards
114  bool done(const float dt)
115  {
116  m_remaining_time -= dt;
117  return m_remaining_time < 0;
118  } // done
119  }; // TimedMessage
120  // ---------------------------------------------------------
121 
122  typedef std::vector<TimedMessage> AllMessageType;
123  AllMessageType m_messages;
124  int m_small_font_max_height;
125 
128 
130  video::ITexture* m_music_icon;
131 
133  video::ITexture* m_plunger_face;
134 
136  core::stringw m_string_ready, m_string_set, m_string_go, m_string_goal,
137  m_string_waiting_for_others, m_string_waiting_for_the_server;
138 
140  std::vector<Vec3> m_referee_pos;
141 
143  std::vector<Vec3> m_referee_rotation;
144 
149 
152 
153  /* True if spectating is possible in current GUI (when local player
154  * finished). */
155  bool m_enabled_network_spectator;
156 
157  /* this flag is set to true if we show at least one custom color for other karts
158  * in that case we want to draw a bigger circle around the player's own kart
159  * to make it easier for the player to identify */
160  bool m_showing_kart_colors;
161 protected:
162 
167  enum PlungerState {PLUNGER_STATE_INIT, PLUNGER_STATE_SLOW_1,
168  PLUNGER_STATE_SLOW_2, PLUNGER_STATE_FAST}
169  m_plunger_state;
170 
173 
175  core::vector2di m_plunger_offset;
176 
177  /* Speed of the plunger. This gets changed depending on state (not moving,
178  * slow moving, fast moving). */
179  core::vector2df m_plunger_speed;
180 
182  //int m_marker_rendered_size;
183 
185  //video::ITexture *m_marker;
186  video::ITexture *m_gauge_empty;
188  video::ITexture *m_gauge_full;
190  video::ITexture *m_gauge_full_bright;
191 
192  video::ITexture *m_gauge_goal;
193 
195  video::ITexture* m_icons_frame;
196 
198  video::ITexture* m_icons_kart_list;
199 
201  video::ITexture* m_lap_flag;
202 
203  RaceGUIMultitouch* m_multitouch_gui;
204 
205  //void createMarkerTexture();
206  void createRegularPolygon(unsigned int n, float radius,
207  const core::vector2df &center,
208  const video::SColor &color,
209  video::S3DVertex *v, unsigned short int *index);
210  void drawAllMessages (const AbstractKart* kart,
211  const core::recti &viewport,
212  const core::vector2df &scaling);
213  void drawPowerupIcons (const AbstractKart* kart,
214  const core::recti &viewport,
215  const core::vector2df &scaling);
216  void drawGlobalMusicDescription();
217  void drawGlobalReadySetGo();
218  void drawGlobalGoal();
219  void drawPlungerInFace(const Camera *camera, float dt);
223  void ignoreUnimportantMessages() { m_ignore_unimportant_messages = true; }
224 
228 
230  std::vector< core::vector2d<s32> > m_previous_icons_position;
231 
234  std::vector<KartIconDisplayInfo> m_kart_display_infos;
235 
236 public:
237 
238  bool m_enabled;
239 
240  RaceGUIBase();
241  virtual ~RaceGUIBase();
242  virtual void renderGlobal(float dt);
243  virtual void init();
244  virtual void reset();
245  virtual void renderPlayerView(const Camera *camera, float dt);
246  virtual void addMessage(const irr::core::stringw &m,
247  const AbstractKart *kart, float time,
248  const video::SColor &color=
249  video::SColor(255, 255, 0, 255),
250  bool important=true,
251  bool big_font=false, bool outline=false);
252  virtual void update(float dt);
253  virtual void preRenderCallback(const Camera *camera);
254  // ------------------------------------------------------------------------
256  virtual const core::dimension2du
257  getMiniMapSize() const = 0;
258  virtual void calculateMinimapSize() {};
259  // ------------------------------------------------------------------------
260  virtual void clearAllMessages() { m_messages.clear(); }
261 
262  void drawGlobalPlayerIcons(int bottom_margin);
263  void drawPlayerIcon(AbstractKart *kart, int x, int y, int w,
264  bool is_local);
265 
266  virtual void drawEnergyMeter(int x, int y, const AbstractKart *kart,
267  const core::recti &viewport,
268  const core::vector2df &scaling) {};
269 
270  void cleanupMessages(const float dt);
271  void removeReferee();
272 
273  RaceGUIMultitouch* getMultitouchGUI() {return m_multitouch_gui;}
274  void recreateGUI();
275  virtual void initSize();
276 
277 }; // RaceGUIBase
278 
279 #endif
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
This is the base class for all cameras.
Definition: camera.hpp:49
Definition: material.hpp:48
Definition: race_gui_base.hpp:79
bool m_important
Important msgs are displayed in the middle of the screen.
Definition: race_gui_base.hpp:90
video::SColor m_color
Color of message.
Definition: race_gui_base.hpp:86
irr::core::stringw m_message
Message to display.
Definition: race_gui_base.hpp:82
float m_remaining_time
Time remaining before removing this message from screen.
Definition: race_gui_base.hpp:84
An abstract base class for the two race guis (race_gui and race_result gui)
Definition: race_gui_base.hpp:50
int m_max_font_height
Used to display messages without overlapping.
Definition: race_gui_base.hpp:127
video::ITexture * m_plunger_face
Texture for the 'plunger in the face' texture.
Definition: race_gui_base.hpp:133
std::vector< KartIconDisplayInfo > m_kart_display_infos
This vector is passed to world to be filled with the current race data information.
Definition: race_gui_base.hpp:234
video::ITexture * m_music_icon
Musical notes icon (for music description and credits)
Definition: race_gui_base.hpp:130
void ignoreUnimportantMessages()
Instructs the base gui to ignore unimportant messages (like item messages).
Definition: race_gui_base.hpp:223
std::vector< Vec3 > m_referee_rotation
The actual rotation to use for the referee for each kart.
Definition: race_gui_base.hpp:143
float m_referee_height
The height of the referee.
Definition: race_gui_base.hpp:148
video::ITexture * m_gauge_full
Default texture for nitro gauge.
Definition: race_gui_base.hpp:188
float m_icons_inertia
can be zero
Definition: race_gui_base.hpp:227
core::stringw m_string_ready
Translated strings 'ready', 'set', 'go'.
Definition: race_gui_base.hpp:136
PlungerState
State of the plunger: From the 'init' states the plunger switches between two slow moving states ('sh...
Definition: race_gui_base.hpp:167
float m_plunger_move_time
How long the plunger should stay in the current state.
Definition: race_gui_base.hpp:172
bool m_ignore_unimportant_messages
True if unimportant messags (like item messages) should not be displayed.
Definition: race_gui_base.hpp:76
std::vector< Vec3 > m_referee_pos
The position of the referee for all karts.
Definition: race_gui_base.hpp:140
video::ITexture * m_gauge_empty
The size of a single marker in pixels, must be a power of 2.
Definition: race_gui_base.hpp:186
video::ITexture * m_icons_kart_list
The frame around player karts in the kart list.
Definition: race_gui_base.hpp:198
Referee * m_referee
The referee scene node.
Definition: race_gui_base.hpp:151
virtual const core::dimension2du getMiniMapSize() const =0
Returns the size of the texture on which to render the minimap to.
float m_dist_show_overlap
Distance on track to begin showing overlap in drawGlobalPlayerIcons.
Definition: race_gui_base.hpp:226
video::ITexture * m_gauge_full_bright
Highlight gauge, used when a kart uses nitro.
Definition: race_gui_base.hpp:190
video::ITexture * m_icons_frame
The frame around player karts in the mini map.
Definition: race_gui_base.hpp:195
std::vector< core::vector2d< s32 > > m_previous_icons_position
can be zero
Definition: race_gui_base.hpp:230
video::ITexture * m_lap_flag
Texture for the lap icon.
Definition: race_gui_base.hpp:201
core::vector2di m_plunger_offset
Offset of the plunger.
Definition: race_gui_base.hpp:175
Definition: race_gui_multitouch.hpp:39
This implements the referee, a character that is displayed at the start of the race holding a 'ready-...
Definition: referee.hpp:53
Used to display the list of karts and their times or whatever other info is relevant to the current m...
Definition: race_gui_base.hpp:57
core::stringw special_title
If this kart has a special title, e.g.
Definition: race_gui_base.hpp:65
video::SColor m_color
Text color, if any text.
Definition: race_gui_base.hpp:62
core::stringw m_text
Text to display next to icon, if any.
Definition: race_gui_base.hpp:59
int lap
Current lap of this kart, or -1 if irrelevant.
Definition: race_gui_base.hpp:68