diff --git a/application/core/Formatter.php b/application/core/Formatter.php index 0c0faf6e..be1b21b6 100644 --- a/application/core/Formatter.php +++ b/application/core/Formatter.php @@ -16,7 +16,7 @@ abstract class Formatter { * @return string */ public static function formatTime($time) { - if(!is_int($time)) { + if (!is_int($time)) { $time = (int)$time; } $milliseconds = $time % 1000; @@ -32,6 +32,25 @@ abstract class Formatter { return $format; } + /** + * Formats a Time to H:M:S + * + * @param int $seconds + * @return string + */ + public static function formatTimeHMS($seconds) { + $minutes = floor($seconds / 60); + $hours = floor($minutes / 60); + $minutes -= $hours * 60; + $seconds -= ($hours * 3600 + $minutes * 60); + + $hours = ($hours < 10 ? '0' : '') . $hours; + $minutes = ($minutes < 10 ? '0' : '') . $minutes;; + $seconds = ($seconds < 10 ? '0' : '') . $seconds;; + + return $hours . ":" . $minutes . ":" . $seconds; + } + /** * Formatts a Elapset time String (2 days ago...) by a given timestamp * @@ -41,7 +60,7 @@ abstract class Formatter { public static function time_elapsed_string($ptime) { $etime = time() - $ptime; - if($etime < 1) { + if ($etime < 1) { return '0 seconds'; } @@ -49,7 +68,7 @@ abstract class Formatter { foreach($a as $secs => $str) { $d = $etime / $secs; - if($d >= 1) { + if ($d >= 1) { $r = round($d); return $r . ' ' . $str . ($r > 1 ? 's' : '') . ' ago'; } @@ -136,10 +155,10 @@ abstract class Formatter { 'Canada' => 'CAN', 'Cape Verde' => 'CPV', 'Central African Republic' => 'CAF', 'Chad' => 'CHA', 'Chile' => 'CHI', 'China' => 'CHN', 'Chinese Taipei' => 'TPE', 'Colombia' => 'COL', 'Congo' => 'CGO', 'Costa Rica' => 'CRC', 'Croatia' => 'CRO', 'Cuba' => 'CUB', 'Cyprus' => 'CYP', 'Czech Republic' => 'CZE', 'Czech republic' => 'CZE', 'DR Congo' => 'COD', 'Denmark' => 'DEN', 'Djibouti' => 'DJI', 'Dominica' => 'DMA', 'Dominican Republic' => 'DOM', 'Ecuador' => 'ECU', 'Egypt' => 'EGY', 'El Salvador' => 'ESA', 'Eritrea' => 'ERI', 'Estonia' => 'EST', 'Ethiopia' => 'ETH', 'Fiji' => 'FIJ', 'Finland' => 'FIN', 'France' => 'FRA', 'Gabon' => 'GAB', 'Gambia' => 'GAM', 'Georgia' => 'GEO', 'Germany' => 'GER', 'Ghana' => 'GHA', 'Greece' => 'GRE', 'Grenada' => 'GRN', 'Guam' => 'GUM', 'Guatemala' => 'GUA', 'Guinea' => 'GUI', 'Guinea-Bissau' => 'GBS', 'Guyana' => 'GUY', 'Haiti' => 'HAI', 'Honduras' => 'HON', 'Hong Kong' => 'HKG', 'Hungary' => 'HUN', 'Iceland' => 'ISL', 'India' => 'IND', 'Indonesia' => 'INA', 'Iran' => 'IRI', 'Iraq' => 'IRQ', 'Ireland' => 'IRL', 'Israel' => 'ISR', 'Italy' => 'ITA', 'Ivory Coast' => 'CIV', 'Jamaica' => 'JAM', 'Japan' => 'JPN', 'Jordan' => 'JOR', 'Kazakhstan' => 'KAZ', 'Kenya' => 'KEN', 'Kiribati' => 'KIR', 'Korea' => 'KOR', 'Kuwait' => 'KUW', 'Kyrgyzstan' => 'KGZ', 'Laos' => 'LAO', 'Latvia' => 'LAT', 'Lebanon' => 'LIB', 'Lesotho' => 'LES', 'Liberia' => 'LBR', 'Libya' => 'LBA', 'Liechtenstein' => 'LIE', 'Lithuania' => 'LTU', 'Luxembourg' => 'LUX', 'Macedonia' => 'MKD', 'Malawi' => 'MAW', 'Malaysia' => 'MAS', 'Mali' => 'MLI', 'Malta' => 'MLT', 'Mauritania' => 'MTN', 'Mauritius' => 'MRI', 'Mexico' => 'MEX', 'Moldova' => 'MDA', 'Monaco' => 'MON', 'Mongolia' => 'MGL', 'Montenegro' => 'MNE', 'Morocco' => 'MAR', 'Mozambique' => 'MOZ', 'Myanmar' => 'MYA', 'Namibia' => 'NAM', 'Nauru' => 'NRU', 'Nepal' => 'NEP', 'Netherlands' => 'NED', 'New Zealand' => 'NZL', 'Nicaragua' => 'NCA', 'Niger' => 'NIG', 'Nigeria' => 'NGR', 'Norway' => 'NOR', 'Oman' => 'OMA', 'Other Countries' => 'OTH', 'Pakistan' => 'PAK', 'Palau' => 'PLW', 'Palestine' => 'PLE', 'Panama' => 'PAN', 'Paraguay' => 'PAR', 'Peru' => 'PER', 'Philippines' => 'PHI', 'Poland' => 'POL', 'Portugal' => 'POR', 'Puerto Rico' => 'PUR', 'Qatar' => 'QAT', 'Romania' => 'ROM', // actually ROU 'Russia' => 'RUS', 'Rwanda' => 'RWA', 'Samoa' => 'SAM', 'San Marino' => 'SMR', 'Saudi Arabia' => 'KSA', 'Senegal' => 'SEN', 'Serbia' => 'SCG', // actually SRB 'Sierra Leone' => 'SLE', 'Singapore' => 'SIN', 'Slovakia' => 'SVK', 'Slovenia' => 'SLO', 'Somalia' => 'SOM', 'South Africa' => 'RSA', 'Spain' => 'ESP', 'Sri Lanka' => 'SRI', 'Sudan' => 'SUD', 'Suriname' => 'SUR', 'Swaziland' => 'SWZ', 'Sweden' => 'SWE', 'Switzerland' => 'SUI', 'Syria' => 'SYR', 'Taiwan' => 'TWN', 'Tajikistan' => 'TJK', 'Tanzania' => 'TAN', 'Thailand' => 'THA', 'Togo' => 'TOG', 'Tonga' => 'TGA', 'Trinidad and Tobago' => 'TRI', 'Tunisia' => 'TUN', 'Turkey' => 'TUR', 'Turkmenistan' => 'TKM', 'Tuvalu' => 'TUV', 'Uganda' => 'UGA', 'Ukraine' => 'UKR', 'United Arab Emirates' => 'UAE', 'United Kingdom' => 'GBR', 'United States of America' => 'USA', 'Uruguay' => 'URU', 'Uzbekistan' => 'UZB', 'Vanuatu' => 'VAN', 'Venezuela' => 'VEN', 'Vietnam' => 'VIE', 'Yemen' => 'YEM', 'Zambia' => 'ZAM', 'Zimbabwe' => 'ZIM'); - if(array_key_exists($country, $nations)) { + if (array_key_exists($country, $nations)) { return $nations[$country]; } - if($country) { + if ($country) { trigger_error("Couldn't map Country: '{$country}'!"); } return 'OTH'; diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index fa941afd..9b3513d1 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -529,7 +529,6 @@ class MapManager implements CallbackListener { $mapFileName = $downloadDirectory . '/' . $fileName; - var_dump($mapDir); //Check if it can get locally Written if (is_dir($mapDir)) { // Create download directory if necessary diff --git a/application/core/Statistics/SimpleStatsList.php b/application/core/Statistics/SimpleStatsList.php index be2dc2c9..47dbdbb4 100644 --- a/application/core/Statistics/SimpleStatsList.php +++ b/application/core/Statistics/SimpleStatsList.php @@ -15,6 +15,7 @@ use FML\ManiaLink; use FML\Script\Script; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; +use ManiaControl\Commands\CommandListener; use ManiaControl\Formatter; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\ManialinkManager; @@ -22,7 +23,7 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; -class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener { +class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener, CommandListener { /** * Constants */ @@ -52,17 +53,18 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener { * @param array $callback */ public function handleOnInit(array $callback) { + $this->maniaControl->commandManager->registerCommandListener('stats', $this, 'command_ShowStatsList'); + // Action Open StatsList $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_STATSLIST, $this, 'command_ShowStatsList'); - //TODO command + $itemQuad = new Quad_UIConstruction_Buttons(); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Stats); $itemQuad->setAction(self::ACTION_OPEN_STATSLIST); $this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 14, 'Open Statistics'); - //TODO setting if a stat get shown - //TODO sort out stats where no player have a point + //TODO settings if a stat get shown $this->registerStat(PlayerManager::STAT_SERVERTIME, 10, "ST", 20, StatisticManager::STAT_TYPE_TIME); $this->registerStat(StatisticCollector::STAT_ON_HIT, 20, "H"); $this->registerStat(StatisticCollector::STAT_ON_NEARMISS, 30, "NM"); @@ -155,16 +157,25 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener { $x = $xStart + 55; + //Display Head $statRankings = array(); - foreach($this->statArray as $key => $stat) { - $statRankings[$stat["Name"]] = $this->maniaControl->statisticManager->getStatsRanking($stat["Name"]); - $array[$stat['HeadShortCut']] = $x; - $x += $stat["Width"]; + foreach($this->statArray as $stat) { + $ranking = $this->maniaControl->statisticManager->getStatsRanking($stat["Name"]); + if (!empty($ranking)) { + $statRankings[$stat["Name"]] = $ranking; + $array[$stat['HeadShortCut']] = $x; + $x += $stat["Width"]; + } } - //TODO description on each - $this->maniaControl->manialinkManager->labelLine($headFrame, $array); + $labels = $this->maniaControl->manialinkManager->labelLine($headFrame, $array); + //Description Label + $i = 2; + foreach($this->statArray as $statArray) { + $script->addTooltip($labels[$i], $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => '$o ' . $statArray["Name"])); + $i++; + } // define standard properties $hAlign = Control::LEFT; @@ -192,11 +203,10 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener { if (isset($statRankings[$stat['Name']][$playerId])) { $statValue = $statRankings[$stat['Name']][$playerId]; if ($stat['Format'] == StatisticManager::STAT_TYPE_TIME) { - $statValue = Formatter::formatTimeH($statValue); + $statValue = Formatter::formatTimeHMS($statValue); } else if ($stat['Format'] == StatisticManager::STAT_TYPE_FLOAT) { $statValue = round(floatval($statValue), 2); } - } $displayArray[$stat['Name']] = array("Value" => strval($statValue), "Width" => $stat['Width']); }