Back to index

supertuxkart  0.5+dfsg1
race_gui.hpp
Go to the documentation of this file.
00001 //  $Id: race_gui.hpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2004-2005 Steve Baker <sjbaker1@airmail.net>
00005 //  Copyright (C) 2006 Joerg Henrichs, SuperTuxKart-Team, Steve Baker
00006 //
00007 //  This program is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU General Public License
00009 //  as published by the Free Software Foundation; either version 2
00010 //  of the License, or (at your option) any later version.
00011 //
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU General Public License
00018 //  along with this program; if not, write to the Free Software
00019 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 #ifndef HEADER_RACEGUI_H
00022 #define HEADER_RACEGUI_H
00023 
00024 #include <string>
00025 #include <vector>
00026 
00027 #include "base_gui.hpp"
00028 #include "kart.hpp"
00029 #include "material.hpp"
00030 #include "player_kart.hpp"
00031 #include "player.hpp"
00032 #include "world.hpp"
00033 #include "race_manager.hpp"
00034 
00035 class InputMap;
00036 class RaceSetup;
00037 
00038 class RaceGUI: public BaseGUI
00039 {
00040 
00041     class TimedMessage
00042     {
00043      public:
00044         std::string m_message;            // message to display
00045         float       m_end_time;           // end time for the message (-1 if once only)
00046         int         m_red,m_blue,m_green; // colour
00047         int         m_font_size;          // size
00048         Kart        *m_kart;
00049         // std::vector needs standard copy-ctor and std-assignment op.
00050         // let compiler create defaults .. they'll do the job, no
00051         // deep copies here ..
00052         TimedMessage(const char *message, 
00053                      Kart *kart, float time, int size, 
00054                      int red, int green, int blue)
00055         {
00056             m_message    = message; 
00057             m_font_size  = size;
00058             m_kart       = kart;
00059             m_end_time   = time>=0.0f 
00060                          ? (race_manager->getRaceMode()==RaceManager::RM_FOLLOW_LEADER 
00061                             ?world->getTime()-time
00062                             :world->getTime()+time )
00063                          : -1.0f;
00064             m_red=red; m_blue=blue; m_green=green; 
00065         }
00066         // in follow leader the clock counts backwards
00067         bool done() const {return m_end_time<0 || 
00068                            (race_manager->getRaceMode()==RaceManager::RM_FOLLOW_LEADER 
00069                                   ? world->getTime()<m_end_time
00070                                   : world->getTime()>m_end_time);}
00071     };
00072 public:
00073 
00074     RaceGUI();
00075     ~RaceGUI();
00076     void update(float dt);
00077     void select() {}
00078     void handle(GameAction, int);
00079     void handleKartAction(KartAction ka, int value);
00080     void addMessage(const char *message, Kart *kart, float time, int fonst_size,
00081                     int red=255, int green=0, int blue=255);
00082 
00083 private:
00084     ulClock     m_fps_timer;
00085     int         m_fps_counter;
00086     char        m_fps_string[10];
00087     const char* m_pos_string [11];
00088     Material*   m_steering_wheel_icon;
00089     Material*   m_speed_back_icon;
00090     Material* m_speed_fore_icon;
00091     typedef   std::vector<TimedMessage> AllMessageType;
00092     AllMessageType m_messages;
00093 
00094     /* Display informat on screen */
00095     void drawStatusText        (const float dt);
00096     void drawEnergyMeter       (Kart *player_kart,
00097                                 int   offset_x, int   offset_y,
00098                                 float ratio_x,  float ratio_y  );
00099     void drawCollectableIcons  (Kart* player_kart,
00100                                 int   offset_x, int   offset_y,
00101                                 float ratio_x,  float ratio_y  );
00102     void drawAllMessages       (Kart* player_kart,
00103                                 int   offset_x, int   offset_y,
00104                                 float ratio_x,  float ratio_y  );
00105     void drawPlayerIcons       ();
00106     void oldDrawPlayerIcons    ();
00107     void drawMap               ();
00108     void drawTimer             ();
00109     void drawFPS               ();
00110     void drawMusicDescription  ();
00111     void cleanupMessages       ();
00112 
00113     /* Text drawing */
00117     void drawSteering             (Kart* kart, int offset_x, int offset_y,
00118                                    float ratio_x, float ratio_y           );
00119     void drawPosition             (Kart* kart, int offset_x, int offset_y,
00120                                    float ratio_x, float ratio_y           );
00121     void drawSpeed                (Kart* kart, int offset_x, int offset_y,
00122                                    float ratio_x, float ratio_y           );
00123     void drawLap                  (Kart* kart, int offset_x, int offset_y,
00124                                    float ratio_x, float ratio_y           );
00125 };
00126 
00127 #endif