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.

255 lines
6.9 KiB

  1. //========= Copyright 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. if ( code == KEY_XBUTTON_A || code == STEAMCONTROLLER_A )
  104. {
  105. OnCommand( "TurnOn" );
  106. return;
  107. }
  108. else if ( code == KEY_XBUTTON_B || code == STEAMCONTROLLER_B )
  109. {
  110. OnCommand( "TurnOff" );
  111. return;
  112. }
  113. BaseClass::OnKeyCodePressed(code);
  114. }
  115. //-----------------------------------------------------------------------------
  116. // Purpose:
  117. //-----------------------------------------------------------------------------
  118. void OpenCommentaryDialog( void )
  119. {
  120. DHANDLE<CCommentaryDialog> hCommentaryDialog;
  121. if ( !hCommentaryDialog.Get() )
  122. {
  123. hCommentaryDialog = new CCommentaryDialog( BasePanel() );
  124. }
  125. GameUI().ActivateGameUI();
  126. hCommentaryDialog->Activate();
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Purpose:
  130. //-----------------------------------------------------------------------------
  131. ConVar commentary_firstrun("commentary_firstrun", "0", FCVAR_ARCHIVE );
  132. void CC_CommentaryTestFirstRun( void )
  133. {
  134. // The enable/disable commentary box in the sound options got lost in time;
  135. // always prompt the user for commentary mode instead on new game.
  136. //if ( !commentary_firstrun.GetBool() )
  137. {
  138. commentary_firstrun.SetValue(1);
  139. OpenCommentaryDialog();
  140. }
  141. }
  142. static ConCommand commentary_testfirstrun("commentary_testfirstrun", CC_CommentaryTestFirstRun, 0 );
  143. //-----------------------------------------------------------------------------
  144. // Purpose:
  145. //-----------------------------------------------------------------------------
  146. CPostCommentaryDialog::CPostCommentaryDialog(vgui::Panel *parent) : BaseClass(parent, "PostCommentaryDialog")
  147. {
  148. SetDeleteSelfOnClose(true);
  149. SetSizeable( false );
  150. input()->SetAppModalSurface(GetVPanel());
  151. vgui::surface()->RestrictPaintToSinglePanel(GetVPanel());
  152. m_bResetPaintRestrict = false;
  153. SetTitle("#GameUI_CommentaryDialogTitle", true);
  154. LoadControlSettings("Resource/PostCommentaryDialog.res");
  155. MoveToCenterOfScreen();
  156. bool bCommentaryOn = false;
  157. ConVarRef commentary("commentary");
  158. if ( commentary.IsValid() )
  159. {
  160. bCommentaryOn = commentary.GetBool();
  161. }
  162. // Setup the buttons & labels to reflect the current state of the commentary
  163. if ( bCommentaryOn )
  164. {
  165. SetControlString( "PostModeLabel", "#GAMEUI_PostCommentary_ModeLabelOn" );
  166. }
  167. else
  168. {
  169. SetControlString( "PostModeLabel", "#GAMEUI_PostCommentary_ModeLabelOff" );
  170. }
  171. }
  172. //-----------------------------------------------------------------------------
  173. // Purpose:
  174. //-----------------------------------------------------------------------------
  175. CPostCommentaryDialog::~CPostCommentaryDialog()
  176. {
  177. }
  178. //-----------------------------------------------------------------------------
  179. // Purpose:
  180. //-----------------------------------------------------------------------------
  181. void CPostCommentaryDialog::OnFinishedClose( void )
  182. {
  183. BaseClass::OnFinishedClose();
  184. if ( !m_bResetPaintRestrict )
  185. {
  186. m_bResetPaintRestrict = true;
  187. vgui::surface()->RestrictPaintToSinglePanel(NULL);
  188. GameUI().HideGameUI();
  189. }
  190. }
  191. void CPostCommentaryDialog::OnKeyCodeTyped(KeyCode code)
  192. {
  193. if ( code == KEY_ESCAPE )
  194. {
  195. Close();
  196. vgui::surface()->RestrictPaintToSinglePanel(NULL);
  197. m_bResetPaintRestrict = true;
  198. }
  199. else
  200. {
  201. BaseClass::OnKeyCodeTyped(code);
  202. }
  203. }
  204. //-----------------------------------------------------------------------------
  205. // Purpose:
  206. //-----------------------------------------------------------------------------
  207. void CPostCommentaryDialog::OnKeyCodePressed(KeyCode code)
  208. {
  209. if ( code == KEY_XBUTTON_A || code == KEY_XBUTTON_B || code == STEAMCONTROLLER_B )
  210. {
  211. Close();
  212. vgui::surface()->RestrictPaintToSinglePanel(NULL);
  213. m_bResetPaintRestrict = true;
  214. }
  215. else
  216. {
  217. BaseClass::OnKeyCodePressed(code);
  218. }
  219. }