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.

367 lines
11 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef DIALOGMENU_H
  8. #define DIALOGMENU_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #if defined(_WIN32) && !defined(_X360)
  13. #include "winlite.h" // FILETIME
  14. #endif
  15. #include "vgui_controls/Panel.h"
  16. #include "vgui_controls/Frame.h"
  17. class IAchievement;
  18. #define MAX_COMMAND_LEN 256
  19. #define MAX_COLUMNS 32
  20. class CDialogMenu;
  21. class CBaseDialog;
  22. struct sessionProperty_t
  23. {
  24. static const int MAX_KEY_LEN = 64;
  25. byte nType;
  26. char szID[MAX_KEY_LEN];
  27. char szValue[MAX_KEY_LEN];
  28. char szValueType[MAX_KEY_LEN];
  29. };
  30. //-----------------------------------------------------------------------
  31. // Base class representing a generic menu item. Supports two text labels,
  32. // where the first label is the "action" text and the second is an optional
  33. // description of the action.
  34. //-----------------------------------------------------------------------
  35. class CMenuItem : public vgui::EditablePanel
  36. {
  37. DECLARE_CLASS_SIMPLE( CMenuItem, vgui::EditablePanel );
  38. public:
  39. CMenuItem( CDialogMenu *pParent, const char *pTitle, const char *pDescription );
  40. virtual ~CMenuItem();
  41. virtual void PerformLayout();
  42. virtual void ApplySettings( KeyValues *pSettings );
  43. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  44. virtual void SetFocus( const bool bActive );
  45. virtual void SetEnabled( bool bEnabled );
  46. virtual void SetActiveColumn( int col );
  47. virtual bool IsEnabled();
  48. virtual void OnClick();
  49. protected:
  50. CDialogMenu *m_pParent;
  51. vgui::Label *m_pTitle;
  52. vgui::Label *m_pDescription;
  53. Color m_BgColor;
  54. Color m_BgColorActive;
  55. int m_nDisabledAlpha;
  56. int m_nBottomMargin;
  57. int m_nRightMargin;
  58. bool m_bEnabled;
  59. };
  60. //-----------------------------------------------------------------------
  61. // CCommandItem
  62. //
  63. // Menu item that issues a command when clicked.
  64. //-----------------------------------------------------------------------
  65. class CCommandItem : public CMenuItem
  66. {
  67. DECLARE_CLASS_SIMPLE( CCommandItem, CMenuItem );
  68. public:
  69. CCommandItem( CDialogMenu *pParent, const char *pTitle, const char *pDescription, const char *pCommand );
  70. virtual ~CCommandItem();
  71. virtual void OnClick();
  72. virtual void SetFocus( const bool bActive );
  73. bool m_bHasFocus;
  74. char m_szCommand[MAX_PATH];
  75. };
  76. //-----------------------------------------------------------------------
  77. // CPlayerItem
  78. //
  79. // Menu item to display a player in the lobby.
  80. //-----------------------------------------------------------------------
  81. class CPlayerItem : public CCommandItem
  82. {
  83. DECLARE_CLASS_SIMPLE( CMenuItem, CCommandItem );
  84. public:
  85. CPlayerItem( CDialogMenu *pParent, const char *pTitle, int64 nId, byte bVoice, bool bReady );
  86. virtual ~CPlayerItem();
  87. virtual void PerformLayout();
  88. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  89. virtual void OnClick();
  90. vgui::Label *m_pVoiceIcon;
  91. vgui::Label *m_pReadyIcon;
  92. byte m_bVoice;
  93. bool m_bReady;
  94. uint64 m_nId;
  95. };
  96. //-----------------------------------------------------------------------
  97. // CBrowserItem
  98. //
  99. // Menu item used to display session search results, etc.
  100. //-----------------------------------------------------------------------
  101. class CBrowserItem : public CCommandItem
  102. {
  103. DECLARE_CLASS_SIMPLE( CBrowserItem, CCommandItem );
  104. public:
  105. CBrowserItem( CDialogMenu *pParent, const char *pHost, const char *pPlayers, const char *pScenario, const char *pPing );
  106. virtual ~CBrowserItem();
  107. virtual void PerformLayout();
  108. virtual void ApplySettings( KeyValues *pSettings );
  109. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  110. private:
  111. vgui::Label *m_pPlayers;
  112. vgui::Label *m_pScenario;
  113. vgui::Label *m_pPing;
  114. };
  115. //-----------------------------------------------------------------------
  116. // COptionsItem
  117. //
  118. // Menu item used to present a list of options for the player to select
  119. // from, such as "choose a map" or "number of rounds".
  120. //-----------------------------------------------------------------------
  121. class COptionsItem : public CMenuItem
  122. {
  123. DECLARE_CLASS_SIMPLE( COptionsItem, CMenuItem );
  124. public:
  125. COptionsItem( CDialogMenu *pParent, const char *pLabel );
  126. virtual ~COptionsItem();
  127. virtual void PerformLayout();
  128. virtual void ApplySettings( KeyValues *pSettings );
  129. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  130. virtual void SetFocus( const bool bActive );
  131. void SetOptionFocus( unsigned int idx );
  132. void SetOptionFocusNext();
  133. void SetOptionFocusPrev();
  134. void AddOption( const char *pLabelText, const sessionProperty_t &option );
  135. int GetActiveOptionIndex();
  136. const sessionProperty_t &GetActiveOption();
  137. void DeleteAllOptions()
  138. {
  139. m_Options.RemoveAll();
  140. m_OptionLabels.PurgeAndDeleteElements();
  141. m_nActiveOption = m_Options.InvalidIndex();
  142. }
  143. private:
  144. int m_nActiveOption;
  145. int m_nOptionsXPos;
  146. int m_nOptionsMinWide;
  147. int m_nOptionsLeftMargin;
  148. int m_nMaxOptionWidth;
  149. int m_nArrowGap;
  150. CUtlVector< vgui::Label* > m_OptionLabels;
  151. CUtlVector< sessionProperty_t > m_Options;
  152. char m_szOptionsFont[64];
  153. vgui::HFont m_hOptionsFont;
  154. vgui::Label *m_pLeftArrow;
  155. vgui::Label *m_pRightArrow;
  156. };
  157. //-----------------------------------------------------------------------
  158. // CAchievementItem
  159. //
  160. // Menu item used to present an achievement - including image, title,
  161. // description, points and unlock date. Clicking the item opens another
  162. // dialog with additional information about the achievement.
  163. //-----------------------------------------------------------------------
  164. class CAchievementItem : public CMenuItem
  165. {
  166. DECLARE_CLASS_SIMPLE( CAchievementItem, CMenuItem );
  167. public:
  168. CAchievementItem( CDialogMenu *pParent, const wchar_t *pName, const wchar_t *pDesc, uint points, bool bUnlocked, IAchievement* pSourceAchievement );
  169. virtual ~CAchievementItem();
  170. virtual void PerformLayout();
  171. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  172. private:
  173. vgui::Label *m_pPoints;
  174. vgui::ImagePanel *m_pLockedIcon;
  175. vgui::ImagePanel *m_pUnlockedIcon;
  176. vgui::ImagePanel *m_pImage;
  177. vgui::ImagePanel *m_pPercentageBarBackground;
  178. vgui::ImagePanel *m_pPercentageBar;
  179. vgui::Label *m_pPercentageText;
  180. IAchievement *m_pSourceAchievement;
  181. Color m_AchievedBGColor;
  182. Color m_UnachievedBGColor;
  183. CPanelAnimationVar( Color, m_clrProgressBar, "ProgressBarColor", "140 140 140 255" );
  184. };
  185. //-----------------------------------------------------------------------
  186. // CSectionedItem
  187. //
  188. // Menu item used to display some number of data entries, which are arranged
  189. // into columns. Supports scrolling through columns horizontally with the
  190. // ability to "lock" columns so they don't scroll
  191. //-----------------------------------------------------------------------
  192. class CSectionedItem : public CCommandItem
  193. {
  194. DECLARE_CLASS_SIMPLE( CSectionedItem, CCommandItem );
  195. public:
  196. CSectionedItem( CDialogMenu *pParent, const char **ppEntries, int ct );
  197. virtual ~CSectionedItem();
  198. virtual void PerformLayout();
  199. virtual void ApplySettings( KeyValues *pSettings );
  200. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  201. virtual void SetActiveColumn( int col );
  202. void ClearSections();
  203. void AddSection( const char *pText, int wide );
  204. struct section_s
  205. {
  206. int wide;
  207. vgui::Label *pLabel;
  208. };
  209. CUtlVector< section_s >m_Sections;
  210. bool m_bHeader;
  211. };
  212. //--------------------------------------------------------------------------------------
  213. // Generic menu for Xbox 360 matchmaking dialogs. Contains a list of CMenuItems arranged
  214. // vertically. The user can navigate the list using the controller and click on any
  215. // item. A clicked item may send a command to the dialog and the dialog responds accordingly.
  216. //--------------------------------------------------------------------------------------
  217. class CDialogMenu : public vgui::Panel
  218. {
  219. DECLARE_CLASS_SIMPLE( CDialogMenu, vgui::Panel );
  220. public:
  221. CDialogMenu();
  222. ~CDialogMenu();
  223. virtual void OnCommand( const char *pCommand );
  224. virtual void ApplySettings( KeyValues *inResourceData );
  225. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  226. virtual void PerformLayout();
  227. void SetFilter( const char *pFilter );
  228. virtual bool HandleKeyCode( vgui::KeyCode code );
  229. void SetMaxVisibleItems( uint nMaxVisibleItems );
  230. void SetParent( CBaseDialog *pParent );
  231. // Menu items
  232. CCommandItem *AddCommandItem( const char *pTitleLabel, const char *pDescLabel, const char *pCommand );
  233. CPlayerItem *AddPlayerItem( const char *pTitleLabel, int64 nId, byte bVoice, bool bReady );
  234. CBrowserItem *AddBrowserItem( const char *pHost, const char *pPlayers, const char *pScenario, const char *pPing );
  235. COptionsItem *AddOptionsItem( const char *pLabel );
  236. CSectionedItem *AddSectionedItem( const char **ppEntries, int ct );
  237. CAchievementItem *AddAchievementItem( const wchar_t *pName, const wchar_t *pDesc, uint cred, bool bUnlocked, IAchievement* pSourceAchievement );
  238. CMenuItem *AddItemInternal( CMenuItem *pItem );
  239. void RemovePlayerItem( int idx );
  240. void SortMenuItems();
  241. void ClearItems();
  242. // Navigation
  243. void SetFocus( int idx );
  244. void SetFocusNext();
  245. void SetFocusPrev();
  246. void SetOptionFocusNext();
  247. void SetOptionFocusPrev();
  248. void SetColumnFocusNext();
  249. void SetColumnFocusPrev();
  250. void UpdateBaseColumnIndex();
  251. // Accessors
  252. CMenuItem *GetItem( int idx);
  253. int GetItemCount();
  254. int GetActiveItemIndex();
  255. int GetActiveColumnIndex();
  256. int GetActiveOptionIndex( int idx );
  257. int GetVisibleItemCount();
  258. int GetVisibleColumnCount();
  259. int GetFirstUnlockedColumnIndex();
  260. int GetBaseRowIndex();
  261. void SetBaseRowIndex( int idx );
  262. int GetColumnXPos( int idx );
  263. int GetColumnYPos( int idx );
  264. int GetColumnWide( int idx );
  265. int GetColumnAlignment( int idx );
  266. vgui::HFont GetColumnFont( int idx );
  267. Color GetColumnColor( int idx );
  268. bool GetColumnSortType( int idx );
  269. private:
  270. struct columninfo_s
  271. {
  272. int xpos;
  273. int ypos;
  274. int wide;
  275. int align;
  276. bool bLocked;
  277. Color color;
  278. vgui::HFont hFont;
  279. bool bSortDown;
  280. };
  281. CUtlVector< columninfo_s >m_Columns;
  282. CUtlVector< CMenuItem* > m_MenuItems;
  283. CBaseDialog *m_pParent;
  284. CSectionedItem *m_pHeader;
  285. vgui::IScheme *m_pScheme;
  286. char m_szFilter[MAX_COMMAND_LEN]; // string to use as a keyvalues filter when reading in menu items
  287. int m_nItemSpacing; // gap between menu items
  288. int m_nMinWide; // minimum width - final menu width will always be >= m_nMinWide
  289. bool m_bInitialized;
  290. bool m_bUseFilter;
  291. bool m_bHasHeader;
  292. int m_nMaxVisibleItems; // max number of items to display in the menu
  293. int m_nMaxVisibleColumns; // max number of columns to display in the menu
  294. int m_nActiveColumn; // index of the current active column
  295. int m_nBaseColumnIdx; // array index of the first non-static column
  296. int m_nBaseRowIdx; // array index of the first visible row
  297. int m_nActive; // index of the current active item
  298. int m_iUnlocked; // first unlocked column in the menu
  299. };
  300. #endif // DIALOGMENU_H