FML Improvements

This commit is contained in:
Steffen Schröder 2014-05-16 22:44:22 +02:00
parent 1c4d024f4b
commit 192cb2cb79
18 changed files with 430 additions and 332 deletions

View File

@ -7,6 +7,7 @@ use FML\Controls\Frame;
use FML\Controls\Quad; use FML\Controls\Quad;
use FML\Models\CheckBoxDesign; use FML\Models\CheckBoxDesign;
use FML\Script\Features\CheckBoxFeature; use FML\Script\Features\CheckBoxFeature;
use FML\Script\Features\ScriptFeature;
use FML\Types\Renderable; use FML\Types\Renderable;
use FML\Types\ScriptFeatureable; use FML\Types\ScriptFeatureable;
@ -99,22 +100,6 @@ class CheckBox implements Renderable, ScriptFeatureable {
return $this; return $this;
} }
/**
* Get the CheckBox Quad
*
* @param bool $createIfEmpty (optional) Create the Quad if it's not set
* @return \FML\Controls\Quad
*/
public function getQuad($createIfEmpty = true) {
if (!$this->feature->getQuad() && $createIfEmpty) {
$quad = new Quad();
$quad->setSize(10, 10);
$quad->setScriptEvents(true);
$this->feature->setQuad($quad);
}
return $this->feature->getQuad();
}
/** /**
* Set the CheckBox Quad * Set the CheckBox Quad
* *
@ -130,7 +115,24 @@ class CheckBox implements Renderable, ScriptFeatureable {
* @see \FML\Types\ScriptFeatureable::getScriptFeatures() * @see \FML\Types\ScriptFeatureable::getScriptFeatures()
*/ */
public function getScriptFeatures() { public function getScriptFeatures() {
return array($this->feature); return ScriptFeature::collect($this->feature, $this->getQuad(), $this->feature->getEntry());
}
/**
* Get the CheckBox Quad
*
* @param bool $createIfEmpty (optional) Create the Quad if it's not set
* @return \FML\Controls\Quad
*/
public function getQuad($createIfEmpty = true) {
if (!$this->feature->getQuad() && $createIfEmpty) {
$quad = new Quad();
$quad->setSize(10, 10);
$quad->setScriptEvents(true);
$this->feature->setQuad($quad);
}
return $this->feature->getQuad();
} }
/** /**

View File

@ -9,9 +9,9 @@ use FML\Types\Scriptable;
* Audio Control * Audio Control
* (CMlMediaPlayer) * (CMlMediaPlayer)
* *
* @author steeffeen * @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder * @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class Audio extends Control implements Playable, Scriptable { class Audio extends Control implements Playable, Scriptable {
/* /*
@ -25,6 +25,16 @@ class Audio extends Control implements Playable, Scriptable {
protected $volume = 1.; protected $volume = 1.;
protected $scriptEvents = 0; protected $scriptEvents = 0;
/**
* Construct a new Audio Control
*
* @param string $id (optional) Control Id
*/
public function __construct($id = null) {
parent::__construct($id);
$this->tagName = 'audio';
}
/** /**
* Create a new Audio Control * Create a new Audio Control
* *
@ -37,35 +47,29 @@ class Audio extends Control implements Playable, Scriptable {
} }
/** /**
* Construct a new Audio Control * @see \FML\Controls\Control::getManiaScriptClass()
*
* @param string $id (optional) Control Id
*/ */
public function __construct($id = null) { public function getManiaScriptClass() {
parent::__construct($id); return 'CMlMediaPlayer';
$this->tagName = 'audio';
} }
/** /**
*
* @see \FML\Types\Playable::setData() * @see \FML\Types\Playable::setData()
*/ */
public function setData($data) { public function setData($data) {
$this->data = (string) $data; $this->data = (string)$data;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\Playable::setDataId() * @see \FML\Types\Playable::setDataId()
*/ */
public function setDataId($dataId) { public function setDataId($dataId) {
$this->dataId = (string) $dataId; $this->dataId = (string)$dataId;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\Playable::setPlay() * @see \FML\Types\Playable::setPlay()
*/ */
public function setPlay($play) { public function setPlay($play) {
@ -74,7 +78,6 @@ class Audio extends Control implements Playable, Scriptable {
} }
/** /**
*
* @see \FML\Types\Playable::setLooping() * @see \FML\Types\Playable::setLooping()
*/ */
public function setLooping($looping) { public function setLooping($looping) {
@ -83,7 +86,6 @@ class Audio extends Control implements Playable, Scriptable {
} }
/** /**
*
* @see \FML\Types\Playable::setMusic() * @see \FML\Types\Playable::setMusic()
*/ */
public function setMusic($music) { public function setMusic($music) {
@ -92,16 +94,14 @@ class Audio extends Control implements Playable, Scriptable {
} }
/** /**
*
* @see \FML\Types\Playable::setVolume() * @see \FML\Types\Playable::setVolume()
*/ */
public function setVolume($volume) { public function setVolume($volume) {
$this->volume = (float) $volume; $this->volume = (float)$volume;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\Scriptable::setScriptEvents() * @see \FML\Types\Scriptable::setScriptEvents()
*/ */
public function setScriptEvents($scriptEvents) { public function setScriptEvents($scriptEvents) {
@ -110,7 +110,6 @@ class Audio extends Control implements Playable, Scriptable {
} }
/** /**
*
* @see \FML\Control::render() * @see \FML\Control::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -67,30 +67,6 @@ abstract class Control implements Renderable, ScriptFeatureable {
} }
} }
/**
* Get Control Id
*
* @param bool $escaped (optional) Whether the Id should be escaped for ManiaScript
* @return string
*/
public function getId($escaped = false) {
if ($escaped) {
return Builder::escapeText($this->id);
}
return $this->id;
}
/**
* Set Control Id
*
* @param string $id Control Id
* @return \FML\Controls\Control
*/
public function setId($id) {
$this->id = (string)$id;
return $this;
}
/** /**
* Check Id for dangerous Characters and assign a unique Id if necessary * Check Id for dangerous Characters and assign a unique Id if necessary
* *
@ -121,6 +97,47 @@ abstract class Control implements Renderable, ScriptFeatureable {
return $this; return $this;
} }
/**
* Get Control Id
*
* @param bool $escaped (optional) Whether the Id should be escaped for ManiaScript
* @return string
*/
public function getId($escaped = false) {
if ($escaped) {
return Builder::escapeText($this->id);
}
return $this->id;
}
/**
* Set Control Id
*
* @param string $id Control Id
* @return \FML\Controls\Control
*/
public function setId($id) {
$this->id = (string)$id;
return $this;
}
/**
* Set Control Position
*
* @param float $x Horizontal Position
* @param float $y Vertical Position
* @param float $z (optional) Depth
* @return \FML\Controls\Control
*/
public function setPosition($x, $y, $z = null) {
$this->setX($x);
$this->setY($y);
if ($z !== null) {
$this->setZ($z);
}
return $this;
}
/** /**
* Set X Position * Set X Position
* *
@ -155,19 +172,15 @@ abstract class Control implements Renderable, ScriptFeatureable {
} }
/** /**
* Set Control Position * Set Control Size
* *
* @param float $x Horizontal Position * @param float $width Control Width
* @param float $y Vertical Position * @param float $height Control Height
* @param float $z (optional) Depth
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setPosition($x, $y, $z = null) { public function setSize($width, $height) {
$this->setX($x); $this->setWidth($width);
$this->setY($y); $this->setHeight($height);
if ($z !== null) {
$this->setZ($z);
}
return $this; return $this;
} }
@ -194,15 +207,25 @@ abstract class Control implements Renderable, ScriptFeatureable {
} }
/** /**
* Set Control Size * Center Alignment
* *
* @param float $width Control Width
* @param float $height Control Height
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function setSize($width, $height) { public function centerAlign() {
$this->setWidth($width); $this->setAlign(self::CENTER, self::CENTER2);
$this->setHeight($height); return $this;
}
/**
* Set Horizontal and Vertical Alignment
*
* @param string $hAlign Horizontal Alignment
* @param string $vAlign Vertical Alignment
* @return \FML\Controls\Control
*/
public function setAlign($hAlign, $vAlign) {
$this->setHAlign($hAlign);
$this->setVAlign($vAlign);
return $this; return $this;
} }
@ -228,29 +251,6 @@ abstract class Control implements Renderable, ScriptFeatureable {
return $this; return $this;
} }
/**
* Set Horizontal and Vertical Alignment
*
* @param string $hAlign Horizontal Alignment
* @param string $vAlign Vertical Alignment
* @return \FML\Controls\Control
*/
public function setAlign($hAlign, $vAlign) {
$this->setHAlign($hAlign);
$this->setVAlign($vAlign);
return $this;
}
/**
* Center Alignment
*
* @return \FML\Controls\Control
*/
public function centerAlign() {
$this->setAlign(self::CENTER, self::CENTER2);
return $this;
}
/** /**
* Reset Alignment * Reset Alignment
* *
@ -310,6 +310,17 @@ abstract class Control implements Renderable, ScriptFeatureable {
return $this; return $this;
} }
/**
* Add a Script Feature
*
* @param ScriptFeature $scriptFeature Script Feature
* @return \FML\Controls\Control
*/
public function addScriptFeature(ScriptFeature $scriptFeature) {
array_push($this->scriptFeatures, $scriptFeature);
return $this;
}
/** /**
* Add a dynamic Feature opening the current Map Info * Add a dynamic Feature opening the current Map Info
* *
@ -398,26 +409,14 @@ abstract class Control implements Renderable, ScriptFeatureable {
* *
* @param string $scriptText Script Text * @param string $scriptText Script Text
* @param string $label (optional) Script Label Name * @param string $label (optional) Script Label Name
* @param bool $isolated (optional) Whether to isolate the Script Text
* @return \FML\Controls\Control * @return \FML\Controls\Control
*/ */
public function addScriptText($scriptText, $label = ScriptLabel::MOUSECLICK, $isolated = true) { public function addScriptText($scriptText, $label = ScriptLabel::MOUSECLICK) {
$customText = new ControlScript($this, $scriptText, $label, $isolated); $customText = new ControlScript($this, $scriptText, $label);
$this->addScriptFeature($customText); $this->addScriptFeature($customText);
return $this; return $this;
} }
/**
* Add a Script Feature
*
* @param ScriptFeature $scriptFeature Script Feature
* @return \FML\Controls\Control
*/
public function addScriptFeature(ScriptFeature $scriptFeature) {
array_push($this->scriptFeatures, $scriptFeature);
return $this;
}
/** /**
* Remove all Script Features * Remove all Script Features
* *
@ -467,4 +466,11 @@ abstract class Control implements Renderable, ScriptFeatureable {
} }
return $xmlElement; return $xmlElement;
} }
/**
* Get the ManiaScript Class of the Control
*
* @return string
*/
public abstract function getManiaScriptClass();
} }

View File

@ -32,6 +32,16 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF
protected $focusAreaColor2 = ''; protected $focusAreaColor2 = '';
protected $autoComplete = null; protected $autoComplete = null;
/**
* Construct a new Entry Control
*
* @param string $id (optional) Control Id
*/
public function __construct($id = null) {
parent::__construct($id);
$this->tagName = 'entry';
}
/** /**
* Create a new Entry Control * Create a new Entry Control
* *
@ -44,13 +54,19 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF
} }
/** /**
* Construct a new Entry Control * @see \FML\Controls\Control::getManiaScriptClass()
*
* @param string $id (optional) Control Id
*/ */
public function __construct($id = null) { public function getManiaScriptClass() {
parent::__construct($id); return 'CMlEntry';
$this->tagName = 'entry'; }
/**
* Get the Entry Name
*
* @return string
*/
public function getName() {
return $this->name;
} }
/** /**
@ -65,12 +81,12 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF
} }
/** /**
* Get the Entry Name * Get the Default Value
* *
* @return string * @return mixed
*/ */
public function getName() { public function getDefault() {
return $this->name; return $this->default;
} }
/** /**
@ -84,15 +100,6 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF
return $this; return $this;
} }
/**
* Get the Default Value
*
* @return mixed
*/
public function getDefault() {
return $this->default;
}
/** /**
* @see \FML\Types\NewLineable::setAutoNewLine() * @see \FML\Types\NewLineable::setAutoNewLine()
*/ */

View File

@ -6,9 +6,9 @@ namespace FML\Controls;
* FileEntry Control * FileEntry Control
* (CMlFileEntry) * (CMlFileEntry)
* *
* @author steeffeen * @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder * @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class FileEntry extends Entry { class FileEntry extends Entry {
/* /*
@ -16,6 +16,16 @@ class FileEntry extends Entry {
*/ */
protected $folder = ''; protected $folder = '';
/**
* Construct a new FileEntry Control
*
* @param string $id (optional) Control Id
*/
public function __construct($id = null) {
parent::__construct($id);
$this->tagName = 'fileentry';
}
/** /**
* Create a new FileEntry Control * Create a new FileEntry Control
* *
@ -28,13 +38,10 @@ class FileEntry extends Entry {
} }
/** /**
* Construct a new FileEntry Control * @see \FML\Controls\Control::getManiaScriptClass()
*
* @param string $id (optional) Control Id
*/ */
public function __construct($id = null) { public function getManiaScriptClass() {
parent::__construct($id); return 'CMlFileEntry';
$this->tagName = 'fileentry';
} }
/** /**
@ -44,12 +51,11 @@ class FileEntry extends Entry {
* @return \FML\Controls\FileEntry * @return \FML\Controls\FileEntry
*/ */
public function setFolder($folder) { public function setFolder($folder) {
$this->folder = (string) $folder; $this->folder = (string)$folder;
return $this; return $this;
} }
/** /**
*
* @see \FML\Entry::render() * @see \FML\Entry::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -23,6 +23,16 @@ class Frame extends Control implements Container {
/** @var Format $format */ /** @var Format $format */
protected $format = null; protected $format = null;
/**
* Construct a new Frame Control
*
* @param string $id (optional) Control Id
*/
public function __construct($id = null) {
parent::__construct($id);
$this->tagName = 'frame';
}
/** /**
* Create a new Frame Control * Create a new Frame Control
* *
@ -35,13 +45,10 @@ class Frame extends Control implements Container {
} }
/** /**
* Construct a new Frame Control * @see \FML\Controls\Control::getManiaScriptClass()
*
* @param string $id (optional) Control Id
*/ */
public function __construct($id = null) { public function getManiaScriptClass() {
parent::__construct($id); return 'CMlFrame';
$this->tagName = 'frame';
} }
/** /**
@ -62,14 +69,6 @@ class Frame extends Control implements Container {
return $this; return $this;
} }
/**
* @see \FML\Types\Container::setFormat()
*/
public function setFormat(Format $format) {
$this->format = $format;
return $this;
}
/** /**
* @see \FML\Types\Container::getFormat() * @see \FML\Types\Container::getFormat()
*/ */
@ -80,6 +79,14 @@ class Frame extends Control implements Container {
return $this->format; return $this->format;
} }
/**
* @see \FML\Types\Container::setFormat()
*/
public function setFormat(Format $format) {
$this->format = $format;
return $this;
}
/** /**
* @see \FML\Controls\Control::getScriptFeatures() * @see \FML\Controls\Control::getScriptFeatures()
*/ */

View File

@ -20,18 +20,6 @@ class FrameInstance extends Control {
/** @var FrameModel $model */ /** @var FrameModel $model */
protected $model = null; protected $model = null;
/**
* Create a new Frame Instance
*
* @param string $modelId (optional) Frame Model Id
* @param string $controlId (optional) Control Id
* @return \FML\Controls\Frame
*/
public static function create($modelId = null, $controlId = null) {
$frameInstance = new FrameInstance($modelId, $controlId);
return $frameInstance;
}
/** /**
* Construct a new Frame Instance * Construct a new Frame Instance
* *
@ -58,6 +46,25 @@ class FrameInstance extends Control {
return $this; return $this;
} }
/**
* Create a new Frame Instance
*
* @param string $modelId (optional) Frame Model Id
* @param string $controlId (optional) Control Id
* @return \FML\Controls\Frame
*/
public static function create($modelId = null, $controlId = null) {
$frameInstance = new FrameInstance($modelId, $controlId);
return $frameInstance;
}
/**
* @see \FML\Controls\Control::getManiaScriptClass()
*/
public function getManiaScriptClass() {
return 'CMlFrame';
}
/** /**
* Set Frame Model to use * Set Frame Model to use
* *

View File

@ -8,19 +8,19 @@ use FML\Types\Styleable;
* Gauge Control * Gauge Control
* (CMlGauge) * (CMlGauge)
* *
* @author steeffeen * @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder * @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class Gauge extends Control implements Styleable { class Gauge extends Control implements Styleable {
/* /*
* Constants * Constants
*/ */
const STYLE_BgCard = 'BgCard'; const STYLE_BgCard = 'BgCard';
const STYLE_EnergyBar = 'EnergyBar'; const STYLE_EnergyBar = 'EnergyBar';
const STYLE_ProgressBar = 'ProgressBar'; const STYLE_ProgressBar = 'ProgressBar';
const STYLE_ProgressBarSmall = 'ProgressBarSmall'; const STYLE_ProgressBarSmall = 'ProgressBarSmall';
/* /*
* Protected Properties * Protected Properties
*/ */
@ -34,6 +34,16 @@ class Gauge extends Control implements Styleable {
protected $drawBlockBg = 1; protected $drawBlockBg = 1;
protected $style = ''; protected $style = '';
/**
* Construct a new Gauge Control
*
* @param string $id (optional) Control Id
*/
public function __construct($id = null) {
parent::__construct($id);
$this->tagName = 'gauge';
}
/** /**
* Create a new Gauge Control * Create a new Gauge Control
* *
@ -46,13 +56,10 @@ class Gauge extends Control implements Styleable {
} }
/** /**
* Construct a new Gauge Control * @see \FML\Controls\Control::getManiaScriptClass()
*
* @param string $id (optional) Control Id
*/ */
public function __construct($id = null) { public function getManiaScriptClass() {
parent::__construct($id); return 'CMlGauge';
$this->tagName = 'gauge';
} }
/** /**
@ -62,7 +69,7 @@ class Gauge extends Control implements Styleable {
* @return \FML\Controls\Gauge * @return \FML\Controls\Gauge
*/ */
public function setRatio($ratio) { public function setRatio($ratio) {
$this->ratio = (float) $ratio; $this->ratio = (float)$ratio;
return $this; return $this;
} }
@ -73,7 +80,7 @@ class Gauge extends Control implements Styleable {
* @return \FML\Controls\Gauge * @return \FML\Controls\Gauge
*/ */
public function setGrading($grading) { public function setGrading($grading) {
$this->grading = (float) $grading; $this->grading = (float)$grading;
return $this; return $this;
} }
@ -84,7 +91,7 @@ class Gauge extends Control implements Styleable {
* @return \FML\Controls\Gauge * @return \FML\Controls\Gauge
*/ */
public function setColor($color) { public function setColor($color) {
$this->color = (string) $color; $this->color = (string)$color;
return $this; return $this;
} }
@ -95,7 +102,7 @@ class Gauge extends Control implements Styleable {
* @return \FML\Controls\Gauge * @return \FML\Controls\Gauge
*/ */
public function setRotation($rotation) { public function setRotation($rotation) {
$this->rotation = (float) $rotation; $this->rotation = (float)$rotation;
return $this; return $this;
} }
@ -117,7 +124,7 @@ class Gauge extends Control implements Styleable {
* @return \FML\Controls\Gauge * @return \FML\Controls\Gauge
*/ */
public function setClan($clan) { public function setClan($clan) {
$this->clan = (int) $clan; $this->clan = (int)$clan;
return $this; return $this;
} }
@ -144,16 +151,14 @@ class Gauge extends Control implements Styleable {
} }
/** /**
*
* @see \FML\Types\Styleable::setStyle() * @see \FML\Types\Styleable::setStyle()
*/ */
public function setStyle($style) { public function setStyle($style) {
$this->style = (string) $style; $this->style = (string)$style;
return $this; return $this;
} }
/** /**
*
* @see \FML\Control::render() * @see \FML\Control::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -2,21 +2,21 @@
namespace FML\Controls; namespace FML\Controls;
use FML\Script\Features\Clock;
use FML\Types\Actionable; use FML\Types\Actionable;
use FML\Types\Linkable; use FML\Types\Linkable;
use FML\Types\NewLineable; use FML\Types\NewLineable;
use FML\Types\Scriptable; use FML\Types\Scriptable;
use FML\Types\Styleable; use FML\Types\Styleable;
use FML\Types\TextFormatable; use FML\Types\TextFormatable;
use FML\Script\Features\Clock;
/** /**
* Label Control * Label Control
* (CMlLabel) * (CMlLabel)
* *
* @author steeffeen * @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder * @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class Label extends Control implements Actionable, Linkable, NewLineable, Scriptable, Styleable, TextFormatable { class Label extends Control implements Actionable, Linkable, NewLineable, Scriptable, Styleable, TextFormatable {
/* /*
@ -42,17 +42,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script
protected $focusAreaColor1 = ''; protected $focusAreaColor1 = '';
protected $focusAreaColor2 = ''; protected $focusAreaColor2 = '';
/**
* Create a new Label Control
*
* @param string $id (optional) Control Id
* @return \FML\Controls\Label
*/
public static function create($id = null) {
$label = new Label($id);
return $label;
}
/** /**
* Construct a new Label Control * Construct a new Label Control
* *
@ -64,6 +53,24 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script
$this->setZ(1); $this->setZ(1);
} }
/**
* Create a new Label Control
*
* @param string $id (optional) Control Id
* @return \FML\Controls\Label
*/
public static function create($id = null) {
$label = new Label($id);
return $label;
}
/**
* @see \FML\Controls\Control::getManiaScriptClass()
*/
public function getManiaScriptClass() {
return 'CMlLabel';
}
/** /**
* Set Text * Set Text
* *
@ -71,7 +78,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script
* @return \FML\Controls\Label * @return \FML\Controls\Label
*/ */
public function setText($text) { public function setText($text) {
$this->text = (string) $text; $this->text = (string)$text;
return $this; return $this;
} }
@ -82,7 +89,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script
* @return \FML\Controls\Label * @return \FML\Controls\Label
*/ */
public function setTextId($textId) { public function setTextId($textId) {
$this->textId = (string) $textId; $this->textId = (string)$textId;
return $this; return $this;
} }
@ -93,7 +100,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script
* @return \FML\Controls\Label * @return \FML\Controls\Label
*/ */
public function setTextPrefix($textPrefix) { public function setTextPrefix($textPrefix) {
$this->textPrefix = (string) $textPrefix; $this->textPrefix = (string)$textPrefix;
return $this; return $this;
} }
@ -126,21 +133,11 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script
* @return \FML\Controls\Label * @return \FML\Controls\Label
*/ */
public function setMaxLines($maxLines) { public function setMaxLines($maxLines) {
$this->maxLines = (int) $maxLines; $this->maxLines = (int)$maxLines;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\Actionable::setAction()
*/
public function setAction($action) {
$this->action = (string) $action;
return $this;
}
/**
*
* @see \FML\Types\Actionable::getAction() * @see \FML\Types\Actionable::getAction()
*/ */
public function getAction() { public function getAction() {
@ -148,52 +145,54 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script
} }
/** /**
* * @see \FML\Types\Actionable::setAction()
*/
public function setAction($action) {
$this->action = (string)$action;
return $this;
}
/**
* @see \FML\Types\Actionable::setActionKey() * @see \FML\Types\Actionable::setActionKey()
*/ */
public function setActionKey($actionKey) { public function setActionKey($actionKey) {
$this->actionKey = (int) $actionKey; $this->actionKey = (int)$actionKey;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\Linkable::setUrl() * @see \FML\Types\Linkable::setUrl()
*/ */
public function setUrl($url) { public function setUrl($url) {
$this->url = (string) $url; $this->url = (string)$url;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\Linkable::setUrlId() * @see \FML\Types\Linkable::setUrlId()
*/ */
public function setUrlId($urlId) { public function setUrlId($urlId) {
$this->urlId = (string) $urlId; $this->urlId = (string)$urlId;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\Linkable::setManialink() * @see \FML\Types\Linkable::setManialink()
*/ */
public function setManialink($manialink) { public function setManialink($manialink) {
$this->manialink = (string) $manialink; $this->manialink = (string)$manialink;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\Linkable::setManialinkId() * @see \FML\Types\Linkable::setManialinkId()
*/ */
public function setManialinkId($manialinkId) { public function setManialinkId($manialinkId) {
$this->manialinkId = (string) $manialinkId; $this->manialinkId = (string)$manialinkId;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\NewLineable::setAutoNewLine() * @see \FML\Types\NewLineable::setAutoNewLine()
*/ */
public function setAutoNewLine($autoNewLine) { public function setAutoNewLine($autoNewLine) {
@ -202,7 +201,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script
} }
/** /**
*
* @see \FML\Types\Scriptable::setScriptEvents() * @see \FML\Types\Scriptable::setScriptEvents()
*/ */
public function setScriptEvents($scriptEvents) { public function setScriptEvents($scriptEvents) {
@ -211,54 +209,49 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script
} }
/** /**
*
* @see \FML\Types\Styleable::setStyle() * @see \FML\Types\Styleable::setStyle()
*/ */
public function setStyle($style) { public function setStyle($style) {
$this->style = (string) $style; $this->style = (string)$style;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\TextFormatable::setTextSize() * @see \FML\Types\TextFormatable::setTextSize()
*/ */
public function setTextSize($textSize) { public function setTextSize($textSize) {
$this->textSize = (int) $textSize; $this->textSize = (int)$textSize;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\TextFormatable::setTextColor() * @see \FML\Types\TextFormatable::setTextColor()
*/ */
public function setTextColor($textColor) { public function setTextColor($textColor) {
$this->textColor = (string) $textColor; $this->textColor = (string)$textColor;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\TextFormatable::setAreaColor() * @see \FML\Types\TextFormatable::setAreaColor()
*/ */
public function setAreaColor($areaColor) { public function setAreaColor($areaColor) {
$this->focusAreaColor1 = (string) $areaColor; $this->focusAreaColor1 = (string)$areaColor;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\TextFormatable::setAreaFocusColor() * @see \FML\Types\TextFormatable::setAreaFocusColor()
*/ */
public function setAreaFocusColor($areaFocusColor) { public function setAreaFocusColor($areaFocusColor) {
$this->focusAreaColor2 = (string) $areaFocusColor; $this->focusAreaColor2 = (string)$areaFocusColor;
return $this; return $this;
} }
/** /**
* Add a dynamic Feature showing the current Time * Add a dynamic Feature showing the current Time
* *
* @param bool $showSeconds (optional) Whether the Seconds should be shown * @param bool $showSeconds (optional) Whether the Seconds should be shown
* @param bool $showFullDate (optional) Whether the Date should be shown * @param bool $showFullDate (optional) Whether the Date should be shown
* @return \FML\Controls\Label * @return \FML\Controls\Label
*/ */
@ -269,7 +262,6 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script
} }
/** /**
*
* @see \FML\Control::render() * @see \FML\Control::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -40,6 +40,17 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta
protected $style = ''; protected $style = '';
protected $subStyle = ''; protected $subStyle = '';
/**
* Construct a new Quad Control
*
* @param string $id (optional) Control Id
*/
public function __construct($id = null) {
parent::__construct($id);
$this->tagName = 'quad';
$this->setZ(-1);
}
/** /**
* Create a new Quad Control * Create a new Quad Control
* *
@ -52,14 +63,10 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta
} }
/** /**
* Construct a new Quad Control * @see \FML\Controls\Control::getManiaScriptClass()
*
* @param string $id (optional) Control Id
*/ */
public function __construct($id = null) { public function getManiaScriptClass() {
parent::__construct($id); return 'CMlQuad';
$this->tagName = 'quad';
$this->setZ(-1);
} }
/** /**
@ -139,6 +146,13 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta
return $this; return $this;
} }
/**
* @see \FML\Types\Actionable::getAction()
*/
public function getAction() {
return $this->action;
}
/** /**
* @see \FML\Types\Actionable::setAction() * @see \FML\Types\Actionable::setAction()
*/ */
@ -147,13 +161,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta
return $this; return $this;
} }
/**
* @see \FML\Types\Actionable::getAction()
*/
public function getAction() {
return $this->action;
}
/** /**
* @see \FML\Types\Actionable::setActionKey() * @see \FML\Types\Actionable::setActionKey()
*/ */
@ -210,6 +217,15 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta
return $this; return $this;
} }
/**
* @see \FML\Types\SubStyleable::setStyles()
*/
public function setStyles($style, $subStyle) {
$this->setStyle($style);
$this->setSubStyle($subStyle);
return $this;
}
/** /**
* @see \FML\Types\Styleable::setStyle() * @see \FML\Types\Styleable::setStyle()
*/ */
@ -226,15 +242,6 @@ class Quad extends Control implements Actionable, BgColorable, Linkable, Scripta
return $this; return $this;
} }
/**
* @see \FML\Types\SubStyleable::setStyles()
*/
public function setStyles($style, $subStyle) {
$this->setStyle($style);
$this->setSubStyle($subStyle);
return $this;
}
/** /**
* Apply the given CheckBox Design * Apply the given CheckBox Design
* *

View File

@ -9,9 +9,9 @@ use FML\Types\Scriptable;
* Video Control * Video Control
* (CMlMediaPlayer) * (CMlMediaPlayer)
* *
* @author steeffeen * @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder * @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class Video extends Control implements Playable, Scriptable { class Video extends Control implements Playable, Scriptable {
/* /*
@ -25,6 +25,16 @@ class Video extends Control implements Playable, Scriptable {
protected $volume = 1.; protected $volume = 1.;
protected $scriptEvents = 0; protected $scriptEvents = 0;
/**
* Construct a new Video Control
*
* @param string $id (optional) Control Id
*/
public function __construct($id = null) {
parent::__construct($id);
$this->tagName = 'video';
}
/** /**
* Create a new Video Control * Create a new Video Control
* *
@ -37,35 +47,29 @@ class Video extends Control implements Playable, Scriptable {
} }
/** /**
* Construct a new Video Control * @see \FML\Controls\Control::getManiaScriptClass()
*
* @param string $id (optional) Control Id
*/ */
public function __construct($id = null) { public function getManiaScriptClass() {
parent::__construct($id); return 'CMlMediaPlayer';
$this->tagName = 'video';
} }
/** /**
*
* @see \FML\Types\Playable::setData() * @see \FML\Types\Playable::setData()
*/ */
public function setData($data) { public function setData($data) {
$this->data = (string) $data; $this->data = (string)$data;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\Playable::setDataId() * @see \FML\Types\Playable::setDataId()
*/ */
public function setDataId($dataId) { public function setDataId($dataId) {
$this->dataId = (string) $dataId; $this->dataId = (string)$dataId;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\Playable::setPlay() * @see \FML\Types\Playable::setPlay()
*/ */
public function setPlay($play) { public function setPlay($play) {
@ -74,7 +78,6 @@ class Video extends Control implements Playable, Scriptable {
} }
/** /**
*
* @see \FML\Types\Playable::setLooping() * @see \FML\Types\Playable::setLooping()
*/ */
public function setLooping($looping) { public function setLooping($looping) {
@ -83,7 +86,6 @@ class Video extends Control implements Playable, Scriptable {
} }
/** /**
*
* @see \FML\Types\Playable::setMusic() * @see \FML\Types\Playable::setMusic()
*/ */
public function setMusic($music) { public function setMusic($music) {
@ -92,16 +94,14 @@ class Video extends Control implements Playable, Scriptable {
} }
/** /**
*
* @see \FML\Types\Playable::setVolume() * @see \FML\Types\Playable::setVolume()
*/ */
public function setVolume($volume) { public function setVolume($volume) {
$this->volume = (float) $volume; $this->volume = (float)$volume;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\Scriptable::setScriptEvents() * @see \FML\Types\Scriptable::setScriptEvents()
*/ */
public function setScriptEvents($scriptEvents) { public function setScriptEvents($scriptEvents) {
@ -110,7 +110,6 @@ class Video extends Control implements Playable, Scriptable {
} }
/** /**
*
* @see \FML\Control::render() * @see \FML\Control::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -122,6 +122,9 @@ class CheckBoxDesign implements Styleable, SubStyleable {
} else { } else {
$string = $this->style . '|' . $this->subStyle;; $string = $this->style . '|' . $this->subStyle;;
} }
return Builder::escapeText($string); if ($escaped) {
return Builder::escapeText($string);
}
return $string;
} }
} }

View File

@ -5,18 +5,18 @@ namespace FML\Script;
/** /**
* Builder Class offering Methods to build ManiaScript * Builder Class offering Methods to build ManiaScript
* *
* @author steeffeen * @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder * @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
abstract class Builder { abstract class Builder {
/** /**
* Build a Label Implementation Block * Build a Label Implementation Block
* *
* @param string $labelName Name of the Label * @param string $labelName Name of the Label
* @param string $implementationCode Label Implementation Coding (without declaration) * @param string $implementationCode Label Implementation Coding (without declaration)
* @param bool $isolate Whether the Code should be isolated in an own Block * @param bool $isolate Whether the Code should be isolated in an own Block
* @return string * @return string
*/ */
public static function getLabelImplementationBlock($labelName, $implementationCode, $isolate = true) { public static function getLabelImplementationBlock($labelName, $implementationCode, $isolate = true) {
@ -30,14 +30,14 @@ abstract class Builder {
/** /**
* Escape dangerous Characters in the given Text * Escape dangerous Characters in the given Text
* *
* @param string $text Text to escape * @param string $text Text to escape
* @param bool $addApostrophes (optional) Whether to add Apostrophes before and after the Text * @param bool $addApostrophes (optional) Whether to add Apostrophes before and after the Text
* @return string * @return string
*/ */
public static function escapeText($text, $addApostrophes = false) { public static function escapeText($text, $addApostrophes = false) {
$dangers = array('\\', '"', "\n"); $dangers = array('\\', '"', "\n");
$replacements = array('\\\\', '\\"', '\\n'); $replacements = array('\\\\', '\\"', '\\n');
$escapedText = str_ireplace($dangers, $replacements, $text); $escapedText = str_ireplace($dangers, $replacements, $text);
if ($addApostrophes) { if ($addApostrophes) {
$escapedText = '"' . $escapedText . '"'; $escapedText = '"' . $escapedText . '"';
} }
@ -51,8 +51,8 @@ abstract class Builder {
* @return string * @return string
*/ */
public static function getReal($value) { public static function getReal($value) {
$value = (float) $value; $value = (float)$value;
$stringVal = (string) $value; $stringVal = (string)$value;
if (!fmod($value, 1)) { if (!fmod($value, 1)) {
$stringVal .= '.'; $stringVal .= '.';
} }
@ -66,7 +66,7 @@ abstract class Builder {
* @return string * @return string
*/ */
public static function getBoolean($value) { public static function getBoolean($value) {
$bool = (bool) $value; $bool = (bool)$value;
if ($bool) { if ($bool) {
return "True"; return "True";
} }
@ -76,28 +76,26 @@ abstract class Builder {
/** /**
* Get the String-Representation of the given Array * Get the String-Representation of the given Array
* *
* @param array $array Array to convert to a ManiaScript Array * @param array $array Array to convert to a ManiaScript Array
* @param bool $associative (optional) Whether the Array should be associative * @param bool $associative (optional) Whether the Array should be associative
* @return string * @return string
*/ */
public static function getArray(array $array, $associative = false) { public static function getArray(array $array, $associative = false) {
$arrayText = '['; $arrayText = '[';
$index = 0; $index = 0;
$count = count($array); $count = count($array);
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
if ($associative) { if ($associative) {
if (is_string($key)) { if (is_string($key)) {
$arrayText .= '"' . self::escapeText($key) . '"'; $arrayText .= '"' . self::escapeText($key) . '"';
} } else {
else {
$arrayText .= $key; $arrayText .= $key;
} }
$arrayText .= ' => '; $arrayText .= ' => ';
} }
if (is_string($value)) { if (is_string($value)) {
$arrayText .= '"' . self::escapeText($value) . '"'; $arrayText .= '"' . self::escapeText($value) . '"';
} } else {
else {
$arrayText .= $value; $arrayText .= $value;
} }
if ($index < $count - 1) { if ($index < $count - 1) {
@ -112,7 +110,7 @@ abstract class Builder {
/** /**
* Get the Include Command for the given File and Namespace * Get the Include Command for the given File and Namespace
* *
* @param string $file Include File * @param string $file Include File
* @param string $namespace Include Namespace * @param string $namespace Include Namespace
* @return string * @return string
*/ */
@ -124,7 +122,7 @@ abstract class Builder {
/** /**
* Get the Constant Command for the given Name and Value * Get the Constant Command for the given Name and Value
* *
* @param string $name Constant Name * @param string $name Constant Name
* @param string $value Constant Value * @param string $value Constant Value
* @return string * @return string
*/ */

View File

@ -89,6 +89,15 @@ class CheckBoxFeature extends ScriptFeature {
return $this; return $this;
} }
/**
* Get the managed Entry
*
* @return \FML\Controls\Entry
*/
public function getEntry() {
return $this->entry;
}
/** /**
* Set the Enabled Design * Set the Enabled Design
* *
@ -134,6 +143,7 @@ class CheckBoxFeature extends ScriptFeature {
Void " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(CMlQuad _Quad) { Void " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(CMlQuad _Quad) {
declare " . self::VAR_CHECKBOX_ENABLED . " as Enabled for _Quad = True; declare " . self::VAR_CHECKBOX_ENABLED . " as Enabled for _Quad = True;
Enabled = !Enabled; Enabled = !Enabled;
_Quad.StyleSelected = Enabled;
declare " . self::VAR_CHECKBOX_DESIGNS . " as Designs for _Quad = Text[Boolean]; declare " . self::VAR_CHECKBOX_DESIGNS . " as Designs for _Quad = Text[Boolean];
declare Design = Designs[Enabled]; declare Design = Designs[Enabled];
declare DesignParts = TextLib::Split(\"|\", Design); declare DesignParts = TextLib::Split(\"|\", Design);

View File

@ -22,7 +22,6 @@ class ControlScript extends ScriptFeature {
protected $control = null; protected $control = null;
protected $labelName = null; protected $labelName = null;
protected $text = null; protected $text = null;
protected $isolated = null;
/** /**
* Construct a new Custom Script Text * Construct a new Custom Script Text
@ -30,13 +29,11 @@ class ControlScript extends ScriptFeature {
* @param Control $control Event Control * @param Control $control Event Control
* @param string $text Script Text * @param string $text Script Text
* @param string $labelName (optional) Script Label Name * @param string $labelName (optional) Script Label Name
* @param bool $isolated (optional) Whether to isolate the Script Text
*/ */
public function __construct(Control $control, $text, $labelName = ScriptLabel::MOUSECLICK, $isolated = true) { public function __construct(Control $control, $text, $labelName = ScriptLabel::MOUSECLICK) {
$this->setControl($control); $this->setControl($control);
$this->setText($text); $this->setText($text);
$this->setLabelName($labelName); $this->setLabelName($labelName);
$this->setIsolated($isolated);
} }
/** /**
@ -76,36 +73,47 @@ class ControlScript extends ScriptFeature {
return $this; return $this;
} }
/**
* Set whether the Script should be isolated
*
* @param bool $isolated Whether to isolate the Script Text
* @return \FML\Script\Features\ControlScript
*/
public function setIsolated($isolated = true) {
$this->isolated = (bool)$isolated;
return $this;
}
/** /**
* @see \FML\Script\Features\ScriptFeature::prepare() * @see \FML\Script\Features\ScriptFeature::prepare()
*/ */
public function prepare(Script $script) { public function prepare(Script $script) {
$script->appendGenericScriptLabel($this->labelName, $this->getEncapsulatedText(), $this->isolated); $script->appendGenericScriptLabel($this->labelName, $this->buildScriptText(), true);
return $this; return $this;
} }
/** /**
* Get the Script Text encapsulated for the Control Event * Build the Script Text for the Control
* *
* @return string * @return string
*/ */
protected function getEncapsulatedText() { protected function buildScriptText() {
$controlId = $this->control->getId(true); $controlId = $this->control->getId(true);
$scriptText = " $scriptText = '';
if (Event.ControlId == \"{$controlId}\") { $closeBlock = false;
{$this->text}
}"; if (ScriptLabel::isEventLabel($this->labelName)) {
$scriptText .= '
if (Event.ControlId == "' . $controlId . '") {
declare Control <=> Event.Control;';
$closeBlock = true;
} else {
$scriptText .= '
declare Control <=> Page.GetFirstChild("' . $controlId . '");';
}
$class = $this->control->getManiaScriptClass();
$name = preg_replace('/^CMl/', '', $class, 1);
$scriptText .= '
declare ' . $name . ' <=> (Control as ' . $class . ');
';
$scriptText .= $this->text . '
';
if ($closeBlock) {
$scriptText .= '}';
}
return $scriptText; return $scriptText;
} }
} }

View File

@ -3,16 +3,37 @@
namespace FML\Script\Features; namespace FML\Script\Features;
use FML\Script\Script; use FML\Script\Script;
use FML\Types\ScriptFeatureable;
/** /**
* ManiaLink Script Feature Class * ManiaLink Script Feature Class
* *
* @author steeffeen * @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder * @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
abstract class ScriptFeature { abstract class ScriptFeature {
/**
* Collect the Script Features of the given Objects
*
* @param object $scriptFeatureable ScriptFeatureable Object
* @param object $_ (optional) Various Amount of additional Objects
* @return array
*/
public static function collect($scriptFeatureable, $_ = null) {
$params = func_get_args();
$scriptFeatures = array();
foreach ($params as $object) {
if ($object instanceof ScriptFeatureable) {
$scriptFeatures = array_merge($scriptFeatures, $object->getScriptFeatures());
} else if ($object instanceof ScriptFeature) {
array_push($scriptFeatures, $object);
}
}
return $scriptFeatures;
}
/** /**
* Prepare the given Script for Rendering by adding the needed Labels, etc. * Prepare the given Script for Rendering by adding the needed Labels, etc.
* *

View File

@ -75,6 +75,29 @@ class ScriptLabel {
return $this; return $this;
} }
/**
* Check if the given Label is an Event Label
*
* @param string $label Label Name
* @return bool
*/
public static function isEventLabel($label) {
$eventLabels = self::getEventLabels();
if (in_array($label, $eventLabels)) {
return true;
}
return false;
}
/**
* Get the possible Event Label Names
*
* @return array
*/
public static function getEventLabels() {
return array(self::ENTRYSUBMIT, self::KEYPRESS, self::MOUSECLICK, self::MOUSEOUT, self::MOUSEOVER);
}
/** /**
* Build the full Script Label Text * Build the full Script Label Text
* *

View File

@ -15,9 +15,7 @@ if (!defined('FML_PATH')) {
if (!defined('FML_VERSION')) { if (!defined('FML_VERSION')) {
define('FML_VERSION', '1.2'); define('FML_VERSION', '1.2');
} }
if (!defined('FML_SIMPLE_CLASSES')) { //define('FML_SIMPLE_CLASSES', true);
define('FML_SIMPLE_CLASSES', false);
}
/* /*
* Autoload Function that loads FML Class Files on Demand * Autoload Function that loads FML Class Files on Demand
@ -30,7 +28,7 @@ if (!defined('FML_AUTOLOAD_DEFINED')) {
if (file_exists($filePath)) { if (file_exists($filePath)) {
// Load with FML namespace // Load with FML namespace
require_once $filePath; require_once $filePath;
} else if (FML_SIMPLE_CLASSES) { } else if (defined('FML_SIMPLE_CLASSES') && FML_SIMPLE_CLASSES) {
// Load as simple class name // Load as simple class name
if (!function_exists('loadSimpleClass')) { if (!function_exists('loadSimpleClass')) {