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.

272 lines
6.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "cstrikeclassmenu.h"
  9. #include <KeyValues.h>
  10. #include <filesystem.h>
  11. #include <vgui_controls/Button.h>
  12. #include <vgui/IVGui.h>
  13. #include "hud.h" // for gEngfuncs
  14. #include "cs_gamerules.h"
  15. using namespace vgui;
  16. // ----------------------------------------------------------------------------- //
  17. // Class image panels. These maintain a list of the class image panels so
  18. // it can render 3D images into them.
  19. // ----------------------------------------------------------------------------- //
  20. CUtlVector<CCSClassImagePanel*> g_ClassImagePanels;
  21. CCSClassImagePanel::CCSClassImagePanel( vgui::Panel *pParent, const char *pName )
  22. : vgui::ImagePanel( pParent, pName )
  23. {
  24. g_ClassImagePanels.AddToTail( this );
  25. m_ModelName[0] = 0;
  26. }
  27. CCSClassImagePanel::~CCSClassImagePanel()
  28. {
  29. g_ClassImagePanels.FindAndRemove( this );
  30. }
  31. void CCSClassImagePanel::ApplySettings( KeyValues *inResourceData )
  32. {
  33. const char *pName = inResourceData->GetString( "3DModel" );
  34. if ( pName )
  35. {
  36. Q_strncpy( m_ModelName, pName, sizeof( m_ModelName ) );
  37. }
  38. BaseClass::ApplySettings( inResourceData );
  39. }
  40. void CCSClassImagePanel::Paint()
  41. {
  42. BaseClass::Paint();
  43. }
  44. // ----------------------------------------------------------------------------- //
  45. // CClassMenu_TER
  46. // ----------------------------------------------------------------------------- //
  47. CClassMenu_TER::CClassMenu_TER(IViewPort *pViewPort) : CClassMenu(pViewPort, PANEL_CLASS_TER)
  48. {
  49. LoadControlSettings( "Resource/UI/ClassMenu_TER.res" );
  50. CreateBackground( this );
  51. m_backgroundLayoutFinished = false;
  52. }
  53. const char *CClassMenu_TER::GetName( void )
  54. {
  55. return PANEL_CLASS_TER;
  56. }
  57. void CClassMenu_TER::ShowPanel(bool bShow)
  58. {
  59. if ( bShow)
  60. {
  61. engine->CheckPoint( "ClassMenu" );
  62. }
  63. BaseClass::ShowPanel( bShow );
  64. }
  65. void CClassMenu_TER::SetVisible(bool state)
  66. {
  67. BaseClass::SetVisible(state);
  68. if ( state )
  69. {
  70. Panel *pAutoButton = FindChildByName( "autoselect_t" );
  71. if ( pAutoButton )
  72. {
  73. pAutoButton->RequestFocus();
  74. }
  75. }
  76. }
  77. bool modelExists( const char *search, const CUtlVector< const char * > &names )
  78. {
  79. for ( int i=0; i<names.Count(); ++i )
  80. {
  81. if ( Q_stristr( names[i], search ) != NULL )
  82. {
  83. return true;
  84. }
  85. }
  86. return false;
  87. }
  88. void CClassMenu_TER::Update()
  89. {
  90. C_CSPlayer *pLocalPlayer = C_CSPlayer::GetLocalCSPlayer();
  91. if ( pLocalPlayer && pLocalPlayer->PlayerClass() >= FIRST_T_CLASS && pLocalPlayer->PlayerClass() <= LAST_T_CLASS )
  92. {
  93. SetVisibleButton( "CancelButton", true );
  94. }
  95. else
  96. {
  97. SetVisibleButton( "CancelButton", false );
  98. }
  99. // if we don't have the new models installed,
  100. // turn off the militia and spetsnaz buttons
  101. SetVisibleButton( "militia", false );
  102. }
  103. Panel *CClassMenu_TER::CreateControlByName(const char *controlName)
  104. {
  105. if ( Q_stricmp( controlName, "CSClassImagePanel" ) == 0 )
  106. {
  107. return new CCSClassImagePanel( NULL, controlName );
  108. }
  109. return BaseClass::CreateControlByName( controlName );
  110. }
  111. // ----------------------------------------------------------------------------- //
  112. // CClassMenu_CT
  113. // ----------------------------------------------------------------------------- //
  114. CClassMenu_CT::CClassMenu_CT(IViewPort *pViewPort) : CClassMenu(pViewPort, PANEL_CLASS_CT)
  115. {
  116. LoadControlSettings( "Resource/UI/ClassMenu_CT.res" );
  117. CreateBackground( this );
  118. m_backgroundLayoutFinished = false;
  119. }
  120. Panel *CClassMenu_CT::CreateControlByName(const char *controlName)
  121. {
  122. if ( Q_stricmp( controlName, "CSClassImagePanel" ) == 0 )
  123. {
  124. return new CCSClassImagePanel( NULL, controlName );
  125. }
  126. return BaseClass::CreateControlByName( controlName );
  127. }
  128. const char *CClassMenu_CT::GetName( void )
  129. {
  130. return PANEL_CLASS_CT;
  131. }
  132. void CClassMenu_CT::ShowPanel(bool bShow)
  133. {
  134. if ( bShow)
  135. {
  136. engine->CheckPoint( "ClassMenu" );
  137. }
  138. BaseClass::ShowPanel( bShow );
  139. }
  140. void CClassMenu_CT::SetVisible(bool state)
  141. {
  142. BaseClass::SetVisible(state);
  143. if ( state )
  144. {
  145. Panel *pAutoButton = FindChildByName( "autoselect_ct" );
  146. if ( pAutoButton )
  147. {
  148. pAutoButton->RequestFocus();
  149. }
  150. }
  151. }
  152. void CClassMenu_CT::Update()
  153. {
  154. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  155. if ( pPlayer && pPlayer->PlayerClass() >= FIRST_CT_CLASS && pPlayer->PlayerClass() <= LAST_CT_CLASS )
  156. {
  157. SetVisibleButton( "CancelButton", true );
  158. }
  159. else
  160. {
  161. SetVisibleButton( "CancelButton", false );
  162. }
  163. // if we don't have the new models installed,
  164. // turn off the militia and spetsnaz buttons
  165. SetVisibleButton( "spetsnaz", false );
  166. }
  167. //-----------------------------------------------------------------------------
  168. // Purpose: The CS background is painted by image panels, so we should do nothing
  169. //-----------------------------------------------------------------------------
  170. void CClassMenu_TER::PaintBackground()
  171. {
  172. }
  173. //-----------------------------------------------------------------------------
  174. // Purpose: Scale / center the window
  175. //-----------------------------------------------------------------------------
  176. void CClassMenu_TER::PerformLayout()
  177. {
  178. BaseClass::PerformLayout();
  179. // stretch the window to fullscreen
  180. if ( !m_backgroundLayoutFinished )
  181. LayoutBackgroundPanel( this );
  182. m_backgroundLayoutFinished = true;
  183. }
  184. //-----------------------------------------------------------------------------
  185. // Purpose:
  186. //-----------------------------------------------------------------------------
  187. void CClassMenu_TER::ApplySchemeSettings( vgui::IScheme *pScheme )
  188. {
  189. BaseClass::ApplySchemeSettings( pScheme );
  190. ApplyBackgroundSchemeSettings( this, pScheme );
  191. }
  192. //-----------------------------------------------------------------------------
  193. // Purpose: The CS background is painted by image panels, so we should do nothing
  194. //-----------------------------------------------------------------------------
  195. void CClassMenu_CT::PaintBackground()
  196. {
  197. }
  198. //-----------------------------------------------------------------------------
  199. // Purpose: Scale / center the window
  200. //-----------------------------------------------------------------------------
  201. void CClassMenu_CT::PerformLayout()
  202. {
  203. BaseClass::PerformLayout();
  204. // stretch the window to fullscreen
  205. if ( !m_backgroundLayoutFinished )
  206. LayoutBackgroundPanel( this );
  207. m_backgroundLayoutFinished = true;
  208. }
  209. //-----------------------------------------------------------------------------
  210. // Purpose:
  211. //-----------------------------------------------------------------------------
  212. void CClassMenu_CT::ApplySchemeSettings( vgui::IScheme *pScheme )
  213. {
  214. BaseClass::ApplySchemeSettings( pScheme );
  215. ApplyBackgroundSchemeSettings( this, pScheme );
  216. }