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.

215 lines
6.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Disconnect prompt to warn leavers of penalty they will incur
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "cbase.h"
  8. #include "tf_hud_disconnect_prompt.h"
  9. #include "econ_controls.h"
  10. #include "tf_gc_client.h"
  11. #include "tf_gamerules.h"
  12. using namespace vgui;
  13. CTFDisconnectConfirmDialog::CTFDisconnectConfirmDialog(
  14. const char *pTitle,
  15. const char *pTextKey,
  16. const char *pConfirmBtnText,
  17. const char *pCancelBtnText,
  18. GenericConfirmDialogCallback callback,
  19. vgui::Panel *pParent
  20. ) : CTFGenericConfirmDialog( pTitle, pTextKey, pConfirmBtnText, pCancelBtnText, callback, pParent )
  21. {
  22. m_eAbandonStatus = GTFGCClientSystem()->GetCurrentServerAbandonStatus();
  23. }
  24. //-----------------------------------------------------------------------------
  25. // Purpose:
  26. //-----------------------------------------------------------------------------
  27. const char *CTFDisconnectConfirmDialog::GetResFile()
  28. {
  29. switch ( m_eAbandonStatus )
  30. {
  31. case k_EAbandonGameStatus_Safe:
  32. return "Resource/UI/econ/ConfirmDialogAbandonSafe.res";
  33. case k_EAbandonGameStatus_AbandonWithoutPenalty:
  34. return "Resource/UI/econ/ConfirmDialogAbandonNoPenalty.res";
  35. case k_EAbandonGameStatus_AbandonWithPenalty:
  36. return "Resource/UI/econ/ConfirmDialogAbandonPenalty.res";
  37. }
  38. return "Resource/UI/econ/ConfirmDialogOptOut.res";
  39. }
  40. void CTFDisconnectConfirmDialog::SetReason( eDisconnectReason reason )
  41. {
  42. m_eReason = reason;
  43. }
  44. void CTFDisconnectConfirmDialog::OnCommand( const char *command )
  45. {
  46. if( FStrEq( command, "confirm" ) )
  47. {
  48. // Check this before disconnecting
  49. if ( GTFGCClientSystem()->BExitMatchmakingAfterDisconnect() )
  50. {
  51. GTFGCClientSystem()->EndMatchmaking( true );
  52. }
  53. engine->DisconnectInternal();
  54. int nCount = m_confirmCommands.Count();
  55. for( int i=0; i<nCount; ++i )
  56. {
  57. engine->ClientCmd_Unrestricted( m_confirmCommands[i] );
  58. }
  59. }
  60. else if( FStrEq( command, "cancel" ) )
  61. {
  62. int nCount = m_cancelCommands.Count();
  63. for( int i=0; i<nCount; ++i )
  64. {
  65. engine->ClientCmd_Unrestricted( m_cancelCommands[i] );
  66. }
  67. }
  68. // This will clean us up if we get a cancel or confirm command
  69. BaseClass::OnCommand( command );
  70. }
  71. void CTFDisconnectConfirmDialog::AddConfirmCommand( const char *command )
  72. {
  73. m_confirmCommands.AddToTail( command );
  74. }
  75. void CTFDisconnectConfirmDialog::AddCancelCommand( const char *command )
  76. {
  77. m_cancelCommands.AddToTail( command );
  78. }
  79. //
  80. // Extern Helper to Build Dialog
  81. CTFDisconnectConfirmDialog *BuildDisconnectConfirmDialog ()
  82. {
  83. EAbandonGameStatus eAbandonStatus = GTFGCClientSystem()->GetCurrentServerAbandonStatus();
  84. const char* pszTitle = NULL;
  85. const char* pszBody = NULL;
  86. const char* pszConfirm = NULL;
  87. switch ( eAbandonStatus )
  88. {
  89. case k_EAbandonGameStatus_Safe:
  90. pszTitle = "#TF_MM_Disconnect_Title";
  91. pszBody = "#TF_MM_Disconnect";
  92. pszConfirm = "#TF_MM_Rejoin_Leave";
  93. break;
  94. case k_EAbandonGameStatus_AbandonWithoutPenalty:
  95. pszTitle = "#TF_MM_Abandon_Title";
  96. pszBody = "#TF_MM_Abandon_NoPenalty";
  97. pszConfirm = "#TF_MM_Rejoin_Leave";
  98. break;
  99. case k_EAbandonGameStatus_AbandonWithPenalty:
  100. pszTitle = "#TF_MM_Abandon_Title";
  101. pszBody = ( TFGameRules() && TFGameRules()->IsMannVsMachineMode() ) ? "TF_MM_Abandon_Ban" : "#TF_MM_Abandon";
  102. pszConfirm = "#TF_MM_Rejoin_Abandon";
  103. break;
  104. }
  105. CTFDisconnectConfirmDialog *pDialog = vgui::SETUP_PANEL( new CTFDisconnectConfirmDialog(
  106. pszTitle,
  107. pszBody,
  108. pszConfirm,
  109. "#TF_MM_Rejoin_Stay",
  110. NULL,
  111. NULL ) );
  112. return pDialog;
  113. }
  114. // sent from quit and disconnect attempts
  115. CON_COMMAND( cl_disconnect_prompt, "Prompt about disconnect" )
  116. {
  117. CTFDisconnectConfirmDialog *pDialog = vgui::SETUP_PANEL( new CTFDisconnectConfirmDialog( "#TF_MM_Abandon_Title",
  118. "#TF_MM_Abandon",
  119. "#TF_Coach_Yes",
  120. "#TF_Coach_No",
  121. NULL,
  122. NULL ) );
  123. if ( pDialog )
  124. {
  125. pDialog->Show();
  126. }
  127. }
  128. bool HandleDisconnectAttempt()
  129. {
  130. // !FIXME! We could show different messages depending on the abandon status
  131. if( engine->IsInGame() && GameRules() && GameRules()->ShouldConfirmOnDisconnect() &&
  132. GTFGCClientSystem()->GetCurrentServerAbandonStatus() == k_EAbandonGameStatus_AbandonWithPenalty )
  133. {
  134. CTFDisconnectConfirmDialog *pDialog = vgui::SETUP_PANEL( new CTFDisconnectConfirmDialog( "#TF_MM_Abandon_Title",
  135. "#TF_MM_Abandon",
  136. "#TF_Coach_Yes",
  137. "#TF_Coach_No",
  138. NULL,
  139. NULL ) );
  140. if ( pDialog )
  141. {
  142. pDialog->Show();
  143. }
  144. // The disconnect was handled by us. Stop the engine from handling it.
  145. return true;
  146. }
  147. // We're not changing the disconnect behavior in any way. Let the engine take care of it.
  148. return false;
  149. }
  150. //-----------------------------------------------------------------------------
  151. // CTFRejoinConfirmDialog
  152. //-----------------------------------------------------------------------------
  153. CTFRejoinConfirmDialog::CTFRejoinConfirmDialog(
  154. const char *pTitle,
  155. const char *pTextKey,
  156. const char *pConfirmBtnText,
  157. const char *pCancelBtnText,
  158. GenericConfirmDialogCallback callback,
  159. vgui::Panel *pParent
  160. ) : CTFGenericConfirmDialog( pTitle, pTextKey, pConfirmBtnText, pCancelBtnText, callback, pParent )
  161. {
  162. m_eAbandonStatus = GTFGCClientSystem()->GetAssignedMatchAbandonStatus();
  163. }
  164. //-----------------------------------------------------------------------------
  165. // Purpose:
  166. //-----------------------------------------------------------------------------
  167. const char *CTFRejoinConfirmDialog::GetResFile()
  168. {
  169. switch ( m_eAbandonStatus )
  170. {
  171. case k_EAbandonGameStatus_Safe:
  172. return "Resource/UI/econ/ConfirmDialogAbandonSafe.res";
  173. case k_EAbandonGameStatus_AbandonWithoutPenalty:
  174. return "Resource/UI/econ/ConfirmDialogAbandonNoPenalty.res";
  175. case k_EAbandonGameStatus_AbandonWithPenalty:
  176. return "Resource/UI/econ/ConfirmDialogAbandonPenalty.res";
  177. }
  178. return "Resource/UI/econ/ConfirmDialogOptOut.res";
  179. }
  180. //-----------------------------------------------------------------------------
  181. void CTFRejoinConfirmDialog::CloseRejoinWindow()
  182. {
  183. FinishUp();
  184. }