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 * @return bool
*/ */
public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) { 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; $manialinkText = (string) $manialinkText;
if (!$manialinkText) { if (!$manialinkText) {

View File

@ -13,7 +13,6 @@ use FML\Types\ScriptFeatureable;
/** /**
* CheckBox Component * CheckBox Component
* *
* @uses Quad
* @author steeffeen <mail@steeffeen.com> * @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder * @copyright FancyManiaLinks Copyright © 2017 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
@ -74,6 +73,8 @@ class CheckBox implements Renderable, ScriptFeatureable
public function setName($name) public function setName($name)
{ {
$this->name = (string)$name; $this->name = (string)$name;
$this->getEntry()
->setName($this->name);
return $this; return $this;
} }
@ -221,6 +222,7 @@ class CheckBox implements Renderable, ScriptFeatureable
* *
* @param Entry $entry Hidden Entry * @param Entry $entry Hidden Entry
* @return static * @return static
* @deprecated
*/ */
public function setEntry(Entry $entry) public function setEntry(Entry $entry)
{ {
@ -236,9 +238,11 @@ class CheckBox implements Renderable, ScriptFeatureable
protected function createEntry() protected function createEntry()
{ {
$entry = new Entry(); $entry = new Entry();
$entry->setVisible(false) $entry->setVisible(false);
->setName($this->name); if ($this->name) {
$this->setEntry($entry); $entry->setName($this->name);
}
$this->feature->setEntry($entry);
return $entry; return $entry;
} }
@ -247,7 +251,7 @@ class CheckBox implements Renderable, ScriptFeatureable
*/ */
public function getScriptFeatures() 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 * ValuePicker Component
* *
* @uses Entry
* @author steeffeen <mail@steeffeen.com> * @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder * @copyright FancyManiaLinks Copyright © 2017 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

View File

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

View File

@ -3,8 +3,8 @@
namespace FML\Controls; namespace FML\Controls;
use FML\Script\Features\GraphCurve; use FML\Script\Features\GraphCurve;
use FML\Script\Features\GraphSettings;
// TODO: check CoordsMin & CoordsMax properties of CMlGraph use FML\Script\Features\ScriptFeature;
/** /**
* Graph Control * Graph Control
@ -17,11 +17,42 @@ use FML\Script\Features\GraphCurve;
class Graph extends Control class Graph extends Control
{ {
/**
* @var GraphSettings $graphSettings Graph settings
*/
protected $graphSettings = null;
/** /**
* @var GraphCurve[] $curves Curves * @var GraphCurve[] $curves Curves
*/ */
protected $curves = array(); 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 * Get curves
* *

View File

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

View File

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

View File

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

View File

@ -69,6 +69,30 @@ abstract class Builder
return static::escapeText($element->getId(), false); 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 * 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 * @param bool $associative (optional) Whether the array should be associative
* @return string * @return string
*/ */
public static function getArray(array $array, $associative = false) public static function getArray(array $array, $associative = true)
{ {
$arrayText = "["; $arrayText = "[";
$index = 0; $index = 0;
@ -180,6 +204,9 @@ abstract class Builder
if (is_bool($value)) { if (is_bool($value)) {
return static::getBoolean($value); return static::getBoolean($value);
} }
if (is_array($value)) {
return static::getArray($value);
}
return $value; return $value;
} }

View File

@ -45,7 +45,7 @@ class GraphCurve extends ScriptFeature
/** /**
* @var float $width Width * @var float $width Width
*/ */
protected $width = -1.; protected $width = null;
/** /**
* Construct a new Graph Curve * Construct a new Graph Curve
@ -292,7 +292,7 @@ GraphCurve.Color = {$colorVec3};";
$scriptText .= " $scriptText .= "
GraphCurve.Style = {$this->style};"; GraphCurve.Style = {$this->style};";
} }
if ($this->width > 0) { if ($this->width) {
$scriptText .= " $scriptText .= "
GraphCurve.Width = {$this->width};"; GraphCurve.Width = {$this->width};";
} }

View File

@ -25,10 +25,38 @@ abstract class ScriptFeature
$params = func_get_args(); $params = func_get_args();
$scriptFeatures = array(); $scriptFeatures = array();
foreach ($params as $object) { foreach ($params as $object) {
if ($object instanceof ScriptFeatureable) { if ($object instanceof ScriptFeature) {
$scriptFeatures = array_merge($scriptFeatures, $object->getScriptFeatures()); $scriptFeatures = static::addScriptFeature($scriptFeatures, $object);
} else if ($object instanceof ScriptFeature) { } else if ($object instanceof ScriptFeatureable) {
array_push($scriptFeatures, $object); $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; return $scriptFeatures;

View File

@ -219,7 +219,7 @@ class ValuePickerFeature extends ScriptFeature
{ {
return " return "
Void " . self::FUNCTION_UPDATE_PICKER_VALUE . "(CMlLabel _Label) { 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; declare NewValueIndex = -1;
if (Values.exists(_Label.Value)) { if (Values.exists(_Label.Value)) {
declare ValueIndex = Values.keyof(_Label.Value); declare ValueIndex = Values.keyof(_Label.Value);
@ -264,11 +264,11 @@ Void " . self::FUNCTION_UPDATE_PICKER_VALUE . "(CMlLabel _Label) {
return " return "
declare Label_Picker <=> (Page.GetFirstChild(\"{$labelId}\") as CMlLabel); 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}; 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}; 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}\"; EntryId = \"{$entryId}\";
" . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker); " . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker);
"; ";

View File

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

View File

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