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.

462 lines
15 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef BASEPANEL_H
  8. #define BASEPANEL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "vgui_controls/Panel.h"
  13. #include "vgui_controls/PHandle.h"
  14. #include "vgui_controls/MenuItem.h"
  15. #include "vgui_controls/MessageDialog.h"
  16. #include "KeyValues.h"
  17. #include "utlvector.h"
  18. #include "tier1/CommandBuffer.h"
  19. #include "ixboxsystem.h"
  20. #if !defined( _X360 )
  21. #include "xbox/xboxstubs.h"
  22. #endif
  23. enum
  24. {
  25. DIALOG_STACK_IDX_STANDARD,
  26. DIALOG_STACK_IDX_WARNING,
  27. DIALOG_STACK_IDX_ERROR,
  28. };
  29. class CMatchmakingBasePanel;
  30. class CBackgroundMenuButton;
  31. class CGameMenu;
  32. class CAsyncCtxOnDeviceAttached;
  33. // X360TBD: Move into a separate module when finished
  34. class CMessageDialogHandler
  35. {
  36. public:
  37. CMessageDialogHandler();
  38. void ShowMessageDialog( int nType, vgui::Panel *pOwner );
  39. void CloseMessageDialog( const uint nType = 0 );
  40. void CloseAllMessageDialogs();
  41. void CreateMessageDialog( const uint nType, const char *pTitle, const char *pMsg, const char *pCmdA, const char *pCmdB, vgui::Panel *pCreator, bool bShowActivity = false );
  42. void ActivateMessageDialog( int nStackIdx );
  43. void PositionDialogs( int wide, int tall );
  44. void PositionDialog( vgui::PHandle dlg, int wide, int tall );
  45. private:
  46. static const int MAX_MESSAGE_DIALOGS = 3;
  47. vgui::DHANDLE< CMessageDialog > m_hMessageDialogs[MAX_MESSAGE_DIALOGS];
  48. int m_iDialogStackTop;
  49. };
  50. //-----------------------------------------------------------------------------
  51. // Purpose: Panel that acts as background for button icons and help text in the UI
  52. //-----------------------------------------------------------------------------
  53. class CFooterPanel : public vgui::EditablePanel
  54. {
  55. DECLARE_CLASS_SIMPLE( CFooterPanel, vgui::EditablePanel );
  56. public:
  57. CFooterPanel( Panel *parent, const char *panelName );
  58. virtual ~CFooterPanel();
  59. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  60. virtual void ApplySettings( KeyValues *pResourceData );
  61. virtual void Paint( void );
  62. virtual void PaintBackground( void );
  63. // caller tags the current hint, used to assist in ownership
  64. void SetHelpNameAndReset( const char *pName );
  65. const char *GetHelpName();
  66. void AddButtonsFromMap( vgui::Frame *pMenu );
  67. void SetStandardDialogButtons();
  68. void AddNewButtonLabel( const char *text, const char *icon );
  69. void ShowButtonLabel( const char *name, bool show = true );
  70. void SetButtonText( const char *buttonName, const char *text );
  71. void ClearButtons();
  72. void SetButtonGap( int nButtonGap ){ m_nButtonGap = nButtonGap; }
  73. void UseDefaultButtonGap(){ m_nButtonGap = m_nButtonGapDefault; }
  74. private:
  75. struct ButtonLabel_t
  76. {
  77. bool bVisible;
  78. char name[MAX_PATH];
  79. wchar_t text[MAX_PATH];
  80. wchar_t icon[2]; // icon is a single character
  81. };
  82. CUtlVector< ButtonLabel_t* > m_ButtonLabels;
  83. vgui::Label *m_pSizingLabel; // used to measure font sizes
  84. bool m_bPaintBackground; // fill the background?
  85. bool m_bCenterHorizontal; // center buttons horizontally?
  86. int m_ButtonPinRight; // if not centered, this is the distance from the right margin that we use to start drawing buttons (right to left)
  87. int m_nButtonGap; // space between buttons when drawing
  88. int m_nButtonGapDefault; // space between buttons (initial value)
  89. int m_FooterTall; // height of the footer
  90. int m_ButtonOffsetFromTop; // how far below the top the buttons should be drawn
  91. int m_ButtonSeparator; // space between the button icon and text
  92. int m_TextAdjust; // extra adjustment for the text (vertically)...text is centered on the button icon and then this value is applied
  93. char m_szTextFont[64]; // font for the button text
  94. char m_szButtonFont[64]; // font for the button icon
  95. char m_szFGColor[64]; // foreground color (text)
  96. char m_szBGColor[64]; // background color (fill color)
  97. vgui::HFont m_hButtonFont;
  98. vgui::HFont m_hTextFont;
  99. char *m_pHelpName;
  100. };
  101. //-----------------------------------------------------------------------------
  102. // Purpose: EditablePanel that can replace the GameMenuButtons in CBasePanel
  103. //-----------------------------------------------------------------------------
  104. class CMainMenuGameLogo : public vgui::EditablePanel
  105. {
  106. DECLARE_CLASS_SIMPLE( CMainMenuGameLogo, vgui::EditablePanel );
  107. public:
  108. CMainMenuGameLogo( vgui::Panel *parent, const char *name );
  109. virtual void ApplySettings( KeyValues *inResourceData );
  110. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  111. int GetOffsetX(){ return m_nOffsetX; }
  112. int GetOffsetY(){ return m_nOffsetY; }
  113. private:
  114. int m_nOffsetX;
  115. int m_nOffsetY;
  116. };
  117. //-----------------------------------------------------------------------------
  118. // Purpose: Transparent menu item designed to sit on the background ingame
  119. //-----------------------------------------------------------------------------
  120. class CGameMenuItem : public vgui::MenuItem
  121. {
  122. DECLARE_CLASS_SIMPLE( CGameMenuItem, vgui::MenuItem );
  123. public:
  124. CGameMenuItem(vgui::Menu *parent, const char *name);
  125. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  126. virtual void PaintBackground( void );
  127. void SetRightAlignedText( bool state );
  128. private:
  129. bool m_bRightAligned;
  130. };
  131. //-----------------------------------------------------------------------------
  132. // Purpose: This is the panel at the top of the panel hierarchy for GameUI
  133. // It handles all the menus, background images, and loading dialogs
  134. //-----------------------------------------------------------------------------
  135. class CBasePanel : public vgui::Panel
  136. {
  137. DECLARE_CLASS_SIMPLE( CBasePanel, vgui::Panel );
  138. public:
  139. CBasePanel();
  140. virtual ~CBasePanel();
  141. public:
  142. //
  143. // Implementation of async jobs
  144. // An async job is enqueued by calling "ExecuteAsync" with the proper job context.
  145. // Job's function "ExecuteAsync" is called on a separate thread.
  146. // After the job finishes the "Completed" function is called on the
  147. // main thread.
  148. //
  149. class CAsyncJobContext
  150. {
  151. public:
  152. CAsyncJobContext( float flLeastExecuteTime = 0.0f ) : m_flLeastExecuteTime( flLeastExecuteTime ), m_hThreadHandle( NULL ) {}
  153. virtual ~CAsyncJobContext() {}
  154. virtual void ExecuteAsync() = 0; // Executed on the secondary thread
  155. virtual void Completed() = 0; // Executed on the main thread
  156. public:
  157. void * volatile m_hThreadHandle; // Handle to an async job thread waiting for
  158. float m_flLeastExecuteTime; // Least amount of time this job should keep executing
  159. };
  160. CAsyncJobContext *m_pAsyncJob;
  161. void ExecuteAsync( CAsyncJobContext *pAsync );
  162. public:
  163. // notifications
  164. void OnLevelLoadingStarted();
  165. void OnLevelLoadingFinished();
  166. // update the taskbar a frame
  167. void RunFrame();
  168. // fades to black then runs an engine command (usually to start a level)
  169. void FadeToBlackAndRunEngineCommand( const char *engineCommand );
  170. // sets the blinking state of a menu item
  171. void SetMenuItemBlinkingState( const char *itemName, bool state );
  172. // handles gameUI being shown
  173. void OnGameUIActivated();
  174. // game dialogs
  175. void OnOpenNewGameDialog( const char *chapter = NULL );
  176. void OnOpenBonusMapsDialog();
  177. void OnOpenLoadGameDialog();
  178. void OnOpenLoadGameDialog_Xbox();
  179. void OnOpenSaveGameDialog();
  180. void OnOpenSaveGameDialog_Xbox();
  181. void OnOpenServerBrowser();
  182. void OnOpenFriendsDialog();
  183. void OnOpenDemoDialog();
  184. void OnOpenCreateMultiplayerGameDialog();
  185. void OnOpenQuitConfirmationDialog();
  186. void OnOpenDisconnectConfirmationDialog();
  187. void OnOpenChangeGameDialog();
  188. void OnOpenPlayerListDialog();
  189. void OnOpenBenchmarkDialog();
  190. void OnOpenOptionsDialog();
  191. void OnOpenOptionsDialog_Xbox();
  192. void OnOpenLoadCommentaryDialog();
  193. void OpenLoadSingleplayerCommentaryDialog();
  194. void OnOpenAchievementsDialog();
  195. //=============================================================================
  196. // HPE_BEGIN:
  197. // [dwenger] Specific code for CS Achievements Display
  198. //=============================================================================
  199. // $TODO(HPE): Move this to a game-specific location
  200. void OnOpenCSAchievementsDialog();
  201. //=============================================================================
  202. // HPE_END
  203. //=============================================================================
  204. void OnOpenAchievementsDialog_Xbox();
  205. void OnOpenControllerDialog();
  206. // Xbox 360
  207. CMatchmakingBasePanel* GetMatchmakingBasePanel();
  208. void OnOpenMatchmakingBasePanel();
  209. void SessionNotification( const int notification, const int param = 0 );
  210. void SystemNotification( const int notification );
  211. void ShowMessageDialog( const uint nType, vgui::Panel *pParent = NULL );
  212. void CloseMessageDialog( const uint nType );
  213. void UpdatePlayerInfo( uint64 nPlayerId, const char *pName, int nTeam, byte cVoiceState, int nPlayersNeeded, bool bHost );
  214. void SessionSearchResult( int searchIdx, void *pHostData, XSESSION_SEARCHRESULT *pResult, int ping );
  215. void OnChangeStorageDevice();
  216. bool ValidateStorageDevice();
  217. bool ValidateStorageDevice( int *pStorageDeviceValidated );
  218. void OnCreditsFinished();
  219. KeyValues *GetConsoleControlSettings( void );
  220. // forces any changed options dialog settings to be applied immediately, if it's open
  221. void ApplyOptionsDialogSettings();
  222. vgui::AnimationController *GetAnimationController( void ) { return m_pConsoleAnimationController; }
  223. void RunCloseAnimation( const char *animName );
  224. void RunAnimationWithCallback( vgui::Panel *parent, const char *animName, KeyValues *msgFunc );
  225. void PositionDialog( vgui::PHandle dlg );
  226. virtual void OnSizeChanged( int newWide, int newTall );
  227. void ArmFirstMenuItem( void );
  228. void OnGameUIHidden();
  229. void CloseBaseDialogs( void );
  230. bool IsWaitingForConsoleUI( void ) { return m_bWaitingForStorageDeviceHandle || m_bWaitingForUserSignIn || m_bXUIVisible; }
  231. #if defined( _X360 )
  232. CON_COMMAND_MEMBER_F( CBasePanel, "gameui_reload_resources", Reload_Resources, "Reload the Xbox 360 UI res files", 0 );
  233. #endif
  234. int GetMenuAlpha( void );
  235. void SetMainMenuOverride( vgui::VPANEL panel );
  236. protected:
  237. virtual void PaintBackground();
  238. virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
  239. public:
  240. // FIXME: This should probably become a friend relationship between the classes
  241. bool HandleSignInRequest( const char *command );
  242. bool HandleStorageDeviceRequest( const char *command );
  243. void ClearPostPromptCommand( const char *pCompletedCommand );
  244. private:
  245. enum EBackgroundState
  246. {
  247. BACKGROUND_INITIAL,
  248. BACKGROUND_LOADING,
  249. BACKGROUND_MAINMENU,
  250. BACKGROUND_LEVEL,
  251. BACKGROUND_DISCONNECTED,
  252. BACKGROUND_EXITING, // Console has started an exiting state, cannot be stopped
  253. };
  254. void SetBackgroundRenderState(EBackgroundState state);
  255. friend class CAsyncCtxOnDeviceAttached;
  256. void OnDeviceAttached( void );
  257. void OnCompletedAsyncDeviceAttached( CAsyncCtxOnDeviceAttached *job );
  258. void IssuePostPromptCommand( void );
  259. void UpdateBackgroundState();
  260. // sets the menu alpha [0..255]
  261. void SetMenuAlpha(int alpha);
  262. // menu manipulation
  263. void CreatePlatformMenu();
  264. void CreateGameMenu();
  265. void CreateGameLogo();
  266. void CheckBonusBlinkState();
  267. void UpdateGameMenus();
  268. CGameMenu *RecursiveLoadGameMenu(KeyValues *datafile);
  269. void StartExitingProcess();
  270. bool IsPromptableCommand( const char *command );
  271. bool CommandRequiresSignIn( const char *command );
  272. bool CommandRequiresStorageDevice( const char *command );
  273. bool CommandRespectsSignInDenied( const char *command );
  274. void QueueCommand( const char *pCommand );
  275. void RunQueuedCommands();
  276. void ClearQueuedCommands();
  277. virtual void OnCommand(const char *command);
  278. virtual void PerformLayout();
  279. MESSAGE_FUNC_INT( OnActivateModule, "ActivateModule", moduleIndex);
  280. void UpdateRichPresenceInfo();
  281. // menu logo
  282. CMainMenuGameLogo *m_pGameLogo;
  283. // menu buttons
  284. CUtlVector< CBackgroundMenuButton * >m_pGameMenuButtons;
  285. CGameMenu *m_pGameMenu;
  286. bool m_bPlatformMenuInitialized;
  287. int m_iGameMenuInset;
  288. vgui::VPANEL m_hMainMenuOverridePanel;
  289. struct coord {
  290. int x;
  291. int y;
  292. };
  293. CUtlVector< coord > m_iGameTitlePos;
  294. coord m_iGameMenuPos;
  295. // base dialogs
  296. vgui::DHANDLE<vgui::Frame> m_hNewGameDialog;
  297. vgui::DHANDLE<vgui::Frame> m_hBonusMapsDialog;
  298. vgui::DHANDLE<vgui::Frame> m_hLoadGameDialog;
  299. vgui::DHANDLE<vgui::Frame> m_hLoadGameDialog_Xbox;
  300. vgui::DHANDLE<vgui::Frame> m_hSaveGameDialog;
  301. vgui::DHANDLE<vgui::Frame> m_hSaveGameDialog_Xbox;
  302. vgui::DHANDLE<vgui::PropertyDialog> m_hOptionsDialog;
  303. vgui::DHANDLE<vgui::Frame> m_hOptionsDialog_Xbox;
  304. vgui::DHANDLE<vgui::Frame> m_hCreateMultiplayerGameDialog;
  305. //vgui::DHANDLE<vgui::Frame> m_hDemoPlayerDialog;
  306. vgui::DHANDLE<vgui::Frame> m_hChangeGameDialog;
  307. vgui::DHANDLE<vgui::Frame> m_hPlayerListDialog;
  308. vgui::DHANDLE<vgui::Frame> m_hBenchmarkDialog;
  309. vgui::DHANDLE<vgui::Frame> m_hLoadCommentaryDialog;
  310. vgui::DHANDLE<vgui::Frame> m_hAchievementsDialog;
  311. // Xbox 360
  312. vgui::DHANDLE<vgui::Frame> m_hMatchmakingBasePanel;
  313. vgui::DHANDLE<vgui::Frame> m_hControllerDialog;
  314. EBackgroundState m_eBackgroundState;
  315. CMessageDialogHandler m_MessageDialogHandler;
  316. CUtlVector< CUtlString > m_CommandQueue;
  317. vgui::AnimationController *m_pConsoleAnimationController;
  318. KeyValues *m_pConsoleControlSettings;
  319. void DrawBackgroundImage();
  320. int m_iBackgroundImageID;
  321. int m_iRenderTargetImageID;
  322. int m_iLoadingImageID;
  323. int m_iProductImageID;
  324. bool m_bLevelLoading;
  325. bool m_bEverActivated;
  326. bool m_bCopyFrameBuffer;
  327. bool m_bUseRenderTargetImage;
  328. int m_ExitingFrameCount;
  329. bool m_bXUIVisible;
  330. bool m_bUseMatchmaking;
  331. bool m_bRestartFromInvite;
  332. bool m_bRestartSameGame;
  333. // Used for internal state dealing with blades
  334. bool m_bUserRefusedSignIn;
  335. bool m_bUserRefusedStorageDevice;
  336. bool m_bWaitingForUserSignIn;
  337. bool m_bStorageBladeShown;
  338. CUtlString m_strPostPromptCommand;
  339. // Storage device changing vars
  340. bool m_bWaitingForStorageDeviceHandle;
  341. bool m_bNeedStorageDeviceHandle;
  342. AsyncHandle_t m_hStorageDeviceChangeHandle;
  343. uint m_iStorageID;
  344. int *m_pStorageDeviceValidatedNotify;
  345. // background transition
  346. bool m_bFadingInMenus;
  347. float m_flFadeMenuStartTime;
  348. float m_flFadeMenuEndTime;
  349. bool m_bRenderingBackgroundTransition;
  350. float m_flTransitionStartTime;
  351. float m_flTransitionEndTime;
  352. // Used for rich presence updates on xbox360
  353. bool m_bSinglePlayer;
  354. uint m_iGameID; // matches context value in hl2orange.spa.h
  355. // background fill transition
  356. bool m_bHaveDarkenedBackground;
  357. bool m_bHaveDarkenedTitleText;
  358. bool m_bForceTitleTextUpdate;
  359. float m_flFrameFadeInTime;
  360. Color m_BackdropColor;
  361. CPanelAnimationVar( float, m_flBackgroundFillAlpha, "m_flBackgroundFillAlpha", "0" );
  362. // fading to game
  363. MESSAGE_FUNC_CHARPTR( RunEngineCommand, "RunEngineCommand", command );
  364. MESSAGE_FUNC( FinishDialogClose, "FinishDialogClose" );
  365. public:
  366. MESSAGE_FUNC_CHARPTR( RunMenuCommand, "RunMenuCommand", command );
  367. };
  368. //-----------------------------------------------------------------------------
  369. // Purpose: singleton accessor
  370. //-----------------------------------------------------------------------------
  371. extern CBasePanel *BasePanel();
  372. #endif // BASEPANEL_H