FML Update

This commit is contained in:
Steffen Schröder 2014-01-03 17:18:14 +01:00
parent ad1455bf5a
commit 985feb398e
8 changed files with 1057 additions and 862 deletions

View File

@ -1,287 +1,287 @@
<?php <?php
namespace FML\Controls; namespace FML\Controls;
use FML\Types\Renderable; use FML\Types\Renderable;
/** /**
* Class representing CMlControl * Class representing CMlControl
* *
* @author steeffeen * @author steeffeen
*/ */
abstract class Control implements Renderable { abstract class Control implements Renderable {
/** /**
* Constants * Constants
*/ */
const CENTER = 'center'; const CENTER = 'center';
const CENTER2 = 'center2'; const CENTER2 = 'center2';
const TOP = 'top'; const TOP = 'top';
const RIGHT = 'right'; const RIGHT = 'right';
const BOTTOM = 'bottom'; const BOTTOM = 'bottom';
const LEFT = 'left'; const LEFT = 'left';
/** /**
* Protected Properties * Protected Properties
*/ */
protected $tagName = 'control'; protected $tagName = 'control';
protected $id = ''; protected $id = '';
protected $x = 0.; protected $x = 0.;
protected $y = 0.; protected $y = 0.;
protected $z = 0.; protected $z = 0.;
protected $width = -1.; protected $width = -1.;
protected $height = -1.; protected $height = -1.;
protected $hAlign = self::CENTER; protected $hAlign = self::CENTER;
protected $vAlign = self::CENTER2; protected $vAlign = self::CENTER2;
protected $scale = 1.; protected $scale = 1.;
protected $hidden = 0; protected $hidden = 0;
protected $classes = array(); protected $classes = array();
/** /**
* Construct a new Control * Construct a new Control
* *
* @param string $id Control Id * @param string $id Control Id
*/ */
public function __construct($id = null) { public function __construct($id = null) {
if ($id !== null) { if ($id !== null) {
$this->setId($id); $this->setId($id);
} }
} }
/** /**
* Get Control Id * Get Control Id
* *
* @return string * @return string
*/ */
public function getId() { public function getId() {
return $this->id; return $this->id;
} }
/** /**
* Set Control Id * Set Control Id
* *
* @param string $id Control Id * @param string $id Control Id
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setId($id) { public function setId($id) {
$this->id = $id; $this->id = $id;
return $this; return $this;
} }
/** /**
* Check Id for dangerous Characters and assign an unique Id if necessary * Check Id for dangerous Characters and assign an unique Id if necessary
* *
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function checkId() { public function checkId() {
if (!$this->getId()) { if (!$this->getId()) {
$this->setId(uniqid()); $this->setId(uniqid());
return $this; return $this;
} }
$dangerousCharacters = array(' ', ' ', '.', '|', '-', PHP_EOL); $dangerousCharacters = array(' ', ' ', '.', '|', '-', PHP_EOL);
$idCharacters = str_split($this->getId()); $idCharacters = str_split($this->getId());
$danger = false; $danger = false;
foreach ($idCharacters as $character) { foreach ($idCharacters as $character) {
if (!in_array($character, $dangerousCharacters)) continue; if (!in_array($character, $dangerousCharacters)) continue;
$danger = true; $danger = true;
break; break;
} }
if ($danger) { if ($danger) {
trigger_error("Please don't use special Characters in Ids, they might cause Problems! (I stripped them for You.)"); trigger_error("Please don't use special Characters in Ids, they might cause Problems! (I stripped them for You.)");
$id = str_ireplace($dangerousCharacters, '', $this->getId()); $id = str_ireplace($dangerousCharacters, '', $this->getId());
$this->setId($id); $this->setId($id);
} }
return $this; return $this;
} }
/** /**
* Set X Position * Set X Position
* *
* @param float $x Horizontal Position * @param float $x Horizontal Position
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setX($x) { public function setX($x) {
$this->x = $x; $this->x = $x;
return $this; return $this;
} }
/** /**
* Set Y Position * Set Y Position
* *
* @param float $y Vertical Position * @param float $y Vertical Position
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setY($y) { public function setY($y) {
$this->y = $y; $this->y = $y;
return $this; return $this;
} }
/** /**
* Set Z Position * Set Z Position
* *
* @param float $z Depth * @param float $z Depth
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setZ($z) { public function setZ($z) {
$this->z = $z; $this->z = $z;
return $this; return $this;
} }
/** /**
* Set Control Position * Set Control Position
* *
* @param float $x Horizontal Position * @param float $x Horizontal Position
* @param float $y Vertical Position * @param float $y Vertical Position
* @param float $z Depth * @param float $z Depth
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setPosition($x, $y, $z = null) { public function setPosition($x, $y, $z = null) {
$this->setX($x); $this->setX($x);
$this->setY($y); $this->setY($y);
if ($z !== null) { if ($z !== null) {
$this->setZ($z); $this->setZ($z);
} }
return $this; return $this;
} }
/** /**
* Set Control Width * Set Control Width
* *
* @param float $width Control Width * @param float $width Control Width
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setWidth($width) { public function setWidth($width) {
$this->width = $width; $this->width = $width;
return $this; return $this;
} }
/** /**
* Set Control Height * Set Control Height
* *
* @param float $height Control Height * @param float $height Control Height
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setHeight($height) { public function setHeight($height) {
$this->height = $height; $this->height = $height;
return $this; return $this;
} }
/** /**
* Set Control Size * Set Control Size
* *
* @param float $width Control Width * @param float $width Control Width
* @param float $height Control Height * @param float $height Control Height
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setSize($width, $height) { public function setSize($width, $height) {
$this->setWidth($width); $this->setWidth($width);
$this->setHeight($height); $this->setHeight($height);
return $this; return $this;
} }
/** /**
* Set Horizontal Alignment * Set Horizontal Alignment
* *
* @param string $hAlign Horizontal Alignment * @param string $hAlign Horizontal Alignment
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setHAlign($hAlign) { public function setHAlign($hAlign) {
$this->hAlign = $hAlign; $this->hAlign = $hAlign;
return $this; return $this;
} }
/** /**
* Set Vertical Alignment * Set Vertical Alignment
* *
* @param string $vAlign Vertical Alignment * @param string $vAlign Vertical Alignment
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setVAlign($vAlign) { public function setVAlign($vAlign) {
$this->vAlign = $vAlign; $this->vAlign = $vAlign;
return $this; return $this;
} }
/** /**
* Set Horizontal and Vertical Alignment * Set Horizontal and Vertical Alignment
* *
* @param string $hAlign Horizontal Alignment * @param string $hAlign Horizontal Alignment
* @param string $vAlign Vertical Alignment * @param string $vAlign Vertical Alignment
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setAlign($hAlign, $vAlign) { public function setAlign($hAlign, $vAlign) {
$this->setHAlign($hAlign); $this->setHAlign($hAlign);
$this->setVAlign($vAlign); $this->setVAlign($vAlign);
return $this; return $this;
} }
/** /**
* Set Control Scale * Set Control Scale
* *
* @param float $scale Control Scale * @param float $scale Control Scale
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setScale($scale) { public function setScale($scale) {
$this->scale = $scale; $this->scale = $scale;
return $this; return $this;
} }
/** /**
* Set Visibility * Set Visibility
* *
* @param bool $visible If Control should be visible * @param bool $visible If Control should be visible
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setVisible($visible) { public function setVisible($visible) {
$this->hidden = ($visible ? 0 : 1); $this->hidden = ($visible ? 0 : 1);
return $this; return $this;
} }
/** /**
* Add new Class Name * Add new Class Name
* *
* @param string $class Class Name * @param string $class Class Name
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function addClass($class) { public function addClass($class) {
if (!in_array($class, $this->classes)) { if (!in_array($class, $this->classes)) {
array_push($this->classes, $class); array_push($this->classes, $class);
} }
return $this; return $this;
} }
/** /**
* *
* @see \FML\Types\Renderable::render() * @see \FML\Types\Renderable::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {
$xml = $domDocument->createElement($this->tagName); $xml = $domDocument->createElement($this->tagName);
if ($this->id) { if ($this->id) {
$xml->setAttribute('id', $this->id); $xml->setAttribute('id', $this->id);
} }
if ($this->x !== 0. || $this->y !== 0. || $this->z !== 0.) { if ($this->x !== 0. || $this->y !== 0. || $this->z !== 0.) {
$xml->setAttribute('posn', "{$this->x} {$this->y} {$this->z}"); $xml->setAttribute('posn', "{$this->x} {$this->y} {$this->z}");
} }
if ($this->width >= 0. || $this->height >= 0.) { if ($this->width >= 0. || $this->height >= 0.) {
$xml->setAttribute('sizen', "{$this->width} {$this->height}"); $xml->setAttribute('sizen', "{$this->width} {$this->height}");
} }
if ($this->hAlign) { if ($this->hAlign) {
$xml->setAttribute('halign', $this->hAlign); $xml->setAttribute('halign', $this->hAlign);
} }
if ($this->vAlign) { if ($this->vAlign) {
$xml->setAttribute('valign', $this->vAlign); $xml->setAttribute('valign', $this->vAlign);
} }
if ($this->scale !== 1.) { if ($this->scale !== 1.) {
$xml->setAttribute('scale', $this->scale); $xml->setAttribute('scale', $this->scale);
} }
if ($this->hidden) { if ($this->hidden) {
$xml->setAttribute('hidden', $this->hidden); $xml->setAttribute('hidden', $this->hidden);
} }
$classes = ''; $classes = '';
foreach ($this->classes as $class) { foreach ($this->classes as $class) {
$classes .= $class . ' '; $classes .= $class . ' ';
} }
if ($classes) { if ($classes) {
$xml->setAttribute('class', $classes); $xml->setAttribute('class', $classes);
} }
return $xml; return $xml;
} }
} }

View File

@ -62,7 +62,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script
* Set Text Prefix * Set Text Prefix
* *
* @param string $textPrefix * @param string $textPrefix
* Text Pefix * Text Prefix
* @return \FML\Controls\Label * @return \FML\Controls\Label
*/ */
public function setTextPrefix($textPrefix) { public function setTextPrefix($textPrefix) {

View File

@ -1,182 +1,182 @@
<?php <?php
namespace FML; namespace FML;
/** /**
* Class representing a Custom_UI * Class representing a Custom_UI
* *
* @author steeffeen * @author steeffeen
*/ */
class CustomUI { class CustomUI {
/** /**
* Protected Properties * Protected Properties
*/ */
protected $encoding = 'utf-8'; protected $encoding = 'utf-8';
protected $tagName = 'custom_ui'; protected $tagName = 'custom_ui';
protected $noticeVisible = null; protected $noticeVisible = null;
protected $challengeInfoVisible = null; protected $challengeInfoVisible = null;
protected $netInfosVisible = null; protected $netInfosVisible = null;
protected $chatVisible = null; protected $chatVisible = null;
protected $checkpointListVisible = null; protected $checkpointListVisible = null;
protected $roundScoresVisible = null; protected $roundScoresVisible = null;
protected $scoretableVisible = null; protected $scoretableVisible = null;
protected $globalVisible = null; protected $globalVisible = null;
/** /**
* Set XML Encoding * Set XML Encoding
* *
* @param string $encoding * @param string $encoding
* @return \FML\CustomUI * @return \FML\CustomUI
*/ */
public function setXMLEncoding($encoding) { public function setXMLEncoding($encoding) {
$this->encoding = $encoding; $this->encoding = $encoding;
return $this; return $this;
} }
/** /**
* Set Showing of Notices * Set Showing of Notices
* *
* @param bool $visible * @param bool $visible
* @return \FML\CustomUI * @return \FML\CustomUI
*/ */
public function setNoticeVisible($visible) { public function setNoticeVisible($visible) {
$this->noticeVisible = $visible; $this->noticeVisible = $visible;
return $this; return $this;
} }
/** /**
* Set Showing of the Challenge Info * Set Showing of the Challenge Info
* *
* @param bool $visible * @param bool $visible
* @return \FML\CustomUI * @return \FML\CustomUI
*/ */
public function setChallengeInfoVisible($visible) { public function setChallengeInfoVisible($visible) {
$this->challengeInfoVisible = $visible; $this->challengeInfoVisible = $visible;
return $this; return $this;
} }
/** /**
* Set Showing of the Net Infos * Set Showing of the Net Infos
* *
* @param bool $visible * @param bool $visible
* @return \FML\CustomUI * @return \FML\CustomUI
*/ */
public function setNetInfosVisible($visible) { public function setNetInfosVisible($visible) {
$this->netInfosVisible = $visible; $this->netInfosVisible = $visible;
return $this; return $this;
} }
/** /**
* Set Showing of the Chat * Set Showing of the Chat
* *
* @param bool $visible * @param bool $visible
* @return \FML\CustomUI * @return \FML\CustomUI
*/ */
public function setChatVisible($visible) { public function setChatVisible($visible) {
$this->chatVisible = $visible; $this->chatVisible = $visible;
return $this; return $this;
} }
/** /**
* Set Showing of the Checkpoint List * Set Showing of the Checkpoint List
* *
* @param bool $visible * @param bool $visible
* @return \FML\CustomUI * @return \FML\CustomUI
*/ */
public function setCheckpointListVisible($visible) { public function setCheckpointListVisible($visible) {
$this->checkpointListVisible = $visible; $this->checkpointListVisible = $visible;
return $this; return $this;
} }
/** /**
* Set Showing of Round Scores * Set Showing of Round Scores
* *
* @param bool $visible * @param bool $visible
* @return \FML\CustomUI * @return \FML\CustomUI
*/ */
public function setRoundScoresVisible($visible) { public function setRoundScoresVisible($visible) {
$this->roundScoresVisible = $visible; $this->roundScoresVisible = $visible;
return $this; return $this;
} }
/** /**
* Set Showing of the Scoretable * Set Showing of the Scoretable
* *
* @param bool $visible * @param bool $visible
* @return \FML\CustomUI * @return \FML\CustomUI
*/ */
public function setScoretableVisible($visible) { public function setScoretableVisible($visible) {
$this->scoretableVisible = $visible; $this->scoretableVisible = $visible;
return $this; return $this;
} }
/** /**
* Set Global Showing * Set Global Showing
* *
* @param bool $visible * @param bool $visible
* @return \FML\CustomUI * @return \FML\CustomUI
*/ */
public function setGlobalVisible($visible) { public function setGlobalVisible($visible) {
$this->globalVisible = $visible; $this->globalVisible = $visible;
return $this; return $this;
} }
/** /**
* Render the XML Document * Render the XML Document
* *
* @param \DOMDocument $domDocument * @param \DOMDocument $domDocument
* @return \DOMDocument * @return \DOMDocument
*/ */
public function render($domDocument = null) { public function render($domDocument = null) {
$isChild = false; $isChild = false;
if ($domDocument) { if ($domDocument) {
$isChild = true; $isChild = true;
} }
if (!$isChild) { if (!$isChild) {
$domDocument = new \DOMDocument('1.0', $this->encoding); $domDocument = new \DOMDocument('1.0', $this->encoding);
} }
$xmlElement = $domDocument->createElement($this->tagName); $xmlElement = $domDocument->createElement($this->tagName);
$domDocument->appendChild($xmlElement); $domDocument->appendChild($xmlElement);
$settings = $this->getSettings(); $settings = $this->getSettings();
foreach ($settings as $setting => $value) { foreach ($settings as $setting => $value) {
if ($value === null) continue; if ($value === null) continue;
$xmlSubElement = $domDocument->createElement($setting); $xmlSubElement = $domDocument->createElement($setting);
$xmlSubElement->setAttribute('visible', ($value ? 1 : 0)); $xmlSubElement->setAttribute('visible', ($value ? 1 : 0));
$xmlElement->appendChild($xmlSubElement); $xmlElement->appendChild($xmlSubElement);
} }
if ($isChild) { if ($isChild) {
return $xmlElement; return $xmlElement;
} }
return $domDocument; return $domDocument;
} }
/** /**
* Get String Representation * Get String Representation
* *
* @return string * @return string
*/ */
public function __toString() { public function __toString() {
$domDocument = $this->render(); $domDocument = $this->render();
$xmlText = $domDocument->saveXML(); $xmlText = $domDocument->saveXML();
return $xmlText; return $xmlText;
} }
/** /**
* Get associative Array of all CustomUI Settings * Get associative Array of all CustomUI Settings
* *
* @return array * @return array
*/ */
private function getSettings() { private function getSettings() {
$settings = array(); $settings = array();
$settings['challenge_info'] = $this->challengeInfoVisible; $settings['challenge_info'] = $this->challengeInfoVisible;
$settings['chat'] = $this->chatVisible; $settings['chat'] = $this->chatVisible;
$settings['checkpoint_list'] = $this->checkpointListVisible; $settings['checkpoint_list'] = $this->checkpointListVisible;
$settings['global'] = $this->globalVisible; $settings['global'] = $this->globalVisible;
$settings['net_infos'] = $this->netInfosVisible; $settings['net_infos'] = $this->netInfosVisible;
$settings['notice'] = $this->noticeVisible; $settings['notice'] = $this->noticeVisible;
$settings['round_scores'] = $this->roundScoresVisible; $settings['round_scores'] = $this->roundScoresVisible;
$settings['scoretable'] = $this->scoretableVisible; $settings['scoretable'] = $this->scoretableVisible;
return $settings; return $settings;
} }
} }

View File

@ -1,195 +1,195 @@
<?php <?php
namespace FML; namespace FML;
use FML\Types\Container; use FML\Types\Container;
use FML\Types\Renderable; use FML\Types\Renderable;
use FML\Script\Script; use FML\Script\Script;
/** /**
* Class representing a Manialink * Class representing a Manialink
* *
* @author steeffeen * @author steeffeen
*/ */
class ManiaLink implements Container { class ManiaLink implements Container {
/** /**
* Protected Properties * Protected Properties
*/ */
protected $encoding = 'utf-8'; protected $encoding = 'utf-8';
protected $tagName = 'manialink'; protected $tagName = 'manialink';
protected $id = ''; protected $id = '';
protected $version = 1; protected $version = 1;
protected $background = ''; protected $background = '';
protected $navigable3d = 0; protected $navigable3d = 0;
protected $timeout = 0; protected $timeout = 0;
protected $children = array(); protected $children = array();
protected $script = null; protected $script = null;
/** /**
* Construct a new Manialink * Construct a new Manialink
* *
* @param string $id * @param string $id
* Manialink Id * Manialink Id
*/ */
public function __construct($id = null) { public function __construct($id = null) {
if ($id !== null) { if ($id !== null) {
$this->setId($id); $this->setId($id);
} }
} }
/** /**
* Set XML Encoding * Set XML Encoding
* *
* @param string $encoding * @param string $encoding
* XML Encoding * XML Encoding
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
public function setXmlEncoding($encoding) { public function setXmlEncoding($encoding) {
$this->encoding = $encoding; $this->encoding = $encoding;
return $this; return $this;
} }
/** /**
* Set Manialink Id * Set Manialink Id
* *
* @param string $id * @param string $id
* Manialink Id * Manialink Id
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
public function setId($id) { public function setId($id) {
$this->id = $id; $this->id = $id;
return $this; return $this;
} }
/** /**
* Set Background * Set Background
* *
* @param string $background * @param string $background
* Background Value * Background Value
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
public function setBackground($background) { public function setBackground($background) {
$this->background = $background; $this->background = $background;
return $this; return $this;
} }
/** /**
* Set Navigable3d * Set Navigable3d
* *
* @param bool $navigable3d * @param bool $navigable3d
* If the manialink is 3d navigable * If the manialink is 3d navigable
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
public function setNavigable3d($navigable3d) { public function setNavigable3d($navigable3d) {
$this->navigable3d = ($navigable3d ? 1 : 0); $this->navigable3d = ($navigable3d ? 1 : 0);
return $this; return $this;
} }
/** /**
* Set Timeout * Set Timeout
* *
* @param int $timeout * @param int $timeout
* Timeout Duration * Timeout Duration
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
public function setTimeout($timeout) { public function setTimeout($timeout) {
$this->timeout = $timeout; $this->timeout = $timeout;
return $this; return $this;
} }
/** /**
* *
* @see \FML\Types\Container::add() * @see \FML\Types\Container::add()
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
public function add(Renderable $child) { public function add(Renderable $child) {
array_push($this->children, $child); array_push($this->children, $child);
return $this; return $this;
} }
/** /**
* *
* @see \FML\Types\Container::removeChildren() * @see \FML\Types\Container::removeChildren()
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
public function removeChildren() { public function removeChildren() {
$this->children = array(); $this->children = array();
return $this; return $this;
} }
/** /**
* Set the script object of the Manialink * Set the script object of the Manialink
* *
* @param Script $script * @param Script $script
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
public function setScript(Script $script) { public function setScript(Script $script) {
$this->script = $script; $this->script = $script;
return $this; return $this;
} }
/** /**
* Render the XML Document * Render the XML Document
* *
* @param bool $echo * @param bool $echo
* If the xml should be echoed and the content-type header should be set * If the xml should be echoed and the content-type header should be set
* @param \DOMDocument $domDocument * @param \DOMDocument $domDocument
* @return \DOMDocument * @return \DOMDocument
*/ */
public function render($echo = false, $domDocument = null) { public function render($echo = false, $domDocument = null) {
$isChild = false; $isChild = false;
if ($domDocument) { if ($domDocument) {
$isChild = true; $isChild = true;
} }
if (!$isChild) { if (!$isChild) {
$domDocument = new \DOMDocument('1.0', $this->encoding); $domDocument = new \DOMDocument('1.0', $this->encoding);
} }
$manialink = $domDocument->createElement($this->tagName); $manialink = $domDocument->createElement($this->tagName);
if (!$isChild) { if (!$isChild) {
$domDocument->appendChild($manialink); $domDocument->appendChild($manialink);
} }
if ($this->id) { if ($this->id) {
$manialink->setAttribute('id', $this->id); $manialink->setAttribute('id', $this->id);
} }
if ($this->version) { if ($this->version) {
$manialink->setAttribute('version', $this->version); $manialink->setAttribute('version', $this->version);
} }
if ($this->background) { if ($this->background) {
$manialink->setAttribute('background', $this->background); $manialink->setAttribute('background', $this->background);
} }
if ($this->navigable3d) { if ($this->navigable3d) {
$manialink->setAttribute('navigable3d', $this->navigable3d); $manialink->setAttribute('navigable3d', $this->navigable3d);
} }
if ($this->timeout) { if ($this->timeout) {
$timeoutXml = $domDocument->createElement('timeout', $this->timeout); $timeoutXml = $domDocument->createElement('timeout', $this->timeout);
$manialink->appendChild($timeoutXml); $manialink->appendChild($timeoutXml);
} }
foreach ($this->children as $child) { foreach ($this->children as $child) {
$childXml = $child->render($domDocument); $childXml = $child->render($domDocument);
$manialink->appendChild($childXml); $manialink->appendChild($childXml);
} }
if ($this->script) { if ($this->script) {
$scriptXml = $this->script->render($domDocument); $scriptXml = $this->script->render($domDocument);
$manialink->appendChild($scriptXml); $manialink->appendChild($scriptXml);
} }
if ($isChild) { if ($isChild) {
return $manialink; return $manialink;
} }
if ($echo) { if ($echo) {
header('Content-Type: application/xml'); header('Content-Type: application/xml');
echo $domDocument->saveXML(); echo $domDocument->saveXML();
} }
return $domDocument; return $domDocument;
} }
/** /**
* Get String Representation * Get String Representation
* *
* @return string * @return string
*/ */
public function __toString() { public function __toString() {
$domDocument = $this->render(); $domDocument = $this->render();
$xmlText = $domDocument->saveXML(); $xmlText = $domDocument->saveXML();
return $xmlText; return $xmlText;
} }
} }

View File

@ -14,12 +14,12 @@ class ManiaLinks {
protected $encoding = 'utf-8'; protected $encoding = 'utf-8';
protected $tagName = 'manialinks'; protected $tagName = 'manialinks';
protected $children = array(); protected $children = array();
protected $customUI = null;
/** /**
* Set XML Encoding * Set XML Encoding
* *
* @param string $encoding * @param string $encoding XML Encoding
* XML Encoding
* @return \FML\ManiaLinks * @return \FML\ManiaLinks
*/ */
public function setXmlEncoding($encoding) { public function setXmlEncoding($encoding) {
@ -30,8 +30,7 @@ class ManiaLinks {
/** /**
* Add a Child Manialink * Add a Child Manialink
* *
* @param ManiaLink $child * @param ManiaLink $child Child Manialink
* Child Manialink
* @return \FML\ManiaLinks * @return \FML\ManiaLinks
*/ */
public function add(ManiaLink $child) { public function add(ManiaLink $child) {
@ -51,11 +50,21 @@ class ManiaLinks {
return $this; return $this;
} }
/**
* Set the CustomUI
*
* @param CustomUI $customUI The CustomUI Object
* @return \FML\ManiaLinks
*/
public function setCustomUI(CustomUI $customUI) {
$this->customUI = $customUI;
return $this;
}
/** /**
* Render the XML Document * Render the XML Document
* *
* @param bool $echo * @param bool $echo If the XML should be echoed and the Content-Type Header should be set
* If the xml should be echoed and the content-type header should be set
* @return \DOMDocument * @return \DOMDocument
*/ */
public function render($echo = false) { public function render($echo = false) {
@ -66,6 +75,10 @@ class ManiaLinks {
$childXml = $child->render(false, $domDocument); $childXml = $child->render(false, $domDocument);
$manialinks->appendChild($childXml); $manialinks->appendChild($childXml);
} }
if ($this->customUI) {
$customUIXml = $this->customUI->render($domDocument);
$manialinks->appendChild($customUIXml);
}
if ($echo) { if ($echo) {
header('Content-Type: application/xml'); header('Content-Type: application/xml');
echo $domDocument->saveXML(); echo $domDocument->saveXML();

View File

@ -1,23 +1,23 @@
<?php <?php
namespace FML\Script; namespace FML\Script;
/** /**
* Builder Class offering Methods to build ManiaScript * Builder Class offering Methods to build ManiaScript
* *
* @author steeffeen * @author steeffeen
*/ */
abstract class Builder { abstract class Builder {
/** /**
* Build a Label Implementation Block * Build a Label Implementation Block
* *
* @param string $labelName * @param string $labelName
* @param string $implementationCode * @param string $implementationCode
* @return string * @return string
*/ */
public static function getLabelImplementationBlock($labelName, $implementationCode) { public static function getLabelImplementationBlock($labelName, $implementationCode) {
$labelText = PHP_EOL . "***{$labelName}***" . PHP_EOL . "***{$implementationCode}***" . PHP_EOL; $labelText = PHP_EOL . "***{$labelName}***" . PHP_EOL . "***{$implementationCode}***" . PHP_EOL;
return $labelText; return $labelText;
} }
} }

View File

@ -15,50 +15,84 @@ class Script {
/** /**
* Constants * Constants
*/ */
const CLASS_TOOLTIPS = "FML_Tooltips"; const CLASS_TOOLTIPS = 'FML_Tooltips';
const CLASS_MENU = "FML_Menu"; const CLASS_MENU = 'FML_Menu';
const CLASS_MENUBUTTON = "FML_MenuButton"; const CLASS_MENUBUTTON = 'FML_MenuButton';
const CLASS_PAGE = "FML_Page"; const CLASS_PAGE = 'FML_Page';
const CLASS_PAGER = "FML_Pager"; const CLASS_PAGER = 'FML_Pager';
const CLASS_PAGELABEL = "FML_PageLabel"; const CLASS_PAGELABEL = 'FML_PageLabel';
const CLASS_PROFILE = "FML_Profile"; const CLASS_PROFILE = 'FML_Profile';
const CLASS_MAPINFO = "FML_MapInfo"; const CLASS_MAPINFO = 'FML_MapInfo';
const LABEL_ONINIT = "OnInit"; const OPTION_TOOLTIP_ONCLICK = 'FML_Tooltip_OnClick';
const LABEL_LOOP = "Loop"; const OPTION_TOOLTIP_STAYONCLICK = 'FML_Tooltip_StayOnClick';
const LABEL_ENTRYSUBMIT = "EntrySubmit"; const OPTION_TOOLTIP_INVERT = 'FML_Tooltip_Invert';
const LABEL_KEYPRESS = "KeyPress"; const OPTION_TOOLTIP_TEXT = 'FML_Tooltip_Text';
const LABEL_MOUSECLICK = "MouseClick"; const LABEL_ONINIT = 'OnInit';
const LABEL_MOUSEOUT = "MouseOut"; const LABEL_LOOP = 'Loop';
const LABEL_MOUSEOVER = "MouseOver"; const LABEL_ENTRYSUBMIT = 'EntrySubmit';
const LABEL_KEYPRESS = 'KeyPress';
const LABEL_MOUSECLICK = 'MouseClick';
const LABEL_MOUSEOUT = 'MouseOut';
const LABEL_MOUSEOVER = 'MouseOver';
const CONSTANT_TOOLTIPTEXTS = 'C_FML_TooltipTexts';
const FUNCTION_SETTOOLTIPTEXT = 'FML_SetTooltipText';
/** /**
* Protected Properties * Protected Properties
*/ */
protected $tagName = 'script'; protected $tagName = 'script';
protected $includes = array(); protected $includes = array();
protected $constants = array();
protected $functions = array();
protected $tooltips = false; protected $tooltips = false;
protected $tooltipTexts = array();
protected $menus = false; protected $menus = false;
protected $pages = false; protected $pages = false;
protected $profile = false; protected $profile = false;
protected $mapInfo = false; protected $mapInfo = false;
/** /**
* Add an Include to the Script * Set an Include of the Script
* *
* @param string $namespace * @param string $namespace
* @param string $file * @param string $file
* @return \FML\Script\Script * @return \FML\Script\Script
*/ */
public function addInclude($namespace, $file) { public function setInclude($namespace, $file) {
$this->includes[$namespace] = $file; $this->includes[$namespace] = $file;
return $this; return $this;
} }
/**
* Set a Constant of the Script
*
* @param string $name
* @param string $value
* @return \FML\Script\Script
*/
public function setConstant($name, $value) {
$this->constants[$name] = $value;
return $this;
}
/**
* Set a Function of the Script
*
* @param string $name
* @param string $coding
* @return \FML\Script\Script
*/
public function setFunction($name, $coding) {
$this->functions[$name] = $coding;
return $this;
}
/** /**
* Add a Tooltip Behavior * Add a Tooltip Behavior
* *
* @param Control $hoverControl * @param Control $hoverControl The Control that shows the Tooltip
* @param Control $tooltipControl * @param Control $tooltipControl The Tooltip to display
* @param string $options,... (optional) Unlimited Number of Tooltip Options
* @return \FML\Script\Script * @return \FML\Script\Script
*/ */
public function addTooltip(Control $hoverControl, Control $tooltipControl) { public function addTooltip(Control $hoverControl, Control $tooltipControl) {
@ -68,9 +102,30 @@ class Script {
} }
$tooltipControl->checkId(); $tooltipControl->checkId();
$tooltipControl->setVisible(false); $tooltipControl->setVisible(false);
$hoverControl->checkId();
$hoverControl->setScriptEvents(true); $hoverControl->setScriptEvents(true);
$hoverControl->addClass(self::CLASS_TOOLTIPS); $hoverControl->addClass(self::CLASS_TOOLTIPS);
$hoverControl->addClass($tooltipControl->getId()); $hoverControl->addClass($tooltipControl->getId());
$options = $this->spliceParameters(func_get_args(), 2);
foreach ($options as $option => $value) {
if ($option == self::OPTION_TOOLTIP_TEXT) {
if (!($tooltipControl instanceof Label)) {
trigger_error('Label needed for Tooltip Text Option!');
continue;
}
$hoverId = $hoverControl->getId();
$tooltipId = $tooltipControl->getId();
if (!isset($this->tooltipTexts[$tooltipId])) {
$this->tooltipTexts[$tooltipId] = array();
}
$this->tooltipTexts[$tooltipId][$hoverId] = $value;
continue;
}
if ($option == self::OPTION_TOOLTIP_INVERT) {
$tooltipControl->setVisible(true);
}
$hoverControl->addClass($option);
}
$this->tooltips = true; $this->tooltips = true;
return $this; return $this;
} }
@ -78,9 +133,9 @@ class Script {
/** /**
* Add a Menu Behavior * Add a Menu Behavior
* *
* @param Control $clickControl * @param Control $clickControl
* @param Control $menuControl * @param Control $menuControl
* @param string $menuId * @param string $menuId
* @return \FML\Script\Script * @return \FML\Script\Script
*/ */
public function addMenu(Control $clickControl, Control $menuControl, $menuId = null) { public function addMenu(Control $clickControl, Control $menuControl, $menuId = null) {
@ -95,7 +150,7 @@ class Script {
$clickControl->setScriptEvents(true); $clickControl->setScriptEvents(true);
$clickControl->addClass(self::CLASS_MENUBUTTON); $clickControl->addClass(self::CLASS_MENUBUTTON);
$clickControl->addClass($menuId . '-' . $menuControl->getId()); $clickControl->addClass($menuId . '-' . $menuControl->getId());
$this->addInclude('TextLib', 'TextLib'); $this->setInclude('TextLib', 'TextLib');
$this->menus = true; $this->menus = true;
return $this; return $this;
} }
@ -103,9 +158,9 @@ class Script {
/** /**
* Add a Page for a Paging Behavior * Add a Page for a Paging Behavior
* *
* @param Control $pageControl * @param Control $pageControl
* @param int $pageNumber * @param int $pageNumber
* @param string $pagesId * @param string $pagesId
* @return \FML\Script\Script * @return \FML\Script\Script
*/ */
public function addPage(Control $pageControl, $pageNumber, $pagesId = null) { public function addPage(Control $pageControl, $pageNumber, $pagesId = null) {
@ -120,9 +175,9 @@ class Script {
/** /**
* Add a Pager Button for a Paging Behavior * Add a Pager Button for a Paging Behavior
* *
* @param Control $pagerControl * @param Control $pagerControl
* @param int $pagingAction * @param int $pagingAction
* @param string $pagesId * @param string $pagesId
* @return \FML\Script\Script * @return \FML\Script\Script
*/ */
public function addPager(Control $pagerControl, $pagingAction, $pagesId = null) { public function addPager(Control $pagerControl, $pagingAction, $pagesId = null) {
@ -136,7 +191,7 @@ class Script {
$pagerControl->addClass(self::CLASS_PAGER); $pagerControl->addClass(self::CLASS_PAGER);
$pagerControl->addClass(self::CLASS_PAGER . '-I' . $pagesId); $pagerControl->addClass(self::CLASS_PAGER . '-I' . $pagesId);
$pagerControl->addClass(self::CLASS_PAGER . '-A' . $pagingAction); $pagerControl->addClass(self::CLASS_PAGER . '-A' . $pagingAction);
$this->addInclude('TextLib', 'TextLib'); $this->setInclude('TextLib', 'TextLib');
$this->pages = true; $this->pages = true;
return $this; return $this;
} }
@ -144,8 +199,8 @@ class Script {
/** /**
* Add a Label that shows the current Page Number * Add a Label that shows the current Page Number
* *
* @param Label $pageLabel * @param Label $pageLabel
* @param string $pagesId * @param string $pagesId
* @return \FML\Script\Script * @return \FML\Script\Script
*/ */
public function addPageLabel(Label $pageLabel, $pagesId = null) { public function addPageLabel(Label $pageLabel, $pagesId = null) {
@ -158,8 +213,8 @@ class Script {
/** /**
* Add a Button Behavior that will open the Built-In Player Profile * Add a Button Behavior that will open the Built-In Player Profile
* *
* @param Control $profileControl * @param Control $profileControl
* @param string $playerLogin * @param string $playerLogin
* @return \FML\Script\Script * @return \FML\Script\Script
*/ */
public function addProfileButton(Control $profileControl, $playerLogin) { public function addProfileButton(Control $profileControl, $playerLogin) {
@ -172,7 +227,7 @@ class Script {
if ($playerLogin) { if ($playerLogin) {
$profileControl->addClass(self::CLASS_PROFILE . '-' . $playerLogin); $profileControl->addClass(self::CLASS_PROFILE . '-' . $playerLogin);
} }
$this->addInclude('TextLib', 'TextLib'); $this->setInclude('TextLib', 'TextLib');
$this->profile = true; $this->profile = true;
return $this; return $this;
} }
@ -180,7 +235,7 @@ class Script {
/** /**
* Add a Button Behavior that will open the Built-In Map Info * Add a Button Behavior that will open the Built-In Map Info
* *
* @param Control $mapInfoControl * @param Control $mapInfoControl
* @return \FML\Script\Script * @return \FML\Script\Script
*/ */
public function addMapInfoButton(Control $mapInfoControl) { public function addMapInfoButton(Control $mapInfoControl) {
@ -197,7 +252,7 @@ class Script {
/** /**
* Create the Script XML Tag * Create the Script XML Tag
* *
* @param \DOMDocument $domDocument * @param \DOMDocument $domDocument
* @return \DOMElement * @return \DOMElement
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {
@ -217,21 +272,13 @@ class Script {
$scriptText = ""; $scriptText = "";
$scriptText .= $this->getHeaderComment(); $scriptText .= $this->getHeaderComment();
$scriptText .= $this->getIncludes(); $scriptText .= $this->getIncludes();
if ($this->tooltips) { $scriptText .= $this->getConstants();
$scriptText .= $this->getTooltipLabels(); $scriptText .= $this->getFunctions();
} $scriptText .= $this->getTooltipLabels();
if ($this->menus) { $scriptText .= $this->getMenuLabels();
$scriptText .= $this->getMenuLabels(); $scriptText .= $this->getPagesLabels();
} $scriptText .= $this->getProfileLabels();
if ($this->pages) { $scriptText .= $this->getMapInfoLabels();
$scriptText .= $this->getPagesLabels();
}
if ($this->profile) {
$scriptText .= $this->getProfileLabels();
}
if ($this->mapInfo) {
$scriptText .= $this->getMapInfoLabels();
}
$scriptText .= $this->getMainFunction(); $scriptText .= $this->getMainFunction();
return $scriptText; return $scriptText;
} }
@ -259,30 +306,133 @@ class Script {
return $includesText; return $includesText;
} }
/**
* Get the Constants
*
* @return string
*/
private function getConstants() {
$this->buildTooltipConstants();
$constantsText = PHP_EOL;
foreach ($this->constants as $name => $value) {
$constantsText .= "#Const {$name} {$value}" . PHP_EOL;
}
return $constantsText;
}
/**
* Build the Constants needed for tooltips
*/
private function buildTooltipConstants() {
if (!$this->tooltips) return;
$constantText = "[";
$index = 0;
$count = count($this->tooltipTexts);
foreach ($this->tooltipTexts as $tooltipId => $tooltipTexts) {
$constantText .= "\"{$tooltipId}\" => [";
$subIndex = 0;
$subCount = count($tooltipTexts);
foreach ($tooltipTexts as $hoverId => $text) {
$constantText .= "\"{$hoverId}\" => \"{$text}\"";
if ($subIndex < $subCount - 1) $constantText .= ", ";
$subIndex++;
}
$constantText .= "]";
if ($index < $count - 1) $constantText .= ", ";
$index++;
}
$constantText .= "]";
$this->setConstant(self::CONSTANT_TOOLTIPTEXTS, $constantText);
}
/**
* Get the Functions
*
* @return string
*/
private function getFunctions() {
$this->buildTooltipFunctions();
$functionsText = PHP_EOL;
foreach ($this->functions as $name => $coding) {
$functionsText .= $coding;
}
return $functionsText;
}
/**
* Build the Functions needed for Tooltips
*/
private function buildTooltipFunctions() {
if (!$this->tooltips) return;
$setFunctionText = "
Void " . self::FUNCTION_SETTOOLTIPTEXT . "(CMlControl _TooltipControl, CMlControl _HoverControl) {
if (!_TooltipControl.Visible) return;
declare TooltipId = _TooltipControl.ControlId;
declare HoverId = _HoverControl.ControlId;
if (!" . self::CONSTANT_TOOLTIPTEXTS . ".existskey(TooltipId)) return;
if (!" . self::CONSTANT_TOOLTIPTEXTS . "[TooltipId].existskey(HoverId)) return;
declare Label = (_TooltipControl as CMlLabel);
Label.Value = " . self::CONSTANT_TOOLTIPTEXTS . "[TooltipId][HoverId];
}";
$this->setFunction(self::FUNCTION_SETTOOLTIPTEXT, $setFunctionText);
}
/** /**
* Get the Tooltip Labels * Get the Tooltip Labels
* *
* @return string * @return string
*/ */
private function getTooltipLabels() { private function getTooltipLabels() {
$mouseOverScript = " if (!$this->tooltips) return "";
if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) { $mouseOverScript = "
foreach (ControlClass in Event.Control.ControlClasses) { if (!Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) break;
declare TooltipControl <=> Page.GetFirstChild(ControlClass); if (Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_ONCLICK . "\")) break;
if (TooltipControl == Null) continue; declare Invert = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_INVERT . "\");
TooltipControl.Show(); foreach (ControlClass in Event.Control.ControlClasses) {
} declare TooltipControl <=> Page.GetFirstChild(ControlClass);
if (TooltipControl == Null) continue;
TooltipControl.Visible = !Invert;
" . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control);
}"; }";
$mouseOutScript = " $mouseOutScript = "
if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) { if (!Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) break;
foreach (ControlClass in Event.Control.ControlClasses) { declare FML_Clicked for Event.Control = False;
declare TooltipControl <=> Page.GetFirstChild(ControlClass); declare StayOnClick = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_STAYONCLICK . "\");
if (TooltipControl == Null) continue; if (StayOnClick && FML_Clicked) break;
TooltipControl.Hide(); declare Invert = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_INVERT . "\");
} foreach (ControlClass in Event.Control.ControlClasses) {
declare TooltipControl <=> Page.GetFirstChild(ControlClass);
if (TooltipControl == Null) continue;
TooltipControl.Visible = Invert;
" . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control);
}";
$mouseClickScript = "
if (!Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) break;
declare Show = False;
declare OnClick = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_ONCLICK . "\");
if (OnClick) {
Show = !Event.Control.Visible;
} else {
declare StayOnClick = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_STAYONCLICK . "\");
if (StayOnClick) {
declare FML_Clicked for Event.Control = False;
FML_Clicked = !FML_Clicked;
if (FML_Clicked) break;
Show = False;
} else {
break;
}
}
declare Invert = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_INVERT . "\");
foreach (ControlClass in Event.Control.ControlClasses) {
declare TooltipControl <=> Page.GetFirstChild(ControlClass);
if (TooltipControl == Null) continue;
TooltipControl.Visible = Show && !Invert;
" . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control);
}"; }";
$tooltipsLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSEOVER, $mouseOverScript); $tooltipsLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSEOVER, $mouseOverScript);
$tooltipsLabels .= Builder::getLabelImplementationBlock(self::LABEL_MOUSEOUT, $mouseOutScript); $tooltipsLabels .= Builder::getLabelImplementationBlock(self::LABEL_MOUSEOUT, $mouseOutScript);
$tooltipsLabels .= Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $mouseClickScript);
return $tooltipsLabels; return $tooltipsLabels;
} }
@ -292,26 +442,27 @@ if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) {
* @return string * @return string
*/ */
private function getMenuLabels() { private function getMenuLabels() {
$mouseClickScript = " if (!$this->menus) return "";
if (Event.Control.HasClass(\"" . self::CLASS_MENUBUTTON . "\")) { $mouseClickScript = "
declare Text MenuIdClass; if (Event.Control.HasClass(\"" . self::CLASS_MENUBUTTON . "\")) {
declare Text MenuControlId; declare Text MenuIdClass;
foreach (ControlClass in Event.Control.ControlClasses) { declare Text MenuControlId;
declare ClassParts = TextLib::Split(\"-\", ControlClass); foreach (ControlClass in Event.Control.ControlClasses) {
if (ClassParts.count <= 1) continue; declare ClassParts = TextLib::Split(\"-\", ControlClass);
MenuIdClass = ClassParts[0]; if (ClassParts.count <= 1) continue;
MenuControlId = ClassParts[1]; MenuIdClass = ClassParts[0];
break; MenuControlId = ClassParts[1];
} break;
Page.GetClassChildren(MenuIdClass, Page.MainFrame, True); }
foreach (MenuControl in Page.GetClassChildren_Result) { Page.GetClassChildren(MenuIdClass, Page.MainFrame, True);
if (!MenuControl.HasClass(\"" . self::CLASS_MENU . "\")) continue; foreach (MenuControl in Page.GetClassChildren_Result) {
if (MenuControlId != MenuControl.ControlId) { if (!MenuControl.HasClass(\"" . self::CLASS_MENU . "\")) continue;
MenuControl.Hide(); if (MenuControlId != MenuControl.ControlId) {
} else { MenuControl.Hide();
MenuControl.Show(); } else {
} MenuControl.Show();
} }
}
}"; }";
$menuLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $mouseClickScript); $menuLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $mouseClickScript);
return $menuLabels; return $menuLabels;
@ -323,76 +474,77 @@ if (Event.Control.HasClass(\"" . self::CLASS_MENUBUTTON . "\")) {
* @return string * @return string
*/ */
private function getPagesLabels() { private function getPagesLabels() {
if (!$this->pages) return "";
$pagesNumberPrefix = self::CLASS_PAGE . '-P'; $pagesNumberPrefix = self::CLASS_PAGE . '-P';
$pagesNumberPrefixLength = strlen($pagesNumberPrefix); $pagesNumberPrefixLength = strlen($pagesNumberPrefix);
$pagesScript = " $pagesScript = "
if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) { if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) {
declare Text PagesId; declare Text PagesId;
declare Integer PagingAction; declare Integer PagingAction;
foreach (ControlClass in Event.Control.ControlClasses) { foreach (ControlClass in Event.Control.ControlClasses) {
declare ClassParts = TextLib::Split(\"-\", ControlClass); declare ClassParts = TextLib::Split(\"-\", ControlClass);
if (ClassParts.count <= 1) continue; if (ClassParts.count <= 1) continue;
if (ClassParts[0] != \"" . self::CLASS_PAGER . "\") continue; if (ClassParts[0] != \"" . self::CLASS_PAGER . "\") continue;
switch (TextLib::SubText(ClassParts[1], 0, 1)) { switch (TextLib::SubText(ClassParts[1], 0, 1)) {
case \"I\": { case \"I\": {
PagesId = TextLib::SubText(ClassParts[1], 1, 99); PagesId = TextLib::SubText(ClassParts[1], 1, 99);
} }
case \"A\": { case \"A\": {
PagingAction = TextLib::ToInteger(TextLib::SubText(ClassParts[1], 1, 99)); PagingAction = TextLib::ToInteger(TextLib::SubText(ClassParts[1], 1, 99));
} }
} }
} }
declare FML_PagesLastScriptStart for This = FML_ScriptStart; declare FML_PagesLastScriptStart for This = FML_ScriptStart;
declare FML_MinPageNumber for This = Integer[Text]; declare FML_MinPageNumber for This = Integer[Text];
declare FML_MaxPageNumber for This = Integer[Text]; declare FML_MaxPageNumber for This = Integer[Text];
declare FML_PageNumber for This = Integer[Text]; declare FML_PageNumber for This = Integer[Text];
if (FML_PagesLastScriptStart != FML_ScriptStart || !FML_PageNumber.existskey(PagesId) || !FML_MinPageNumber.existskey(PagesId) || !FML_MaxPageNumber.existskey(PagesId)) { if (FML_PagesLastScriptStart != FML_ScriptStart || !FML_PageNumber.existskey(PagesId) || !FML_MinPageNumber.existskey(PagesId) || !FML_MaxPageNumber.existskey(PagesId)) {
Page.GetClassChildren(PagesId, Page.MainFrame, True); Page.GetClassChildren(PagesId, Page.MainFrame, True);
foreach (PageControl in Page.GetClassChildren_Result) { foreach (PageControl in Page.GetClassChildren_Result) {
if (!PageControl.HasClass(\"" . self::CLASS_PAGE . "\")) continue; if (!PageControl.HasClass(\"" . self::CLASS_PAGE . "\")) continue;
foreach (ControlClass in PageControl.ControlClasses) { foreach (ControlClass in PageControl.ControlClasses) {
if (TextLib::SubText(ControlClass, 0, {$pagesNumberPrefixLength}) != \"{$pagesNumberPrefix}\") continue; if (TextLib::SubText(ControlClass, 0, {$pagesNumberPrefixLength}) != \"{$pagesNumberPrefix}\") continue;
declare PageNumber = TextLib::ToInteger(TextLib::SubText(ControlClass, {$pagesNumberPrefixLength}, 99)); declare PageNumber = TextLib::ToInteger(TextLib::SubText(ControlClass, {$pagesNumberPrefixLength}, 99));
if (!FML_MinPageNumber.existskey(PagesId) || PageNumber < FML_MinPageNumber[PagesId]) { if (!FML_MinPageNumber.existskey(PagesId) || PageNumber < FML_MinPageNumber[PagesId]) {
FML_MinPageNumber[PagesId] = PageNumber; FML_MinPageNumber[PagesId] = PageNumber;
} }
if (!FML_MaxPageNumber.existskey(PagesId) || PageNumber > FML_MaxPageNumber[PagesId]) { if (!FML_MaxPageNumber.existskey(PagesId) || PageNumber > FML_MaxPageNumber[PagesId]) {
FML_MaxPageNumber[PagesId] = PageNumber; FML_MaxPageNumber[PagesId] = PageNumber;
} }
break; break;
} }
} }
FML_PageNumber[PagesId] = FML_MinPageNumber[PagesId]; FML_PageNumber[PagesId] = FML_MinPageNumber[PagesId];
} }
FML_PageNumber[PagesId] += PagingAction; FML_PageNumber[PagesId] += PagingAction;
if (FML_PageNumber[PagesId] < FML_MinPageNumber[PagesId]) { if (FML_PageNumber[PagesId] < FML_MinPageNumber[PagesId]) {
FML_PageNumber[PagesId] = FML_MinPageNumber[PagesId]; FML_PageNumber[PagesId] = FML_MinPageNumber[PagesId];
} }
if (FML_PageNumber[PagesId] > FML_MaxPageNumber[PagesId]) { if (FML_PageNumber[PagesId] > FML_MaxPageNumber[PagesId]) {
FML_PageNumber[PagesId] = FML_MaxPageNumber[PagesId]; FML_PageNumber[PagesId] = FML_MaxPageNumber[PagesId];
} }
FML_PagesLastScriptStart = FML_ScriptStart; FML_PagesLastScriptStart = FML_ScriptStart;
Page.GetClassChildren(PagesId, Page.MainFrame, True); Page.GetClassChildren(PagesId, Page.MainFrame, True);
foreach (PageControl in Page.GetClassChildren_Result) { foreach (PageControl in Page.GetClassChildren_Result) {
if (!PageControl.HasClass(\"" . self::CLASS_PAGE . "\")) continue; if (!PageControl.HasClass(\"" . self::CLASS_PAGE . "\")) continue;
declare PageNumber = -1; declare PageNumber = -1;
foreach (ControlClass in PageControl.ControlClasses) { foreach (ControlClass in PageControl.ControlClasses) {
if (TextLib::SubText(ControlClass, 0, {$pagesNumberPrefixLength}) != \"{$pagesNumberPrefix}\") continue; if (TextLib::SubText(ControlClass, 0, {$pagesNumberPrefixLength}) != \"{$pagesNumberPrefix}\") continue;
PageNumber = TextLib::ToInteger(TextLib::SubText(ControlClass, {$pagesNumberPrefixLength}, 99)); PageNumber = TextLib::ToInteger(TextLib::SubText(ControlClass, {$pagesNumberPrefixLength}, 99));
break; break;
} }
if (PageNumber != FML_PageNumber[PagesId]) { if (PageNumber != FML_PageNumber[PagesId]) {
PageControl.Hide(); PageControl.Hide();
} else { } else {
PageControl.Show(); PageControl.Show();
} }
} }
Page.GetClassChildren(\"" . self::CLASS_PAGELABEL . "\", Page.MainFrame, True); Page.GetClassChildren(\"" . self::CLASS_PAGELABEL . "\", Page.MainFrame, True);
foreach (PageControl in Page.GetClassChildren_Result) { foreach (PageControl in Page.GetClassChildren_Result) {
if (!PageControl.HasClass(PagesId)) continue; if (!PageControl.HasClass(PagesId)) continue;
declare PageLabel <=> (PageControl as CMlLabel); declare PageLabel <=> (PageControl as CMlLabel);
PageLabel.Value = FML_PageNumber[PagesId]^\"/\"^FML_MaxPageNumber[PagesId]; PageLabel.Value = FML_PageNumber[PagesId]^\"/\"^FML_MaxPageNumber[PagesId];
} }
}"; }";
$pagesLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $pagesScript); $pagesLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $pagesScript);
return $pagesLabels; return $pagesLabels;
@ -404,17 +556,18 @@ if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) {
* @return string * @return string
*/ */
private function getProfileLabels() { private function getProfileLabels() {
$profileScript = " if (!$this->profile) return "";
if (Event.Control.HasClass(\"" . self::CLASS_PROFILE . "\")) { $profileScript = "
declare Login = LocalUser.Login; if (Event.Control.HasClass(\"" . self::CLASS_PROFILE . "\")) {
foreach (ControlClass in Event.Control.ControlClasses) { declare Login = LocalUser.Login;
declare ClassParts = TextLib::Split(\"-\", ControlClass); foreach (ControlClass in Event.Control.ControlClasses) {
if (ClassParts.count <= 1) continue; declare ClassParts = TextLib::Split(\"-\", ControlClass);
if (ClassParts[0] != \"" . self::CLASS_PROFILE . "\") continue; if (ClassParts.count <= 1) continue;
Login = ClassParts[1]; if (ClassParts[0] != \"" . self::CLASS_PROFILE . "\") continue;
break; Login = ClassParts[1];
} break;
ShowProfile(Login); }
ShowProfile(Login);
}"; }";
$profileLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $profileScript); $profileLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $profileScript);
return $profileLabels; return $profileLabels;
@ -426,9 +579,10 @@ if (Event.Control.HasClass(\"" . self::CLASS_PROFILE . "\")) {
* @return string * @return string
*/ */
private function getMapInfoLabels() { private function getMapInfoLabels() {
$mapInfoScript = " if (!$this->mapInfo) return "";
if (Event.Control.HasClass(\"" . self::CLASS_MAPINFO . "\")) { $mapInfoScript = "
ShowCurChallengeCard(); if (Event.Control.HasClass(\"" . self::CLASS_MAPINFO . "\")) {
ShowCurChallengeCard();
}"; }";
$mapInfoLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $mapInfoScript); $mapInfoLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $mapInfoScript);
return $mapInfoLabels; return $mapInfoLabels;
@ -443,4 +597,28 @@ if (Event.Control.HasClass(\"" . self::CLASS_MAPINFO . "\")) {
$mainFunction = file_get_contents(__DIR__ . '/Parts/Main.txt'); $mainFunction = file_get_contents(__DIR__ . '/Parts/Main.txt');
return $mainFunction; return $mainFunction;
} }
}
/**
* Return the Array of additional optional Parameters
*
* @param array $args
* @param int $offset
* @return array
*/
private function spliceParameters(array $params, $offset) {
$args = array_splice($params, $offset);
if (!$args) return $args;
$parameters = array();
foreach ($args as $arg) {
if (is_array($arg)) {
foreach ($arg as $key => $value) {
$parameters[$key] = $value;
}
}
else {
$parameters[$arg] = true;
}
}
return $parameters;
}
}

View File

@ -9,7 +9,11 @@
if (!defined('FML_PATH')) { if (!defined('FML_PATH')) {
define('FML_PATH', __DIR__ . '/../'); define('FML_PATH', __DIR__ . '/../');
} }
if (!defined('FML_VERSION')) {
define('FML_VERSION', 1.0);
}
// Register Autoload Function that loads FML Class Files on Demand
spl_autoload_register( spl_autoload_register(
function ($className) { function ($className) {
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className); $classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className);