Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
9.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: MiniMap.h: interface for the CMiniMap class.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #if !defined HLTVPANEL_H
  8. #define HLTVPANEL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui_controls/Panel.h>
  13. #include <game/client/iviewport.h>
  14. #include "mathlib/vector.h"
  15. #include <igameevents.h>
  16. #include <shareddefs.h>
  17. #include <const.h>
  18. #include "hudelement.h"
  19. typedef struct MapObject_s {
  20. int objectID; // unique object ID
  21. int index; // entity index if any
  22. int icon; // players texture icon ID
  23. Color color; // players team color
  24. char name[MAX_PLAYER_NAME_LENGTH]; // show text under icon
  25. Vector position; // current x,y pos
  26. QAngle angle; // view origin 0..360
  27. float endtime; // time stop showing object
  28. float size; // object size
  29. float status; // green status bar [0..1], -1 = disabled
  30. Color statusColor; // color of status bar
  31. int flags; // MAB_OBJECT_*
  32. Color iconColor;
  33. const char *text; // text to draw underneath the icon
  34. } MapObject_t;
  35. class IMapOverviewPanel
  36. {
  37. public:
  38. virtual void SetMode( int mode ) = 0;
  39. virtual int GetMode( void ) = 0;
  40. virtual void FlashEntity( int entityID ) = 0;
  41. virtual void SetPlayerPositions(int index, const Vector &position, const QAngle &angle) = 0;
  42. virtual void SetVisible(bool state) = 0;
  43. virtual float GetZoom( void ) = 0;
  44. virtual vgui::Panel *GetAsPanel() = 0;
  45. virtual bool AllowConCommandsWhileAlive() = 0;
  46. virtual void SetPlayerPreferredMode( int mode ) = 0;
  47. virtual void SetPlayerPreferredViewSize( float viewSize ) = 0;
  48. virtual bool IsVisible() = 0;
  49. virtual void GetBounds(int &x, int &y, int &wide, int &tall) = 0;
  50. virtual float GetFullZoom( void ) = 0;
  51. virtual float GetMapScale( void ) = 0;
  52. };
  53. #define MAX_TRAIL_LENGTH 30
  54. #define OVERVIEW_MAP_SIZE 1024 // an overview map is 1024x1024 pixels
  55. typedef bool ( *FnCustomMapOverviewObjectPaint )( int textureID, Vector pos, float scale, float angle, const char *text, Color *textColor, float status, Color *statusColor );
  56. class CMapOverview : public CHudElement, public vgui::Panel, public IMapOverviewPanel
  57. {
  58. DECLARE_CLASS_SIMPLE( CMapOverview, vgui::Panel );
  59. public:
  60. enum
  61. {
  62. MAP_MODE_OFF = 0, // Totally off
  63. MAP_MODE_INSET, // A little map up in a corner
  64. MAP_MODE_FULL, // Full screen, full map
  65. MAP_MODE_RADAR // In game radar, extra functionality
  66. };
  67. CMapOverview( const char *pElementName );
  68. virtual ~CMapOverview();
  69. virtual bool ShouldDraw( void );
  70. vgui::Panel *GetAsPanel(){ return this; }
  71. virtual bool AllowConCommandsWhileAlive(){return true;}
  72. virtual void SetPlayerPreferredMode( int mode ){}
  73. virtual void SetPlayerPreferredViewSize( float viewSize ){};
  74. protected: // private structures & types
  75. float GetViewAngle( void ); // The angle that determines the viewport twist from map texture to panel drawing.
  76. // list of game events the hLTV takes care of
  77. typedef struct {
  78. int xpos;
  79. int ypos;
  80. } FootStep_t;
  81. typedef struct MapPlayer_s {
  82. int index; // player's index
  83. int userid; // user ID on server
  84. int icon; // players texture icon ID
  85. Color color; // players team color
  86. char name[MAX_PLAYER_NAME_LENGTH];
  87. int team; // N,T,CT
  88. int health; // 0..100, 7 bit
  89. Vector position; // current x,y pos
  90. QAngle angle; // view origin 0..360
  91. Vector2D trail[MAX_TRAIL_LENGTH]; // save 1 footstep each second for 1 minute
  92. } MapPlayer_t;
  93. #define MAP_OBJECT_ALIGN_TO_MAP (1<<0)
  94. #define MAP_OBJECT_DONT_DRAW (1<<1)
  95. public: // IViewPortPanel interface:
  96. virtual const char *GetName( void ) { return PANEL_OVERVIEW; }
  97. virtual void SetData(KeyValues *data);
  98. virtual void Reset();
  99. virtual void OnThink();
  100. virtual void Update();
  101. virtual bool NeedsUpdate( void );
  102. virtual bool HasInputElements( void ) { return false; }
  103. virtual void ShowPanel( bool bShow );
  104. virtual void Init( void );
  105. // both vgui::Frame and IViewPortPanel define these, so explicitly define them here as passthroughs to vgui
  106. vgui::VPANEL GetVPanel( void ) { return BaseClass::GetVPanel(); }
  107. virtual bool IsVisible() { return BaseClass::IsVisible(); }
  108. virtual void GetBounds(int &x, int &y, int &wide, int &tall) { BaseClass::GetBounds(x, y, wide, tall); }
  109. virtual void SetParent(vgui::VPANEL parent) { BaseClass::SetParent(parent); }
  110. public: // IGameEventListener
  111. virtual void FireGameEvent( IGameEvent *event);
  112. public: // VGUI overrides
  113. virtual void Paint();
  114. virtual void OnMousePressed( vgui::MouseCode code );
  115. virtual void ApplySchemeSettings(vgui::IScheme *scheme);
  116. virtual void SetVisible(bool state){BaseClass::SetVisible(state);}
  117. public:
  118. virtual float GetZoom( void );
  119. virtual int GetMode( void );
  120. virtual float GetFullZoom( void ){ return m_fFullZoom; }
  121. virtual float GetMapScale( void ){ return m_fMapScale; }
  122. // Player settings:
  123. virtual void ShowPlayerNames(bool state);
  124. virtual void ShowPlayerHealth(bool state);
  125. virtual void ShowPlayerTracks(float seconds);
  126. virtual void SetPlayerPositions(int index, const Vector &position, const QAngle &angle);
  127. // general settings:
  128. virtual void SetMap(const char * map);
  129. virtual void SetTime( float time );
  130. virtual void SetMode( int mode );
  131. virtual bool SetTeamColor(int team, Color color);
  132. virtual void SetFollowAngle(bool state);
  133. virtual void SetFollowEntity(int entindex); // 0 = off
  134. virtual void SetCenter( const Vector2D &mappos);
  135. virtual void SetAngle( float angle);
  136. virtual Vector2D WorldToMap( const Vector &worldpos );
  137. Vector2D MapToPanel( const Vector2D &mappos );
  138. // Object settings
  139. virtual int AddObject( const char *icon, int entity, float timeToLive ); // returns object ID, 0 = no entity, -1 = forever
  140. virtual void SetObjectIcon( int objectID, const char *icon, float size ); // icon world size
  141. virtual void SetObjectText( int objectID, const char *text, Color color ); // text under icon
  142. virtual void SetObjectStatus( int objectID, float value, Color statusColor ); // status bar under icon
  143. virtual void SetObjectPosition( int objectID, const Vector &position, const QAngle &angle ); // world pos/angles
  144. virtual void SetObjectIconColor( int objectID, Color color );
  145. virtual void AddObjectFlags( int objectID, int flags );
  146. virtual void SetObjectFlags( int objectID, int flags );
  147. virtual void RemoveObject( int objectID );
  148. virtual void RemoveObjectByIndex( int index );
  149. virtual void FlashEntity( int entityID ){}
  150. // rules that define if you can see a player on the overview or not
  151. virtual bool CanPlayerBeSeen(MapPlayer_t *player);
  152. /// allows mods to restrict health
  153. virtual bool CanPlayerHealthBeSeen(MapPlayer_t *player);
  154. /// allows mods to restrict names (e.g. CS when mp_playerid is non-zero)
  155. virtual bool CanPlayerNameBeSeen(MapPlayer_t *player);
  156. virtual int GetIconNumberFromTeamNumber( int teamNumber ){return teamNumber;}
  157. MapObject_t* FindObjectByIndex(int objectIndex);
  158. protected:
  159. virtual void DrawCamera();
  160. virtual void DrawObjects();
  161. virtual void DrawMapTexture();
  162. virtual void DrawMapPlayers();
  163. virtual void DrawMapPlayerTrails();
  164. virtual void UpdatePlayerTrails();
  165. virtual void ResetRound();
  166. virtual void InitTeamColorsAndIcons();
  167. virtual void UpdateSizeAndPosition();
  168. virtual bool RunHudAnimations(){ return true; }
  169. bool IsInPanel(Vector2D &pos);
  170. MapPlayer_t* GetPlayerByUserID( int userID );
  171. int AddIconTexture(const char *filename);
  172. int GetPixelOffset( float height );
  173. void UpdateFollowEntity();
  174. virtual void UpdatePlayers();
  175. virtual void UpdateObjects(); // objects bound to entities
  176. MapObject_t* FindObjectByID(int objectID);
  177. virtual bool IsRadarLocked() {return false;}
  178. virtual bool DrawIcon( MapObject_t *obj );
  179. /*virtual bool DrawIcon( int textureID,
  180. int offscreenTextureID,
  181. Vector pos,
  182. float scale,
  183. float angle,
  184. int alpha = 255,
  185. const char *text = NULL,
  186. Color *textColor = NULL,
  187. float status = -1,
  188. Color *statusColor = NULL,
  189. int objectType = OBJECT_TYPE_NORMAL );*/
  190. int m_nMode;
  191. Vector2D m_vPosition;
  192. Vector2D m_vSize;
  193. float m_flChangeSpeed;
  194. float m_flIconSize;
  195. IViewPort * m_pViewPort;
  196. MapPlayer_t m_Players[MAX_PLAYERS];
  197. CUtlDict< int, int> m_TextureIDs;
  198. CUtlVector<MapObject_t> m_Objects;
  199. Color m_TeamColors[MAX_TEAMS];
  200. int m_TeamIcons[MAX_TEAMS];
  201. int m_ObjectIcons[64];
  202. int m_ObjectCounterID;
  203. vgui::HFont m_hIconFont;
  204. bool m_bShowNames;
  205. bool m_bShowTrails;
  206. bool m_bShowHealth;
  207. int m_nMapTextureID; // texture id for current overview image
  208. KeyValues * m_MapKeyValues; // keyvalues describing overview parameters
  209. Vector m_MapOrigin; // read from KeyValues files
  210. float m_fMapScale; // origin and scale used when screenshot was made
  211. bool m_bRotateMap; // if true roatate map around 90 degress, so it fits better to 4:3 screen ratio
  212. int m_nFollowEntity;// entity number to follow, 0 = off
  213. CPanelAnimationVar( float, m_fZoom, "zoom", "1.0" ); // current zoom n = overview panel shows 1/n^2 of whole map'
  214. float m_fFullZoom; // best zoom factor for full map view (1.0 is map is a square)
  215. Vector2D m_ViewOrigin; // map coordinates that are in the center of the pverview panel
  216. Vector2D m_MapCenter; // map coordinates that are in the center of the pverview panel
  217. float m_fNextUpdateTime;
  218. float m_fViewAngle; // rotation of overview map
  219. float m_fWorldTime; // current world time
  220. float m_fNextTrailUpdate; // next time to update player trails
  221. float m_fTrailUpdateInterval; // if -1 don't show trails
  222. bool m_bFollowAngle; // if true, map rotates with view angle
  223. };
  224. IMapOverviewPanel *GetMapOverView();
  225. void SetMapOverView( int nSlot, IMapOverviewPanel *pPanel );
  226. #endif //