updated FML

This commit is contained in:
kremsy 2017-06-21 19:43:38 +02:00
parent 68a0c493ae
commit dd0572d7b2
16 changed files with 649 additions and 472 deletions

View File

@ -233,6 +233,13 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener,
* @return bool
*/
public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) {
//Add Toggle Feature
if($manialinkText instanceof ManiaLink){
/*$toggleInterfaceF9 = new \FML\Script\Features\ToggleInterface("F9");
$manialinkText->getScript()
->addFeature($toggleInterfaceF9); (not working yet) */
}
$manialinkText = (string) $manialinkText;
if (!$manialinkText) {

View File

@ -13,7 +13,6 @@ use FML\Types\ScriptFeatureable;
/**
* CheckBox Component
*
* @uses Quad
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
@ -74,6 +73,8 @@ class CheckBox implements Renderable, ScriptFeatureable
public function setName($name)
{
$this->name = (string)$name;
$this->getEntry()
->setName($this->name);
return $this;
}
@ -221,6 +222,7 @@ class CheckBox implements Renderable, ScriptFeatureable
*
* @param Entry $entry Hidden Entry
* @return static
* @deprecated
*/
public function setEntry(Entry $entry)
{
@ -236,9 +238,11 @@ class CheckBox implements Renderable, ScriptFeatureable
protected function createEntry()
{
$entry = new Entry();
$entry->setVisible(false)
->setName($this->name);
$this->setEntry($entry);
$entry->setVisible(false);
if ($this->name) {
$entry->setName($this->name);
}
$this->feature->setEntry($entry);
return $entry;
}
@ -247,7 +251,7 @@ class CheckBox implements Renderable, ScriptFeatureable
*/
public function getScriptFeatures()
{
return ScriptFeature::collect($this->feature, $this->getQuad(), $this->feature->getEntry());
return ScriptFeature::collect($this->feature, $this->getQuad(), $this->getEntry());
}
/**

View File

@ -13,7 +13,6 @@ use FML\Types\ScriptFeatureable;
/**
* ValuePicker Component
*
* @uses Entry
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3

View File

@ -67,11 +67,21 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable
*/
protected $height = 0.;
/**
* @var string $defaultHorizontalAlign Default horizontal alignment
*/
static protected $defaultHorizontalAlign = self::CENTER;
/**
* @var string $horizontalAlign Horizontal alignment
*/
protected $horizontalAlign = self::CENTER;
/**
* @var string $defaultVerticalAlign Default vertical alignment
*/
static protected $defaultVerticalAlign = self::CENTER2;
/**
* @var string $verticalAlign Vertical alignment
*/
@ -130,6 +140,8 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable
if ($controlId) {
$this->setId($controlId);
}
$this->setHorizontalAlign(static::$defaultHorizontalAlign);
$this->setVerticalAlign(static::$defaultVerticalAlign);
}
/**
@ -310,6 +322,17 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable
->setHeight($height);
}
/**
* Get the default horizontal alignment
*
* @api
* @return string
*/
public static function getDefaultHorizontalAlign()
{
return static::$defaultHorizontalAlign;
}
/**
* Get the horizontal alignment
*
@ -321,6 +344,17 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable
return $this->horizontalAlign;
}
/**
* Set the default horizontal alignment
*
* @api
* @param string $defaultHorizontalAlignment Default horizontal alignment
*/
public static function setDefaultHorizontalAlign($defaultHorizontalAlignment)
{
static::$defaultHorizontalAlign = (string)$defaultHorizontalAlignment;
}
/**
* Set the horizontal alignment
*
@ -348,6 +382,17 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable
return $this;
}
/**
* Get the default vertical alignment
*
* @api
* @return string
*/
public static function getDefaultVerticalAlign()
{
return static::$defaultVerticalAlign;
}
/**
* Get the vertical alignment
*
@ -359,6 +404,17 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable
return $this->verticalAlign;
}
/**
* Set the default vertical alignment
*
* @api
* @param string $defaultVerticalAlignment Default vertical alignment
*/
public static function setDefaultVerticalAlign($defaultVerticalAlignment)
{
static::$defaultVerticalAlign = (string)$defaultVerticalAlignment;
}
/**
* Set the vertical alignment
*
@ -400,6 +456,17 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable
->setVerticalAlign($verticalAlign);
}
/**
* Center the default alignment
*
* @api
*/
public static function centerDefaultAlign()
{
static::$defaultHorizontalAlign = static::CENTER;
static::$defaultVerticalAlign = static::CENTER2;
}
/**
* Center the alignment
*
@ -424,6 +491,17 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable
return $this->clearAlign();
}
/**
* Clear the default alignment
*
* @api
*/
public static function clearDefaultAlign()
{
static::$defaultHorizontalAlign = null;
static::$defaultVerticalAlign = null;
}
/**
* Clear the alignment
*

View File

@ -3,8 +3,8 @@
namespace FML\Controls;
use FML\Script\Features\GraphCurve;
// TODO: check CoordsMin & CoordsMax properties of CMlGraph
use FML\Script\Features\GraphSettings;
use FML\Script\Features\ScriptFeature;
/**
* Graph Control
@ -17,11 +17,42 @@ use FML\Script\Features\GraphCurve;
class Graph extends Control
{
/**
* @var GraphSettings $graphSettings Graph settings
*/
protected $graphSettings = null;
/**
* @var GraphCurve[] $curves Curves
*/
protected $curves = array();
/**
* Get the graph settings
*
* @api
* @return GraphSettings
*/
public function getSettings()
{
if (!$this->graphSettings) {
$this->createSettings();
}
return $this->graphSettings;
}
/**
* Create new graph settings
*
* @return GraphSettings
*/
protected function createSettings()
{
$this->graphSettings = new GraphSettings($this);
$this->addScriptFeature($this->graphSettings);
return $this->graphSettings;
}
/**
* Get curves
*

View File

@ -65,7 +65,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, MultiL
/**
* @var int $actionKey Action key
*/
protected $actionKey = -1;
protected $actionKey = null;
/**
* @var string $url Url
@ -651,7 +651,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, MultiL
if ($this->action) {
$domElement->setAttribute("action", $this->action);
}
if ($this->actionKey >= 0) {
if ($this->actionKey) {
$domElement->setAttribute("actionkey", $this->actionKey);
}
if ($this->url) {

View File

@ -98,7 +98,7 @@ class Quad extends Control implements Actionable, BackgroundColorable, BgColorab
/**
* @var int $actionKey Action key
*/
protected $actionKey = -1;
protected $actionKey = null;
/**
* @var string $url Link url
@ -676,6 +676,8 @@ class Quad extends Control implements Actionable, BackgroundColorable, BgColorab
* @api
* @param CheckBoxDesign $checkBoxDesign CheckBox Design
* @return static
* @deprecated Use CheckBoxDesign::applyToQuad()
* @see CheckBoxDesign::applyToQuad()
*/
public function applyCheckBoxDesign(CheckBoxDesign $checkBoxDesign)
{

View File

@ -20,7 +20,6 @@ class Quad_Icons128x32_1 extends Quad
const STYLE = 'Icons128x32_1';
const SUBSTYLE_ArrowUp = 'ArrowUp';
const SUBSTYLE_BgQuadWhite = 'BgQuadWhite';
// TODO: validate existence of 'close'
const SUBSTYLE_Close = 'Close';
const SUBSTYLE_Empty = 'Empty';
const SUBSTYLE_ManiaLinkHome = 'ManiaLinkHome';

View File

@ -53,7 +53,7 @@ class CustomUI
protected $scoretableVisible = null;
/**
* Create a new CustomUI
* Create a new Custom UI
*
* @api
* @return static
@ -256,7 +256,7 @@ class CustomUI
}
/**
* Render the CustomUI standalone
* Render the Custom UI standalone
*
* @return \DOMDocument
*/
@ -272,9 +272,9 @@ class CustomUI
}
/**
* Render the CustomUI
* Render the Custom UI
*
* @param \DOMDocument $domDocument DOMDocument for which the CustomUI should be rendered
* @param \DOMDocument $domDocument DOMDocument for which the Custom UI should be rendered
* @return \DOMElement
*/
public function render(\DOMDocument $domDocument)
@ -307,7 +307,7 @@ class CustomUI
}
/**
* Get associative array of all CustomUI settings
* Get associative array of all Custom UI settings
*
* @return array
*/

View File

@ -69,6 +69,30 @@ abstract class Builder
return static::escapeText($element->getId(), false);
}
/**
* Get the 'Text' string representation of the given value
*
* @api
* @param string $value String value to convert to a ManiaScript 'Text'
* @return string
*/
public static function getText($value)
{
return '"' . (string)$value . '"';
}
/**
* Get the 'Integer' string representation of the given value
*
* @api
* @param int $value Int value to convert to a ManiaScript 'Integer'
* @return string
*/
public static function getInteger($value)
{
return (string)(int)$value;
}
/**
* Get the 'Real' string representation of the given value
*
@ -146,7 +170,7 @@ abstract class Builder
* @param bool $associative (optional) Whether the array should be associative
* @return string
*/
public static function getArray(array $array, $associative = false)
public static function getArray(array $array, $associative = true)
{
$arrayText = "[";
$index = 0;
@ -180,6 +204,9 @@ abstract class Builder
if (is_bool($value)) {
return static::getBoolean($value);
}
if (is_array($value)) {
return static::getArray($value);
}
return $value;
}

View File

@ -45,7 +45,7 @@ class GraphCurve extends ScriptFeature
/**
* @var float $width Width
*/
protected $width = -1.;
protected $width = null;
/**
* Construct a new Graph Curve
@ -277,24 +277,24 @@ if (Graph != Null) {
foreach ($this->points as $point) {
$pointVec2 = Builder::getVec2($point);
$scriptText .= "
GraphCurve.Points.add({$pointVec2});";
GraphCurve.Points.add({$pointVec2});";
}
if ($this->sortPoints) {
$scriptText .= "
GraphCurve.SortPoints();";
GraphCurve.SortPoints();";
}
if ($this->color) {
$colorVec3 = Builder::getVec3($this->color);
$scriptText .= "
GraphCurve.Color = {$colorVec3};";
GraphCurve.Color = {$colorVec3};";
}
if ($this->style) {
$scriptText .= "
GraphCurve.Style = {$this->style};";
GraphCurve.Style = {$this->style};";
}
if ($this->width > 0) {
if ($this->width) {
$scriptText .= "
GraphCurve.Width = {$this->width};";
GraphCurve.Width = {$this->width};";
}
return $scriptText . "
}";

View File

@ -25,10 +25,38 @@ abstract class ScriptFeature
$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);
if ($object instanceof ScriptFeature) {
$scriptFeatures = static::addScriptFeature($scriptFeatures, $object);
} else if ($object instanceof ScriptFeatureable) {
$scriptFeatures = static::addScriptFeature($scriptFeatures, $object->getScriptFeatures());
} else if (is_array($object)) {
foreach ($object as $subObject) {
$scriptFeatures = static::addScriptFeature($scriptFeatures, static::collect($subObject));
}
}
}
return $scriptFeatures;
}
/**
* Add one or more Script Features to an Array of Features if they are not already contained
*
* @param array $scriptFeatures
* @param ScriptFeature||ScriptFeature[] $newScriptFeatures
* @return array
*/
public static function addScriptFeature(array $scriptFeatures, $newScriptFeatures)
{
if (!$newScriptFeatures) {
return $scriptFeatures;
}
if ($newScriptFeatures instanceof ScriptFeature) {
if (!in_array($newScriptFeatures, $scriptFeatures, true)) {
array_push($scriptFeatures, $newScriptFeatures);
}
} else if (is_array($newScriptFeatures)) {
foreach ($newScriptFeatures as $newScriptFeature) {
$scriptFeatures = static::addScriptFeature($scriptFeatures, $newScriptFeature);
}
}
return $scriptFeatures;

View File

@ -219,7 +219,7 @@ class ValuePickerFeature extends ScriptFeature
{
return "
Void " . self::FUNCTION_UPDATE_PICKER_VALUE . "(CMlLabel _Label) {
declare " . self::VAR_PICKER_VALUES . " as Values for _Label = Text[];
declare " . self::VAR_PICKER_VALUES . " as Values for _Label = Text[Integer];
declare NewValueIndex = -1;
if (Values.exists(_Label.Value)) {
declare ValueIndex = Values.keyof(_Label.Value);
@ -264,11 +264,11 @@ Void " . self::FUNCTION_UPDATE_PICKER_VALUE . "(CMlLabel _Label) {
return "
declare Label_Picker <=> (Page.GetFirstChild(\"{$labelId}\") as CMlLabel);
declare Text[] " . self::VAR_PICKER_VALUES . " as Values for Label_Picker;
declare " . self::VAR_PICKER_VALUES . " as Values for Label_Picker = Text[Integer];
Values = {$values};
declare Text " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for Label_Picker;
declare " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for Label_Picker = \"\";
Default = {$default};
declare Text " . self::VAR_PICKER_ENTRY_ID . " as EntryId for Label_Picker;
declare " . self::VAR_PICKER_ENTRY_ID . " as EntryId for Label_Picker = \"\";
EntryId = \"{$entryId}\";
" . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker);
";

View File

@ -265,14 +265,14 @@ class Script
*/
protected function getHeaderComment()
{
$headerComment = '/****************************************************
$headerComment = '/**************************************************
* FancyManiaLinks';
if (defined('FML_VERSION')) {
$headerComment .= ' v' . FML_VERSION;
}
$headerComment .= ' by steeffeen *
* http://github.com/steeffeen/FancyManiaLinks *
****************************************************/
**************************************************/
';
return $headerComment;
@ -349,6 +349,7 @@ main() {
}
case CMlEvent::Type::MouseClick: {
+++' . ScriptLabel::MOUSECLICK . '+++
+++' . ScriptLabel::MOUSECLICK2 . '+++
}
case CMlEvent::Type::MouseOut: {
+++' . ScriptLabel::MOUSEOUT . '+++

View File

@ -21,6 +21,7 @@ class ScriptLabel
const ENTRYSUBMIT = 'FML_EntrySubmit';
const KEYPRESS = 'FML_KeyPress';
const MOUSECLICK = 'FML_MouseClick';
const MOUSECLICK2 = 'FML_MouseClick2';
const MOUSEOUT = 'FML_MouseOut';
const MOUSEOVER = 'FML_MouseOver';