1 //
2 //  SuperTuxKart - a fun racing game with go-kart
3 //  Copyright (C) 2004-2015 Steve Baker <sjbaker1@airmail.net>
4 //  Copyright (C) 2006-2015 Joerg Henrichs, SuperTuxKart-Team, Steve Baker
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 3
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 
20 #ifndef HEADER_RACE_GUI_HPP
21 #define HEADER_RACE_GUI_HPP
22 
23 #include <string>
24 #include <vector>
25 
26 #include <irrString.h>
27 using namespace irr;
28 
29 #include "states_screens/race_gui_base.hpp"
30 
31 class AbstractKart;
32 class InputMap;
33 class Material;
34 class RaceSetup;
35 
36 /**
37   * \brief Handles the in-race GUI (messages, mini-map, rankings, timer, etc...)
38   * \ingroup states_screens
39   */
40 class RaceGUI : public RaceGUIBase
41 {
42 private:
43 
44     Material        *m_speed_meter_icon;
45     Material        *m_speed_bar_icon;
46 
47     // Minimap related variables
48     // -------------------------
49     /** The size of a single marker on the screen for AI karts,
50      *  need not be a power of 2. */
51     int              m_minimap_ai_size;
52 
53     /** The size of a single marker on the screen or player karts,
54      *  need not be a power of 2. */
55     int              m_minimap_player_size;
56 
57     /** The width of the rendered mini map in pixels, must be a power of 2. */
58     int              m_map_rendered_width;
59 
60     /** The height of the rendered mini map in pixels, must be a power of 2. */
61     int              m_map_rendered_height;
62 
63     /** Width of the map in pixels on the screen, need not be a power of 2. */
64     int              m_map_width;
65 
66     /** Height of the map in pixels on the screen, need not be a power of 2. */
67     int              m_map_height;
68 
69     /** Distance of map from left side of screen. */
70     int              m_map_left;
71 
72     /** Distance of map from bottom of screen. */
73     int              m_map_bottom;
74 
75     /** Maximum lap display length (either 9/9  or 99/99). */
76     int              m_lap_width;
77 
78     /** Maximum string length for the timer */
79     int              m_timer_width;
80 
81     /** Maximum string length for a small precise timer
82      *  (like the live difference timer under a minute) */
83     int              m_small_precise_timer_width;
84 
85     /** Maximum string length for a big precise timer
86      *  (like the live difference timer over a minute) */
87     int              m_big_precise_timer_width;
88 
89     int              m_negative_timer_additional_width;
90 
91     /** Height of the digit font. */
92     int              m_font_height;
93 
94     /** Icon textures (stored as variables to not look up
95         their location on every frame) */
96     irr::video::ITexture *m_red_team;
97     irr::video::ITexture *m_blue_team;
98     irr::video::ITexture *m_red_flag;
99     irr::video::ITexture *m_blue_flag;
100     irr::video::ITexture *m_soccer_ball;
101     irr::video::ITexture *m_heart_icon;
102     irr::video::ITexture *m_basket_ball_icon;
103     /** Texture for the hit limit icon*/
104     irr::video::ITexture* m_champion;
105 
106     /** Animation state: none, getting smaller (old value),
107      *  getting bigger (new number). */
108     enum AnimationState {AS_NONE, AS_SMALLER, AS_BIGGER};
109     std::vector<AnimationState> m_animation_states;
110 
111     /** How long the rank animation has been shown. */
112     std::vector<float> m_rank_animation_duration;
113 
114     /** Stores the previous rank for each kart. Used for the rank animation. */
115     std::vector<int> m_last_ranks;
116 
117     bool m_is_tutorial;
118 
119     /* Display informat for one player on the screen. */
120     void drawEnergyMeter       (int x, int y, const AbstractKart *kart,
121                                 const core::recti &viewport,
122                                 const core::vector2df &scaling);
123     void drawSpeedEnergyRank   (const AbstractKart* kart,
124                                 const core::recti &viewport,
125                                 const core::vector2df &scaling, float dt);
126     void drawLap               (const AbstractKart* kart,
127                                 const core::recti &viewport,
128                                 const core::vector2df &scaling);
129     void drawRank              (const AbstractKart *kart,
130                                 const core::vector2df &offset,
131                                 float min_ratio, int meter_width,
132                                 int meter_height, float dt);
133 
134     /* Helper functions for drawing meters */
135 
136     void drawMeterTexture(video::ITexture *meter_texture, video::S3DVertex vertices[], unsigned int count);
137 
138     unsigned int computeVerticesForMeter(core::vector2df position[], float threshold[], video::S3DVertex vertices[],
139                                          unsigned int vertices_count, float measure, int gauge_width,
140                                          int gauge_height, core::vector2df offset);
141 
142     /** Display items that are shown once only (for all karts). */
143     void drawGlobalMiniMap     ();
144     void drawGlobalTimer       ();
145     void drawLiveDifference    ();
146 
147 public:
148 
149          RaceGUI();
150         ~RaceGUI();
151     virtual void init();
152     virtual void reset();
153     virtual void renderGlobal(float dt);
154     virtual void renderPlayerView(const Camera *camera, float dt);
155 
156     /** Returns the size of the texture on which to render the minimap to. */
getMiniMapSize() const157     virtual const core::dimension2du getMiniMapSize() const
158                   { return core::dimension2du(m_map_width, m_map_height); }
159     virtual void initSize();
160     virtual void calculateMinimapSize();
161 };   // RaceGUI
162 
163 #endif
164