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

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

View File

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

View File

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