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.

297 lines
8.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "tf_gc_client.h"
  8. #include "tf_party.h"
  9. #include "vgui_controls/PropertySheet.h"
  10. #include "vgui_controls/ComboBox.h"
  11. #include "vgui_controls/ScrollableEditablePanel.h"
  12. #include "vgui_avatarimage.h"
  13. #include "tf_leaderboardpanel.h"
  14. #include "tf_lobbypanel_comp.h"
  15. #include "tf_hud_mainmenuoverride.h"
  16. #include "tf_lobby_container_frame_comp.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include <tier0/memdbgon.h>
  19. //-----------------------------------------------------------------------------
  20. // Purpose: Override of the generic messagebox dialog to provide a welcome-to-competitive message
  21. //-----------------------------------------------------------------------------
  22. ConVar tf_comp_welcome_hide_forever( "tf_comp_welcome_hide_forever", "0", FCVAR_ARCHIVE | FCVAR_HIDDEN );
  23. ConVar tf_comp_welcome_hide( "tf_comp_welcome_hide", "0", FCVAR_HIDDEN );
  24. class CTFCompetitiveWelcomeDialog : public CTFMessageBoxDialog
  25. {
  26. DECLARE_CLASS_SIMPLE( CTFCompetitiveWelcomeDialog, CTFMessageBoxDialog );
  27. public:
  28. CTFCompetitiveWelcomeDialog()
  29. : CTFMessageBoxDialog( NULL, (const char *)NULL, NULL, NULL, NULL )
  30. {}
  31. virtual ~CTFCompetitiveWelcomeDialog() {};
  32. virtual void OnCommand( const char *command )
  33. {
  34. if ( FStrEq( "hideforever", command ) )
  35. {
  36. tf_comp_welcome_hide_forever.SetValue( 1 );
  37. return;
  38. }
  39. else if ( FStrEq( "show_explanations", command ) )
  40. {
  41. CHudMainMenuOverride *pMMOverride = (CHudMainMenuOverride*)( gViewPortInterface->FindPanelByName( PANEL_MAINMENUOVERRIDE ) );
  42. pMMOverride->GetCompLobbyPanel()->OnCommand( command );
  43. OnCommand( "confirm" );
  44. return;
  45. }
  46. BaseClass::OnCommand( command );
  47. }
  48. MESSAGE_FUNC_PTR( OnCheckButtonChecked, "CheckButtonChecked", panel )
  49. {
  50. CheckButton* pNeverAskAgainCheckBox = FindControl< CheckButton >( "NeverShowAgainCheckBox" );
  51. if ( panel == pNeverAskAgainCheckBox )
  52. {
  53. tf_comp_welcome_hide_forever.SetValue( pNeverAskAgainCheckBox->IsSelected() );
  54. }
  55. }
  56. virtual const char *GetResFile() OVERRIDE
  57. {
  58. // FIXME controller?
  59. return "Resource/UI/CompetitiveWelcomeDialog.res";
  60. }
  61. };
  62. //-----------------------------------------------------------------------------
  63. CLobbyContainerFrame_Comp::CLobbyContainerFrame_Comp()
  64. : CBaseLobbyContainerFrame( "LobbyContainerFrame" )
  65. {
  66. // Our internal lobby panel
  67. m_pContents = new CLobbyPanel_Comp( this, this );
  68. m_pContents->AddActionSignalTarget( this );
  69. AddPage( m_pContents, "#TF_Matchmaking_HeaderCompetitive" );
  70. GetPropertySheet()->SetNavToRelay( m_pContents->GetName() );
  71. m_pContents->SetVisible( true );
  72. }
  73. //-----------------------------------------------------------------------------
  74. CLobbyContainerFrame_Comp::~CLobbyContainerFrame_Comp( void )
  75. {
  76. }
  77. void CLobbyContainerFrame_Comp::ShowPanel( bool bShow )
  78. {
  79. if ( bShow )
  80. {
  81. if ( tf_comp_welcome_hide.GetBool() == false
  82. && tf_comp_welcome_hide_forever.GetBool() == false
  83. && GTFGCClientSystem()->GetWizardStep() == TF_Matchmaking_WizardStep_LADDER )
  84. {
  85. CTFCompetitiveWelcomeDialog *pDialog = vgui::SETUP_PANEL( new CTFCompetitiveWelcomeDialog() );
  86. if ( pDialog )
  87. {
  88. tf_comp_welcome_hide.SetValue( 1 );
  89. pDialog->Show();
  90. }
  91. else
  92. {
  93. Warning( "Failed to create CompetitiveWelcomeDialog. Outdated HUD?\n" );
  94. }
  95. }
  96. }
  97. BaseClass::ShowPanel( bShow );
  98. }
  99. void CLobbyContainerFrame_Comp::OnCommand( const char *command )
  100. {
  101. if ( FStrEq( command, "next" ) )
  102. {
  103. switch ( GTFGCClientSystem()->GetWizardStep() )
  104. {
  105. case TF_Matchmaking_WizardStep_LADDER:
  106. StartSearch();
  107. break;
  108. default:
  109. AssertMsg1( false, "Unexpected wizard step %d", (int)GTFGCClientSystem()->GetWizardStep() );
  110. break;
  111. }
  112. return;
  113. }
  114. else if ( FStrEq( command, "show_explanations" ) )
  115. {
  116. CExplanationPopup *pPopup = FindControl<CExplanationPopup>( "StartExplanation" );
  117. if ( pPopup )
  118. {
  119. pPopup->Popup();
  120. }
  121. return;
  122. }
  123. BaseClass::OnCommand( command );
  124. }
  125. //-----------------------------------------------------------------------------
  126. void CLobbyContainerFrame_Comp::WriteControls()
  127. {
  128. // Make sure we want to be in matchmaking. (If we don't, the frame should hide us pretty quickly.)
  129. // We might get an event or something right at the transition point occasionally when the UI should
  130. // not be visible
  131. if ( GTFGCClientSystem()->GetMatchmakingUIState() == eMatchmakingUIState_Inactive )
  132. {
  133. return;
  134. }
  135. const char *pszBackButtonText = "#TF_Matchmaking_Back";
  136. const char *pszNextButtonText = NULL;
  137. if ( GCClientSystem()->BConnectedtoGC() )
  138. {
  139. if ( BIsPartyLeader() )
  140. {
  141. switch ( GTFGCClientSystem()->GetWizardStep() )
  142. {
  143. case TF_Matchmaking_WizardStep_LADDER:
  144. pszBackButtonText = "#TF_Matchmaking_Back";
  145. pszNextButtonText = "#TF_Matchmaking_StartSearch";
  146. break;
  147. case TF_Matchmaking_WizardStep_SEARCHING:
  148. pszBackButtonText = "#TF_Matchmaking_CancelSearch";
  149. break;
  150. case TF_Matchmaking_WizardStep_INVALID:
  151. // Still being setup
  152. break;
  153. default:
  154. AssertMsg1( false, "Unknown wizard step %d", (int)GTFGCClientSystem()->GetWizardStep() );
  155. break;
  156. }
  157. }
  158. else
  159. {
  160. pszBackButtonText = "#TF_Matchmaking_LeaveParty";
  161. m_pNextButton->SetEnabled( false );
  162. }
  163. }
  164. m_pBackButton->SetText( pszBackButtonText );
  165. m_pNextButton->SetText( pszNextButtonText );
  166. m_pNextButton->SetVisible( pszNextButtonText != NULL );
  167. BaseClass::WriteControls();
  168. }
  169. //-----------------------------------------------------------------------------
  170. bool CheckCompetitiveConvars()
  171. {
  172. static ConVarRef mat_dxlevel( "mat_dxlevel");
  173. return mat_dxlevel.GetInt() >= 90;
  174. }
  175. //-----------------------------------------------------------------------------
  176. bool CLobbyContainerFrame_Comp::VerifyPartyAuthorization() const
  177. {
  178. // Solo
  179. CTFParty *pParty = GTFGCClientSystem()->GetParty();
  180. if ( pParty == NULL || pParty->GetNumMembers() <= 1 )
  181. {
  182. if ( !GTFGCClientSystem()->BHasCompetitiveAccess() )
  183. {
  184. ShowEconRequirementDialog( "#TF_Competitive_RequiresPass_Title", "#TF_Competitive_RequiresPass", CTFItemSchema::k_rchLadderPassItemDefName );
  185. return false;
  186. }
  187. else if ( !CheckCompetitiveConvars() )
  188. {
  189. ShowMessageBox( "#TF_Competitive_Convars_CantProceed_Title", "#TF_Competitive_Convars_CantProceed", "#GameUI_OK" );
  190. return false;
  191. }
  192. }
  193. // Group
  194. else
  195. {
  196. wchar_t wszLocalized[512];
  197. char szLocalized[512];
  198. wchar_t wszCharPlayerName[128];
  199. bool bAnyMembersWithoutAuth = false;
  200. for ( int i = 0 ; i < pParty->GetNumMembers() ; ++i )
  201. {
  202. // Need a ticket and two-factor for the beta
  203. if ( !pParty->Obj().members( i ).competitive_access() )
  204. {
  205. bAnyMembersWithoutAuth = true;
  206. V_UTF8ToUnicode( steamapicontext->SteamFriends()->GetFriendPersonaName( pParty->GetMember( i ) ), wszCharPlayerName, sizeof( wszCharPlayerName ) );
  207. g_pVGuiLocalize->ConstructString_safe( wszLocalized, g_pVGuiLocalize->Find( "#TF_Matchmaking_MissingPass" ), 1, wszCharPlayerName );
  208. g_pVGuiLocalize->ConvertUnicodeToANSI( wszLocalized, szLocalized, sizeof( szLocalized ) );
  209. GTFGCClientSystem()->SendSteamLobbyChat( CTFGCClientSystem::k_eLobbyMsg_SystemMsgFromLeader, szLocalized );
  210. }
  211. }
  212. if ( bAnyMembersWithoutAuth )
  213. {
  214. ShowMessageBox( "#TF_Competitive_RequiresPass_Title", "#TF_Competitive_RequiresPass", "#GameUI_OK" );
  215. return false;
  216. }
  217. }
  218. CLobbyPanel_Comp* pCompContents = static_cast< CLobbyPanel_Comp* >( m_pContents );
  219. if ( pCompContents )
  220. {
  221. uint32 unModeType = pCompContents->GetMatchGroup();
  222. if ( unModeType >= k_nMatchGroup_Ladder_First && unModeType <= k_nMatchGroup_Ladder_Last )
  223. {
  224. GTFGCClientSystem()->SetLadderType( unModeType );
  225. }
  226. }
  227. return true;
  228. }
  229. void CLobbyContainerFrame_Comp::HandleBackPressed()
  230. {
  231. switch ( GTFGCClientSystem()->GetWizardStep() )
  232. {
  233. case TF_Matchmaking_WizardStep_LADDER:
  234. // !FIXME! Really need to confirm this!
  235. GTFGCClientSystem()->EndMatchmaking();
  236. // And hide us
  237. ShowPanel( false );
  238. return;
  239. case TF_Matchmaking_WizardStep_SEARCHING:
  240. switch ( GTFGCClientSystem()->GetSearchMode() )
  241. {
  242. case TF_Matchmaking_LADDER:
  243. GTFGCClientSystem()->RequestSelectWizardStep( TF_Matchmaking_WizardStep_LADDER );
  244. return;
  245. }
  246. break;
  247. default:
  248. Msg( "Unexpected wizard step %d", (int)GTFGCClientSystem()->GetWizardStep() );
  249. break;
  250. }
  251. // Unhandled case
  252. BaseClass::HandleBackPressed();
  253. }