Team Fortress 2 Source Code as on 22/4/2020
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.

275 lines
9.3 KiB

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