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.

237 lines
6.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "tf_notification.h"
  9. #include "c_tf_notification.h"
  10. #include "tf_gc_client.h"
  11. #include "econ/econ_notifications.h"
  12. ///
  13. /// Support message notification dialog
  14. ///
  15. class CTFSupportNotificationDialog : public CTFMessageBoxDialog
  16. {
  17. DECLARE_CLASS_SIMPLE( CTFSupportNotificationDialog, CTFMessageBoxDialog );
  18. public:
  19. CTFSupportNotificationDialog( int iNotificationID, const char *pszSupportMessage )
  20. : CTFMessageBoxDialog( NULL, pszSupportMessage, NULL, NULL, NULL )
  21. , m_iNotificationID( iNotificationID )
  22. , m_pConfirmDialog( NULL )
  23. {
  24. SetDialogVariable( "text", GetText() );
  25. }
  26. void CleanupConfirmDialog()
  27. {
  28. if ( m_pConfirmDialog )
  29. {
  30. m_pConfirmDialog->SetVisible( false );
  31. m_pConfirmDialog->MarkForDeletion();
  32. m_pConfirmDialog = NULL;
  33. }
  34. }
  35. virtual ~CTFSupportNotificationDialog() {
  36. CleanupConfirmDialog();
  37. }
  38. void ConfirmDialogCallback( bool bConfirmed )
  39. {
  40. CleanupConfirmDialog();
  41. if ( bConfirmed )
  42. {
  43. // User acknowledged the message, tell the notification it can go away now
  44. CClientNotification *pNotification = dynamic_cast< CClientNotification * >( NotificationQueue_Get( m_iNotificationID ) );
  45. if ( pNotification )
  46. {
  47. pNotification->OnDialogAcknowledged();
  48. }
  49. BaseClass::OnCommand( "confirm" );
  50. }
  51. }
  52. static void StaticConfirmDialogCallback( bool bConfirmed, void *pContext )
  53. {
  54. static_cast< CTFSupportNotificationDialog * >( pContext )->ConfirmDialogCallback( bConfirmed );
  55. }
  56. virtual void OnCommand( const char *command ) OVERRIDE
  57. {
  58. if ( FStrEq( "acknowledge", command ) )
  59. {
  60. // Confirm this, it's going away forever!
  61. CleanupConfirmDialog();
  62. m_pConfirmDialog = ShowConfirmDialog( "#DeleteConfirmDefault",
  63. "#TF_Support_Message_Confirm_Acknowledge_Text",
  64. "#TF_Support_Message_Acknowledge", "#Cancel",
  65. &StaticConfirmDialogCallback );
  66. m_pConfirmDialog->SetContext( this );
  67. return;
  68. }
  69. else if ( FStrEq( "show_later", command ) )
  70. {
  71. // User selected "show this later" -- leave notification as is and close.
  72. CleanupConfirmDialog();
  73. BaseClass::OnCommand( "confirm" );
  74. return;
  75. }
  76. BaseClass::OnCommand( command );
  77. }
  78. virtual const char *GetResFile() OVERRIDE
  79. {
  80. return "Resource/UI/SupportNotificationDialog.res";
  81. }
  82. private:
  83. // Associated notification to clear
  84. int m_iNotificationID;
  85. CTFGenericConfirmDialog *m_pConfirmDialog;
  86. };
  87. ///
  88. /// The notification class
  89. ///
  90. CClientNotification::CClientNotification()
  91. {
  92. m_pText = NULL;
  93. m_flExpireTime = CRTime::RTime32TimeCur();
  94. m_ulNotificationID = 0;
  95. m_unAccountID = 0;
  96. m_bSupportMessage = false;
  97. }
  98. CClientNotification::~CClientNotification()
  99. {}
  100. void CClientNotification::Update( const CTFNotification* notification )
  101. {
  102. // Custom type handling. For now only support message does anything special.
  103. m_bSupportMessage = false;
  104. switch ( notification->Obj().type() )
  105. {
  106. case CMsgGCNotification_NotificationType_NOTIFICATION_REPORTED_PLAYER_BANNED:
  107. case CMsgGCNotification_NotificationType_NOTIFICATION_CUSTOM_STRING:
  108. case CMsgGCNotification_NotificationType_NOTIFICATION_MM_BAN_DUE_TO_EXCESSIVE_REPORTS:
  109. case CMsgGCNotification_NotificationType_NOTIFICATION_REPORTED_PLAYER_WAS_BANNED:
  110. // All identical.
  111. //
  112. // Really, the other types could be used to avoid having to send a localization string down? Otherwise
  113. // they're all just redundant with CUSTOM_STRING for now.
  114. break;
  115. case CMsgGCNotification_NotificationType_NOTIFICATION_SUPPORT_MESSAGE:
  116. m_bSupportMessage = true;
  117. break;
  118. default:
  119. Assert( !"Unhandled enum value" );
  120. }
  121. m_pText = NULL;
  122. m_strText = notification->Obj().notification_string().c_str();
  123. if ( m_bSupportMessage )
  124. {
  125. // Use generic notification, save actual notification contents for dialog
  126. m_pText = "#TF_Support_Message_Notification";
  127. }
  128. else
  129. {
  130. // Just use our message
  131. m_pText = m_strText.Get();
  132. }
  133. // 0 -> does not expire
  134. RTime32 rtExpire = notification->Obj().expiration_time();
  135. m_flExpireTime = rtExpire > 0 ? (float)rtExpire : FLT_MAX;
  136. m_ulNotificationID = notification->Obj().notification_id();
  137. m_unAccountID = notification->Obj().account_id();
  138. }
  139. void CClientNotification::GCAcknowledge() {
  140. GTFGCClientSystem()->AcknowledgeNotification( m_unAccountID, m_ulNotificationID );
  141. }
  142. void CClientNotification::Deleted()
  143. {
  144. if ( m_bSupportMessage )
  145. {
  146. AssertMsg( !m_bSupportMessage,
  147. "Support messages should only be able to be triggered, not deleted" );
  148. return;
  149. }
  150. GCAcknowledge();
  151. }
  152. void CClientNotification::Expired()
  153. {
  154. // No action, we don't want de-sync'd client clock to acknowledge these incorrectly, GC will expire them on its end.
  155. }
  156. CClientNotification::EType CClientNotification::NotificationType()
  157. {
  158. // Support messages are "must trigger" type -- no delete action, user must click "view"
  159. if ( m_bSupportMessage )
  160. {
  161. return eType_MustTrigger;
  162. }
  163. return eType_Basic;
  164. }
  165. bool CClientNotification::BHighPriority()
  166. {
  167. return m_bSupportMessage;
  168. }
  169. void CClientNotification::Trigger()
  170. {
  171. if ( !m_bSupportMessage )
  172. {
  173. AssertMsg( m_bSupportMessage,
  174. "Don't expect to be trigger-able when not in support message mode" );
  175. return;
  176. }
  177. CTFSupportNotificationDialog *pDialog = vgui::SETUP_PANEL( new CTFSupportNotificationDialog( GetID(), m_strText.Get() ) );
  178. pDialog->Show();
  179. }
  180. void CClientNotification::OnDialogAcknowledged()
  181. {
  182. if ( !m_bSupportMessage )
  183. {
  184. AssertMsg( m_bSupportMessage,
  185. "Don't expect to be getting callbacks from the support message dialog when not in support message mode" );
  186. return;
  187. }
  188. GCAcknowledge();
  189. MarkForDeletion();
  190. }
  191. //-----------------------------------------------------------------------------
  192. // CAutobalanceVolunteerNotification
  193. //-----------------------------------------------------------------------------
  194. void CAutobalanceVolunteerNotification::SendResponse( bool bResponse )
  195. {
  196. KeyValues *kv = new KeyValues( "AutoBalanceVolunteerReply" );
  197. kv->SetBool( "response", bResponse );
  198. engine->ServerCmdKeyValues( kv );
  199. MarkForDeletion();
  200. }