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.

629 lines
19 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "hudelement.h"
  8. #include <vgui_controls/Panel.h>
  9. #include <vgui_controls/EditablePanel.h>
  10. #include <vgui_controls/ImagePanel.h>
  11. #include <vgui/ISurface.h>
  12. #include "c_dod_player.h"
  13. #include "clientmode_dod.h"
  14. #include "c_dod_objective_resource.h"
  15. #include "c_dod_playerresource.h"
  16. #include "dod_hud_capturepanel.h"
  17. DECLARE_HUDELEMENT( CDoDHudCapturePanel );
  18. ConVar hud_capturepanel( "hud_capturepanel", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE, "Set to 0 to not draw the HUD capture panel" );
  19. //-----------------------------------------------------------------------------
  20. // Purpose:
  21. //-----------------------------------------------------------------------------
  22. CDoDCapturePanelProgressBar::CDoDCapturePanelProgressBar( vgui::Panel *parent, const char *name ) : vgui::ImagePanel( parent, name )
  23. {
  24. m_flPercent = 0.0f;
  25. m_iTexture = vgui::surface()->DrawGetTextureId( "vgui/progress_bar" );
  26. if ( m_iTexture == -1 ) // we didn't find it, so create a new one
  27. {
  28. m_iTexture = vgui::surface()->CreateNewTextureID();
  29. }
  30. vgui::surface()->DrawSetTextureFile( m_iTexture, "vgui/progress_bar", true, false );
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Purpose:
  34. //-----------------------------------------------------------------------------
  35. void CDoDCapturePanelProgressBar::Paint()
  36. {
  37. int wide, tall;
  38. GetSize( wide, tall );
  39. float uv1 = 0.0f, uv2 = 1.0f;
  40. Vector2D uv11( uv1, uv1 );
  41. Vector2D uv21( uv2, uv1 );
  42. Vector2D uv22( uv2, uv2 );
  43. Vector2D uv12( uv1, uv2 );
  44. vgui::Vertex_t verts[4];
  45. verts[0].Init( Vector2D( 0, 0 ), uv11 );
  46. verts[1].Init( Vector2D( wide, 0 ), uv21 );
  47. verts[2].Init( Vector2D( wide, tall ), uv22 );
  48. verts[3].Init( Vector2D( 0, tall ), uv12 );
  49. // first, just draw the whole thing inactive.
  50. vgui::surface()->DrawSetTexture( m_iTexture );
  51. vgui::surface()->DrawSetColor( m_clrInActive );
  52. vgui::surface()->DrawTexturedPolygon( 4, verts );
  53. // now, let's calculate the "active" part of the progress bar
  54. vgui::surface()->DrawSetColor( m_clrActive );
  55. // we're going to do this using quadrants
  56. // -------------------------
  57. // | | |
  58. // | | |
  59. // | 4 | 1 |
  60. // | | |
  61. // | | |
  62. // -------------------------
  63. // | | |
  64. // | | |
  65. // | 3 | 2 |
  66. // | | |
  67. // | | |
  68. // -------------------------
  69. float flCompleteCircle = ( 2.0f * M_PI );
  70. float fl90degrees = flCompleteCircle / 4.0f;
  71. float flEndAngle = flCompleteCircle * ( 1.0f - m_flPercent ); // count DOWN (counter-clockwise)
  72. // float flEndAngle = flCompleteCircle * m_flPercent; // count UP (clockwise)
  73. float flHalfWide = (float)wide / 2.0f;
  74. float flHalfTall = (float)tall / 2.0f;
  75. if ( flEndAngle >= fl90degrees * 3.0f ) // >= 270 degrees
  76. {
  77. // draw the first and second quadrants
  78. uv11.Init( 0.5f, 0.0f );
  79. uv21.Init( 1.0f, 0.0f );
  80. uv22.Init( 1.0f, 1.0f );
  81. uv12.Init( 0.5, 1.0f );
  82. verts[0].Init( Vector2D( flHalfWide, 0.0f ), uv11 );
  83. verts[1].Init( Vector2D( wide, 0.0f ), uv21 );
  84. verts[2].Init( Vector2D( wide, tall ), uv22 );
  85. verts[3].Init( Vector2D( flHalfWide, tall ), uv12 );
  86. vgui::surface()->DrawTexturedPolygon( 4, verts );
  87. // draw the third quadrant
  88. uv11.Init( 0.0f, 0.5f );
  89. uv21.Init( 0.5f, 0.5f );
  90. uv22.Init( 0.5f, 1.0f );
  91. uv12.Init( 0.0f, 1.0f );
  92. verts[0].Init( Vector2D( 0.0f, flHalfTall ), uv11 );
  93. verts[1].Init( Vector2D( flHalfWide, flHalfTall ), uv21 );
  94. verts[2].Init( Vector2D( flHalfWide, tall ), uv22 );
  95. verts[3].Init( Vector2D( 0.0f, tall ), uv12 );
  96. vgui::surface()->DrawTexturedPolygon( 4, verts );
  97. // draw the partial fourth quadrant
  98. if ( flEndAngle > fl90degrees * 3.5f ) // > 315 degrees
  99. {
  100. uv11.Init( 0.0f, 0.0f );
  101. uv21.Init( 0.5f - ( tan(fl90degrees * 4.0f - flEndAngle) * 0.5 ), 0.0f );
  102. uv22.Init( 0.5f, 0.5f );
  103. uv12.Init( 0.0f, 0.5f );
  104. verts[0].Init( Vector2D( 0.0f, 0.0f ), uv11 );
  105. verts[1].Init( Vector2D( flHalfWide - ( tan(fl90degrees * 4.0f - flEndAngle) * flHalfTall ), 0.0f ), uv21 );
  106. verts[2].Init( Vector2D( flHalfWide, flHalfTall ), uv22 );
  107. verts[3].Init( Vector2D( 0.0f, flHalfTall ), uv12 );
  108. vgui::surface()->DrawTexturedPolygon( 4, verts );
  109. }
  110. else // <= 315 degrees
  111. {
  112. uv11.Init( 0.0f, 0.5f );
  113. uv21.Init( 0.0f, 0.5f - ( tan(flEndAngle - fl90degrees * 3.0f) * 0.5 ) );
  114. uv22.Init( 0.5f, 0.5f );
  115. uv12.Init( 0.0f, 0.5f );
  116. verts[0].Init( Vector2D( 0.0f, flHalfTall ), uv11 );
  117. verts[1].Init( Vector2D( 0.0f, flHalfTall - ( tan(flEndAngle - fl90degrees * 3.0f) * flHalfWide ) ), uv21 );
  118. verts[2].Init( Vector2D( flHalfWide, flHalfTall ), uv22 );
  119. verts[3].Init( Vector2D( 0.0f, flHalfTall ), uv12 );
  120. vgui::surface()->DrawTexturedPolygon( 4, verts );
  121. }
  122. }
  123. else if ( flEndAngle >= fl90degrees * 2.0f ) // >= 180 degrees
  124. {
  125. // draw the first and second quadrants
  126. uv11.Init( 0.5f, 0.0f );
  127. uv21.Init( 1.0f, 0.0f );
  128. uv22.Init( 1.0f, 1.0f );
  129. uv12.Init( 0.5, 1.0f );
  130. verts[0].Init( Vector2D( flHalfWide, 0.0f ), uv11 );
  131. verts[1].Init( Vector2D( wide, 0.0f ), uv21 );
  132. verts[2].Init( Vector2D( wide, tall ), uv22 );
  133. verts[3].Init( Vector2D( flHalfWide, tall ), uv12 );
  134. vgui::surface()->DrawTexturedPolygon( 4, verts );
  135. // draw the partial third quadrant
  136. if ( flEndAngle > fl90degrees * 2.5f ) // > 225 degrees
  137. {
  138. uv11.Init( 0.5f, 0.5f );
  139. uv21.Init( 0.5f, 1.0f );
  140. uv22.Init( 0.0f, 1.0f );
  141. uv12.Init( 0.0f, 0.5f + ( tan(fl90degrees * 3.0f - flEndAngle) * 0.5 ) );
  142. verts[0].Init( Vector2D( flHalfWide, flHalfTall ), uv11 );
  143. verts[1].Init( Vector2D( flHalfWide, tall ), uv21 );
  144. verts[2].Init( Vector2D( 0.0f, tall ), uv22 );
  145. verts[3].Init( Vector2D( 0.0f, flHalfTall + ( tan(fl90degrees * 3.0f - flEndAngle) * flHalfWide ) ), uv12 );
  146. vgui::surface()->DrawTexturedPolygon( 4, verts );
  147. }
  148. else // <= 225 degrees
  149. {
  150. uv11.Init( 0.5f, 0.5f );
  151. uv21.Init( 0.5f, 1.0f );
  152. uv22.Init( 0.5f - ( tan( flEndAngle - fl90degrees * 2.0f) * 0.5 ), 1.0f );
  153. uv12.Init( 0.5f, 0.5f );
  154. verts[0].Init( Vector2D( flHalfWide, flHalfTall ), uv11 );
  155. verts[1].Init( Vector2D( flHalfWide, tall ), uv21 );
  156. verts[2].Init( Vector2D( flHalfWide - ( tan(flEndAngle - fl90degrees * 2.0f) * flHalfTall ), tall ), uv22 );
  157. verts[3].Init( Vector2D( flHalfWide, flHalfTall ), uv12 );
  158. vgui::surface()->DrawTexturedPolygon( 4, verts );
  159. }
  160. }
  161. else if ( flEndAngle >= fl90degrees ) // >= 90 degrees
  162. {
  163. // draw the first quadrant
  164. uv11.Init( 0.5f, 0.0f );
  165. uv21.Init( 1.0f, 0.0f );
  166. uv22.Init( 1.0f, 0.5f );
  167. uv12.Init( 0.5f, 0.5f );
  168. verts[0].Init( Vector2D( flHalfWide, 0.0f ), uv11 );
  169. verts[1].Init( Vector2D( wide, 0.0f ), uv21 );
  170. verts[2].Init( Vector2D( wide, flHalfTall ), uv22 );
  171. verts[3].Init( Vector2D( flHalfWide, flHalfTall ), uv12 );
  172. vgui::surface()->DrawTexturedPolygon( 4, verts );
  173. // draw the partial second quadrant
  174. if ( flEndAngle > fl90degrees * 1.5f ) // > 135 degrees
  175. {
  176. uv11.Init( 0.5f, 0.5f );
  177. uv21.Init( 1.0f, 0.5f );
  178. uv22.Init( 1.0f, 1.0f );
  179. uv12.Init( 0.5f + ( tan(fl90degrees * 2.0f - flEndAngle) * 0.5f ), 1.0f );
  180. verts[0].Init( Vector2D( flHalfWide, flHalfTall ), uv11 );
  181. verts[1].Init( Vector2D( wide, flHalfTall ), uv21 );
  182. verts[2].Init( Vector2D( wide, tall ), uv22 );
  183. verts[3].Init( Vector2D( flHalfWide + ( tan(fl90degrees * 2.0f - flEndAngle) * flHalfTall ), tall ), uv12 );
  184. vgui::surface()->DrawTexturedPolygon( 4, verts );
  185. }
  186. else // <= 135 degrees
  187. {
  188. uv11.Init( 0.5f, 0.5f );
  189. uv21.Init( 1.0f, 0.5f );
  190. uv22.Init( 1.0f, 0.5f + ( tan(flEndAngle - fl90degrees) * 0.5f ) );
  191. uv12.Init( 0.5f, 0.5f );
  192. verts[0].Init( Vector2D( flHalfWide, flHalfTall ), uv11 );
  193. verts[1].Init( Vector2D( wide, flHalfTall ), uv21 );
  194. verts[2].Init( Vector2D( wide, flHalfTall + ( tan(flEndAngle - fl90degrees) * flHalfWide ) ), uv22 );
  195. verts[3].Init( Vector2D( flHalfWide, flHalfTall ), uv12 );
  196. vgui::surface()->DrawTexturedPolygon( 4, verts );
  197. }
  198. }
  199. else // > 0 degrees
  200. {
  201. if ( flEndAngle > fl90degrees / 2.0f ) // > 45 degrees
  202. {
  203. uv11.Init( 0.5f, 0.0f );
  204. uv21.Init( 1.0f, 0.0f );
  205. uv22.Init( 1.0f, 0.5f - ( tan(fl90degrees - flEndAngle) * 0.5 ) );
  206. uv12.Init( 0.5f, 0.5f );
  207. verts[0].Init( Vector2D( flHalfWide, 0.0f ), uv11 );
  208. verts[1].Init( Vector2D( wide, 0.0f ), uv21 );
  209. verts[2].Init( Vector2D( wide, flHalfTall - ( tan(fl90degrees - flEndAngle) * flHalfWide ) ), uv22 );
  210. verts[3].Init( Vector2D( flHalfWide, flHalfTall ), uv12 );
  211. vgui::surface()->DrawTexturedPolygon( 4, verts );
  212. }
  213. else // <= 45 degrees
  214. {
  215. uv11.Init( 0.5f, 0.0f );
  216. uv21.Init( 0.5 + ( tan(flEndAngle) * 0.5 ), 0.0f );
  217. uv22.Init( 0.5f, 0.5f );
  218. uv12.Init( 0.5f, 0.0f );
  219. verts[0].Init( Vector2D( flHalfWide, 0.0f ), uv11 );
  220. verts[1].Init( Vector2D( flHalfWide + ( tan(flEndAngle) * flHalfTall ), 0.0f ), uv21 );
  221. verts[2].Init( Vector2D( flHalfWide, flHalfTall ), uv22 );
  222. verts[3].Init( Vector2D( flHalfWide, 0.0f ), uv12 );
  223. vgui::surface()->DrawTexturedPolygon( 4, verts );
  224. }
  225. }
  226. }
  227. //-----------------------------------------------------------------------------
  228. // Purpose:
  229. //-----------------------------------------------------------------------------
  230. CDoDCapturePanelIcon::CDoDCapturePanelIcon( vgui::Panel *parent, const char *name ) : vgui::ImagePanel( parent, name )
  231. {
  232. m_bActive = false;
  233. m_iTexture = vgui::surface()->DrawGetTextureId( "vgui/capture_icon" );
  234. if ( m_iTexture == -1 ) // we didn't find it, so create a new one
  235. {
  236. m_iTexture = vgui::surface()->CreateNewTextureID();
  237. }
  238. vgui::surface()->DrawSetTextureFile( m_iTexture, "vgui/capture_icon", true, false );
  239. }
  240. //-----------------------------------------------------------------------------
  241. // Purpose:
  242. //-----------------------------------------------------------------------------
  243. void CDoDCapturePanelIcon::Paint()
  244. {
  245. int wide, tall;
  246. GetSize( wide, tall );
  247. float uv1 = 0.0f, uv2 = 1.0f;
  248. Vector2D uv11( uv1, uv1 );
  249. Vector2D uv12( uv1, uv2 );
  250. Vector2D uv21( uv2, uv1 );
  251. Vector2D uv22( uv2, uv2 );
  252. vgui::Vertex_t verts[4];
  253. verts[0].Init( Vector2D( 0, 0 ), uv11 );
  254. verts[1].Init( Vector2D( wide, 0 ), uv21 );
  255. verts[2].Init( Vector2D( wide, tall ), uv22 );
  256. verts[3].Init( Vector2D( 0, tall ), uv12 );
  257. // just draw the whole thing
  258. vgui::surface()->DrawSetTexture( m_iTexture );
  259. vgui::surface()->DrawSetColor( m_bActive ? m_clrActive : m_clrInActive );
  260. vgui::surface()->DrawTexturedPolygon( 4, verts );
  261. }
  262. //-----------------------------------------------------------------------------
  263. // Purpose: Constructor
  264. //-----------------------------------------------------------------------------
  265. CDoDHudCapturePanel::CDoDHudCapturePanel( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudCapturePanel" )
  266. {
  267. SetParent( g_pClientMode->GetViewport() );
  268. m_pBackground = new vgui::Panel( this, "CapturePanelBackground" );
  269. m_pProgressBar = new CDoDCapturePanelProgressBar( this, "CapturePanelProgressBar" );
  270. for ( int i = 0 ; i < 5 ; i++ )
  271. {
  272. CDoDCapturePanelIcon *pPanel;
  273. char szName[64];
  274. Q_snprintf( szName, sizeof( szName ), "CapturePanelPlayerIcon%d", i + 1 );
  275. pPanel = new CDoDCapturePanelIcon( this, szName );
  276. m_PlayerIcons.AddToTail( pPanel );
  277. }
  278. m_pAlliesFlag = new vgui::ImagePanel( this, "CapturePanelAlliesFlag" );
  279. m_pAxisFlag = new vgui::ImagePanel( this, "CapturePanelAxisFlag" );
  280. m_pNeutralFlag = new vgui::ImagePanel( this, "CapturePanelNeutralFlag" );
  281. m_pMessage = new vgui::Label( this, "CapturePanelMessage", " " );
  282. // load control settings...
  283. LoadControlSettings( "resource/UI/HudCapturePanel.res" );
  284. }
  285. //-----------------------------------------------------------------------------
  286. // Purpose:
  287. //-----------------------------------------------------------------------------
  288. void CDoDHudCapturePanel::OnScreenSizeChanged( int iOldWide, int iOldTall )
  289. {
  290. LoadControlSettings( "resource/UI/HudCapturePanel.res" );
  291. }
  292. //-----------------------------------------------------------------------------
  293. // Purpose:
  294. //-----------------------------------------------------------------------------
  295. void CDoDHudCapturePanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  296. {
  297. BaseClass::ApplySchemeSettings( pScheme );
  298. if ( m_pBackground )
  299. {
  300. m_pBackground->SetBgColor( GetSchemeColor( "HintMessageBg", pScheme ) );
  301. m_pBackground->SetPaintBackgroundType( 2 );
  302. }
  303. SetFgColor( GetSchemeColor( "HudProgressBar.Active", pScheme ) );
  304. }
  305. //-----------------------------------------------------------------------------
  306. // Purpose:
  307. //-----------------------------------------------------------------------------
  308. void CDoDHudCapturePanel::OnThink()
  309. {
  310. BaseClass::OnThink();
  311. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  312. if ( pPlayer )
  313. {
  314. int iCPIndex = pPlayer->GetCPIndex();
  315. bool bInCapZone = ( iCPIndex >= 0 );
  316. // turn off the panel and children if the player is dead or not in a cap zone
  317. if ( !pPlayer->IsAlive() )
  318. {
  319. if ( IsVisible() )
  320. {
  321. SetVisible( false );
  322. }
  323. return;
  324. }
  325. if ( !bInCapZone || !hud_capturepanel.GetBool() )
  326. {
  327. // see if the player progress bar wants to draw
  328. // then return, we're not in an area cap
  329. if ( pPlayer->m_iProgressBarDuration > 0 && pPlayer )
  330. {
  331. if ( !IsVisible() )
  332. {
  333. SetVisible( true );
  334. }
  335. // hide the other stuff
  336. m_pAlliesFlag->SetVisible( false );
  337. m_pAxisFlag->SetVisible( false );
  338. m_pNeutralFlag->SetVisible( false );
  339. m_pMessage->SetVisible( false );
  340. int i;
  341. for ( i = 0 ; i < m_PlayerIcons.Count() ; i++ )
  342. {
  343. m_PlayerIcons[i]->SetVisible( false );
  344. }
  345. // turn on the progress bar, we're capping
  346. if ( m_pProgressBar )
  347. {
  348. if ( !m_pProgressBar->IsVisible() )
  349. {
  350. m_pProgressBar->SetVisible( true );
  351. }
  352. float flPercent = (pPlayer->m_flSimulationTime - pPlayer->m_flProgressBarStartTime) / (float)pPlayer->m_iProgressBarDuration;
  353. flPercent = clamp( flPercent, 0, 1 );
  354. m_pProgressBar->SetPercentage( flPercent );
  355. }
  356. }
  357. else
  358. {
  359. if ( IsVisible() )
  360. {
  361. SetVisible( false );
  362. }
  363. }
  364. return;
  365. }
  366. int nOwningTeam = g_pObjectiveResource->GetOwningTeam( iCPIndex );
  367. int nPlayerTeam = pPlayer->GetTeamNumber();
  368. int nNumTeammates = g_pObjectiveResource->GetNumPlayersInArea( iCPIndex, nPlayerTeam == TEAM_ALLIES ? TEAM_ALLIES : TEAM_AXIS );
  369. int nRequiredTeammates = g_pObjectiveResource->GetRequiredCappers( iCPIndex, nPlayerTeam == TEAM_ALLIES ? TEAM_ALLIES : TEAM_AXIS );
  370. int nNumEnemies = g_pObjectiveResource->GetNumPlayersInArea( iCPIndex, nPlayerTeam == TEAM_ALLIES ? TEAM_AXIS : TEAM_ALLIES );
  371. int nRequiredEnemies = g_pObjectiveResource->GetRequiredCappers( iCPIndex, nPlayerTeam == TEAM_ALLIES ? TEAM_AXIS : TEAM_ALLIES );
  372. int iCappingTeam = g_pObjectiveResource->GetCappingTeam( iCPIndex );
  373. // if we already own this capture point and there are no enemies in the area
  374. if ( nOwningTeam == nPlayerTeam && nNumEnemies < nRequiredEnemies )
  375. {
  376. // don't need to do anything
  377. if ( IsVisible() )
  378. {
  379. SetVisible( false );
  380. }
  381. return;
  382. }
  383. // okay, turn on the capture point panel
  384. if ( !IsVisible() )
  385. {
  386. SetVisible( true );
  387. }
  388. // set the correct flag image
  389. switch( nOwningTeam )
  390. {
  391. case TEAM_ALLIES:
  392. if ( m_pAlliesFlag && !m_pAlliesFlag->IsVisible() )
  393. m_pAlliesFlag->SetVisible( true );
  394. if ( m_pAxisFlag && m_pAxisFlag->IsVisible() )
  395. m_pAxisFlag->SetVisible( false );
  396. if ( m_pNeutralFlag && m_pNeutralFlag->IsVisible() )
  397. m_pNeutralFlag->SetVisible( false );
  398. break;
  399. case TEAM_AXIS:
  400. if ( m_pAlliesFlag && m_pAlliesFlag->IsVisible() )
  401. m_pAlliesFlag->SetVisible( false );
  402. if ( m_pAxisFlag && !m_pAxisFlag->IsVisible() )
  403. m_pAxisFlag->SetVisible( true );
  404. if ( m_pNeutralFlag && m_pNeutralFlag->IsVisible() )
  405. m_pNeutralFlag->SetVisible( false );
  406. break;
  407. default:
  408. if ( m_pAlliesFlag && m_pAlliesFlag->IsVisible() )
  409. m_pAlliesFlag->SetVisible( false );
  410. if ( m_pAxisFlag && m_pAxisFlag->IsVisible() )
  411. m_pAxisFlag->SetVisible( false );
  412. if ( m_pNeutralFlag && !m_pNeutralFlag->IsVisible() )
  413. m_pNeutralFlag->SetVisible( true );
  414. break;
  415. }
  416. // arrange the player icons
  417. int i = 0;
  418. for ( i = 0 ; i < m_PlayerIcons.Count() ; i++ )
  419. {
  420. CDoDCapturePanelIcon *pPanel = m_PlayerIcons[i];
  421. if ( !pPanel )
  422. {
  423. continue;
  424. }
  425. if ( i < nRequiredTeammates )
  426. {
  427. if ( i < nNumTeammates )
  428. {
  429. pPanel->SetActive( true );
  430. if ( !pPanel->IsVisible() )
  431. pPanel->SetVisible( true );
  432. }
  433. else
  434. {
  435. pPanel->SetActive( false );
  436. if ( !pPanel->IsVisible() )
  437. pPanel->SetVisible( true );
  438. }
  439. }
  440. else
  441. {
  442. if ( pPanel->IsVisible() )
  443. pPanel->SetVisible( false );
  444. }
  445. }
  446. int wide = 0, tall = 0, iconWide = 0, iconTall = 0;
  447. GetSize( wide, tall );
  448. vgui::ImagePanel *pPanel = m_PlayerIcons[0];
  449. if ( pPanel )
  450. pPanel->GetSize( iconWide, iconTall );
  451. int width = ( nRequiredTeammates * iconWide ) + ( ( nRequiredTeammates - 1 ) * m_nSpaceBetweenIcons );
  452. int xpos = wide / 2.0 - width / 2.0;
  453. // rearrange the player icon panels
  454. for ( i = 0 ; i < nRequiredTeammates ; i++ )
  455. {
  456. CDoDCapturePanelIcon *pPanel = m_PlayerIcons[i];
  457. if ( pPanel )
  458. {
  459. int x, y, w, t;
  460. pPanel->GetBounds( x, y, w, t );
  461. pPanel->SetBounds( xpos, y, w, t );
  462. }
  463. xpos += iconWide + m_nSpaceBetweenIcons;
  464. }
  465. // are we capping an area?
  466. if ( iCappingTeam == TEAM_UNASSIGNED || iCappingTeam != nPlayerTeam )
  467. {
  468. // turn off the progress bar, we're not capping
  469. if ( m_pProgressBar && m_pProgressBar->IsVisible() )
  470. {
  471. m_pProgressBar->SetVisible( false );
  472. }
  473. // turn on the message
  474. if ( m_pMessage )
  475. {
  476. m_pMessage->SetFgColor( GetFgColor() );
  477. if ( !m_pMessage->IsVisible() )
  478. {
  479. m_pMessage->SetVisible( true );
  480. }
  481. if ( nNumTeammates >= nRequiredTeammates && nNumEnemies > 0 )
  482. {
  483. m_pMessage->SetText( "#Dod_Capture_Blocked" );
  484. }
  485. else if ( nNumEnemies > 0 /*nNumEnemies >= nRequiredEnemies*/ )
  486. {
  487. m_pMessage->SetText( "#Dod_Blocking_Capture" );
  488. }
  489. else
  490. {
  491. m_pMessage->SetText( "#Dod_Waiting_for_teammate" );
  492. }
  493. if ( m_pBackground )
  494. {
  495. // do we need to resize our background?
  496. int textW, textH, bgX, bgY, bgW, bgH;
  497. m_pMessage->GetContentSize( textW, textH );
  498. m_pBackground->GetBounds( bgX, bgY, bgW, bgH );
  499. if ( bgW < textW )
  500. {
  501. m_pBackground->SetBounds( bgX + ( bgW / 2.0 ) - ( ( textW + XRES(3) ) / 2.0 ), bgY, textW + XRES(3), bgH );
  502. }
  503. }
  504. }
  505. }
  506. else
  507. {
  508. // turn on the progress bar, we're capping
  509. if ( m_pProgressBar )
  510. {
  511. if ( !m_pProgressBar->IsVisible() )
  512. {
  513. m_pProgressBar->SetVisible( true );
  514. }
  515. m_pProgressBar->SetPercentage( g_pObjectiveResource->GetCPCapPercentage( pPlayer->GetCPIndex() ) );
  516. }
  517. // turn off the message
  518. if ( m_pMessage && m_pMessage->IsVisible() )
  519. {
  520. m_pMessage->SetVisible( false );
  521. }
  522. }
  523. }
  524. }