From cfc3694835c14a15d9db4dd86d625ab8c13335cb Mon Sep 17 00:00:00 2001 From: Jocy Date: Wed, 29 Mar 2017 22:25:50 +0200 Subject: [PATCH] Moved LabelLine to own class --- core/Manialinks/LabelLine.php | 145 +++++++++++++++++++++++++++ core/Manialinks/ManialinkManager.php | 48 +++------ 2 files changed, 160 insertions(+), 33 deletions(-) create mode 100644 core/Manialinks/LabelLine.php diff --git a/core/Manialinks/LabelLine.php b/core/Manialinks/LabelLine.php new file mode 100644 index 00000000..6e782420 --- /dev/null +++ b/core/Manialinks/LabelLine.php @@ -0,0 +1,145 @@ +frame = $frame; + } + + /** + * Create a new text label + * + * @param $labelText + * @param $posX + * @param int $width + */ + public function addLabelEntryText($labelText, $posX, $width = 0) { + $label = new Label_Text(); + $label->setText($labelText); + $label->setX($posX); + if ($width) { + $label->setWidth($width); + } + $this->addLabel($label); + } + + /** + * Adds a label to private attribute + * + * @param \FML\Controls\Labels\Label_Text $label + */ + private function addLabel(Label_Text $label) { + array_push($this->entries, $label); + } + + /** + * Adds the labels to your frame + */ + public function render() { + /** @var Label $entry */ + foreach ($this->entries as $entry) { + $entry->setHorizontalAlign($this->horizontalAlign); + $entry->setStyle($this->style); + $entry->setTextSize($this->textSize); + $entry->setTextColor($this->textColor); + $entry->setZ($this->posZ); + + $this->frame->addChild($entry); + } + } + + /** + * @return string + */ + public function getHorizontalAlign() { + return $this->horizontalAlign; + } + + /** + * @param string $horizontalAlign + */ + public function setHorizontalAlign($horizontalAlign) { + $this->horizontalAlign = $horizontalAlign; + } + + /** + * @return string + */ + public function getStyle() { + return $this->style; + } + + /** + * @param string $style + */ + public function setStyle($style) { + $this->style = $style; + } + + /** + * @return float + */ + public function getTextSize() { + return $this->textSize; + } + + /** + * @param float $textSize + */ + public function setTextSize($textSize) { + $this->textSize = $textSize; + } + + /** + * @return string + */ + public function getTextColor() { + return $this->textColor; + } + + /** + * @param string $textColor + */ + public function setTextColor($textColor) { + $this->textColor = $textColor; + } + /** + * @return int + */ + public function getPosZ() { + return $this->posZ; + } + + /** + * @param int $posZ + */ + public function setPosZ($posZ) { + $this->posZ = $posZ; + } + + /** + * @return \FML\Controls\Labels\Label_Text[] + */ + public function getEntries() { + return $this->entries; + } +} \ No newline at end of file diff --git a/core/Manialinks/ManialinkManager.php b/core/Manialinks/ManialinkManager.php index 6275c11a..9e2df899 100644 --- a/core/Manialinks/ManialinkManager.php +++ b/core/Manialinks/ManialinkManager.php @@ -376,10 +376,19 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener, $style = (isset($properties['style']) ? $properties['style'] : Label_Text::STYLE_TextCardSmall); $textSize = (isset($properties['textSize']) ? $properties['textSize'] : 1.5); $textColor = (isset($properties['textColor']) ? $properties['textColor'] : 'FFF'); - $profile = (isset($properties['profile']) ? $properties['profile'] : false); $posZ = (isset($properties['posZ']) ? $properties['posZ'] : 0); - $labels = array(); + $labelLine = new LabelLine($frame); + $labelLine->setHorizontalAlign($hAlign); + $labelLine->setStyle($style); + $labelLine->setTextSize($textSize); + $labelLine->setTextColor($textColor); + $labelLine->setPosZ($posZ); + + /** + * @var Label_Text $prevLabel + */ + $prevLabel = null; //If you call LabelLine with array(array(positions), array(texts)) if (count($labelStrings) == 2 && array_key_exists(0, $labelStrings) && array_key_exists(1, $labelStrings) && array_key_exists(0, $labelStrings[0]) && array_key_exists(0, $labelStrings[1])) { @@ -391,42 +400,15 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener, } foreach ($positions as $key => $x) { - $label = new Label_Text(); - $frame->addChild($label); - $label->setHorizontalAlign($hAlign); - $label->setX($x); - $label->setZ($posZ); - $label->setStyle($style); - $label->setTextSize($textSize); - $label->setText($texts[$key]); - $label->setTextColor($textColor); - - if ($profile) { - $label->addPlayerProfileFeature($profile); - } - - array_push($labels, $label); + $labelLine->addLabelEntryText($texts[$key], $x); } } else { foreach ($labelStrings as $text => $x) { - $label = new Label_Text(); - $frame->addChild($label); - $label->setHorizontalAlign($hAlign); - $label->setX($x); - $label->setZ($posZ); - $label->setStyle($style); - $label->setTextSize($textSize); - $label->setText($text); - $label->setTextColor($textColor); - - if ($profile) { - $label->addPlayerProfileFeature($profile); - } - - array_push($labels, $label); + $labelLine->addLabelEntryText($text,$x); } } + $labelLine->render(); - return $labels; + return $labelLine->getEntries(); } }