Updated FML to newest version

This commit is contained in:
Jocy 2017-04-02 16:32:57 +02:00
parent 83710a9269
commit c5926aded2
21 changed files with 1425 additions and 995 deletions

View File

@ -60,12 +60,12 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable
/** /**
* @var float $width Width * @var float $width Width
*/ */
protected $width = -1.; protected $width = 0.;
/** /**
* @var float $height Height * @var float $height Height
*/ */
protected $height = -1.; protected $height = 0.;
/** /**
* @var string $horizontalAlign Horizontal alignment * @var string $horizontalAlign Horizontal alignment
@ -411,6 +411,19 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable
return $this->setAlign(self::CENTER, self::CENTER2); 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 * Clear the alignment
* *
@ -862,15 +875,15 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable
if ($this->posZ) { if ($this->posZ) {
$domElement->setAttribute("z-index", $this->posZ); $domElement->setAttribute("z-index", $this->posZ);
} }
if ($this->width >= 0. || $this->height >= 0.) { if ($this->width > 0. || $this->height > 0.) {
$domElement->setAttribute("size", "{$this->width} {$this->height}"); $domElement->setAttribute("size", "{$this->width} {$this->height}");
// backwards-compatibility // backwards-compatibility
$domElement->setAttribute("sizen", "{$this->width} {$this->height}"); $domElement->setAttribute("sizen", "{$this->width} {$this->height}");
if ($this->width >= 0.) { if ($this->width > 0.) {
// backwards-compatibility // backwards-compatibility
$domElement->setAttribute("width", $this->width); $domElement->setAttribute("width", $this->width);
} }
if ($this->height >= 0.) { if ($this->height > 0.) {
// backwards-compatibility // backwards-compatibility
$domElement->setAttribute("height", $this->height); $domElement->setAttribute("height", $this->height);
} }
@ -900,6 +913,18 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable
return $domElement; 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 * Get the tag name of the Control
* *

View File

@ -43,8 +43,8 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF
protected $selectText = null; protected $selectText = null;
/** /**
* @deprecated
* @var bool $autoNewLine Auto new line * @var bool $autoNewLine Auto new line
* @deprecated
*/ */
protected $autoNewLine = null; protected $autoNewLine = null;

View File

@ -3,6 +3,7 @@
namespace FML\Controls; namespace FML\Controls;
use FML\Elements\Format; use FML\Elements\Format;
use FML\Stylesheet\Style;
use FML\Types\Container; use FML\Types\Container;
use FML\Types\Renderable; use FML\Types\Renderable;
use FML\Types\ScriptFeatureable; use FML\Types\ScriptFeatureable;
@ -25,6 +26,7 @@ class Frame extends Control implements Container
/** /**
* @var Format $format Format * @var Format $format Format
* @deprecated
*/ */
protected $format = null; protected $format = null;
@ -37,8 +39,8 @@ class Frame extends Control implements Container
} }
/** /**
* @see Container::addChild() * @deprecated Use addChild()
* @deprecated use addChild() instead * @see Frame::addChild()
*/ */
public function add(Renderable $child) public function add(Renderable $child)
{ {
@ -67,6 +69,15 @@ class Frame extends Control implements Container
return $this; return $this;
} }
/**
* @deprecated Use removeAllChildren()
* @see Frame::removeAllChildren()
*/
public function removeChildren()
{
return $this->removeAllChildren();
}
/** /**
* @see Container::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; return $this->format;
} }
/** /**
* @see Container::setFormat() * @deprecated Use Style
* @see Style
*/ */
public function setFormat(Format $format = null) public function setFormat(Format $format = null)
{ {

View File

@ -19,16 +19,21 @@ class Frame3d extends Frame implements Scriptable
/* /*
* Constants * Constants
*/ */
const STYLE_BaseStation = 'BaseStation'; const STYLE_BaseStation = "BaseStation";
const STYLE_BaseBoxCase = 'BaseBoxCase'; const STYLE_BaseBoxCase = "BaseBoxCase";
const STYLE_TitleLogo = 'Titlelogo'; const STYLE_TitleLogo = "TitleLogo";
const STYLE_ButtonBack = 'ButtonBack'; /**
const STYLE_ButtonNav = 'ButtonNav'; * @deprecated Use STYLE_TitleLogo
const STYLE_ButtonH = 'ButtonH'; * @see Frame3d::STYLE_TitleLogo
const STYLE_Station3x3 = 'Station3x3'; */
const STYLE_Title = 'Title'; const STYLE_Titlelogo = "Titlelogo";
const STYLE_TitleEditor = 'TitleEditor'; const STYLE_ButtonBack = "ButtonBack";
const STYLE_Window = 'Window'; 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 * @var string $style3dId Style3d id

View File

@ -25,6 +25,34 @@ class FrameInstance extends Control
*/ */
protected $model = null; 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 * Get the FrameModel id
* *

View File

@ -192,9 +192,10 @@ class Gauge extends Control implements Colorable, Styleable
* Set draw background * Set draw background
* *
* @api * @api
* @param bool $drawBackground If the Gauges background should be drawn * @param bool $drawBackground If the Gauge background should be drawn
* @return static * @return static
* @deprecated use setDrawBackground() instead * @deprecated Use setDrawBackground()
* @see Gauge::setDrawBackground()
*/ */
public function setDrawBg($drawBackground) public function setDrawBg($drawBackground)
{ {
@ -205,7 +206,7 @@ class Gauge extends Control implements Colorable, Styleable
* Set draw background * Set draw background
* *
* @api * @api
* @param bool $drawBackground If the Gauges background should be drawn * @param bool $drawBackground If the Gauge background should be drawn
* @return static * @return static
*/ */
public function setDrawBackground($drawBackground) public function setDrawBackground($drawBackground)
@ -229,7 +230,7 @@ class Gauge extends Control implements Colorable, Styleable
* Set draw block background * Set draw block background
* *
* @api * @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 * @return static
*/ */
public function setDrawBlockBackground($drawBlockBackground) public function setDrawBlockBackground($drawBlockBackground)
@ -280,7 +281,7 @@ class Gauge extends Control implements Colorable, Styleable
if ($this->ratio) { if ($this->ratio) {
$domElement->setAttribute("ratio", $this->ratio); $domElement->setAttribute("ratio", $this->ratio);
} }
if ($this->grading != 1.) { if ($this->grading !== 1.) {
$domElement->setAttribute("grading", $this->grading); $domElement->setAttribute("grading", $this->grading);
} }
if ($this->color) { if ($this->color) {

View File

@ -95,7 +95,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, MultiL
/** /**
* @var float $lineSpacing Line spacing * @var float $lineSpacing Line spacing
*/ */
protected $lineSpacing = -1.; protected $lineSpacing = 1.;
/** /**
* @var bool $scriptEvents Script events usage * @var bool $scriptEvents Script events usage
@ -669,7 +669,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, MultiL
if ($this->autoNewLine) { if ($this->autoNewLine) {
$domElement->setAttribute("autonewline", $this->autoNewLine); $domElement->setAttribute("autonewline", $this->autoNewLine);
} }
if ($this->lineSpacing) { if ($this->lineSpacing !== 1.) {
$domElement->setAttribute("linespacing", $this->lineSpacing); $domElement->setAttribute("linespacing", $this->lineSpacing);
} }
if ($this->maxLines > 0) { if ($this->maxLines > 0) {

View File

@ -2,8 +2,10 @@
namespace FML\Controls; namespace FML\Controls;
use FML\Components\CheckBoxDesign;
use FML\Types\Actionable; use FML\Types\Actionable;
use FML\Types\BackgroundColorable; use FML\Types\BackgroundColorable;
use FML\Types\BgColorable;
use FML\Types\Imageable; use FML\Types\Imageable;
use FML\Types\Linkable; use FML\Types\Linkable;
use FML\Types\Scriptable; use FML\Types\Scriptable;
@ -18,7 +20,7 @@ use FML\Types\SubStyleable;
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder * @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @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; protected $backgroundColor = null;
/**
* @var string $focusBackgroundColor Focus background color
*/
protected $focusBackgroundColor = null;
/** /**
* @var string $action Action name * @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) public function setImage($imageUrl)
{ {
@ -204,9 +212,13 @@ class Quad extends Control implements Actionable, BackgroundColorable, Imageable
} }
/** /**
* @param $imageFocusUrl * Set the focus image url
* @return \FML\Controls\Quad *
* @deprecated * @api
* @param string $imageFocusUrl Focus image url
* @return static
* @deprecated Use setImageFocusUrl()
* @see Quad::setImageFocusUrl()
*/ */
public function setImageFocus($imageFocusUrl) 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) public function setBackgroundColor($backgroundColor)
{ {
@ -411,6 +423,32 @@ class Quad extends Control implements Actionable, BackgroundColorable, Imageable
return $this; 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() * @see Actionable::getAction()
*/ */
@ -632,6 +670,19 @@ class Quad extends Control implements Actionable, BackgroundColorable, Imageable
return $this; 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() * @see Control::getTagName()
*/ */
@ -687,6 +738,9 @@ class Quad extends Control implements Actionable, BackgroundColorable, Imageable
if ($this->backgroundColor) { if ($this->backgroundColor) {
$domElement->setAttribute("bgcolor", $this->backgroundColor); $domElement->setAttribute("bgcolor", $this->backgroundColor);
} }
if ($this->focusBackgroundColor) {
$domElement->setAttribute("bgcolorfocus", $this->focusBackgroundColor);
}
if ($this->action) { if ($this->action) {
$domElement->setAttribute("action", $this->action); $domElement->setAttribute("action", $this->action);
} }

View File

@ -39,7 +39,7 @@ class TextEdit extends Control implements MultiLineable, Scriptable, Styleable,
/** /**
* @var float $lineSpacing Line spacing * @var float $lineSpacing Line spacing
*/ */
protected $lineSpacing = -1.; protected $lineSpacing = 1.;
/** /**
* @var int $maxLines Maximum number of lines * @var int $maxLines Maximum number of lines
@ -406,7 +406,7 @@ class TextEdit extends Control implements MultiLineable, Scriptable, Styleable,
if ($this->autoNewLine) { if ($this->autoNewLine) {
$domElement->setAttribute("autonewline", 1); $domElement->setAttribute("autonewline", 1);
} }
if ($this->lineSpacing > 0) { if ($this->lineSpacing !== 1.) {
$domElement->setAttribute("linespacing", $this->lineSpacing); $domElement->setAttribute("linespacing", $this->lineSpacing);
} }
if ($this->maxLines > 0) { if ($this->maxLines > 0) {

View File

@ -216,14 +216,18 @@ class Dico
* *
* @api * @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 * @return static
*/ */
public function removeEntry($entryId) public function removeEntry($entryId, $language = null)
{ {
$entryId = (string)$entryId; $entryId = (string)$entryId;
foreach ($this->entries as $language => $entries) { foreach ($this->entries as $languageKey => $entries) {
if (isset($this->entries[$language][$entryId])) { if ($language && $language !== $languageKey) {
unset($this->entries[$language][$entryId]); continue;
}
if (isset($this->entries[$languageKey][$entryId])) {
unset($this->entries[$languageKey][$entryId]);
} }
} }
return $this; return $this;
@ -245,6 +249,19 @@ class Dico
return $this; return $this;
} }
/**
* Remove entries
*
* @api
* @return static
* @deprecated Use removeAllEntries()
* @see Dico::removeAllEntries()
*/
public function removeEntries()
{
return $this->removeAllEntries();
}
/** /**
* Remove all entries * Remove all entries
* *

View File

@ -2,7 +2,9 @@
namespace FML\Elements; namespace FML\Elements;
use FML\Stylesheet\Style;
use FML\Types\BackgroundColorable; use FML\Types\BackgroundColorable;
use FML\Types\BgColorable;
use FML\Types\Renderable; use FML\Types\Renderable;
use FML\Types\Styleable; use FML\Types\Styleable;
use FML\Types\TextFormatable; use FML\Types\TextFormatable;
@ -13,8 +15,10 @@ use FML\Types\TextFormatable;
* @author steeffeen <mail@steeffeen.com> * @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder * @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @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; protected $backgroundColor = null;
/**
* @var string $focusBackgroundColor Focus background color
*/
protected $focusBackgroundColor = null;
/** /**
* @var string $style Style * @var string $style Style
*/ */
@ -64,7 +73,7 @@ class Format implements BackgroundColorable, Renderable, Styleable, TextFormatab
} }
/** /**
* @see BgColorable::getBackgroundColor() * @see BackgroundColorable::getBackgroundColor()
*/ */
public function 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) public function setBackgroundColor($backgroundColor)
{ {
@ -80,6 +89,32 @@ class Format implements BackgroundColorable, Renderable, Styleable, TextFormatab
return $this; 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() * @see Styleable::getStyle()
*/ */
@ -191,6 +226,9 @@ class Format implements BackgroundColorable, Renderable, Styleable, TextFormatab
if ($this->backgroundColor) { if ($this->backgroundColor) {
$domElement->setAttribute("bgcolor", $this->backgroundColor); $domElement->setAttribute("bgcolor", $this->backgroundColor);
} }
if ($this->focusBackgroundColor) {
$domElement->setAttribute("bgcolorfocus", $this->focusBackgroundColor);
}
if ($this->style) { if ($this->style) {
$domElement->setAttribute("style", $this->style); $domElement->setAttribute("style", $this->style);
} }

View File

@ -2,6 +2,7 @@
namespace FML\Elements; namespace FML\Elements;
use FML\Stylesheet\Style;
use FML\Types\Container; use FML\Types\Container;
use FML\Types\Identifiable; use FML\Types\Identifiable;
use FML\Types\Renderable; use FML\Types\Renderable;
@ -113,14 +114,23 @@ class FrameModel implements Container, Identifiable, Renderable
/** /**
* @see Container::addChild() * @see Container::addChild()
*/ */
public function addChild(Renderable $childElement) public function addChild(Renderable $child)
{ {
if (!in_array($childElement, $this->children, true)) { if (!in_array($child, $this->children, true)) {
array_push($this->children, $childElement); array_push($this->children, $child);
} }
return $this; return $this;
} }
/**
* @deprecated Use addChild()
* @see FrameModel::addChild()
*/
public function add(Renderable $child)
{
return $this->addChild($child);
}
/** /**
* @see Container::addChildren() * @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; return $this->format;
} }
/** /**
* @see Container::setFormat() * @deprecated Use Style
* @see Style
*/ */
public function setFormat(Format $format = null) public function setFormat(Format $format = null)
{ {

View File

@ -232,12 +232,13 @@ class ManiaCode
* Join a server * Join a server
* *
* @api * @api
* @param string $login Server login * @param string $loginOrIp (optional) Server login or ip
* @param int $port (optional) Server port
* @return static * @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); return $this->addElement($serverElement);
} }
@ -245,12 +246,13 @@ class ManiaCode
* Add a server as favorite * Add a server as favorite
* *
* @api * @api
* @param string $login Server login * @param string $loginOrIp (optional) Server login or ip
* @param int $port (optional) Server port
* @return static * @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); return $this->addElement($favoriteElement);
} }
@ -311,15 +313,18 @@ class ManiaCode
} }
/** /**
* Remove all ManiaCode Elements * Add ManiaCode Elements
* *
* @api * @api
* @param Element[] $elements Elements to add
* @return static * @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; return $this;
} }
/**
* Remove all ManiaCode Elements
*
* @api
* @return static
* @deprecated Use removeAllElements()
* @see ManiaCode::removeAllElements()
*/
public function removeElements()
{
return $this->removeAllElements();
}
/** /**
* Render the ManiaCode * Render the ManiaCode
* *

View File

@ -21,7 +21,10 @@ class ManiaLink
/* /*
* Constants * 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_0 = "0";
const BACKGROUND_1 = "1"; const BACKGROUND_1 = "1";
const BACKGROUND_STARS = "stars"; const BACKGROUND_STARS = "stars";
@ -36,7 +39,7 @@ class ManiaLink
/** /**
* @var int $version ManiaLink version * @var int $version ManiaLink version
*/ */
protected $version = 1; protected $version = 0;
/** /**
* @var string $name ManiaLink name * @var string $name ManiaLink name
@ -88,7 +91,7 @@ class ManiaLink
* @param Renderable[] $children (optional) Children * @param Renderable[] $children (optional) Children
* @return static * @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); return new static($maniaLinkId, $version, $name, $children);
} }
@ -102,18 +105,17 @@ class ManiaLink
* @param string $name (optional) Name * @param string $name (optional) Name
* @param Renderable[] $children (optional) Children * @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) // backwards-compatibility (version has been introduced later)
$children = $name; $children = $name;
$name = $version; $name = $version;
$version = null; $version = ManiaLink::VERSION_3;
} }
if ($maniaLinkId) { if ($maniaLinkId) {
$this->setId($maniaLinkId); $this->setId($maniaLinkId);
} }
$this->setVersion(self::MANIALINK_VERSION);
if ($version) { if ($version) {
$this->setVersion($version); $this->setVersion($version);
} }
@ -123,7 +125,6 @@ class ManiaLink
if ($children) { if ($children) {
$this->setChildren($children); $this->setChildren($children);
} }
$this->createScript();
} }
/** /**
@ -290,7 +291,8 @@ class ManiaLink
* @api * @api
* @param Renderable $child Child Element to add * @param Renderable $child Child Element to add
* @return static * @return static
* @deprecated use addChild() instead * @deprecated Use addChild()
* @see ManiaLink::addChild()
*/ */
public function add(Renderable $child) public function add(Renderable $child)
{ {
@ -312,6 +314,21 @@ class ManiaLink
return $this; 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 * Set children
* *
@ -321,11 +338,8 @@ class ManiaLink
*/ */
public function setChildren(array $children) public function setChildren(array $children)
{ {
$this->children = array(); return $this->removeAllChildren()
foreach ($children as $child) { ->addChildren($children);
$this->addChild($child);
}
return $this;
} }
/** /**
@ -333,7 +347,8 @@ class ManiaLink
* *
* @api * @api
* @return static * @return static
* @deprecated use removeAllChildren() instead * @deprecated Use removeAllChildren()
* @see ManiaLink::removeAllChildren()
*/ */
public function removeChildren() public function removeChildren()
{ {
@ -356,10 +371,14 @@ class ManiaLink
* Get the Dictionary * Get the Dictionary
* *
* @api * @api
* @param bool $createIfEmpty (optional) If the Dico should be created if it doesn't exist yet
* @return Dico * @return Dico
*/ */
public function getDico() public function getDico($createIfEmpty = true)
{ {
if (!$this->dico && $createIfEmpty) {
$this->setDico(new Dico());
}
return $this->dico; return $this->dico;
} }
@ -382,8 +401,11 @@ class ManiaLink
* @api * @api
* @return Stylesheet * @return Stylesheet
*/ */
public function getStylesheet() public function getStylesheet($createIfEmpty = true)
{ {
if (!$this->stylesheet && $createIfEmpty) {
return $this->createStylesheet();
}
return $this->stylesheet; return $this->stylesheet;
} }
@ -400,14 +422,34 @@ class ManiaLink
return $this; 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 * Get the Script
* *
* @api * @api
* @param bool $createIfEmpty (optional) Create the script if it's not set yet
* @return Script * @return Script
*/ */
public function getScript() public function getScript($createIfEmpty = true)
{ {
if (!$this->script && $createIfEmpty) {
return $this->createScript();
}
return $this->script; return $this->script;
} }

View File

@ -64,7 +64,8 @@ class ManiaLinks
* @api * @api
* @param ManiaLink $child Child ManiaLink * @param ManiaLink $child Child ManiaLink
* @return static * @return static
* @deprecated use addChild() instead * @deprecated Use addChild()
* @see ManiaLinks::addChild()
*/ */
public function add(ManiaLink $child) public function add(ManiaLink $child)
{ {
@ -86,6 +87,21 @@ class ManiaLinks
return $this; 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 * Set ManiaLink children
* *
@ -95,23 +111,8 @@ class ManiaLinks
*/ */
public function setChildren(array $children) public function setChildren(array $children)
{ {
$this->children = array(); return $this->removeAllChildren()
foreach ($children as $child) { ->addChildren($children);
$this->addChild($child);
}
return $this;
}
/**
* Remove all child ManiaLinks
*
* @api
* @return static
* @deprecated use removeAllChildren instead
*/
public function removeChildren()
{
return $this->removeAllChildren();
} }
/** /**
@ -126,14 +127,31 @@ class ManiaLinks
return $this; return $this;
} }
/**
* Remove all child ManiaLinks
*
* @api
* @return static
* @deprecated Use removeAllChildren()
* @see ManiaLinks::removeAllChildren()
*/
public function removeChildren()
{
return $this->removeAllChildren();
}
/** /**
* Get the CustomUI * Get the CustomUI
* *
* @api * @api
* @param bool $createIfEmpty (optional) If the Custom UI should be created if it doesn't exist yet
* @return CustomUI * @return CustomUI
*/ */
public function getCustomUI() public function getCustomUI($createIfEmpty = true)
{ {
if (!$this->customUI && $createIfEmpty) {
$this->setCustomUI(new CustomUI());
}
return $this->customUI; return $this->customUI;
} }

View File

@ -75,6 +75,7 @@ class ControlScript extends ScriptFeature
public function setControl(Control $control) public function setControl(Control $control)
{ {
$control->checkId(); $control->checkId();
$control->addScriptFeature($this);
$this->control = $control; $this->control = $control;
$this->updateScriptEvents(); $this->updateScriptEvents();
return $this; return $this;
@ -104,6 +105,20 @@ class ControlScript extends ScriptFeature
return $this; 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 * Get the Script Label name
* *

View File

@ -18,19 +18,38 @@ class Script
* Constants * Constants
*/ */
const TICKINTERVAL = 250; const TICKINTERVAL = 250;
const VAR_ScriptStart = 'FML_ScriptStart'; const VAR_ScriptStart = "FML_ScriptStart";
const VAR_LoopCounter = 'FML_LoopCounter'; const VAR_LoopCounter = "FML_LoopCounter";
const VAR_LastTick = 'FML_LastTick'; const VAR_LastTick = "FML_LastTick";
/* /**
* Protected properties * @var ScriptFeature[] $features Script Features
*/ */
protected $tagName = 'script';
protected $features = array(); protected $features = array();
/**
* @var ScriptInclude[] $includes Script Includes
*/
protected $includes = array(); protected $includes = array();
/**
* @var ScriptConstant[] $constants Script Constants
*/
protected $constants = array(); protected $constants = array();
/**
* @var ScriptFunction[] $functions Script Functions
*/
protected $functions = array(); protected $functions = array();
/**
* @var ScriptLabel[] $customLabels Custom Script Labels
*/
protected $customLabels = array(); protected $customLabels = array();
/**
* @var ScriptLabel[] $genericLabels Generic Script Labels
*/
protected $genericLabels = array(); protected $genericLabels = array();
/** /**
@ -229,10 +248,13 @@ class Script
public function render(\DOMDocument $domDocument) public function render(\DOMDocument $domDocument)
{ {
$this->loadFeatures($this->features); $this->loadFeatures($this->features);
$scriptXml = $domDocument->createElement($this->tagName);
$scriptXml = $domDocument->createElement("script");
$scriptText = $this->buildScriptText(); $scriptText = $this->buildScriptText();
$scriptComment = $domDocument->createComment($scriptText); $scriptComment = $domDocument->createComment($scriptText);
$scriptXml->appendChild($scriptComment); $scriptXml->appendChild($scriptComment);
return $scriptXml; return $scriptXml;
} }

View File

@ -12,6 +12,11 @@ namespace FML\Stylesheet;
class Stylesheet class Stylesheet
{ {
/**
* @var Style[] $styles Styles
*/
protected $styles = array();
/** /**
* @var Style3d[] $styles3d 3d Styles * @var Style3d[] $styles3d 3d Styles
*/ */
@ -33,6 +38,44 @@ class Stylesheet
return new static(); 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 * Get the Styles3d
* *
@ -71,14 +114,32 @@ class Stylesheet
return $this; return $this;
} }
/**
* Remove all Style3ds
*
* @api
* @return static
* @deprecated Use removeAllStyles3d()
* @see Stylesheet::removeAllStyles3d()
*/
public function removeStyles()
{
return $this->removeAllStyles()
->removeAllStyles3d();
}
/** /**
* Get the Mood * Get the Mood
* *
* @api * @api
* @param bool $createIfEmpty (optional) If the Mood should be created if it doesn't exist yet
* @return Mood * @return Mood
*/ */
public function getMood() public function getMood($createIfEmpty = true)
{ {
if (!$this->mood && $createIfEmpty) {
$this->createMood();
}
return $this->mood; return $this->mood;
} }

View File

@ -29,4 +29,21 @@ interface BackgroundColorable
*/ */
public function setBackgroundColor($backgroundColor); 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);
} }

View File

@ -3,6 +3,7 @@
namespace FML\Types; namespace FML\Types;
use FML\Elements\Format; use FML\Elements\Format;
use FML\Stylesheet\Style;
/** /**
* Interface for Element being able to contain other Controls * Interface for Element being able to contain other Controls
@ -31,6 +32,17 @@ interface Container
*/ */
public function addChild(Renderable $child); 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 * Add new children
* *
@ -48,13 +60,26 @@ interface Container
*/ */
public function removeAllChildren(); public function removeAllChildren();
/**
* Remove all children
*
* @api
* @return static
* @deprecated Use removeAllChildren()
* @see Container::removeAllChildren()
*/
public function removeChildren();
/** /**
* Get the Format * Get the Format
* *
* @api * @api
* @param bool $createIfEmpty If the format should be created if it doesn't exist yet
* @return Format * @return Format
* @deprecated Use Style
* @see Style
*/ */
public function getFormat(); public function getFormat($createIfEmpty = true);
/** /**
* Set the Format * Set the Format
@ -62,6 +87,8 @@ interface Container
* @api * @api
* @param Format $format New Format * @param Format $format New Format
* @return static * @return static
* @deprecated Use Style
* @see Style
*/ */
public function setFormat(Format $format = null); public function setFormat(Format $format = null);

View File

@ -18,8 +18,9 @@ interface NewLineable
* Get auto new line * Get auto new line
* *
* @api * @api
* @deprecated
* @return bool * @return bool
* @deprecated Use MultiLineable::getAutoNewLine()
* @see MultiLineable::getAutoNewLine()
*/ */
public function getAutoNewLine(); public function getAutoNewLine();
@ -27,9 +28,10 @@ interface NewLineable
* Set auto new line * Set auto new line
* *
* @api * @api
* @deprecated
* @param bool $autoNewLine If the Element should insert new lines automatically * @param bool $autoNewLine If the Element should insert new lines automatically
* @return static * @return static
* @deprecated Use MultiLineable::setAutoNewLine()
* @see MultiLineable::setAutoNewLine()
*/ */
public function setAutoNewLine($autoNewLine); public function setAutoNewLine($autoNewLine);