FML Update

This commit is contained in:
Steffen Schröder 2014-05-18 19:45:50 +02:00
parent 31cba03bba
commit 4194f99c2a
45 changed files with 922 additions and 598 deletions

View File

@ -202,14 +202,13 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
if (is_bool($value)) {
// Boolean checkbox
$checkBox = new CheckBox(self::ACTION_PREFIX_SETTING . $name, $value);
$settingFrame->add($checkBox);
$quad = new Quad();
$checkBox->setQuad($quad);
$quad->setX($width / 2 * 0.46);
$quad->setZ(-0.01);
$quad->setSize(4, 4);
$checkBox = new CheckBox(self::ACTION_PREFIX_SETTING . $name, $value, $quad);
$settingFrame->add($checkBox);
} else {
// Other
$entry = new Entry();

View File

@ -23,8 +23,6 @@ class CheckBox implements Renderable, ScriptFeatureable {
* Protected Properties
*/
protected $name = null;
protected $default = null;
protected $hiddenEntryDisabled = null;
protected $feature = null;
/**
@ -35,10 +33,10 @@ class CheckBox implements Renderable, ScriptFeatureable {
* @param Quad $quad (optional) CheckBox Quad
*/
public function __construct($name = null, $default = null, Quad $quad = null) {
$this->feature = new CheckBoxFeature();
$this->setName($name);
$this->setDefault($default);
$this->feature = new CheckBoxFeature();
$this->feature->setQuad($quad);
$this->setQuad($quad);
}
/**
@ -59,18 +57,7 @@ class CheckBox implements Renderable, ScriptFeatureable {
* @return \FML\Components\CheckBox
*/
public function setDefault($default) {
$this->default = ($default ? 1 : 0);
return $this;
}
/**
* Disable the hidden Entry that's sending the Value on Page Actions
*
* @param bool $disable (optional) Whether to disable or not
* @return \FML\Components\CheckBox
*/
public function disableHiddenEntry($disable = true) {
$this->hiddenEntryDisabled = (bool)$disable;
$this->feature->setDefault($default);
return $this;
}
@ -106,7 +93,7 @@ class CheckBox implements Renderable, ScriptFeatureable {
* @param Quad $quad CheckBox Quad
* @return \FML\Components\CheckBox
*/
public function setQuad(Quad $quad) {
public function setQuad(Quad $quad = null) {
$this->feature->setQuad($quad);
return $this;
}
@ -128,9 +115,7 @@ class CheckBox implements Renderable, ScriptFeatureable {
if (!$this->feature->getQuad() && $createIfEmpty) {
$quad = new Quad();
$quad->setSize(10, 10);
$quad->setScriptEvents(true);
$this->feature->setQuad($quad);
$this->setQuad($quad);
}
return $this->feature->getQuad();
}
@ -140,18 +125,13 @@ class CheckBox implements Renderable, ScriptFeatureable {
*/
public function render(\DOMDocument $domDocument) {
$frame = new Frame();
$frame->addScriptFeature($this->feature);
$quad = $this->getQuad();
$frame->add($quad);
if (!$this->hiddenEntryDisabled) {
$entry = $this->buildEntry();
$frame->add($entry);
$this->feature->setEntry($entry);
} else {
$this->feature->setEntry(null);
}
return $frame->render($domDocument);
}
@ -165,7 +145,6 @@ class CheckBox implements Renderable, ScriptFeatureable {
$entry = new Entry();
$entry->setVisible(false);
$entry->setName($this->name);
$entry->setDefault($this->default);
return $entry;
}
}

View File

@ -0,0 +1,135 @@
<?php
namespace FML\Components;
use FML\Controls\Entry;
use FML\Controls\Frame;
use FML\Controls\Label;
use FML\Script\Features\ScriptFeature;
use FML\Script\Features\ValuePickerFeature;
use FML\Types\Renderable;
use FML\Types\ScriptFeatureable;
/**
* ValuePicker Component
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ValuePicker implements Renderable, ScriptFeatureable {
/*
* Protected Properties
*/
protected $name = null;
protected $feature = null;
/**
* Create a new ValuePicker Component
*
* @param string $name (optional) CheckBox Name
* @param array $values (optional) Possible Values
* @param bool $default (optional) Default Value
* @param Label $label (optional) ValuePicker Label
*/
public function __construct($name = null, array $values = array(), $default = null, Label $label = null) {
$this->feature = new ValuePickerFeature();
$this->setName($name);
$this->setValues($values);
$this->setDefault($default);
$this->setLabel($label);
}
/**
* Set the Name
*
* @param string $name ValuePicker Name
* @return \FML\Components\ValuePicker
*/
public function setName($name) {
$this->name = (string)$name;
return $this;
}
/**
* Set the possible Values
*
* @param array $values Possible Values
* @return \FML\Components\ValuePicker
*/
public function setValues(array $values) {
$this->feature->setValues($values);
return $this;
}
/**
* Set the Default Value
*
* @param bool $default Default Value
* @return \FML\Components\ValuePicker
*/
public function setDefault($default) {
$this->feature->setDefault($default);
return $this;
}
/**
* Set the ValuePicker Label
*
* @param Label $label ValuePicker Label
* @return \FML\Components\ValuePicker
*/
public function setLabel(Label $label = null) {
$this->feature->setLabel($label);
return $this;
}
/**
* Get the ValuePicker Label
*
* @param bool $createIfEmpty (optional) Create the Label if it's not set
* @return \FML\Controls\Label
*/
public function getLabel($createIfEmpty = true) {
if (!$this->feature->getLabel() && $createIfEmpty) {
$label = new Label();
$this->setLabel($label);
}
return $this->feature->getLabel();
}
/**
* @see \FML\Types\ScriptFeatureable::getScriptFeatures()
*/
public function getScriptFeatures() {
return ScriptFeature::collect($this->feature, $this->getLabel(), $this->feature->getEntry());
}
/**
* @see \ManiaControl\Types\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {
$frame = new Frame();
$label = $this->getLabel();
$frame->add($label);
$entry = $this->buildEntry();
$frame->add($entry);
$this->feature->setEntry($entry);
return $frame->render($domDocument);
}
/**
* Build the hidden Entry
*
* @return Entry
*/
protected function buildEntry() {
$entry = new Entry();
$entry->setVisible(false);
$entry->setName($this->name);
return $entry;
}
}

View File

@ -189,8 +189,7 @@ class Dico {
}
if ($entryValue) {
$this->entries[$language][$entryId] = $entryValue;
}
else {
} else {
if (isset($this->entries[$language][$entryId])) {
unset($this->entries[$language][$entryId]);
}
@ -212,8 +211,7 @@ class Dico {
if (isset($this->entries[$language])) {
unset($this->entries[$language][$entryId]);
}
}
else {
} else {
foreach ($this->entries as $language => $entries) {
if (isset($entries[$entryId])) {
unset($entries[$language][$entryId]);
@ -236,8 +234,7 @@ class Dico {
if ($entryId) {
$entryId = (string)$entryId;
unset($this->entries[$language][$entryId]);
}
else {
} else {
unset($this->entries[$language]);
}
}

View File

@ -43,7 +43,6 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable {
}
/**
*
* @see \FML\Types\BgColorable::setBgColor()
*/
public function setBgColor($bgColor) {
@ -52,7 +51,6 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable {
}
/**
*
* @see \FML\Types\Styleable::setStyle()
*/
public function setStyle($style) {
@ -61,7 +59,6 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable {
}
/**
*
* @see \FML\Types\TextFormatable::setTextSize()
*/
public function setTextSize($textSize) {
@ -70,7 +67,6 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable {
}
/**
*
* @see \FML\Types\TextFormatable::setTextColor()
*/
public function setTextColor($textColor) {
@ -79,7 +75,6 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable {
}
/**
*
* @see \FML\Types\TextFormatable::setAreaColor()
*/
public function setAreaColor($areaColor) {
@ -88,7 +83,6 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable {
}
/**
*
* @see \FML\Types\TextFormatable::setAreaFocusColor()
*/
public function setAreaFocusColor($areaFocusColor) {
@ -97,7 +91,6 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable {
}
/**
*
* @see \FML\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {

View File

@ -50,7 +50,6 @@ class Including implements Renderable {
}
/**
*
* @see \FML\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {

View File

@ -52,7 +52,6 @@ class Music implements Renderable {
}
/**
*
* @see \FML\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {

View File

@ -52,7 +52,6 @@ class SimpleScript implements Renderable {
}
/**
*
* @see \FML\Types\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {

View File

@ -67,7 +67,6 @@ class InstallMap implements Element {
}
/**
*
* @see \FML\ManiaCode\Element::render()
*/
public function render(\DOMDocument $domDocument) {

View File

@ -84,7 +84,6 @@ class InstallPack implements Element {
}
/**
*
* @see \FML\ManiaCode\Element::render()
*/
public function render(\DOMDocument $domDocument) {

View File

@ -67,7 +67,6 @@ class InstallReplay implements Element {
}
/**
*
* @see \FML\ManiaCode\Element::render()
*/
public function render(\DOMDocument $domDocument) {

View File

@ -84,7 +84,6 @@ class InstallScript implements Element {
}
/**
*
* @see \FML\ManiaCode\Element::render()
*/
public function render(\DOMDocument $domDocument) {

View File

@ -84,7 +84,6 @@ class InstallSkin implements Element {
}
/**
*
* @see \FML\ManiaCode\Element::render()
*/
public function render(\DOMDocument $domDocument) {

View File

@ -68,7 +68,6 @@ class JoinServer implements Element {
}
/**
*
* @see \FML\ManiaCode\Element::render()
*/
public function render(\DOMDocument $domDocument) {
@ -76,8 +75,7 @@ class JoinServer implements Element {
if ($this->ip === null) {
$loginElement = $domDocument->createElement('login', $this->login);
$xmlElement->appendChild($loginElement);
}
else {
} else {
$ipElement = $domDocument->createElement('ip', $this->ip . ':' . $this->port);
$xmlElement->appendChild($ipElement);
}

View File

@ -67,7 +67,6 @@ class PlayMap implements Element {
}
/**
*
* @see \FML\ManiaCode\Element::render()
*/
public function render(\DOMDocument $domDocument) {

View File

@ -67,7 +67,6 @@ class PlayReplay implements Element {
}
/**
*
* @see \FML\ManiaCode\Element::render()
*/
public function render(\DOMDocument $domDocument) {

View File

@ -50,7 +50,6 @@ class ShowMessage implements Element {
}
/**
*
* @see \FML\ManiaCode\Element::render()
*/
public function render(\DOMDocument $domDocument) {

View File

@ -67,7 +67,6 @@ class ViewReplay implements Element {
}
/**
*
* @see \FML\ManiaCode\Element::render()
*/
public function render(\DOMDocument $domDocument) {

View File

@ -33,6 +33,7 @@ class CheckBoxFeature extends ScriptFeature {
protected $quad = null;
/** @var Entry $entry */
protected $entry = null;
protected $default = null;
/** @var CheckBoxDesign $enabledDesign */
protected $enabledDesign = null;
/** @var CheckBoxDesign $disabledDesign */
@ -44,7 +45,7 @@ class CheckBoxFeature extends ScriptFeature {
* @param Quad $quad (optional) CheckBox Quad
* @param Entry $entry (optional) Hidden Entry
*/
public function __construct(Quad $quad = null, Entry $entry = null) {
public function __construct(Quad $quad = null, Entry $entry = null, $default = null) {
$this->setQuad($quad);
$this->setEntry($entry);
$this->setEnabledDesign(CheckBoxDesign::defaultEnabledDesign());
@ -98,10 +99,21 @@ class CheckBoxFeature extends ScriptFeature {
return $this->entry;
}
/**
* Set the default Value
*
* @param bool $default Default Value
* @return \FML\Script\Features\CheckBoxFeature
*/
public function setDefault($default) {
$this->default = (bool)$default;
return $this;
}
/**
* Set the Enabled Design
*
* @param CheckBoxDesign $checkBoxDesign CheckBox Design
* @param CheckBoxDesign $checkBoxDesign Enabled CheckBox Design
* @return \FML\Script\Features\CheckBoxFeature
*/
public function setEnabledDesign(CheckBoxDesign $checkBoxDesign) {
@ -112,7 +124,7 @@ class CheckBoxFeature extends ScriptFeature {
/**
* Set the Disabled Design
*
* @param CheckBoxDesign $checkBoxDesign CheckBox Design
* @param CheckBoxDesign $checkBoxDesign Disabled CheckBox Design
* @return \FML\Script\Features\CheckBoxFeature
*/
public function setDisabledDesign(CheckBoxDesign $checkBoxDesign) {
@ -126,7 +138,7 @@ class CheckBoxFeature extends ScriptFeature {
public function prepare(Script $script) {
if ($this->getQuad()) {
$script->setScriptInclude(ScriptInclude::TEXTLIB);
$script->addScriptFunction(self::FUNCTION_UPDATE_QUAD_DESIGN, $this->buildSetQuadDesignFunction());
$script->addScriptFunction(self::FUNCTION_UPDATE_QUAD_DESIGN, $this->buildUpdateQuadDesignFunction());
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->buildInitScriptText(), true);
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $this->buildClickScriptText());
}
@ -138,7 +150,7 @@ class CheckBoxFeature extends ScriptFeature {
*
* @return string
*/
protected function buildSetQuadDesignFunction() {
protected function buildUpdateQuadDesignFunction() {
$functionText = "
Void " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(CMlQuad _Quad) {
declare " . self::VAR_CHECKBOX_ENABLED . " as Enabled for _Quad = True;
@ -173,13 +185,11 @@ Void " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(CMlQuad _Quad) {
*/
protected function buildInitScriptText() {
$quadId = $this->getQuad()->getId(true);
$default = true;
$entryId = '';
if ($this->entry) {
$default = $this->entry->getDefault();
$entryId = $this->entry->getId(true);
}
$default = Builder::getBoolean($default);
$default = Builder::getBoolean($this->default);
$enabledDesignString = $this->enabledDesign->getDesignString();
$disabledDesignString = $this->disabledDesign->getDesignString();
$scriptText = "

View File

@ -0,0 +1,226 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Entry;
use FML\Controls\Label;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptInclude;
use FML\Script\ScriptLabel;
/**
* Script Feature for creating a ValuePicker Behavior
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ValuePickerFeature extends ScriptFeature {
/*
* Constants
*/
const FUNCTION_UPDATE_PICKER_VALUE = 'FML_UpdatePickerValue';
const VAR_PICKER_VALUES = 'FML_Picker_Values';
const VAR_PICKER_DEFAULT_VALUE = 'FML_Picker_Default_Value';
const VAR_PICKER_ENTRY_ID = 'FML_Picker_EntryId';
/*
* Protected Properties
*/
/** @var Label $label */
protected $label = null;
/** @var Entry $entry */
protected $entry = null;
protected $values = null;
protected $default = null;
/**
* Construct a new ValuePicker Feature
*
* @param Label $label (optional) ValuePicker Label
* @param Entry $entry (optional) Hidden Entry
* @param array $values (optional) Possible Values
* @param string $default (optional) Default Value
*/
public function __construct(Label $label = null, Entry $entry = null, array $values = array(), $default = null) {
$this->setLabel($label);
$this->setEntry($entry);
$this->setValues($values);
$this->setDefault($default);
}
/**
* Set the ValuePicker Label
*
* @param Label $label ValuePicker Label
* @return \FML\Script\Features\ValuePickerFeature
*/
public function setLabel(Label $label = null) {
if ($label) {
$label->checkId();
$label->setScriptEvents(true);
}
$this->label = $label;
return $this;
}
/**
* Get the ValuePicker Label
*
* @return \FML\Controls\Label
*/
public function getLabel() {
return $this->label;
}
/**
* Set the hidden Entry
*
* @param Entry $entry Hidden Entry
* @return \FML\Script\Features\ValuePickerFeature
*/
public function setEntry(Entry $entry = null) {
if ($entry) {
$entry->checkId();
}
$this->entry = $entry;
return $this;
}
/**
* Get the hidden Entry
*
* @return \FML\Controls\Entry
*/
public function getEntry() {
return $this->entry;
}
/**
* Set the possible Values
*
* @param array $values Possible Values
* @return \FML\Script\Features\ValuePickerFeature
*/
public function setValues(array $values) {
$this->values = array();
foreach ($values as $value) {
array_push($this->values, (string)$value);
}
return $this;
}
/**
* Set the default Value
*
* @param string $default Default Value
* @return \FML\Script\Features\ValuePickerFeature
*/
public function setDefault($default) {
$this->default = (string)$default;
}
/**
* Get the default Value
*
* @return string
*/
public function getDefault() {
if ($this->default) {
return $this->default;
}
if ($this->values) {
return reset($this->values);
}
return null;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
if ($this->label) {
$script->setScriptInclude(ScriptInclude::TEXTLIB);
$script->addScriptFunction(self::FUNCTION_UPDATE_PICKER_VALUE, $this->buildUpdatePickerValueFunction());
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->buildInitScriptText(), true);
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->buildClickScriptText());
}
return $this;
}
/**
* Build the Function Text
*
* @return string
*/
protected function buildUpdatePickerValueFunction() {
$functionText = "
Void " . self::FUNCTION_UPDATE_PICKER_VALUE . "(CMlLabel _Label) {
declare " . self::VAR_PICKER_VALUES . " as Values for _Label = Text[];
declare NewValueIndex = 0;
if (Values.exists(_Label.Value) {
declare ValueIndex = _Label.keyof(_Label.Value);
ValueIndex += 1;
if (Values.existskey(ValueIndex)) {
NewValueIndex = ValueIndex;
}
}
declare NewValue = \"\";
if (Values.existskey(NewValueIndex)) {
NewValue = Values[NewValueIndex];
} else {
declare " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for _Label = \"\";
NewValue = Default;
}
_Label.Value = NewValue;
declare " . self::VAR_PICKER_ENTRY_ID . " as EntryId for _Label = \"\";
if (EntryId != \"\") {
declare Entry <=> (Page.GetFirstChild(EntryId) as CMlEntry);
Entry.Value = NewValue;
}
}";
return $functionText;
}
/**
* Build the Init Script Text
*
* @return string
*/
protected function buildInitScriptText() {
$labelId = $this->label->getId(true);
$entryId = '';
if ($this->entry) {
$entryId = $this->entry->getId(true);
}
$values = Builder::getArray($this->values);
$default = $this->getDefault();
$scriptText = "
declare Label_Picker <=> (Page.GetFirstChild(\"{$labelId}\") as CMlLabel);
declare Text[] " . self::VAR_PICKER_VALUES . " as Values for Label_Picker;
Values = {$values};
declare Text " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for Label_Picker;
Default = \"{$default}\";
declare Text " . self::VAR_PICKER_ENTRY_ID . " as EntryId for Label_Picker;
EntryId = \"{$entryId}\";
" . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker);
";
return $scriptText;
}
/**
* Build the Script Text for Label Clicks
*
* @return string
*/
protected function buildClickScriptText() {
$labelId = $this->label->getId(true);
$scriptText = "
if (Event.ControlId == \"{$labelId}\") {
declare Label_Picker <=> (Event.Control as CMlLabel);
" . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker);
}";
return $scriptText;
}
}

View File

@ -32,8 +32,7 @@ class ScriptInclude {
$this->setFile($file);
if ($namespace) {
$this->setNamespace($namespace);
}
else {
} else {
$fileParts = explode('.', $file);
if (count($fileParts) === 1) {
$this->setNamespace($file);