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

@ -17,10 +17,9 @@ class Quad_Icons128x32_1 extends Quad
/* /*
* Constants * Constants
*/ */
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

@ -53,7 +53,7 @@ class CustomUI
protected $scoretableVisible = null; protected $scoretableVisible = null;
/** /**
* Create a new CustomUI * Create a new Custom UI
* *
* @api * @api
* @return static * @return static
@ -256,7 +256,7 @@ class CustomUI
} }
/** /**
* Render the CustomUI standalone * Render the Custom UI standalone
* *
* @return \DOMDocument * @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 * @return \DOMElement
*/ */
public function render(\DOMDocument $domDocument) 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 * @return array
*/ */

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
@ -275,26 +275,26 @@ if (Graph != Null) {
declare GraphCurve <=> Graph.AddCurve(); declare GraphCurve <=> Graph.AddCurve();
"; ";
foreach ($this->points as $point) { foreach ($this->points as $point) {
$pointVec2 = Builder::getVec2($point); $pointVec2 = Builder::getVec2($point);
$scriptText .= " $scriptText .= "
GraphCurve.Points.add({$pointVec2});"; GraphCurve.Points.add({$pointVec2});";
} }
if ($this->sortPoints) { if ($this->sortPoints) {
$scriptText .= " $scriptText .= "
GraphCurve.SortPoints();"; GraphCurve.SortPoints();";
} }
if ($this->color) { if ($this->color) {
$colorVec3 = Builder::getVec3($this->color); $colorVec3 = Builder::getVec3($this->color);
$scriptText .= " $scriptText .= "
GraphCurve.Color = {$colorVec3};"; GraphCurve.Color = {$colorVec3};";
} }
if ($this->style) { if ($this->style) {
$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};";
} }
return $scriptText . " return $scriptText . "
}"; }";

View File

@ -19,409 +19,409 @@ use FML\Script\ScriptLabel;
class Paging extends ScriptFeature class Paging extends ScriptFeature
{ {
/* /*
* Constants * Constants
*/ */
const VAR_CURRENT_PAGE = "FML_Paging_CurrentPage"; const VAR_CURRENT_PAGE = "FML_Paging_CurrentPage";
const FUNCTION_UPDATE_CURRENT_PAGE = "FML_UpdateCurrentPage"; const FUNCTION_UPDATE_CURRENT_PAGE = "FML_UpdateCurrentPage";
/** /**
* @var Label $label Page number Label * @var Label $label Page number Label
*/ */
protected $label = null; protected $label = null;
/** /**
* @var PagingPage[] $pages Pages * @var PagingPage[] $pages Pages
*/ */
protected $pages = array(); protected $pages = array();
/** /**
* @var PagingButton[] $buttons Paging Buttons * @var PagingButton[] $buttons Paging Buttons
*/ */
protected $buttons = array(); protected $buttons = array();
/** /**
* @var int $startPageNumber Start Page number * @var int $startPageNumber Start Page number
*/ */
protected $startPageNumber = null; protected $startPageNumber = null;
/** /**
* @var int $customMaxPageNumber Custom maximum page number * @var int $customMaxPageNumber Custom maximum page number
*/ */
protected $customMaxPageNumber = null; protected $customMaxPageNumber = null;
/** /**
* @var string $previousChunkAction Previous chunk action name * @var string $previousChunkAction Previous chunk action name
*/ */
protected $previousChunkAction = null; protected $previousChunkAction = null;
/** /**
* @var string $nextChunkAction Next chunk action name * @var string $nextChunkAction Next chunk action name
*/ */
protected $nextChunkAction = null; protected $nextChunkAction = null;
/** /**
* @var bool $chunkActionAppendsPageNumber Chunk action appended with Page number * @var bool $chunkActionAppendsPageNumber Chunk action appended with Page number
*/ */
protected $chunkActionAppendsPageNumber = null; protected $chunkActionAppendsPageNumber = null;
/** /**
* Construct a new Paging * Construct a new Paging
* *
* @api * @api
* @param Label $label (optional) Page number Label * @param Label $label (optional) Page number Label
* @param PagingPage[] $pages (optional) Pages * @param PagingPage[] $pages (optional) Pages
* @param PagingButton[] $buttons (optional) Pageing Buttons * @param PagingButton[] $buttons (optional) Pageing Buttons
*/ */
public function __construct(Label $label = null, array $pages = null, array $buttons = null) public function __construct(Label $label = null, array $pages = null, array $buttons = null)
{ {
if ($label) { if ($label) {
$this->setLabel($label); $this->setLabel($label);
} }
if ($pages) { if ($pages) {
$this->setPages($pages); $this->setPages($pages);
} }
if ($buttons) { if ($buttons) {
$this->setButtons($buttons); $this->setButtons($buttons);
} }
} }
/** /**
* Get the Label showing the Page number * Get the Label showing the Page number
* *
* @api * @api
* @return Label * @return Label
*/ */
public function getLabel() public function getLabel()
{ {
return $this->label; return $this->label;
} }
/** /**
* Set the Label showing the Page number * Set the Label showing the Page number
* *
* @api * @api
* @param Label $label Page number Label * @param Label $label Page number Label
* @return static * @return static
*/ */
public function setLabel(Label $label) public function setLabel(Label $label)
{ {
$label->checkId(); $label->checkId();
$this->label = $label; $this->label = $label;
return $this; return $this;
} }
/** /**
* Get the Pages * Get the Pages
* *
* @api * @api
* @return PagingPage[] * @return PagingPage[]
*/ */
public function getPages() public function getPages()
{ {
return $this->pages; return $this->pages;
} }
/** /**
* Add a new Page Control * Add a new Page Control
* *
* @api * @api
* @param Control $pageControl Page Control * @param Control $pageControl Page Control
* @param string $pageNumber (optional) Page number * @param string $pageNumber (optional) Page number
* @return static * @return static
*/ */
public function addPageControl(Control $pageControl, $pageNumber = null) public function addPageControl(Control $pageControl, $pageNumber = null)
{ {
if ($pageNumber === null) { if ($pageNumber === null) {
$pageNumber = count($this->pages) + 1; $pageNumber = count($this->pages) + 1;
} }
$page = new PagingPage($pageControl, $pageNumber); $page = new PagingPage($pageControl, $pageNumber);
return $this->addPage($page); return $this->addPage($page);
} }
/** /**
* Add a new Page * Add a new Page
* *
* @api * @api
* @param PagingPage $page Page * @param PagingPage $page Page
* @return static * @return static
*/ */
public function addPage(PagingPage $page) public function addPage(PagingPage $page)
{ {
if (!in_array($page, $this->pages, true)) { if (!in_array($page, $this->pages, true)) {
array_push($this->pages, $page); array_push($this->pages, $page);
} }
return $this; return $this;
} }
/** /**
* Add new Pages * Add new Pages
* *
* @api * @api
* @param PagingPage[] $pages Pages * @param PagingPage[] $pages Pages
* @return static * @return static
*/ */
public function setPages(array $pages) public function setPages(array $pages)
{ {
$this->pages = array(); $this->pages = array();
foreach ($pages as $page) { foreach ($pages as $page) {
$this->addPage($page); $this->addPage($page);
} }
return $this; return $this;
} }
/** /**
* Get the Buttons * Get the Buttons
* *
* @api * @api
* @return PagingButton[] * @return PagingButton[]
*/ */
public function getButtons() public function getButtons()
{ {
return $this->buttons; return $this->buttons;
} }
/** /**
* Add a new Button Control to browse through the Pages * Add a new Button Control to browse through the Pages
* *
* @api * @api
* @param Control $buttonControl Button used for browsing * @param Control $buttonControl Button used for browsing
* @param int $browseAction (optional) Number of browsed Pages per click * @param int $browseAction (optional) Number of browsed Pages per click
* @return static * @return static
*/ */
public function addButtonControl(Control $buttonControl, $browseAction = null) public function addButtonControl(Control $buttonControl, $browseAction = null)
{ {
if ($browseAction === null) { if ($browseAction === null) {
$buttonCount = count($this->buttons); $buttonCount = count($this->buttons);
if ($buttonCount % 2 === 0) { if ($buttonCount % 2 === 0) {
$browseAction = $buttonCount / 2 + 1; $browseAction = $buttonCount / 2 + 1;
} else { } else {
$browseAction = $buttonCount / -2 - 1; $browseAction = $buttonCount / -2 - 1;
} }
} }
$button = new PagingButton($buttonControl, $browseAction); $button = new PagingButton($buttonControl, $browseAction);
return $this->addButton($button); return $this->addButton($button);
} }
/** /**
* Add a new Button to browse through Pages * Add a new Button to browse through Pages
* *
* @api * @api
* @param PagingButton $button Paging Button * @param PagingButton $button Paging Button
* @return static * @return static
*/ */
public function addButton(PagingButton $button) public function addButton(PagingButton $button)
{ {
if (!in_array($button, $this->buttons, true)) { if (!in_array($button, $this->buttons, true)) {
array_push($this->buttons, $button); array_push($this->buttons, $button);
} }
return $this; return $this;
} }
/** /**
* Set the Paging Buttons * Set the Paging Buttons
* *
* @api * @api
* @param PagingButton[] $buttons Paging Buttons * @param PagingButton[] $buttons Paging Buttons
* @return static * @return static
*/ */
public function setButtons(array $buttons) public function setButtons(array $buttons)
{ {
$this->buttons = array(); $this->buttons = array();
foreach ($buttons as $button) { foreach ($buttons as $button) {
$this->addButton($button); $this->addButton($button);
} }
return $this; return $this;
} }
/** /**
* Get the start Page number * Get the start Page number
* *
* @api * @api
* @return int * @return int
*/ */
public function getStartPageNumber() public function getStartPageNumber()
{ {
return $this->startPageNumber; return $this->startPageNumber;
} }
/** /**
* Set the start Page number * Set the start Page number
* *
* @api * @api
* @param int $startPageNumber Page number to start with * @param int $startPageNumber Page number to start with
* @return static * @return static
*/ */
public function setStartPageNumber($startPageNumber) public function setStartPageNumber($startPageNumber)
{ {
$this->startPageNumber = (int)$startPageNumber; $this->startPageNumber = (int)$startPageNumber;
return $this; return $this;
} }
/** /**
* Get a custom maximum Page number for using chunks * Get a custom maximum Page number for using chunks
* *
* @api * @api
* @return int * @return int
*/ */
public function getCustomMaxPageNumber() public function getCustomMaxPageNumber()
{ {
return $this->customMaxPageNumber; return $this->customMaxPageNumber;
} }
/** /**
* Set a custom maximum Page number for using chunks * Set a custom maximum Page number for using chunks
* *
* @api * @api
* @param int $maxPageNumber Custom maximum Page number * @param int $maxPageNumber Custom maximum Page number
* @return static * @return static
*/ */
public function setCustomMaxPageNumber($maxPageNumber) public function setCustomMaxPageNumber($maxPageNumber)
{ {
$this->customMaxPageNumber = (int)$maxPageNumber; $this->customMaxPageNumber = (int)$maxPageNumber;
return $this; return $this;
} }
/** /**
* Get the action triggered when the previous chunk is needed * Get the action triggered when the previous chunk is needed
* *
* @api * @api
* @return string * @return string
*/ */
public function getPreviousChunkAction() public function getPreviousChunkAction()
{ {
return $this->previousChunkAction; return $this->previousChunkAction;
} }
/** /**
* Set the action triggered when the previous chunk is needed * Set the action triggered when the previous chunk is needed
* *
* @api * @api
* @param string $previousChunkAction Triggered action * @param string $previousChunkAction Triggered action
* @return static * @return static
*/ */
public function setPreviousChunkAction($previousChunkAction) public function setPreviousChunkAction($previousChunkAction)
{ {
$this->previousChunkAction = (string)$previousChunkAction; $this->previousChunkAction = (string)$previousChunkAction;
return $this; return $this;
} }
/** /**
* Get the action triggered when the next chunk is needed * Get the action triggered when the next chunk is needed
* *
* @api * @api
* @return string * @return string
*/ */
public function getNextChunkAction() public function getNextChunkAction()
{ {
return $this->nextChunkAction; return $this->nextChunkAction;
} }
/** /**
* Set the action triggered when the next chunk is needed * Set the action triggered when the next chunk is needed
* *
* @api * @api
* @param string $nextChunkAction Triggered action * @param string $nextChunkAction Triggered action
* @return static * @return static
*/ */
public function setNextChunkAction($nextChunkAction) public function setNextChunkAction($nextChunkAction)
{ {
$this->nextChunkAction = (string)$nextChunkAction; $this->nextChunkAction = (string)$nextChunkAction;
return $this; return $this;
} }
/** /**
* Set the actions triggered when another chunk is needed * Set the actions triggered when another chunk is needed
* *
* @api * @api
* @param string $chunkAction Triggered action * @param string $chunkAction Triggered action
* @return static * @return static
*/ */
public function setChunkActions($chunkAction) public function setChunkActions($chunkAction)
{ {
return $this->setNextChunkAction($chunkAction) return $this->setNextChunkAction($chunkAction)
->setPreviousChunkAction($chunkAction); ->setPreviousChunkAction($chunkAction);
} }
/** /**
* Get if the chunk action should append the needed Page number * Get if the chunk action should append the needed Page number
* *
* @api * @api
* @return bool * @return bool
*/ */
public function getChunkActionAppendsPageNumber() public function getChunkActionAppendsPageNumber()
{ {
return $this->chunkActionAppendsPageNumber; return $this->chunkActionAppendsPageNumber;
} }
/** /**
* Set if the chunk action should append the needed Page number * Set if the chunk action should append the needed Page number
* *
* @api * @api
* @param bool $appendPageNumber Append the needed Page number * @param bool $appendPageNumber Append the needed Page number
* @return static * @return static
*/ */
public function setChunkActionAppendsPageNumber($appendPageNumber) public function setChunkActionAppendsPageNumber($appendPageNumber)
{ {
$this->chunkActionAppendsPageNumber = (bool)$appendPageNumber; $this->chunkActionAppendsPageNumber = (bool)$appendPageNumber;
return $this; return $this;
} }
/** /**
* @see ScriptFeature::prepare() * @see ScriptFeature::prepare()
*/ */
public function prepare(Script $script) public function prepare(Script $script)
{ {
if (empty($this->pages)) { if (empty($this->pages)) {
return $this; return $this;
} }
$script->setScriptInclude(ScriptInclude::TEXTLIB); $script->setScriptInclude(ScriptInclude::TEXTLIB);
$currentPageVariable = self::VAR_CURRENT_PAGE; $currentPageVariable = self::VAR_CURRENT_PAGE;
$updatePageFunction = self::FUNCTION_UPDATE_CURRENT_PAGE; $updatePageFunction = self::FUNCTION_UPDATE_CURRENT_PAGE;
$minPageNumber = 1; $minPageNumber = 1;
$startPageNumber = (is_int($this->startPageNumber) ? $this->startPageNumber : $minPageNumber); $startPageNumber = (is_int($this->startPageNumber) ? $this->startPageNumber : $minPageNumber);
$maxPage = $this->getMaxPage(); $maxPage = $this->getMaxPage();
$maxPageNumber = $this->customMaxPageNumber; $maxPageNumber = $this->customMaxPageNumber;
if (!is_int($maxPageNumber)) { if (!is_int($maxPageNumber)) {
$maxPageNumber = $maxPage->getPageNumber(); $maxPageNumber = $maxPage->getPageNumber();
} }
$pagingId = $maxPage->getControl() $pagingId = $maxPage->getControl()
->getId(true, true); ->getId(true, true);
$pagingId = Builder::escapeText($maxPage->getControl() $pagingId = Builder::escapeText($maxPage->getControl()
->getId()); ->getId());
$pageLabelId = Builder::EMPTY_STRING; $pageLabelId = Builder::EMPTY_STRING;
if ($this->label) { if ($this->label) {
$pageLabelId = Builder::escapeText($this->label->getId()); $pageLabelId = Builder::escapeText($this->label->getId());
} }
$pagesArrayText = $this->getPagesArrayText(); $pagesArrayText = $this->getPagesArrayText();
$pageButtonsArrayText = $this->getPageButtonsArrayText(); $pageButtonsArrayText = $this->getPageButtonsArrayText();
$previousChunkAction = Builder::escapeText($this->previousChunkAction); $previousChunkAction = Builder::escapeText($this->previousChunkAction);
$nextChunkAction = Builder::escapeText($this->nextChunkAction); $nextChunkAction = Builder::escapeText($this->nextChunkAction);
$chunkActionAppendsPageNumber = Builder::getBoolean($this->chunkActionAppendsPageNumber); $chunkActionAppendsPageNumber = Builder::getBoolean($this->chunkActionAppendsPageNumber);
// Init // Init
$initScriptText = " $initScriptText = "
declare {$currentPageVariable} for This = Integer[Text]; declare {$currentPageVariable} for This = Integer[Text];
{$currentPageVariable}[{$pagingId}] = {$startPageNumber}; {$currentPageVariable}[{$pagingId}] = {$startPageNumber};
{$updatePageFunction}({$pagingId}, {$pageLabelId}, 0, {$minPageNumber}, {$maxPageNumber}, {$pagesArrayText}, {$previousChunkAction}, {$nextChunkAction}, {$chunkActionAppendsPageNumber});"; {$updatePageFunction}({$pagingId}, {$pageLabelId}, 0, {$minPageNumber}, {$maxPageNumber}, {$pagesArrayText}, {$previousChunkAction}, {$nextChunkAction}, {$chunkActionAppendsPageNumber});";
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $initScriptText, true); $script->appendGenericScriptLabel(ScriptLabel::ONINIT, $initScriptText, true);
// MouseClick // MouseClick
$clickScriptText = " $clickScriptText = "
declare PageButtons = {$pageButtonsArrayText}; declare PageButtons = {$pageButtonsArrayText};
if (PageButtons.existskey(Event.Control.ControlId)) { if (PageButtons.existskey(Event.Control.ControlId)) {
declare BrowseAction = PageButtons[Event.Control.ControlId]; declare BrowseAction = PageButtons[Event.Control.ControlId];
{$updatePageFunction}({$pagingId}, {$pageLabelId}, BrowseAction, {$minPageNumber}, {$maxPageNumber}, {$pagesArrayText}, {$previousChunkAction}, {$nextChunkAction}, {$chunkActionAppendsPageNumber}); {$updatePageFunction}({$pagingId}, {$pageLabelId}, BrowseAction, {$minPageNumber}, {$maxPageNumber}, {$pagesArrayText}, {$previousChunkAction}, {$nextChunkAction}, {$chunkActionAppendsPageNumber});
}"; }";
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $clickScriptText, true); $script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $clickScriptText, true);
// Update function // Update function
$functionText = " $functionText = "
Void {$updatePageFunction}(Text _PagingId, Text _PageLabelId, Integer _BrowseAction, Integer _MinPageNumber, Integer _MaxPageNumber, Text[Integer] _Pages, Text _PreviousChunkAction, Text _NextChunkAction, Boolean _ChunkActionAppendPageNumber) { Void {$updatePageFunction}(Text _PagingId, Text _PageLabelId, Integer _BrowseAction, Integer _MinPageNumber, Integer _MaxPageNumber, Text[Integer] _Pages, Text _PreviousChunkAction, Text _NextChunkAction, Boolean _ChunkActionAppendPageNumber) {
declare {$currentPageVariable} for This = Integer[Text]; declare {$currentPageVariable} for This = Integer[Text];
if (!{$currentPageVariable}.existskey(_PagingId)) return; if (!{$currentPageVariable}.existskey(_PagingId)) return;
@ -454,82 +454,82 @@ Void {$updatePageFunction}(Text _PagingId, Text _PageLabelId, Integer _BrowseAct
TriggerPageAction(ChunkAction); TriggerPageAction(ChunkAction);
} }
}"; }";
$script->addScriptFunction($updatePageFunction, $functionText); $script->addScriptFunction($updatePageFunction, $functionText);
return $this; return $this;
} }
/** /**
* Get the minimum Page * Get the minimum Page
* *
* @return PagingPage * @return PagingPage
*/ */
protected function getMinPage() protected function getMinPage()
{ {
$minPageNumber = null; $minPageNumber = null;
$minPage = null; $minPage = null;
foreach ($this->pages as $page) { foreach ($this->pages as $page) {
$pageNumber = $page->getPageNumber(); $pageNumber = $page->getPageNumber();
if ($minPageNumber === null || $pageNumber < $minPageNumber) { if ($minPageNumber === null || $pageNumber < $minPageNumber) {
$minPageNumber = $pageNumber; $minPageNumber = $pageNumber;
$minPage = $page; $minPage = $page;
} }
} }
return $minPage; return $minPage;
} }
/** /**
* Get the maximum Page * Get the maximum Page
* *
* @return PagingPage * @return PagingPage
*/ */
protected function getMaxPage() protected function getMaxPage()
{ {
$maxPageNumber = null; $maxPageNumber = null;
$maxPage = null; $maxPage = null;
foreach ($this->pages as $page) { foreach ($this->pages as $page) {
$pageNumber = $page->getPageNumber(); $pageNumber = $page->getPageNumber();
if ($maxPageNumber === null || $pageNumber > $maxPageNumber) { if ($maxPageNumber === null || $pageNumber > $maxPageNumber) {
$maxPageNumber = $pageNumber; $maxPageNumber = $pageNumber;
$maxPage = $page; $maxPage = $page;
} }
} }
return $maxPage; return $maxPage;
} }
/** /**
* Build the array text for the Pages * Build the array text for the Pages
* *
* @return string * @return string
*/ */
protected function getPagesArrayText() protected function getPagesArrayText()
{ {
if (empty($this->pages)) { if (empty($this->pages)) {
return Builder::getArray(array(0 => ''), true); return Builder::getArray(array(0 => ''), true);
} }
$pages = array(); $pages = array();
foreach ($this->pages as $page) { foreach ($this->pages as $page) {
$pages[$page->getPageNumber()] = $page->getControl() $pages[$page->getPageNumber()] = $page->getControl()
->getId(); ->getId();
} }
return Builder::getArray($pages, true); return Builder::getArray($pages, true);
} }
/** /**
* Build the array text for the Page Buttons * Build the array text for the Page Buttons
* *
* @return string * @return string
*/ */
protected function getPageButtonsArrayText() protected function getPageButtonsArrayText()
{ {
if (empty($this->buttons)) { if (empty($this->buttons)) {
return Builder::getArray(array('' => 0), true); return Builder::getArray(array('' => 0), true);
} }
$pageButtons = array(); $pageButtons = array();
foreach ($this->buttons as $pageButton) { foreach ($this->buttons as $pageButton) {
$pageButtons[$pageButton->getControl() $pageButtons[$pageButton->getControl()
->getId()] = $pageButton->getPagingCount(); ->getId()] = $pageButton->getPagingCount();
} }
return Builder::getArray($pageButtons, true); return Builder::getArray($pageButtons, true);
} }
} }

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';