FML Update
This commit is contained in:
@ -14,6 +14,7 @@ use FML\Script\Features\UISound;
|
||||
use FML\Script\ScriptLabel;
|
||||
use FML\Types\Renderable;
|
||||
use FML\Types\ScriptFeatureable;
|
||||
use FML\UniqueID;
|
||||
|
||||
/**
|
||||
* Base Control
|
||||
@ -35,48 +36,55 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
const LEFT = 'left';
|
||||
|
||||
/*
|
||||
* Static Properties
|
||||
*/
|
||||
protected static $currentIndex = 0;
|
||||
|
||||
/*
|
||||
* Protected Properties
|
||||
* Protected properties
|
||||
*/
|
||||
protected $tagName = 'control';
|
||||
protected $id = '';
|
||||
protected $x = 0.;
|
||||
protected $y = 0.;
|
||||
protected $z = 0.;
|
||||
protected $controlId = null;
|
||||
protected $posX = 0.;
|
||||
protected $posY = 0.;
|
||||
protected $posZ = 0.;
|
||||
protected $width = -1.;
|
||||
protected $height = -1.;
|
||||
protected $hAlign = self::CENTER;
|
||||
protected $vAlign = self::CENTER2;
|
||||
protected $scale = 1.;
|
||||
protected $hidden = 0;
|
||||
protected $hidden = null;
|
||||
protected $rotation = 0.;
|
||||
/** @var string[] $classes */
|
||||
protected $classes = array();
|
||||
/** @var ScriptFeature[] $scriptFeatures */
|
||||
protected $scriptFeatures = array();
|
||||
|
||||
/**
|
||||
* Construct a new Control
|
||||
* Create a new Control object
|
||||
*
|
||||
* @param string $id (optional) Control Id
|
||||
* @param string $controlId (optional) Control id
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function __construct($id = null) {
|
||||
if ($id !== null) {
|
||||
$this->setId($id);
|
||||
public static function create($controlId = null) {
|
||||
return new static($controlId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new Control object
|
||||
*
|
||||
* @param string $controlId (optional) Control id
|
||||
*/
|
||||
public function __construct($controlId = null) {
|
||||
if (!is_null($controlId)) {
|
||||
$this->setId($controlId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Id for dangerous Characters and assign a unique Id if necessary
|
||||
* Check Id for dangerous characters and assign a new unique id if necessary
|
||||
*
|
||||
* @param bool $forceNewId Whether to force setting a newly generated Id
|
||||
* @return \FML\Controls\Control
|
||||
* @param bool $forceNewId (optional) Whether to force setting a newly generated id
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function checkId($forceNewId = false) {
|
||||
if ($forceNewId || !$this->getId()) {
|
||||
$this->setId('FML_ID_' . self::$currentIndex);
|
||||
self::$currentIndex++;
|
||||
$this->setId(new UniqueID());
|
||||
return $this;
|
||||
}
|
||||
$dangerousCharacters = array(' ', ' ', '.', '|', '-', PHP_EOL);
|
||||
@ -90,93 +98,94 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
break;
|
||||
}
|
||||
if ($danger) {
|
||||
trigger_error("Please don't use special Characters in Ids, they might cause Problems! (I stripped them for You.)");
|
||||
$id = str_ireplace($dangerousCharacters, '', $this->getId());
|
||||
$this->setId($id);
|
||||
trigger_error("Please don't use special characters in ids, they might cause problems! (I stripped them for you.)");
|
||||
$controlId = str_ireplace($dangerousCharacters, '', $this->getId());
|
||||
$this->setId($controlId);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Control Id
|
||||
* Get the Control id
|
||||
*
|
||||
* @param bool $escaped (optional) Whether the Id should be escaped for ManiaScript
|
||||
* @param bool $escaped (optional) Whether the id should be escaped for ManiaScript
|
||||
* @param bool $addApostrophes (optional) Whether to add apostrophes before and after the text
|
||||
* @return string
|
||||
*/
|
||||
public function getId($escaped = false) {
|
||||
public function getId($escaped = false, $addApostrophes = false) {
|
||||
if ($escaped) {
|
||||
return Builder::escapeText($this->id);
|
||||
return Builder::escapeText($this->controlId, $addApostrophes);
|
||||
}
|
||||
return $this->id;
|
||||
return $this->controlId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Control Id
|
||||
* Set Control id
|
||||
*
|
||||
* @param string $id Control Id
|
||||
* @return \FML\Controls\Control
|
||||
* @param string $controlId Control id
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setId($id) {
|
||||
$this->id = (string)$id;
|
||||
public function setId($controlId) {
|
||||
$this->controlId = (string)$controlId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Control Position
|
||||
* Set Control position
|
||||
*
|
||||
* @param float $x Horizontal Position
|
||||
* @param float $y Vertical Position
|
||||
* @param float $z (optional) Depth
|
||||
* @return \FML\Controls\Control
|
||||
* @param float $posX Horizontal position
|
||||
* @param float $posY Vertical position
|
||||
* @param float $posZ (optional) Depth
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setPosition($x, $y, $z = null) {
|
||||
$this->setX($x);
|
||||
$this->setY($y);
|
||||
if ($z !== null) {
|
||||
$this->setZ($z);
|
||||
public function setPosition($posX, $posY, $posZ = null) {
|
||||
$this->setX($posX);
|
||||
$this->setY($posY);
|
||||
if (!is_null($posZ)) {
|
||||
$this->setZ($posZ);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X Position
|
||||
* Set X position
|
||||
*
|
||||
* @param float $x Horizontal Position
|
||||
* @return \FML\Controls\Control
|
||||
* @param float $posX Horizontal position
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setX($x) {
|
||||
$this->x = (float)$x;
|
||||
public function setX($posX) {
|
||||
$this->posX = (float)$posX;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y Position
|
||||
* Set Y position
|
||||
*
|
||||
* @param float $y Vertical Position
|
||||
* @return \FML\Controls\Control
|
||||
* @param float $posY Vertical position
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setY($y) {
|
||||
$this->y = (float)$y;
|
||||
public function setY($posY) {
|
||||
$this->posY = (float)$posY;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z Position
|
||||
* Set Z position
|
||||
*
|
||||
* @param float $z Depth
|
||||
* @return \FML\Controls\Control
|
||||
* @param float $posZ Depth
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setZ($z) {
|
||||
$this->z = (float)$z;
|
||||
public function setZ($posZ) {
|
||||
$this->posZ = (float)$posZ;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Control Size
|
||||
* Set Control size
|
||||
*
|
||||
* @param float $width Control Width
|
||||
* @param float $height Control Height
|
||||
* @return \FML\Controls\Control
|
||||
* @param float $width Control width
|
||||
* @param float $height Control height
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setSize($width, $height) {
|
||||
$this->setWidth($width);
|
||||
@ -185,10 +194,10 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Control Width
|
||||
* Set Control width
|
||||
*
|
||||
* @param float $width Control Width
|
||||
* @return \FML\Controls\Control
|
||||
* @param float $width Control width
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setWidth($width) {
|
||||
$this->width = (float)$width;
|
||||
@ -196,10 +205,10 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Control Height
|
||||
* Set Control height
|
||||
*
|
||||
* @param float $height Control Height
|
||||
* @return \FML\Controls\Control
|
||||
* @param float $height Control height
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setHeight($height) {
|
||||
$this->height = (float)$height;
|
||||
@ -207,9 +216,9 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Center Alignment
|
||||
* Center alignment
|
||||
*
|
||||
* @return \FML\Controls\Control
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function centerAlign() {
|
||||
$this->setAlign(self::CENTER, self::CENTER2);
|
||||
@ -217,11 +226,11 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Horizontal and Vertical Alignment
|
||||
* Set horizontal and vertical alignment
|
||||
*
|
||||
* @param string $hAlign Horizontal Alignment
|
||||
* @param string $vAlign Vertical Alignment
|
||||
* @return \FML\Controls\Control
|
||||
* @param string $hAlign Horizontal alignment
|
||||
* @param string $vAlign Vertical alignment
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setAlign($hAlign, $vAlign) {
|
||||
$this->setHAlign($hAlign);
|
||||
@ -230,10 +239,10 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Horizontal Alignment
|
||||
* Set horizontal alignment
|
||||
*
|
||||
* @param string $hAlign Horizontal Alignment
|
||||
* @return \FML\Controls\Control
|
||||
* @param string $hAlign Horizontal alignment
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setHAlign($hAlign) {
|
||||
$this->hAlign = (string)$hAlign;
|
||||
@ -241,10 +250,10 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Vertical Alignment
|
||||
* Set vertical alignment
|
||||
*
|
||||
* @param string $vAlign Vertical Alignment
|
||||
* @return \FML\Controls\Control
|
||||
* @param string $vAlign Vertical alignment
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setVAlign($vAlign) {
|
||||
$this->vAlign = (string)$vAlign;
|
||||
@ -252,9 +261,9 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset Alignment
|
||||
* Reset alignment
|
||||
*
|
||||
* @return \FML\Controls\Control
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function resetAlign() {
|
||||
$this->setAlign(null, null);
|
||||
@ -262,10 +271,10 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Control Scale
|
||||
* Set Control scale
|
||||
*
|
||||
* @param float $scale Control Scale
|
||||
* @return \FML\Controls\Control
|
||||
* @param float $scale Control scale
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setScale($scale) {
|
||||
$this->scale = (float)$scale;
|
||||
@ -273,10 +282,10 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Visibility
|
||||
* Set visibility
|
||||
*
|
||||
* @param bool $visible Whether Control should be visible
|
||||
* @return \FML\Controls\Control
|
||||
* @param bool $visible Whether the Control should be visible
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setVisible($visible = true) {
|
||||
$this->hidden = ($visible ? 0 : 1);
|
||||
@ -284,10 +293,21 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new Class Name
|
||||
* Set Control rotation
|
||||
*
|
||||
* @param string $class Class Name
|
||||
* @return \FML\Controls\Control
|
||||
* @param float $rotation
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function setRotation($rotation) {
|
||||
$this->rotation = (float)$rotation;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new class name
|
||||
*
|
||||
* @param string $class Class name
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function addClass($class) {
|
||||
$class = (string)$class;
|
||||
@ -301,31 +321,37 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
* 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
|
||||
* @param string $eventLabel (optional) Event on which the action is triggered
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function addActionTriggerFeature($actionName, $eventLabel = ScriptLabel::MOUSECLICK) {
|
||||
$actionTrigger = new ActionTrigger($actionName, $this, $eventLabel);
|
||||
$this->addScriptFeature($actionTrigger);
|
||||
if (is_object($actionName) && ($actionName instanceof ActionTrigger)) {
|
||||
$this->addScriptFeature($actionName);
|
||||
} else {
|
||||
$actionTrigger = new ActionTrigger($actionName, $this, $eventLabel);
|
||||
$this->addScriptFeature($actionTrigger);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Script Feature
|
||||
* Add a new Script Feature
|
||||
*
|
||||
* @param ScriptFeature $scriptFeature Script Feature
|
||||
* @return \FML\Controls\Control
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function addScriptFeature(ScriptFeature $scriptFeature) {
|
||||
array_push($this->scriptFeatures, $scriptFeature);
|
||||
if (!in_array($scriptFeature, $this->scriptFeatures, true)) {
|
||||
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
|
||||
*
|
||||
* @param string $eventLabel (optional) Event on which the Map Info will be opened
|
||||
* @return \FML\Controls\Control
|
||||
* @param string $eventLabel (optional) Event on which the map info will be opened
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function addMapInfoFeature($eventLabel = ScriptLabel::MOUSECLICK) {
|
||||
$mapInfo = new MapInfo($this, $eventLabel);
|
||||
@ -334,11 +360,11 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a dynamic Feature to open a specific Player Profile
|
||||
* 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
|
||||
* @param string $login Login of the player
|
||||
* @param string $eventLabel (optional) Event on which the player profile will be opened
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function addPlayerProfileFeature($login, $eventLabel = ScriptLabel::MOUSECLICK) {
|
||||
$playerProfile = new PlayerProfile($login, $this, $eventLabel);
|
||||
@ -347,12 +373,12 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a dynamic Feature playing an UISound
|
||||
* Add a dynamic Feature playing a 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
|
||||
* @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|static
|
||||
*/
|
||||
public function addUISoundFeature($soundName, $variant = 0, $eventLabel = ScriptLabel::MOUSECLICK) {
|
||||
$uiSound = new UISound($soundName, $this, $variant, $eventLabel);
|
||||
@ -364,10 +390,10 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
* 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
|
||||
* @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|static
|
||||
*/
|
||||
public function addToggleFeature(Control $toggledControl, $labelName = Scriptlabel::MOUSECLICK, $onlyShow = false, $onlyHide = false) {
|
||||
$toggle = new Toggle($this, $toggledControl, $labelName, $onlyShow, $onlyHide);
|
||||
@ -379,9 +405,9 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
* 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
|
||||
* @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|static
|
||||
*/
|
||||
public function addTooltipFeature(Control $tooltipControl, $stayOnClick = false, $invert = false) {
|
||||
$tooltip = new Tooltip($this, $tooltipControl, $stayOnClick, $invert);
|
||||
@ -393,10 +419,10 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
* 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
|
||||
* @param string $text Text to display on the Tooltip Label
|
||||
* @param bool $stayOnClick (optional) Whether the Tooltip should stay on click
|
||||
* @param bool $invert (optional) Whether the visibility toggling should be inverted
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function addTooltipLabelFeature(Label $tooltipControl, $text, $stayOnClick = false, $invert = false) {
|
||||
$tooltip = new Tooltip($this, $tooltipControl, $stayOnClick, $invert, $text);
|
||||
@ -405,11 +431,11 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Custom Control Script Text Part
|
||||
* Add a custom Control Script text part
|
||||
*
|
||||
* @param string $scriptText Script Text
|
||||
* @param string $label (optional) Script Label Name
|
||||
* @return \FML\Controls\Control
|
||||
* @param string $scriptText Script text
|
||||
* @param string $label (optional) Script label name
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function addScriptText($scriptText, $label = ScriptLabel::MOUSECLICK) {
|
||||
$customText = new ControlScript($this, $scriptText, $label);
|
||||
@ -420,7 +446,7 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
/**
|
||||
* Remove all Script Features
|
||||
*
|
||||
* @return \FML\Controls\Control
|
||||
* @return \FML\Controls\Control|static
|
||||
*/
|
||||
public function removeScriptFeatures() {
|
||||
$this->scriptFeatures = array();
|
||||
@ -439,19 +465,19 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
*/
|
||||
public function render(\DOMDocument $domDocument) {
|
||||
$xmlElement = $domDocument->createElement($this->tagName);
|
||||
if ($this->id) {
|
||||
$xmlElement->setAttribute('id', $this->id);
|
||||
if ($this->controlId) {
|
||||
$xmlElement->setAttribute('id', $this->controlId);
|
||||
}
|
||||
if ($this->x != 0. || $this->y != 0. || $this->z != 0.) {
|
||||
$xmlElement->setAttribute('posn', "{$this->x} {$this->y} {$this->z}");
|
||||
if ($this->posX || $this->posY || $this->posZ) {
|
||||
$xmlElement->setAttribute('posn', "{$this->posX} {$this->posY} {$this->posZ}");
|
||||
}
|
||||
if ($this->width >= 0. || $this->height >= 0.) {
|
||||
$xmlElement->setAttribute('sizen', "{$this->width} {$this->height}");
|
||||
}
|
||||
if ($this->hAlign) {
|
||||
if ($this->hAlign !== self::LEFT) {
|
||||
$xmlElement->setAttribute('halign', $this->hAlign);
|
||||
}
|
||||
if ($this->vAlign) {
|
||||
if ($this->vAlign !== self::TOP) {
|
||||
$xmlElement->setAttribute('valign', $this->vAlign);
|
||||
}
|
||||
if ($this->scale != 1.) {
|
||||
@ -460,6 +486,9 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
if ($this->hidden) {
|
||||
$xmlElement->setAttribute('hidden', $this->hidden);
|
||||
}
|
||||
if ($this->rotation) {
|
||||
$xmlElement->setAttribute('rot', $this->rotation);
|
||||
}
|
||||
if (!empty($this->classes)) {
|
||||
$classes = implode(' ', $this->classes);
|
||||
$xmlElement->setAttribute('class', $classes);
|
||||
@ -468,7 +497,7 @@ abstract class Control implements Renderable, ScriptFeatureable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ManiaScript Class of the Control
|
||||
* Get the ManiaScript class of the Control
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
Reference in New Issue
Block a user