MapList now show local record if plugin is activated (#191)

This commit is contained in:
agiorla 2018-07-11 11:29:39 -04:00 committed by Lukas Kremsmayr
parent f6d48341f4
commit 2177858368

View File

@ -31,6 +31,7 @@ use Maniaplanet\DedicatedServer\Xmlrpc\NextMapException;
use Maniaplanet\DedicatedServer\Xmlrpc\NotInListException; use Maniaplanet\DedicatedServer\Xmlrpc\NotInListException;
use MCTeam\CustomVotesPlugin; use MCTeam\CustomVotesPlugin;
use MCTeam\KarmaPlugin; use MCTeam\KarmaPlugin;
use MCTeam\LocalRecordsPlugin;
/** /**
* MapList Widget Class * MapList Widget Class
@ -59,6 +60,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
const MAX_PAGES_PER_CHUNK = 2; const MAX_PAGES_PER_CHUNK = 2;
const DEFAULT_KARMA_PLUGIN = 'MCTeam\KarmaPlugin'; const DEFAULT_KARMA_PLUGIN = 'MCTeam\KarmaPlugin';
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin'; const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
const DEFAULT_LOCAL_RECORDS_PLUGIN = 'MCTeam\LocalRecordsPlugin';
const CACHE_CURRENT_PAGE = 'CurrentPage'; const CACHE_CURRENT_PAGE = 'CurrentPage';
const WIDGET_NAME = 'MapList'; const WIDGET_NAME = 'MapList';
@ -232,11 +234,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$headFrame->setY($height / 2 - 5); $headFrame->setY($height / 2 - 5);
$posX = -$width / 2; $posX = -$width / 2;
$localRecordsPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_LOCAL_RECORDS_PLUGIN);
$labelLine = new LabelLine($headFrame); $labelLine = new LabelLine($headFrame);
$labelLine->addLabelEntryText('Id', $posX + 5); $labelLine->addLabelEntryText('Id', $posX + 5);
$labelLine->addLabelEntryText('Mx Id', $posX + 10); $labelLine->addLabelEntryText('Mx Id', $posX + 10);
$labelLine->addLabelEntryText('Map Name', $posX + 20); if ($localRecordsPlugin) {
$labelLine->addLabelEntryText('Author', $posX + 68); $labelLine->addLabelEntryText('Rank', $posX + 20);
}
$labelLine->addLabelEntryText('Map Name', $posX + 30);
$labelLine->addLabelEntryText('Author', $posX + 78);
$labelLine->addLabelEntryText('Actions', $width / 2 - 16); $labelLine->addLabelEntryText('Actions', $width / 2 - 16);
$labelLine->setY(-7); $labelLine->setY(-7);
$labelLine->render(); $labelLine->render();
@ -252,6 +259,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/** @var KarmaPlugin $karmaPlugin */ /** @var KarmaPlugin $karmaPlugin */
$karmaPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_KARMA_PLUGIN); $karmaPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_KARMA_PLUGIN);
$pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK; $pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK;
$paging->setStartPageNumber($pageIndex + 1); $paging->setStartPageNumber($pageIndex + 1);
@ -337,12 +345,24 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$labelLine = new LabelLine($mapFrame); $labelLine = new LabelLine($mapFrame);
$labelLine->addLabelEntryText($mapListId, $posX + 5, 5); $labelLine->addLabelEntryText($mapListId, $posX + 5, 5);
$labelLine->addLabelEntryText($mxId, $posX + 10, 10); $labelLine->addLabelEntryText($mxId, $posX + 10, 10);
$labelLine->addLabelEntryText(Formatter::stripDirtyCodes($map->name), $posX + 20, 42);
// Map rank
if ($localRecordsPlugin) {
$record = $localRecordsPlugin->getLocalRecord($map, $player);
$playerCurrentRank = '-';
if ($record) {
$playerCurrentRank = strval($record->rank);
}
$labelLine->addLabelEntryText($playerCurrentRank, $posX + 22, 22);
}
// Map Name
$labelLine->addLabelEntryText(Formatter::stripDirtyCodes($map->name), $posX + 30, 42);
$label = new Label_Text(); $label = new Label_Text();
$mapFrame->addChild($label); $mapFrame->addChild($label);
$label->setText($map->authorNick); $label->setText($map->authorNick);
$label->setX($posX + 68); $label->setX($posX + 78);
$label->setSize(47, 0); $label->setSize(47, 0);
$label->setAction(MapCommands::ACTION_SHOW_AUTHOR . $map->authorLogin); $label->setAction(MapCommands::ACTION_SHOW_AUTHOR . $map->authorLogin);
$description = 'Click to checkout all maps by $<' . $map->authorLogin . '$>!'; $description = 'Click to checkout all maps by $<' . $map->authorLogin . '$>!';