diff --git a/application/core/Libs/FML/Components/CheckBox.php b/application/core/Libs/FML/Components/CheckBox.php index 1044fbcb..094519b6 100644 --- a/application/core/Libs/FML/Components/CheckBox.php +++ b/application/core/Libs/FML/Components/CheckBox.php @@ -7,6 +7,7 @@ use FML\Controls\Frame; use FML\Controls\Quad; use FML\Models\CheckBoxDesign; use FML\Script\Features\CheckBoxFeature; +use FML\Script\Features\ScriptFeature; use FML\Types\Renderable; use FML\Types\ScriptFeatureable; @@ -99,22 +100,6 @@ class CheckBox implements Renderable, ScriptFeatureable { return $this; } - /** - * Get the CheckBox Quad - * - * @param bool $createIfEmpty (optional) Create the Quad if it's not set - * @return \FML\Controls\Quad - */ - public function getQuad($createIfEmpty = true) { - if (!$this->feature->getQuad() && $createIfEmpty) { - $quad = new Quad(); - $quad->setSize(10, 10); - $quad->setScriptEvents(true); - $this->feature->setQuad($quad); - } - return $this->feature->getQuad(); - } - /** * Set the CheckBox Quad * @@ -130,7 +115,24 @@ class CheckBox implements Renderable, ScriptFeatureable { * @see \FML\Types\ScriptFeatureable::getScriptFeatures() */ public function getScriptFeatures() { - return array($this->feature); + return ScriptFeature::collect($this->feature, $this->getQuad(), $this->feature->getEntry()); + } + + /** + * Get the CheckBox Quad + * + * @param bool $createIfEmpty (optional) Create the Quad if it's not set + * @return \FML\Controls\Quad + */ + public function getQuad($createIfEmpty = true) { + if (!$this->feature->getQuad() && $createIfEmpty) { + $quad = new Quad(); + $quad->setSize(10, 10); + $quad->setScriptEvents(true); + $this->feature->setQuad($quad); + + } + return $this->feature->getQuad(); } /** diff --git a/application/core/Libs/FML/Controls/Audio.php b/application/core/Libs/FML/Controls/Audio.php index b2e3cac1..768c5b03 100644 --- a/application/core/Libs/FML/Controls/Audio.php +++ b/application/core/Libs/FML/Controls/Audio.php @@ -9,9 +9,9 @@ use FML\Types\Scriptable; * Audio Control * (CMlMediaPlayer) * - * @author steeffeen + * @author steeffeen * @copyright FancyManiaLinks Copyright © 2014 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 Audio extends Control implements Playable, Scriptable { /* @@ -25,6 +25,16 @@ class Audio extends Control implements Playable, Scriptable { protected $volume = 1.; protected $scriptEvents = 0; + /** + * Construct a new Audio Control + * + * @param string $id (optional) Control Id + */ + public function __construct($id = null) { + parent::__construct($id); + $this->tagName = 'audio'; + } + /** * Create a new Audio Control * @@ -37,35 +47,29 @@ class Audio extends Control implements Playable, Scriptable { } /** - * Construct a new Audio Control - * - * @param string $id (optional) Control Id + * @see \FML\Controls\Control::getManiaScriptClass() */ - public function __construct($id = null) { - parent::__construct($id); - $this->tagName = 'audio'; + public function getManiaScriptClass() { + return 'CMlMediaPlayer'; } /** - * * @see \FML\Types\Playable::setData() */ public function setData($data) { - $this->data = (string) $data; + $this->data = (string)$data; return $this; } /** - * * @see \FML\Types\Playable::setDataId() */ public function setDataId($dataId) { - $this->dataId = (string) $dataId; + $this->dataId = (string)$dataId; return $this; } /** - * * @see \FML\Types\Playable::setPlay() */ public function setPlay($play) { @@ -74,7 +78,6 @@ class Audio extends Control implements Playable, Scriptable { } /** - * * @see \FML\Types\Playable::setLooping() */ public function setLooping($looping) { @@ -83,7 +86,6 @@ class Audio extends Control implements Playable, Scriptable { } /** - * * @see \FML\Types\Playable::setMusic() */ public function setMusic($music) { @@ -92,16 +94,14 @@ class Audio extends Control implements Playable, Scriptable { } /** - * * @see \FML\Types\Playable::setVolume() */ public function setVolume($volume) { - $this->volume = (float) $volume; + $this->volume = (float)$volume; return $this; } /** - * * @see \FML\Types\Scriptable::setScriptEvents() */ public function setScriptEvents($scriptEvents) { @@ -110,7 +110,6 @@ class Audio extends Control implements Playable, Scriptable { } /** - * * @see \FML\Control::render() */ public function render(\DOMDocument $domDocument) { diff --git a/application/core/Libs/FML/Controls/Control.php b/application/core/Libs/FML/Controls/Control.php index 51e72c41..6a79f6f7 100644 --- a/application/core/Libs/FML/Controls/Control.php +++ b/application/core/Libs/FML/Controls/Control.php @@ -67,30 +67,6 @@ abstract class Control implements Renderable, ScriptFeatureable { } } - /** - * Get Control Id - * - * @param bool $escaped (optional) Whether the Id should be escaped for ManiaScript - * @return string - */ - public function getId($escaped = false) { - if ($escaped) { - return Builder::escapeText($this->id); - } - return $this->id; - } - - /** - * Set Control Id - * - * @param string $id Control Id - * @return \FML\Controls\Control - */ - public function setId($id) { - $this->id = (string)$id; - return $this; - } - /** * Check Id for dangerous Characters and assign a unique Id if necessary * @@ -121,6 +97,47 @@ abstract class Control implements Renderable, ScriptFeatureable { return $this; } + /** + * Get Control Id + * + * @param bool $escaped (optional) Whether the Id should be escaped for ManiaScript + * @return string + */ + public function getId($escaped = false) { + if ($escaped) { + return Builder::escapeText($this->id); + } + return $this->id; + } + + /** + * Set Control Id + * + * @param string $id Control Id + * @return \FML\Controls\Control + */ + public function setId($id) { + $this->id = (string)$id; + return $this; + } + + /** + * Set Control Position + * + * @param float $x Horizontal Position + * @param float $y Vertical Position + * @param float $z (optional) Depth + * @return \FML\Controls\Control + */ + public function setPosition($x, $y, $z = null) { + $this->setX($x); + $this->setY($y); + if ($z !== null) { + $this->setZ($z); + } + return $this; + } + /** * Set X Position * @@ -155,19 +172,15 @@ abstract class Control implements Renderable, ScriptFeatureable { } /** - * Set Control Position + * Set Control Size * - * @param float $x Horizontal Position - * @param float $y Vertical Position - * @param float $z (optional) Depth + * @param float $width Control Width + * @param float $height Control Height * @return \FML\Controls\Control */ - public function setPosition($x, $y, $z = null) { - $this->setX($x); - $this->setY($y); - if ($z !== null) { - $this->setZ($z); - } + public function setSize($width, $height) { + $this->setWidth($width); + $this->setHeight($height); return $this; } @@ -194,15 +207,25 @@ abstract class Control implements Renderable, ScriptFeatureable { } /** - * Set Control Size + * Center Alignment * - * @param float $width Control Width - * @param float $height Control Height * @return \FML\Controls\Control */ - public function setSize($width, $height) { - $this->setWidth($width); - $this->setHeight($height); + public function centerAlign() { + $this->setAlign(self::CENTER, self::CENTER2); + return $this; + } + + /** + * Set Horizontal and Vertical Alignment + * + * @param string $hAlign Horizontal Alignment + * @param string $vAlign Vertical Alignment + * @return \FML\Controls\Control + */ + public function setAlign($hAlign, $vAlign) { + $this->setHAlign($hAlign); + $this->setVAlign($vAlign); return $this; } @@ -228,29 +251,6 @@ abstract class Control implements Renderable, ScriptFeatureable { return $this; } - /** - * Set Horizontal and Vertical Alignment - * - * @param string $hAlign Horizontal Alignment - * @param string $vAlign Vertical Alignment - * @return \FML\Controls\Control - */ - public function setAlign($hAlign, $vAlign) { - $this->setHAlign($hAlign); - $this->setVAlign($vAlign); - return $this; - } - - /** - * Center Alignment - * - * @return \FML\Controls\Control - */ - public function centerAlign() { - $this->setAlign(self::CENTER, self::CENTER2); - return $this; - } - /** * Reset Alignment * @@ -310,6 +310,17 @@ abstract class Control implements Renderable, ScriptFeatureable { return $this; } + /** + * Add a Script Feature + * + * @param ScriptFeature $scriptFeature Script Feature + * @return \FML\Controls\Control + */ + public function addScriptFeature(ScriptFeature $scriptFeature) { + array_push($this->scriptFeatures, $scriptFeature); + return $this; + } + /** * Add a dynamic Feature opening the current Map Info * @@ -398,26 +409,14 @@ abstract class Control implements Renderable, ScriptFeatureable { * * @param string $scriptText Script Text * @param string $label (optional) Script Label Name - * @param bool $isolated (optional) Whether to isolate the Script Text * @return \FML\Controls\Control */ - public function addScriptText($scriptText, $label = ScriptLabel::MOUSECLICK, $isolated = true) { - $customText = new ControlScript($this, $scriptText, $label, $isolated); + public function addScriptText($scriptText, $label = ScriptLabel::MOUSECLICK) { + $customText = new ControlScript($this, $scriptText, $label); $this->addScriptFeature($customText); return $this; } - /** - * Add a Script Feature - * - * @param ScriptFeature $scriptFeature Script Feature - * @return \FML\Controls\Control - */ - public function addScriptFeature(ScriptFeature $scriptFeature) { - array_push($this->scriptFeatures, $scriptFeature); - return $this; - } - /** * Remove all Script Features * @@ -467,4 +466,11 @@ abstract class Control implements Renderable, ScriptFeatureable { } return $xmlElement; } + + /** + * Get the ManiaScript Class of the Control + * + * @return string + */ + public abstract function getManiaScriptClass(); } diff --git a/application/core/Libs/FML/Controls/Entry.php b/application/core/Libs/FML/Controls/Entry.php index 180588ba..263177e7 100644 --- a/application/core/Libs/FML/Controls/Entry.php +++ b/application/core/Libs/FML/Controls/Entry.php @@ -32,6 +32,16 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF protected $focusAreaColor2 = ''; protected $autoComplete = null; + /** + * Construct a new Entry Control + * + * @param string $id (optional) Control Id + */ + public function __construct($id = null) { + parent::__construct($id); + $this->tagName = 'entry'; + } + /** * Create a new Entry Control * @@ -44,13 +54,19 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF } /** - * Construct a new Entry Control - * - * @param string $id (optional) Control Id + * @see \FML\Controls\Control::getManiaScriptClass() */ - public function __construct($id = null) { - parent::__construct($id); - $this->tagName = 'entry'; + public function getManiaScriptClass() { + return 'CMlEntry'; + } + + /** + * Get the Entry Name + * + * @return string + */ + public function getName() { + return $this->name; } /** @@ -65,12 +81,12 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF } /** - * Get the Entry Name + * Get the Default Value * - * @return string + * @return mixed */ - public function getName() { - return $this->name; + public function getDefault() { + return $this->default; } /** @@ -84,15 +100,6 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF return $this; } - /** - * Get the Default Value - * - * @return mixed - */ - public function getDefault() { - return $this->default; - } - /** * @see \FML\Types\NewLineable::setAutoNewLine() */ diff --git a/application/core/Libs/FML/Controls/FileEntry.php b/application/core/Libs/FML/Controls/FileEntry.php index 748361d0..e1a97de0 100644 --- a/application/core/Libs/FML/Controls/FileEntry.php +++ b/application/core/Libs/FML/Controls/FileEntry.php @@ -6,9 +6,9 @@ namespace FML\Controls; * FileEntry Control * (CMlFileEntry) * - * @author steeffeen + * @author steeffeen * @copyright FancyManiaLinks Copyright © 2014 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 FileEntry extends Entry { /* @@ -16,6 +16,16 @@ class FileEntry extends Entry { */ protected $folder = ''; + /** + * Construct a new FileEntry Control + * + * @param string $id (optional) Control Id + */ + public function __construct($id = null) { + parent::__construct($id); + $this->tagName = 'fileentry'; + } + /** * Create a new FileEntry Control * @@ -28,13 +38,10 @@ class FileEntry extends Entry { } /** - * Construct a new FileEntry Control - * - * @param string $id (optional) Control Id + * @see \FML\Controls\Control::getManiaScriptClass() */ - public function __construct($id = null) { - parent::__construct($id); - $this->tagName = 'fileentry'; + public function getManiaScriptClass() { + return 'CMlFileEntry'; } /** @@ -44,12 +51,11 @@ class FileEntry extends Entry { * @return \FML\Controls\FileEntry */ public function setFolder($folder) { - $this->folder = (string) $folder; + $this->folder = (string)$folder; return $this; } /** - * * @see \FML\Entry::render() */ public function render(\DOMDocument $domDocument) { diff --git a/application/core/Libs/FML/Controls/Frame.php b/application/core/Libs/FML/Controls/Frame.php index 90d03a27..1918c1d1 100644 --- a/application/core/Libs/FML/Controls/Frame.php +++ b/application/core/Libs/FML/Controls/Frame.php @@ -23,6 +23,16 @@ class Frame extends Control implements Container { /** @var Format $format */ protected $format = null; + /** + * Construct a new Frame Control + * + * @param string $id (optional) Control Id + */ + public function __construct($id = null) { + parent::__construct($id); + $this->tagName = 'frame'; + } + /** * Create a new Frame Control * @@ -35,13 +45,10 @@ class Frame extends Control implements Container { } /** - * Construct a new Frame Control - * - * @param string $id (optional) Control Id + * @see \FML\Controls\Control::getManiaScriptClass() */ - public function __construct($id = null) { - parent::__construct($id); - $this->tagName = 'frame'; + public function getManiaScriptClass() { + return 'CMlFrame'; } /** @@ -62,14 +69,6 @@ class Frame extends Control implements Container { return $this; } - /** - * @see \FML\Types\Container::setFormat() - */ - public function setFormat(Format $format) { - $this->format = $format; - return $this; - } - /** * @see \FML\Types\Container::getFormat() */ @@ -80,6 +79,14 @@ class Frame extends Control implements Container { return $this->format; } + /** + * @see \FML\Types\Container::setFormat() + */ + public function setFormat(Format $format) { + $this->format = $format; + return $this; + } + /** * @see \FML\Controls\Control::getScriptFeatures() */ diff --git a/application/core/Libs/FML/Controls/FrameInstance.php b/application/core/Libs/FML/Controls/FrameInstance.php index b382515b..ea0df3d6 100644 --- a/application/core/Libs/FML/Controls/FrameInstance.php +++ b/application/core/Libs/FML/Controls/FrameInstance.php @@ -20,18 +20,6 @@ class FrameInstance extends Control { /** @var FrameModel $model */ protected $model = null; - /** - * Create a new Frame Instance - * - * @param string $modelId (optional) Frame Model Id - * @param string $controlId (optional) Control Id - * @return \FML\Controls\Frame - */ - public static function create($modelId = null, $controlId = null) { - $frameInstance = new FrameInstance($modelId, $controlId); - return $frameInstance; - } - /** * Construct a new Frame Instance * @@ -58,6 +46,25 @@ class FrameInstance extends Control { return $this; } + /** + * Create a new Frame Instance + * + * @param string $modelId (optional) Frame Model Id + * @param string $controlId (optional) Control Id + * @return \FML\Controls\Frame + */ + public static function create($modelId = null, $controlId = null) { + $frameInstance = new FrameInstance($modelId, $controlId); + return $frameInstance; + } + + /** + * @see \FML\Controls\Control::getManiaScriptClass() + */ + public function getManiaScriptClass() { + return 'CMlFrame'; + } + /** * Set Frame Model to use * diff --git a/application/core/Libs/FML/Controls/Gauge.php b/application/core/Libs/FML/Controls/Gauge.php index 32aa030a..e4019f5f 100644 --- a/application/core/Libs/FML/Controls/Gauge.php +++ b/application/core/Libs/FML/Controls/Gauge.php @@ -8,19 +8,19 @@ use FML\Types\Styleable; * Gauge Control * (CMlGauge) * - * @author steeffeen + * @author steeffeen * @copyright FancyManiaLinks Copyright © 2014 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 Gauge extends Control implements Styleable { /* * Constants */ - const STYLE_BgCard = 'BgCard'; - const STYLE_EnergyBar = 'EnergyBar'; - const STYLE_ProgressBar = 'ProgressBar'; + const STYLE_BgCard = 'BgCard'; + const STYLE_EnergyBar = 'EnergyBar'; + const STYLE_ProgressBar = 'ProgressBar'; const STYLE_ProgressBarSmall = 'ProgressBarSmall'; - + /* * Protected Properties */ @@ -34,6 +34,16 @@ class Gauge extends Control implements Styleable { protected $drawBlockBg = 1; protected $style = ''; + /** + * Construct a new Gauge Control + * + * @param string $id (optional) Control Id + */ + public function __construct($id = null) { + parent::__construct($id); + $this->tagName = 'gauge'; + } + /** * Create a new Gauge Control * @@ -46,13 +56,10 @@ class Gauge extends Control implements Styleable { } /** - * Construct a new Gauge Control - * - * @param string $id (optional) Control Id + * @see \FML\Controls\Control::getManiaScriptClass() */ - public function __construct($id = null) { - parent::__construct($id); - $this->tagName = 'gauge'; + public function getManiaScriptClass() { + return 'CMlGauge'; } /** @@ -62,7 +69,7 @@ class Gauge extends Control implements Styleable { * @return \FML\Controls\Gauge */ public function setRatio($ratio) { - $this->ratio = (float) $ratio; + $this->ratio = (float)$ratio; return $this; } @@ -73,7 +80,7 @@ class Gauge extends Control implements Styleable { * @return \FML\Controls\Gauge */ public function setGrading($grading) { - $this->grading = (float) $grading; + $this->grading = (float)$grading; return $this; } @@ -84,7 +91,7 @@ class Gauge extends Control implements Styleable { * @return \FML\Controls\Gauge */ public function setColor($color) { - $this->color = (string) $color; + $this->color = (string)$color; return $this; } @@ -95,7 +102,7 @@ class Gauge extends Control implements Styleable { * @return \FML\Controls\Gauge */ public function setRotation($rotation) { - $this->rotation = (float) $rotation; + $this->rotation = (float)$rotation; return $this; } @@ -117,7 +124,7 @@ class Gauge extends Control implements Styleable { * @return \FML\Controls\Gauge */ public function setClan($clan) { - $this->clan = (int) $clan; + $this->clan = (int)$clan; return $this; } @@ -144,16 +151,14 @@ class Gauge extends Control implements Styleable { } /** - * * @see \FML\Types\Styleable::setStyle() */ public function setStyle($style) { - $this->style = (string) $style; + $this->style = (string)$style; return $this; } /** - * * @see \FML\Control::render() */ public function render(\DOMDocument $domDocument) { diff --git a/application/core/Libs/FML/Controls/Label.php b/application/core/Libs/FML/Controls/Label.php index 7eeabb7b..da34ee18 100644 --- a/application/core/Libs/FML/Controls/Label.php +++ b/application/core/Libs/FML/Controls/Label.php @@ -2,21 +2,21 @@ namespace FML\Controls; +use FML\Script\Features\Clock; use FML\Types\Actionable; use FML\Types\Linkable; use FML\Types\NewLineable; use FML\Types\Scriptable; use FML\Types\Styleable; use FML\Types\TextFormatable; -use FML\Script\Features\Clock; /** * Label Control * (CMlLabel) * - * @author steeffeen + * @author steeffeen * @copyright FancyManiaLinks Copyright © 2014 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 Label extends Control implements Actionable, Linkable, NewLineable, Scriptable, Styleable, TextFormatable { /* @@ -42,17 +42,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script protected $focusAreaColor1 = ''; protected $focusAreaColor2 = ''; - /** - * Create a new Label Control - * - * @param string $id (optional) Control Id - * @return \FML\Controls\Label - */ - public static function create($id = null) { - $label = new Label($id); - return $label; - } - /** * Construct a new Label Control * @@ -64,6 +53,24 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script $this->setZ(1); } + /** + * Create a new Label Control + * + * @param string $id (optional) Control Id + * @return \FML\Controls\Label + */ + public static function create($id = null) { + $label = new Label($id); + return $label; + } + + /** + * @see \FML\Controls\Control::getManiaScriptClass() + */ + public function getManiaScriptClass() { + return 'CMlLabel'; + } + /** * Set Text * @@ -71,7 +78,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script * @return \FML\Controls\Label */ public function setText($text) { - $this->text = (string) $text; + $this->text = (string)$text; return $this; } @@ -82,7 +89,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script * @return \FML\Controls\Label */ public function setTextId($textId) { - $this->textId = (string) $textId; + $this->textId = (string)$textId; return $this; } @@ -93,7 +100,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script * @return \FML\Controls\Label */ public function setTextPrefix($textPrefix) { - $this->textPrefix = (string) $textPrefix; + $this->textPrefix = (string)$textPrefix; return $this; } @@ -126,21 +133,11 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script * @return \FML\Controls\Label */ public function setMaxLines($maxLines) { - $this->maxLines = (int) $maxLines; + $this->maxLines = (int)$maxLines; return $this; } /** - * - * @see \FML\Types\Actionable::setAction() - */ - public function setAction($action) { - $this->action = (string) $action; - return $this; - } - - /** - * * @see \FML\Types\Actionable::getAction() */ public function getAction() { @@ -148,52 +145,54 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script } /** - * + * @see \FML\Types\Actionable::setAction() + */ + public function setAction($action) { + $this->action = (string)$action; + return $this; + } + + /** * @see \FML\Types\Actionable::setActionKey() */ public function setActionKey($actionKey) { - $this->actionKey = (int) $actionKey; + $this->actionKey = (int)$actionKey; return $this; } /** - * * @see \FML\Types\Linkable::setUrl() */ public function setUrl($url) { - $this->url = (string) $url; + $this->url = (string)$url; return $this; } /** - * * @see \FML\Types\Linkable::setUrlId() */ public function setUrlId($urlId) { - $this->urlId = (string) $urlId; + $this->urlId = (string)$urlId; return $this; } /** - * * @see \FML\Types\Linkable::setManialink() */ public function setManialink($manialink) { - $this->manialink = (string) $manialink; + $this->manialink = (string)$manialink; return $this; } /** - * * @see \FML\Types\Linkable::setManialinkId() */ public function setManialinkId($manialinkId) { - $this->manialinkId = (string) $manialinkId; + $this->manialinkId = (string)$manialinkId; return $this; } /** - * * @see \FML\Types\NewLineable::setAutoNewLine() */ public function setAutoNewLine($autoNewLine) { @@ -202,7 +201,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script } /** - * * @see \FML\Types\Scriptable::setScriptEvents() */ public function setScriptEvents($scriptEvents) { @@ -211,54 +209,49 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script } /** - * * @see \FML\Types\Styleable::setStyle() */ public function setStyle($style) { - $this->style = (string) $style; + $this->style = (string)$style; return $this; } /** - * * @see \FML\Types\TextFormatable::setTextSize() */ public function setTextSize($textSize) { - $this->textSize = (int) $textSize; + $this->textSize = (int)$textSize; return $this; } /** - * * @see \FML\Types\TextFormatable::setTextColor() */ public function setTextColor($textColor) { - $this->textColor = (string) $textColor; + $this->textColor = (string)$textColor; return $this; } /** - * * @see \FML\Types\TextFormatable::setAreaColor() */ public function setAreaColor($areaColor) { - $this->focusAreaColor1 = (string) $areaColor; + $this->focusAreaColor1 = (string)$areaColor; return $this; } /** - * * @see \FML\Types\TextFormatable::setAreaFocusColor() */ public function setAreaFocusColor($areaFocusColor) { - $this->focusAreaColor2 = (string) $areaFocusColor; + $this->focusAreaColor2 = (string)$areaFocusColor; return $this; } /** * Add a dynamic Feature showing the current Time * - * @param bool $showSeconds (optional) Whether the Seconds should be shown + * @param bool $showSeconds (optional) Whether the Seconds should be shown * @param bool $showFullDate (optional) Whether the Date should be shown * @return \FML\Controls\Label */ @@ -269,7 +262,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script } /** - * * @see \FML\Control::render() */ public function render(\DOMDocument $domDocument) { diff --git a/application/core/Libs/FML/Controls/Quad.php b/application/core/Libs/FML/Controls/Quad.php index 87996cb6..50d1e5ae 100644 --- a/application/core/Libs/FML/Controls/Quad.php +++ b/application/core/Libs/FML/Controls/Quad.php @@ -40,6 +40,17 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta protected $style = ''; protected $subStyle = ''; + /** + * Construct a new Quad Control + * + * @param string $id (optional) Control Id + */ + public function __construct($id = null) { + parent::__construct($id); + $this->tagName = 'quad'; + $this->setZ(-1); + } + /** * Create a new Quad Control * @@ -52,14 +63,10 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta } /** - * Construct a new Quad Control - * - * @param string $id (optional) Control Id + * @see \FML\Controls\Control::getManiaScriptClass() */ - public function __construct($id = null) { - parent::__construct($id); - $this->tagName = 'quad'; - $this->setZ(-1); + public function getManiaScriptClass() { + return 'CMlQuad'; } /** @@ -139,6 +146,13 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta return $this; } + /** + * @see \FML\Types\Actionable::getAction() + */ + public function getAction() { + return $this->action; + } + /** * @see \FML\Types\Actionable::setAction() */ @@ -147,13 +161,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta return $this; } - /** - * @see \FML\Types\Actionable::getAction() - */ - public function getAction() { - return $this->action; - } - /** * @see \FML\Types\Actionable::setActionKey() */ @@ -210,6 +217,15 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta return $this; } + /** + * @see \FML\Types\SubStyleable::setStyles() + */ + public function setStyles($style, $subStyle) { + $this->setStyle($style); + $this->setSubStyle($subStyle); + return $this; + } + /** * @see \FML\Types\Styleable::setStyle() */ @@ -226,15 +242,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta return $this; } - /** - * @see \FML\Types\SubStyleable::setStyles() - */ - public function setStyles($style, $subStyle) { - $this->setStyle($style); - $this->setSubStyle($subStyle); - return $this; - } - /** * Apply the given CheckBox Design * diff --git a/application/core/Libs/FML/Controls/Video.php b/application/core/Libs/FML/Controls/Video.php index aca2d92e..4fecacf4 100644 --- a/application/core/Libs/FML/Controls/Video.php +++ b/application/core/Libs/FML/Controls/Video.php @@ -9,9 +9,9 @@ use FML\Types\Scriptable; * Video Control * (CMlMediaPlayer) * - * @author steeffeen + * @author steeffeen * @copyright FancyManiaLinks Copyright © 2014 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 Video extends Control implements Playable, Scriptable { /* @@ -25,6 +25,16 @@ class Video extends Control implements Playable, Scriptable { protected $volume = 1.; protected $scriptEvents = 0; + /** + * Construct a new Video Control + * + * @param string $id (optional) Control Id + */ + public function __construct($id = null) { + parent::__construct($id); + $this->tagName = 'video'; + } + /** * Create a new Video Control * @@ -37,35 +47,29 @@ class Video extends Control implements Playable, Scriptable { } /** - * Construct a new Video Control - * - * @param string $id (optional) Control Id + * @see \FML\Controls\Control::getManiaScriptClass() */ - public function __construct($id = null) { - parent::__construct($id); - $this->tagName = 'video'; + public function getManiaScriptClass() { + return 'CMlMediaPlayer'; } /** - * * @see \FML\Types\Playable::setData() */ public function setData($data) { - $this->data = (string) $data; + $this->data = (string)$data; return $this; } /** - * * @see \FML\Types\Playable::setDataId() */ public function setDataId($dataId) { - $this->dataId = (string) $dataId; + $this->dataId = (string)$dataId; return $this; } /** - * * @see \FML\Types\Playable::setPlay() */ public function setPlay($play) { @@ -74,7 +78,6 @@ class Video extends Control implements Playable, Scriptable { } /** - * * @see \FML\Types\Playable::setLooping() */ public function setLooping($looping) { @@ -83,7 +86,6 @@ class Video extends Control implements Playable, Scriptable { } /** - * * @see \FML\Types\Playable::setMusic() */ public function setMusic($music) { @@ -92,16 +94,14 @@ class Video extends Control implements Playable, Scriptable { } /** - * * @see \FML\Types\Playable::setVolume() */ public function setVolume($volume) { - $this->volume = (float) $volume; + $this->volume = (float)$volume; return $this; } /** - * * @see \FML\Types\Scriptable::setScriptEvents() */ public function setScriptEvents($scriptEvents) { @@ -110,7 +110,6 @@ class Video extends Control implements Playable, Scriptable { } /** - * * @see \FML\Control::render() */ public function render(\DOMDocument $domDocument) { diff --git a/application/core/Libs/FML/Models/CheckBoxDesign.php b/application/core/Libs/FML/Models/CheckBoxDesign.php index 9ad1c8a5..009979cd 100644 --- a/application/core/Libs/FML/Models/CheckBoxDesign.php +++ b/application/core/Libs/FML/Models/CheckBoxDesign.php @@ -122,6 +122,9 @@ class CheckBoxDesign implements Styleable, SubStyleable { } else { $string = $this->style . '|' . $this->subStyle;; } - return Builder::escapeText($string); + if ($escaped) { + return Builder::escapeText($string); + } + return $string; } } diff --git a/application/core/Libs/FML/Script/Builder.php b/application/core/Libs/FML/Script/Builder.php index 70233e16..6ceaa32e 100644 --- a/application/core/Libs/FML/Script/Builder.php +++ b/application/core/Libs/FML/Script/Builder.php @@ -5,18 +5,18 @@ namespace FML\Script; /** * Builder Class offering Methods to build ManiaScript * - * @author steeffeen + * @author steeffeen * @copyright FancyManiaLinks Copyright © 2014 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 */ abstract class Builder { /** * Build a Label Implementation Block * - * @param string $labelName Name of the Label + * @param string $labelName Name of the Label * @param string $implementationCode Label Implementation Coding (without declaration) - * @param bool $isolate Whether the Code should be isolated in an own Block + * @param bool $isolate Whether the Code should be isolated in an own Block * @return string */ public static function getLabelImplementationBlock($labelName, $implementationCode, $isolate = true) { @@ -30,14 +30,14 @@ abstract class Builder { /** * Escape dangerous Characters in the given Text * - * @param string $text Text to escape - * @param bool $addApostrophes (optional) Whether to add Apostrophes before and after the Text + * @param string $text Text to escape + * @param bool $addApostrophes (optional) Whether to add Apostrophes before and after the Text * @return string */ public static function escapeText($text, $addApostrophes = false) { - $dangers = array('\\', '"', "\n"); + $dangers = array('\\', '"', "\n"); $replacements = array('\\\\', '\\"', '\\n'); - $escapedText = str_ireplace($dangers, $replacements, $text); + $escapedText = str_ireplace($dangers, $replacements, $text); if ($addApostrophes) { $escapedText = '"' . $escapedText . '"'; } @@ -51,8 +51,8 @@ abstract class Builder { * @return string */ public static function getReal($value) { - $value = (float) $value; - $stringVal = (string) $value; + $value = (float)$value; + $stringVal = (string)$value; if (!fmod($value, 1)) { $stringVal .= '.'; } @@ -66,7 +66,7 @@ abstract class Builder { * @return string */ public static function getBoolean($value) { - $bool = (bool) $value; + $bool = (bool)$value; if ($bool) { return "True"; } @@ -76,28 +76,26 @@ abstract class Builder { /** * Get the String-Representation of the given Array * - * @param array $array Array to convert to a ManiaScript Array - * @param bool $associative (optional) Whether the Array should be associative + * @param array $array Array to convert to a ManiaScript Array + * @param bool $associative (optional) Whether the Array should be associative * @return string */ public static function getArray(array $array, $associative = false) { $arrayText = '['; - $index = 0; - $count = count($array); + $index = 0; + $count = count($array); foreach ($array as $key => $value) { if ($associative) { if (is_string($key)) { $arrayText .= '"' . self::escapeText($key) . '"'; - } - else { + } else { $arrayText .= $key; } $arrayText .= ' => '; } if (is_string($value)) { $arrayText .= '"' . self::escapeText($value) . '"'; - } - else { + } else { $arrayText .= $value; } if ($index < $count - 1) { @@ -112,7 +110,7 @@ abstract class Builder { /** * Get the Include Command for the given File and Namespace * - * @param string $file Include File + * @param string $file Include File * @param string $namespace Include Namespace * @return string */ @@ -124,7 +122,7 @@ abstract class Builder { /** * Get the Constant Command for the given Name and Value * - * @param string $name Constant Name + * @param string $name Constant Name * @param string $value Constant Value * @return string */ diff --git a/application/core/Libs/FML/Script/Features/CheckBoxFeature.php b/application/core/Libs/FML/Script/Features/CheckBoxFeature.php index dc7c3811..2a684f99 100644 --- a/application/core/Libs/FML/Script/Features/CheckBoxFeature.php +++ b/application/core/Libs/FML/Script/Features/CheckBoxFeature.php @@ -89,6 +89,15 @@ class CheckBoxFeature extends ScriptFeature { return $this; } + /** + * Get the managed Entry + * + * @return \FML\Controls\Entry + */ + public function getEntry() { + return $this->entry; + } + /** * Set the Enabled Design * @@ -134,6 +143,7 @@ class CheckBoxFeature extends ScriptFeature { Void " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(CMlQuad _Quad) { declare " . self::VAR_CHECKBOX_ENABLED . " as Enabled for _Quad = True; Enabled = !Enabled; + _Quad.StyleSelected = Enabled; declare " . self::VAR_CHECKBOX_DESIGNS . " as Designs for _Quad = Text[Boolean]; declare Design = Designs[Enabled]; declare DesignParts = TextLib::Split(\"|\", Design); diff --git a/application/core/Libs/FML/Script/Features/ControlScript.php b/application/core/Libs/FML/Script/Features/ControlScript.php index e1927014..de69c8b3 100644 --- a/application/core/Libs/FML/Script/Features/ControlScript.php +++ b/application/core/Libs/FML/Script/Features/ControlScript.php @@ -22,7 +22,6 @@ class ControlScript extends ScriptFeature { protected $control = null; protected $labelName = null; protected $text = null; - protected $isolated = null; /** * Construct a new Custom Script Text @@ -30,13 +29,11 @@ class ControlScript extends ScriptFeature { * @param Control $control Event Control * @param string $text Script Text * @param string $labelName (optional) Script Label Name - * @param bool $isolated (optional) Whether to isolate the Script Text */ - public function __construct(Control $control, $text, $labelName = ScriptLabel::MOUSECLICK, $isolated = true) { + public function __construct(Control $control, $text, $labelName = ScriptLabel::MOUSECLICK) { $this->setControl($control); $this->setText($text); $this->setLabelName($labelName); - $this->setIsolated($isolated); } /** @@ -76,36 +73,47 @@ class ControlScript extends ScriptFeature { return $this; } - /** - * Set whether the Script should be isolated - * - * @param bool $isolated Whether to isolate the Script Text - * @return \FML\Script\Features\ControlScript - */ - public function setIsolated($isolated = true) { - $this->isolated = (bool)$isolated; - return $this; - } - /** * @see \FML\Script\Features\ScriptFeature::prepare() */ public function prepare(Script $script) { - $script->appendGenericScriptLabel($this->labelName, $this->getEncapsulatedText(), $this->isolated); + $script->appendGenericScriptLabel($this->labelName, $this->buildScriptText(), true); return $this; } /** - * Get the Script Text encapsulated for the Control Event + * Build the Script Text for the Control * * @return string */ - protected function getEncapsulatedText() { + protected function buildScriptText() { $controlId = $this->control->getId(true); - $scriptText = " -if (Event.ControlId == \"{$controlId}\") { - {$this->text} -}"; + $scriptText = ''; + $closeBlock = false; + + if (ScriptLabel::isEventLabel($this->labelName)) { + $scriptText .= ' +if (Event.ControlId == "' . $controlId . '") { +declare Control <=> Event.Control;'; + $closeBlock = true; + } else { + $scriptText .= ' +declare Control <=> Page.GetFirstChild("' . $controlId . '");'; + } + + $class = $this->control->getManiaScriptClass(); + $name = preg_replace('/^CMl/', '', $class, 1); + $scriptText .= ' +declare ' . $name . ' <=> (Control as ' . $class . '); +'; + + $scriptText .= $this->text . ' +'; + + if ($closeBlock) { + $scriptText .= '}'; + } + return $scriptText; } } diff --git a/application/core/Libs/FML/Script/Features/ScriptFeature.php b/application/core/Libs/FML/Script/Features/ScriptFeature.php index ab432ca5..cae00d15 100644 --- a/application/core/Libs/FML/Script/Features/ScriptFeature.php +++ b/application/core/Libs/FML/Script/Features/ScriptFeature.php @@ -3,16 +3,37 @@ namespace FML\Script\Features; use FML\Script\Script; +use FML\Types\ScriptFeatureable; /** * ManiaLink Script Feature Class * - * @author steeffeen + * @author steeffeen * @copyright FancyManiaLinks Copyright © 2014 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 */ abstract class ScriptFeature { + /** + * Collect the Script Features of the given Objects + * + * @param object $scriptFeatureable ScriptFeatureable Object + * @param object $_ (optional) Various Amount of additional Objects + * @return array + */ + public static function collect($scriptFeatureable, $_ = null) { + $params = func_get_args(); + $scriptFeatures = array(); + foreach ($params as $object) { + if ($object instanceof ScriptFeatureable) { + $scriptFeatures = array_merge($scriptFeatures, $object->getScriptFeatures()); + } else if ($object instanceof ScriptFeature) { + array_push($scriptFeatures, $object); + } + } + return $scriptFeatures; + } + /** * Prepare the given Script for Rendering by adding the needed Labels, etc. * diff --git a/application/core/Libs/FML/Script/ScriptLabel.php b/application/core/Libs/FML/Script/ScriptLabel.php index 411387e2..42b537ea 100644 --- a/application/core/Libs/FML/Script/ScriptLabel.php +++ b/application/core/Libs/FML/Script/ScriptLabel.php @@ -75,6 +75,29 @@ class ScriptLabel { return $this; } + /** + * Check if the given Label is an Event Label + * + * @param string $label Label Name + * @return bool + */ + public static function isEventLabel($label) { + $eventLabels = self::getEventLabels(); + if (in_array($label, $eventLabels)) { + return true; + } + return false; + } + + /** + * Get the possible Event Label Names + * + * @return array + */ + public static function getEventLabels() { + return array(self::ENTRYSUBMIT, self::KEYPRESS, self::MOUSECLICK, self::MOUSEOUT, self::MOUSEOVER); + } + /** * Build the full Script Label Text * diff --git a/application/core/Libs/FML/autoload.php b/application/core/Libs/FML/autoload.php index cab34fc7..bf3f88f3 100644 --- a/application/core/Libs/FML/autoload.php +++ b/application/core/Libs/FML/autoload.php @@ -15,9 +15,7 @@ if (!defined('FML_PATH')) { if (!defined('FML_VERSION')) { define('FML_VERSION', '1.2'); } -if (!defined('FML_SIMPLE_CLASSES')) { - define('FML_SIMPLE_CLASSES', false); -} +//define('FML_SIMPLE_CLASSES', true); /* * Autoload Function that loads FML Class Files on Demand @@ -30,7 +28,7 @@ if (!defined('FML_AUTOLOAD_DEFINED')) { if (file_exists($filePath)) { // Load with FML namespace require_once $filePath; - } else if (FML_SIMPLE_CLASSES) { + } else if (defined('FML_SIMPLE_CLASSES') && FML_SIMPLE_CLASSES) { // Load as simple class name if (!function_exists('loadSimpleClass')) {