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)) { if (is_bool($value)) {
// Boolean checkbox // Boolean checkbox
$checkBox = new CheckBox(self::ACTION_PREFIX_SETTING . $name, $value);
$settingFrame->add($checkBox);
$quad = new Quad(); $quad = new Quad();
$checkBox->setQuad($quad);
$quad->setX($width / 2 * 0.46); $quad->setX($width / 2 * 0.46);
$quad->setZ(-0.01); $quad->setZ(-0.01);
$quad->setSize(4, 4); $quad->setSize(4, 4);
$checkBox = new CheckBox(self::ACTION_PREFIX_SETTING . $name, $value, $quad);
$settingFrame->add($checkBox);
} else { } else {
// Other // Other
$entry = new Entry(); $entry = new Entry();

View File

@ -23,8 +23,6 @@ class CheckBox implements Renderable, ScriptFeatureable {
* Protected Properties * Protected Properties
*/ */
protected $name = null; protected $name = null;
protected $default = null;
protected $hiddenEntryDisabled = null;
protected $feature = null; protected $feature = null;
/** /**
@ -35,10 +33,10 @@ class CheckBox implements Renderable, ScriptFeatureable {
* @param Quad $quad (optional) CheckBox Quad * @param Quad $quad (optional) CheckBox Quad
*/ */
public function __construct($name = null, $default = null, Quad $quad = null) { public function __construct($name = null, $default = null, Quad $quad = null) {
$this->feature = new CheckBoxFeature();
$this->setName($name); $this->setName($name);
$this->setDefault($default); $this->setDefault($default);
$this->feature = new CheckBoxFeature(); $this->setQuad($quad);
$this->feature->setQuad($quad);
} }
/** /**
@ -59,18 +57,7 @@ class CheckBox implements Renderable, ScriptFeatureable {
* @return \FML\Components\CheckBox * @return \FML\Components\CheckBox
*/ */
public function setDefault($default) { public function setDefault($default) {
$this->default = ($default ? 1 : 0); $this->feature->setDefault($default);
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;
return $this; return $this;
} }
@ -106,7 +93,7 @@ class CheckBox implements Renderable, ScriptFeatureable {
* @param Quad $quad CheckBox Quad * @param Quad $quad CheckBox Quad
* @return \FML\Components\CheckBox * @return \FML\Components\CheckBox
*/ */
public function setQuad(Quad $quad) { public function setQuad(Quad $quad = null) {
$this->feature->setQuad($quad); $this->feature->setQuad($quad);
return $this; return $this;
} }
@ -128,9 +115,7 @@ class CheckBox implements Renderable, ScriptFeatureable {
if (!$this->feature->getQuad() && $createIfEmpty) { if (!$this->feature->getQuad() && $createIfEmpty) {
$quad = new Quad(); $quad = new Quad();
$quad->setSize(10, 10); $quad->setSize(10, 10);
$quad->setScriptEvents(true); $this->setQuad($quad);
$this->feature->setQuad($quad);
} }
return $this->feature->getQuad(); return $this->feature->getQuad();
} }
@ -140,18 +125,13 @@ class CheckBox implements Renderable, ScriptFeatureable {
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {
$frame = new Frame(); $frame = new Frame();
$frame->addScriptFeature($this->feature);
$quad = $this->getQuad(); $quad = $this->getQuad();
$frame->add($quad); $frame->add($quad);
if (!$this->hiddenEntryDisabled) {
$entry = $this->buildEntry(); $entry = $this->buildEntry();
$frame->add($entry); $frame->add($entry);
$this->feature->setEntry($entry); $this->feature->setEntry($entry);
} else {
$this->feature->setEntry(null);
}
return $frame->render($domDocument); return $frame->render($domDocument);
} }
@ -165,7 +145,6 @@ class CheckBox implements Renderable, ScriptFeatureable {
$entry = new Entry(); $entry = new Entry();
$entry->setVisible(false); $entry->setVisible(false);
$entry->setName($this->name); $entry->setName($this->name);
$entry->setDefault($this->default);
return $entry; 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

@ -181,16 +181,15 @@ class Dico {
* @return \FML\Elements\Dico * @return \FML\Elements\Dico
*/ */
public function setEntry($language, $entryId, $entryValue) { public function setEntry($language, $entryId, $entryValue) {
$language = (string) $language; $language = (string)$language;
$entryId = (string) $entryId; $entryId = (string)$entryId;
$entryValue = (string) $entryValue; $entryValue = (string)$entryValue;
if (!isset($this->entries[$language]) && $entryValue) { if (!isset($this->entries[$language]) && $entryValue) {
$this->entries[$language] = array(); $this->entries[$language] = array();
} }
if ($entryValue) { if ($entryValue) {
$this->entries[$language][$entryId] = $entryValue; $this->entries[$language][$entryId] = $entryValue;
} } else {
else {
if (isset($this->entries[$language][$entryId])) { if (isset($this->entries[$language][$entryId])) {
unset($this->entries[$language][$entryId]); unset($this->entries[$language][$entryId]);
} }
@ -206,14 +205,13 @@ class Dico {
* @return \FML\Elements\Dico * @return \FML\Elements\Dico
*/ */
public function removeEntry($entryId, $language = null) { public function removeEntry($entryId, $language = null) {
$entryId = (string) $entryId; $entryId = (string)$entryId;
if ($language) { if ($language) {
$language = (string) $language; $language = (string)$language;
if (isset($this->entries[$language])) { if (isset($this->entries[$language])) {
unset($this->entries[$language][$entryId]); unset($this->entries[$language][$entryId]);
} }
} } else {
else {
foreach ($this->entries as $language => $entries) { foreach ($this->entries as $language => $entries) {
if (isset($entries[$entryId])) { if (isset($entries[$entryId])) {
unset($entries[$language][$entryId]); unset($entries[$language][$entryId]);
@ -231,13 +229,12 @@ class Dico {
* @return \FML\Elements\Dico * @return \FML\Elements\Dico
*/ */
public function removeLanguage($language, $entryId = null) { public function removeLanguage($language, $entryId = null) {
$language = (string) $language; $language = (string)$language;
if (isset($this->entries[$language])) { if (isset($this->entries[$language])) {
if ($entryId) { if ($entryId) {
$entryId = (string) $entryId; $entryId = (string)$entryId;
unset($this->entries[$language][$entryId]); unset($this->entries[$language][$entryId]);
} } else {
else {
unset($this->entries[$language]); unset($this->entries[$language]);
} }
} }

View File

@ -43,61 +43,54 @@ class Format implements BgColorable, Renderable, Styleable, TextFormatable {
} }
/** /**
*
* @see \FML\Types\BgColorable::setBgColor() * @see \FML\Types\BgColorable::setBgColor()
*/ */
public function setBgColor($bgColor) { public function setBgColor($bgColor) {
$this->bgColor = (string) $bgColor; $this->bgColor = (string)$bgColor;
return $this; return $this;
} }
/** /**
*
* @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;
} }
/** /**
*
* @see \FML\Renderable::render() * @see \FML\Renderable::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -46,11 +46,10 @@ class Including implements Renderable {
* @param string $url Include Url * @param string $url Include Url
*/ */
public function setUrl($url) { public function setUrl($url) {
$this->url = (string) $url; $this->url = (string)$url;
} }
/** /**
*
* @see \FML\Renderable::render() * @see \FML\Renderable::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -47,12 +47,11 @@ class Music implements Renderable {
* @return \FML\Elements\Music * @return \FML\Elements\Music
*/ */
public function setData($data) { public function setData($data) {
$this->data = (string) $data; $this->data = (string)$data;
return $this; return $this;
} }
/** /**
*
* @see \FML\Renderable::render() * @see \FML\Renderable::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -47,12 +47,11 @@ class SimpleScript implements Renderable {
* @return \FML\Script\Script * @return \FML\Script\Script
*/ */
public function setText($text) { public function setText($text) {
$this->text = (string) $text; $this->text = (string)$text;
return $this; return $this;
} }
/** /**
*
* @see \FML\Types\Renderable::render() * @see \FML\Types\Renderable::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -51,7 +51,7 @@ class InstallMap implements Element {
* @return \FML\ManiaCode\InstallMap * @return \FML\ManiaCode\InstallMap
*/ */
public function setName($name) { public function setName($name) {
$this->name = (string) $name; $this->name = (string)$name;
return $this; return $this;
} }
@ -62,12 +62,11 @@ class InstallMap implements Element {
* @return \FML\ManiaCode\InstallMap * @return \FML\ManiaCode\InstallMap
*/ */
public function setUrl($url) { public function setUrl($url) {
$this->url = (string) $url; $this->url = (string)$url;
return $this; return $this;
} }
/** /**
*
* @see \FML\ManiaCode\Element::render() * @see \FML\ManiaCode\Element::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -57,7 +57,7 @@ class InstallPack implements Element {
* @return \FML\ManiaCode\InstallPack * @return \FML\ManiaCode\InstallPack
*/ */
public function setName($name) { public function setName($name) {
$this->name = (string) $name; $this->name = (string)$name;
return $this; return $this;
} }
@ -68,7 +68,7 @@ class InstallPack implements Element {
* @return \FML\ManiaCode\InstallPack * @return \FML\ManiaCode\InstallPack
*/ */
public function setFile($file) { public function setFile($file) {
$this->file = (string) $file; $this->file = (string)$file;
return $this; return $this;
} }
@ -79,12 +79,11 @@ class InstallPack implements Element {
* @return \FML\ManiaCode\InstallPack * @return \FML\ManiaCode\InstallPack
*/ */
public function setUrl($url) { public function setUrl($url) {
$this->url = (string) $url; $this->url = (string)$url;
return $this; return $this;
} }
/** /**
*
* @see \FML\ManiaCode\Element::render() * @see \FML\ManiaCode\Element::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -51,7 +51,7 @@ class InstallReplay implements Element {
* @return \FML\ManiaCode\InstallReplay * @return \FML\ManiaCode\InstallReplay
*/ */
public function setName($name) { public function setName($name) {
$this->name = (string) $name; $this->name = (string)$name;
return $this; return $this;
} }
@ -62,12 +62,11 @@ class InstallReplay implements Element {
* @return \FML\ManiaCode\InstallReplay * @return \FML\ManiaCode\InstallReplay
*/ */
public function setUrl($url) { public function setUrl($url) {
$this->url = (string) $url; $this->url = (string)$url;
return $this; return $this;
} }
/** /**
*
* @see \FML\ManiaCode\Element::render() * @see \FML\ManiaCode\Element::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -57,7 +57,7 @@ class InstallScript implements Element {
* @return \FML\ManiaCode\InstallScript * @return \FML\ManiaCode\InstallScript
*/ */
public function setName($name) { public function setName($name) {
$this->name = (string) $name; $this->name = (string)$name;
return $this; return $this;
} }
@ -68,7 +68,7 @@ class InstallScript implements Element {
* @return \FML\ManiaCode\InstallScript * @return \FML\ManiaCode\InstallScript
*/ */
public function setFile($file) { public function setFile($file) {
$this->file = (string) $file; $this->file = (string)$file;
return $this; return $this;
} }
@ -79,12 +79,11 @@ class InstallScript implements Element {
* @return \FML\ManiaCode\InstallScript * @return \FML\ManiaCode\InstallScript
*/ */
public function setUrl($url) { public function setUrl($url) {
$this->url = (string) $url; $this->url = (string)$url;
return $this; return $this;
} }
/** /**
*
* @see \FML\ManiaCode\Element::render() * @see \FML\ManiaCode\Element::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -57,7 +57,7 @@ class InstallSkin implements Element {
* @return \FML\ManiaCode\InstallSkin * @return \FML\ManiaCode\InstallSkin
*/ */
public function setName($name) { public function setName($name) {
$this->name = (string) $name; $this->name = (string)$name;
return $this; return $this;
} }
@ -68,7 +68,7 @@ class InstallSkin implements Element {
* @return \FML\ManiaCode\InstallSkin * @return \FML\ManiaCode\InstallSkin
*/ */
public function setFile($file) { public function setFile($file) {
$this->file = (string) $file; $this->file = (string)$file;
return $this; return $this;
} }
@ -79,12 +79,11 @@ class InstallSkin implements Element {
* @return \FML\ManiaCode\InstallSkin * @return \FML\ManiaCode\InstallSkin
*/ */
public function setUrl($url) { public function setUrl($url) {
$this->url = (string) $url; $this->url = (string)$url;
return $this; return $this;
} }
/** /**
*
* @see \FML\ManiaCode\Element::render() * @see \FML\ManiaCode\Element::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

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

View File

@ -51,7 +51,7 @@ class PlayMap implements Element {
* @return \FML\ManiaCode\PlayMap * @return \FML\ManiaCode\PlayMap
*/ */
public function setName($name) { public function setName($name) {
$this->name = (string) $name; $this->name = (string)$name;
return $this; return $this;
} }
@ -62,12 +62,11 @@ class PlayMap implements Element {
* @return \FML\ManiaCode\PlayMap * @return \FML\ManiaCode\PlayMap
*/ */
public function setUrl($url) { public function setUrl($url) {
$this->url = (string) $url; $this->url = (string)$url;
return $this; return $this;
} }
/** /**
*
* @see \FML\ManiaCode\Element::render() * @see \FML\ManiaCode\Element::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -51,7 +51,7 @@ class PlayReplay implements Element {
* @return \FML\ManiaCode\PlayReplay * @return \FML\ManiaCode\PlayReplay
*/ */
public function setName($name) { public function setName($name) {
$this->name = (string) $name; $this->name = (string)$name;
return $this; return $this;
} }
@ -62,12 +62,11 @@ class PlayReplay implements Element {
* @return \FML\ManiaCode\PlayReplay * @return \FML\ManiaCode\PlayReplay
*/ */
public function setUrl($url) { public function setUrl($url) {
$this->url = (string) $url; $this->url = (string)$url;
return $this; return $this;
} }
/** /**
*
* @see \FML\ManiaCode\Element::render() * @see \FML\ManiaCode\Element::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -45,12 +45,11 @@ class ShowMessage implements Element {
* @return \FML\ManiaCode\ShowMessage * @return \FML\ManiaCode\ShowMessage
*/ */
public function setMessage($message) { public function setMessage($message) {
$this->message = (string) $message; $this->message = (string)$message;
return $this; return $this;
} }
/** /**
*
* @see \FML\ManiaCode\Element::render() * @see \FML\ManiaCode\Element::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

@ -51,7 +51,7 @@ class ViewReplay implements Element {
* @return \FML\ManiaCode\ViewReplay * @return \FML\ManiaCode\ViewReplay
*/ */
public function setName($name) { public function setName($name) {
$this->name = (string) $name; $this->name = (string)$name;
return $this; return $this;
} }
@ -62,12 +62,11 @@ class ViewReplay implements Element {
* @return \FML\ManiaCode\ViewReplay * @return \FML\ManiaCode\ViewReplay
*/ */
public function setUrl($url) { public function setUrl($url) {
$this->url = (string) $url; $this->url = (string)$url;
return $this; return $this;
} }
/** /**
*
* @see \FML\ManiaCode\Element::render() * @see \FML\ManiaCode\Element::render()
*/ */
public function render(\DOMDocument $domDocument) { public function render(\DOMDocument $domDocument) {

View File

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

View File

@ -57,7 +57,7 @@ class PagingPage {
* @return \FML\Script\Features\PagingPage * @return \FML\Script\Features\PagingPage
*/ */
public function setPageNumber($pageNumber) { public function setPageNumber($pageNumber) {
$this->number = (int) $pageNumber; $this->number = (int)$pageNumber;
return $this; return $this;
} }

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

@ -34,7 +34,7 @@ class ScriptFunction {
* @return \FML\Script\ScriptFunction * @return \FML\Script\ScriptFunction
*/ */
public function setName($name) { public function setName($name) {
$this->name = (string) $name; $this->name = (string)$name;
return $this; return $this;
} }
@ -45,7 +45,7 @@ class ScriptFunction {
* @return \FML\Script\ScriptFunction * @return \FML\Script\ScriptFunction
*/ */
public function setText($text) { public function setText($text) {
$this->text = (string) $text; $this->text = (string)$text;
return $this; return $this;
} }

View File

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