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.

227 lines
6.3 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "commentarydialog.h"
  7. #include "basepanel.h"
  8. #include "convar.h"
  9. #include "engineinterface.h"
  10. #include "gameui_interface.h"
  11. #include "vgui/ISurface.h"
  12. #include "vgui/IInput.h"
  13. #include <stdio.h>
  14. using namespace vgui;
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include "tier0/memdbgon.h"
  17. //-----------------------------------------------------------------------------
  18. // Purpose:
  19. //-----------------------------------------------------------------------------
  20. CCommentaryDialog::CCommentaryDialog(vgui::Panel *parent) : BaseClass(parent, "CommentaryDialog")
  21. {
  22. SetDeleteSelfOnClose(true);
  23. SetSizeable( false );
  24. input()->SetAppModalSurface(GetVPanel());
  25. vgui::surface()->RestrictPaintToSinglePanel(GetVPanel());
  26. GameUI().PreventEngineHideGameUI();
  27. SetTitle("#GameUI_CommentaryDialogTitle", true);
  28. LoadControlSettings("Resource/CommentaryDialog.res");
  29. MoveToCenterOfScreen();
  30. bool bCommentaryOn = false;
  31. ConVarRef commentary( "commentary" );
  32. if ( commentary.IsValid() )
  33. {
  34. bCommentaryOn = commentary.GetBool();
  35. }
  36. // Setup the buttons & labels to reflect the current state of the commentary
  37. if ( bCommentaryOn )
  38. {
  39. SetControlString( "ModeLabel", "#GAMEUI_Commentary_LabelOn" );
  40. SetControlString( "TurnOnButton", "#GAMEUI_Commentary_LeaveOn" );
  41. SetControlString( "TurnOffButton", "#GAMEUI_Commentary_TurnOff" );
  42. }
  43. else
  44. {
  45. SetControlString( "ModeLabel", "#GAMEUI_Commentary_LabelOff" );
  46. SetControlString( "TurnOnButton", "#GAMEUI_Commentary_TurnOn" );
  47. SetControlString( "TurnOffButton", "#GAMEUI_Commentary_LeaveOff" );
  48. }
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose:
  52. //-----------------------------------------------------------------------------
  53. CCommentaryDialog::~CCommentaryDialog()
  54. {
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Purpose:
  58. //-----------------------------------------------------------------------------
  59. void CCommentaryDialog::OnClose( void )
  60. {
  61. BaseClass::OnClose();
  62. vgui::surface()->RestrictPaintToSinglePanel(NULL);
  63. GameUI().AllowEngineHideGameUI();
  64. // Bring up the post dialog
  65. DHANDLE<CPostCommentaryDialog> hPostCommentaryDialog;
  66. if ( !hPostCommentaryDialog.Get() )
  67. {
  68. hPostCommentaryDialog = new CPostCommentaryDialog( BasePanel() );
  69. }
  70. hPostCommentaryDialog->Activate();
  71. }
  72. //-----------------------------------------------------------------------------
  73. // Purpose:
  74. // Input : *command -
  75. //-----------------------------------------------------------------------------
  76. void CCommentaryDialog::OnCommand( const char *command )
  77. {
  78. if ( !Q_stricmp( command, "TurnOn" ) )
  79. {
  80. ConVarRef commentary("commentary");
  81. commentary.SetValue( 1 );
  82. Close();
  83. }
  84. else if ( !Q_stricmp( command, "TurnOff" ) )
  85. {
  86. ConVarRef commentary("commentary");
  87. commentary.SetValue( 0 );
  88. Close();
  89. }
  90. else
  91. {
  92. BaseClass::OnCommand( command );
  93. }
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose:
  97. //-----------------------------------------------------------------------------
  98. void CCommentaryDialog::OnKeyCodePressed(KeyCode code)
  99. {
  100. // Ignore escape key
  101. if (code == KEY_ESCAPE)
  102. return;
  103. BaseClass::OnKeyCodePressed(code);
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Purpose:
  107. //-----------------------------------------------------------------------------
  108. void OpenCommentaryDialog( void )
  109. {
  110. DHANDLE<CCommentaryDialog> hCommentaryDialog;
  111. if ( !hCommentaryDialog.Get() )
  112. {
  113. hCommentaryDialog = new CCommentaryDialog( BasePanel() );
  114. }
  115. GameUI().ActivateGameUI();
  116. hCommentaryDialog->Activate();
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Purpose:
  120. //-----------------------------------------------------------------------------
  121. ConVar commentary_firstrun("commentary_firstrun", "0", FCVAR_ARCHIVE );
  122. void CC_CommentaryTestFirstRun( void )
  123. {
  124. if ( !commentary_firstrun.GetBool() )
  125. {
  126. commentary_firstrun.SetValue(1);
  127. OpenCommentaryDialog();
  128. }
  129. }
  130. static ConCommand commentary_testfirstrun("commentary_testfirstrun", CC_CommentaryTestFirstRun, 0 );
  131. //-----------------------------------------------------------------------------
  132. // Purpose:
  133. //-----------------------------------------------------------------------------
  134. CPostCommentaryDialog::CPostCommentaryDialog(vgui::Panel *parent) : BaseClass(parent, "PostCommentaryDialog")
  135. {
  136. SetDeleteSelfOnClose(true);
  137. SetSizeable( false );
  138. input()->SetAppModalSurface(GetVPanel());
  139. vgui::surface()->RestrictPaintToSinglePanel(GetVPanel());
  140. m_bResetPaintRestrict = false;
  141. SetTitle("#GameUI_CommentaryDialogTitle", true);
  142. LoadControlSettings("Resource/PostCommentaryDialog.res");
  143. MoveToCenterOfScreen();
  144. bool bCommentaryOn = false;
  145. ConVarRef commentary("commentary");
  146. if ( commentary.IsValid() )
  147. {
  148. bCommentaryOn = commentary.GetBool();
  149. }
  150. // Setup the buttons & labels to reflect the current state of the commentary
  151. if ( bCommentaryOn )
  152. {
  153. SetControlString( "PostModeLabel", "#GAMEUI_PostCommentary_ModeLabelOn" );
  154. }
  155. else
  156. {
  157. SetControlString( "PostModeLabel", "#GAMEUI_PostCommentary_ModeLabelOff" );
  158. }
  159. }
  160. //-----------------------------------------------------------------------------
  161. // Purpose:
  162. //-----------------------------------------------------------------------------
  163. CPostCommentaryDialog::~CPostCommentaryDialog()
  164. {
  165. }
  166. //-----------------------------------------------------------------------------
  167. // Purpose:
  168. //-----------------------------------------------------------------------------
  169. void CPostCommentaryDialog::OnFinishedClose( void )
  170. {
  171. BaseClass::OnFinishedClose();
  172. if ( !m_bResetPaintRestrict )
  173. {
  174. m_bResetPaintRestrict = true;
  175. vgui::surface()->RestrictPaintToSinglePanel(NULL);
  176. GameUI().HideGameUI();
  177. }
  178. }
  179. //-----------------------------------------------------------------------------
  180. // Purpose:
  181. //-----------------------------------------------------------------------------
  182. void CPostCommentaryDialog::OnKeyCodePressed(KeyCode code)
  183. {
  184. if (code == KEY_ESCAPE)
  185. {
  186. Close();
  187. vgui::surface()->RestrictPaintToSinglePanel(NULL);
  188. m_bResetPaintRestrict = true;
  189. }
  190. else
  191. {
  192. BaseClass::OnKeyCodePressed(code);
  193. }
  194. }