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.

365 lines
11 KiB

  1. //========= Copyright � 1996-2008, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=====================================================================================//
  6. #ifndef __UIGAMEDATA_H__
  7. #define __UIGAMEDATA_H__
  8. #include "vgui_controls/Panel.h"
  9. #include "vgui_controls/Frame.h"
  10. #include "vgui_controls/Button.h"
  11. #include "tier1/utllinkedlist.h"
  12. #include "tier1/utlmap.h"
  13. #include "tier1/keyvalues.h"
  14. #include "tier1/fmtstr.h"
  15. #if !defined( NO_STEAM )
  16. #include "steam/steam_api.h"
  17. #endif // !defined( NO_STEAM )
  18. #include "matchmaking/imatchframework.h"
  19. #include "matchmaking/imatchsystem.h"
  20. #include "matchmaking/iplayer.h"
  21. #include "matchmaking/iplayermanager.h"
  22. #include "matchmaking/iservermanager.h"
  23. #include "ixboxsystem.h"
  24. #include "uiavatarimage.h"
  25. #include "tokenset.h"
  26. #include "engineinterface.h"
  27. #include "matchmaking/mm_helpers.h"
  28. namespace BaseModUI {
  29. class CAsyncCtxUIOnDeviceAttached;
  30. class CAvatarImage;
  31. class CBaseModFrame;
  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. bool CanPlayer2Join();
  116. void OpenFriendRequestPanel(int index, uint64 playerXuid);
  117. void OpenInviteUI( char const *szInviteUiType );
  118. void ExecuteOverlayCommand( char const *szCommand );
  119. // Listening for match events
  120. virtual void OnEvent( KeyValues *pEvent );
  121. bool SignedInToLive();
  122. bool AnyUserSignedInToLiveWithMultiplayerDisabled();
  123. bool CheckAndDisplayErrorIfNotSignedInToLive( CBaseModFrame *pCallerFrame );
  124. bool CheckAndDisplayErrorIfOffline( CBaseModFrame *pCallerFrame, char const *szMsg );
  125. void DisplayOkOnlyMsgBox( CBaseModFrame *pCallerFrame, const char *szTitle, const char *szMsg );
  126. CBaseModFrame * GetParentWindowForSystemMessageBox();
  127. const char *GetLocalPlayerName( int iController );
  128. bool SelectStorageDevice( ISelectStorageDeviceClient *pSelectClient );
  129. void OnDeviceAttached();
  130. void OnCompletedAsyncDeviceAttached( CAsyncCtxUIOnDeviceAttached * job );
  131. void OnGameUIHidden();
  132. void SetLookSensitivity(float sensitivity);
  133. float GetLookSensitivity();
  134. bool IsXUIOpen();
  135. void OpenWaitScreen( const char * messageText, float minDisplayTime = 3.0f, KeyValues *pSettings = NULL );
  136. void UpdateWaitPanel( const char * messageText, float minDisplayTime = 3.0f );
  137. void UpdateWaitPanel( const wchar_t * messageText, float minDisplayTime = 3.0f );
  138. void CloseWaitScreen( vgui::Panel * callbackPanel, const char * messageName );
  139. void NeedConnectionProblemWaitScreen( void );
  140. void ShowPasswordUI( char const *pchCurrentPW );
  141. void FinishPasswordUI( bool bOk );
  142. vgui::IImage * GetAvatarImage( XUID playerID );
  143. char const * GetPlayerName( XUID playerID, char const *szPlayerNameSpeculative );
  144. #if !defined( NO_STEAM )
  145. STEAM_CALLBACK( CUIGameData, Steam_OnUserStatsReceived, UserStatsReceived_t, m_CallbackUserStatsReceived );
  146. STEAM_CALLBACK( CUIGameData, Steam_OnUserStatsStored, UserStatsStored_t, m_CallbackUserStatsStored );
  147. #endif
  148. #if !defined( _GAMECONSOLE ) && !defined( NO_STEAM )
  149. STEAM_CALLBACK( CUIGameData, Steam_OnPersonaStateChanged, PersonaStateChange_t, m_CallbackPersonaStateChanged );
  150. #endif
  151. void ReloadScheme();
  152. //
  153. // Implementation of async jobs
  154. // An async job is enqueued by calling "ExecuteAsync" with the proper job context.
  155. // Job's function "ExecuteAsync" is called on a separate thread.
  156. // After the job finishes the "Completed" function is called on the
  157. // main thread.
  158. //
  159. class CAsyncJobContext
  160. {
  161. public:
  162. explicit CAsyncJobContext( float flLeastExecuteTime = 0.0f ) : m_flLeastExecuteTime( flLeastExecuteTime ), m_hThreadHandle( NULL ) {}
  163. virtual ~CAsyncJobContext() {}
  164. virtual void ExecuteAsync() = 0; // Executed on the secondary thread
  165. virtual void Completed() = 0; // Executed on the main thread
  166. public:
  167. void * volatile m_hThreadHandle; // Handle to an async job thread waiting for
  168. float m_flLeastExecuteTime; // Least amount of time this job should keep executing
  169. };
  170. CAsyncJobContext *m_pAsyncJob;
  171. void ExecuteAsync( CAsyncJobContext *pAsync );
  172. private:
  173. bool IsActiveSplitScreenPlayerSpectating( void );
  174. protected:
  175. static CUIGameData* m_Instance;
  176. static bool m_bModuleShutDown;
  177. bool m_CGameUIPostInit;
  178. float m_LookSensitivity;
  179. float m_flShowConnectionProblemTimer;
  180. float m_flTimeLastFrame;
  181. bool m_bShowConnectionProblemActive;
  182. CUtlMap< XUID, CAvatarImage * > m_mapUserXuidToAvatar;
  183. CUtlMap< XUID, CUtlString > m_mapUserXuidToName;
  184. //XUI info
  185. bool m_bXUIOpen;
  186. //storage device info
  187. bool m_bWaitingForStorageDeviceHandle;
  188. AsyncHandle_t m_hStorageDeviceChangeHandle;
  189. uint m_iStorageID;
  190. int m_iStorageController;
  191. ISelectStorageDeviceClient *m_pSelectStorageClient;
  192. void OnSetStorageDeviceId( int iController, uint nDeviceId );
  193. };
  194. }
  195. //extern ConVar x360_audio_english;
  196. extern ConVar demo_ui_enable;
  197. extern ConVar demo_connect_string;
  198. uint64 GetDlcInstalledMask();
  199. bool GameModeHasDifficulty( char const *szGameMode );
  200. bool GameModeHasRoundLimit( char const *szGameMode );
  201. bool GameModeIsSingleChapter( char const *szGameMode );
  202. char const * GameModeGetDefaultDifficulty( char const *szGameMode );
  203. struct DifficultyItem
  204. {
  205. int m_difficultyValue;
  206. const char* m_difficultyStringValue;
  207. const char* m_difficultyUnlocalizedName;
  208. const char* m_difficultyLocKey;
  209. };
  210. struct GameModeItem
  211. {
  212. int m_Value;
  213. const char* m_StringValue;
  214. const char* m_UnlocalizedName;
  215. const char* m_LocKey;
  216. };
  217. extern const GameModeItem gGameModeItems[2];
  218. const char *GameModeStringFromInt( int i );
  219. const char *GameModeLocKeyFromInt( int iMode );
  220. int GameModeIntFromString( const char *szString );
  221. #if defined( _PS3 )
  222. class IPS3SaveSteamInfoProviderUiGameData : public IPS3SaveSteamInfoProvider
  223. {
  224. public:
  225. virtual void RunFrame() = 0;
  226. virtual void WriteSteamStats() = 0;
  227. };
  228. IPS3SaveSteamInfoProviderUiGameData * GetPs3SaveSteamInfoProvider();
  229. #endif
  230. //
  231. // RemapText_t arrText[] = {
  232. // { "", "#SessionError_Unknown", RemapText_t::MATCH_FULL },
  233. // { "n/a", "#SessionError_NotAvailable", RemapText_t::MATCH_FULL },
  234. // { "create", "#SessionError_Create", RemapText_t::MATCH_FULL },
  235. // { "connect", "#SessionError_Connect", RemapText_t::MATCH_FULL },
  236. // { "full", "#SessionError_Full", RemapText_t::MATCH_FULL },
  237. // { "lock", "#SessionError_Lock", RemapText_t::MATCH_FULL },
  238. // { "kicked", "#SessionError_Kicked", RemapText_t::MATCH_FULL },
  239. // { "migrate", "#SessionError_Migrate", RemapText_t::MATCH_FULL },
  240. // { "SteamServersDisconnected", "#SessionError_SteamServersDisconnected", RemapText_t::MATCH_FULL },
  241. // { NULL, NULL, RemapText_t::MATCH_FULL }
  242. // };
  243. // szReason = RemapText_t::RemapRawText( arrText, szReason );
  244. //
  245. struct RemapText_t
  246. {
  247. char const *m_szRawText;
  248. char const *m_szRemapText;
  249. enum MatchPolicy_t
  250. {
  251. MATCH_FULL,
  252. MATCH_SUBSTR,
  253. MATCH_START
  254. };
  255. MatchPolicy_t m_eMatchPolicy;
  256. inline bool Match( char const *szRawText )
  257. {
  258. switch( m_eMatchPolicy )
  259. {
  260. case MATCH_FULL:
  261. return !Q_stricmp( szRawText, m_szRawText );
  262. case MATCH_SUBSTR:
  263. return Q_stristr( szRawText, m_szRawText ) != NULL;
  264. case MATCH_START:
  265. return StringHasPrefix( szRawText, m_szRawText );
  266. default:
  267. return false;
  268. }
  269. }
  270. inline static char const * RemapRawText( RemapText_t *pRemapTable, char const *szRawText )
  271. {
  272. for ( ; pRemapTable && pRemapTable->m_szRawText; ++ pRemapTable )
  273. {
  274. if ( pRemapTable->Match( szRawText ) )
  275. {
  276. return pRemapTable->m_szRemapText;
  277. }
  278. }
  279. return szRawText;
  280. }
  281. };
  282. #endif // __UIGAMEDATA_H__