From b75946e0488500638587671efed78e02104b17fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Sun, 27 Apr 2014 14:44:40 +0200 Subject: [PATCH] FML 1.1 --- application/core/Libs/FML/Controls/Audio.php | 7 - .../core/Libs/FML/Controls/Control.php | 128 ++- application/core/Libs/FML/Controls/Entry.php | 53 +- application/core/Libs/FML/Controls/Frame.php | 22 +- .../core/Libs/FML/Controls/Frame3d.php | 2 - .../core/Libs/FML/Controls/FrameInstance.php | 2 +- application/core/Libs/FML/Controls/Gauge.php | 1 - application/core/Libs/FML/Controls/Label.php | 27 +- application/core/Libs/FML/Controls/Quad.php | 11 - application/core/Libs/FML/Controls/Video.php | 7 - application/core/Libs/FML/CustomUI.php | 2 +- application/core/Libs/FML/Elements/Format.php | 6 - .../core/Libs/FML/Elements/FrameModel.php | 3 - application/core/Libs/FML/ManiaCode.php | 1 - .../Libs/FML/ManiaCode/InstallMacroblock.php | 3 +- application/core/Libs/FML/ManiaLink.php | 27 +- application/core/Libs/FML/Script/Builder.php | 88 +- application/core/Libs/FML/Script/EUISound.php | 45 - .../FML/Script/Features/ActionTrigger.php | 105 ++ .../core/Libs/FML/Script/Features/Clock.php | 107 ++ .../Libs/FML/Script/Features/EntrySubmit.php | 107 ++ .../core/Libs/FML/Script/Features/MapInfo.php | 90 ++ .../core/Libs/FML/Script/Features/Menu.php | 138 +++ .../Libs/FML/Script/Features/MenuElement.php | 74 ++ .../core/Libs/FML/Script/Features/Paging.php | 326 ++++++ .../Libs/FML/Script/Features/PagingButton.php | 73 ++ .../Libs/FML/Script/Features/PagingPage.php | 72 ++ .../FML/Script/Features/PlayerProfile.php | 104 ++ .../FML/Script/Features/ScriptFeature.php | 23 + .../core/Libs/FML/Script/Features/Toggle.php | 133 +++ .../core/Libs/FML/Script/Features/Tooltip.php | 156 +++ .../core/Libs/FML/Script/Features/UISound.php | 162 +++ .../core/Libs/FML/Script/Parts/Header.txt | 4 - .../core/Libs/FML/Script/Parts/Main.txt | 34 - application/core/Libs/FML/Script/Script.php | 985 +++--------------- .../core/Libs/FML/Script/ScriptConstant.php | 61 ++ .../core/Libs/FML/Script/ScriptFunction.php | 60 ++ .../core/Libs/FML/Script/ScriptInclude.php | 84 ++ .../core/Libs/FML/Script/ScriptLabel.php | 87 ++ application/core/Libs/FML/Stylesheet/Mood.php | 10 +- .../core/Libs/FML/Stylesheet/Style3d.php | 29 +- .../core/Libs/FML/Stylesheet/Stylesheet.php | 6 +- .../core/Libs/FML/Types/ScriptFeatureable.php | 20 + application/core/Libs/FML/autoload.php | 14 +- 44 files changed, 2461 insertions(+), 1038 deletions(-) delete mode 100644 application/core/Libs/FML/Script/EUISound.php create mode 100644 application/core/Libs/FML/Script/Features/ActionTrigger.php create mode 100644 application/core/Libs/FML/Script/Features/Clock.php create mode 100644 application/core/Libs/FML/Script/Features/EntrySubmit.php create mode 100644 application/core/Libs/FML/Script/Features/MapInfo.php create mode 100644 application/core/Libs/FML/Script/Features/Menu.php create mode 100644 application/core/Libs/FML/Script/Features/MenuElement.php create mode 100644 application/core/Libs/FML/Script/Features/Paging.php create mode 100644 application/core/Libs/FML/Script/Features/PagingButton.php create mode 100644 application/core/Libs/FML/Script/Features/PagingPage.php create mode 100644 application/core/Libs/FML/Script/Features/PlayerProfile.php create mode 100644 application/core/Libs/FML/Script/Features/ScriptFeature.php create mode 100644 application/core/Libs/FML/Script/Features/Toggle.php create mode 100644 application/core/Libs/FML/Script/Features/Tooltip.php create mode 100644 application/core/Libs/FML/Script/Features/UISound.php delete mode 100644 application/core/Libs/FML/Script/Parts/Header.txt delete mode 100644 application/core/Libs/FML/Script/Parts/Main.txt create mode 100644 application/core/Libs/FML/Script/ScriptConstant.php create mode 100644 application/core/Libs/FML/Script/ScriptFunction.php create mode 100644 application/core/Libs/FML/Script/ScriptInclude.php create mode 100644 application/core/Libs/FML/Script/ScriptLabel.php create mode 100644 application/core/Libs/FML/Types/ScriptFeatureable.php diff --git a/application/core/Libs/FML/Controls/Audio.php b/application/core/Libs/FML/Controls/Audio.php index a6065fe4..b2e3cac1 100644 --- a/application/core/Libs/FML/Controls/Audio.php +++ b/application/core/Libs/FML/Controls/Audio.php @@ -49,7 +49,6 @@ class Audio extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Playable::setData() - * @return \FML\Controls\Audio */ public function setData($data) { $this->data = (string) $data; @@ -59,7 +58,6 @@ class Audio extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Playable::setDataId() - * @return \FML\Controls\Audio */ public function setDataId($dataId) { $this->dataId = (string) $dataId; @@ -69,7 +67,6 @@ class Audio extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Playable::setPlay() - * @return \FML\Controls\Audio */ public function setPlay($play) { $this->play = ($play ? 1 : 0); @@ -79,7 +76,6 @@ class Audio extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Playable::setLooping() - * @return \FML\Controls\Audio */ public function setLooping($looping) { $this->looping = ($looping ? 1 : 0); @@ -89,7 +85,6 @@ class Audio extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Playable::setMusic() - * @return \FML\Controls\Audio */ public function setMusic($music) { $this->music = ($music ? 1 : 0); @@ -99,7 +94,6 @@ class Audio extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Playable::setVolume() - * @return \FML\Controls\Audio */ public function setVolume($volume) { $this->volume = (float) $volume; @@ -109,7 +103,6 @@ class Audio extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Scriptable::setScriptEvents() - * @return \FML\Controls\Audio */ public function setScriptEvents($scriptEvents) { $this->scriptEvents = ($scriptEvents ? 1 : 0); diff --git a/application/core/Libs/FML/Controls/Control.php b/application/core/Libs/FML/Controls/Control.php index c3b6e4a9..8e983727 100644 --- a/application/core/Libs/FML/Controls/Control.php +++ b/application/core/Libs/FML/Controls/Control.php @@ -3,6 +3,16 @@ namespace FML\Controls; use FML\Types\Renderable; +use FML\Script\Features\ActionTrigger; +use FML\Script\ScriptLabel; + +use FML\Types\ScriptFeatureable; +use FML\Script\Features\MapInfo; +use FML\Script\Features\PlayerProfile; +use FML\Script\Features\UISound; +use FML\Script\Builder; +use FML\Script\Features\Toggle; +use FML\Script\Features\Tooltip; /** * Base Control @@ -12,7 +22,7 @@ use FML\Types\Renderable; * @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ -abstract class Control implements Renderable { +abstract class Control implements Renderable, ScriptFeatureable { /* * Constants */ @@ -43,6 +53,7 @@ abstract class Control implements Renderable { protected $scale = 1.; protected $hidden = 0; protected $classes = array(); + protected $scriptFeatures = array(); /** * Construct a new Control @@ -58,9 +69,13 @@ abstract class Control implements Renderable { /** * Get Control Id * + * @param bool $escaped (optional) Whether the Id should be escaped for ManiaScript * @return string */ - public function getId() { + public function getId($escaped = false) { + if ($escaped) { + return Builder::escapeText($this->id); + } return $this->id; } @@ -258,6 +273,110 @@ abstract class Control implements Renderable { return $this; } + /** + * Add a dynamic Action Trigger + * + * @param string $actionName Action to trigger + * @param string $eventLabel (optional) Event on which the Action is triggered + * @return \FML\Controls\Control + */ + public function addActionTriggerFeature($actionName, $eventLabel = ScriptLabel::MOUSECLICK) { + $actionTrigger = new ActionTrigger($actionName, $this, $eventLabel); + array_push($this->scriptFeatures, $actionTrigger); + return $this; + } + + /** + * Add a dynamic Feature opening the current Map Info + * + * @param string $eventLabel (optional) Event on which the Map Info will be opened + * @return \FML\Controls\Control + */ + public function addMapInfoFeature($eventLabel = ScriptLabel::MOUSECLICK) { + $mapInfo = new MapInfo($this, $eventLabel); + array_push($this->scriptFeatures, $mapInfo); + return $this; + } + + /** + * Add a dynamic Feature to open a specific Player Profile + * + * @param string $login The Login of the Player + * @param string $eventLabel (optional) Event on which the Player Profile will be opened + * @return \FML\Controls\Control + */ + public function addPlayerProfileFeature($login, $eventLabel = ScriptLabel::MOUSECLICK) { + $playerProfile = new PlayerProfile($login, $this, $eventLabel); + array_push($this->scriptFeatures, $playerProfile); + return $this; + } + + /** + * Add a dynamic Feature playing an UISound + * + * @param string $soundName UISound Name + * @param int $variant (optional) Sound Variant + * @param string $eventLabel (optional) Event on which the Sound will be played + * @return \FML\Controls\Control + */ + public function addUISoundFeature($soundName, $variant = 0, $eventLabel = ScriptLabel::MOUSECLICK) { + $uiSound = new UISound($soundName, $this, $variant, $eventLabel); + array_push($this->scriptFeatures, $uiSound); + return $this; + } + + /** + * Add a dynamic Feature toggling another Control + * + * @param Control $toggledControl Toggled Control + * @param string $labelName (optional) Script Label Name + * @param bool $onlyShow (optional) Whether it should only Show the Control but not toggle + * @param bool $onlyHide (optional) Whether it should only Hide the Control but not toggle + * @return \FML\Controls\Control + */ + public function addToggleFeature(Control $toggledControl, $labelName = Scriptlabel::MOUSECLICK, $onlyShow = false, $onlyHide = false) { + $toggle = new Toggle($this, $toggledControl, $labelName, $onlyShow, $onlyHide); + array_push($this->scriptFeatures, $toggle); + return $this; + } + + /** + * Add a dynamic Feature showing a Tooltip on hovering + * + * @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 \FML\Controls\Control + */ + public function addTooltipFeature(Control $tooltipControl, $stayOnClick = false, $invert = false) { + $tooltip = new Tooltip($this, $tooltipControl, $stayOnClick, $invert); + array_push($this->scriptFeatures, $tooltip); + return $this; + } + + /** + * Add a dynamic Feature showing a Tooltip on hovering + * + * @param Label $tooltipControl Tooltip Control + * @param string $text The 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 \FML\Controls\Control + */ + public function addTooltipLabelFeature(Label $tooltipControl, $text, $stayOnClick = false, $invert = false) { + $tooltip = new Tooltip($this, $tooltipControl, $stayOnClick, $invert, $text); + array_push($this->scriptFeatures, $tooltip); + return $this; + } + + /** + * + * @see \FML\Types\ScriptFeatureable::getScriptFeatures() + */ + public function getScriptFeatures() { + return $this->scriptFeatures; + } + /** * * @see \FML\Types\Renderable::render() @@ -286,10 +405,7 @@ abstract class Control implements Renderable { $xmlElement->setAttribute('hidden', $this->hidden); } if (!empty($this->classes)) { - $classes = ''; - foreach ($this->classes as $class) { - $classes .= $class . ' '; - } + $classes = implode(' ', $this->classes); $xmlElement->setAttribute('class', $classes); } return $xmlElement; diff --git a/application/core/Libs/FML/Controls/Entry.php b/application/core/Libs/FML/Controls/Entry.php index b9337315..70972181 100644 --- a/application/core/Libs/FML/Controls/Entry.php +++ b/application/core/Libs/FML/Controls/Entry.php @@ -6,6 +6,7 @@ use FML\Types\NewLineable; use FML\Types\Scriptable; use FML\Types\Styleable; use FML\Types\TextFormatable; +use FML\Script\Features\EntrySubmit; /** * Entry Control @@ -28,6 +29,7 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF protected $textSize = -1; protected $focusAreaColor1 = ''; protected $focusAreaColor2 = ''; + protected $autoComplete = null; /** * Create a new Entry Control @@ -61,6 +63,15 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF return $this; } + /** + * Get the Entry Name + * + * @return string + */ + public function getName() { + return $this->name; + } + /** * Set Default Value * @@ -75,7 +86,6 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF /** * * @see \FML\Types\NewLineable::setAutoNewLine() - * @return \FML\Controls\Entry */ public function setAutoNewLine($autoNewLine) { $this->autoNewLine = ($autoNewLine ? 1 : 0); @@ -85,7 +95,6 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF /** * * @see \FML\Types\Scriptable::setScriptEvents() - * @return \FML\Controls\Entry */ public function setScriptEvents($scriptEvents) { $this->scriptEvents = ($scriptEvents ? 1 : 0); @@ -95,7 +104,6 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF /** * * @see \FML\Types\Styleable::setStyle() - * @return \FML\Controls\Entry */ public function setStyle($style) { $this->style = (string) $style; @@ -105,7 +113,6 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF /** * * @see \FML\Types\TextFormatable::setTextColor() - * @return \FML\Controls\Entry */ public function setTextColor($textColor) { $this->textColor = (string) $textColor; @@ -115,7 +122,6 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF /** * * @see \FML\Types\TextFormatable::setTextSize() - * @return \FML\Controls\Entry */ public function setTextSize($textSize) { $this->textSize = (int) $textSize; @@ -125,7 +131,6 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF /** * * @see \FML\Types\TextFormatable::setAreaColor() - * @return \FML\Controls\Entry */ public function setAreaColor($areaColor) { $this->focusAreaColor1 = (string) $areaColor; @@ -135,13 +140,35 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF /** * * @see \FML\Types\TextFormatable::setAreaFocusColor() - * @return \FML\Controls\Entry */ public function setAreaFocusColor($areaFocusColor) { $this->focusAreaColor2 = (string) $areaFocusColor; return $this; } + /** + * Set Auto Completion + * + * @param bool $autoComplete Whether the Default Value should be automatically completed based on the current Request Parameters + * @return \FML\Controls\Entry + */ + public function setAutoComplete($autoComplete) { + $this->autoComplete = (bool) $autoComplete; + return $this; + } + + /** + * Add a dynamic Feature submitting the Entry + * + * @param string $url Submit Url + * @return \FML\Controls\Entry + */ + public function addSubmitFeature($url) { + $entrySubmit = new EntrySubmit($this, $url); + array_push($this->scriptFeatures, $entrySubmit); + return $this; + } + /** * * @see \FML\Control::render() @@ -154,6 +181,18 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF if ($this->default !== null) { $xmlElement->setAttribute('default', $this->default); } + else if ($this->autoComplete) { + $value = null; + if (array_key_exists($this->name, $_GET)) { + $value = $_GET[$this->name]; + } + else if (array_key_exists($this->name, $_POST)) { + $value = $_POST[$this->name]; + } + if ($value) { + $xmlElement->setAttribute('default', $value); + } + } if ($this->autoNewLine) { $xmlElement->setAttribute('autonewline', $this->autoNewLine); } diff --git a/application/core/Libs/FML/Controls/Frame.php b/application/core/Libs/FML/Controls/Frame.php index 9e5b33d5..373cbec7 100644 --- a/application/core/Libs/FML/Controls/Frame.php +++ b/application/core/Libs/FML/Controls/Frame.php @@ -3,9 +3,10 @@ namespace FML\Controls; use FML\Types\Container; -use FML\Types\Renderable; + use FML\Elements\Format; -use FML\Elements\FrameModel; + +use FML\Types\ScriptFeatureable; /** * Frame Control @@ -46,7 +47,6 @@ class Frame extends Control implements Container { /** * * @see \FML\Types\Container::add() - * @return \FML\Controls\Frame */ public function add(Control $child) { if (!in_array($child, $this->children, true)) { @@ -58,7 +58,6 @@ class Frame extends Control implements Container { /** * * @see \FML\Types\Container::removeChildren() - * @return \FML\Controls\Frame */ public function removeChildren() { $this->children = array(); @@ -68,7 +67,6 @@ class Frame extends Control implements Container { /** * * @see \FML\Types\Container::setFormat() - * @return \FML\Controls\Frame */ public function setFormat(Format $format) { $this->format = $format; @@ -86,6 +84,20 @@ class Frame extends Control implements Container { return $this->format; } + /** + * + * @see \FML\Controls\Control::getScriptFeatures() + */ + public function getScriptFeatures() { + $scriptFeatures = $this->scriptFeatures; + foreach ($this->children as $child) { + if ($child instanceof ScriptFeatureable) { + $scriptFeatures = array_merge($scriptFeatures, $child->getScriptFeatures()); + } + } + return $scriptFeatures; + } + /** * * @see \FML\Renderable::render() diff --git a/application/core/Libs/FML/Controls/Frame3d.php b/application/core/Libs/FML/Controls/Frame3d.php index e205d2cb..c0032196 100644 --- a/application/core/Libs/FML/Controls/Frame3d.php +++ b/application/core/Libs/FML/Controls/Frame3d.php @@ -62,14 +62,12 @@ class Frame3d extends Frame implements Scriptable { */ public function setStyle3d(Style3d $style3d) { $this->style3d = $style3d; - $this->style = ''; return $this; } /** * * @see \FML\Types\Scriptable::setScriptEvents() - * @return \FML\Controls\Frame3d */ public function setScriptEvents($scriptEvents) { $this->scriptEvents = ($scriptEvents ? 1 : 0); diff --git a/application/core/Libs/FML/Controls/FrameInstance.php b/application/core/Libs/FML/Controls/FrameInstance.php index 573f3435..f31e2228 100644 --- a/application/core/Libs/FML/Controls/FrameInstance.php +++ b/application/core/Libs/FML/Controls/FrameInstance.php @@ -3,7 +3,7 @@ namespace FML\Controls; use FML\Elements\FrameModel; -use FML\Types\Renderable; + /** * Class representing an Instance of a Frame Model diff --git a/application/core/Libs/FML/Controls/Gauge.php b/application/core/Libs/FML/Controls/Gauge.php index ee1035cb..32aa030a 100644 --- a/application/core/Libs/FML/Controls/Gauge.php +++ b/application/core/Libs/FML/Controls/Gauge.php @@ -146,7 +146,6 @@ class Gauge extends Control implements Styleable { /** * * @see \FML\Types\Styleable::setStyle() - * @return \FML\Controls\Gauge */ public function setStyle($style) { $this->style = (string) $style; diff --git a/application/core/Libs/FML/Controls/Label.php b/application/core/Libs/FML/Controls/Label.php index 4c2a0cb2..757361b3 100644 --- a/application/core/Libs/FML/Controls/Label.php +++ b/application/core/Libs/FML/Controls/Label.php @@ -8,6 +8,7 @@ use FML\Types\NewLineable; use FML\Types\Scriptable; use FML\Types\Styleable; use FML\Types\TextFormatable; +use FML\Script\Features\Clock; /** * Label Control @@ -132,7 +133,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script /** * * @see \FML\Types\Actionable::setAction() - * @return \FML\Controls\Label */ public function setAction($action) { $this->action = (string) $action; @@ -150,7 +150,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script /** * * @see \FML\Types\Actionable::setActionKey() - * @return \FML\Controls\Label */ public function setActionKey($actionKey) { $this->actionKey = (int) $actionKey; @@ -160,7 +159,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script /** * * @see \FML\Types\Linkable::setUrl() - * @return \FML\Controls\Label */ public function setUrl($url) { $this->url = (string) $url; @@ -170,7 +168,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script /** * * @see \FML\Types\Linkable::setUrlId() - * @return \FML\Controls\Label */ public function setUrlId($urlId) { $this->urlId = (string) $urlId; @@ -180,7 +177,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script /** * * @see \FML\Types\Linkable::setManialink() - * @return \FML\Controls\Label */ public function setManialink($manialink) { $this->manialink = (string) $manialink; @@ -190,7 +186,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script /** * * @see \FML\Types\Linkable::setManialinkId() - * @return \FML\Controls\Label */ public function setManialinkId($manialinkId) { $this->manialinkId = (string) $manialinkId; @@ -200,7 +195,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script /** * * @see \FML\Types\NewLineable::setAutoNewLine() - * @return \FML\Controls\Label */ public function setAutoNewLine($autoNewLine) { $this->autoNewLine = ($autoNewLine ? 1 : 0); @@ -210,7 +204,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script /** * * @see \FML\Types\Scriptable::setScriptEvents() - * @return \FML\Controls\Label */ public function setScriptEvents($scriptEvents) { $this->scriptEvents = ($scriptEvents ? 1 : 0); @@ -220,7 +213,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script /** * * @see \FML\Types\Styleable::setStyle() - * @return \FML\Controls\Label */ public function setStyle($style) { $this->style = (string) $style; @@ -230,7 +222,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script /** * * @see \FML\Types\TextFormatable::setTextSize() - * @return \FML\Controls\Label */ public function setTextSize($textSize) { $this->textSize = (int) $textSize; @@ -240,7 +231,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script /** * * @see \FML\Types\TextFormatable::setTextColor() - * @return \FML\Controls\Label */ public function setTextColor($textColor) { $this->textColor = (string) $textColor; @@ -250,7 +240,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script /** * * @see \FML\Types\TextFormatable::setAreaColor() - * @return \FML\Controls\Label */ public function setAreaColor($areaColor) { $this->focusAreaColor1 = (string) $areaColor; @@ -260,13 +249,25 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script /** * * @see \FML\Types\TextFormatable::setAreaFocusColor() - * @return \FML\Controls\Label */ public function setAreaFocusColor($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 $showFullDate (optional) Whether the Date should be shown + * @return \FML\Controls\Label + */ + public function addClockFeature($showSeconds = true, $showFullDate = false) { + $clock = new Clock($this, $showSeconds, $showFullDate); + array_push($this->scriptFeatures, $clock); + return $this; + } + /** * * @see \FML\Control::render() diff --git a/application/core/Libs/FML/Controls/Quad.php b/application/core/Libs/FML/Controls/Quad.php index eccbd74c..1fca3184 100644 --- a/application/core/Libs/FML/Controls/Quad.php +++ b/application/core/Libs/FML/Controls/Quad.php @@ -141,7 +141,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta /** * * @see \FML\Types\Actionable::setAction() - * @return \FML\Controls\Quad */ public function setAction($action) { $this->action = (string) $action; @@ -159,7 +158,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta /** * * @see \FML\Types\Actionable::setActionKey() - * @return \FML\Controls\Quad */ public function setActionKey($actionKey) { $this->actionKey = (int) $actionKey; @@ -169,7 +167,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta /** * * @see \FML\Types\BgColorable::setBgColor() - * @return \FML\Controls\Quad */ public function setBgColor($bgColor) { $this->bgColor = (string) $bgColor; @@ -179,7 +176,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta /** * * @see \FML\Types\Linkable::setUrl() - * @return \FML\Controls\Quad */ public function setUrl($url) { $this->url = (string) $url; @@ -189,7 +185,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta /** * * @see \FML\Types\Linkable::setUrlId() - * @return \FML\Controls\Quad */ public function setUrlId($urlId) { $this->urlId = (string) $urlId; @@ -199,7 +194,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta /** * * @see \FML\Types\Linkable::setManialink() - * @return \FML\Controls\Quad */ public function setManialink($manialink) { $this->manialink = (string) $manialink; @@ -209,7 +203,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta /** * * @see \FML\Types\Linkable::setManialinkId() - * @return \FML\Controls\Quad */ public function setManialinkId($manialinkId) { $this->manialinkId = (string) $manialinkId; @@ -219,7 +212,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta /** * * @see \FML\Types\Scriptable::setScriptEvents() - * @return \FML\Controls\Quad */ public function setScriptEvents($scriptEvents) { $this->scriptEvents = ($scriptEvents ? 1 : 0); @@ -229,7 +221,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta /** * * @see \FML\Types\Styleable::setStyle() - * @return \FML\Controls\Quad */ public function setStyle($style) { $this->style = (string) $style; @@ -239,7 +230,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta /** * * @see \FML\Types\SubStyleable::setSubStyle() - * @return \FML\Controls\Quad */ public function setSubStyle($subStyle) { $this->subStyle = (string) $subStyle; @@ -249,7 +239,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta /** * * @see \FML\Types\SubStyleable::setStyles() - * @return \FML\Controls\Quad */ public function setStyles($style, $subStyle) { $this->setStyle($style); diff --git a/application/core/Libs/FML/Controls/Video.php b/application/core/Libs/FML/Controls/Video.php index 74228624..aca2d92e 100644 --- a/application/core/Libs/FML/Controls/Video.php +++ b/application/core/Libs/FML/Controls/Video.php @@ -49,7 +49,6 @@ class Video extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Playable::setData() - * @return \FML\Controls\Video */ public function setData($data) { $this->data = (string) $data; @@ -59,7 +58,6 @@ class Video extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Playable::setDataId() - * @return \FML\Controls\Video */ public function setDataId($dataId) { $this->dataId = (string) $dataId; @@ -69,7 +67,6 @@ class Video extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Playable::setPlay() - * @return \FML\Controls\Video */ public function setPlay($play) { $this->play = ($play ? 1 : 0); @@ -79,7 +76,6 @@ class Video extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Playable::setLooping() - * @return \FML\Controls\Video */ public function setLooping($looping) { $this->looping = ($looping ? 1 : 0); @@ -89,7 +85,6 @@ class Video extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Playable::setMusic() - * @return \FML\Controls\Video */ public function setMusic($music) { $this->music = ($music ? 1 : 0); @@ -99,7 +94,6 @@ class Video extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Playable::setVolume() - * @return \FML\Controls\Video */ public function setVolume($volume) { $this->volume = (float) $volume; @@ -109,7 +103,6 @@ class Video extends Control implements Playable, Scriptable { /** * * @see \FML\Types\Scriptable::setScriptEvents() - * @return \FML\Controls\Video */ public function setScriptEvents($scriptEvents) { $this->scriptEvents = ($scriptEvents ? 1 : 0); diff --git a/application/core/Libs/FML/CustomUI.php b/application/core/Libs/FML/CustomUI.php index 965c7188..1d8a2cd3 100644 --- a/application/core/Libs/FML/CustomUI.php +++ b/application/core/Libs/FML/CustomUI.php @@ -184,7 +184,7 @@ class CustomUI { * * @return array */ - private function getSettings() { + protected function getSettings() { $settings = array(); $settings['challenge_info'] = $this->challengeInfoVisible; $settings['chat'] = $this->chatVisible; diff --git a/application/core/Libs/FML/Elements/Format.php b/application/core/Libs/FML/Elements/Format.php index d45144ac..996d10da 100644 --- a/application/core/Libs/FML/Elements/Format.php +++ b/application/core/Libs/FML/Elements/Format.php @@ -45,7 +45,6 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable { /** * * @see \FML\Types\BgColorable::setBgColor() - * @return \FML\Elements\Format */ public function setBgColor($bgColor) { $this->bgColor = (string) $bgColor; @@ -55,7 +54,6 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable { /** * * @see \FML\Types\Styleable::setStyle() - * @return \FML\Elements\Format */ public function setStyle($style) { $this->style = (string) $style; @@ -65,7 +63,6 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable { /** * * @see \FML\Types\TextFormatable::setTextSize() - * @return \FML\Elements\Format */ public function setTextSize($textSize) { $this->textSize = (int) $textSize; @@ -75,7 +72,6 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable { /** * * @see \FML\Types\TextFormatable::setTextColor() - * @return \FML\Elements\Format */ public function setTextColor($textColor) { $this->textColor = (string) $textColor; @@ -85,7 +81,6 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable { /** * * @see \FML\Types\TextFormatable::setAreaColor() - * @return \FML\Elements\Format */ public function setAreaColor($areaColor) { $this->focusAreaColor1 = (string) $areaColor; @@ -95,7 +90,6 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable { /** * * @see \FML\Types\TextFormatable::setAreaFocusColor() - * @return \FML\Elements\Format */ public function setAreaFocusColor($areaFocusColor) { $this->focusAreaColor2 = (string) $areaFocusColor; diff --git a/application/core/Libs/FML/Elements/FrameModel.php b/application/core/Libs/FML/Elements/FrameModel.php index d4f966ba..4dcb975e 100644 --- a/application/core/Libs/FML/Elements/FrameModel.php +++ b/application/core/Libs/FML/Elements/FrameModel.php @@ -57,7 +57,6 @@ class FrameModel implements Container, Renderable { /** * * @see \FML\Types\Container::add() - * @return \FML\Elements\FrameModel */ public function add(Control $childControl) { if (!in_array($childControl, $this->children, true)) { @@ -69,7 +68,6 @@ class FrameModel implements Container, Renderable { /** * * @see \FML\Types\Container::removeChildren() - * @return \FML\Elements\FrameModel */ public function removeChildren() { $this->children = array(); @@ -79,7 +77,6 @@ class FrameModel implements Container, Renderable { /** * * @see \FML\Types\Container::setFormat() - * @return \FML\Elements\FrameModel */ public function setFormat(Format $format) { $this->format = $format; diff --git a/application/core/Libs/FML/ManiaCode.php b/application/core/Libs/FML/ManiaCode.php index 3ecf50e4..afebf535 100644 --- a/application/core/Libs/FML/ManiaCode.php +++ b/application/core/Libs/FML/ManiaCode.php @@ -13,7 +13,6 @@ use FML\ManiaCode\InstallReplay; use FML\ManiaCode\InstallScript; use FML\ManiaCode\InstallSkin; use FML\ManiaCode\JoinServer; -use FML\ManiaCode\Message; use FML\ManiaCode\PlayMap; use FML\ManiaCode\PlayReplay; use FML\ManiaCode\ShowMessage; diff --git a/application/core/Libs/FML/ManiaCode/InstallMacroblock.php b/application/core/Libs/FML/ManiaCode/InstallMacroblock.php index 04978d10..5153c71b 100644 --- a/application/core/Libs/FML/ManiaCode/InstallMacroblock.php +++ b/application/core/Libs/FML/ManiaCode/InstallMacroblock.php @@ -34,6 +34,7 @@ class InstallMacroblock implements Element { * Construct a new InstallMacroblock Element * * @param string $name (optional) Macroblock Name + * @param string $file (optional) Macroblock File * @param string $url (optional) Macroblock Url */ public function __construct($name = null, $file = null, $url = null) { @@ -69,7 +70,7 @@ class InstallMacroblock implements Element { $this->file = (string) $file; return $this; } - + /** * Set the Url of the Macroblock * diff --git a/application/core/Libs/FML/ManiaLink.php b/application/core/Libs/FML/ManiaLink.php index 72f5f065..cd08629b 100644 --- a/application/core/Libs/FML/ManiaLink.php +++ b/application/core/Libs/FML/ManiaLink.php @@ -6,6 +6,7 @@ use FML\Elements\Dico; use FML\Script\Script; use FML\Stylesheet\Stylesheet; use FML\Types\Renderable; +use FML\Types\ScriptFeatureable; /** * Class representing a ManiaLink @@ -32,7 +33,7 @@ class ManiaLink { protected $id = ''; protected $version = 1; protected $background = ''; - protected $navigable3d = 0; + protected $navigable3d = 1; protected $timeout = 0; protected $children = array(); protected $dico = null; @@ -85,7 +86,7 @@ class ManiaLink { /** * Get ManiaLink Id - * + * * @return string */ public function getId() { @@ -128,6 +129,7 @@ class ManiaLink { /** * Add an Element to the ManiaLink * + * @param Renderable $child Child Element to add * @return \FML\ManiaLink */ public function add(Renderable $child) { @@ -245,30 +247,37 @@ class ManiaLink { if (strlen($this->background) > 0) { $maniaLink->setAttribute('background', $this->background); } - if ($this->navigable3d) { - // TODO: check default value + if (!$this->navigable3d) { $maniaLink->setAttribute('navigable3d', $this->navigable3d); } if ($this->timeout) { $timeoutXml = $domDocument->createElement('timeout', $this->timeout); $maniaLink->appendChild($timeoutXml); } - foreach ($this->children as $child) { - $childXml = $child->render($domDocument); - $maniaLink->appendChild($childXml); - } if ($this->dico) { $dicoXml = $this->dico->render($domDocument); $maniaLink->appendChild($dicoXml); } + $scriptFeatures = array(); + foreach ($this->children as $child) { + $childXml = $child->render($domDocument, $this->getScript()); + $maniaLink->appendChild($childXml); + if ($child instanceof ScriptFeatureable) { + $scriptFeatures = array_merge($scriptFeatures, $child->getScriptFeatures()); + } + } + if ($scriptFeatures) { + $this->getScript()->loadFeatures($scriptFeatures); + } if ($this->stylesheet) { $stylesheetXml = $this->stylesheet->render($domDocument); $maniaLink->appendChild($stylesheetXml); } - if ($this->script) { + if ($this->script->needsRendering()) { $scriptXml = $this->script->render($domDocument); $maniaLink->appendChild($scriptXml); } + $this->script->resetGenericScriptLabels(); if ($isChild) { return $maniaLink; } diff --git a/application/core/Libs/FML/Script/Builder.php b/application/core/Libs/FML/Script/Builder.php index e6a358b2..70233e16 100644 --- a/application/core/Libs/FML/Script/Builder.php +++ b/application/core/Libs/FML/Script/Builder.php @@ -16,9 +16,13 @@ abstract class Builder { * * @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 * @return string */ - public static function getLabelImplementationBlock($labelName, $implementationCode) { + public static function getLabelImplementationBlock($labelName, $implementationCode, $isolate = true) { + if ($isolate) { + $implementationCode = 'if(True){' . $implementationCode . '}'; + } $labelText = PHP_EOL . "***{$labelName}***" . PHP_EOL . "***{$implementationCode}***" . PHP_EOL; return $labelText; } @@ -27,13 +31,16 @@ 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 * @return string */ - public static function escapeText($text) { - $escapedText = $text; + public static function escapeText($text, $addApostrophes = false) { $dangers = array('\\', '"', "\n"); - $replacements = array('\\\\', '\\"', '\n'); - $escapedText = str_ireplace($dangers, $replacements, $escapedText); + $replacements = array('\\\\', '\\"', '\\n'); + $escapedText = str_ireplace($dangers, $replacements, $text); + if ($addApostrophes) { + $escapedText = '"' . $escapedText . '"'; + } return $escapedText; } @@ -46,13 +53,15 @@ abstract class Builder { public static function getReal($value) { $value = (float) $value; $stringVal = (string) $value; - if (!fmod($value, 1)) $stringVal .= '.'; + if (!fmod($value, 1)) { + $stringVal .= '.'; + } return $stringVal; } - + /** * Get the Boolean String-Representation of the given Value - * + * * @param bool $value The Value to convert to a ManiaScript Boolean * @return string */ @@ -63,4 +72,67 @@ abstract class Builder { } return "False"; } + + /** + * 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 + * @return string + */ + public static function getArray(array $array, $associative = false) { + $arrayText = '['; + $index = 0; + $count = count($array); + foreach ($array as $key => $value) { + if ($associative) { + if (is_string($key)) { + $arrayText .= '"' . self::escapeText($key) . '"'; + } + else { + $arrayText .= $key; + } + $arrayText .= ' => '; + } + if (is_string($value)) { + $arrayText .= '"' . self::escapeText($value) . '"'; + } + else { + $arrayText .= $value; + } + if ($index < $count - 1) { + $arrayText .= ', '; + $index++; + } + } + $arrayText .= ']'; + return $arrayText; + } + + /** + * Get the Include Command for the given File and Namespace + * + * @param string $file Include File + * @param string $namespace Include Namespace + * @return string + */ + public static function getInclude($file, $namespace) { + $includeText = "#Include \"{$file}\" as {$namespace}" . PHP_EOL; + return $includeText; + } + + /** + * Get the Constant Command for the given Name and Value + * + * @param string $name Constant Name + * @param string $value Constant Value + * @return string + */ + public static function getConstant($name, $value) { + if (is_string($value)) { + $value = '"' . $value . '"'; + } + $constantText = "#Const {$name} {$value}" . PHP_EOL; + return $constantText; + } } diff --git a/application/core/Libs/FML/Script/EUISound.php b/application/core/Libs/FML/Script/EUISound.php deleted file mode 100644 index 1ab9c355..00000000 --- a/application/core/Libs/FML/Script/EUISound.php +++ /dev/null @@ -1,45 +0,0 @@ -setActionName($actionName); + $this->setControl($control); + $this->setLabelName($labelName); + } + + /** + * Set the Action to trigger + * + * @param string $actionName + * @return \FML\Script\Features\ActionTrigger + */ + public function setActionName($actionName) { + $this->actionName = $actionName; + return $this; + } + + /** + * Set the Control + * + * @param Control $control Action Control + * @return \FML\Script\Features\ActionTrigger + */ + public function setControl(Control $control) { + $control->checkId(); + $control->setScriptEvents(true); + $this->control = $control; + return $this; + } + + /** + * Set the Label Name + * + * @param string $labelName Script Label Name + * @return \FML\Script\Features\ActionTrigger + */ + public function setLabelName($labelName) { + $this->labelName = $labelName; + return $this; + } + + /** + * + * @see \FML\Script\Features\ScriptFeature::prepare() + */ + public function prepare(Script $script) { + $script->appendGenericScriptLabel($this->labelName, $this->getScriptText()); + return $this; + } + + /** + * Get the Script Text + * + * @return string + */ + protected function getScriptText() { + $actionName = Builder::escapeText($this->actionName); + if ($this->control) { + // Control event + $controlId = Builder::escapeText($this->control->getId()); + $scriptText = " +if (Event.Control.ControlId == \"{$controlId}\") { + TriggerPageAction(\"{$actionName}\"); +}"; + } + else { + // Other + $scriptText = " +TriggerPageAction(\"{$actionName}\");"; + } + return $scriptText; + } +} diff --git a/application/core/Libs/FML/Script/Features/Clock.php b/application/core/Libs/FML/Script/Features/Clock.php new file mode 100644 index 00000000..454a9795 --- /dev/null +++ b/application/core/Libs/FML/Script/Features/Clock.php @@ -0,0 +1,107 @@ +setLabel($label); + $this->setShowSeconds($showSeconds); + $this->setShowFullDate($showFullDate); + } + + /** + * Set the Label + * + * @param Label $label Clock Label + * @return \FML\Script\Features\Clock + */ + public function setLabel(Label $label) { + $label->checkId(); + $this->label = $label; + return $this; + } + + /** + * Set whether the Seconds should be shown + * + * @param bool $showSeconds Whether the Seconds should be shown + * @return \FML\Script\Features\Clock + */ + public function setShowSeconds($showSeconds) { + $this->showSeconds = (bool) $showSeconds; + return $this; + } + + /** + * Set whether the Full Date should be shown + * + * @param bool $showFullDate Whether the Full Date should be shown + * @return \FML\Script\Features\Clock + */ + public function setShowFullDate($showFullDate) { + $this->showFullDate = (bool) $showFullDate; + return $this; + } + + /** + * + * @see \FML\Script\Features\ScriptFeature::prepare() + */ + public function prepare(Script $script) { + $script->setScriptInclude(ScriptInclude::TEXTLIB); + $script->appendGenericScriptLabel(ScriptLabel::TICK, $this->getScriptText(), true); + return $this; + } + + /** + * Get the Script Text + * + * @return string + */ + protected function getScriptText() { + $controlId = $this->label->getId(true); + $scriptText = " +declare ClockLabel <=> (Page.GetFirstChild(\"{$controlId}\") as CMlLabel); +declare TimeText = CurrentLocalDateText;"; + if (!$this->showSeconds) { + $scriptText .= " +TimeText = TextLib::SubText(TimeText, 0, 16);"; + } + if (!$this->showFullDate) { + $scriptText .= " +TimeText = TextLib::SubText(TimeText, 11, 9);"; + } + $scriptText .= " +ClockLabel.Value = TimeText;"; + return $scriptText; + } +} diff --git a/application/core/Libs/FML/Script/Features/EntrySubmit.php b/application/core/Libs/FML/Script/Features/EntrySubmit.php new file mode 100644 index 00000000..66adbee4 --- /dev/null +++ b/application/core/Libs/FML/Script/Features/EntrySubmit.php @@ -0,0 +1,107 @@ +setEntry($entry); + $this->setUrl($url); + } + + /** + * Set the Entry + * + * @param Entry $entry Entry Control + * @return \FML\Script\Features\EntrySubmit + */ + public function setEntry(Entry $entry) { + $entry->checkId(); + $entry->setScriptEvents(true); + $this->entry = $entry; + return $this; + } + + /** + * Set the Submit Url + * + * @param string $url Submit Url + * @return \FML\Script\Features\EntrySubmit + */ + public function setUrl($url) { + $this->url = (string) $url; + return $this; + } + + /** + * + * @see \FML\Script\Features\ScriptFeature::prepare() + */ + public function prepare(Script $script) { + $script->setScriptInclude(ScriptInclude::TEXTLIB); + $script->appendGenericScriptLabel(ScriptLabel::ENTRYSUBMIT, $this->getScriptText()); + return $this; + } + + /** + * Get the Script Text + * + * @return string + */ + protected function getScriptText() { + $controlId = $this->entry->getId(true); + $url = $this->buildCompatibleUrl(); + $entryName = Builder::escapeText($this->entry->getName()); + $scriptText = " +if (Event.Control.ControlId == \"{$controlId}\") { + declare Entry <=> (Event.Control as CMlEntry); + declare Value = TextLib::URLEncode(Entry.Value); + OpenLink(\"{$url}{$entryName}=\"^Value, CMlScript::LinkType::Goto); +}"; + return $scriptText; + } + + /** + * Build the Submit Url compatible for the Entry Parameter + * + * @return string + */ + protected function buildCompatibleUrl() { + $url = $this->url; + $paramsBegin = stripos($url, '?'); + if (!is_int($paramsBegin) || $paramsBegin < 0) { + $url .= '?'; + } + else { + $url .= '&'; + } + return $url; + } +} diff --git a/application/core/Libs/FML/Script/Features/MapInfo.php b/application/core/Libs/FML/Script/Features/MapInfo.php new file mode 100644 index 00000000..7f8fdb05 --- /dev/null +++ b/application/core/Libs/FML/Script/Features/MapInfo.php @@ -0,0 +1,90 @@ +setControl($control); + $this->setLabelName($labelName); + } + + /** + * Set the Control + * + * @param Control $control Action Control + * @return \FML\Script\Features\ActionTrigger + */ + public function setControl(Control $control) { + $control->checkId(); + $control->setScriptEvents(true); + $this->control = $control; + return $this; + } + + /** + * Set the Label Name + * + * @param string $labelName Script Label Name + * @return \FML\Script\Features\ActionTrigger + */ + public function setLabelName($labelName) { + $this->labelName = $labelName; + return $this; + } + + /** + * + * @see \FML\Script\Features\ScriptFeature::prepare() + */ + public function prepare(Script $script) { + $script->appendGenericScriptLabel($this->labelName, $this->getScriptText()); + return $this; + } + + /** + * Get the Script Text + * + * @return string + */ + protected function getScriptText() { + if ($this->control) { + // Control event + $controlId = Builder::escapeText($this->control->getId()); + $scriptText = " +if (Event.Control.ControlId == \"{$controlId}\") { + ShowCurChallengeCard(); +}"; + } + else { + // Other + $scriptText = " +ShowCurChallengeCard();"; + } + return $scriptText; + } +} diff --git a/application/core/Libs/FML/Script/Features/Menu.php b/application/core/Libs/FML/Script/Features/Menu.php new file mode 100644 index 00000000..58caea29 --- /dev/null +++ b/application/core/Libs/FML/Script/Features/Menu.php @@ -0,0 +1,138 @@ +addNewElement($item, $control); + } + } + + /** + * Add a new Element to the Menu + * + * @param Control $item Item Control in the Menu Bar + * @param Control $control Toggled Menu Control + * @param bool $isStartElement (optional) Whether the Menu should start with this Element + * @return \FML\Script\Features\Menu + */ + public function addElement(Control $item, Control $control, $isStartElement = false) { + $menuElement = new MenuElement($item, $control); + $this->appendElement($menuElement, $isStartElement); + return $this; + } + + /** + * Append an Element to the Menu + * + * @param MenuElement $menuElement Menu Element + * @param bool $isStartElement (optional) Whether the Menu should start with this Element + * @return \FML\Script\Features\Menu + */ + public function appendElement(MenuElement $menuElement, $isStartElement = false) { + array_push($this->elements, $menuElement); + if ($isStartElement) { + $this->setStartElement($menuElement); + } + else if (count($this->elements) > 1) { + $menuElement->getControl()->setVisible(false); + } + return $this; + } + + /** + * Set the Element to start with + * + * @param MenuElement $startElement Starting Element + * @return \FML\Script\Features\Menu + */ + public function setStartElement(MenuElement $startElement) { + $this->startElement = $startElement; + if (!in_array($startElement, $this->elements, true)) { + array_push($this->elements, $startElement); + } + return $this; + } + + /** + * + * @see \FML\Script\Features\ScriptFeature::prepare() + */ + public function prepare(Script $script) { + $updateFunctionName = self::FUNCTION_UPDATE_MENU; + $elementsArrayText = $this->getElementsArrayText(); + + // OnInit + if ($this->startElement) { + $startControlId = $this->startElement->getControl()->getId(true); + $initScriptText = " +{$updateFunctionName}({$elementsArrayText}, \"{$startControlId}\");"; + $script->appendGenericScriptLabel(ScriptLabel::ONINIT, $initScriptText, true); + } + + // MouseClick + $scriptText = " +declare MenuElements = {$elementsArrayText}; +if (MenuElements.existskey(Event.Control.ControlId)) { + declare ShownControlId = MenuElements[Event.Control.ControlId]; + {$updateFunctionName}(MenuElements, ShownControlId); +}"; + $script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $scriptText, true); + + // Update menu function + $updateFunctionText = " +Void {$updateFunctionName}(Text[Text] _Elements, Text _ShownControlId) { + foreach (ItemId => ControlId in _Elements) { + declare Control <=> (Page.GetFirstChild(ControlId)); + Control.Visible = (ControlId == _ShownControlId); + } +}"; + $script->addScriptFunction($updateFunctionName, $updateFunctionText); + + return $this; + } + + /** + * Build the Array Text for the Elements + * + * @return string + */ + protected function getElementsArrayText() { + $elements = array(); + foreach ($this->elements as $element) { + $elements[$element->getItem()->getId()] = $element->getControl()->getId(); + } + return Builder::getArray($elements, true); + } +} diff --git a/application/core/Libs/FML/Script/Features/MenuElement.php b/application/core/Libs/FML/Script/Features/MenuElement.php new file mode 100644 index 00000000..e837f272 --- /dev/null +++ b/application/core/Libs/FML/Script/Features/MenuElement.php @@ -0,0 +1,74 @@ +setItem($item); + $this->setControl($control); + } + + /** + * Set the Item Control + * + * @param Control $item Item Control in the Menu Bar + * @return \FML\Script\Features\MenuElement + */ + public function setItem(Control $item) { + $item->checkId(); + $item->setScriptEvents(true); + $this->item = $item; + return $this; + } + + /** + * Get the Item Control + * + * @return \FML\Controls\Control + */ + public function getItem() { + return $this->item; + } + + /** + * Set the Menu Control + * + * @param Control $control Toggled Menu Control + * @return \FML\Script\Features\MenuElement + */ + public function setControl(Control $control) { + $control->checkId(); + $this->control = $control; + return $this; + } + + /** + * Get the Menu Control + * + * @return \FML\Controls\Control + */ + public function getControl() { + return $this->control; + } +} diff --git a/application/core/Libs/FML/Script/Features/Paging.php b/application/core/Libs/FML/Script/Features/Paging.php new file mode 100644 index 00000000..163c5ba4 --- /dev/null +++ b/application/core/Libs/FML/Script/Features/Paging.php @@ -0,0 +1,326 @@ +setLabel($label); + } + } + + /** + * Add a new Page Control + * + * @param Control $pageControl Page Control + * @param string $pageNumber (optional) Page Number + * @return \FML\Script\Features\Paging + */ + public function addPage(Control $pageControl, $pageNumber = null) { + if ($pageNumber === null) { + $pageNumber = count($this->pages) + 1; + } + $page = new PagingPage($pageControl, $pageNumber); + $this->appendPage($page); + return $this; + } + + /** + * Append a Page + * + * @param PagingPage $page Paging Page + * @return \FML\Script\Features\Paging + */ + public function appendPage(PagingPage $page) { + array_push($this->pages, $page); + return $this; + } + + /** + * Add a new Button to browse through the Pages + * + * @param Control $buttonControl Button used for Browsing + * @param int $browseAction (optional) Number of browsed Pages per Click + * @return \FML\Script\Features\Paging + */ + public function addButton(Control $buttonControl, $browseAction = null) { + if ($browseAction === null) { + $buttonCount = count($this->buttons); + if ($buttonCount % 2 === 0) { + $browseAction = $buttonCount / 2 + 1; + } + else { + $browseAction = $buttonCount / -2 - 1; + } + } + $button = new PagingButton($buttonControl, $browseAction); + $this->appendButton($button); + return $this; + } + + /** + * Append a Button to browse through Pages + * + * @param PagingButton $button Paging Button + * @return \FML\Script\Features\Paging + */ + public function appendButton(PagingButton $button) { + array_push($this->buttons, $button); + return $this; + } + + /** + * Set the Label showing the Page Number + * + * @param Label $label Page Number Label + * @return \FML\Script\Features\Paging + */ + public function setLabel(Label $label) { + $label->checkId(); + $this->label = $label; + return $this; + } + + /** + * Set a custom Minimum Page Number for using Chunks + * + * @param int $minPageNumber Custom Minimum Page Number + * @return \FML\Script\Features\Paging + */ + public function setCustomMinPageNumber($minPageNumber) { + $this->customMinPageNumber = (int) $minPageNumber; + return $this; + } + + /** + * Set a custom Maximum Page Number for using Chunks + * + * @param int $maxPageNumber Custom Maximum Page Number + * @return \FML\Script\Features\Paging + */ + public function setCustomMaxPageNumber($maxPageNumber) { + $this->customMaxPageNumber = (int) $maxPageNumber; + return $this; + } + + /** + * Set the Action triggered when the previous Chunk is needed + * + * @param string $previousChunkAction Triggered Action + * @return \FML\Script\Features\Paging + */ + public function setPreviousChunkAction($previousChunkAction) { + $this->previousChunkAction = (string) $previousChunkAction; + return $this; + } + + /** + * Set the Action triggered when the next Chunk is needed + * + * @param string $nextChunkAction Triggered Action + * @return \FML\Script\Features\Paging + */ + public function setNextChunkAction($nextChunkAction) { + $this->nextChunkAction = (string) $nextChunkAction; + return $this; + } + + /** + * Set if the Chunk Action should get the needed Page Number appended + * + * @param bool $appendPageNumber Whether to append the needed Page Number + * @return \FML\Script\Features\Paging + * + */ + public function setChunkActionAppendsPageNumber($appendPageNumber) { + $this->chunkActionAppendsPageNumber = (bool) $appendPageNumber; + return $this; + } + + /** + * + * @see \FML\Script\Features\ScriptFeature::prepare() + */ + public function prepare(Script $script) { + $script->setScriptInclude(ScriptInclude::TEXTLIB); + + $currentPageVariable = self::VAR_CURRENT_PAGE; + $updatePageFunction = self::FUNCTION_UPDATE_CURRENT_PAGE; + + $minPage = $this->getMinPage(); + $startPageNumber = $minPage->getPageNumber(); + $minPageNumber = $startPageNumber; + if (is_int($this->customMinPageNumber)) { + $minPageNumber = $this->customMinPageNumber; + } + $maxPage = $this->getMaxPage(); + $maxPageNumber = $maxPage->getPageNumber(); + if (is_int($this->customMaxPageNumber)) { + $maxPageNumber = $this->customMaxPageNumber; + } + + $pagingId = $minPage->getControl()->getId(true); + $pageLabelId = $this->label->getId(true); + $pagesArrayText = $this->getPagesArrayText(); + $pageButtonsArrayText = $this->getPageButtonsArrayText(); + + $previousChunkAction = Builder::escapeText($this->previousChunkAction); + $nextChunkAction = Builder::escapeText($this->nextChunkAction); + $chunkActionAppendsPageNumber = Builder::getBoolean($this->chunkActionAppendsPageNumber); + + // Init + $initScriptText = " +declare {$currentPageVariable} for This = Integer[Text]; +{$currentPageVariable}[\"{$pagingId}\"] = {$startPageNumber}; +{$updatePageFunction}(\"{$pagingId}\", \"{$pageLabelId}\", 0, {$minPageNumber}, {$maxPageNumber}, {$pagesArrayText}, \"{$previousChunkAction}\", \"{$nextChunkAction}\", {$chunkActionAppendsPageNumber});"; + $script->appendGenericScriptLabel(ScriptLabel::ONINIT, $initScriptText, true); + + // MouseClick + $clickScriptText = " +declare PageButtons = {$pageButtonsArrayText}; +if (PageButtons.existskey(Event.Control.ControlId)) { + declare BrowseAction = PageButtons[Event.Control.ControlId]; + {$updatePageFunction}(\"{$pagingId}\", \"{$pageLabelId}\", BrowseAction, {$minPageNumber}, {$maxPageNumber}, {$pagesArrayText}, \"{$previousChunkAction}\", \"{$nextChunkAction}\", {$chunkActionAppendsPageNumber}); +}"; + $script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $clickScriptText, true); + + // Update function + $functionText = " +Void {$updatePageFunction}(Text _PagingId, Text _PageLabelId, Integer _BrowseAction, Integer _MinPageNumber, Integer _MaxPageNumber, Text[Integer] _Pages, Text _PreviousChunkAction, Text _NextChunkAction, Boolean _ChunkActionAppendPageNumber) { + declare {$currentPageVariable} for This = Integer[Text]; + if (!{$currentPageVariable}.existskey(_PagingId)) return; + declare CurrentPage = {$currentPageVariable}[_PagingId] + _BrowseAction; + if (CurrentPage < _MinPageNumber) { + CurrentPage = _MinPageNumber; + } else if (CurrentPage > _MaxPageNumber) { + CurrentPage = _MaxPageNumber; + } + {$currentPageVariable}[_PagingId] = CurrentPage; + declare PageFound = False; + foreach (PageNumber => PageId in _Pages) { + declare PageControl <=> Page.GetFirstChild(PageId); + PageControl.Visible = (CurrentPage == PageNumber); + if (PageControl.Visible) { + PageFound = True; + } + } + if (!PageFound && _BrowseAction != 0) { + declare Text ChunkAction; + if (_BrowseAction < 0) { + ChunkAction = _PreviousChunkAction; + } else { + ChunkAction = _NextChunkAction; + } + if (_ChunkActionAppendPageNumber) { + ChunkAction ^= CurrentPage; + } + TriggerPageAction(ChunkAction); + } + declare PageLabel <=> (Page.GetFirstChild(_PageLabelId) as CMlLabel); + if (PageLabel == Null) return; + PageLabel.Value = CurrentPage^\"/\"^_MaxPageNumber; +}"; + $script->addScriptFunction($updatePageFunction, $functionText); + return $this; + } + + /** + * Get the minimum Page + * + * @return \FML\Script\Features\PagingPage + */ + protected function getMinPage() { + $minPageNumber = null; + $minPage = null; + foreach ($this->pages as $page) { + $pageNumber = $page->getPageNumber(); + if ($minPageNumber === null || $pageNumber < $minPageNumber) { + $minPageNumber = $pageNumber; + $minPage = $page; + } + } + return $minPage; + } + + /** + * Get the maximum Page + * + * @return \FML\Script\Features\PagingPage + */ + protected function getMaxPage() { + $maxPageNumber = null; + $maxPage = null; + foreach ($this->pages as $page) { + $pageNumber = $page->getPageNumber(); + if ($maxPageNumber === null || $pageNumber > $maxPageNumber) { + $maxPageNumber = $pageNumber; + $maxPage = $page; + } + } + return $maxPage; + } + + /** + * Build the Array Text for the Pages + * + * @return string + */ + protected function getPagesArrayText() { + $pages = array(); + foreach ($this->pages as $page) { + $pages[$page->getPageNumber()] = $page->getControl()->getId(); + } + return Builder::getArray($pages, true); + } + + /** + * Build the Array Text for the Page Buttons + * + * @return string + */ + protected function getPageButtonsArrayText() { + $pageButtons = array(); + foreach ($this->buttons as $pageButton) { + $pageButtons[$pageButton->getControl()->getId()] = $pageButton->getBrowseAction(); + } + return Builder::getArray($pageButtons, true); + } +} diff --git a/application/core/Libs/FML/Script/Features/PagingButton.php b/application/core/Libs/FML/Script/Features/PagingButton.php new file mode 100644 index 00000000..57109030 --- /dev/null +++ b/application/core/Libs/FML/Script/Features/PagingButton.php @@ -0,0 +1,73 @@ +setControl($control); + $this->setBrowseAction($browseAction); + } + + /** + * Set the Button Control + * + * @param Control $control Browse Control + * @return \FML\Script\Features\PagingButton + */ + public function setControl(Control $control) { + $control->checkId(); + $control->setScriptEvents(true); + $this->control = $control; + return $this; + } + + /** + * Get the Button Control + * + * @return \FML\Controls\Control + */ + public function getControl() { + return $this->control; + } + + /** + * Set the Browse Action + * + * @param int $browseAction Number of browsed Pages per Click + * @return \FML\Script\Features\PagingButton + */ + public function setBrowseAction($browseAction) { + $this->browseAction = (int) $browseAction; + return $this; + } + + /** + * Get the Browse Action + * + * @return int + */ + public function getBrowseAction() { + return $this->browseAction; + } +} diff --git a/application/core/Libs/FML/Script/Features/PagingPage.php b/application/core/Libs/FML/Script/Features/PagingPage.php new file mode 100644 index 00000000..8c5e3a16 --- /dev/null +++ b/application/core/Libs/FML/Script/Features/PagingPage.php @@ -0,0 +1,72 @@ +setControl($control); + $this->setPageNumber($pageNumber); + } + + /** + * Set the Page Control + * + * @param Control $control Page Control + * @return \FML\Script\Features\PagingPage + */ + public function setControl(Control $control) { + $control->checkId(); + $this->control = $control; + return $this; + } + + /** + * Get the Page Control + * + * @return \FML\Controls\Control + */ + public function getControl() { + return $this->control; + } + + /** + * Set the Page Number + * + * @param int $pageNumber Number of the Page + * @return \FML\Script\Features\PagingPage + */ + public function setPageNumber($pageNumber) { + $this->number = (int) $pageNumber; + return $this; + } + + /** + * Get the Page Number + * + * @return int + */ + public function getPageNumber() { + return $this->number; + } +} diff --git a/application/core/Libs/FML/Script/Features/PlayerProfile.php b/application/core/Libs/FML/Script/Features/PlayerProfile.php new file mode 100644 index 00000000..90c0ac3a --- /dev/null +++ b/application/core/Libs/FML/Script/Features/PlayerProfile.php @@ -0,0 +1,104 @@ +setLogin($login); + $this->setControl($control); + $this->setLabelName($labelName); + } + + /** + * Set the Login of the Player + * + * @param string $login Player Login + * @return \FML\Script\Features\PlayerProfile + */ + public function setLogin($login) { + $this->login = $login; + return $this; + } + + /** + * Set the Control + * + * @param Control $control Profile Control + * @return \FML\Script\Features\PlayerProfile + */ + public function setControl(Control $control) { + $control->checkId(); + $control->setScriptEvents(true); + $this->control = $control; + return $this; + } + + /** + * Set the Label Name + * + * @param string $labelName Script Label Name + * @return \FML\Script\Features\PlayerProfile + */ + public function setLabelName($labelName) { + $this->labelName = $labelName; + return $this; + } + + /** + * + * @see \FML\Script\Features\ScriptFeature::prepare() + */ + public function prepare(Script $script) { + $script->appendGenericScriptLabel($this->labelName, $this->getScriptText()); + return $this; + } + + /** + * Get the Script Text + * + * @return string + */ + protected function getScriptText() { + $login = Builder::escapeText($this->login); + if ($this->control) { + // Control event + $controlId = Builder::escapeText($this->control->getId()); + $scriptText = " +if (Event.Control.ControlId == \"{$controlId}\") { + ShowProfile(\"{$login}\"); +}"; + } + else { + // Other + $scriptText = " +ShowProfile(\"{$login}\");"; + } + return $scriptText; + } +} diff --git a/application/core/Libs/FML/Script/Features/ScriptFeature.php b/application/core/Libs/FML/Script/Features/ScriptFeature.php new file mode 100644 index 00000000..ab432ca5 --- /dev/null +++ b/application/core/Libs/FML/Script/Features/ScriptFeature.php @@ -0,0 +1,23 @@ +setTogglingControl($togglingControl); + $this->setToggledControl($toggledControl); + $this->setLabelName($labelName); + $this->setOnlyShow($onlyShow); + $this->setOnlyHide($onlyHide); + } + + /** + * Set the Toggling Control + * + * @param Control $control Toggling Control + * @return \FML\Script\Features\Toggle + */ + public function setTogglingControl(Control $control) { + $control->checkId(); + $control->setScriptEvents(true); + $this->togglingControl = $control; + return $this; + } + + /** + * Set the Toggled Control + * + * @param Control $control Toggling Control + * @return \FML\Script\Features\Toggle + */ + public function setToggledControl(Control $control) { + $control->checkId(); + $this->toggledControl = $control; + return $this; + } + + /** + * Set the Label Name + * + * @param string $labelName Script Label Name + * @return \FML\Script\Features\Toggle + */ + public function setLabelName($labelName) { + $this->labelName = (string) $labelName; + return $this; + } + + /** + * Set only Show + * + * @param bool $onlyShow Whether it should only Show the Control but not toggle + * @return \FML\Script\Features\Toggle + */ + public function setOnlyShow($onlyShow) { + $this->onlyShow = (bool) $onlyShow; + return $this; + } + + /** + * Set only Hide + * + * @param bool $onlyHide Whether it should only Hide the Control but not toggle + * @return \FML\Script\Features\Toggle + */ + public function setOnlyHide($onlyHide) { + $this->onlyHide = (bool) $onlyHide; + return $this; + } + + /** + * + * @see \FML\Script\Features\ScriptFeature::prepare() + */ + public function prepare(Script $script) { + $script->appendGenericScriptLabel($this->labelName, $this->getScriptText()); + return $this; + } + + /** + * Get the Script Text + * + * @return string + */ + protected function getScriptText() { + $togglingControlId = $this->togglingControl->getId(true); + $toggledControlId = $this->toggledControl->getId(true); + $visibility = '!ToggleControl.Visible'; + if ($this->onlyShow) { + $visibility = 'True'; + } + else if ($this->onlyHide) { + $visibility = 'False'; + } + $scriptText = " +if (Event.Control.ControlId == \"{$togglingControlId}\") { + declare ToggleControl = Page.GetFirstChild(\"{$toggledControlId}\"); + ToggleControl.Visible = {$visibility}; +}"; + return $scriptText; + } +} diff --git a/application/core/Libs/FML/Script/Features/Tooltip.php b/application/core/Libs/FML/Script/Features/Tooltip.php new file mode 100644 index 00000000..00929eaa --- /dev/null +++ b/application/core/Libs/FML/Script/Features/Tooltip.php @@ -0,0 +1,156 @@ +setHoverControl($hoverControl); + $this->setTooltipControl($tooltipControl); + $this->setStayOnClick($stayOnClick); + $this->setInvert($invert); + $this->setText($text); + } + + /** + * Set the Hover Control + * + * @param Control $hoverControl Hover Control + * @return \FML\Script\Features\Tooltip + */ + public function setHoverControl(Control $hoverControl) { + $hoverControl->checkId(); + $hoverControl->setScriptEvents(true); + $this->hoverControl = $hoverControl; + return $this; + } + + /** + * Set the Tooltip Control + * + * @param Control $tooltipControl Tooltip Control + * @return \FML\Script\Features\Tooltip + */ + public function setTooltipControl(Control $tooltipControl) { + $tooltipControl->checkId(); + $tooltipControl->setVisible(false); + $this->tooltipControl = $tooltipControl; + return $this; + } + + /** + * Set only Show + * + * @param bool $stayOnClick (optional) Whether the Tooltip should stay on Click + * @return \FML\Script\Features\Tooltip + */ + public function setStayOnClick($stayOnClick) { + $this->stayOnClick = (bool) $stayOnClick; + return $this; + } + + /** + * Set only Hide + * + * @param bool $invert (optional) Whether the Visibility Toggling should be inverted + * @return \FML\Script\Features\Tooltip + */ + public function setInvert($invert) { + $this->invert = (bool) $invert; + return $this; + } + + /** + * Set Text + * + * @param string $text (optional) The Text to display if the TooltipControl is a Label + * @return \FML\Script\Features\Tooltip + */ + public function setText($text) { + $this->text = $text; + return $this; + } + + /** + * + * @see \FML\Script\Features\ScriptFeature::prepare() + */ + public function prepare(Script $script) { + $hoverControlId = $this->hoverControl->getId(true); + $tooltipControlId = $this->tooltipControl->getId(true); + + // MouseOver + $visibility = ($this->invert ? 'False' : 'True'); + $scriptText = " +if (Event.Control.ControlId == \"{$hoverControlId}\") { + declare TooltipControl = Page.GetFirstChild(\"{$tooltipControlId}\"); + TooltipControl.Visible = {$visibility};"; + if (is_string($this->text) && ($this->tooltipControl instanceof Label)) { + $tooltipText = Builder::escapeText($this->text); + $scriptText .= " + declare TooltipLabel = (TooltipControl as CMlLabel); + TooltipLabel.Value = \"{$tooltipText}\";"; + } + $scriptText .= " +}"; + $script->appendGenericScriptLabel(ScriptLabel::MOUSEOVER, $scriptText); + + // MouseOut + $visibility = ($this->invert ? 'True' : 'False'); + $scriptText = " +if (Event.Control.ControlId == \"{$hoverControlId}\") { + declare TooltipControl = Page.GetFirstChild(\"{$tooltipControlId}\");"; + if ($this->stayOnClick) { + $scriptText .= " + declare FML_Clicked for Event.Control = False; + if (!FML_Clicked) "; + } + $scriptText .= " + TooltipControl.Visible = {$visibility}; +}"; + $script->appendGenericScriptLabel(ScriptLabel::MOUSEOUT, $scriptText); + + // MouseClick + if ($this->stayOnClick) { + $scriptText = " +if (Event.Control.ControlId == \"{$hoverControlId}\") { + declare FML_Clicked for Event.Control = False; + FML_Clicked = !FML_Clicked; +}"; + $script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $scriptText); + } + return $this; + } +} diff --git a/application/core/Libs/FML/Script/Features/UISound.php b/application/core/Libs/FML/Script/Features/UISound.php new file mode 100644 index 00000000..046b7e13 --- /dev/null +++ b/application/core/Libs/FML/Script/Features/UISound.php @@ -0,0 +1,162 @@ +setSoundName($soundName); + $this->setControl($control); + $this->setVariant($variant); + $this->setLabelName($labelName); + } + + /** + * Set the Sound to play + * + * @param string $soundName Sound Name + * @return \FML\Script\Features\UISound + */ + public function setSoundName($soundName) { + $this->soundName = (string) $soundName; + return $this; + } + + /** + * Set the Control + * + * @param Control $control Action Control + * @return \FML\Script\Features\UISound + */ + public function setControl(Control $control) { + $control->checkId(); + $control->setScriptEvents(true); + $this->control = $control; + return $this; + } + + /** + * Set the Sound Variant + * + * @param int $variant Sound Variant + * @return \FML\Script\Features\UISound + */ + public function setVariant($variant) { + $this->variant = (int) $variant; + return $this; + } + + /** + * Set the Volume + * + * @param float $volume Sound Volume + * @return \FML\Script\Features\UISound + */ + public function setVolume($volume) { + $this->volume = (float) $volume; + return $this; + } + + /** + * Set the Label Name + * + * @param string $labelName Script Label Name + * @return \FML\Script\Features\UISound + */ + public function setLabelName($labelName) { + $this->labelName = (string) $labelName; + return $this; + } + + /** + * + * @see \FML\Script\Features\ScriptFeature::prepare() + */ + public function prepare(Script $script) { + $script->appendGenericScriptLabel($this->labelName, $this->getScriptText()); + return $this; + } + + /** + * Get the Script Text + * + * @return string + */ + protected function getScriptText() { + if ($this->control) { + // Control event + $controlId = Builder::escapeText($this->control->getId()); + $scriptText = " +if (Event.Control.ControlId == \"{$controlId}\") { + PlayUiSound(CMlScriptIngame::EUISound::{$this->soundName}, {$this->variant}, {$this->volume}); +}"; + } + else { + // Other + $scriptText = " +PlayUiSound(CMlScriptIngame::EUISound::{$this->soundName}, {$this->variant}, {$this->volume});"; + } + return $scriptText; + } +} diff --git a/application/core/Libs/FML/Script/Parts/Header.txt b/application/core/Libs/FML/Script/Parts/Header.txt deleted file mode 100644 index f299f5cb..00000000 --- a/application/core/Libs/FML/Script/Parts/Header.txt +++ /dev/null @@ -1,4 +0,0 @@ -/********************************* -* FancyManiaLinks by steeffeen * -* http://fml.steeffeen.com * -*********************************/ \ No newline at end of file diff --git a/application/core/Libs/FML/Script/Parts/Main.txt b/application/core/Libs/FML/Script/Parts/Main.txt deleted file mode 100644 index 1262b5d3..00000000 --- a/application/core/Libs/FML/Script/Parts/Main.txt +++ /dev/null @@ -1,34 +0,0 @@ -Void Dummy() {} -main() { - declare FML_ScriptStart = Now; - +++OnInit+++ - declare FML_LoopCounter = 0; - declare FML_LastTick = 0; - while (True) { - yield; - foreach (Event in PendingEvents) { - switch (Event.Type) { - case CMlEvent::Type::EntrySubmit: { - +++EntrySubmit+++ - } - case CMlEvent::Type::KeyPress: { - +++KeyPress+++ - } - case CMlEvent::Type::MouseClick: { - +++MouseClick+++ - } - case CMlEvent::Type::MouseOut: { - +++MouseOut+++ - } - case CMlEvent::Type::MouseOver: { - +++MouseOver+++ - } - } - } - FML_LoopCounter += 1; - +++Loop+++ - if (FML_LastTick + 250 > Now) continue; - FML_LastTick = Now; - +++Tick+++ - } -} \ No newline at end of file diff --git a/application/core/Libs/FML/Script/Script.php b/application/core/Libs/FML/Script/Script.php index 67c2e9e4..75a523b7 100644 --- a/application/core/Libs/FML/Script/Script.php +++ b/application/core/Libs/FML/Script/Script.php @@ -2,10 +2,7 @@ namespace FML\Script; -use FML\Controls\Control; -use FML\Controls\Label; -use FML\Types\Scriptable; -use FML\Types\Actionable; +use FML\Script\Features\ScriptFeature; /** * Class representing the ManiaLink Script @@ -18,401 +15,184 @@ class Script { /* * Constants */ - const CLASS_TOOLTIP = 'FML_Tooltip'; - const CLASS_MENU = 'FML_Menu'; - const CLASS_MENUBUTTON = 'FML_MenuButton'; - const CLASS_PAGE = 'FML_Page'; - const CLASS_PAGER = 'FML_Pager'; - const CLASS_PAGELABEL = 'FML_PageLabel'; - const CLASS_PROFILE = 'FML_Profile'; - const CLASS_MAPINFO = 'FML_MapInfo'; - const CLASS_SOUND = 'FML_Sound'; - const CLASS_TOGGLE = 'FML_Toggle'; - const CLASS_SPECTATE = 'FML_Spectate'; - const CLASS_PAGEACTION = 'FML_PageAction'; - const CLASS_TIME = 'FML_Time'; - const OPTION_TOOLTIP_STAYONCLICK = 'FML_StayOnClick_Tooltip'; - const OPTION_TOOLTIP_INVERT = 'FML_Invert_Tooltip'; - const OPTION_TOOLTIP_TEXT = 'FML_Text_Tooltip'; - const OPTION_TOGGLE_SHOW = 'FML_Show_Toggle'; - const OPTION_TOGGLE_HIDE = 'FML_Hide_Toggle'; - const OPTION_PROFILE_OWN = 'FML_Own_Profile'; - const OPTION_TIME_HIDESECONDS = 'FML_HideSeconds_Time'; - const OPTION_TIME_FULLDATE = 'FML_FullDate_Time'; - const LABEL_ONINIT = 'OnInit'; - const LABEL_LOOP = 'Loop'; - const LABEL_TICK = 'Tick'; - const LABEL_ENTRYSUBMIT = 'EntrySubmit'; - const LABEL_KEYPRESS = 'KeyPress'; - const LABEL_MOUSECLICK = 'MouseClick'; - const LABEL_MOUSEOUT = 'MouseOut'; - const LABEL_MOUSEOVER = 'MouseOver'; - const CONSTANT_TOOLTIPTEXTS = 'C_FML_TooltipTexts'; - const FUNCTION_GETTOOLTIPCONTROLID = 'FML_GetTooltipControlId'; - const FUNCTION_SETTOOLTIPTEXT = 'FML_SetTooltipText'; - const FUNCTION_TOGGLE = 'FML_Toggle'; + const TICKINTERVAL = 250; + const VAR_ScriptStart = 'FML_ScriptStart'; + const VAR_LoopCounter = 'FML_LoopCounter'; + const VAR_LastTick = 'FML_LastTick'; /* * Protected Properties */ protected $tagName = 'script'; + protected $features = array(); protected $includes = array(); protected $constants = array(); protected $functions = array(); - protected $tooltips = false; - protected $tooltipTexts = array(); - protected $menus = false; - protected $pages = false; - protected $profile = false; - protected $mapInfo = false; - protected $sounds = array(); - protected $toggles = false; - protected $spectate = false; - protected $pageActions = false; - protected $times = false; + protected $customLabels = array(); + protected $genericLabels = array(); /** - * Create a new Script Object + * Set a Script Include * + * @param string $file Include File + * @param string $namespace Include Namespace * @return \FML\Script\Script */ - public static function create() { - $script = new Script(); - return $script; - } - - /** - * Construct a new Script Object - */ - public function __construct() { - } - - /** - * Set an Include of the Script - * - * @param string $namespace Namespace used for the Include - * @param string $file Included File Url - * @return \FML\Script\Script - */ - public function setInclude($namespace, $file) { - $this->includes[$namespace] = $file; + public function setScriptInclude($file, $namespace = null) { + if (is_object($file) && ($file instanceof ScriptInclude)) { + $scriptInclude = $file; + } + else { + $scriptInclude = new ScriptInclude($file, $namespace); + } + $this->includes[$scriptInclude->getNamespace()] = $scriptInclude; return $this; } /** - * Set a Constant of the Script + * Add a Script Constant * - * @param string $name Variable Name of the Constant + * @param string $name Constant Name * @param string $value Constant Value * @return \FML\Script\Script */ - public function setConstant($name, $value) { - $this->constants[$name] = $value; + public function addScriptConstant($name, $value = null) { + if (is_object($name) && ($name instanceof ScriptConstant)) { + $scriptConstant = $name; + } + else { + $scriptConstant = new ScriptConstant($name, $value); + } + array_push($this->constants, $scriptConstant); return $this; } /** - * Set a Function of the Script + * Add a Script Function * * @param string $name Function Name - * @param string $coding Complete Function Implementation including Declaration + * @param string $text Function Text * @return \FML\Script\Script */ - public function setFunction($name, $coding) { - $this->functions[$name] = $coding; + public function addScriptFunction($name, $text = null) { + if (is_object($name) && ($name instanceof ScriptFunction)) { + $scriptFunction = $name; + } + else { + $scriptFunction = new ScriptFunction($name, $text); + } + array_push($this->functions, $scriptFunction); return $this; } /** - * Add a Tooltip Behavior + * Add a custom Script Text * - * @param Control $hoverControl The Control that shows the Tooltip - * @param Control $tooltipControl The Tooltip to display - * @param string $options,... (optional) Unlimited Number of Tooltip Options + * @param string $name Label Name + * @param string $text Script Text * @return \FML\Script\Script */ - public function addTooltip(Control $hoverControl, Control $tooltipControl) { - if (!($hoverControl instanceof Scriptable)) { - trigger_error('Scriptable Control needed as HoverControl for Tooltips!'); - return $this; + public function addCustomScriptLabel($name, $text = null) { + if (is_object($name) && ($name instanceof ScriptLabel)) { + $scriptLabel = $name; } - $tooltipControl->checkId(); - $tooltipControl->setVisible(false); - $hoverControl->checkId(); - $hoverControl->setScriptEvents(true); - $hoverControl->addClass(self::CLASS_TOOLTIP); - $hoverControl->addClass(self::CLASS_TOOLTIP . '-' . $tooltipControl->getId()); - $options = $this->spliceParameters(func_get_args(), 2); - foreach ($options as $option => $value) { - if ($option == self::OPTION_TOOLTIP_TEXT) { - if (!($tooltipControl instanceof Label)) { - trigger_error('Label needed for Tooltip Text Option!'); - continue; - } - $hoverId = $hoverControl->getId(); - $tooltipId = $tooltipControl->getId(); - if (!isset($this->tooltipTexts[$tooltipId])) { - $this->tooltipTexts[$tooltipId] = array(); - } - $this->tooltipTexts[$tooltipId][$hoverId] = $value; - continue; - } - if ($option == self::OPTION_TOOLTIP_INVERT) { - $tooltipControl->setVisible(true); - } - $hoverControl->addClass($option); + else { + $scriptLabel = new ScriptLabel($name, $text); } - $this->tooltips = true; + array_push($this->customLabels, $scriptLabel); return $this; } /** - * Add a Menu Behavior + * Append a generic Script Text for the next Rendering * - * @param Control $clickControl The Control showing the Menu - * @param Control $menuControl The Menu to show - * @param string $menuId (optional) An identifier to specify the Menu Group + * @param string $name Label Name + * @param string $text Script Text + * @param bool $isolated (optional) Whether to isolate the Label Script * @return \FML\Script\Script */ - public function addMenu(Control $clickControl, Control $menuControl, $menuId = null) { - if (!($clickControl instanceof Scriptable)) { - trigger_error('Scriptable Control needed as ClickControl for Menus!'); - return $this; + public function appendGenericScriptLabel($name, $text = null, $isolated = false) { + if (is_object($name) && ($name instanceof ScriptLabel)) { + $scriptLabel = $name; } - if (!$menuId) $menuId = '_'; - $menuControl->checkId(); - $menuControl->addClass(self::CLASS_MENU); - $menuControl->addClass($menuId); - $clickControl->setScriptEvents(true); - $clickControl->addClass(self::CLASS_MENUBUTTON); - $clickControl->addClass($menuId . '-' . $menuControl->getId()); - $this->menus = true; + else { + $scriptLabel = new ScriptLabel($name, $text, $isolated); + } + array_push($this->genericLabels, $scriptLabel); return $this; } /** - * Add a Page for a Paging Behavior + * Remove all generic Script Texts * - * @param Control $pageControl The Page to display - * @param int $pageNumber The Number of the Page - * @param string $pagesId (optional) An identifier to specify the Pages Group * @return \FML\Script\Script */ - public function addPage(Control $pageControl, $pageNumber, $pagesId = null) { - $pageNumber = (int) $pageNumber; - if (!$pagesId) $pagesId = '_'; - $pageControl->addClass(self::CLASS_PAGE); - $pageControl->addClass($pagesId); - $pageControl->addClass(self::CLASS_PAGE . '-P' . $pageNumber); + public function resetGenericScriptLabels() { + $this->genericLabels = array(); return $this; } /** - * Add a Pager Button for a Paging Behavior + * Add an own Script Feature * - * @param Control $pagerControl The Control to leaf through the Pages - * @param int $pagingAction The Number of Pages the Pager leafs - * @param string $pagesId (optional) An identifier to specify the Pages Group + * @param ScriptFeature $feature Script Feature * @return \FML\Script\Script */ - public function addPager(Control $pagerControl, $pagingAction, $pagesId = null) { - if (!($pagerControl instanceof Scriptable)) { - trigger_error('Scriptable Control needed as PagerControl for Pages!'); - return $this; - } - $pagingAction = (int) $pagingAction; - if (!$pagesId) $pagesId = '_'; - $pagerControl->setScriptEvents(true); - $pagerControl->addClass(self::CLASS_PAGER); - $pagerControl->addClass(self::CLASS_PAGER . '-I' . $pagesId); - $pagerControl->addClass(self::CLASS_PAGER . '-A' . $pagingAction); - $this->pages = true; + public function addFeature(ScriptFeature $feature) { + array_push($this->features, $feature); return $this; } /** - * Add a Label that shows the current Page Number + * Load the given Script Feature * - * @param Label $pageLabel The Label showing the Number of the currently displayed Page - * @param string $pagesId + * @param ScriptFeature $scriptFeature Script Feature to load * @return \FML\Script\Script */ - public function addPageLabel(Label $pageLabel, $pagesId = null) { - if (!$pagesId) $pagesId = '_'; - $pageLabel->addClass(self::CLASS_PAGELABEL); - $pageLabel->addClass($pagesId); + public function loadFeature(ScriptFeature $scriptFeature) { + $scriptFeature->prepare($this); return $this; } /** - * Add a Button Behavior that will open the Built-In Player Profile - * (Works only for Server ManiaLinks) + * Load the given Script Features * - * @param Control $profileControl The Control opening a Profile - * @param string $playerLogin The Player Login - * @param string $options,... (optional) Unlimited Number of Profile Options + * @param array $scriptFeatures Script Features to load * @return \FML\Script\Script */ - public function addProfileButton(Control $profileControl, $playerLogin) { - if (!($profileControl instanceof Scriptable)) { - trigger_error('Scriptable Control needed as ClickControl for Profiles!'); - return $this; + public function loadFeatures(array $scriptFeatures) { + foreach ($scriptFeatures as $scriptFeature) { + $this->loadFeature($scriptFeature); } - $profileControl->setScriptEvents(true); - $profileControl->addClass(self::CLASS_PROFILE); - $playerLogin = (string) $playerLogin; - $profileControl->addClass(self::CLASS_PROFILE . '-' . $playerLogin); - $options = $this->spliceParameters(func_get_args(), 2); - foreach ($options as $option => $value) { - $profileControl->addClass($option); - } - $this->profile = true; return $this; } /** - * Add a Button Behavior that will open the Built-In Map Info - * (Works only on a Server) + * Check if the Script has Stuff so that it needs to be rendered * - * @param Control $mapInfoControl The Control opening the Map Info - * @return \FML\Script\Script + * @return bool */ - public function addMapInfoButton(Control $mapInfoControl) { - if (!($mapInfoControl instanceof Scriptable)) { - trigger_error('Scriptable Control needed as ClickControl for Map Info!'); - return $this; + public function needsRendering() { + if ($this->features || $this->customLabels || $this->genericLabels) { + return true; } - $mapInfoControl->setScriptEvents(true); - $mapInfoControl->addClass(self::CLASS_MAPINFO); - $this->mapInfo = true; - return $this; + return false; } /** - * Add a Sound Playing for the Control - * (Works only for Server ManiaLinks) + * Build the complete Script Text * - * @param Control $control The Control playing a Sound - * @param string $soundName The Sound to play - * @param int $soundVariant (optional) Sound Variant - * @param float $soundVolume (optional) Sound Volume - * @param string $eventLabel (optional) The Event Label on which the Sound should be played - * @return \FML\Script\Script + * @return string */ - public function addSound(Control $control, $soundName, $soundVariant = 0, $soundVolume = 1., $eventLabel = self::LABEL_MOUSECLICK) { - if (!($control instanceof Scriptable)) { - trigger_error('Scriptable Control needed as ClickControl for Sounds!'); - return $this; - } - $control->setScriptEvents(true); - $control->checkId(); - $control->addClass(self::CLASS_SOUND); - $soundData = array(); - $soundData['soundName'] = $soundName; - $soundData['soundVariant'] = $soundVariant; - $soundData['soundVolume'] = $soundVolume; - $soundData['controlId'] = $control->getId(); - $soundData['eventLabel'] = $eventLabel; - array_push($this->sounds, $soundData); - return $this; - } - - /** - * Add a Toggling Behavior - * - * @param Control $clickControl The Control that toggles another Control on Click - * @param Control $toggleControl The Control to toggle - * @param string $mode (optional) Whether the Visibility should be toggled or only en-/disabled - * @return \FML\Script\Script - */ - public function addToggle(Control $clickControl, Control $toggleControl, $option = null) { - if (!($clickControl instanceof Scriptable)) { - trigger_error('Scriptable Control needed as ClickControl for Toggles!'); - return $this; - } - $toggleControl->checkId(); - if ($option == self::OPTION_TOGGLE_HIDE) { - $toggleControl->setVisible(true); - $clickControl->addClass($option); - } - else if ($option == self::OPTION_TOGGLE_SHOW) { - $toggleControl->setVisible(false); - $clickControl->addClass($option); - } - $clickControl->setScriptEvents(true); - $clickControl->addClass(self::CLASS_TOGGLE); - $clickControl->addClass(self::CLASS_TOGGLE . '-' . $toggleControl->getId()); - $this->toggles = true; - return $this; - } - - /** - * Add a Spectate Button Behavior - * - * @param Control $clickControl The Control that works as Spectate Button - * @param string $spectateTargetLogin The Login of the Player to Spectate - * @return \FML\Script\Script - */ - public function addSpectateButton(Control $clickControl, $spectateTargetLogin) { - // FIXME: current implementation doesn't support logins with dots in them ('nick.name') - if (!($clickControl instanceof Scriptable)) { - trigger_error('Scriptable Control needed as ClickControl for Spectating!'); - return $this; - } - $clickControl->setScriptEvents(true); - $clickControl->addClass(self::CLASS_SPECTATE); - $spectateTargetLogin = (string) $spectateTargetLogin; - $clickControl->addClass(self::CLASS_SPECTATE . '-' . $spectateTargetLogin); - $this->spectate = true; - return $this; - } - - /** - * Trigger an Action on Control Click - * - * @param Control $actionControl The Control triggering the Action - * @param string $action (optional) The Action to trigger (if empty the Action of the Control will be triggered) - * @return \FML\Script\Script - */ - public function addPageActionTrigger(Control $actionControl, $action = null) { - if (!($actionControl instanceof Scriptable)) { - trigger_error('Scriptable Control needed as ActionControl for PageActions!'); - return $this; - } - $action = (string) $action; - if (strlen($action) <= 0) { - if (!($actionControl instanceof Actionable)) { - trigger_error('Either Action or Actionable Control needed for PageActions!'); - return $this; - } - $action = $actionControl->getAction(); - } - $actionControl->setScriptEvents(true); - $actionControl->setAction(''); - $actionControl->addClass(self::CLASS_PAGEACTION); - $actionControl->addClass(self::CLASS_PAGEACTION . '-' . $action); - $this->pageActions = true; - return $this; - } - - /** - * Add a Label showing the current Time - * - * @param Label $timeLabel The Label showing the current Time - * @param bool $hideSeconds Whether the seconds should be hidden - * @param bool $showDate Whether to show the full Date Text - * @return \FML\Script\Script - */ - public function addTimeLabel(Label $timeLabel, $hideSeconds = false, $showDate = false) { - $timeLabel->addClass(self::CLASS_TIME); - if ($hideSeconds) { - $timeLabel->addClass(self::OPTION_TIME_HIDESECONDS); - } - if ($showDate) { - $timeLabel->addClass(self::OPTION_TIME_FULLDATE); - } - $this->times = true; - return $this; + public function buildScriptText() { + $scriptText = PHP_EOL; + $scriptText .= $this->getHeaderComment(); + $scriptText .= $this->getIncludes(); + $scriptText .= $this->getConstants(); + $scriptText .= $this->getFunctions(); + $scriptText .= $this->getLabels(); + $scriptText .= $this->getMainFunction(); + return $scriptText; } /** @@ -422,6 +202,7 @@ class Script { * @return \DOMElement */ public function render(\DOMDocument $domDocument) { + $this->loadFeatures($this->features); $scriptXml = $domDocument->createElement($this->tagName); $scriptText = $this->buildScriptText(); $scriptComment = $domDocument->createComment($scriptText); @@ -429,37 +210,17 @@ class Script { return $scriptXml; } - /** - * Build the complete Script Text - * - * @return string - */ - private function buildScriptText() { - $mainFunction = $this->getMainFunction(); - $labels = $this->getLabels(); - $functions = $this->getFunctions(); - $constants = $this->getConstants(); - $includes = $this->getIncludes(); - $headerComment = $this->getHeaderComment(); - - $scriptText = PHP_EOL; - $scriptText .= $headerComment; - $scriptText .= $includes; - $scriptText .= $constants; - $scriptText .= $functions; - $scriptText .= $labels; - $scriptText .= $mainFunction; - - return $scriptText; - } - /** * Get the Header Comment * * @return string */ - private function getHeaderComment() { - $headerComment = file_get_contents(__DIR__ . '/Parts/Header.txt'); + protected function getHeaderComment() { + $headerComment = '/**************************************************** +* FancyManiaLinks v' . FML_VERSION . ' by steeffeen * +* http://github.com/steeffeen/FancyManiaLinks * +****************************************************/ +'; return $headerComment; } @@ -468,11 +229,8 @@ class Script { * * @return string */ - private function getIncludes() { - $includesText = PHP_EOL; - foreach ($this->includes as $namespace => $file) { - $includesText .= "#Include \"{$file}\" as {$namespace}" . PHP_EOL; - } + protected function getIncludes() { + $includesText = implode(PHP_EOL, $this->includes); return $includesText; } @@ -481,495 +239,30 @@ class Script { * * @return string */ - private function getConstants() { - $this->buildTooltipConstants(); - $constantsText = PHP_EOL; - foreach ($this->constants as $name => $value) { - $constantsText .= "#Const {$name} {$value}" . PHP_EOL; - } + protected function getConstants() { + $constantsText = implode(PHP_EOL, $this->constants); return $constantsText; } - /** - * Build the Constants needed for tooltips - */ - private function buildTooltipConstants() { - if (!$this->tooltips) return; - $constantText = '['; - $index = 0; - $count = count($this->tooltipTexts); - if ($count > 0) { - foreach ($this->tooltipTexts as $tooltipId => $tooltipTexts) { - $constantText .= '"' . Builder::escapeText($tooltipId) . '" => ['; - $subIndex = 0; - $subCount = count($tooltipTexts); - if ($subCount > 0) { - foreach ($tooltipTexts as $hoverId => $text) { - $constantText .= '"' . Builder::escapeText($hoverId) . '" => "' . Builder::escapeText($text) . '"'; - if ($subIndex < $subCount - 1) $constantText .= ', '; - $subIndex++; - } - } - else { - $constantText .= '""'; - } - $constantText .= ']'; - if ($index < $count - 1) $constantText .= ', '; - $index++; - } - } - else { - $constantText .= '"" => ["" => ""]'; - } - $constantText .= ']'; - $this->setConstant(self::CONSTANT_TOOLTIPTEXTS, $constantText); - } - /** * Get the Functions * * @return string */ - private function getFunctions() { - $this->buildTooltipFunctions(); - $functionsText = PHP_EOL; - foreach ($this->functions as $name => $coding) { - $functionsText .= $coding; - } + protected function getFunctions() { + $functionsText = implode(PHP_EOL, $this->functions); return $functionsText; } /** - * Build the Functions needed for Tooltips - */ - private function buildTooltipFunctions() { - if (!$this->tooltips) return; - $this->setInclude('TextLib', 'TextLib'); - $setFunctionText = " -Void " . self::FUNCTION_SETTOOLTIPTEXT . "(CMlControl _TooltipControl, CMlControl _HoverControl) { - if (!_TooltipControl.Visible) return; - declare TooltipId = _TooltipControl.ControlId; - declare HoverId = _HoverControl.ControlId; - if (!" . self::CONSTANT_TOOLTIPTEXTS . ".existskey(TooltipId)) return; - if (!" . self::CONSTANT_TOOLTIPTEXTS . "[TooltipId].existskey(HoverId)) return; - declare Label = (_TooltipControl as CMlLabel); - Label.Value = " . self::CONSTANT_TOOLTIPTEXTS . "[TooltipId][HoverId]; -}"; - $this->setFunction(self::FUNCTION_SETTOOLTIPTEXT, $setFunctionText); - $getFunctionText = " -Text " . self::FUNCTION_GETTOOLTIPCONTROLID . "(Text _ControlClass) { - declare ClassParts = TextLib::Split(\"-\", _ControlClass); - if (ClassParts.count < 2) return \"\"; - if (ClassParts[0] != \"" . self::CLASS_TOOLTIP . "\") return \"\"; - return ClassParts[1]; -}"; - $this->setFunction(self::FUNCTION_GETTOOLTIPCONTROLID, $getFunctionText); - } - - /** - * Get Labels + * Get the Labels * * @return string */ - private function getLabels() { - $labelsText = PHP_EOL; - $labelsText .= $this->getTooltipLabels(); - $labelsText .= $this->getMenuLabels(); - $labelsText .= $this->getPagesLabels(); - $labelsText .= $this->getProfileLabels(); - $labelsText .= $this->getMapInfoLabels(); - $labelsText .= $this->getSoundLabels(); - $labelsText .= $this->getToggleLabels(); - $labelsText .= $this->getSpectateLabels(); - $labelsText .= $this->getTimeLabels(); - return $labelsText; - } - - /** - * Get the Tooltip Labels - * - * @return string - */ - private function getTooltipLabels() { - if (!$this->tooltips) return ''; - $mouseOverScript = " -if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIP . "\")) { - declare Invert = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_INVERT . "\"); - foreach (ControlClass in Event.Control.ControlClasses) { - declare ControlId = " . self::FUNCTION_GETTOOLTIPCONTROLID . "(ControlClass); - if (ControlId == \"\") continue; - declare TooltipControl <=> Page.GetFirstChild(ControlId); - if (TooltipControl == Null) continue; - TooltipControl.Visible = !Invert; - " . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control); - } -}"; - $mouseOutScript = " -if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIP . "\")) { - declare FML_Clicked for Event.Control = False; - declare StayOnClick = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_STAYONCLICK . "\"); - if (!StayOnClick || !FML_Clicked) { - declare Invert = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_INVERT . "\"); - foreach (ControlClass in Event.Control.ControlClasses) { - declare ControlId = " . self::FUNCTION_GETTOOLTIPCONTROLID . "(ControlClass); - if (ControlId == \"\") continue; - declare TooltipControl <=> Page.GetFirstChild(ControlId); - if (TooltipControl == Null) continue; - TooltipControl.Visible = Invert; - " . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control); - } - } -}"; - $mouseClickScript = " -if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIP . "\")) { - declare Handle = True; - declare Show = False; - declare StayOnClick = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_STAYONCLICK . "\"); - if (StayOnClick) { - declare FML_Clicked for Event.Control = False; - FML_Clicked = !FML_Clicked; - if (FML_Clicked) { - Handle = False; - } else { - Show = False; - } - } else { - Handle = False; - } - if (Handle) { - declare Invert = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_INVERT . "\"); - foreach (ControlClass in Event.Control.ControlClasses) { - declare ControlId = " . self::FUNCTION_GETTOOLTIPCONTROLID . "(ControlClass); - if (ControlId == \"\") continue; - declare TooltipControl <=> Page.GetFirstChild(ControlId); - if (TooltipControl == Null) continue; - TooltipControl.Visible = Show && !Invert; - " . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control); - } - } -}"; - $tooltipsLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSEOVER, $mouseOverScript); - $tooltipsLabels .= Builder::getLabelImplementationBlock(self::LABEL_MOUSEOUT, $mouseOutScript); - $tooltipsLabels .= Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $mouseClickScript); - return $tooltipsLabels; - } - - /** - * Get the Menu Labels - * - * @return string - */ - private function getMenuLabels() { - if (!$this->menus) return ''; - $this->setInclude('TextLib', 'TextLib'); - $mouseClickScript = " -if (Event.Control.HasClass(\"" . self::CLASS_MENUBUTTON . "\")) { - declare Text MenuIdClass; - declare Text MenuControlId; - foreach (ControlClass in Event.Control.ControlClasses) { - declare ClassParts = TextLib::Split(\"-\", ControlClass); - if (ClassParts.count < 2) continue; - MenuIdClass = ClassParts[0]; - MenuControlId = ClassParts[1]; - break; - } - Page.GetClassChildren(MenuIdClass, Page.MainFrame, True); - foreach (MenuControl in Page.GetClassChildren_Result) { - if (!MenuControl.HasClass(\"" . self::CLASS_MENU . "\")) continue; - MenuControl.Visible = (MenuControlId == MenuControl.ControlId); - } -}"; - $menuLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $mouseClickScript); - return $menuLabels; - } - - /** - * Get the Pages Labels - * - * @return string - */ - private function getPagesLabels() { - if (!$this->pages) return ""; - $this->setInclude('TextLib', 'TextLib'); - $pagesNumberPrefix = self::CLASS_PAGE . '-P'; - $pagesNumberPrefixLength = strlen($pagesNumberPrefix); - - $pagesInitScript = " -declare PageLabelControls = CMlControl[]; -Page.GetClassChildren(\"" . self::CLASS_PAGELABEL . "\", Page.MainFrame, True); -foreach (PageLabelControl in Page.GetClassChildren_Result) { - declare Temp = PageLabelControl; - PageLabelControls.add(Temp); -} -declare FML_MinPageNumber for This = Integer[Text]; -declare FML_MaxPageNumber for This = Integer[Text]; -declare FML_PageNumber for This = Integer[Text]; -foreach (PageLabelControl in PageLabelControls) { - foreach (ControlClass in PageLabelControl.ControlClasses) { - Page.GetClassChildren(ControlClass, Page.MainFrame, True); - foreach (PageControl in Page.GetClassChildren_Result) { - if (!PageControl.HasClass(\"" . self::CLASS_PAGE . "\")) continue; - foreach (PageControlClass in PageControl.ControlClasses) { - if (TextLib::SubText(PageControlClass, 0, {$pagesNumberPrefixLength}) != \"{$pagesNumberPrefix}\") continue; - declare PageNumber = TextLib::ToInteger(TextLib::SubText(PageControlClass, {$pagesNumberPrefixLength}, TextLib::Length(PageControlClass))); - if (!FML_MinPageNumber.existskey(ControlClass) || PageNumber < FML_MinPageNumber[ControlClass]) { - FML_MinPageNumber[ControlClass] = PageNumber; - } - if (!FML_MaxPageNumber.existskey(ControlClass) || PageNumber > FML_MaxPageNumber[ControlClass]) { - FML_MaxPageNumber[ControlClass] = PageNumber; - } - break; - } - } - if (FML_MinPageNumber.existskey(ControlClass)) { - FML_PageNumber[ControlClass] = FML_MinPageNumber[ControlClass]; - declare PageLabel <=> (PageLabelControl as CMlLabel); - PageLabel.Value = FML_PageNumber[ControlClass]^\"/\"^FML_MaxPageNumber[ControlClass]; - } - } -}"; - - $pagesClickScript = " -if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) { - declare Text PagesId; - declare Integer PagingAction; - foreach (ControlClass in Event.Control.ControlClasses) { - declare ClassParts = TextLib::Split(\"-\", ControlClass); - if (ClassParts.count < 2) continue; - if (ClassParts[0] != \"" . self::CLASS_PAGER . "\") continue; - switch (TextLib::SubText(ClassParts[1], 0, 1)) { - case \"I\": { - PagesId = TextLib::SubText(ClassParts[1], 1, TextLib::Length(ClassParts[1])); - } - case \"A\": { - PagingAction = TextLib::ToInteger(TextLib::SubText(ClassParts[1], 1, TextLib::Length(ClassParts[1]))); - } - } - } - declare FML_MinPageNumber for This = Integer[Text]; - declare FML_MaxPageNumber for This = Integer[Text]; - declare FML_PageNumber for This = Integer[Text]; - FML_PageNumber[PagesId] += PagingAction; - if (FML_PageNumber[PagesId] < FML_MinPageNumber[PagesId]) { - FML_PageNumber[PagesId] = FML_MinPageNumber[PagesId]; - } - if (FML_PageNumber[PagesId] > FML_MaxPageNumber[PagesId]) { - FML_PageNumber[PagesId] = FML_MaxPageNumber[PagesId]; - } - Page.GetClassChildren(PagesId, Page.MainFrame, True); - foreach (PageControl in Page.GetClassChildren_Result) { - if (!PageControl.HasClass(\"" . self::CLASS_PAGE . "\")) continue; - declare PageNumber = -1; - foreach (ControlClass in PageControl.ControlClasses) { - if (TextLib::SubText(ControlClass, 0, {$pagesNumberPrefixLength}) != \"{$pagesNumberPrefix}\") continue; - PageNumber = TextLib::ToInteger(TextLib::SubText(ControlClass, {$pagesNumberPrefixLength}, TextLib::Length(ControlClass))); - break; - } - PageControl.Visible = (PageNumber == FML_PageNumber[PagesId]); - } - Page.GetClassChildren(\"" . self::CLASS_PAGELABEL . "\", Page.MainFrame, True); - foreach (PageControl in Page.GetClassChildren_Result) { - if (!PageControl.HasClass(PagesId)) continue; - declare PageLabel <=> (PageControl as CMlLabel); - PageLabel.Value = FML_PageNumber[PagesId]^\"/\"^FML_MaxPageNumber[PagesId]; - } -}"; - - $pagesLabels = Builder::getLabelImplementationBlock(self::LABEL_ONINIT, $pagesInitScript); - $pagesLabels .= Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $pagesClickScript); - return $pagesLabels; - } - - /** - * Get the Profile Labels - * - * @return string - */ - private function getProfileLabels() { - if (!$this->profile) return ""; - $this->setInclude('TextLib', 'TextLib'); - $prefixLength = strlen(self::CLASS_PROFILE) + 1; - $profileScript = " -if (Event.Control.HasClass(\"" . self::CLASS_PROFILE . "\")) { - declare Login = LocalUser.Login; - if (!Event.Control.HasClass(\"" . self::OPTION_PROFILE_OWN . "\")) { - foreach (ControlClass in Event.Control.ControlClasses) { - declare ClassParts = TextLib::Split(\"-\", ControlClass); - if (ClassParts.count < 2) continue; - if (ClassParts[0] != \"" . self::CLASS_PROFILE . "\") continue; - Login = TextLib::SubText(ControlClass, {$prefixLength}, TextLib::Length(ControlClass)); - break; - } - } - ShowProfile(Login); -}"; - $profileLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $profileScript); - return $profileLabels; - } - - /** - * Get the Map Info Labels - * - * @return string - */ - private function getMapInfoLabels() { - if (!$this->mapInfo) return ""; - $mapInfoScript = " -if (Event.Control.HasClass(\"" . self::CLASS_MAPINFO . "\")) { - ShowCurChallengeCard(); -}"; - $mapInfoLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $mapInfoScript); - return $mapInfoLabels; - } - - /** - * Get the Sound Labels - * - * @return string - */ - private function getSoundLabels() { - if (!$this->sounds) return ''; - $labelScripts = array(); - foreach ($this->sounds as $soundData) { - $volume = Builder::getReal($soundData['soundVolume']); - $labelScript = " - case \"{$soundData['controlId']}\": { - PlayUiSound(CMlScriptIngame::EUISound::{$soundData['soundName']}, {$soundData['soundVariant']}, {$volume}); - }"; - if (!isset($labelScripts[$soundData['eventLabel']])) { - $labelScripts[$soundData['eventLabel']] = ''; - } - $labelScripts[$soundData['eventLabel']] .= $labelScript; - } - - $soundScript = ''; - foreach ($labelScripts as $label => $scriptPart) { - $labelScript = " -if (Event.Control.HasClass(\"" . self::CLASS_SOUND . "\")) { - switch (Event.Control.ControlId) { - {$scriptPart} - } -}"; - $soundScript .= Builder::getLabelImplementationBlock($label, $labelScript); - } - return $soundScript; - } - - /** - * Get the Toggle Labels - * - * @return string - */ - private function getToggleLabels() { - if (!$this->toggles) return ''; - $this->setInclude('TextLib', 'TextLib'); - $toggleScript = " -if (Event.Control.HasClass(\"" . self::CLASS_TOGGLE . "\")) { - declare HasShow = Event.Control.HasClass(\"" . self::OPTION_TOGGLE_SHOW . "\"); - declare HasHide = Event.Control.HasClass(\"" . self::OPTION_TOGGLE_HIDE . "\"); - declare Toggle = True; - declare Show = True; - if (HasShow || HasHide) { - Toggle = False; - Show = HasShow; - } - declare PrefixLength = TextLib::Length(\"" . self::CLASS_TOGGLE . "\"); - foreach (ControlClass in Event.Control.ControlClasses) { - declare ClassParts = TextLib::Split(\"-\", ControlClass); - if (ClassParts.count < 2) continue; - if (ClassParts[0] != \"" . self::CLASS_TOGGLE . "\") continue; - declare ToggleControl <=> Page.GetFirstChild(ClassParts[1]); - if (ToggleControl == Null) continue; - if (Toggle) { - ToggleControl.Visible = !ToggleControl.Visible; - } else { - ToggleControl.Visible = Show; - } - } -}"; - $toggleScript = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $toggleScript); - return $toggleScript; - } - - /** - * Get the Spectate labels - * - * @return string - */ - private function getSpectateLabels() { - if (!$this->spectate) return ''; - $this->setInclude('TextLib', 'TextLib'); - $prefixLength = strlen(self::CLASS_SPECTATE) + 1; - $spectateScript = " -if (Event.Control.HasClass(\"" . self::CLASS_SPECTATE . "\")) { - declare Login = \"\"; - foreach (ControlClass in Event.Control.ControlClasses) { - declare ClassParts = TextLib::Split(\"-\", ControlClass); - if (ClassParts.count < 2) continue; - if (ClassParts[0] != \"" . self::CLASS_SPECTATE . "\") continue; - Login = TextLib::SubText(ControlClass, {$prefixLength}, TextLib::Length(ControlClass)); - break; - } - if (Login != \"\") { - SetSpectateTarget(Login); - } -}"; - $spectateScript = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $spectateScript); - return $spectateScript; - } - - /** - * Get the Page Actions Labels - * - * @return string - */ - private function getPageActionLabels() { - if (!$this->pageActions) return ''; - $this->setInclude('TextLib', 'TextLib'); - $prefixLength = strlen(self::CLASS_PAGEACTION) + 1; - $pageActionScript = " -if (Event.Control.HasClass(\"" . self::CLASS_PAGEACTION . "\")) { - declare Action = \"\"; - foreach (ControlClass in Event.Control.ControlClasses) { - declare ClassParts = TextLib::Split(\"-\", ControlClass); - if (ClassParts.count < 2) continue; - if (ClassParts[0] != \"" . self::CLASS_PAGEACTION . "\") continue; - Action = TextLib::SubText(ControlClass, {$prefixLength}, TextLib::Length(ControlClass)); - break; - } - if (Action != \"\") { - TriggerPageAction(Action); - } -}"; - $pageActionScript = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $pageActionScript); - return $pageActionScript; - } - - /** - * Get the Time Labels - * - * @return string - */ - private function getTimeLabels() { - if (!$this->times) return ''; - $this->setInclude('TextLib', 'TextLib'); - $timesScript = " -Page.GetClassChildren(\"" . self::CLASS_TIME . "\", Page.MainFrame, True); -foreach (TimeLabelControl in Page.GetClassChildren_Result) { - declare TimeLabel = (TimeLabelControl as CMlLabel); - declare HideSeconds = TimeLabel.HasClass(\"" . self::OPTION_TIME_HIDESECONDS . "\"); - declare ShowDate = TimeLabel.HasClass(\"" . self::OPTION_TIME_FULLDATE . "\"); - declare TimeText = CurrentLocalDateText; - if (HideSeconds) { - TimeText = TextLib::SubText(TimeText, 0, 16); - } - if (!ShowDate) { - TimeText = TextLib::SubText(TimeText, 11, 9); - } - TimeLabel.Value = TimeText; -}"; - $timesScript = Builder::getLabelImplementationBlock(self::LABEL_TICK, $timesScript); - return $timesScript; + protected function getLabels() { + $customLabelsText = implode(PHP_EOL, $this->customLabels); + $genericLabelsText = implode(PHP_EOL, $this->genericLabels); + return $customLabelsText . $genericLabelsText; } /** @@ -977,32 +270,42 @@ foreach (TimeLabelControl in Page.GetClassChildren_Result) { * * @return string */ - private function getMainFunction() { - $mainFunction = file_get_contents(__DIR__ . '/Parts/Main.txt'); - return $mainFunction; - } - - /** - * Return the Array of additional optional Parameters - * - * @param array $args The Array of Function Parameters - * @param int $offset The Number of obligatory Parameters - * @return array - */ - private function spliceParameters(array $params, $offset) { - $args = array_splice($params, $offset); - if (!$args) return $args; - $parameters = array(); - foreach ($args as $arg) { - if (is_array($arg)) { - foreach ($arg as $key => $value) { - $parameters[$key] = $value; + protected function getMainFunction() { + $mainFunction = ' +Void FML_Dummy() {} +main() { + declare ' . self::VAR_ScriptStart . ' = Now; + +++' . ScriptLabel::ONINIT . '+++ + declare ' . self::VAR_LoopCounter . ' = 0; + declare ' . self::VAR_LastTick . ' = 0; + while (True) { + yield; + foreach (Event in PendingEvents) { + switch (Event.Type) { + case CMlEvent::Type::EntrySubmit: { + +++' . ScriptLabel::ENTRYSUBMIT . '+++ + } + case CMlEvent::Type::KeyPress: { + +++' . ScriptLabel::KEYPRESS . '+++ + } + case CMlEvent::Type::MouseClick: { + +++' . ScriptLabel::MOUSECLICK . '+++ + } + case CMlEvent::Type::MouseOut: { + +++' . ScriptLabel::MOUSEOUT . '+++ + } + case CMlEvent::Type::MouseOver: { + +++' . ScriptLabel::MOUSEOVER . '+++ } } - else { - $parameters[$arg] = true; - } } - return $parameters; + +++' . ScriptLabel::LOOP . '+++ + ' . self::VAR_LoopCounter . ' += 1; + if (' . self::VAR_LastTick . ' + ' . self::TICKINTERVAL . ' > Now) continue; + +++' . ScriptLabel::TICK . '+++ + ' . self::VAR_LastTick . ' = Now; + } +}'; + return $mainFunction; } } diff --git a/application/core/Libs/FML/Script/ScriptConstant.php b/application/core/Libs/FML/Script/ScriptConstant.php new file mode 100644 index 00000000..31584763 --- /dev/null +++ b/application/core/Libs/FML/Script/ScriptConstant.php @@ -0,0 +1,61 @@ +setName($name); + $this->setValue($value); + } + + /** + * Set the Name + * + * @param string $name Constant Name + * @return \FML\Script\ScriptConstant + */ + public function setName($name) { + $this->name = $name; + return $this; + } + + /** + * Set the Value + * + * @param string $value Constant Value + * @return \FML\Script\ScriptConstant + */ + public function setValue($value) { + $this->value = $value; + return $this; + } + + /** + * Build the Script Constant Text + * + * @return string + */ + public function __toString() { + $scriptText = Builder::getConstant($this->name, $this->value); + return $scriptText; + } +} diff --git a/application/core/Libs/FML/Script/ScriptFunction.php b/application/core/Libs/FML/Script/ScriptFunction.php new file mode 100644 index 00000000..19eeccbc --- /dev/null +++ b/application/core/Libs/FML/Script/ScriptFunction.php @@ -0,0 +1,60 @@ +setName($name); + $this->setText($text); + } + + /** + * Set the Name + * + * @param string $name Function Name + * @return \FML\Script\ScriptFunction + */ + public function setName($name) { + $this->name = (string) $name; + return $this; + } + + /** + * Set the Text + * + * @param string $text Function Text + * @return \FML\Script\ScriptFunction + */ + public function setText($text) { + $this->text = (string) $text; + return $this; + } + + /** + * Get the Script Function Text + * + * @return string + */ + public function __toString() { + return $this->text; + } +} diff --git a/application/core/Libs/FML/Script/ScriptInclude.php b/application/core/Libs/FML/Script/ScriptInclude.php new file mode 100644 index 00000000..b8eadef1 --- /dev/null +++ b/application/core/Libs/FML/Script/ScriptInclude.php @@ -0,0 +1,84 @@ +setFile($file); + if ($namespace) { + $this->setNamespace($namespace); + } + else { + $fileParts = explode('.', $file); + if (count($fileParts) === 1) { + $this->setNamespace($file); + } + } + } + + /** + * Set the File + * + * @param string $file Include File + * @return \FML\Script\ScriptInclude + */ + public function setFile($file) { + $this->file = $file; + return $this; + } + + /** + * Set the Namespace + * + * @param string $namespace Include Namespace + * @return \FML\Script\ScriptInclude + */ + public function setNamespace($namespace) { + $this->namespace = $namespace; + return $this; + } + + /** + * Get the Namespace + * + * @return string + */ + public function getNamespace() { + return $this->namespace; + } + + /** + * Build the Script Include Text + * + * @return string + */ + public function __toString() { + $scriptText = Builder::getInclude($this->file, $this->namespace); + return $scriptText; + } +} diff --git a/application/core/Libs/FML/Script/ScriptLabel.php b/application/core/Libs/FML/Script/ScriptLabel.php new file mode 100644 index 00000000..9b121628 --- /dev/null +++ b/application/core/Libs/FML/Script/ScriptLabel.php @@ -0,0 +1,87 @@ +setName($name); + $this->setText($text); + $this->setIsolated($isolated); + } + + /** + * Set the Name + * + * @param string $name Label Name + * @return \FML\Script\ScriptLabel + */ + public function setName($name) { + $this->name = (string) $name; + return $this; + } + + /** + * Set the Text + * + * @param string $text Script Text + * @return \FML\Script\ScriptLabel + */ + public function setText($text) { + $this->text = (string) $text; + return $this; + } + + /** + * Set Isolation + * + * @param bool $isolated Whether the Code should be isolated in an own Block + * @return \FML\Script\ScriptLabel + */ + public function setIsolated($isolated) { + $this->isolated = (bool) $isolated; + return $this; + } + + /** + * Build the full Script Label Text + * + * @return string + */ + public function __toString() { + $scriptText = Builder::getLabelImplementationBlock($this->name, $this->text, $this->isolated); + return $scriptText; + } +} diff --git a/application/core/Libs/FML/Stylesheet/Mood.php b/application/core/Libs/FML/Stylesheet/Mood.php index 3b70e6c9..742e509e 100644 --- a/application/core/Libs/FML/Stylesheet/Mood.php +++ b/application/core/Libs/FML/Stylesheet/Mood.php @@ -35,7 +35,7 @@ class Mood { /** * Create a new Mood Object * - * @return \FML\Elements\Mood + * @return \FML\Stylesheet\Mood */ public static function create() { $mood = new Mood(); @@ -168,7 +168,7 @@ class Mood { * @return \FML\Stylesheet\Mood */ public function setLightBallIntensity($intensity) { - $this->lBall_Intens = (float) $intensity; + $this->lBall_Intensity = (float) $intensity; return $this; } @@ -218,7 +218,7 @@ class Mood { /** * Set Sky Gradient Scale * - * @param float $vScale Gradient Scale Scale + * @param float $scale Gradient Scale * @return \FML\Stylesheet\Mood */ public function setSkyGradientScale($scale) { @@ -283,8 +283,8 @@ class Mood { if ($this->lBall_LinearRgb) { $moodXml->setAttribute('LBall_LinearRgb', $this->lBall_LinearRgb); } - if ($this->lBall_Intens) { - $moodXml->setAttribute('LBall_Intens', $this->lBall_Intens); + if ($this->lBall_Intensity) { + $moodXml->setAttribute('LBall_Intens', $this->lBall_Intensity); } if ($this->lBall_Radius) { $moodXml->setAttribute('LBall_Radius', $this->lBall_Radius); diff --git a/application/core/Libs/FML/Stylesheet/Style3d.php b/application/core/Libs/FML/Stylesheet/Style3d.php index 2895eab2..4f45cfa6 100644 --- a/application/core/Libs/FML/Stylesheet/Style3d.php +++ b/application/core/Libs/FML/Stylesheet/Style3d.php @@ -23,27 +23,26 @@ class Style3d { * Protected Properties */ protected $tagName = 'style3d'; - protected $id = ''; + protected $id = null; protected $model = self::MODEL_Box; - // TODO: check what happens for negative thickness values + adapt rendering protected $thickness = null; - protected $color = ''; - protected $focusColor = ''; - protected $lightColor = ''; - protected $focusLightColor = ''; - // TODO: check offset value ranges + apapt rendering - protected $yOffset = 0.; - protected $focusYOffset = 0.; - protected $zOffset = 0.; - protected $focusZOffset = 0.; + protected $color = null; + protected $focusColor = null; + protected $lightColor = null; + protected $focusLightColor = null; + protected $yOffset = null; + protected $focusYOffset = null; + protected $zOffset = null; + protected $focusZOffset = null; /** * Create a new Style3d Object * - * @return \FML\Elements\Style3d + * @param string $id (optional) Style Id + * @return \FML\Stylesheet\Style3d */ - public static function create() { - $style3d = new Style3d(); + public static function create($id = null) { + $style3d = new Style3d($id); return $style3d; } @@ -159,7 +158,7 @@ class Style3d { /** * Set Y-Offset * - * @param flaot $yOffset Y-Offset + * @param float $yOffset Y-Offset * @return \FML\Stylesheet\Style3d */ public function setYOffset($yOffset) { diff --git a/application/core/Libs/FML/Stylesheet/Stylesheet.php b/application/core/Libs/FML/Stylesheet/Stylesheet.php index 31bf8f39..59c63dc1 100644 --- a/application/core/Libs/FML/Stylesheet/Stylesheet.php +++ b/application/core/Libs/FML/Stylesheet/Stylesheet.php @@ -20,7 +20,7 @@ class Stylesheet { /** * Create a new Stylesheet Object * - * @return \FML\Elements\Stylesheet + * @return \FML\Stylesheet\Stylesheet */ public static function create() { $stylesheet = new Stylesheet(); @@ -37,7 +37,7 @@ class Stylesheet { * Add a new Style3d * * @param Style3d $style3d The Style3d to add - * @return \FML\Stylesheet\Frame3dStyles + * @return \FML\Stylesheet\Stylesheet */ public function addStyle3d(Style3d $style3d) { if (!in_array($style3d, $this->styles3d, true)) { @@ -49,7 +49,7 @@ class Stylesheet { /** * Remove all Styles * - * @return \FML\Stylesheet\Frame3dStyles + * @return \FML\Stylesheet\Stylesheet */ public function removeStyles() { $this->styles3d = array(); diff --git a/application/core/Libs/FML/Types/ScriptFeatureable.php b/application/core/Libs/FML/Types/ScriptFeatureable.php new file mode 100644 index 00000000..4f3819a3 --- /dev/null +++ b/application/core/Libs/FML/Types/ScriptFeatureable.php @@ -0,0 +1,20 @@ +