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.

274 lines
7.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "inputsystem/iinputsystem.h"
  9. #include "input.h"
  10. #include "tf_textwindow.h"
  11. #include <cdll_client_int.h>
  12. #include <vgui/IScheme.h>
  13. #include <vgui/ILocalize.h>
  14. #include <vgui/ISurface.h>
  15. #include <filesystem.h>
  16. #include <KeyValues.h>
  17. #include <convar.h>
  18. #include <vgui_controls/ImageList.h>
  19. #include <vgui_controls/Panel.h>
  20. #include <vgui_controls/TextEntry.h>
  21. #include <vgui_controls/Button.h>
  22. #include <vgui_controls/BuildGroup.h>
  23. #include <vgui_controls/ImagePanel.h>
  24. #include "tf_controls.h"
  25. #include "tf_shareddefs.h"
  26. #include "IGameUIFuncs.h" // for key bindings
  27. #include <igameresources.h>
  28. extern IGameUIFuncs *gameuifuncs; // for key binding details
  29. #include <game/client/iviewport.h>
  30. // memdbgon must be the last include file in a .cpp file!!!
  31. #include "tier0/memdbgon.h"
  32. using namespace vgui;
  33. //-----------------------------------------------------------------------------
  34. // Purpose: Constructor
  35. //-----------------------------------------------------------------------------
  36. CTFTextWindow::CTFTextWindow( IViewPort *pViewPort ) : CTextWindow( pViewPort )
  37. {
  38. m_pTFTextMessage = new CExRichText( this, "TFTextMessage" );
  39. SetProportional( true );
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Purpose: Destructor
  43. //-----------------------------------------------------------------------------
  44. CTFTextWindow::~CTFTextWindow()
  45. {
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Purpose:
  49. //-----------------------------------------------------------------------------
  50. void CTFTextWindow::ApplySchemeSettings( IScheme *pScheme )
  51. {
  52. Frame::ApplySchemeSettings( pScheme ); // purposely skipping the CTextWindow version
  53. if ( ::input->IsSteamControllerActive() )
  54. {
  55. if ( m_bCustomSvrPage )
  56. {
  57. LoadControlSettings( "Resource/UI/TextWindowCustomServer_SC.res" );
  58. }
  59. else
  60. {
  61. LoadControlSettings( "Resource/UI/TextWindow_SC.res" );
  62. }
  63. SetMouseInputEnabled( false );
  64. }
  65. else
  66. {
  67. if ( m_bCustomSvrPage )
  68. {
  69. LoadControlSettings( "Resource/UI/TextWindowCustomServer.res" );
  70. }
  71. else
  72. {
  73. LoadControlSettings( "Resource/UI/TextWindow.res" );
  74. }
  75. SetMouseInputEnabled( true );
  76. }
  77. if ( m_pHTMLMessage )
  78. {
  79. m_pHTMLMessage->SetBgColor( pScheme->GetColor( "HTMLBackground", Color( 255, 0, 0, 255 ) ) );
  80. }
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Purpose:
  84. //-----------------------------------------------------------------------------
  85. void CTFTextWindow::Reset( void )
  86. {
  87. Update();
  88. }
  89. //-----------------------------------------------------------------------------
  90. // Purpose:
  91. //-----------------------------------------------------------------------------
  92. void CTFTextWindow::OnThink()
  93. {
  94. //Always hide the health... this needs to be done every frame because a message from the server keeps resetting this.
  95. C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
  96. if ( pLocalPlayer )
  97. {
  98. pLocalPlayer->m_Local.m_iHideHUD |= HIDEHUD_HEALTH;
  99. }
  100. BaseClass::OnThink();
  101. }
  102. //-----------------------------------------------------------------------------
  103. // Purpose:
  104. //-----------------------------------------------------------------------------
  105. void CTFTextWindow::SetData(KeyValues *data)
  106. {
  107. m_bCustomSvrPage = data->GetBool( "customsvr" );
  108. InvalidateLayout( false, true );
  109. BaseClass::SetData( data );
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Purpose:
  113. //-----------------------------------------------------------------------------
  114. void CTFTextWindow::Update()
  115. {
  116. CExLabel *pTitle = dynamic_cast<CExLabel *>( FindChildByName( "TFMessageTitle" ) );
  117. if ( pTitle )
  118. {
  119. pTitle->SetText( m_szTitle );
  120. }
  121. if ( m_pTFTextMessage )
  122. {
  123. m_pTFTextMessage->SetVisible( false );
  124. }
  125. BaseClass::Update();
  126. Panel *pOK = FindChildByName( "ok" );
  127. if ( pOK )
  128. {
  129. pOK->RequestFocus();
  130. }
  131. }
  132. //-----------------------------------------------------------------------------
  133. // Purpose:
  134. //---------------------------------------------------------------------------
  135. void CTFTextWindow::SetVisible( bool state )
  136. {
  137. BaseClass::SetVisible( state );
  138. if ( state )
  139. {
  140. Panel *pOK = FindChildByName( "ok" );
  141. if ( pOK )
  142. {
  143. pOK->RequestFocus();
  144. }
  145. }
  146. }
  147. //-----------------------------------------------------------------------------
  148. // Purpose: shows the text window
  149. //-----------------------------------------------------------------------------
  150. void CTFTextWindow::ShowPanel( bool bShow )
  151. {
  152. if ( IsVisible() == bShow )
  153. return;
  154. // Force use to reevaluate our scheme, in case Steam Controller stuff has changed.
  155. InvalidateLayout( true, true );
  156. BaseClass::ShowPanel( bShow );
  157. if ( m_pViewPort )
  158. {
  159. m_pViewPort->ShowBackGround( false );
  160. }
  161. }
  162. //-----------------------------------------------------------------------------
  163. // Purpose:
  164. //-----------------------------------------------------------------------------
  165. void CTFTextWindow::OnKeyCodePressed( KeyCode code )
  166. {
  167. if ( code == KEY_XBUTTON_A || code == STEAMCONTROLLER_A )
  168. {
  169. OnCommand( "okay" );
  170. }
  171. else
  172. {
  173. BaseClass::OnKeyCodePressed( code );
  174. }
  175. }
  176. //-----------------------------------------------------------------------------
  177. // Purpose: The background is painted elsewhere, so we should do nothing
  178. //-----------------------------------------------------------------------------
  179. void CTFTextWindow::PaintBackground()
  180. {
  181. }
  182. //-----------------------------------------------------------------------------
  183. // Purpose:
  184. //-----------------------------------------------------------------------------
  185. void CTFTextWindow::OnCommand( const char *command )
  186. {
  187. BaseClass::OnCommand( command );
  188. // Don't open up the mapinfo if it was a custom server html page
  189. if ( !Q_strcmp( command, "okay" ) && !m_bCustomSvrPage )
  190. {
  191. m_pViewPort->ShowPanel( PANEL_MAPINFO, true );
  192. }
  193. }
  194. //-----------------------------------------------------------------------------
  195. // Purpose:
  196. //-----------------------------------------------------------------------------
  197. void CTFTextWindow::ShowText( const char *text )
  198. {
  199. ShowTitleLabel( true );
  200. if ( m_pTFTextMessage )
  201. {
  202. m_pTFTextMessage->SetVisible( true );
  203. m_pTFTextMessage->SetText( text );
  204. m_pTFTextMessage->GotoTextStart();
  205. }
  206. }
  207. //-----------------------------------------------------------------------------
  208. // Purpose:
  209. //-----------------------------------------------------------------------------
  210. void CTFTextWindow::ShowURL( const char *URL, bool bAllowUserToDisable )
  211. {
  212. ShowTitleLabel( false );
  213. BaseClass::ShowURL( URL, bAllowUserToDisable );
  214. }
  215. //-----------------------------------------------------------------------------
  216. // Purpose:
  217. //-----------------------------------------------------------------------------
  218. void CTFTextWindow::ShowFile( const char *filename )
  219. {
  220. ShowTitleLabel( false ) ;
  221. BaseClass::ShowFile( filename );
  222. }
  223. //-----------------------------------------------------------------------------
  224. // Purpose:
  225. //-----------------------------------------------------------------------------
  226. void CTFTextWindow::ShowTitleLabel( bool show )
  227. {
  228. CExLabel *pTitle = dynamic_cast<CExLabel *>( FindChildByName( "TFMessageTitle" ) );
  229. if ( pTitle )
  230. {
  231. pTitle->SetVisible( show );
  232. }
  233. }