2014-01-19 00:09:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Statistics;
|
|
|
|
|
|
|
|
use FML\Controls\Frame;
|
|
|
|
use FML\Controls\Label;
|
2014-01-21 21:58:39 +01:00
|
|
|
use FML\Controls\Labels\Label_Text;
|
2014-01-19 00:09:15 +01:00
|
|
|
use FML\Controls\Quad;
|
|
|
|
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
|
|
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
|
|
|
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
|
|
|
use FML\ManiaLink;
|
2017-04-20 16:49:07 +02:00
|
|
|
use FML\Script\Features\Paging;
|
2014-01-21 21:58:39 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
2014-01-29 20:51:53 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2014-05-24 16:39:12 +02:00
|
|
|
use ManiaControl\Callbacks\Callbacks;
|
2014-01-31 15:16:26 +01:00
|
|
|
use ManiaControl\Commands\CommandListener;
|
2017-05-12 21:06:43 +02:00
|
|
|
use ManiaControl\Logger;
|
2014-01-19 00:09:15 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
2017-04-01 18:48:36 +02:00
|
|
|
use ManiaControl\Manialinks\LabelLine;
|
2014-01-19 00:09:15 +01:00
|
|
|
use ManiaControl\Manialinks\ManialinkManager;
|
|
|
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
|
|
|
use ManiaControl\Players\Player;
|
2014-01-21 21:58:39 +01:00
|
|
|
use ManiaControl\Players\PlayerManager;
|
2014-05-15 17:58:57 +02:00
|
|
|
use ManiaControl\Utils\Formatter;
|
2014-01-19 00:09:15 +01:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/**
|
|
|
|
* Simple Stats List Class
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2018-03-27 20:11:40 +02:00
|
|
|
* @copyright 2014-2018 ManiaControl Team
|
2014-05-02 17:50:30 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-04-12 12:14:37 +02:00
|
|
|
*/
|
2014-01-31 15:16:26 +01:00
|
|
|
class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener, CommandListener {
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-01-19 00:09:15 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
const ACTION_OPEN_STATSLIST = 'SimpleStatsList.OpenStatsList';
|
2014-01-31 15:41:01 +01:00
|
|
|
const ACTION_SORT_STATS = 'SimpleStatsList.SortStats';
|
2017-05-14 19:05:45 +02:00
|
|
|
const ACTION_PAGING_CHUNKS = 'SimpleStatsList.PagingChunk';
|
2017-04-20 16:49:07 +02:00
|
|
|
const MAX_PLAYERS_PER_PAGE = 15;
|
2017-05-15 19:31:24 +02:00
|
|
|
const MAX_PAGES_PER_CHUNK = 10;
|
2017-05-14 19:05:45 +02:00
|
|
|
const CACHE_CURRENT_PAGE = 'SimpleStatsList.CurrentPage';
|
|
|
|
|
2014-01-19 00:09:15 +01:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-08-02 22:31:46 +02:00
|
|
|
* Private properties
|
2014-01-19 00:09:15 +01:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2014-01-19 00:09:15 +01:00
|
|
|
private $maniaControl = null;
|
2017-04-01 18:48:36 +02:00
|
|
|
private $statArray = array();
|
|
|
|
private $statsWidth = 0;
|
2014-01-19 00:09:15 +01:00
|
|
|
|
|
|
|
/**
|
2014-08-03 01:34:18 +02:00
|
|
|
* Construct a new simple stats list instance
|
2014-01-19 00:09:15 +01:00
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Callbacks
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
|
2014-01-23 21:55:40 +01:00
|
|
|
}
|
2014-01-21 21:58:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the menu entry
|
|
|
|
*/
|
2014-02-19 15:44:00 +01:00
|
|
|
public function handleOnInit() {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCommandManager()->registerCommandListener('stats', $this, 'command_ShowStatsList', false, 'Shows statistics.');
|
2014-01-31 15:16:26 +01:00
|
|
|
|
2014-01-21 21:58:39 +01:00
|
|
|
// Action Open StatsList
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_OPEN_STATSLIST, $this, 'command_ShowStatsList');
|
2014-01-19 00:09:15 +01:00
|
|
|
|
|
|
|
$itemQuad = new Quad_UIConstruction_Buttons();
|
2014-01-21 21:58:39 +01:00
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Stats);
|
2014-01-19 00:09:15 +01:00
|
|
|
$itemQuad->setAction(self::ACTION_OPEN_STATSLIST);
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getActionsMenu()->addMenuItem($itemQuad, true, 14, 'Open Statistics');
|
2017-05-12 22:11:20 +02:00
|
|
|
//TODO Chunking
|
2017-05-14 19:05:45 +02:00
|
|
|
|
2014-01-31 15:16:26 +01:00
|
|
|
//TODO settings if a stat get shown
|
2014-01-23 21:55:40 +01:00
|
|
|
$this->registerStat(PlayerManager::STAT_SERVERTIME, 10, "ST", 20, StatisticManager::STAT_TYPE_TIME);
|
2017-05-12 22:11:20 +02:00
|
|
|
$this->registerStat(StatisticCollector::STAT_ARROW_HIT, 20, "H");
|
2014-01-23 21:55:40 +01:00
|
|
|
$this->registerStat(StatisticCollector::STAT_ON_NEARMISS, 30, "NM");
|
|
|
|
$this->registerStat(StatisticCollector::STAT_ON_KILL, 40, "K");
|
|
|
|
$this->registerStat(StatisticCollector::STAT_ON_DEATH, 50, "D");
|
|
|
|
$this->registerStat(StatisticCollector::STAT_ON_CAPTURE, 60, "C");
|
|
|
|
|
2014-02-06 21:18:25 +01:00
|
|
|
$this->registerStat(StatisticManager::SPECIAL_STAT_KD_RATIO, 70, "K/D", 12, StatisticManager::STAT_TYPE_FLOAT);
|
2014-05-20 14:59:17 +02:00
|
|
|
$this->registerStat(StatisticManager::SPECIAL_STAT_LASER_ACC, 80, "LAcc", 15, StatisticManager::STAT_TYPE_FLOAT);
|
2014-02-06 21:18:25 +01:00
|
|
|
$this->registerStat(StatisticManager::SPECIAL_STAT_HITS_PH, 85, "H/h", 15, StatisticManager::STAT_TYPE_FLOAT);
|
2014-01-19 00:09:15 +01:00
|
|
|
}
|
|
|
|
|
2014-02-06 22:51:32 +01:00
|
|
|
/**
|
|
|
|
* Register a Certain Stat
|
2014-02-13 20:48:25 +01:00
|
|
|
*
|
2014-05-20 14:59:17 +02:00
|
|
|
* @param string $statName
|
|
|
|
* @param int $order
|
|
|
|
* @param string $headShortCut
|
2014-02-06 22:51:32 +01:00
|
|
|
* @param int $width
|
|
|
|
* @param string $format
|
|
|
|
*/
|
2014-02-06 21:18:25 +01:00
|
|
|
public function registerStat($statName, $order, $headShortCut, $width = 10, $format = StatisticManager::STAT_TYPE_INT) {
|
2014-05-20 14:59:17 +02:00
|
|
|
// TODO: use own model class
|
2014-01-23 21:55:40 +01:00
|
|
|
$this->statArray[$order] = array();
|
|
|
|
$this->statArray[$order]["Name"] = $statName;
|
|
|
|
$this->statArray[$order]["HeadShortCut"] = '$o' . $headShortCut;
|
|
|
|
$this->statArray[$order]["Width"] = $width;
|
|
|
|
$this->statArray[$order]["Format"] = $format;
|
2017-04-01 18:48:36 +02:00
|
|
|
$this->statsWidth += $width;
|
2014-01-23 21:55:40 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
/**
|
|
|
|
* Show the stat List
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function command_ShowStatsList(array $callback, Player $player) {
|
|
|
|
$this->showStatsList($player);
|
|
|
|
}
|
2014-01-23 21:55:40 +01:00
|
|
|
|
2014-01-19 00:09:15 +01:00
|
|
|
/**
|
2014-05-02 16:13:45 +02:00
|
|
|
* Show the StatsList Widget to the Player
|
2014-01-19 00:09:15 +01:00
|
|
|
*
|
|
|
|
* @param Player $player
|
2014-05-02 16:13:45 +02:00
|
|
|
* @param string $order
|
2014-01-19 00:09:15 +01:00
|
|
|
*/
|
2017-05-14 19:05:45 +02:00
|
|
|
public function showStatsList(Player $player, $order = PlayerManager::STAT_SERVERTIME, $pageIndex = -1) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
|
|
|
|
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowSubStyle();
|
2017-05-15 19:31:24 +02:00
|
|
|
$limit = 2000;
|
2014-01-19 00:09:15 +01:00
|
|
|
|
2017-05-14 19:05:45 +02:00
|
|
|
if ($pageIndex < 0) {
|
|
|
|
$pageIndex = (int) $player->getCache($this, self::CACHE_CURRENT_PAGE);
|
|
|
|
}
|
2017-05-15 19:31:24 +02:00
|
|
|
|
2017-05-14 19:05:45 +02:00
|
|
|
$player->setCache($this, self::CACHE_CURRENT_PAGE, $pageIndex);
|
|
|
|
|
|
|
|
$totalPlayersCount = $this->maniaControl->getStatisticManager()->getTotalStatsPlayerCount(-1);
|
2017-05-15 19:31:24 +02:00
|
|
|
if ($totalPlayersCount > $limit) {
|
|
|
|
$totalPlayersCount = $limit;
|
|
|
|
}
|
2017-05-14 19:05:45 +02:00
|
|
|
|
2017-05-15 19:31:24 +02:00
|
|
|
$chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount);
|
|
|
|
$playerBeginIndex = $this->getChunkStatsBeginIndex($chunkIndex);
|
|
|
|
$pagesCount = ceil($totalPlayersCount / self::MAX_PLAYERS_PER_PAGE);
|
2014-01-21 21:58:39 +01:00
|
|
|
|
2014-01-19 00:09:15 +01:00
|
|
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
2014-01-29 20:51:53 +01:00
|
|
|
$width = $this->statsWidth + 60;
|
2014-02-02 19:59:42 +01:00
|
|
|
//TODO handle size when stats are empty
|
2014-01-19 00:09:15 +01:00
|
|
|
|
2017-04-20 16:49:07 +02:00
|
|
|
$script = $maniaLink->getScript();
|
|
|
|
$paging = new Paging();
|
|
|
|
$script->addFeature($paging);
|
2017-05-14 19:05:45 +02:00
|
|
|
$paging->setCustomMaxPageNumber($pagesCount);
|
|
|
|
$paging->setChunkActionAppendsPageNumber(true);
|
|
|
|
$paging->setChunkActions(self::ACTION_PAGING_CHUNKS);
|
|
|
|
$paging->setStartPageNumber($pageIndex + 1);
|
2017-04-20 16:49:07 +02:00
|
|
|
|
2014-01-19 00:09:15 +01:00
|
|
|
// Main frame
|
|
|
|
$frame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$maniaLink->addChild($frame);
|
2014-01-19 00:09:15 +01:00
|
|
|
$frame->setSize($width, $height);
|
2017-03-28 16:13:05 +02:00
|
|
|
$frame->setPosition(0, 0, ManialinkManager::MAIN_MANIALINK_Z_VALUE);
|
2014-01-19 00:09:15 +01:00
|
|
|
|
|
|
|
// Background
|
|
|
|
$backgroundQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($backgroundQuad);
|
2014-01-19 00:09:15 +01:00
|
|
|
$backgroundQuad->setSize($width, $height);
|
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
|
|
|
|
|
|
|
// Close Quad (X)
|
|
|
|
$closeQuad = new Quad_Icons64x64_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($closeQuad);
|
2014-01-19 00:09:15 +01:00
|
|
|
$closeQuad->setPosition($width * 0.483, $height * 0.467, 3);
|
|
|
|
$closeQuad->setSize(6, 6);
|
|
|
|
$closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace);
|
|
|
|
$closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
|
|
|
|
|
|
|
|
// Start offsets
|
2014-01-21 21:58:39 +01:00
|
|
|
$xStart = -$width / 2;
|
2014-06-14 14:32:29 +02:00
|
|
|
$posY = $height / 2;
|
2014-01-19 00:09:15 +01:00
|
|
|
|
|
|
|
// Predefine Description Label
|
2017-04-01 18:48:36 +02:00
|
|
|
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($descriptionLabel);
|
2014-01-19 00:09:15 +01:00
|
|
|
|
|
|
|
// Headline
|
|
|
|
$headFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($headFrame);
|
2014-06-14 14:32:29 +02:00
|
|
|
$headFrame->setY($posY - 5);
|
2017-03-28 16:13:05 +02:00
|
|
|
$headFrame->setZ(1);
|
2014-01-19 00:09:15 +01:00
|
|
|
|
2017-04-01 18:48:36 +02:00
|
|
|
$labelLine = new LabelLine($headFrame);
|
|
|
|
|
|
|
|
$posX = $xStart;
|
|
|
|
$labelLine->addLabelEntryText('Id', $posX + 5);
|
|
|
|
$labelLine->addLabelEntryText('Nickname', $posX + 14);
|
2014-01-21 21:58:39 +01:00
|
|
|
|
2014-07-26 16:31:47 +02:00
|
|
|
// Headline
|
2014-06-14 14:32:29 +02:00
|
|
|
$posX = $xStart + 55;
|
2014-01-23 21:55:40 +01:00
|
|
|
$statRankings = array();
|
2017-05-12 21:06:43 +02:00
|
|
|
|
2017-05-14 19:05:45 +02:00
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
foreach ($this->statArray as $key => $stat) {
|
2017-05-15 19:31:24 +02:00
|
|
|
$ranking = $this->maniaControl->getStatisticManager()->getStatsRanking($stat["Name"], -1, -1, $limit);
|
2014-01-31 15:16:26 +01:00
|
|
|
if (!empty($ranking)) {
|
2017-04-01 18:48:36 +02:00
|
|
|
$statRankings[$stat["Name"]] = $ranking;
|
|
|
|
|
|
|
|
$label = new Label_Text();
|
|
|
|
$label->setText($stat['HeadShortCut']);
|
|
|
|
$label->setX($posX);
|
|
|
|
$label->setSize($stat['Width'], 0);
|
|
|
|
$label->setAction(self::ACTION_SORT_STATS . '.' . $stat["Name"]);
|
|
|
|
$label->addTooltipLabelFeature($descriptionLabel, '$o ' . $stat["Name"]);
|
|
|
|
$labelLine->addLabel($label);
|
|
|
|
|
2014-06-14 14:32:29 +02:00
|
|
|
$posX += $stat["Width"];
|
2014-02-13 20:48:25 +01:00
|
|
|
} else {
|
2014-02-02 19:59:42 +01:00
|
|
|
unset($this->statArray[$key]);
|
2014-01-31 15:16:26 +01:00
|
|
|
}
|
2014-01-23 21:55:40 +01:00
|
|
|
}
|
2017-04-01 18:48:36 +02:00
|
|
|
$labelLine->render();
|
2014-01-23 21:55:40 +01:00
|
|
|
|
2014-01-29 20:51:53 +01:00
|
|
|
|
2014-01-21 21:58:39 +01:00
|
|
|
// define standard properties
|
2017-05-14 19:05:45 +02:00
|
|
|
$index = 1;
|
|
|
|
$posY -= 10;
|
|
|
|
$pageFrame = null;
|
|
|
|
$playerIndex = 1 + $playerBeginIndex;
|
2014-01-29 20:51:53 +01:00
|
|
|
|
2014-02-13 20:48:25 +01:00
|
|
|
if (!isset($statRankings[$order])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-14 19:05:45 +02:00
|
|
|
//Slice Array to chunk length
|
|
|
|
$statRankings[$order] = array_slice($statRankings{$order}, $playerBeginIndex, self::MAX_PAGES_PER_CHUNK * self::MAX_PLAYERS_PER_PAGE, true);
|
|
|
|
$pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK;
|
2014-05-02 17:50:30 +02:00
|
|
|
foreach ($statRankings[$order] as $playerId => $value) {
|
2017-04-20 16:49:07 +02:00
|
|
|
if ($index % self::MAX_PLAYERS_PER_PAGE === 1) {
|
|
|
|
$pageFrame = new Frame();
|
|
|
|
$frame->addChild($pageFrame);
|
|
|
|
$pageFrame->setZ(1);
|
|
|
|
|
2017-05-14 19:05:45 +02:00
|
|
|
$paging->addPageControl($pageFrame, $pageNumber);
|
|
|
|
$pageNumber++;
|
2017-04-20 16:49:07 +02:00
|
|
|
$posY = $height / 2 - 10;
|
|
|
|
}
|
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$listPlayer = $this->maniaControl->getPlayerManager()->getPlayerByIndex($playerId);
|
2014-05-15 17:58:57 +02:00
|
|
|
if (!$listPlayer) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-23 21:55:40 +01:00
|
|
|
|
2014-01-19 00:09:15 +01:00
|
|
|
$playerFrame = new Frame();
|
2017-04-20 16:49:07 +02:00
|
|
|
$pageFrame->addChild($playerFrame);
|
2014-01-19 00:09:15 +01:00
|
|
|
|
2014-07-26 16:31:47 +02:00
|
|
|
// Show current Player Arrow
|
2014-01-31 15:41:01 +01:00
|
|
|
if ($playerId == $player->index) {
|
|
|
|
$currentQuad = new Quad_Icons64x64_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$playerFrame->addChild($currentQuad);
|
2014-01-31 15:41:01 +01:00
|
|
|
$currentQuad->setX($xStart + 3.5);
|
|
|
|
$currentQuad->setSize(4, 4);
|
|
|
|
$currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue);
|
|
|
|
}
|
|
|
|
|
2017-04-01 18:48:36 +02:00
|
|
|
$labelLine = new LabelLine($playerFrame);
|
|
|
|
$posX = $xStart + 55;
|
2017-05-12 21:06:43 +02:00
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
foreach ($this->statArray as $stat) {
|
2014-01-23 21:55:40 +01:00
|
|
|
$statValue = 0;
|
2014-01-29 20:51:53 +01:00
|
|
|
if (isset($statRankings[$stat['Name']][$playerId])) {
|
2014-01-23 21:55:40 +01:00
|
|
|
$statValue = $statRankings[$stat['Name']][$playerId];
|
2014-01-29 20:51:53 +01:00
|
|
|
if ($stat['Format'] == StatisticManager::STAT_TYPE_TIME) {
|
2014-06-15 02:50:13 +02:00
|
|
|
$statValue = Formatter::formatTimeH($statValue);
|
2014-01-29 20:51:53 +01:00
|
|
|
} else if ($stat['Format'] == StatisticManager::STAT_TYPE_FLOAT) {
|
|
|
|
$statValue = round(floatval($statValue), 2);
|
2014-01-23 21:55:40 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-21 21:58:39 +01:00
|
|
|
|
|
|
|
$label = new Label_Text();
|
2014-06-14 14:32:29 +02:00
|
|
|
$label->setX($posX);
|
2017-04-01 18:48:36 +02:00
|
|
|
$label->setText(strval($statValue));
|
2017-05-12 21:06:43 +02:00
|
|
|
//$label->addTooltipLabelFeature($descriptionLabel, '$o ' . $stat['Name']);
|
2017-04-01 18:48:36 +02:00
|
|
|
$labelLine->addLabel($label);
|
|
|
|
|
|
|
|
$posX += $stat['Width'];
|
2017-05-12 21:06:43 +02:00
|
|
|
|
2014-01-21 21:58:39 +01:00
|
|
|
}
|
|
|
|
|
2017-05-14 19:05:45 +02:00
|
|
|
$labelLine->addLabelEntryText($playerIndex, $xStart + 5, 9);
|
2017-05-15 19:31:24 +02:00
|
|
|
$labelLine->addLabelEntryText($listPlayer->nickname, $xStart + 14, 41);
|
2017-04-01 18:48:36 +02:00
|
|
|
$labelLine->render();
|
|
|
|
|
2014-06-14 14:32:29 +02:00
|
|
|
$playerFrame->setY($posY);
|
2014-01-21 21:58:39 +01:00
|
|
|
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($index % 2 !== 0) {
|
2014-01-19 00:09:15 +01:00
|
|
|
$lineQuad = new Quad_BgsPlayerCard();
|
2017-03-25 19:15:50 +01:00
|
|
|
$playerFrame->addChild($lineQuad);
|
2014-01-19 00:09:15 +01:00
|
|
|
$lineQuad->setSize($width, 4);
|
|
|
|
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
|
2017-03-28 16:13:05 +02:00
|
|
|
$lineQuad->setZ(-0.5);
|
2014-01-19 00:09:15 +01:00
|
|
|
}
|
|
|
|
|
2014-06-14 14:32:29 +02:00
|
|
|
$index++;
|
2017-05-14 19:05:45 +02:00
|
|
|
$playerIndex++;
|
2014-06-14 14:32:29 +02:00
|
|
|
$posY -= 4;
|
2017-05-12 21:06:43 +02:00
|
|
|
|
2014-01-19 00:09:15 +01:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:49:07 +02:00
|
|
|
$pagerSize = 6.;
|
|
|
|
$pagerPrev = new Quad_Icons64x64_1();
|
|
|
|
$frame->addChild($pagerPrev);
|
|
|
|
$pagerPrev->setPosition($width * 0.42, $height * -0.44, 2)->setSize($pagerSize, $pagerSize)->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
|
|
|
|
|
|
|
|
$pagerNext = new Quad_Icons64x64_1();
|
|
|
|
$frame->addChild($pagerNext);
|
|
|
|
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2)->setSize($pagerSize, $pagerSize)->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
|
|
|
|
|
|
|
|
$pageCountLabel = new Label_Text();
|
|
|
|
$frame->addChild($pageCountLabel);
|
|
|
|
$pageCountLabel->setHorizontalAlign($pageCountLabel::RIGHT)->setPosition($width * 0.40, $height * -0.44, 1)->setStyle($pageCountLabel::STYLE_TextTitle1)->setTextSize(1.3);
|
|
|
|
|
|
|
|
$paging->addButtonControl($pagerNext)->addButtonControl($pagerPrev)->setLabel($pageCountLabel);
|
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'SimpleStatsList');
|
2014-01-19 00:09:15 +01:00
|
|
|
}
|
2014-01-31 15:41:01 +01:00
|
|
|
|
2017-05-14 19:05:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Chunk Index with the given Page Index
|
|
|
|
*
|
|
|
|
* @param int $pageIndex
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
private function getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount) {
|
|
|
|
$pagesCount = ceil($totalPlayersCount / self::MAX_PLAYERS_PER_PAGE);
|
|
|
|
if ($pageIndex > $pagesCount - 1) {
|
|
|
|
$pageIndex = $pagesCount - 1;
|
|
|
|
}
|
|
|
|
return floor($pageIndex / self::MAX_PAGES_PER_CHUNK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the First Player Index to show for the given Chunk
|
|
|
|
*
|
|
|
|
* @param int $chunkIndex
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
private function getChunkStatsBeginIndex($chunkIndex) {
|
|
|
|
return $chunkIndex * self::MAX_PAGES_PER_CHUNK * self::MAX_PLAYERS_PER_PAGE;
|
|
|
|
}
|
|
|
|
|
2014-01-31 15:41:01 +01:00
|
|
|
/**
|
|
|
|
* Called on ManialinkPageAnswer
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handleManialinkPageAnswer(array $callback) {
|
|
|
|
$actionId = $callback[1][2];
|
|
|
|
$actionArray = explode('.', $actionId, 3);
|
2017-05-14 19:05:45 +02:00
|
|
|
if (count($actionArray) < 2) {
|
2014-01-31 15:41:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-26 16:31:47 +02:00
|
|
|
$action = $actionArray[0] . '.' . $actionArray[1];
|
2014-01-31 15:41:01 +01:00
|
|
|
|
2017-05-14 19:05:45 +02:00
|
|
|
$playerLogin = $callback[1][1];
|
|
|
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($playerLogin);
|
2014-05-02 17:50:30 +02:00
|
|
|
switch ($action) {
|
2014-01-31 15:41:01 +01:00
|
|
|
case self::ACTION_SORT_STATS:
|
|
|
|
$this->showStatsList($player, $actionArray[2]);
|
2017-05-15 19:31:24 +02:00
|
|
|
$player->destroyCache($this, self::CACHE_CURRENT_PAGE);
|
|
|
|
break;
|
|
|
|
case ManialinkManager::ACTION_CLOSEWIDGET:
|
|
|
|
$player->destroyCache($this, self::CACHE_CURRENT_PAGE);
|
2014-01-31 15:41:01 +01:00
|
|
|
break;
|
2017-05-14 19:05:45 +02:00
|
|
|
default:
|
|
|
|
if (substr($actionId, 0, strlen(self::ACTION_PAGING_CHUNKS)) === self::ACTION_PAGING_CHUNKS) {
|
|
|
|
// Paging chunks
|
|
|
|
$neededPage = (int) substr($actionId, strlen(self::ACTION_PAGING_CHUNKS));
|
|
|
|
$this->showStatsList($player, PlayerManager::STAT_SERVERTIME, $neededPage - 1);
|
|
|
|
}
|
2014-01-31 15:41:01 +01:00
|
|
|
}
|
|
|
|
}
|
2014-07-26 16:31:47 +02:00
|
|
|
}
|