From 6a703f7311eb1ce926cec77917be77981993a832 Mon Sep 17 00:00:00 2001 From: Jocy Date: Wed, 29 Mar 2017 23:26:03 +0200 Subject: [PATCH] Updated MXlist with new Labelline --- core/ManiaExchange/ManiaExchangeList.php | 29 ++++++++++++++---- core/Manialinks/LabelLine.php | 39 +++++++++++++++++++++--- core/Manialinks/ManialinkManager.php | 2 ++ 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/core/ManiaExchange/ManiaExchangeList.php b/core/ManiaExchange/ManiaExchangeList.php index 47051b3c..d242c17b 100644 --- a/core/ManiaExchange/ManiaExchangeList.php +++ b/core/ManiaExchange/ManiaExchangeList.php @@ -18,6 +18,7 @@ use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\IconManager; +use ManiaControl\Manialinks\LabelLine; use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Maps\MapCommands; @@ -201,6 +202,17 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener '$oLast Update' => $posX + 130); $this->maniaControl->getManialinkManager()->labelLine($headFrame, $array); + $labelLine = new LabelLine($headFrame); + $labelLine->addLabelEntryText('Id', $posX + 3.5, 9); + $labelLine->addLabelEntryText('Name', $posX + 12.5, 38.5); + $labelLine->addLabelEntryText('Author', $posX + 59, 44); + $labelLine->addLabelEntryText('Type', $posX + 103, 15); + $labelLine->addLabelEntryText('Mood', $posX + 118, 12); + $labelLine->addLabelEntryText('Last Update', $posX + 130, $width - ($posX + 130)); + + $labelLine->setPrefix('$o'); + $labelLine->render(); + $index = 0; $posY = $height / 2 - 16; $pageFrame = null; @@ -226,12 +238,17 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener $lineQuad->setZ(0.001); } - $time = Formatter::timeElapsedString(strtotime($map->updated)); - $array = array('$s' . $map->id => $posX + 3.5, '$s' . $map->name => $posX + 12.5, '$s' . $map->author => $posX + 59, '$s' . str_replace('Arena', '', $map->maptype) => $posX + 103, - '$s' . $map->mood => $posX + 118, '$s' . $time => $posX + 130); - $labels = $this->maniaControl->getManialinkManager()->labelLine($mapFrame, $array); - $authorLabel = $labels[2]; - $authorLabel->setAction(self::ACTION_GET_MAPS_FROM_AUTHOR . '.' . $map->author); + $time = Formatter::timeElapsedString(strtotime($map->updated)); + $labelLine = new LabelLine($mapFrame); + $labelLine->addLabelEntryText($map->id, $posX + 3.5, 9); + $labelLine->addLabelEntryText($map->name, $posX + 12.5, 38.5); + $labelLine->addLabelEntryText($map->author, $posX + 59, 44, self::ACTION_GET_MAPS_FROM_AUTHOR . '.' . $map->author); + $labelLine->addLabelEntryText(str_replace('Arena', '', $map->maptype), $posX + 103, 15); + $labelLine->addLabelEntryText($map->mood, $posX + 118, 12); + $labelLine->addLabelEntryText($time, $posX + 130, $width - ($posX + 130)); + + $labelLine->setPrefix('$s'); + $labelLine->render(); $mapFrame->setY($posY); diff --git a/core/Manialinks/LabelLine.php b/core/Manialinks/LabelLine.php index 6e782420..b894818f 100644 --- a/core/Manialinks/LabelLine.php +++ b/core/Manialinks/LabelLine.php @@ -8,6 +8,13 @@ use FML\Controls\Labels\Label_Text; use ManiaControl\General\UsageInformationAble; use ManiaControl\General\UsageInformationTrait; +/** + * Class providing easy labels in a line + * + * @author ManiaControl Team + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ class LabelLine implements UsageInformationAble { use UsageInformationTrait; @@ -19,23 +26,30 @@ class LabelLine implements UsageInformationAble { private $textSize = 1.5; private $textColor = 'FFF'; private $posZ = 0; + private $prefix = ''; public function __construct(Frame $frame) { $this->frame = $frame; } + /** * Create a new text label * - * @param $labelText - * @param $posX - * @param int $width + * @param $labelText + * @param $posX + * @param int $width + * @param string $action */ - public function addLabelEntryText($labelText, $posX, $width = 0) { + public function addLabelEntryText($labelText, $posX, $width = 0, $action = '') { $label = new Label_Text(); + $this->frame->addChild($label); $label->setText($labelText); $label->setX($posX); + if ($action) { + $label->setAction($action); + } if ($width) { $label->setWidth($width); } @@ -54,6 +68,7 @@ class LabelLine implements UsageInformationAble { /** * Adds the labels to your frame */ + public function render() { /** @var Label $entry */ foreach ($this->entries as $entry) { @@ -62,6 +77,7 @@ class LabelLine implements UsageInformationAble { $entry->setTextSize($this->textSize); $entry->setTextColor($this->textColor); $entry->setZ($this->posZ); + $entry->setTextPrefix($this->prefix); $this->frame->addChild($entry); } @@ -122,6 +138,7 @@ class LabelLine implements UsageInformationAble { public function setTextColor($textColor) { $this->textColor = $textColor; } + /** * @return int */ @@ -142,4 +159,18 @@ class LabelLine implements UsageInformationAble { public function getEntries() { return $this->entries; } + + /** + * @return string + */ + public function getPrefix() { + return $this->prefix; + } + + /** + * @param string $prefix + */ + public function setPrefix($prefix) { + $this->prefix = $prefix; + } } \ No newline at end of file diff --git a/core/Manialinks/ManialinkManager.php b/core/Manialinks/ManialinkManager.php index 9e2df899..9ce12b8a 100644 --- a/core/Manialinks/ManialinkManager.php +++ b/core/Manialinks/ManialinkManager.php @@ -369,6 +369,8 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener, * @param array $labelStrings * @param array $properties * @return Label_Text[] + * @deprecated use \ManiaControl\Manialinks\LabelLine instead + * @see \ManiaControl\Manialinks\LabelLine */ public function labelLine(Frame $frame, array $labelStrings, array $properties = array()) { // define standard properties