statslist improvements

This commit is contained in:
kremsy 2014-01-31 15:16:26 +01:00 committed by Steffen Schröder
parent 8fede6f508
commit 2176cb7791
3 changed files with 46 additions and 18 deletions

View File

@ -32,6 +32,25 @@ abstract class Formatter {
return $format; 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 * Formatts a Elapset time String (2 days ago...) by a given timestamp
* *

View File

@ -529,7 +529,6 @@ class MapManager implements CallbackListener {
$mapFileName = $downloadDirectory . '/' . $fileName; $mapFileName = $downloadDirectory . '/' . $fileName;
var_dump($mapDir);
//Check if it can get locally Written //Check if it can get locally Written
if (is_dir($mapDir)) { if (is_dir($mapDir)) {
// Create download directory if necessary // Create download directory if necessary

View File

@ -15,6 +15,7 @@ use FML\ManiaLink;
use FML\Script\Script; use FML\Script\Script;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
@ -22,7 +23,7 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener { class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener, CommandListener {
/** /**
* Constants * Constants
*/ */
@ -52,17 +53,18 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
* @param array $callback * @param array $callback
*/ */
public function handleOnInit(array $callback) { public function handleOnInit(array $callback) {
$this->maniaControl->commandManager->registerCommandListener('stats', $this, 'command_ShowStatsList');
// Action Open StatsList // Action Open StatsList
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_STATSLIST, $this, 'command_ShowStatsList'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_STATSLIST, $this, 'command_ShowStatsList');
//TODO command
$itemQuad = new Quad_UIConstruction_Buttons(); $itemQuad = new Quad_UIConstruction_Buttons();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Stats); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Stats);
$itemQuad->setAction(self::ACTION_OPEN_STATSLIST); $itemQuad->setAction(self::ACTION_OPEN_STATSLIST);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 14, 'Open Statistics'); $this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 14, 'Open Statistics');
//TODO setting if a stat get shown //TODO settings if a stat get shown
//TODO sort out stats where no player have a point
$this->registerStat(PlayerManager::STAT_SERVERTIME, 10, "ST", 20, StatisticManager::STAT_TYPE_TIME); $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_HIT, 20, "H");
$this->registerStat(StatisticCollector::STAT_ON_NEARMISS, 30, "NM"); $this->registerStat(StatisticCollector::STAT_ON_NEARMISS, 30, "NM");
@ -155,16 +157,25 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
$x = $xStart + 55; $x = $xStart + 55;
//Display Head
$statRankings = array(); $statRankings = array();
foreach($this->statArray as $key => $stat) { foreach($this->statArray as $stat) {
$statRankings[$stat["Name"]] = $this->maniaControl->statisticManager->getStatsRanking($stat["Name"]); $ranking = $this->maniaControl->statisticManager->getStatsRanking($stat["Name"]);
if (!empty($ranking)) {
$statRankings[$stat["Name"]] = $ranking;
$array[$stat['HeadShortCut']] = $x; $array[$stat['HeadShortCut']] = $x;
$x += $stat["Width"]; $x += $stat["Width"];
} }
}
//TODO description on each $labels = $this->maniaControl->manialinkManager->labelLine($headFrame, $array);
$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 // define standard properties
$hAlign = Control::LEFT; $hAlign = Control::LEFT;
@ -192,11 +203,10 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
if (isset($statRankings[$stat['Name']][$playerId])) { if (isset($statRankings[$stat['Name']][$playerId])) {
$statValue = $statRankings[$stat['Name']][$playerId]; $statValue = $statRankings[$stat['Name']][$playerId];
if ($stat['Format'] == StatisticManager::STAT_TYPE_TIME) { if ($stat['Format'] == StatisticManager::STAT_TYPE_TIME) {
$statValue = Formatter::formatTimeH($statValue); $statValue = Formatter::formatTimeHMS($statValue);
} else if ($stat['Format'] == StatisticManager::STAT_TYPE_FLOAT) { } else if ($stat['Format'] == StatisticManager::STAT_TYPE_FLOAT) {
$statValue = round(floatval($statValue), 2); $statValue = round(floatval($statValue), 2);
} }
} }
$displayArray[$stat['Name']] = array("Value" => strval($statValue), "Width" => $stat['Width']); $displayArray[$stat['Name']] = array("Value" => strval($statValue), "Width" => $stat['Width']);
} }