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.

223 lines
5.7 KiB

  1. //=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. ===========
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. // $Header: $
  9. // $NoKeywords: $
  10. //
  11. //=============================================================================
  12. #include "textdisplay.h"
  13. #include "gameuisystemmgr.h"
  14. #include "gameuisystem.h"
  15. #include "gametext.h"
  16. #include "tier1/utlbuffer.h"
  17. #define VERTICAL_SPACING 20
  18. //-----------------------------------------------------------------------------
  19. //
  20. //-----------------------------------------------------------------------------
  21. CTextDisplay::CTextDisplay()
  22. {
  23. m_nXOffset = 10;
  24. m_nYOffset = 10;
  25. m_nXStaticOffset = 10;
  26. m_nYStaticOffset = 10;
  27. m_bIsInitialized = false;
  28. }
  29. //-----------------------------------------------------------------------------
  30. //
  31. //-----------------------------------------------------------------------------
  32. void CTextDisplay::Init( IGameUISystem *pMenu )
  33. {
  34. if ( m_bIsInitialized )
  35. return;
  36. Vector2D stageSize(0, 0);
  37. m_pMenu = ( CGameUISystem * ) pMenu;
  38. Assert( m_pMenu );
  39. m_pMenu->GetStageSize( stageSize );
  40. m_nXOffset = (-stageSize.x/2) + 10;
  41. m_nYOffset = (-stageSize.y/2) + 10;
  42. m_nXStaticOffset = (-stageSize.x/2) + 500;
  43. m_nYStaticOffset = (-stageSize.y/2) + 10;
  44. m_bIsInitialized = true;
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Text that doesn't change every frame.
  48. //-----------------------------------------------------------------------------
  49. void CTextDisplay::AddStaticText( const char* pFmt, ... )
  50. {
  51. va_list args;
  52. CUtlBuffer message;
  53. va_start( args, pFmt );
  54. message.VaPrintf( pFmt, args );
  55. va_end( args );
  56. char strMessage[255];
  57. message.GetString( strMessage, 255 );
  58. CGameText *pNewInfo = new CGameText( "staticText" );
  59. pNewInfo->SetFont( "Default" );
  60. pNewInfo->SetText( strMessage );
  61. pNewInfo->SetCenter( m_nXStaticOffset, m_nYStaticOffset );
  62. m_nYStaticOffset += VERTICAL_SPACING;
  63. m_pStaticText.AddToTail( pNewInfo );
  64. if ( m_pMenu )
  65. {
  66. m_pMenu->Definition().AddGraphicToLayer( pNewInfo, SUBLAYER_FONT );
  67. }
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Text that doesn't change every frame.
  71. //-----------------------------------------------------------------------------
  72. void CTextDisplay::AddStaticText( int xPos, int yPos, const char* pFmt, ... )
  73. {
  74. va_list args;
  75. CUtlBuffer message;
  76. va_start( args, pFmt );
  77. message.VaPrintf( pFmt, args );
  78. va_end( args );
  79. char strMessage[255];
  80. message.GetString( strMessage, 255 );
  81. CGameText *pNewInfo = new CGameText( "staticText" );
  82. pNewInfo->SetFont( "Default" );
  83. pNewInfo->SetText( strMessage );
  84. pNewInfo->SetCenter( xPos, yPos );
  85. m_pStaticText.AddToTail( pNewInfo );
  86. if ( m_pMenu )
  87. {
  88. m_pMenu->Definition().AddGraphicToLayer( pNewInfo, SUBLAYER_FONT );
  89. }
  90. }
  91. //-----------------------------------------------------------------------------
  92. //
  93. //-----------------------------------------------------------------------------
  94. void CTextDisplay::PrintMsg( const char* pFmt, ... )
  95. {
  96. va_list args;
  97. CUtlBuffer message;
  98. va_start( args, pFmt );
  99. message.VaPrintf( pFmt, args );
  100. va_end( args );
  101. char strMessage[255];
  102. message.GetString( strMessage, 255 );
  103. CGameText *pNewInfo = new CGameText( "msgText" );
  104. pNewInfo->SetFont( "Default" );
  105. pNewInfo->SetText( strMessage );
  106. pNewInfo->SetCenter( m_nXOffset, m_nYOffset );
  107. m_nYOffset += VERTICAL_SPACING;
  108. m_pStatsText.AddToTail( pNewInfo );
  109. if ( m_pMenu )
  110. {
  111. m_pMenu->Definition().AddGraphicToLayer( pNewInfo, SUBLAYER_FONT );
  112. }
  113. }
  114. //-----------------------------------------------------------------------------
  115. //
  116. //-----------------------------------------------------------------------------
  117. void CTextDisplay::PrintMsg( int xPos, int yPos, const char* pFmt, ... )
  118. {
  119. va_list args;
  120. CUtlBuffer message;
  121. va_start( args, pFmt );
  122. message.VaPrintf( pFmt, args );
  123. va_end( args );
  124. char strMessage[255];
  125. message.GetString( strMessage, 255 );
  126. CGameText *pNewInfo = new CGameText( "msgText" );
  127. pNewInfo->SetFont( "Default" );
  128. pNewInfo->SetText( strMessage );
  129. pNewInfo->SetCenter( xPos, yPos );
  130. m_pStatsText.AddToTail( pNewInfo );
  131. if ( m_pMenu )
  132. {
  133. m_pMenu->Definition().AddGraphicToLayer( pNewInfo, SUBLAYER_FONT );
  134. }
  135. }
  136. //-----------------------------------------------------------------------------
  137. //
  138. //-----------------------------------------------------------------------------
  139. void CTextDisplay::ClearStaticText()
  140. {
  141. if ( m_pMenu )
  142. {
  143. for ( int i = 0; i < m_pStaticText.Count(); ++i )
  144. {
  145. m_pMenu->Definition().RemoveGraphic( m_pStaticText[i] );
  146. }
  147. m_pStaticText.RemoveAll();
  148. Vector2D stageSize(0, 0);
  149. m_pMenu->GetStageSize( stageSize );
  150. m_nYStaticOffset = (-stageSize.y/2) + 10;
  151. }
  152. }
  153. //-----------------------------------------------------------------------------
  154. //
  155. //-----------------------------------------------------------------------------
  156. void CTextDisplay::FinishFrame()
  157. {
  158. if ( m_pMenu )
  159. {
  160. for ( int i = 0; i < m_pStatsText.Count(); ++i )
  161. {
  162. m_pMenu->Definition().RemoveGraphic( m_pStatsText[i] );
  163. delete m_pStatsText[i];
  164. m_pStatsText[i] = NULL;
  165. }
  166. m_pStatsText.RemoveAll();
  167. Vector2D stageSize(0, 0);
  168. m_pMenu->GetStageSize( stageSize );
  169. m_nYOffset = (-stageSize.y/2) + 10;
  170. }
  171. }
  172. //-----------------------------------------------------------------------------
  173. //
  174. //-----------------------------------------------------------------------------
  175. void CTextDisplay::Shutdown()
  176. {
  177. FinishFrame();
  178. ClearStaticText();
  179. m_bIsInitialized = false;
  180. }