The teamStats MovieClip, located in the teamStats layer in Scene 1 of HUDKit.fla, is the scoreboard and statistics for the round in progress. It includes the winning and losing textFields (redWinning, blueWinning), the score for each team displayed in two textFields (scoreRed, scoreBlue) and progress bars (teamRed, teamBlue), and the roundtime clock textField (roundTime).
Figure 5: teamStats Symbol
teamStats is updated exclusively using FxHUDView::UpdateTeamStats(). The following code updates the teamStats MovieClip’s elements.
void FxHUDView::UpdateTeamStats(FxHUDEnvironment *penv) { // Retrieve the scores from the simulation. unsigned scoreBlue = unsigned(penv->GetHUDBlueTeamScore()); unsigned scoreRed = unsigned(penv->GetHUDRedTeamScore()); String text; Value tf; Value::DisplayInfo info; // We won't update any element who has not changed since the last update // to avoid unnecessary updates. To do so, we compare the previous // simulation State to the latest simulation data. If the two are different, // update the UI element in the HUD View. if (State.ScoreRed != scoreRed) { Format(text, "{0}", scoreRed); ScoreRedMC.SetText(text); // Update the red team score text. info.SetScale((scoreRed / (Double)MaxScore) * 100, 100); TeamRedMC.SetDisplayInfo(info); // Update and scale the red team score bar movieClip. } if (State.ScoreBlue != scoreBlue) { Format(text, "{0}", scoreBlue); ScoreBlueMC.SetText(text); // Update the blue team score text. info.SetScale((scoreBlue / (Double)MaxScore) * 100, 100); TeamBlueMC.SetDisplayInfo(info); // Update and scale the blue team score bar movieClip. } if (State.ScoreRed != scoreRed || State.ScoreBlue != scoreBlue) { // Update the "Winning" and "Losing" text fields for both teams if the score has changed. if (scoreBlue > scoreRed) { RedWinningMC.SetText(LosingText); BlueWinningMC.SetText(WinningText); } else { RedWinningMC.SetText(WinningText); BlueWinningMC.SetText(LosingText); } } // Update the roundtime clock float secondsLeft = penv->GetSecondsLeftInRound(); unsigned sec = ((unsigned)secondsLeft % 60); if (sec != State.Sec) { unsigned min = ((unsigned)secondsLeft / 60); String timeLeft; Format(timeLeft, "{0}:{1:0.2}", min, sec); RoundTimeMC.SetText(timeLeft); State.Sec = sec; } }
The score is stored in a Scaleform::String and passed to the scoreRed and scoreBlue textFields using GFx::Value::SetText(). The X scale of the teamRed and teamBlue score bars are updated using GFx::Value::SetDisplayInfo(). Both begin at 0% of their original width and are scaled toward 100% as the teams’ score increases toward the score needed to win the round.
Before updating the blueWinning/redWinning textFields, the two team scores are compared to avoid unnecessary updates. GFx::Value::SetText() is called to set the text using the constant “Winning” and “Losing” strings defined during the HUDView’s initialization.
Before updating the round time textField, the time remaining at the last UpdateView() call is compared against the latest time. If more than a second has elapsed since the last update, the roundTime textField is updated with the formatted time String using GFx::Value::SetText().