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.

273 lines
5.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: CLCD Manages the Logitech G-Series Gaming Keyboard LCD
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef HUD_LCD_H
  8. #define HUD_LCD_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tier1/utlvector.h"
  13. #include "tier1/utlstring.h"
  14. #include "tier1/utldict.h"
  15. #include "ihudlcd.h"
  16. class KeyValues;
  17. class IG15;
  18. class C_BasePlayer;
  19. enum
  20. {
  21. LCDITEM_UNKNOWN = 0,
  22. LCDITEM_PAGE,
  23. LCDITEM_TEXT,
  24. LCDITEM_ICON,
  25. LCDITEM_AGGREGATE, // Made up of subitems
  26. };
  27. // Aggregate item types
  28. enum
  29. {
  30. AGGTYPE_UNKNOWN = 0,
  31. AGGTYPE_PERPLAYER,
  32. AGGTYPE_PERTEAM,
  33. };
  34. class CLCDItem
  35. {
  36. public:
  37. CLCDItem() :
  38. m_bActive( true ),
  39. m_nSubPage( 0 ),
  40. m_Type( LCDITEM_UNKNOWN ),
  41. m_Handle( 0 ),
  42. x( 0 ),
  43. y( 0 ),
  44. w( 0 ),
  45. h( 0 )
  46. {
  47. }
  48. virtual ~CLCDItem() {}
  49. virtual void Create( IG15 *lcd ) = 0;
  50. virtual void Wipe( IG15 *lcd );
  51. bool m_bActive;
  52. int m_Type;
  53. void *m_Handle;
  54. int x, y, w, h;
  55. int m_nSubPage;
  56. CUtlVector< CLCDItem * > m_Children;
  57. };
  58. class CLCDItemText : public CLCDItem
  59. {
  60. typedef CLCDItem BaseClass;
  61. public:
  62. CLCDItemText() :
  63. m_bHasWildcard( false ),
  64. m_iSize( 0 ),
  65. m_iAlign( 0 )
  66. {
  67. m_Type = LCDITEM_TEXT;
  68. }
  69. virtual void Create( IG15 *lcd );
  70. CUtlString m_OriginalText;
  71. bool m_bHasWildcard;
  72. int m_iSize;
  73. int m_iAlign;
  74. };
  75. class CLCDItemIcon : public CLCDItem
  76. {
  77. typedef CLCDItem BaseClass;
  78. public:
  79. CLCDItemIcon() :
  80. m_icon( NULL )
  81. {
  82. m_Type = LCDITEM_ICON;
  83. }
  84. virtual void Create( IG15 *lcd );
  85. CUtlString m_IconName;
  86. void *m_icon;
  87. };
  88. class CLCDItemAggregate : public CLCDItem
  89. {
  90. typedef CLCDItem BaseClass;
  91. public:
  92. CLCDItemAggregate() :
  93. m_AggType( AGGTYPE_UNKNOWN ),
  94. m_dwNextUpdateTime( 0 ),
  95. m_yincrement( 0 )
  96. {
  97. m_Type = LCDITEM_AGGREGATE;
  98. }
  99. virtual void Create( IG15 *lcd );
  100. virtual void Wipe( IG15 *lcd );
  101. void WipeChildrenOnly( IG15 *lcd );
  102. unsigned int m_dwNextUpdateTime;
  103. int m_AggType;
  104. int m_yincrement;
  105. // Representative row
  106. CUtlVector< CLCDItem * > m_Definition;
  107. };
  108. class CLCDPage : public CLCDItem
  109. {
  110. public:
  111. CLCDPage() :
  112. m_bSubItem( false ),
  113. m_bTitlePage( false ),
  114. m_bRequiresPlayer( false ),
  115. m_nSubPageCount( 1 )
  116. {
  117. m_Type = LCDITEM_PAGE;
  118. }
  119. ~CLCDPage()
  120. {
  121. }
  122. virtual void Create( IG15 *lcd )
  123. {
  124. }
  125. CLCDItem *Alloc( int type )
  126. {
  127. CLCDItem *item = NULL;
  128. switch ( type )
  129. {
  130. default:
  131. break;
  132. case LCDITEM_PAGE:
  133. // This shouldn't occur
  134. break;
  135. case LCDITEM_TEXT:
  136. item = new CLCDItemText();
  137. break;
  138. case LCDITEM_ICON:
  139. item = new CLCDItemIcon();
  140. break;
  141. case LCDITEM_AGGREGATE:
  142. item = new CLCDItemAggregate();
  143. break;
  144. }
  145. if ( item )
  146. {
  147. return item;
  148. }
  149. Assert( 0 );
  150. return NULL;
  151. }
  152. void InitFromKeyValues( KeyValues *kv );
  153. bool m_bSubItem;
  154. bool m_bTitlePage;
  155. bool m_bRequiresPlayer;
  156. int m_nSubPageCount;
  157. };
  158. //-----------------------------------------------------------------------------
  159. // Purpose: Manages the Logitech G-Series Gaming Keyboard LCD
  160. //-----------------------------------------------------------------------------
  161. class CLCD : public IHudLCD
  162. {
  163. public:
  164. CLCD();
  165. ~CLCD();
  166. // Implement IHudLCD
  167. virtual void SetGlobalStat( char const *name, char const *value );
  168. virtual void AddChatLine( char const *txt );
  169. // Exposed as a ConCommand
  170. void Reload();
  171. void DumpPlayer();
  172. public:
  173. // Init's called when the HUD's created at DLL load
  174. void Init( void );
  175. void Shutdown();
  176. void Update( void );
  177. bool IsConnected() const;
  178. private:
  179. CLCDItemIcon *ParseItemIcon( CLCDPage *page, bool bCreateHandles, KeyValues *sub );
  180. CLCDItemText *ParseItemText( CLCDPage *page, bool bCreateHandles, KeyValues *sub );
  181. void ParseItems_R( CLCDPage *page, bool bCreateHandles, KeyValues *kv, CUtlVector< CLCDItem * >& list );
  182. void ParsePage( KeyValues *kv );
  183. void ParseIconMappings( KeyValues *kv );
  184. void ParseReplacements( KeyValues *kv );
  185. void DisplayCurrentPage( unsigned int dwCurTime );
  186. void ShowItems_R( CLCDPage *page, unsigned int dwCurTime, CUtlVector< CLCDItem * >& list, bool show );
  187. int FindTitlePage();
  188. void BuildUpdatedText( char const *in, CUtlString& out );
  189. void LookupToken( char const *token, CUtlString& value );
  190. bool ExtractArrayIndex( char *str, size_t bufsize, int *index );
  191. bool Replace( CUtlString& str, char const *search, char const *replace );
  192. void DoGlobalReplacements( CUtlString& str );
  193. void ReduceParentheses( CUtlString& str );
  194. bool IsPageValid( int currentPage, C_BasePlayer *player );
  195. void UpdateChat();
  196. IG15 *m_lcd ;
  197. CUtlString m_Title;
  198. int m_Size[ 2 ];
  199. CUtlVector< CLCDPage * > m_Pages;
  200. int m_nCurrentPage;
  201. int m_nSubPage;
  202. int m_nMaxChatHistory;
  203. CUtlDict< int, int > m_TextSizes;
  204. CUtlDict< int, int > m_TextAlignments;
  205. struct IconInfo_t
  206. {
  207. void *m_handle;
  208. };
  209. CUtlDict< IconInfo_t, int > m_Icons;
  210. bool m_bHadPlayer;
  211. CUtlDict< CUtlString, int > m_GlobalStats;
  212. CUtlVector< CUtlString > m_ChatHistory;
  213. unsigned int m_dwNextUpdateTime;
  214. CSysModule *m_pG15Module;
  215. CreateInterfaceFn m_G15Factory;
  216. };
  217. extern CLCD gLCD;
  218. #endif // HUD_LCD_H