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.

568 lines
19 KiB

  1. //========= Copyright 1996-2005, 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. #if !defined( NO_STEAM )
  13. #include "utlvector.h"
  14. #include "clientsteamcontext.h"
  15. #endif
  16. #if defined( SWARM_DLL )
  17. #include "swarm/basemodpanel.h"
  18. inline BaseModUI::CBaseModPanel * BasePanel() { return &BaseModUI::CBaseModPanel::GetSingleton(); }
  19. #elif defined( PORTAL2_UITEST_DLL )
  20. #include "portal2uitest/basemodpanel.h"
  21. inline BaseModUI::CBaseModPanel * BasePanel() { return &BaseModUI::CBaseModPanel::GetSingleton(); }
  22. #else
  23. #define BASEPANEL_LEGACY_SOURCE1
  24. #include "vgui_controls/Panel.h"
  25. #include "vgui_controls/PHandle.h"
  26. #include "vgui_controls/MenuItem.h"
  27. #include "vgui_controls/MessageDialog.h"
  28. #include "keyvalues.h"
  29. #include "utlvector.h"
  30. #include "tier1/commandbuffer.h"
  31. #include "vgui_controls/footerpanel.h"
  32. #include "ixboxsystem.h"
  33. #if !defined( _GAMECONSOLE )
  34. #include "xbox/xboxstubs.h"
  35. #endif
  36. enum
  37. {
  38. DIALOG_STACK_IDX_STANDARD,
  39. DIALOG_STACK_IDX_WARNING,
  40. DIALOG_STACK_IDX_ERROR,
  41. };
  42. class CBackgroundMenuButton;
  43. class CGameMenu;
  44. // X360TBD: Move into a separate module when finished
  45. class CMessageDialogHandler
  46. {
  47. public:
  48. CMessageDialogHandler();
  49. void ShowMessageDialog( int nType, vgui::Panel *pOwner );
  50. void CloseMessageDialog( const uint nType = 0 );
  51. void CloseAllMessageDialogs();
  52. void CreateMessageDialog( const uint nType, const char *pTitle, const char *pMsg, const char *pCmdA, const char *pCmdB, vgui::Panel *pCreator, bool bShowActivity = false );
  53. void ActivateMessageDialog( int nStackIdx );
  54. void PositionDialogs( int wide, int tall );
  55. void PositionDialog( vgui::PHandle dlg, int wide, int tall );
  56. private:
  57. static const int MAX_MESSAGE_DIALOGS = 3;
  58. vgui::DHANDLE< CMessageDialog > m_hMessageDialogs[MAX_MESSAGE_DIALOGS];
  59. int m_iDialogStackTop;
  60. };
  61. //-----------------------------------------------------------------------------
  62. // Purpose: EditablePanel that can replace the GameMenuButtons in CBaseModPanel
  63. //-----------------------------------------------------------------------------
  64. class CMainMenuGameLogo : public vgui::EditablePanel
  65. {
  66. DECLARE_CLASS_SIMPLE( CMainMenuGameLogo, vgui::EditablePanel );
  67. public:
  68. CMainMenuGameLogo( vgui::Panel *parent, const char *name );
  69. virtual void ApplySettings( KeyValues *inResourceData );
  70. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  71. int GetOffsetX(){ return m_nOffsetX; }
  72. int GetOffsetY(){ return m_nOffsetY; }
  73. private:
  74. int m_nOffsetX;
  75. int m_nOffsetY;
  76. };
  77. //-----------------------------------------------------------------------------
  78. // Purpose: Transparent menu item designed to sit on the background ingame
  79. //-----------------------------------------------------------------------------
  80. class CGameMenuItem : public vgui::MenuItem
  81. {
  82. DECLARE_CLASS_SIMPLE( CGameMenuItem, vgui::MenuItem );
  83. public:
  84. CGameMenuItem(vgui::Menu *parent, const char *name);
  85. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  86. virtual void PaintBackground( void );
  87. void SetRightAlignedText( bool state );
  88. private:
  89. bool m_bRightAligned;
  90. };
  91. // dgoodenough - GCC does not treat "friend class foo;" as a forward declaration of foo, so
  92. // explicitly forward declare class CAsyncCtxOnDeviceAttached here.
  93. // PS3_BUILDFIX
  94. class CAsyncCtxOnDeviceAttached;
  95. //-----------------------------------------------------------------------------
  96. // Purpose: This is the panel at the top of the panel hierarchy for GameUI
  97. // It handles all the menus, background images, and loading dialogs
  98. //-----------------------------------------------------------------------------
  99. class CBaseModPanel : public vgui::Panel
  100. {
  101. DECLARE_CLASS_SIMPLE( CBaseModPanel, vgui::Panel );
  102. protected:
  103. explicit CBaseModPanel( const char *panelName );
  104. public:
  105. virtual ~CBaseModPanel();
  106. public:
  107. //
  108. // Implementation of async jobs
  109. // An async job is enqueued by calling "ExecuteAsync" with the proper job context.
  110. // Job's function "ExecuteAsync" is called on a separate thread.
  111. // After the job finishes the "Completed" function is called on the
  112. // main thread.
  113. //
  114. class CAsyncJobContext
  115. {
  116. public:
  117. explicit CAsyncJobContext( float flLeastExecuteTime = 0.0f ) : m_flLeastExecuteTime( flLeastExecuteTime ), m_hThreadHandle( NULL ) {}
  118. virtual ~CAsyncJobContext() {}
  119. virtual void ExecuteAsync() = 0; // Executed on the secondary thread
  120. virtual void Completed() = 0; // Executed on the main thread
  121. public:
  122. void * volatile m_hThreadHandle; // Handle to an async job thread waiting for
  123. float m_flLeastExecuteTime; // Least amount of time this job should keep executing
  124. };
  125. CAsyncJobContext *m_pAsyncJob;
  126. void ExecuteAsync( CAsyncJobContext *pAsync );
  127. public:
  128. // notifications
  129. virtual void OnLevelLoadingStarted( const char *levelName, bool bShowProgressDialog );
  130. virtual void OnLevelLoadingFinished();
  131. virtual bool UpdateProgressBar(float progress, const char *statusText, bool showDialog = true ) { return false; }
  132. // update the taskbar a frame
  133. virtual void RunFrame();
  134. // fades to black then runs an engine command (usually to start a level)
  135. void FadeToBlackAndRunEngineCommand( const char *engineCommand );
  136. // sets the blinking state of a menu item
  137. void SetMenuItemBlinkingState( const char *itemName, bool state );
  138. // handles gameUI being shown
  139. virtual void OnGameUIActivated();
  140. // game dialogs
  141. void OnOpenNewGameDialog( const char *chapter = NULL );
  142. void OnOpenBonusMapsDialog();
  143. void OnOpenLoadGameDialog();
  144. void OnOpenLoadGameDialog_Xbox();
  145. void OnOpenSaveGameDialog();
  146. void OnOpenSaveGameDialog_Xbox();
  147. void OnCloseServerBrowser();
  148. void OnOpenFriendsDialog();
  149. void OnOpenDemoDialog();
  150. // Overridden with the Scaleform dialog box in Cstrike15Basepanel
  151. virtual void OnOpenQuitConfirmationDialog( bool bForceToDesktop = false );
  152. void OnOpenChangeGameDialog();
  153. void OnOpenPlayerListDialog();
  154. void OnOpenBenchmarkDialog();
  155. void OnOpenOptionsDialog();
  156. void OnOpenOptionsDialog_Xbox();
  157. void OnOpenLoadCommentaryDialog();
  158. void OpenLoadSingleplayerCommentaryDialog();
  159. void OnOpenAchievementsDialog();
  160. void OnOpenAchievementsDialog_Xbox();
  161. void OnOpenCSAchievementsDialog();
  162. virtual void OnOpenSettingsDialog();
  163. virtual void OnOpenControllerDialog();
  164. virtual void OnOpenMouseDialog();
  165. virtual void OnOpenKeyboardDialog();
  166. virtual void OnOpenMotionControllerMoveDialog();
  167. virtual void OnOpenMotionControllerSharpshooterDialog();
  168. virtual void OnOpenMotionControllerDialog();
  169. virtual void OnOpenMotionCalibrationDialog();
  170. virtual void OnOpenVideoSettingsDialog();
  171. virtual void OnOpenOptionsQueued();
  172. virtual void OnOpenAudioSettingsDialog();
  173. // [jason] For displaying medals/stats in Cstrike15
  174. virtual void OnOpenMedalsDialog();
  175. virtual void OnOpenStatsDialog();
  176. virtual void CloseMedalsStatsDialog();
  177. // [jason] For displaying Leaderboards in Cstrike15
  178. virtual void OnOpenLeaderboardsDialog();
  179. virtual void OnOpenCallVoteDialog();
  180. virtual void OnOpenMarketplace();
  181. virtual void UpdateLeaderboardsDialog();
  182. virtual void CloseLeaderboardsDialog();
  183. virtual void OnOpenDisconnectConfirmationDialog();
  184. // gameconsole
  185. void SystemNotification( const int notification );
  186. void ShowMessageDialog( const uint nType, vgui::Panel *pParent = NULL );
  187. void CloseMessageDialog( const uint nType );
  188. void OnChangeStorageDevice();
  189. bool ValidateStorageDevice();
  190. bool ValidateStorageDevice( int *pStorageDeviceValidated );
  191. void OnCreditsFinished();
  192. virtual void OnOpenCreateSingleplayerGameDialog( bool bMatchmakingFilter = false ) {}
  193. virtual void OnOpenCreateMultiplayerGameDialog();
  194. virtual void OnOpenCreateMultiplayerGameCommunity();
  195. virtual void ShowMatchmakingStatus() {}
  196. // returns true if message box is displayed successfully
  197. virtual bool ShowLockInput( void ) { return false; }
  198. virtual void OnOpenHowToPlayDialog() {}
  199. virtual void OnOpenServerBrowser() {}
  200. virtual void OnOpenCreateLobbyScreen( bool bIsHost = false ) {}
  201. virtual void OnOpenLobbyBrowserScreen( bool bIsHost = false ) {}
  202. virtual void UpdateLobbyScreen( void ) {}
  203. virtual void UpdateMainMenuScreen() {}
  204. virtual void UpdateLobbyBrowser( void ) {}
  205. // Determine if we have an active team lobby we are part of
  206. virtual bool InTeamLobby( void );
  207. // [jason] Provides the "Press Start" screen interface (show, hide, and reset flags)
  208. virtual void OnOpenCreateStartScreen( void );
  209. virtual void HandleOpenCreateStartScreen( void );
  210. virtual void DismissStartScreen( void );
  211. virtual bool IsStartScreenActive( void );
  212. // Do we want the start screen to come up when we boot up, before we reach main menu?
  213. bool IsStartScreenEnabled( void ) { return m_bShowStartScreen; }
  214. // [jason] Start the sign-in blade
  215. void SignInFromStartScreen( void );
  216. // [jason] Dismiss the start screen and commit the user once they've signed in
  217. void CompleteStartScreenSignIn( void );
  218. // [jason] Callback for the CreateStartScreen interface to allow us to complete the signin process
  219. void NotifySignInCompleted(int userID = -1);
  220. void NotifySignInCancelled( void );
  221. // [jason] Helper function to allow show/hide of the standard Valve main menu (which also enables/disables its processing)
  222. void ShowMainMenu( bool bShow );
  223. virtual void OnPlayCreditsVideo( void );
  224. // [jason] New scaleform Main Menu setup
  225. virtual void OnOpenCreateMainMenuScreen( void );
  226. virtual void DismissMainMenuScreen( void );
  227. virtual void RestoreMainMenuScreen( void );
  228. // Tear down all screens, and either tear down or just hide the main/pause menu (by default, they are also torn down)
  229. virtual void DismissAllMainMenuScreens( bool bHideMainMenuOnly = false );
  230. // Controls whether we allow the next main menu transition to use the Scaleform main menu, or the vgui version
  231. void EnableScaleformMainMenu( bool bEnable ) { m_bScaleformMainMenuEnabled = bEnable; }
  232. bool IsScaleformMainMenuEnabled( void ) { return m_bScaleformMainMenuEnabled; }
  233. // [jason] Notification that a vgui dialog has completed, in case we need to restore Scaleform menu
  234. void NotifyVguiDialogClosed( void );
  235. virtual void OnOpenPauseMenu( void );
  236. virtual void DismissPauseMenu( void );
  237. virtual void RestorePauseMenu( void );
  238. virtual void OnOpenUpsellDialog( void );
  239. void OnMakeGamePublic( void );
  240. virtual void ShowScaleformPauseMenu( bool bShow );
  241. virtual bool IsScaleformPauseMenuActive( void );
  242. virtual bool IsScaleformPauseMenuVisible( void );
  243. bool IsScaleformPauseMenuEnabled( void ) { return m_bScaleformPauseMenuEnabled; }
  244. KeyValues *GetConsoleControlSettings( void );
  245. // forces any changed options dialog settings to be applied immediately, if it's open
  246. void ApplyOptionsDialogSettings();
  247. vgui::AnimationController *GetAnimationController( void ) { return m_pConsoleAnimationController; }
  248. void RunCloseAnimation( const char *animName );
  249. void RunAnimationWithCallback( vgui::Panel *parent, const char *animName, KeyValues *msgFunc );
  250. void PositionDialog( vgui::PHandle dlg );
  251. virtual void OnSizeChanged( int newWide, int newTall );
  252. void ArmFirstMenuItem( void );
  253. void OnGameUIHidden();
  254. virtual void CloseBaseDialogs( void );
  255. bool IsWaitingForConsoleUI( void ) { return m_bWaitingForStorageDeviceHandle || m_bWaitingForUserSignIn || m_bXUIVisible; }
  256. bool LoadingProgressWantsIsolatedRender( bool bContextValid );
  257. bool IsLevelLoading( void ) const { return m_bLevelLoading; }
  258. #if defined( _GAMECONSOLE )
  259. CON_COMMAND_MEMBER_F( CBaseModPanel, "gameui_reload_resources", Reload_Resources, "Reload the Xbox 360 UI res files", 0 );
  260. #endif
  261. protected:
  262. virtual void PaintBackground();
  263. virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
  264. // [jason] Input locking and unlocking based on user sign-in
  265. virtual void LockInput( void );
  266. virtual void UnlockInput( void );
  267. // [jason] Allow toggle of the new scaleform version of the main menu
  268. virtual void ShowScaleformMainMenu( bool bShow );
  269. virtual bool IsScaleformMainMenuActive( void );
  270. virtual bool IsScaleformIntroMovieEnabled( void ) { return false; }
  271. virtual void CreateScaleformIntroMovie( void ) {}
  272. virtual void DismissScaleformIntroMovie( void ) {}
  273. void CreateStartScreenIfNeeded( void );
  274. int CheckForAnyKeyPressed( bool bCheckKeyboard );
  275. void ForcePrimaryUserId( int id ) { m_primaryUserId = id; }
  276. public:
  277. // FIXME: This should probably become a friend relationship between the classes
  278. bool HandleSignInRequest( const char *command );
  279. bool HandleStorageDeviceRequest( const char *command );
  280. void ClearPostPromptCommand( const char *pCompletedCommand );
  281. bool IsSinglePlayer() const { return m_bSinglePlayer; }
  282. void SetSinglePlayer( bool singlePlayer ) { m_bSinglePlayer = singlePlayer; }
  283. void UpdateRichPresenceInfo();
  284. virtual void OnCommand(const char *command);
  285. //HACK: could make this generic...
  286. bool m_bReturnToMPGameMenuOnDisconnect;
  287. bool m_bForceQuitToDesktopOnDisconnect;
  288. protected:
  289. virtual void StartExitingProcess( void );
  290. void SetStatsLoaded( bool value ) { m_bStatsLoaded = value; }
  291. bool GetStatsLoaded( void ) const { return m_bStatsLoaded; }
  292. private:
  293. enum EBackgroundState
  294. {
  295. BACKGROUND_INITIAL,
  296. BACKGROUND_LOADING,
  297. BACKGROUND_MAINMENU,
  298. BACKGROUND_LEVEL,
  299. BACKGROUND_DISCONNECTED,
  300. BACKGROUND_EXITING, // Console has started an exiting state, cannot be stopped
  301. };
  302. void SetBackgroundRenderState(EBackgroundState state);
  303. friend class CAsyncCtxOnDeviceAttached;
  304. void OnDeviceAttached( void );
  305. void OnCompletedAsyncDeviceAttached( CAsyncCtxOnDeviceAttached *job );
  306. void IssuePostPromptCommand( void );
  307. void UpdateBackgroundState();
  308. // sets the menu alpha [0..255]
  309. void SetMenuAlpha(int alpha);
  310. // menu manipulation
  311. void CreatePlatformMenu();
  312. void CreateGameMenu();
  313. void CreateGameLogo();
  314. void CheckBonusBlinkState();
  315. void UpdateGameMenus();
  316. CGameMenu *RecursiveLoadGameMenu(KeyValues *datafile);
  317. bool IsPromptableCommand( const char *command );
  318. bool CommandRequiresSignIn( const char *command );
  319. bool CommandRequiresStorageDevice( const char *command );
  320. bool CommandRespectsSignInDenied( const char *command );
  321. void QueueCommand( const char *pCommand );
  322. void RunQueuedCommands();
  323. void ClearQueuedCommands();
  324. virtual void PerformLayout();
  325. MESSAGE_FUNC_INT( OnActivateModule, "ActivateModule", moduleIndex);
  326. void LoadVersionNumbers();
  327. bool LoadVersionNumber( const char *fileNameA, const char *fileNameB, wchar_t *pVersionBuffer, unsigned int versionBufferSizeBytes );
  328. // Primary user id: used to determine signin privileges, etc
  329. int m_primaryUserId;
  330. // menu logo
  331. CMainMenuGameLogo *m_pGameLogo;
  332. // menu buttons
  333. CUtlVector< CBackgroundMenuButton * >m_pGameMenuButtons;
  334. CGameMenu *m_pGameMenu;
  335. bool m_bPlatformMenuInitialized;
  336. int m_iGameMenuInset;
  337. struct coord {
  338. int x;
  339. int y;
  340. };
  341. CUtlVector< coord > m_iGameTitlePos;
  342. coord m_iGameMenuPos;
  343. // base dialogs
  344. vgui::DHANDLE<vgui::Frame> m_hNewGameDialog;
  345. vgui::DHANDLE<vgui::Frame> m_hBonusMapsDialog;
  346. vgui::DHANDLE<vgui::Frame> m_hLoadGameDialog;
  347. vgui::DHANDLE<vgui::Frame> m_hLoadGameDialog_Xbox;
  348. vgui::DHANDLE<vgui::Frame> m_hSaveGameDialog;
  349. vgui::DHANDLE<vgui::Frame> m_hSaveGameDialog_Xbox;
  350. vgui::DHANDLE<vgui::PropertyDialog> m_hOptionsDialog;
  351. vgui::DHANDLE<vgui::Frame> m_hCreateMultiplayerGameDialog;
  352. //vgui::DHANDLE<vgui::Frame> m_hDemoPlayerDialog;
  353. vgui::DHANDLE<vgui::Frame> m_hChangeGameDialog;
  354. vgui::DHANDLE<vgui::Frame> m_hPlayerListDialog;
  355. vgui::DHANDLE<vgui::Frame> m_hBenchmarkDialog;
  356. vgui::DHANDLE<vgui::Frame> m_hLoadCommentaryDialog;
  357. vgui::Label *m_pCodeVersionLabel;
  358. vgui::Label *m_pContentVersionLabel;
  359. EBackgroundState m_eBackgroundState;
  360. CMessageDialogHandler m_MessageDialogHandler;
  361. CUtlVector< CUtlString > m_CommandQueue;
  362. vgui::AnimationController *m_pConsoleAnimationController;
  363. KeyValues *m_pConsoleControlSettings;
  364. void DrawBackgroundImage();
  365. int m_iBackgroundImageID;
  366. int m_iRenderTargetImageID;
  367. int m_iLoadingImageID;
  368. int m_iProductImageID;
  369. bool m_bLevelLoading;
  370. bool m_bEverActivated;
  371. bool m_bCopyFrameBuffer;
  372. bool m_bUseRenderTargetImage;
  373. int m_ExitingFrameCount;
  374. bool m_bXUIVisible;
  375. bool m_bUseMatchmaking;
  376. bool m_bRestartFromInvite;
  377. bool m_bRestartSameGame;
  378. // Used for internal state dealing with blades
  379. bool m_bUserRefusedSignIn;
  380. bool m_bUserRefusedStorageDevice;
  381. bool m_bWaitingForUserSignIn;
  382. bool m_bStorageBladeShown;
  383. CUtlString m_strPostPromptCommand;
  384. // Used on PS3 to make sure stats get loaded before the player presses start.
  385. bool m_bStatsLoaded;
  386. // Storage device changing vars
  387. bool m_bWaitingForStorageDeviceHandle;
  388. bool m_bNeedStorageDeviceHandle;
  389. AsyncHandle_t m_hStorageDeviceChangeHandle;
  390. uint m_iStorageID;
  391. int *m_pStorageDeviceValidatedNotify;
  392. // background transition
  393. bool m_bFadingInMenus;
  394. float m_flFadeMenuStartTime;
  395. float m_flFadeMenuEndTime;
  396. bool m_bRenderingBackgroundTransition;
  397. float m_flTransitionStartTime;
  398. float m_flTransitionEndTime;
  399. // Used for rich presence updates on xbox360
  400. bool m_bSinglePlayer;
  401. uint m_iGameID; // matches context value in hl2orange.spa.h
  402. // background fill transition
  403. bool m_bHaveDarkenedBackground;
  404. bool m_bHaveDarkenedTitleText;
  405. bool m_bForceTitleTextUpdate;
  406. float m_flFrameFadeInTime;
  407. Color m_BackdropColor;
  408. CPanelAnimationVar( float, m_flBackgroundFillAlpha, "m_flBackgroundFillAlpha", "0" );
  409. // [jason] For platforms that don't require the start screen to set the default controller
  410. bool m_bBypassStartScreen;
  411. // [jason] When flagged, we initially display "Press Start" screen and wait for controller input
  412. bool m_bShowStartScreen;
  413. // [jason] Have we been notified (via CreateStartScreen) that the signin completed successfully?
  414. bool m_bStartScreenPlayerSigninCompleted;
  415. // [jason] Should we use the Scaleform main menu, or the old vgui one?
  416. bool m_bScaleformMainMenuEnabled;
  417. bool m_bScaleformPauseMenuEnabled;
  418. // [jason] Last value that ShowMainMenu was called with: is the old vgui active or not?
  419. bool m_bMainMenuShown;
  420. protected:
  421. int m_iIntroMovieButtonPressed;
  422. bool m_bIntroMovieWaitForButtonToClear;
  423. // [sb] If true, then force us back to the start screen; useful for when primary player signs out
  424. bool m_bForceStartScreen;
  425. public:
  426. void SetForceStartScreen() { m_bForceStartScreen = true; };
  427. protected:
  428. // fading to game
  429. MESSAGE_FUNC_CHARPTR( RunEngineCommand, "RunEngineCommand", command );
  430. MESSAGE_FUNC_CHARPTR( RunMenuCommand, "RunMenuCommand", command );
  431. MESSAGE_FUNC_INT_CHARPTR( RunSlottedMenuCommand, "RunSlottedMenuCommand", slot, command );
  432. MESSAGE_FUNC( FinishDialogClose, "FinishDialogClose" );
  433. };
  434. //-----------------------------------------------------------------------------
  435. // Purpose: singleton accessor
  436. //
  437. // These must be defined in the mod's derived panel
  438. //-----------------------------------------------------------------------------
  439. extern CBaseModPanel *BasePanel();
  440. extern CBaseModPanel *BasePanelSingleton(); // Constructs if not built yet
  441. #endif
  442. #endif // BASEPANEL_H