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.

243 lines
6.1 KiB

  1. //========= Copyright � 1996-2008, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=====================================================================================//
  6. #include "cbase.h"
  7. #include "basemodpanel.h"
  8. #include "UIGameData.h"
  9. // vgui controls
  10. #include "vgui/ILocalize.h"
  11. // matchsystem
  12. #include "matchmaking/imatchframework.h"
  13. #ifndef _GAMECONSOLE
  14. #include "steam/steam_api.h"
  15. #endif
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. using namespace BaseModUI;
  19. using namespace vgui;
  20. //
  21. // Invite approval
  22. //
  23. static int s_nInviteApprovalConf = 0;
  24. static ISelectStorageDeviceClient *s_pPendingInviteStorageSelector = NULL;
  25. enum InviteUserMapping_t
  26. {
  27. INVITE_USER_BLOCK_INPUT,
  28. INVITE_USER_ALLOW_INPUT
  29. };
  30. static void Invite_MapUserForUiInput( InviteUserMapping_t eUi )
  31. {
  32. // Check invited user if it was the active user
  33. #ifdef _GAMECONSOLE
  34. if ( XBX_GetInvitedUserId() == XBX_INVALID_USER_ID )
  35. return;
  36. for ( DWORD k = 0; k < XBX_GetNumGameUsers(); ++ k )
  37. {
  38. if ( XBX_GetInvitedUserId() == (DWORD) XBX_GetUserId( k ) )
  39. return;
  40. }
  41. // Invited user artificial mapping
  42. switch ( eUi )
  43. {
  44. case INVITE_USER_BLOCK_INPUT:
  45. XBX_ClearUserId( XBX_GetInvitedUserId() );
  46. break;
  47. case INVITE_USER_ALLOW_INPUT:
  48. XBX_SetUserId( XBX_GetNumGameUsers(), XBX_GetInvitedUserId() );
  49. break;
  50. }
  51. #endif
  52. }
  53. static void Invite_NotifyAction( char const *szNotifyAction )
  54. {
  55. s_nInviteApprovalConf = 0;
  56. Invite_MapUserForUiInput( INVITE_USER_BLOCK_INPUT );
  57. g_pMatchFramework->GetEventsSubscription()->BroadcastEvent( new KeyValues(
  58. "OnInvite", "action", szNotifyAction ) );
  59. }
  60. static void Invite_Approved()
  61. {
  62. CUIGameData::Get()->Invite_Connecting();
  63. Invite_NotifyAction( "join" );
  64. }
  65. static void Invite_Declined()
  66. {
  67. Invite_NotifyAction( "deny" );
  68. }
  69. void CUIGameData::RunFrame_Invite()
  70. {
  71. if ( s_nInviteApprovalConf )
  72. {
  73. #if 0 // TODO: UI: // Check that the confirmation wasn't dismissed without notifying the invite system
  74. // Check that the confirmation wasn't dismissed without notifying the invite system
  75. GenericConfirmation* confirmation =
  76. static_cast<GenericConfirmation*>( CBaseModPanel::GetSingleton().GetWindow( WT_GENERICCONFIRMATION ) );
  77. if ( !confirmation ||
  78. confirmation->GetUsageId() != s_nInviteApprovalConf )
  79. {
  80. // Well, pretend like user declined the prompt
  81. Invite_Declined();
  82. }
  83. #endif
  84. }
  85. if ( s_pPendingInviteStorageSelector && !IsXUIOpen() )
  86. {
  87. SelectStorageDevice( s_pPendingInviteStorageSelector );
  88. s_pPendingInviteStorageSelector = NULL;
  89. }
  90. }
  91. //=============================================================================
  92. #ifdef _GAMECONSOLE
  93. class CInviteSelectStorageDevice : public CChangeStorageDevice
  94. {
  95. public:
  96. explicit CInviteSelectStorageDevice();
  97. public:
  98. virtual void DeviceChangeCompleted( bool bChanged );
  99. };
  100. CInviteSelectStorageDevice::CInviteSelectStorageDevice() :
  101. CChangeStorageDevice( XBX_GetInvitedUserId() )
  102. {
  103. // Get UI panel
  104. CBaseModPanel &ui = CBaseModPanel::GetSingleton();
  105. ui.OnGameUIActivated();
  106. // Allow non-involved controller
  107. m_bAnyController = true;
  108. // Don't force to re-select, just reload configs
  109. m_bForce = false;
  110. Invite_MapUserForUiInput( INVITE_USER_ALLOW_INPUT );
  111. }
  112. void CInviteSelectStorageDevice::DeviceChangeCompleted( bool bChanged )
  113. {
  114. CChangeStorageDevice::DeviceChangeCompleted( bChanged );
  115. // Proceed with joining the invite session
  116. Invite_NotifyAction( "join" );
  117. }
  118. #endif
  119. //=============================================================================
  120. bool CUIGameData::Invite_IsStorageDeviceValid()
  121. {
  122. #ifdef _GAMECONSOLE
  123. //
  124. // Note: the only code path that should lead to this routine is
  125. // from invite accepting code.
  126. // XBX_GetInvitedUserId() is set to the user id of who accepted the invite
  127. // For that user the storage device has to be validated.
  128. //
  129. // If this function returns "true" it means that the user has a valid device
  130. // selected and it is safe to proceed with the invite.
  131. //
  132. // If this function returns "false" it will send the "join" action OnInvite event
  133. // after storage device selection process is over.
  134. //
  135. int iCtrlr = XBX_GetInvitedUserId();
  136. if ( iCtrlr < 0 || iCtrlr >= XUSER_MAX_COUNT )
  137. return true;
  138. // Check what device the guy currently has mapped
  139. DWORD dwDevice = XBX_GetStorageDeviceId( iCtrlr );
  140. if ( XBX_DescribeStorageDevice( dwDevice ) ||
  141. XBX_STORAGE_DECLINED == dwDevice )
  142. // The guy has a valid device selected
  143. // or allow the guy to play because we already
  144. // told him earlier that his settings will not
  145. // be saved
  146. return true;
  147. //
  148. // Need to show device selector
  149. //
  150. s_pPendingInviteStorageSelector = new CInviteSelectStorageDevice;
  151. return false;
  152. #endif
  153. return true;
  154. }
  155. void CUIGameData::Invite_Confirm()
  156. {
  157. // Activate game ui
  158. CBaseModPanel &ui = CBaseModPanel::GetSingleton();
  159. if ( !ui.IsVisible() )
  160. {
  161. // Activate game ui to see the dialog
  162. engine->ExecuteClientCmd( "gameui_activate" );
  163. }
  164. #if 0 // TODO: UI: // Show a prompt
  165. // Get current window
  166. CBaseModFrame *pFrame = NULL;
  167. WINDOW_TYPE wt = ui.GetActiveWindowType();
  168. if ( wt != WT_NONE &&
  169. wt != WT_GENERICCONFIRMATION )
  170. pFrame = ui.GetWindow( wt );
  171. // Show a prompt
  172. GenericConfirmation* confirmation =
  173. static_cast<GenericConfirmation*>( ui.
  174. OpenWindow( WT_GENERICCONFIRMATION, pFrame, false ) );
  175. GenericConfirmation::Data_t data;
  176. data.pWindowTitle = "#L4D360UI_LeaveInviteConf";
  177. data.pMessageText = "#L4D360UI_LeaveInviteConfTxt";
  178. data.bOkButtonEnabled = true;
  179. data.bCancelButtonEnabled = true;
  180. data.pfnOkCallback = Invite_Approved;
  181. data.pfnCancelCallback = Invite_Declined;
  182. s_nInviteApprovalConf = confirmation->SetUsageData(data);
  183. #endif
  184. Invite_MapUserForUiInput( INVITE_USER_ALLOW_INPUT );
  185. }
  186. void CUIGameData::Invite_Connecting()
  187. {
  188. // Close any session that we might have outstanding
  189. g_pMatchFramework->CloseSession();
  190. #if 0 // TODO: UI: // Navigate to attract screen which might take a frame
  191. // Navigate to attract screen which might take a frame
  192. CBaseModPanel::GetSingleton().CloseAllWindows( CBaseModPanel::CLOSE_POLICY_EVEN_MSGS );
  193. CAttractScreen::SetAttractMode( CAttractScreen::ATTRACT_ACCEPTINVITE );
  194. CBaseModPanel::GetSingleton().OpenWindow( WT_ATTRACTSCREEN, NULL, true );
  195. #endif
  196. }