/** * The progress bar for this member, showing current SCs and units, and distance to SCTarget SCs * @return string */ function memberProgressBar() { // $Remaining // $SCEqual, ($Remaining) // $SCEqual, $UnitDeficit, ($Remaining) // $SCEqual, $UnitSurplus, ($Remaining) libHTML::$first = true; if ($this->supplyCenterNo + $this->unitNo == 0) { return '<table class="memberProgressBarTable"><tr> <td class="memberProgressBarRemaining ' . libHTML::first() . '" style="width:100%"></td> </tr></table>'; } $dividers = array(); if ($this->unitNo < $this->supplyCenterNo) { $dividers[$this->unitNo] = 'SCs'; $dividers[$this->supplyCenterNo] = 'UnitDeficit'; } else { $dividers[$this->supplyCenterNo] = 'SCs'; if ($this->unitNo > $this->supplyCenterNo) { $dividers[$this->unitNo] = 'UnitSurplus'; } } $SCTarget = $this->Game->Variant->supplyCenterTarget; $buf = ''; $lastNumber = 0; foreach ($dividers as $number => $type) { if ($number - $lastNumber == 0) { continue; } if ($lastNumber == $SCTarget) { break; } if ($number > $SCTarget) { $number = $SCTarget; } $width = round(($number - $lastNumber) / $SCTarget * 100); $buf .= '<td class="memberProgressBar' . $type . ' ' . libHTML::first() . '" style="width:' . $width . '%"></td>'; $lastNumber = $number; } if ($number < $SCTarget) { $width = round(($SCTarget - $number) / $SCTarget * 100); $buf .= '<td class="memberProgressBarRemaining ' . libHTML::first() . '" style="width:' . $width . '%"></td>'; } return '<table class="memberProgressBarTable"><tr>' . $buf . '</tr></table>'; }
/** * Returns 'first' the first time it's called, and nothing from then on until $first is set to true. * @return string */ public static function first() { if (self::$first) { self::$first = false; return 'first'; } }
/** * The occupation bar; a bar representing each of the countries current progress as measured by the number of SCs. * If called pre-game it goes from red to green as 1 to 7 players join the game. * * @return string */ function occupationBar() { if (isset($this->occupationBarCache)) { return $this->occupationBarCache; } libHTML::$first = true; if ($this->Game->phase != 'Pre-game') { $SCPercents = $this->SCPercents(); $buf = ''; foreach ($SCPercents as $countryID => $width) { if ($width > 0) { $buf .= '<td class="occupationBar' . $countryID . ' ' . libHTML::first() . '" style="width:' . $width . '%"></td>'; } } } else { $joinedPercent = ceil(count($this->ByID) * 100.0 / count($this->Game->Variant->countries)); $buf = '<td class="occupationBarJoined ' . libHTML::first() . '" style="width:' . $joinedPercent . '%"></td>'; if ($joinedPercent < 99.0) { $buf .= '<td class="occupationBarNotJoined" style="width:' . (100 - $joinedPercent) . '%"></td>'; } } $this->occupationBarCache = '<table class="occupationBarTable"><tr> ' . $buf . ' </tr></table>'; return $this->occupationBarCache; }