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.

294 lines
8.4 KiB

  1. //========= Copyright � 1996-2008, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=====================================================================================//
  6. #ifndef __UIGAMEDATA_H__
  7. #define __UIGAMEDATA_H__
  8. #undef XBX_GetPrimaryUserId
  9. #include "vgui_controls/Panel.h"
  10. #include "vgui_controls/Frame.h"
  11. #include "vgui_controls/Button.h"
  12. #include "tier1/utllinkedlist.h"
  13. #include "tier1/UtlMap.h"
  14. #include "tier1/keyvalues.h"
  15. #include "tier1/fmtstr.h"
  16. #ifndef _GAMECONSOLE
  17. #include "steam/steam_api.h"
  18. #endif // _GAMECONSOLE
  19. #include "matchmaking/imatchframework.h"
  20. #include "matchmaking/imatchsystem.h"
  21. #include "matchmaking/iplayer.h"
  22. #include "matchmaking/iplayermanager.h"
  23. #include "matchmaking/iservermanager.h"
  24. #include "ixboxsystem.h"
  25. #include "basemodpanel.h"
  26. #include "UIAvatarImage.h"
  27. #include "tokenset.h"
  28. #include "EngineInterface.h"
  29. #include "matchmaking/mm_helpers.h"
  30. namespace BaseModUI {
  31. class CAsyncCtxUIOnDeviceAttached;
  32. extern const tokenset_t< const char * > s_characterPortraits[];
  33. //=============================================================================
  34. //
  35. //=============================================================================
  36. //
  37. // ISelectStorageDeviceClient
  38. //
  39. // Client interface for device selector:
  40. // async flow is as follows:
  41. // client calls into SelectStorageDevice with its parameters established:
  42. // GetCtrlrIndex, ForceSelector, AllowDeclined
  43. // XUI blade shows up (or implicitly determines which device should be picked based on settings).
  44. // if OnSelectError callback fires, then the process failed.
  45. // if OnDeviceNotSelected fires, then the process is over, device not picked
  46. // if OnDeviceFull fires, then device has insufficient capacity and cannot be used
  47. // if OnDeviceSelected fires, then device has been picked and async operations on containers started
  48. // should wait for AfterDeviceMounted callback
  49. // when AfterDeviceMounted callback fires the device is fully mounted and ready
  50. //
  51. class ISelectStorageDeviceClient
  52. {
  53. public:
  54. virtual int GetCtrlrIndex() = 0; // Controller index (0, 1, 2 or 3)
  55. virtual bool ForceSelector() = 0; // Whether device selector should be forcefully shown
  56. virtual bool AllowDeclined() = 0; // Whether declining storage device is allowed
  57. virtual bool AllowAnyController() = 0; // Whether any connected controller can be selecting storage or only game-committed
  58. enum FailReason_t
  59. {
  60. FAIL_ERROR,
  61. FAIL_NOT_SELECTED,
  62. FAIL_FULL,
  63. FAIL_CORRUPT
  64. };
  65. virtual void OnDeviceFail( FailReason_t eReason ) = 0; // Storage device has not been set
  66. virtual void OnDeviceSelected() = 0; // After device has been picked in XUI blade, but before mounting symbolic roots and opening containers
  67. virtual void AfterDeviceMounted() = 0; // After device has been successfully mounted, configs processed, etc.
  68. };
  69. //
  70. // CChangeStorageDevice
  71. //
  72. // Should be used when user wants to change storage device
  73. //
  74. class CChangeStorageDevice : public ISelectStorageDeviceClient
  75. {
  76. public:
  77. explicit CChangeStorageDevice( int iCtrlr );
  78. virtual ~CChangeStorageDevice() {}
  79. public:
  80. virtual int GetCtrlrIndex() { return m_iCtrlr; }
  81. virtual bool ForceSelector() { return m_bForce; }
  82. virtual bool AllowDeclined() { return m_bAllowDeclined; }
  83. virtual bool AllowAnyController() { return m_bAnyController; }
  84. virtual void OnDeviceFail( FailReason_t eReason ); // Storage device has not been set
  85. virtual void OnDeviceSelected(); // After device has been picked in XUI blade, but before mounting symbolic roots and opening containers
  86. virtual void AfterDeviceMounted(); // After device has been successfully mounted, configs processed, etc.
  87. public:
  88. // Fired as a follow-up after all async operations finish and
  89. // all confirmation boxes are closed down by user
  90. virtual void DeviceChangeCompleted( bool bChanged );
  91. public:
  92. int m_iCtrlr;
  93. bool m_bForce;
  94. bool m_bAllowDeclined;
  95. bool m_bAnyController;
  96. int m_nConfirmationData;
  97. };
  98. //
  99. // UI game data
  100. //
  101. class CUIGameData : public IMatchEventsSink
  102. {
  103. public:
  104. CUIGameData();
  105. ~CUIGameData();
  106. static CUIGameData* Get();
  107. static void Shutdown();
  108. void RunFrame();
  109. void RunFrame_Storage();
  110. void RunFrame_Invite();
  111. void Invite_Confirm();
  112. void Invite_Connecting();
  113. bool Invite_IsStorageDeviceValid();
  114. void OnGameUIPostInit();
  115. void OpenFriendRequestPanel(int index, uint64 playerXuid);
  116. void OpenInviteUI( char const *szInviteUiType );
  117. void ExecuteOverlayCommand( char const *szCommand );
  118. // Listening for match events
  119. virtual void OnEvent( KeyValues *pEvent );
  120. bool SignedInToLive();
  121. bool AnyUserSignedInToLiveWithMultiplayerDisabled();
  122. const char *GetLocalPlayerName( int iController );
  123. bool SelectStorageDevice( ISelectStorageDeviceClient *pSelectClient );
  124. void OnDeviceAttached();
  125. void OnCompletedAsyncDeviceAttached( CAsyncCtxUIOnDeviceAttached * job );
  126. void OnGameUIHidden();
  127. bool IsXUIOpen();
  128. void NeedConnectionProblemWaitScreen( void );
  129. void ShowPasswordUI( char const *pchCurrentPW );
  130. vgui::IImage * GetAvatarImage( XUID playerID );
  131. char const * GetPlayerName( XUID playerID, char const *szPlayerNameSpeculative );
  132. #if !defined( _GAMECONSOLE ) && !defined( NO_STEAM )
  133. STEAM_CALLBACK( CUIGameData, Steam_OnPersonaStateChanged, PersonaStateChange_t, m_CallbackPersonaStateChanged );
  134. #endif
  135. void ReloadScheme();
  136. //
  137. // Implementation of async jobs
  138. // An async job is enqueued by calling "ExecuteAsync" with the proper job context.
  139. // Job's function "ExecuteAsync" is called on a separate thread.
  140. // After the job finishes the "Completed" function is called on the
  141. // main thread.
  142. //
  143. class CAsyncJobContext
  144. {
  145. public:
  146. CAsyncJobContext( float flLeastExecuteTime = 0.0f ) : m_flLeastExecuteTime( flLeastExecuteTime ), m_hThreadHandle( NULL ) {}
  147. virtual ~CAsyncJobContext() {}
  148. virtual void ExecuteAsync() = 0; // Executed on the secondary thread
  149. virtual void Completed() = 0; // Executed on the main thread
  150. public:
  151. void * volatile m_hThreadHandle; // Handle to an async job thread waiting for
  152. float m_flLeastExecuteTime; // Least amount of time this job should keep executing
  153. };
  154. CAsyncJobContext *m_pAsyncJob;
  155. void ExecuteAsync( CAsyncJobContext *pAsync );
  156. private:
  157. bool IsActiveSplitScreenPlayerSpectating( void );
  158. protected:
  159. static CUIGameData* m_Instance;
  160. static bool m_bModuleShutDown;
  161. bool m_CGameUIPostInit;
  162. float m_flShowConnectionProblemTimer;
  163. float m_flTimeLastFrame;
  164. bool m_bShowConnectionProblemActive;
  165. CUtlMap< XUID, CGameUiAvatarImage * > m_mapUserXuidToAvatar;
  166. CUtlMap< XUID, CUtlString > m_mapUserXuidToName;
  167. //XUI info
  168. bool m_bXUIOpen;
  169. //storage device info
  170. bool m_bWaitingForStorageDeviceHandle;
  171. AsyncHandle_t m_hStorageDeviceChangeHandle;
  172. uint m_iStorageID;
  173. int m_iStorageController;
  174. ISelectStorageDeviceClient *m_pSelectStorageClient;
  175. void OnSetStorageDeviceId( int iController, uint nDeviceId );
  176. };
  177. }
  178. extern ConVar demo_ui_enable;
  179. extern ConVar demo_connect_string;
  180. uint64 GetDlcInstalledMask();
  181. //
  182. // RemapText_t arrText[] = {
  183. // { "", "#SessionError_Unknown", RemapText_t::MATCH_FULL },
  184. // { "n/a", "#SessionError_NotAvailable", RemapText_t::MATCH_FULL },
  185. // { "create", "#SessionError_Create", RemapText_t::MATCH_FULL },
  186. // { "connect", "#SessionError_Connect", RemapText_t::MATCH_FULL },
  187. // { "full", "#SessionError_Full", RemapText_t::MATCH_FULL },
  188. // { "lock", "#SessionError_Lock", RemapText_t::MATCH_FULL },
  189. // { "kicked", "#SessionError_Kicked", RemapText_t::MATCH_FULL },
  190. // { "migrate", "#SessionError_Migrate", RemapText_t::MATCH_FULL },
  191. // { "SteamServersDisconnected", "#SessionError_SteamServersDisconnected", RemapText_t::MATCH_FULL },
  192. // { NULL, NULL, RemapText_t::MATCH_FULL }
  193. // };
  194. // szReason = RemapText_t::RemapRawText( arrText, szReason );
  195. //
  196. struct RemapText_t
  197. {
  198. char const *m_szRawText;
  199. char const *m_szRemapText;
  200. enum MatchPolicy_t
  201. {
  202. MATCH_FULL,
  203. MATCH_SUBSTR,
  204. MATCH_START
  205. };
  206. MatchPolicy_t m_eMatchPolicy;
  207. inline bool Match( char const *szRawText )
  208. {
  209. switch( m_eMatchPolicy )
  210. {
  211. case MATCH_FULL:
  212. return !Q_stricmp( szRawText, m_szRawText );
  213. case MATCH_SUBSTR:
  214. return Q_stristr( szRawText, m_szRawText ) != NULL;
  215. case MATCH_START:
  216. return StringHasPrefix( szRawText, m_szRawText );
  217. default:
  218. return false;
  219. }
  220. }
  221. inline static char const * RemapRawText( RemapText_t *pRemapTable, char const *szRawText )
  222. {
  223. for ( ; pRemapTable && pRemapTable->m_szRawText; ++ pRemapTable )
  224. {
  225. if ( pRemapTable->Match( szRawText ) )
  226. {
  227. return pRemapTable->m_szRemapText;
  228. }
  229. }
  230. return szRawText;
  231. }
  232. };
  233. #endif // __UIGAMEDATA_H__