statslist improvements

This commit is contained in:
kremsy 2014-01-31 15:41:01 +01:00 committed by Steffen Schröder
parent 2176cb7791
commit 6d5062b61c
3 changed files with 53 additions and 2 deletions

View File

@ -163,6 +163,16 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$playerFrame->setY($y); $playerFrame->setY($y);
//Show current Player Arrow
if ($listPlayer->index == $player->index) {
$currentQuad = new Quad_Icons64x64_1();
$playerFrame->add($currentQuad);
$currentQuad->setX($x + 3.5);
$currentQuad->setZ(0.2);
$currentQuad->setSize(4, 4);
$currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue);
}
// Team Emblem // Team Emblem
if ($listPlayer->teamId >= 0) { if ($listPlayer->teamId >= 0) {
// Player is in a Team // Player is in a Team

View File

@ -28,6 +28,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
* Constants * Constants
*/ */
const ACTION_OPEN_STATSLIST = 'SimpleStatsList.OpenStatsList'; const ACTION_OPEN_STATSLIST = 'SimpleStatsList.OpenStatsList';
const ACTION_SORT_STATS = 'SimpleStatsList.SortStats';
/** /**
* Private Properties * Private Properties
@ -44,6 +45,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
} }
@ -173,6 +175,8 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
//Description Label //Description Label
$i = 2; $i = 2;
foreach($this->statArray as $statArray) { foreach($this->statArray as $statArray) {
/** @var Label_Text $labels [] */
$labels[$i]->setAction(self::ACTION_SORT_STATS . '.' . $statArray["Name"]);
$script->addTooltip($labels[$i], $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => '$o ' . $statArray["Name"])); $script->addTooltip($labels[$i], $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => '$o ' . $statArray["Name"]));
$i++; $i++;
} }
@ -191,11 +195,19 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
break; break;
} }
/** @var Player $listPlayer * */
$playerFrame = new Frame(); $playerFrame = new Frame();
$frame->add($playerFrame); $frame->add($playerFrame);
//Show current Player Arrow
if ($playerId == $player->index) {
$currentQuad = new Quad_Icons64x64_1();
$playerFrame->add($currentQuad);
$currentQuad->setX($xStart + 3.5);
$currentQuad->setZ(0.2);
$currentQuad->setSize(4, 4);
$currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue);
}
$displayArray = array(); $displayArray = array();
foreach($this->statArray as $stat) { foreach($this->statArray as $stat) {
@ -249,4 +261,27 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
// Render and display xml // Render and display xml
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'SimpleStatsList'); $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'SimpleStatsList');
} }
/**
* Called on ManialinkPageAnswer
*
* @param array $callback
*/
public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2];
$actionArray = explode('.', $actionId, 3);
if (count($actionArray) <= 2) {
return;
}
$action = $actionArray[0] . "." . $actionArray[1];
switch($action) {
case self::ACTION_SORT_STATS:
$playerLogin = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($playerLogin);
$this->showStatsList($player, $actionArray[2]);
break;
}
}
} }

View File

@ -150,6 +150,7 @@ class StatisticManager {
} }
$statsArray[$key] = intval($kills[$key]) / intval($death); $statsArray[$key] = intval($kills[$key]) / intval($death);
} }
arsort($statsArray);
break; break;
case self::SPECIAL_STAT_HITS_PH: case self::SPECIAL_STAT_HITS_PH:
$hits = $this->getStatsRanking(StatisticCollector::STAT_ON_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_ON_HIT, $serverIndex);
@ -160,6 +161,7 @@ class StatisticManager {
} }
$statsArray[$key] = intval($hits[$key]) / (intval($time) / 3600); $statsArray[$key] = intval($hits[$key]) / (intval($time) / 3600);
} }
arsort($statsArray);
break; break;
case self::SPECIAL_STAT_ARROW_ACC: case self::SPECIAL_STAT_ARROW_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_ARROW_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_ARROW_HIT, $serverIndex);
@ -170,6 +172,7 @@ class StatisticManager {
} }
$statsArray[$key] = intval($hits[$key]) / (intval($shot)); $statsArray[$key] = intval($hits[$key]) / (intval($shot));
} }
arsort($statsArray);
break; break;
case self::SPECIAL_STAT_LASER_ACC: case self::SPECIAL_STAT_LASER_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_LASER_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_LASER_HIT, $serverIndex);
@ -180,6 +183,7 @@ class StatisticManager {
} }
$statsArray[$key] = intval($hits[$key]) / (intval($shot)); $statsArray[$key] = intval($hits[$key]) / (intval($shot));
} }
arsort($statsArray);
break; break;
case self::SPECIAL_STAT_ROCKET_ACC: case self::SPECIAL_STAT_ROCKET_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_HIT, $serverIndex);
@ -190,6 +194,7 @@ class StatisticManager {
} }
$statsArray[$key] = intval($hits[$key]) / (intval($shot)); $statsArray[$key] = intval($hits[$key]) / (intval($shot));
} }
arsort($statsArray);
break; break;
case self::SPECIAL_STAT_NUCLEUS_ACC: case self::SPECIAL_STAT_NUCLEUS_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_HIT, $serverIndex);
@ -200,6 +205,7 @@ class StatisticManager {
} }
$statsArray[$key] = intval($hits[$key]) / (intval($shot)); $statsArray[$key] = intval($hits[$key]) / (intval($shot));
} }
arsort($statsArray);
break; break;
} }
return $statsArray; return $statsArray;