diff --git a/libs/FML/Controls/Control.php b/libs/FML/Controls/Control.php index 60fc589d..e1793851 100644 --- a/libs/FML/Controls/Control.php +++ b/libs/FML/Controls/Control.php @@ -27,891 +27,916 @@ use FML\UniqueID; abstract class Control implements Identifiable, Renderable, ScriptFeatureable { - /* - * Constants - */ - const CENTER = 'center'; - const CENTER2 = 'center2'; - const TOP = 'top'; - const RIGHT = 'right'; - const BOTTOM = 'bottom'; - const LEFT = 'left'; - - /** - * @var string $controlId Control Id - */ - protected $controlId = null; - - /** - * @var float $posX X position - */ - protected $posX = 0.; - - /** - * @var float $posY Y position - */ - protected $posY = 0.; - - /** - * @var float $posZ Z position - */ - protected $posZ = 0.; - - /** - * @var float $width Width - */ - protected $width = -1.; - - /** - * @var float $height Height - */ - protected $height = -1.; - - /** - * @var string $horizontalAlign Horizontal alignment - */ - protected $horizontalAlign = self::CENTER; - - /** - * @var string $verticalAlign Vertical alignment - */ - protected $verticalAlign = self::CENTER2; - - /** - * @var float $scale Scale - */ - protected $scale = 1.; - - /** - * @var bool $visible Visibility - */ - protected $visible = true; - - /** - * @var float $rotation Rotation - */ - protected $rotation = 0.; - - /** - * @var string[] $classes Style classes - */ - protected $classes = array(); - - /** - * @var mixed[] $dataAttributes Data attributes - */ - protected $dataAttributes = array(); - - /** - * @var ScriptFeature[] $scriptFeatures Script Features - */ - protected $scriptFeatures = array(); - - /** - * Create a new Control - * - * @api - * @param string $controlId (optional) Control Id - * @return static - */ - public static function create($controlId = null) - { - return new static($controlId); - } - - /** - * Construct a new Control - * - * @api - * @param string $controlId (optional) Control Id - */ - public function __construct($controlId = null) - { - if ($controlId) { - $this->setId($controlId); - } - } - - /** - * @see Identifiable::getId() - */ - public function getId() - { - return $this->controlId; - } - - /** - * @see Identifiable::setId() - */ - public function setId($controlId) - { - $this->controlId = (string)$controlId; - return $this; - } - - /** - * @see Identifiable::checkId() - */ - public function checkId() - { - return UniqueID::check($this); - } - - /** - * Get the X position - * - * @api - * @return float - */ - public function getX() - { - return $this->posX; - } - - /** - * Set the X position - * - * @api - * @param float $posX Horizontal position - * @return static - */ - public function setX($posX) - { - $this->posX = (float)$posX; - return $this; - } - - /** - * Get the Y position - * - * @api - * @return float - */ - public function getY() - { - return $this->posY; - } - - /** - * Set the Y position - * - * @api - * @param float $posY Vertical position - * @return static - */ - public function setY($posY) - { - $this->posY = (float)$posY; - return $this; - } - - /** - * Get the Z position - * - * @api - * @return float - */ - public function getZ() - { - return $this->posZ; - } - - /** - * Set the Z position - * - * @api - * @param float $posZ Depth - * @return static - */ - public function setZ($posZ) - { - $this->posZ = (float)$posZ; - return $this; - } - - /** - * Set the Control position - * - * @api - * @param float $posX Horizontal position - * @param float $posY Vertical position - * @param float $posZ (optional) Depth - * @return static - */ - public function setPosition($posX, $posY, $posZ = null) - { - $this->setX($posX) - ->setY($posY); - if ($posZ !== null) { - $this->setZ($posZ); - } - return $this; - } - - /** - * Get the width - * - * @api - * @return float - */ - public function getWidth() - { - return $this->width; - } - - /** - * Set the width - * - * @api - * @param float $width Control width - * @return static - */ - public function setWidth($width) - { - $this->width = (float)$width; - return $this; - } - - /** - * Get the height - * - * @api - * @return float - */ - public function getHeight() - { - return $this->height; - } - - /** - * Set the height - * - * @api - * @param float $height Control height - * @return static - */ - public function setHeight($height) - { - $this->height = (float)$height; - return $this; - } - - /** - * Set the size - * - * @api - * @param float $width Control width - * @param float $height Control height - * @return static - */ - public function setSize($width, $height) - { - return $this->setWidth($width) - ->setHeight($height); - } - - /** - * Get the horizontal alignment - * - * @api - * @return string - */ - public function getHorizontalAlign() - { - return $this->horizontalAlign; - } - - /** - * Set the horizontal alignment - * - * @api - * @param string $horizontalAlign Horizontal alignment - * @return static - * @deprecated Use setHorizontalAlign() - * @see Control::setHorizontalAlign() - */ - public function setHAlign($horizontalAlign) - { - return $this->setHorizontalAlign($horizontalAlign); - } - - /** - * Set the horizontal alignment - * - * @api - * @param string $horizontalAlign Horizontal alignment - * @return static - */ - public function setHorizontalAlign($horizontalAlign) - { - $this->horizontalAlign = (string)$horizontalAlign; - return $this; - } - - /** - * Get the vertical alignment - * - * @api - * @return string - */ - public function getVerticalAlign() - { - return $this->verticalAlign; - } - - /** - * Set the vertical alignment - * - * @api - * @param string $verticalAlign Vertical alignment - * @return static - * @deprecated Use setVerticalAlign() - * @see Control::setVerticalAlign() - */ - public function setVAlign($verticalAlign) - { - return $this->setVerticalAlign($verticalAlign); - } - - /** - * Set the vertical alignment - * - * @api - * @param string $verticalAlign Vertical alignment - * @return static - */ - public function setVerticalAlign($verticalAlign) - { - $this->verticalAlign = (string)$verticalAlign; - return $this; - } - - /** - * Set the horizontal and the vertical alignment - * - * @api - * @param string $horizontalAlign Horizontal alignment - * @param string $verticalAlign Vertical alignment - * @return static - */ - public function setAlign($horizontalAlign, $verticalAlign) - { - return $this->setHorizontalAlign($horizontalAlign) - ->setVerticalAlign($verticalAlign); - } - - /** - * Center the alignment - * - * @api - * @return static - */ - public function centerAlign() - { - return $this->setAlign(self::CENTER, self::CENTER2); - } - - /** - * Clear the alignment - * - * @api - * @return static - */ - public function clearAlign() - { - $this->horizontalAlign = null; - $this->verticalAlign = null; - return $this; - } - - /** - * Get the scale - * - * @api - * @return float - */ - public function getScale() - { - return $this->scale; - } - - /** - * Set the scale - * - * @api - * @param float $scale Control scale - * @return static - */ - public function setScale($scale) - { - $this->scale = (float)$scale; - return $this; - } - - /** - * Get the visibility - * - * @api - * @return bool - */ - public function getVisible() - { - return $this->visible; - } - - /** - * Set the visibility - * - * @api - * @param bool $visible If the Control should be visible - * @return static - */ - public function setVisible($visible) - { - $this->visible = $visible; - return $this; - } - - /** - * Get the rotation - * - * @api - * @return float - */ - public function getRotation() - { - return $this->rotation; - } - - /** - * Set the rotation - * - * @api - * @param float $rotation Control rotation - * @return static - */ - public function setRotation($rotation) - { - $this->rotation = (float)$rotation; - return $this; - } - - /** - * Get style classes - * - * @api - * @return string[] - */ - public function getClasses() - { - return $this->classes; - } - - /** - * Add a new style class - * - * @api - * @param string $class Style class - * @return static - */ - public function addClass($class) - { - $class = (string)$class; - if (!in_array($class, $this->classes)) { - array_push($this->classes, $class); - } - return $this; - } - - /** - * Add new style classes - * - * @api - * @param string[] $classes Style classes - * @return static - */ - public function addClasses(array $classes) - { - foreach ($classes as $class) { - $this->addClass($class); - } - return $this; - } - - /** - * Remove all style classes - * - * @api - * @return static - */ - public function removeAllClasses() - { - $this->classes = array(); - return $this; - } - - /** - * Check if a data attribute is set - * - * @api - * @param string $name Name - * @return bool - */ - public function hasDataAttribute($name) - { - return isset($this->dataAttributes[$name]); - } - - /** - * Get data attribute - * - * @api - * @param string $name Name - * @return mixed - */ - public function getDataAttribute($name) - { - if (isset($this->dataAttributes[$name])) { - return $this->dataAttributes[$name]; - } - return null; - } - - /** - * Get data attributes - * - * @api - * @return mixed[] - */ - public function getDataAttributes() - { - return $this->dataAttributes; - } - - /** - * Add data attribute - * - * @api - * @param string $name Name - * @param mixed $value Value - * @return static - */ - public function addDataAttribute($name, $value) - { - $this->dataAttributes[$name] = $value; - return $this; - } - - /** - * Add multiple data attributes - * - * @api - * @param mixed[] $dataAttributes Data attributes - * @return static - */ - public function addDataAttributes(array $dataAttributes) - { - foreach ($dataAttributes as $name => $value) { - $this->addDataAttribute($name, $value); - } - return $this; - } - - /** - * Set data attributes (replacing all previous attributes) - * - * @api - * @param mixed[] $dataAttributes Data attributes - * @return static - */ - public function setDataAttributes(array $dataAttributes) - { - return $this->removeAllDataAttributes() - ->addDataAttributes($dataAttributes); - } - - /** - * Remove data attribute - * - * @api - * @param string $name Name - * @return static - */ - public function removeDataAttribute($name) - { - unset($this->dataAttributes[$name]); - return $this; - } - - /** - * Remove all data attributes - * - * @api - * @return static - */ - public function removeAllDataAttributes() - { - $this->dataAttributes = array(); - return $this; - } - - /** - * @see ScriptFeatureable::getScriptFeatures() - */ - public function getScriptFeatures() - { - return $this->scriptFeatures; - } - - /** - * Add a new Script Feature - * - * @api - * @param ScriptFeature $scriptFeature Script Feature - * @return static - */ - public function addScriptFeature(ScriptFeature $scriptFeature) - { - if (!in_array($scriptFeature, $this->scriptFeatures, true)) { - array_push($this->scriptFeatures, $scriptFeature); - } - return $this; - } - - /** - * Add new Script Features - * - * @api - * @param ScriptFeature[] $scriptFeatures Script Features - * @return static - */ - public function addScriptFeatures(array $scriptFeatures) - { - foreach ($scriptFeatures as $scriptFeature) { - $this->addScriptFeature($scriptFeature); - } - return $this; - } - - /** - * Remove all Script Features - * - * @api - * @return static - * @deprecated Use removeAllScriptFeatures() - * @see Control::removeAllScriptFeatures() - */ - public function removeScriptFeatures() - { - return $this->removeAllScriptFeatures(); - } - - /** - * Remove all Script Features - * - * @api - * @return static - */ - public function removeAllScriptFeatures() - { - $this->scriptFeatures = array(); - return $this; - } - - /** - * Add a dynamic Action Trigger - * - * @api - * @param string $actionName Action to trigger - * @param string $eventLabel (optional) Event on which the action is triggered - * @return static - */ - public function addActionTriggerFeature($actionName, $eventLabel = ScriptLabel::MOUSECLICK) - { - $actionTrigger = new ActionTrigger($actionName, $this, $eventLabel); - $this->addScriptFeature($actionTrigger); - return $this; - } - - /** - * Add a dynamic Feature opening the current map info - * - * @api - * @param string $eventLabel (optional) Event on which the map info will be opened - * @return static - */ - public function addMapInfoFeature($eventLabel = ScriptLabel::MOUSECLICK) - { - $mapInfo = new MapInfo($this, $eventLabel); - $this->addScriptFeature($mapInfo); - return $this; - } - - /** - * Add a dynamic Feature to open a specific player profile - * - * @api - * @param string $login Login of the player - * @param string $eventLabel (optional) Event on which the player profile will be opened - * @return static - */ - public function addPlayerProfileFeature($login, $eventLabel = ScriptLabel::MOUSECLICK) - { - $playerProfile = new PlayerProfile($login, $this, $eventLabel); - $this->addScriptFeature($playerProfile); - return $this; - } - - /** - * Add a dynamic Feature playing a UISound - * - * @api - * @param string $soundName UISound name - * @param int $variant (optional) Sound variant - * @param string $eventLabel (optional) Event on which the sound will be played - * @return static - */ - public function addUISoundFeature($soundName, $variant = 0, $eventLabel = ScriptLabel::MOUSECLICK) - { - $uiSound = new UISound($soundName, $this, $variant, $eventLabel); - $this->addScriptFeature($uiSound); - return $this; - } - - /** - * Add a dynamic Feature toggling another Control - * - * @api - * @param Control $toggledControl Toggled Control - * @param string $labelName (optional) Script label name - * @param bool $onlyShow (optional) If it should only show the Control but not toggle - * @param bool $onlyHide (optional) If it should only hide the Control but not toggle - * @return static - */ - public function addToggleFeature(Control $toggledControl, $labelName = ScriptLabel::MOUSECLICK, $onlyShow = false, $onlyHide = false) - { - $toggle = new Toggle($this, $toggledControl, $labelName, $onlyShow, $onlyHide); - $this->addScriptFeature($toggle); - return $this; - } - - /** - * Add a dynamic Feature showing a Tooltip on hovering - * - * @api - * @param Control $tooltipControl Tooltip Control - * @param bool $stayOnClick (optional) Whether the Tooltip should stay on click - * @param bool $invert (optional) Whether the visibility toggling should be inverted - * @return static - */ - public function addTooltipFeature(Control $tooltipControl, $stayOnClick = false, $invert = false) - { - $tooltip = new Tooltip($this, $tooltipControl, $stayOnClick, $invert); - $this->addScriptFeature($tooltip); - return $this; - } - - /** - * Add a dynamic Feature showing a Tooltip on hovering - * - * @api - * @param Label $tooltipLabel Tooltip Label - * @param string $text Text to display on the Tooltip Label - * @param bool $stayOnClick (optional) Whether the Tooltip should stay on click - * @param bool $invert (optional) Whether the visibility toggling should be inverted - * @return static - */ - public function addTooltipLabelFeature(Label $tooltipLabel, $text, $stayOnClick = false, $invert = false) - { - $tooltip = new Tooltip($this, $tooltipLabel, $stayOnClick, $invert, $text); - $this->addScriptFeature($tooltip); - return $this; - } - - /** - * Add a custom Control Script text part - * - * @api - * @param string $scriptText Script text - * @param string $label (optional) Script label name - * @return static - */ - public function addScriptText($scriptText, $label = ScriptLabel::MOUSECLICK) - { - $customText = new ControlScript($this, $scriptText, $label); - $this->addScriptFeature($customText); - return $this; - } - - /** - * @see Renderable::render() - */ - public function render(\DOMDocument $domDocument) - { - $domElement = $domDocument->createElement($this->getTagName()); - if ($this->controlId) { - $domElement->setAttribute("id", $this->controlId); - } - if ($this->posX || $this->posY) { - $domElement->setAttribute("pos", "{$this->posX} {$this->posY}"); - } - if ($this->posX || $this->posY || $this->posZ) { - // backwards-compatibility - $domElement->setAttribute("posn", "{$this->posX} {$this->posY} {$this->posZ}"); - } - if ($this->posZ) { - $domElement->setAttribute("z-index", $this->posZ); - } - if ($this->width >= 0. || $this->height >= 0.) { - $domElement->setAttribute("size", "{$this->width} {$this->height}"); - // backwards-compatibility - $domElement->setAttribute("sizen", "{$this->width} {$this->height}"); - if ($this->width >= 0.) { - // backwards-compatibility - $domElement->setAttribute("width", $this->width); - } - if ($this->height >= 0.) { - // backwards-compatibility - $domElement->setAttribute("height", $this->height); - } - } - if ($this->horizontalAlign) { - $domElement->setAttribute("halign", $this->horizontalAlign); - } - if ($this->verticalAlign) { - $domElement->setAttribute("valign", $this->verticalAlign); - } - if ($this->scale != 1.) { - $domElement->setAttribute("scale", $this->scale); - } - if (!$this->visible) { - $domElement->setAttribute("hidden", "1"); - } - if ($this->rotation) { - $domElement->setAttribute("rot", $this->rotation); - } - if ($this->classes) { - $classes = implode(" ", $this->classes); - $domElement->setAttribute("class", $classes); - } - foreach ($this->dataAttributes as $dataAttributeName => $dataAttributeValue) { - $domElement->setAttribute("data-" . $dataAttributeName, $dataAttributeValue); - } - return $domElement; - } - - /** - * Get the tag name of the Control - * - * @return string - */ - abstract public function getTagName(); - - /** - * Get the ManiaScript class of the Control - * - * @return string - */ - abstract public function getManiaScriptClass(); + /* + * Constants + */ + const CENTER = 'center'; + const CENTER2 = 'center2'; + const TOP = 'top'; + const RIGHT = 'right'; + const BOTTOM = 'bottom'; + const LEFT = 'left'; + + /** + * @var string $controlId Control Id + */ + protected $controlId = null; + + /** + * @var float $posX X position + */ + protected $posX = 0.; + + /** + * @var float $posY Y position + */ + protected $posY = 0.; + + /** + * @var float $posZ Z position + */ + protected $posZ = 0.; + + /** + * @var float $width Width + */ + protected $width = 0.; + + /** + * @var float $height Height + */ + protected $height = 0.; + + /** + * @var string $horizontalAlign Horizontal alignment + */ + protected $horizontalAlign = self::CENTER; + + /** + * @var string $verticalAlign Vertical alignment + */ + protected $verticalAlign = self::CENTER2; + + /** + * @var float $scale Scale + */ + protected $scale = 1.; + + /** + * @var bool $visible Visibility + */ + protected $visible = true; + + /** + * @var float $rotation Rotation + */ + protected $rotation = 0.; + + /** + * @var string[] $classes Style classes + */ + protected $classes = array(); + + /** + * @var mixed[] $dataAttributes Data attributes + */ + protected $dataAttributes = array(); + + /** + * @var ScriptFeature[] $scriptFeatures Script Features + */ + protected $scriptFeatures = array(); + + /** + * Create a new Control + * + * @api + * @param string $controlId (optional) Control Id + * @return static + */ + public static function create($controlId = null) + { + return new static($controlId); + } + + /** + * Construct a new Control + * + * @api + * @param string $controlId (optional) Control Id + */ + public function __construct($controlId = null) + { + if ($controlId) { + $this->setId($controlId); + } + } + + /** + * @see Identifiable::getId() + */ + public function getId() + { + return $this->controlId; + } + + /** + * @see Identifiable::setId() + */ + public function setId($controlId) + { + $this->controlId = (string)$controlId; + return $this; + } + + /** + * @see Identifiable::checkId() + */ + public function checkId() + { + return UniqueID::check($this); + } + + /** + * Get the X position + * + * @api + * @return float + */ + public function getX() + { + return $this->posX; + } + + /** + * Set the X position + * + * @api + * @param float $posX Horizontal position + * @return static + */ + public function setX($posX) + { + $this->posX = (float)$posX; + return $this; + } + + /** + * Get the Y position + * + * @api + * @return float + */ + public function getY() + { + return $this->posY; + } + + /** + * Set the Y position + * + * @api + * @param float $posY Vertical position + * @return static + */ + public function setY($posY) + { + $this->posY = (float)$posY; + return $this; + } + + /** + * Get the Z position + * + * @api + * @return float + */ + public function getZ() + { + return $this->posZ; + } + + /** + * Set the Z position + * + * @api + * @param float $posZ Depth + * @return static + */ + public function setZ($posZ) + { + $this->posZ = (float)$posZ; + return $this; + } + + /** + * Set the Control position + * + * @api + * @param float $posX Horizontal position + * @param float $posY Vertical position + * @param float $posZ (optional) Depth + * @return static + */ + public function setPosition($posX, $posY, $posZ = null) + { + $this->setX($posX) + ->setY($posY); + if ($posZ !== null) { + $this->setZ($posZ); + } + return $this; + } + + /** + * Get the width + * + * @api + * @return float + */ + public function getWidth() + { + return $this->width; + } + + /** + * Set the width + * + * @api + * @param float $width Control width + * @return static + */ + public function setWidth($width) + { + $this->width = (float)$width; + return $this; + } + + /** + * Get the height + * + * @api + * @return float + */ + public function getHeight() + { + return $this->height; + } + + /** + * Set the height + * + * @api + * @param float $height Control height + * @return static + */ + public function setHeight($height) + { + $this->height = (float)$height; + return $this; + } + + /** + * Set the size + * + * @api + * @param float $width Control width + * @param float $height Control height + * @return static + */ + public function setSize($width, $height) + { + return $this->setWidth($width) + ->setHeight($height); + } + + /** + * Get the horizontal alignment + * + * @api + * @return string + */ + public function getHorizontalAlign() + { + return $this->horizontalAlign; + } + + /** + * Set the horizontal alignment + * + * @api + * @param string $horizontalAlign Horizontal alignment + * @return static + * @deprecated Use setHorizontalAlign() + * @see Control::setHorizontalAlign() + */ + public function setHAlign($horizontalAlign) + { + return $this->setHorizontalAlign($horizontalAlign); + } + + /** + * Set the horizontal alignment + * + * @api + * @param string $horizontalAlign Horizontal alignment + * @return static + */ + public function setHorizontalAlign($horizontalAlign) + { + $this->horizontalAlign = (string)$horizontalAlign; + return $this; + } + + /** + * Get the vertical alignment + * + * @api + * @return string + */ + public function getVerticalAlign() + { + return $this->verticalAlign; + } + + /** + * Set the vertical alignment + * + * @api + * @param string $verticalAlign Vertical alignment + * @return static + * @deprecated Use setVerticalAlign() + * @see Control::setVerticalAlign() + */ + public function setVAlign($verticalAlign) + { + return $this->setVerticalAlign($verticalAlign); + } + + /** + * Set the vertical alignment + * + * @api + * @param string $verticalAlign Vertical alignment + * @return static + */ + public function setVerticalAlign($verticalAlign) + { + $this->verticalAlign = (string)$verticalAlign; + return $this; + } + + /** + * Set the horizontal and the vertical alignment + * + * @api + * @param string $horizontalAlign Horizontal alignment + * @param string $verticalAlign Vertical alignment + * @return static + */ + public function setAlign($horizontalAlign, $verticalAlign) + { + return $this->setHorizontalAlign($horizontalAlign) + ->setVerticalAlign($verticalAlign); + } + + /** + * Center the alignment + * + * @api + * @return static + */ + public function centerAlign() + { + return $this->setAlign(self::CENTER, self::CENTER2); + } + + /** + * Reset the alignment + * + * @api + * @return static + * @deprecated Use clearAlign() + * @see Control::clearAlign() + */ + public function resetAlign() + { + return $this->clearAlign(); + } + + /** + * Clear the alignment + * + * @api + * @return static + */ + public function clearAlign() + { + $this->horizontalAlign = null; + $this->verticalAlign = null; + return $this; + } + + /** + * Get the scale + * + * @api + * @return float + */ + public function getScale() + { + return $this->scale; + } + + /** + * Set the scale + * + * @api + * @param float $scale Control scale + * @return static + */ + public function setScale($scale) + { + $this->scale = (float)$scale; + return $this; + } + + /** + * Get the visibility + * + * @api + * @return bool + */ + public function getVisible() + { + return $this->visible; + } + + /** + * Set the visibility + * + * @api + * @param bool $visible If the Control should be visible + * @return static + */ + public function setVisible($visible) + { + $this->visible = $visible; + return $this; + } + + /** + * Get the rotation + * + * @api + * @return float + */ + public function getRotation() + { + return $this->rotation; + } + + /** + * Set the rotation + * + * @api + * @param float $rotation Control rotation + * @return static + */ + public function setRotation($rotation) + { + $this->rotation = (float)$rotation; + return $this; + } + + /** + * Get style classes + * + * @api + * @return string[] + */ + public function getClasses() + { + return $this->classes; + } + + /** + * Add a new style class + * + * @api + * @param string $class Style class + * @return static + */ + public function addClass($class) + { + $class = (string)$class; + if (!in_array($class, $this->classes)) { + array_push($this->classes, $class); + } + return $this; + } + + /** + * Add new style classes + * + * @api + * @param string[] $classes Style classes + * @return static + */ + public function addClasses(array $classes) + { + foreach ($classes as $class) { + $this->addClass($class); + } + return $this; + } + + /** + * Remove all style classes + * + * @api + * @return static + */ + public function removeAllClasses() + { + $this->classes = array(); + return $this; + } + + /** + * Check if a data attribute is set + * + * @api + * @param string $name Name + * @return bool + */ + public function hasDataAttribute($name) + { + return isset($this->dataAttributes[$name]); + } + + /** + * Get data attribute + * + * @api + * @param string $name Name + * @return mixed + */ + public function getDataAttribute($name) + { + if (isset($this->dataAttributes[$name])) { + return $this->dataAttributes[$name]; + } + return null; + } + + /** + * Get data attributes + * + * @api + * @return mixed[] + */ + public function getDataAttributes() + { + return $this->dataAttributes; + } + + /** + * Add data attribute + * + * @api + * @param string $name Name + * @param mixed $value Value + * @return static + */ + public function addDataAttribute($name, $value) + { + $this->dataAttributes[$name] = $value; + return $this; + } + + /** + * Add multiple data attributes + * + * @api + * @param mixed[] $dataAttributes Data attributes + * @return static + */ + public function addDataAttributes(array $dataAttributes) + { + foreach ($dataAttributes as $name => $value) { + $this->addDataAttribute($name, $value); + } + return $this; + } + + /** + * Set data attributes (replacing all previous attributes) + * + * @api + * @param mixed[] $dataAttributes Data attributes + * @return static + */ + public function setDataAttributes(array $dataAttributes) + { + return $this->removeAllDataAttributes() + ->addDataAttributes($dataAttributes); + } + + /** + * Remove data attribute + * + * @api + * @param string $name Name + * @return static + */ + public function removeDataAttribute($name) + { + unset($this->dataAttributes[$name]); + return $this; + } + + /** + * Remove all data attributes + * + * @api + * @return static + */ + public function removeAllDataAttributes() + { + $this->dataAttributes = array(); + return $this; + } + + /** + * @see ScriptFeatureable::getScriptFeatures() + */ + public function getScriptFeatures() + { + return $this->scriptFeatures; + } + + /** + * Add a new Script Feature + * + * @api + * @param ScriptFeature $scriptFeature Script Feature + * @return static + */ + public function addScriptFeature(ScriptFeature $scriptFeature) + { + if (!in_array($scriptFeature, $this->scriptFeatures, true)) { + array_push($this->scriptFeatures, $scriptFeature); + } + return $this; + } + + /** + * Add new Script Features + * + * @api + * @param ScriptFeature[] $scriptFeatures Script Features + * @return static + */ + public function addScriptFeatures(array $scriptFeatures) + { + foreach ($scriptFeatures as $scriptFeature) { + $this->addScriptFeature($scriptFeature); + } + return $this; + } + + /** + * Remove all Script Features + * + * @api + * @return static + * @deprecated Use removeAllScriptFeatures() + * @see Control::removeAllScriptFeatures() + */ + public function removeScriptFeatures() + { + return $this->removeAllScriptFeatures(); + } + + /** + * Remove all Script Features + * + * @api + * @return static + */ + public function removeAllScriptFeatures() + { + $this->scriptFeatures = array(); + return $this; + } + + /** + * Add a dynamic Action Trigger + * + * @api + * @param string $actionName Action to trigger + * @param string $eventLabel (optional) Event on which the action is triggered + * @return static + */ + public function addActionTriggerFeature($actionName, $eventLabel = ScriptLabel::MOUSECLICK) + { + $actionTrigger = new ActionTrigger($actionName, $this, $eventLabel); + $this->addScriptFeature($actionTrigger); + return $this; + } + + /** + * Add a dynamic Feature opening the current map info + * + * @api + * @param string $eventLabel (optional) Event on which the map info will be opened + * @return static + */ + public function addMapInfoFeature($eventLabel = ScriptLabel::MOUSECLICK) + { + $mapInfo = new MapInfo($this, $eventLabel); + $this->addScriptFeature($mapInfo); + return $this; + } + + /** + * Add a dynamic Feature to open a specific player profile + * + * @api + * @param string $login Login of the player + * @param string $eventLabel (optional) Event on which the player profile will be opened + * @return static + */ + public function addPlayerProfileFeature($login, $eventLabel = ScriptLabel::MOUSECLICK) + { + $playerProfile = new PlayerProfile($login, $this, $eventLabel); + $this->addScriptFeature($playerProfile); + return $this; + } + + /** + * Add a dynamic Feature playing a UISound + * + * @api + * @param string $soundName UISound name + * @param int $variant (optional) Sound variant + * @param string $eventLabel (optional) Event on which the sound will be played + * @return static + */ + public function addUISoundFeature($soundName, $variant = 0, $eventLabel = ScriptLabel::MOUSECLICK) + { + $uiSound = new UISound($soundName, $this, $variant, $eventLabel); + $this->addScriptFeature($uiSound); + return $this; + } + + /** + * Add a dynamic Feature toggling another Control + * + * @api + * @param Control $toggledControl Toggled Control + * @param string $labelName (optional) Script label name + * @param bool $onlyShow (optional) If it should only show the Control but not toggle + * @param bool $onlyHide (optional) If it should only hide the Control but not toggle + * @return static + */ + public function addToggleFeature(Control $toggledControl, $labelName = ScriptLabel::MOUSECLICK, $onlyShow = false, $onlyHide = false) + { + $toggle = new Toggle($this, $toggledControl, $labelName, $onlyShow, $onlyHide); + $this->addScriptFeature($toggle); + return $this; + } + + /** + * Add a dynamic Feature showing a Tooltip on hovering + * + * @api + * @param Control $tooltipControl Tooltip Control + * @param bool $stayOnClick (optional) Whether the Tooltip should stay on click + * @param bool $invert (optional) Whether the visibility toggling should be inverted + * @return static + */ + public function addTooltipFeature(Control $tooltipControl, $stayOnClick = false, $invert = false) + { + $tooltip = new Tooltip($this, $tooltipControl, $stayOnClick, $invert); + $this->addScriptFeature($tooltip); + return $this; + } + + /** + * Add a dynamic Feature showing a Tooltip on hovering + * + * @api + * @param Label $tooltipLabel Tooltip Label + * @param string $text Text to display on the Tooltip Label + * @param bool $stayOnClick (optional) Whether the Tooltip should stay on click + * @param bool $invert (optional) Whether the visibility toggling should be inverted + * @return static + */ + public function addTooltipLabelFeature(Label $tooltipLabel, $text, $stayOnClick = false, $invert = false) + { + $tooltip = new Tooltip($this, $tooltipLabel, $stayOnClick, $invert, $text); + $this->addScriptFeature($tooltip); + return $this; + } + + /** + * Add a custom Control Script text part + * + * @api + * @param string $scriptText Script text + * @param string $label (optional) Script label name + * @return static + */ + public function addScriptText($scriptText, $label = ScriptLabel::MOUSECLICK) + { + $customText = new ControlScript($this, $scriptText, $label); + $this->addScriptFeature($customText); + return $this; + } + + /** + * @see Renderable::render() + */ + public function render(\DOMDocument $domDocument) + { + $domElement = $domDocument->createElement($this->getTagName()); + if ($this->controlId) { + $domElement->setAttribute("id", $this->controlId); + } + if ($this->posX || $this->posY) { + $domElement->setAttribute("pos", "{$this->posX} {$this->posY}"); + } + if ($this->posX || $this->posY || $this->posZ) { + // backwards-compatibility + $domElement->setAttribute("posn", "{$this->posX} {$this->posY} {$this->posZ}"); + } + if ($this->posZ) { + $domElement->setAttribute("z-index", $this->posZ); + } + if ($this->width > 0. || $this->height > 0.) { + $domElement->setAttribute("size", "{$this->width} {$this->height}"); + // backwards-compatibility + $domElement->setAttribute("sizen", "{$this->width} {$this->height}"); + if ($this->width > 0.) { + // backwards-compatibility + $domElement->setAttribute("width", $this->width); + } + if ($this->height > 0.) { + // backwards-compatibility + $domElement->setAttribute("height", $this->height); + } + } + if ($this->horizontalAlign) { + $domElement->setAttribute("halign", $this->horizontalAlign); + } + if ($this->verticalAlign) { + $domElement->setAttribute("valign", $this->verticalAlign); + } + if ($this->scale != 1.) { + $domElement->setAttribute("scale", $this->scale); + } + if (!$this->visible) { + $domElement->setAttribute("hidden", "1"); + } + if ($this->rotation) { + $domElement->setAttribute("rot", $this->rotation); + } + if ($this->classes) { + $classes = implode(" ", $this->classes); + $domElement->setAttribute("class", $classes); + } + foreach ($this->dataAttributes as $dataAttributeName => $dataAttributeValue) { + $domElement->setAttribute("data-" . $dataAttributeName, $dataAttributeValue); + } + return $domElement; + } + + /** + * Get the string representation + * + * @return string + */ + public function __toString() + { + $domDocument = new \DOMDocument("1.0", "utf-8"); + $domDocument->appendChild($this->render($domDocument)); + return $domDocument->saveXML($domDocument->documentElement); + } + + /** + * Get the tag name of the Control + * + * @return string + */ + abstract public function getTagName(); + + /** + * Get the ManiaScript class of the Control + * + * @return string + */ + abstract public function getManiaScriptClass(); } diff --git a/libs/FML/Controls/Entry.php b/libs/FML/Controls/Entry.php index 67258a6b..ceb535f3 100644 --- a/libs/FML/Controls/Entry.php +++ b/libs/FML/Controls/Entry.php @@ -43,8 +43,8 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF protected $selectText = null; /** - * @deprecated * @var bool $autoNewLine Auto new line + * @deprecated */ protected $autoNewLine = null; diff --git a/libs/FML/Controls/Frame.php b/libs/FML/Controls/Frame.php index 2ab8a5e8..c329606d 100644 --- a/libs/FML/Controls/Frame.php +++ b/libs/FML/Controls/Frame.php @@ -3,6 +3,7 @@ namespace FML\Controls; use FML\Elements\Format; +use FML\Stylesheet\Style; use FML\Types\Container; use FML\Types\Renderable; use FML\Types\ScriptFeatureable; @@ -25,6 +26,7 @@ class Frame extends Control implements Container /** * @var Format $format Format + * @deprecated */ protected $format = null; @@ -37,8 +39,8 @@ class Frame extends Control implements Container } /** - * @see Container::addChild() - * @deprecated use addChild() instead + * @deprecated Use addChild() + * @see Frame::addChild() */ public function add(Renderable $child) { @@ -67,6 +69,15 @@ class Frame extends Control implements Container return $this; } + /** + * @deprecated Use removeAllChildren() + * @see Frame::removeAllChildren() + */ + public function removeChildren() + { + return $this->removeAllChildren(); + } + /** * @see Container::removeAllChildren() */ @@ -77,15 +88,20 @@ class Frame extends Control implements Container } /** - * @see Container::getFormat() + * @deprecated Use Style + * @see Style */ - public function getFormat() + public function getFormat($createIfEmpty = true) { + if (!$this->format && $createIfEmpty) { + $this->setFormat(new Format()); + } return $this->format; } /** - * @see Container::setFormat() + * @deprecated Use Style + * @see Style */ public function setFormat(Format $format = null) { diff --git a/libs/FML/Controls/Frame3d.php b/libs/FML/Controls/Frame3d.php index 8449005e..2c84adec 100644 --- a/libs/FML/Controls/Frame3d.php +++ b/libs/FML/Controls/Frame3d.php @@ -19,16 +19,21 @@ class Frame3d extends Frame implements Scriptable /* * Constants */ - const STYLE_BaseStation = 'BaseStation'; - const STYLE_BaseBoxCase = 'BaseBoxCase'; - const STYLE_TitleLogo = 'Titlelogo'; - const STYLE_ButtonBack = 'ButtonBack'; - const STYLE_ButtonNav = 'ButtonNav'; - const STYLE_ButtonH = 'ButtonH'; - const STYLE_Station3x3 = 'Station3x3'; - const STYLE_Title = 'Title'; - const STYLE_TitleEditor = 'TitleEditor'; - const STYLE_Window = 'Window'; + const STYLE_BaseStation = "BaseStation"; + const STYLE_BaseBoxCase = "BaseBoxCase"; + const STYLE_TitleLogo = "TitleLogo"; + /** + * @deprecated Use STYLE_TitleLogo + * @see Frame3d::STYLE_TitleLogo + */ + const STYLE_Titlelogo = "Titlelogo"; + const STYLE_ButtonBack = "ButtonBack"; + const STYLE_ButtonNav = "ButtonNav"; + const STYLE_ButtonH = "ButtonH"; + const STYLE_Station3x3 = "Station3x3"; + const STYLE_Title = "Title"; + const STYLE_TitleEditor = "TitleEditor"; + const STYLE_Window = "Window"; /** * @var string $style3dId Style3d id diff --git a/libs/FML/Controls/FrameInstance.php b/libs/FML/Controls/FrameInstance.php index c4bf2200..cf9b0e74 100644 --- a/libs/FML/Controls/FrameInstance.php +++ b/libs/FML/Controls/FrameInstance.php @@ -25,6 +25,34 @@ class FrameInstance extends Control */ protected $model = null; + /** + * Create a new Frame Instance + * + * @api + * @param string $controlId (optional) Control Id + * @param string $modelId (optional) Model Id + * @return static + */ + public static function create($controlId = null, $modelId = null) + { + return new static($controlId, $modelId); + } + + /** + * Construct a new Frame Instance + * + * @api + * @param string $controlId (optional) Control Id + * @param string $modelId (optional) Model Id + */ + public function __construct($controlId = null, $modelId = null) + { + parent::__construct($controlId); + if ($modelId) { + $this->setModelId($modelId); + } + } + /** * Get the FrameModel id * diff --git a/libs/FML/Controls/Gauge.php b/libs/FML/Controls/Gauge.php index b3338eb5..632f4672 100644 --- a/libs/FML/Controls/Gauge.php +++ b/libs/FML/Controls/Gauge.php @@ -192,9 +192,10 @@ class Gauge extends Control implements Colorable, Styleable * Set draw background * * @api - * @param bool $drawBackground If the Gauges background should be drawn + * @param bool $drawBackground If the Gauge background should be drawn * @return static - * @deprecated use setDrawBackground() instead + * @deprecated Use setDrawBackground() + * @see Gauge::setDrawBackground() */ public function setDrawBg($drawBackground) { @@ -205,7 +206,7 @@ class Gauge extends Control implements Colorable, Styleable * Set draw background * * @api - * @param bool $drawBackground If the Gauges background should be drawn + * @param bool $drawBackground If the Gauge background should be drawn * @return static */ public function setDrawBackground($drawBackground) @@ -229,7 +230,7 @@ class Gauge extends Control implements Colorable, Styleable * Set draw block background * * @api - * @param bool $drawBlockBackground If the Gauges block background should be drawn + * @param bool $drawBlockBackground If the Gauge block background should be drawn * @return static */ public function setDrawBlockBackground($drawBlockBackground) @@ -280,7 +281,7 @@ class Gauge extends Control implements Colorable, Styleable if ($this->ratio) { $domElement->setAttribute("ratio", $this->ratio); } - if ($this->grading != 1.) { + if ($this->grading !== 1.) { $domElement->setAttribute("grading", $this->grading); } if ($this->color) { diff --git a/libs/FML/Controls/Label.php b/libs/FML/Controls/Label.php index 5bcd9532..0462ba28 100644 --- a/libs/FML/Controls/Label.php +++ b/libs/FML/Controls/Label.php @@ -95,7 +95,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, MultiL /** * @var float $lineSpacing Line spacing */ - protected $lineSpacing = -1.; + protected $lineSpacing = 1.; /** * @var bool $scriptEvents Script events usage @@ -669,7 +669,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, MultiL if ($this->autoNewLine) { $domElement->setAttribute("autonewline", $this->autoNewLine); } - if ($this->lineSpacing) { + if ($this->lineSpacing !== 1.) { $domElement->setAttribute("linespacing", $this->lineSpacing); } if ($this->maxLines > 0) { diff --git a/libs/FML/Controls/Quad.php b/libs/FML/Controls/Quad.php index 9064201f..96de66e6 100644 --- a/libs/FML/Controls/Quad.php +++ b/libs/FML/Controls/Quad.php @@ -2,8 +2,10 @@ namespace FML\Controls; +use FML\Components\CheckBoxDesign; use FML\Types\Actionable; use FML\Types\BackgroundColorable; +use FML\Types\BgColorable; use FML\Types\Imageable; use FML\Types\Linkable; use FML\Types\Scriptable; @@ -18,7 +20,7 @@ use FML\Types\SubStyleable; * @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ -class Quad extends Control implements Actionable, BackgroundColorable, Imageable, Linkable, Scriptable, Styleable, SubStyleable +class Quad extends Control implements Actionable, BackgroundColorable, BgColorable, Imageable, Linkable, Scriptable, Styleable, SubStyleable { /* @@ -83,6 +85,11 @@ class Quad extends Control implements Actionable, BackgroundColorable, Imageable */ protected $backgroundColor = null; + /** + * @var string $focusBackgroundColor Focus background color + */ + protected $focusBackgroundColor = null; + /** * @var string $action Action name */ @@ -152,7 +159,8 @@ class Quad extends Control implements Actionable, BackgroundColorable, Imageable } /** - * @deprecated use setImageUrl() instead + * @deprecated Use setImageUrl() + * @see Quad::setImageUrl() */ public function setImage($imageUrl) { @@ -204,9 +212,13 @@ class Quad extends Control implements Actionable, BackgroundColorable, Imageable } /** - * @param $imageFocusUrl - * @return \FML\Controls\Quad - * @deprecated + * Set the focus image url + * + * @api + * @param string $imageFocusUrl Focus image url + * @return static + * @deprecated Use setImageFocusUrl() + * @see Quad::setImageFocusUrl() */ public function setImageFocus($imageFocusUrl) { @@ -403,7 +415,7 @@ class Quad extends Control implements Actionable, BackgroundColorable, Imageable } /** - * @see BackgroundColorable::setBgColor() + * @see BackgroundColorable::setBackgroundColor() */ public function setBackgroundColor($backgroundColor) { @@ -411,6 +423,32 @@ class Quad extends Control implements Actionable, BackgroundColorable, Imageable return $this; } + /** + * @deprecated Use setBackgroundColor() + * @see Quad::setBackgroundColor() + */ + public function setBgColor($bgColor) + { + return $this->setBackgroundColor($bgColor); + } + + /** + * @see BackgroundColorable::getFocusBackgroundColor() + */ + public function getFocusBackgroundColor() + { + return $this->focusBackgroundColor; + } + + /** + * @see BackgroundColorable::setFocusBackgroundColor() + */ + public function setFocusBackgroundColor($focusBackgroundColor) + { + $this->focusBackgroundColor = (string)$focusBackgroundColor; + return $this; + } + /** * @see Actionable::getAction() */ @@ -632,6 +670,19 @@ class Quad extends Control implements Actionable, BackgroundColorable, Imageable return $this; } + /** + * Apply the CheckBox Design + * + * @api + * @param CheckBoxDesign $checkBoxDesign CheckBox Design + * @return static + */ + public function applyCheckBoxDesign(CheckBoxDesign $checkBoxDesign) + { + $checkBoxDesign->applyToQuad($this); + return $this; + } + /** * @see Control::getTagName() */ @@ -687,6 +738,9 @@ class Quad extends Control implements Actionable, BackgroundColorable, Imageable if ($this->backgroundColor) { $domElement->setAttribute("bgcolor", $this->backgroundColor); } + if ($this->focusBackgroundColor) { + $domElement->setAttribute("bgcolorfocus", $this->focusBackgroundColor); + } if ($this->action) { $domElement->setAttribute("action", $this->action); } diff --git a/libs/FML/Controls/TextEdit.php b/libs/FML/Controls/TextEdit.php index e1241e05..fe3008f9 100644 --- a/libs/FML/Controls/TextEdit.php +++ b/libs/FML/Controls/TextEdit.php @@ -39,7 +39,7 @@ class TextEdit extends Control implements MultiLineable, Scriptable, Styleable, /** * @var float $lineSpacing Line spacing */ - protected $lineSpacing = -1.; + protected $lineSpacing = 1.; /** * @var int $maxLines Maximum number of lines @@ -406,7 +406,7 @@ class TextEdit extends Control implements MultiLineable, Scriptable, Styleable, if ($this->autoNewLine) { $domElement->setAttribute("autonewline", 1); } - if ($this->lineSpacing > 0) { + if ($this->lineSpacing !== 1.) { $domElement->setAttribute("linespacing", $this->lineSpacing); } if ($this->maxLines > 0) { diff --git a/libs/FML/Elements/Dico.php b/libs/FML/Elements/Dico.php index a7f809c5..6acd87b4 100644 --- a/libs/FML/Elements/Dico.php +++ b/libs/FML/Elements/Dico.php @@ -215,15 +215,19 @@ class Dico * Remove entries of the given id * * @api - * @param string $entryId Entry id that should be removed + * @param string $entryId Entry id that should be removed + * @param string $language (optional) Only remove entry from the given language * @return static */ - public function removeEntry($entryId) + public function removeEntry($entryId, $language = null) { $entryId = (string)$entryId; - foreach ($this->entries as $language => $entries) { - if (isset($this->entries[$language][$entryId])) { - unset($this->entries[$language][$entryId]); + foreach ($this->entries as $languageKey => $entries) { + if ($language && $language !== $languageKey) { + continue; + } + if (isset($this->entries[$languageKey][$entryId])) { + unset($this->entries[$languageKey][$entryId]); } } return $this; @@ -245,6 +249,19 @@ class Dico return $this; } + /** + * Remove entries + * + * @api + * @return static + * @deprecated Use removeAllEntries() + * @see Dico::removeAllEntries() + */ + public function removeEntries() + { + return $this->removeAllEntries(); + } + /** * Remove all entries * diff --git a/libs/FML/Elements/Format.php b/libs/FML/Elements/Format.php index 3631e434..0b312a49 100644 --- a/libs/FML/Elements/Format.php +++ b/libs/FML/Elements/Format.php @@ -2,7 +2,9 @@ namespace FML\Elements; +use FML\Stylesheet\Style; use FML\Types\BackgroundColorable; +use FML\Types\BgColorable; use FML\Types\Renderable; use FML\Types\Styleable; use FML\Types\TextFormatable; @@ -10,11 +12,13 @@ use FML\Types\TextFormatable; /** * Format Element * - * @author steeffeen - * @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder - * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + * @author steeffeen + * @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + * @deprecated Use Style + * @see Style */ -class Format implements BackgroundColorable, Renderable, Styleable, TextFormatable +class Format implements BackgroundColorable, BgColorable, Renderable, Styleable, TextFormatable { /** @@ -22,6 +26,11 @@ class Format implements BackgroundColorable, Renderable, Styleable, TextFormatab */ protected $backgroundColor = null; + /** + * @var string $focusBackgroundColor Focus background color + */ + protected $focusBackgroundColor = null; + /** * @var string $style Style */ @@ -64,7 +73,7 @@ class Format implements BackgroundColorable, Renderable, Styleable, TextFormatab } /** - * @see BgColorable::getBackgroundColor() + * @see BackgroundColorable::getBackgroundColor() */ public function getBackgroundColor() { @@ -72,7 +81,7 @@ class Format implements BackgroundColorable, Renderable, Styleable, TextFormatab } /** - * @see BgColorable::setBackgroundColor() + * @see BackgroundColorable::setBackgroundColor() */ public function setBackgroundColor($backgroundColor) { @@ -80,6 +89,32 @@ class Format implements BackgroundColorable, Renderable, Styleable, TextFormatab return $this; } + /** + * @deprecated Use setBackgroundColor() + * @see Format::setBackgroundColor() + */ + public function setBgColor($bgColor) + { + return $this->setBackgroundColor($bgColor); + } + + /** + * @see BackgroundColorable::getFocusBackgroundColor() + */ + public function getFocusBackgroundColor() + { + return $this->focusBackgroundColor; + } + + /** + * @see BackgroundColorable::setFocusBackgroundColor() + */ + public function setFocusBackgroundColor($focusBackgroundColor) + { + $this->focusBackgroundColor = (string)$focusBackgroundColor; + return $this; + } + /** * @see Styleable::getStyle() */ @@ -191,6 +226,9 @@ class Format implements BackgroundColorable, Renderable, Styleable, TextFormatab if ($this->backgroundColor) { $domElement->setAttribute("bgcolor", $this->backgroundColor); } + if ($this->focusBackgroundColor) { + $domElement->setAttribute("bgcolorfocus", $this->focusBackgroundColor); + } if ($this->style) { $domElement->setAttribute("style", $this->style); } diff --git a/libs/FML/Elements/FrameModel.php b/libs/FML/Elements/FrameModel.php index 152a5c37..90b52b34 100644 --- a/libs/FML/Elements/FrameModel.php +++ b/libs/FML/Elements/FrameModel.php @@ -2,6 +2,7 @@ namespace FML\Elements; +use FML\Stylesheet\Style; use FML\Types\Container; use FML\Types\Identifiable; use FML\Types\Renderable; @@ -113,14 +114,23 @@ class FrameModel implements Container, Identifiable, Renderable /** * @see Container::addChild() */ - public function addChild(Renderable $childElement) + public function addChild(Renderable $child) { - if (!in_array($childElement, $this->children, true)) { - array_push($this->children, $childElement); + if (!in_array($child, $this->children, true)) { + array_push($this->children, $child); } return $this; } + /** + * @deprecated Use addChild() + * @see FrameModel::addChild() + */ + public function add(Renderable $child) + { + return $this->addChild($child); + } + /** * @see Container::addChildren() */ @@ -142,15 +152,29 @@ class FrameModel implements Container, Identifiable, Renderable } /** - * @see Container::getFormat() + * @deprecated Use removeAllChildren() + * @see FrameModel::removeAllChildren() */ - public function getFormat() + public function removeChildren() { + return $this->removeAllChildren(); + } + + /** + * @deprecated Use Style + * @see Style + */ + public function getFormat($createIfEmpty = true) + { + if (!$this->format && $createIfEmpty) { + $this->setFormat(new Format()); + } return $this->format; } /** - * @see Container::setFormat() + * @deprecated Use Style + * @see Style */ public function setFormat(Format $format = null) { diff --git a/libs/FML/ManiaCode.php b/libs/FML/ManiaCode.php index 532c6a1d..9b17f5f2 100644 --- a/libs/FML/ManiaCode.php +++ b/libs/FML/ManiaCode.php @@ -232,12 +232,13 @@ class ManiaCode * Join a server * * @api - * @param string $login Server login + * @param string $loginOrIp (optional) Server login or ip + * @param int $port (optional) Server port * @return static */ - public function addJoinServer($login) + public function addJoinServer($loginOrIp = null, $port = null) { - $serverElement = new JoinServer($login); + $serverElement = new JoinServer($loginOrIp, $port); return $this->addElement($serverElement); } @@ -245,12 +246,13 @@ class ManiaCode * Add a server as favorite * * @api - * @param string $login Server login + * @param string $loginOrIp (optional) Server login or ip + * @param int $port (optional) Server port * @return static */ - public function addAddFavorite($login) + public function addAddFavorite($loginOrIp = null, $port = null) { - $favoriteElement = new AddFavorite($login); + $favoriteElement = new AddFavorite($loginOrIp, $port); return $this->addElement($favoriteElement); } @@ -311,15 +313,18 @@ class ManiaCode } /** - * Remove all ManiaCode Elements + * Add ManiaCode Elements * * @api + * @param Element[] $elements Elements to add * @return static - * @deprecated use removeAllElements() instead */ - public function removeElements() + public function addElements(array $elements) { - return $this->removeAllElements(); + foreach ($elements as $element) { + $this->addElement($element); + } + return $this; } /** @@ -334,6 +339,19 @@ class ManiaCode return $this; } + /** + * Remove all ManiaCode Elements + * + * @api + * @return static + * @deprecated Use removeAllElements() + * @see ManiaCode::removeAllElements() + */ + public function removeElements() + { + return $this->removeAllElements(); + } + /** * Render the ManiaCode * diff --git a/libs/FML/ManiaLink.php b/libs/FML/ManiaLink.php index 0e9c622c..b3bffc2e 100644 --- a/libs/FML/ManiaLink.php +++ b/libs/FML/ManiaLink.php @@ -21,7 +21,10 @@ class ManiaLink /* * Constants */ - const MANIALINK_VERSION = 3; + const VERSION_0 = 0; + const VERSION_1 = 1; + const VERSION_2 = 2; + const VERSION_3 = 3; const BACKGROUND_0 = "0"; const BACKGROUND_1 = "1"; const BACKGROUND_STARS = "stars"; @@ -36,7 +39,7 @@ class ManiaLink /** * @var int $version ManiaLink version */ - protected $version = 1; + protected $version = 0; /** * @var string $name ManiaLink name @@ -88,7 +91,7 @@ class ManiaLink * @param Renderable[] $children (optional) Children * @return static */ - public static function create($maniaLinkId = null, $version = null, $name = null, array $children = null) + public static function create($maniaLinkId = null, $version = ManiaLink::VERSION_1, $name = null, array $children = null) { return new static($maniaLinkId, $version, $name, $children); } @@ -102,18 +105,17 @@ class ManiaLink * @param string $name (optional) Name * @param Renderable[] $children (optional) Children */ - public function __construct($maniaLinkId = null, $version = null, $name = null, array $children = null) + public function __construct($maniaLinkId = null, $version = ManiaLink::VERSION_3, $name = null, array $children = null) { - if (is_string($version)) { + if (is_string($version) && (!$name || is_array($name)) && !$children) { // backwards-compatibility (version has been introduced later) $children = $name; $name = $version; - $version = null; + $version = ManiaLink::VERSION_3; } if ($maniaLinkId) { $this->setId($maniaLinkId); } - $this->setVersion(self::MANIALINK_VERSION); if ($version) { $this->setVersion($version); } @@ -123,7 +125,6 @@ class ManiaLink if ($children) { $this->setChildren($children); } - $this->createScript(); } /** @@ -290,7 +291,8 @@ class ManiaLink * @api * @param Renderable $child Child Element to add * @return static - * @deprecated use addChild() instead + * @deprecated Use addChild() + * @see ManiaLink::addChild() */ public function add(Renderable $child) { @@ -312,6 +314,21 @@ class ManiaLink return $this; } + /** + * Add children + * + * @api + * @param Renderable[] $children Child Elements to add + * @return static + */ + public function addChildren(array $children) + { + foreach ($children as $child) { + $this->addChild($child); + } + return $this; + } + /** * Set children * @@ -321,11 +338,8 @@ class ManiaLink */ public function setChildren(array $children) { - $this->children = array(); - foreach ($children as $child) { - $this->addChild($child); - } - return $this; + return $this->removeAllChildren() + ->addChildren($children); } /** @@ -333,7 +347,8 @@ class ManiaLink * * @api * @return static - * @deprecated use removeAllChildren() instead + * @deprecated Use removeAllChildren() + * @see ManiaLink::removeAllChildren() */ public function removeChildren() { @@ -356,10 +371,14 @@ class ManiaLink * Get the Dictionary * * @api + * @param bool $createIfEmpty (optional) If the Dico should be created if it doesn't exist yet * @return Dico */ - public function getDico() + public function getDico($createIfEmpty = true) { + if (!$this->dico && $createIfEmpty) { + $this->setDico(new Dico()); + } return $this->dico; } @@ -382,8 +401,11 @@ class ManiaLink * @api * @return Stylesheet */ - public function getStylesheet() + public function getStylesheet($createIfEmpty = true) { + if (!$this->stylesheet && $createIfEmpty) { + return $this->createStylesheet(); + } return $this->stylesheet; } @@ -400,14 +422,34 @@ class ManiaLink return $this; } + /** + * Create and assign a new Stylesheet if necessary + * + * @api + * @return Stylesheet + */ + public function createStylesheet() + { + if ($this->stylesheet) { + return $this->stylesheet; + } + $stylesheet = new Stylesheet(); + $this->setStylesheet($stylesheet); + return $this->stylesheet; + } + /** * Get the Script * * @api + * @param bool $createIfEmpty (optional) Create the script if it's not set yet * @return Script */ - public function getScript() + public function getScript($createIfEmpty = true) { + if (!$this->script && $createIfEmpty) { + return $this->createScript(); + } return $this->script; } diff --git a/libs/FML/ManiaLinks.php b/libs/FML/ManiaLinks.php index 44dc2cf9..9a1a96b1 100644 --- a/libs/FML/ManiaLinks.php +++ b/libs/FML/ManiaLinks.php @@ -64,7 +64,8 @@ class ManiaLinks * @api * @param ManiaLink $child Child ManiaLink * @return static - * @deprecated use addChild() instead + * @deprecated Use addChild() + * @see ManiaLinks::addChild() */ public function add(ManiaLink $child) { @@ -86,6 +87,21 @@ class ManiaLinks return $this; } + /** + * Add child ManiaLinks + * + * @api + * @param ManiaLink[] $children Child ManiaLinks + * @return static + */ + public function addChildren(array $children) + { + foreach ($children as $child) { + $this->addChild($child); + } + return $this; + } + /** * Set ManiaLink children * @@ -95,23 +111,8 @@ class ManiaLinks */ public function setChildren(array $children) { - $this->children = array(); - foreach ($children as $child) { - $this->addChild($child); - } - return $this; - } - - /** - * Remove all child ManiaLinks - * - * @api - * @return static - * @deprecated use removeAllChildren instead - */ - public function removeChildren() - { - return $this->removeAllChildren(); + return $this->removeAllChildren() + ->addChildren($children); } /** @@ -126,14 +127,31 @@ class ManiaLinks return $this; } + /** + * Remove all child ManiaLinks + * + * @api + * @return static + * @deprecated Use removeAllChildren() + * @see ManiaLinks::removeAllChildren() + */ + public function removeChildren() + { + return $this->removeAllChildren(); + } + /** * Get the CustomUI * * @api + * @param bool $createIfEmpty (optional) If the Custom UI should be created if it doesn't exist yet * @return CustomUI */ - public function getCustomUI() + public function getCustomUI($createIfEmpty = true) { + if (!$this->customUI && $createIfEmpty) { + $this->setCustomUI(new CustomUI()); + } return $this->customUI; } diff --git a/libs/FML/Script/Features/ControlScript.php b/libs/FML/Script/Features/ControlScript.php index 1bd2ab29..f4103196 100644 --- a/libs/FML/Script/Features/ControlScript.php +++ b/libs/FML/Script/Features/ControlScript.php @@ -75,6 +75,7 @@ class ControlScript extends ScriptFeature public function setControl(Control $control) { $control->checkId(); + $control->addScriptFeature($this); $this->control = $control; $this->updateScriptEvents(); return $this; @@ -104,6 +105,20 @@ class ControlScript extends ScriptFeature return $this; } + /** + * Set the script text + * + * @api + * @param string $text Text + * @return static + * @deprecated Use setScriptText() + * @see ControlScript::setScriptText() + */ + public function setText($text) + { + return $this->setScriptText($text); + } + /** * Get the Script Label name * @@ -174,8 +189,8 @@ declare Control <=> Event.Control;"; $scriptText .= " declare Control <=> Page.GetFirstChild({$controlId});"; } - $class = $this->control->getManiaScriptClass(); - $name = preg_replace('/^CMl/', '', $class, 1); + $class = $this->control->getManiaScriptClass(); + $name = preg_replace('/^CMl/', '', $class, 1); $scriptText .= " declare {$name} <=> (Control as {$class}); "; diff --git a/libs/FML/Script/Script.php b/libs/FML/Script/Script.php index fbb7d1a7..6498a897 100644 --- a/libs/FML/Script/Script.php +++ b/libs/FML/Script/Script.php @@ -18,19 +18,38 @@ class Script * Constants */ const TICKINTERVAL = 250; - const VAR_ScriptStart = 'FML_ScriptStart'; - const VAR_LoopCounter = 'FML_LoopCounter'; - const VAR_LastTick = 'FML_LastTick'; + const VAR_ScriptStart = "FML_ScriptStart"; + const VAR_LoopCounter = "FML_LoopCounter"; + const VAR_LastTick = "FML_LastTick"; - /* - * Protected properties + /** + * @var ScriptFeature[] $features Script Features */ - protected $tagName = 'script'; protected $features = array(); + + /** + * @var ScriptInclude[] $includes Script Includes + */ protected $includes = array(); + + /** + * @var ScriptConstant[] $constants Script Constants + */ protected $constants = array(); + + /** + * @var ScriptFunction[] $functions Script Functions + */ protected $functions = array(); + + /** + * @var ScriptLabel[] $customLabels Custom Script Labels + */ protected $customLabels = array(); + + /** + * @var ScriptLabel[] $genericLabels Generic Script Labels + */ protected $genericLabels = array(); /** @@ -229,10 +248,13 @@ class Script public function render(\DOMDocument $domDocument) { $this->loadFeatures($this->features); - $scriptXml = $domDocument->createElement($this->tagName); - $scriptText = $this->buildScriptText(); + + $scriptXml = $domDocument->createElement("script"); + $scriptText = $this->buildScriptText(); + $scriptComment = $domDocument->createComment($scriptText); $scriptXml->appendChild($scriptComment); + return $scriptXml; } diff --git a/libs/FML/Stylesheet/Stylesheet.php b/libs/FML/Stylesheet/Stylesheet.php index 40865290..617c0eaa 100644 --- a/libs/FML/Stylesheet/Stylesheet.php +++ b/libs/FML/Stylesheet/Stylesheet.php @@ -12,6 +12,11 @@ namespace FML\Stylesheet; class Stylesheet { + /** + * @var Style[] $styles Styles + */ + protected $styles = array(); + /** * @var Style3d[] $styles3d 3d Styles */ @@ -33,6 +38,44 @@ class Stylesheet return new static(); } + /** + * Get the Styles + * + * @api + * @return Style[] + */ + public function getStyles() + { + return $this->styles; + } + + /** + * Add a new Style + * + * @api + * @param Style $style The Style to be added + * @return static + */ + public function addStyle(Style $style) + { + if (!in_array($style, $this->styles, true)) { + array_push($this->styles, $style); + } + return $this; + } + + /** + * Remove all Styles + * + * @api + * @return static + */ + public function removeAllStyles() + { + $this->styles = array(); + return $this; + } + /** * Get the Styles3d * @@ -71,14 +114,32 @@ class Stylesheet return $this; } + /** + * Remove all Style3ds + * + * @api + * @return static + * @deprecated Use removeAllStyles3d() + * @see Stylesheet::removeAllStyles3d() + */ + public function removeStyles() + { + return $this->removeAllStyles() + ->removeAllStyles3d(); + } + /** * Get the Mood * * @api + * @param bool $createIfEmpty (optional) If the Mood should be created if it doesn't exist yet * @return Mood */ - public function getMood() + public function getMood($createIfEmpty = true) { + if (!$this->mood && $createIfEmpty) { + $this->createMood(); + } return $this->mood; } diff --git a/libs/FML/Types/BackgroundColorable.php b/libs/FML/Types/BackgroundColorable.php index 191f2dc8..7a518d13 100644 --- a/libs/FML/Types/BackgroundColorable.php +++ b/libs/FML/Types/BackgroundColorable.php @@ -29,4 +29,21 @@ interface BackgroundColorable */ public function setBackgroundColor($backgroundColor); + /** + * Get the focus background color + * + * @api + * @return string + */ + public function getFocusBackgroundColor(); + + /** + * Set the focus background color + * + * @api + * @param string $focusBackgroundColor Focus background color + * @return static + */ + public function setFocusBackgroundColor($focusBackgroundColor); + } diff --git a/libs/FML/Types/Container.php b/libs/FML/Types/Container.php index 51f58553..922ef595 100644 --- a/libs/FML/Types/Container.php +++ b/libs/FML/Types/Container.php @@ -3,6 +3,7 @@ namespace FML\Types; use FML\Elements\Format; +use FML\Stylesheet\Style; /** * Interface for Element being able to contain other Controls @@ -31,6 +32,17 @@ interface Container */ public function addChild(Renderable $child); + /** + * Add a new child + * + * @api + * @param Renderable $child Child Control to add + * @return static + * @deprecated Use addChild() + * @see Container::addChild() + */ + public function add(Renderable $child); + /** * Add new children * @@ -48,13 +60,26 @@ interface Container */ public function removeAllChildren(); + /** + * Remove all children + * + * @api + * @return static + * @deprecated Use removeAllChildren() + * @see Container::removeAllChildren() + */ + public function removeChildren(); + /** * Get the Format * * @api + * @param bool $createIfEmpty If the format should be created if it doesn't exist yet * @return Format + * @deprecated Use Style + * @see Style */ - public function getFormat(); + public function getFormat($createIfEmpty = true); /** * Set the Format @@ -62,6 +87,8 @@ interface Container * @api * @param Format $format New Format * @return static + * @deprecated Use Style + * @see Style */ public function setFormat(Format $format = null); diff --git a/libs/FML/Types/NewLineable.php b/libs/FML/Types/NewLineable.php index 1c72a594..e697ab89 100644 --- a/libs/FML/Types/NewLineable.php +++ b/libs/FML/Types/NewLineable.php @@ -18,8 +18,9 @@ interface NewLineable * Get auto new line * * @api - * @deprecated * @return bool + * @deprecated Use MultiLineable::getAutoNewLine() + * @see MultiLineable::getAutoNewLine() */ public function getAutoNewLine(); @@ -27,9 +28,10 @@ interface NewLineable * Set auto new line * * @api - * @deprecated * @param bool $autoNewLine If the Element should insert new lines automatically * @return static + * @deprecated Use MultiLineable::setAutoNewLine() + * @see MultiLineable::setAutoNewLine() */ public function setAutoNewLine($autoNewLine);