Updated to ManiaLink v3
This commit is contained in:
@ -9,104 +9,159 @@ use FML\Script\ScriptLabel;
|
||||
use FML\Types\Scriptable;
|
||||
|
||||
/**
|
||||
* Script Feature for triggering a manialink page action
|
||||
* Script Feature for triggering a ManiaLink page action
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ActionTrigger extends ScriptFeature {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
protected $actionName = null;
|
||||
/** @var Control $control */
|
||||
protected $control = null;
|
||||
protected $labelName = null;
|
||||
class ActionTrigger extends ScriptFeature
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct a new Action Trigger Feature
|
||||
*
|
||||
* @param string $actionName (optional) Triggered action
|
||||
* @param Control $control (optional) Action Control
|
||||
* @param string $labelName (optional) Script Label name
|
||||
*/
|
||||
public function __construct($actionName = null, Control $control = null, $labelName = ScriptLabel::MOUSECLICK) {
|
||||
if ($actionName !== null) {
|
||||
$this->setActionName($actionName);
|
||||
}
|
||||
if ($control !== null) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
if ($labelName !== null) {
|
||||
$this->setLabelName($labelName);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @var string $actionName Triggered action
|
||||
*/
|
||||
protected $actionName = null;
|
||||
|
||||
/**
|
||||
* Set the action to trigger
|
||||
*
|
||||
* @param string $actionName
|
||||
* @return static
|
||||
*/
|
||||
public function setActionName($actionName) {
|
||||
$this->actionName = (string)$actionName;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var Control $control Action Control
|
||||
*/
|
||||
protected $control = null;
|
||||
|
||||
/**
|
||||
* Set the Control
|
||||
*
|
||||
* @param Control $control Action Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control) {
|
||||
$control->checkId();
|
||||
if ($control instanceof Scriptable) {
|
||||
$control->setScriptEvents(true);
|
||||
}
|
||||
$this->control = $control;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var string $labelName Script label name
|
||||
*/
|
||||
protected $labelName = null;
|
||||
|
||||
/**
|
||||
* Set the label name
|
||||
*
|
||||
* @param string $labelName Script Label name
|
||||
* @return static
|
||||
*/
|
||||
public function setLabelName($labelName) {
|
||||
$this->labelName = (string)$labelName;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new Action Trigger
|
||||
*
|
||||
* @api
|
||||
* @param string $actionName (optional) Triggered action
|
||||
* @param Control $control (optional) Action Control
|
||||
* @param string $labelName (optional) Script label name
|
||||
*/
|
||||
public function __construct($actionName = null, Control $control = null, $labelName = ScriptLabel::MOUSECLICK)
|
||||
{
|
||||
if ($actionName) {
|
||||
$this->setActionName($actionName);
|
||||
}
|
||||
if ($control) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
if ($labelName) {
|
||||
$this->setLabelName($labelName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Script\Features\ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script) {
|
||||
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the action to trigger
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getActionName()
|
||||
{
|
||||
return $this->actionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText() {
|
||||
$actionName = Builder::escapeText($this->actionName, true);
|
||||
if ($this->control) {
|
||||
// Control event
|
||||
$controlId = Builder::escapeText($this->control->getId(), true);
|
||||
$scriptText = "
|
||||
/**
|
||||
* Set the action to trigger
|
||||
*
|
||||
* @api
|
||||
* @param string $actionName Action name
|
||||
* @return static
|
||||
*/
|
||||
public function setActionName($actionName)
|
||||
{
|
||||
$this->actionName = (string)$actionName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Control that should trigger the action
|
||||
*
|
||||
* @api
|
||||
* @return Control
|
||||
*/
|
||||
public function getControl()
|
||||
{
|
||||
return $this->control;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Control that should trigger the action
|
||||
*
|
||||
* @api
|
||||
* @param Control $control Action Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control = null)
|
||||
{
|
||||
if ($control) {
|
||||
$control->checkId();
|
||||
if ($control instanceof Scriptable) {
|
||||
$control->setScriptEvents(true);
|
||||
}
|
||||
}
|
||||
$this->control = $control;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script label name
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getLabelName()
|
||||
{
|
||||
return $this->labelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the script label name
|
||||
*
|
||||
* @api
|
||||
* @param string $labelName Script Label name
|
||||
* @return static
|
||||
*/
|
||||
public function setLabelName($labelName)
|
||||
{
|
||||
$this->labelName = (string)$labelName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText()
|
||||
{
|
||||
$actionName = Builder::escapeText($this->actionName);
|
||||
if ($this->control) {
|
||||
// Control event
|
||||
$controlId = Builder::escapeText($this->control->getId());
|
||||
$scriptText = "
|
||||
if (Event.Control.ControlId == {$controlId}) {
|
||||
TriggerPageAction({$actionName});
|
||||
}";
|
||||
} else {
|
||||
// Other
|
||||
$scriptText = "
|
||||
} else {
|
||||
// Other
|
||||
$scriptText = "
|
||||
TriggerPageAction({$actionName});";
|
||||
}
|
||||
return $scriptText;
|
||||
}
|
||||
}
|
||||
return $scriptText;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace FML\Script\Features;
|
||||
|
||||
use FML\Components\CheckBoxDesign;
|
||||
use FML\Controls\Entry;
|
||||
use FML\Controls\Quad;
|
||||
use FML\Models\CheckBoxDesign;
|
||||
use FML\Script\Builder;
|
||||
use FML\Script\Script;
|
||||
use FML\Script\ScriptInclude;
|
||||
@ -14,145 +14,213 @@ use FML\Script\ScriptLabel;
|
||||
* Script Feature for creating a CheckBox behavior
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class CheckBoxFeature extends ScriptFeature {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const FUNCTION_UPDATE_QUAD_DESIGN = 'FML_UpdateQuadDesign';
|
||||
const VAR_CHECKBOX_ENABLED = 'FML_CheckBox_Enabled';
|
||||
const VAR_CHECKBOX_DESIGNS = 'FML_CheckBox_Designs';
|
||||
const VAR_CHECKBOX_ENTRY_ID = 'FML_CheckBox_EntryId';
|
||||
class CheckBoxFeature extends ScriptFeature
|
||||
{
|
||||
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
/** @var Quad $quad */
|
||||
protected $quad = null;
|
||||
/** @var Entry $entry */
|
||||
protected $entry = null;
|
||||
protected $default = null;
|
||||
/** @var CheckBoxDesign $enabledDesign */
|
||||
protected $enabledDesign = null;
|
||||
/** @var CheckBoxDesign $disabledDesign */
|
||||
protected $disabledDesign = null;
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const FUNCTION_UPDATE_QUAD_DESIGN = "FML_UpdateQuadDesign";
|
||||
const VAR_CHECKBOX_ENABLED = "FML_CheckBox_Enabled";
|
||||
const VAR_CHECKBOX_DESIGNS = "FML_CheckBox_Designs";
|
||||
const VAR_CHECKBOX_ENTRY_ID = "FML_CheckBox_EntryId";
|
||||
|
||||
/**
|
||||
* Construct a new CheckBox Feature
|
||||
*
|
||||
* @param Quad $quad (optional) CheckBox Quad
|
||||
* @param Entry $entry (optional) Hidden Entry
|
||||
* @param bool $default (optional) Default value
|
||||
*/
|
||||
public function __construct(Quad $quad = null, Entry $entry = null, $default = null) {
|
||||
if ($quad !== null) {
|
||||
$this->setQuad($quad);
|
||||
}
|
||||
if ($entry !== null) {
|
||||
$this->setEntry($entry);
|
||||
}
|
||||
if ($default !== null) {
|
||||
$this->setDefault($default);
|
||||
}
|
||||
$this->setEnabledDesign(CheckBoxDesign::defaultEnabledDesign());
|
||||
$this->setDisabledDesign(CheckBoxDesign::defaultDisabledDesign());
|
||||
}
|
||||
/**
|
||||
* @var Quad $quad CheckBox Quad
|
||||
*/
|
||||
protected $quad = null;
|
||||
|
||||
/**
|
||||
* Set the CheckBox Quad
|
||||
*
|
||||
* @param Quad $quad CheckBox Quad
|
||||
* @return static
|
||||
*/
|
||||
public function setQuad(Quad $quad) {
|
||||
$this->quad = $quad->checkId()->setScriptEvents(true);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var Entry $entry Hidden Entry for submitting the value
|
||||
*/
|
||||
protected $entry = null;
|
||||
|
||||
/**
|
||||
* Get the CheckBox Quad
|
||||
*
|
||||
* @return \FML\Controls\Quad
|
||||
*/
|
||||
public function getQuad() {
|
||||
return $this->quad;
|
||||
}
|
||||
/**
|
||||
* @var bool $default Default value
|
||||
*/
|
||||
protected $default = null;
|
||||
|
||||
/**
|
||||
* Set the CheckBox Entry
|
||||
*
|
||||
* @param Entry $entry CheckBox Entry
|
||||
* @return static
|
||||
*/
|
||||
public function setEntry(Entry $entry) {
|
||||
$this->entry = $entry->checkId();
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var CheckBoxDesign $enabledDesign Enabled Design
|
||||
*/
|
||||
protected $enabledDesign = null;
|
||||
|
||||
/**
|
||||
* Get the managed Entry
|
||||
*
|
||||
* @return \FML\Controls\Entry
|
||||
*/
|
||||
public function getEntry() {
|
||||
return $this->entry;
|
||||
}
|
||||
/**
|
||||
* @var CheckBoxDesign $disabledDesign Disabled Design
|
||||
*/
|
||||
protected $disabledDesign = null;
|
||||
|
||||
/**
|
||||
* Set the default value
|
||||
*
|
||||
* @param bool $default Default value
|
||||
* @return static
|
||||
*/
|
||||
public function setDefault($default) {
|
||||
$this->default = (bool)$default;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new CheckBox Feature
|
||||
*
|
||||
* @api
|
||||
* @param Quad $quad (optional) CheckBox Quad
|
||||
* @param Entry $entry (optional) Hidden Entry
|
||||
* @param bool $default (optional) Default value
|
||||
*/
|
||||
public function __construct(Quad $quad = null, Entry $entry = null, $default = null)
|
||||
{
|
||||
if ($quad) {
|
||||
$this->setQuad($quad);
|
||||
}
|
||||
if ($entry) {
|
||||
$this->setEntry($entry);
|
||||
}
|
||||
if ($default !== null) {
|
||||
$this->setDefault($default);
|
||||
}
|
||||
$this->setEnabledDesign(CheckBoxDesign::defaultDesign());
|
||||
$this->setDisabledDesign(CheckBoxDesign::defaultDesign());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the enabled Design
|
||||
*
|
||||
* @param CheckBoxDesign $checkBoxDesign Enabled CheckBox Design
|
||||
* @return static
|
||||
*/
|
||||
public function setEnabledDesign(CheckBoxDesign $checkBoxDesign) {
|
||||
$this->enabledDesign = $checkBoxDesign;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the CheckBox Quad
|
||||
*
|
||||
* @api
|
||||
* @return Quad
|
||||
*/
|
||||
public function getQuad()
|
||||
{
|
||||
return $this->quad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the disabled Design
|
||||
*
|
||||
* @param CheckBoxDesign $checkBoxDesign Disabled CheckBox Design
|
||||
* @return static
|
||||
*/
|
||||
public function setDisabledDesign(CheckBoxDesign $checkBoxDesign) {
|
||||
$this->disabledDesign = $checkBoxDesign;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Set the CheckBox Quad
|
||||
*
|
||||
* @api
|
||||
* @param Quad $quad CheckBox Quad
|
||||
* @return static
|
||||
*/
|
||||
public function setQuad(Quad $quad)
|
||||
{
|
||||
$quad->checkId();
|
||||
$quad->setScriptEvents(true);
|
||||
$this->quad = $quad;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Script\Features\ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script) {
|
||||
if ($this->getQuad()) {
|
||||
$script->setScriptInclude(ScriptInclude::TEXTLIB);
|
||||
$script->addScriptFunction(self::FUNCTION_UPDATE_QUAD_DESIGN, $this->buildUpdateQuadDesignFunction());
|
||||
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->buildInitScriptText(), true);
|
||||
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $this->buildClickScriptText());
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the hidden Entry
|
||||
*
|
||||
* @api
|
||||
* @return Entry
|
||||
*/
|
||||
public function getEntry()
|
||||
{
|
||||
return $this->entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the function text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildUpdateQuadDesignFunction() {
|
||||
return "
|
||||
/**
|
||||
* Set the hidden Entry
|
||||
*
|
||||
* @api
|
||||
* @param Entry $entry Hidden Entry
|
||||
* @return static
|
||||
*/
|
||||
public function setEntry(Entry $entry)
|
||||
{
|
||||
$entry->checkId();
|
||||
$this->entry = $entry;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default value
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
return $this->default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default value
|
||||
*
|
||||
* @api
|
||||
* @param bool $default Default value
|
||||
* @return static
|
||||
*/
|
||||
public function setDefault($default)
|
||||
{
|
||||
$this->default = (bool)$default;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the enabled Design
|
||||
*
|
||||
* @api
|
||||
* @return CheckBoxDesign
|
||||
*/
|
||||
public function getEnabledDesign()
|
||||
{
|
||||
return $this->enabledDesign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the enabled Design
|
||||
*
|
||||
* @api
|
||||
* @param CheckBoxDesign $checkBoxDesign Enabled CheckBox Design
|
||||
* @return static
|
||||
*/
|
||||
public function setEnabledDesign(CheckBoxDesign $checkBoxDesign)
|
||||
{
|
||||
$this->enabledDesign = $checkBoxDesign;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the disabled Design
|
||||
*
|
||||
* @api
|
||||
* @return CheckBoxDesign
|
||||
*/
|
||||
public function getDisabledDesign()
|
||||
{
|
||||
return $this->disabledDesign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the disabled Design
|
||||
*
|
||||
* @api
|
||||
* @param CheckBoxDesign $checkBoxDesign Disabled CheckBox Design
|
||||
* @return static
|
||||
*/
|
||||
public function setDisabledDesign(CheckBoxDesign $checkBoxDesign)
|
||||
{
|
||||
$this->disabledDesign = $checkBoxDesign;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
if ($this->getQuad()) {
|
||||
$script->setScriptInclude(ScriptInclude::TEXTLIB);
|
||||
$script->addScriptFunction(self::FUNCTION_UPDATE_QUAD_DESIGN, $this->buildUpdateQuadDesignFunction());
|
||||
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->buildInitScriptText(), true);
|
||||
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $this->buildClickScriptText());
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the function text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildUpdateQuadDesignFunction()
|
||||
{
|
||||
return "
|
||||
Void " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(CMlQuad _Quad) {
|
||||
declare " . self::VAR_CHECKBOX_ENABLED . " as Enabled for _Quad = True;
|
||||
Enabled = !Enabled;
|
||||
@ -160,62 +228,69 @@ Void " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(CMlQuad _Quad) {
|
||||
declare " . self::VAR_CHECKBOX_DESIGNS . " as Designs for _Quad = Text[Boolean];
|
||||
declare Design = Designs[Enabled];
|
||||
declare DesignParts = TextLib::Split(\"|\", Design);
|
||||
if (DesignParts.count > 1) {
|
||||
if (DesignParts.count == 2) {
|
||||
_Quad.Style = DesignParts[0];
|
||||
_Quad.Substyle = DesignParts[1];
|
||||
} else {
|
||||
_Quad.ImageUrl = Design;
|
||||
}
|
||||
declare " . self::VAR_CHECKBOX_ENTRY_ID . " as EntryId for _Quad = " . Builder::EMPTY_STRING . ";
|
||||
if (EntryId != " . Builder::EMPTY_STRING . ") {
|
||||
declare Value = \"0\";
|
||||
if (Enabled) {
|
||||
Value = \"1\";
|
||||
}
|
||||
declare " . self::VAR_CHECKBOX_ENTRY_ID . " as EntryId for _Quad = \"\";
|
||||
if (EntryId != \"\") {
|
||||
declare Entry <=> (Page.GetFirstChild(EntryId) as CMlEntry);
|
||||
Entry.Value = Value;
|
||||
if (Entry != Null) {
|
||||
if (Enabled) {
|
||||
Entry.Value = \"1\";
|
||||
} else {
|
||||
Entry.Value = \"0\";
|
||||
}
|
||||
}
|
||||
}
|
||||
}";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the init script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildInitScriptText() {
|
||||
$quadId = $this->getQuad()->getId(true, true);
|
||||
$entryId = '""';
|
||||
if ($this->entry) {
|
||||
$entryId = $this->entry->getId(true, true);
|
||||
}
|
||||
$default = Builder::getBoolean($this->default);
|
||||
$enabledDesignString = $this->enabledDesign->getDesignString();
|
||||
$disabledDesignString = $this->disabledDesign->getDesignString();
|
||||
return "
|
||||
declare Quad_CheckBox <=> (Page.GetFirstChild({$quadId}) as CMlQuad);
|
||||
/**
|
||||
* Build the init script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildInitScriptText()
|
||||
{
|
||||
$quadId = Builder::getId($this->getQuad());
|
||||
$entryId = Builder::EMPTY_STRING;
|
||||
if ($this->entry) {
|
||||
$entryId = Builder::getId($this->getEntry());
|
||||
}
|
||||
|
||||
$default = Builder::getBoolean($this->default);
|
||||
$enabledDesignString = $this->enabledDesign->getDesignString();
|
||||
$disabledDesignString = $this->disabledDesign->getDesignString();
|
||||
|
||||
return "
|
||||
declare Quad_CheckBox <=> (Page.GetFirstChild(\"{$quadId}\") as CMlQuad);
|
||||
declare Text[Boolean] " . self::VAR_CHECKBOX_DESIGNS . " as Designs for Quad_CheckBox;
|
||||
Designs[True] = {$enabledDesignString};
|
||||
Designs[False] = {$disabledDesignString};
|
||||
Designs[True] = \"{$enabledDesignString}\";
|
||||
Designs[False] = \"{$disabledDesignString}\";
|
||||
declare Boolean " . self::VAR_CHECKBOX_ENABLED . " as Enabled for Quad_CheckBox;
|
||||
Enabled = !{$default};
|
||||
declare Text " . self::VAR_CHECKBOX_ENTRY_ID . " as EntryId for Quad_CheckBox;
|
||||
EntryId = {$entryId};
|
||||
EntryId = \"{$entryId}\";
|
||||
" . self::FUNCTION_UPDATE_QUAD_DESIGN . "(Quad_CheckBox);
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the script text for Quad clicks
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildClickScriptText() {
|
||||
$quadId = $this->getQuad()->getId(true, true);
|
||||
return "
|
||||
if (Event.ControlId == {$quadId}) {
|
||||
/**
|
||||
* Build the script text for Quad clicks
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildClickScriptText()
|
||||
{
|
||||
$quadId = Builder::getId($this->getQuad());
|
||||
return "
|
||||
if (Event.ControlId == \"{$quadId}\") {
|
||||
declare Quad_CheckBox <=> (Event.Control as CMlQuad);
|
||||
" . self::FUNCTION_UPDATE_QUAD_DESIGN . "(Quad_CheckBox);
|
||||
}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace FML\Script\Features;
|
||||
|
||||
use FML\Controls\Label;
|
||||
use FML\Script\Builder;
|
||||
use FML\Script\Script;
|
||||
use FML\Script\ScriptInclude;
|
||||
use FML\Script\ScriptLabel;
|
||||
@ -11,95 +12,149 @@ use FML\Script\ScriptLabel;
|
||||
* Script Feature showing the current time on a Label
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class Clock extends ScriptFeature {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
/** @var Label $label */
|
||||
protected $label = null;
|
||||
protected $showSeconds = null;
|
||||
protected $showFullDate = null;
|
||||
class Clock extends ScriptFeature
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct a new Clock Feature
|
||||
*
|
||||
* @param Label $label (optional) Clock Label
|
||||
* @param bool $showSeconds (optional) Whether the seconds should be shown
|
||||
* @param bool $showFullDate (optional) Whether the date should be shown
|
||||
*/
|
||||
public function __construct(Label $label = null, $showSeconds = true, $showFullDate = false) {
|
||||
if ($label !== null) {
|
||||
$this->setLabel($label);
|
||||
}
|
||||
$this->setShowSeconds($showSeconds);
|
||||
$this->setShowFullDate($showFullDate);
|
||||
}
|
||||
/**
|
||||
* @var Label $label Clock Label
|
||||
*/
|
||||
protected $label = null;
|
||||
|
||||
/**
|
||||
* Set the Label
|
||||
*
|
||||
* @param Label $label Clock Label
|
||||
* @return static
|
||||
*/
|
||||
public function setLabel(Label $label) {
|
||||
$this->label = $label->checkId();
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var bool $showSeconds Show the seconds
|
||||
*/
|
||||
protected $showSeconds = null;
|
||||
|
||||
/**
|
||||
* Set whether seconds should be shown
|
||||
*
|
||||
* @param bool $showSeconds Whether seconds should be shown
|
||||
* @return static
|
||||
*/
|
||||
public function setShowSeconds($showSeconds) {
|
||||
$this->showSeconds = (bool)$showSeconds;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var bool $showFullDate Show the date
|
||||
*/
|
||||
protected $showFullDate = null;
|
||||
|
||||
/**
|
||||
* Set whether the full date should be shown
|
||||
*
|
||||
* @param bool $showFullDate Whether the full date should be shown
|
||||
* @return static
|
||||
*/
|
||||
public function setShowFullDate($showFullDate) {
|
||||
$this->showFullDate = (bool)$showFullDate;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new Clock
|
||||
*
|
||||
* @api
|
||||
* @param Label $label (optional) Clock Label
|
||||
* @param bool $showSeconds (optional) Show the seconds
|
||||
* @param bool $showFullDate (optional) Show the date
|
||||
*/
|
||||
public function __construct(Label $label = null, $showSeconds = true, $showFullDate = false)
|
||||
{
|
||||
if ($label) {
|
||||
$this->setLabel($label);
|
||||
}
|
||||
$this->setShowSeconds($showSeconds)
|
||||
->setShowFullDate($showFullDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Script\Features\ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script) {
|
||||
$script->setScriptInclude(ScriptInclude::TEXTLIB);
|
||||
$script->appendGenericScriptLabel(ScriptLabel::TICK, $this->getScriptText(), true);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the Label
|
||||
*
|
||||
* @api
|
||||
* @return Label
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText() {
|
||||
$controlId = $this->label->getId(true, true);
|
||||
$scriptText = "
|
||||
/**
|
||||
* Set the Label
|
||||
*
|
||||
* @api
|
||||
* @param Label $label Clock Label
|
||||
* @return static
|
||||
*/
|
||||
public function setLabel(Label $label)
|
||||
{
|
||||
$label->checkId();
|
||||
$this->label = $label;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if seconds should be shown
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function getShowSeconds()
|
||||
{
|
||||
return $this->showSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if seconds should be shown
|
||||
*
|
||||
* @api
|
||||
* @param bool $showSeconds If seconds should be shown
|
||||
* @return static
|
||||
*/
|
||||
public function setShowSeconds($showSeconds)
|
||||
{
|
||||
$this->showSeconds = (bool)$showSeconds;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the full date should be shown
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function getShowFullDate()
|
||||
{
|
||||
return $this->showFullDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the full date should be shown
|
||||
*
|
||||
* @api
|
||||
* @param bool $showFullDate If the full date should be shown
|
||||
* @return static
|
||||
*/
|
||||
public function setShowFullDate($showFullDate)
|
||||
{
|
||||
$this->showFullDate = (bool)$showFullDate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$script->setScriptInclude(ScriptInclude::TEXTLIB)
|
||||
->appendGenericScriptLabel(ScriptLabel::TICK, $this->getScriptText(), true);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText()
|
||||
{
|
||||
$controlId = Builder::escapeText($this->label->getId());
|
||||
$scriptText = "
|
||||
declare ClockLabel <=> (Page.GetFirstChild({$controlId}) as CMlLabel);
|
||||
declare TimeText = CurrentLocalDateText;";
|
||||
if (!$this->showSeconds) {
|
||||
$scriptText .= "
|
||||
if (!$this->showSeconds) {
|
||||
$scriptText .= "
|
||||
TimeText = TextLib::SubText(TimeText, 0, 16);";
|
||||
}
|
||||
if (!$this->showFullDate) {
|
||||
$scriptText .= "
|
||||
}
|
||||
if (!$this->showFullDate) {
|
||||
$scriptText .= "
|
||||
TimeText = TextLib::SubText(TimeText, 11, 9);";
|
||||
}
|
||||
$scriptText .= "
|
||||
}
|
||||
$scriptText .= "
|
||||
ClockLabel.Value = TimeText;";
|
||||
return $scriptText;
|
||||
}
|
||||
return $scriptText;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace FML\Script\Features;
|
||||
|
||||
use FML\Controls\Control;
|
||||
use FML\Script\Builder;
|
||||
use FML\Script\Script;
|
||||
use FML\Script\ScriptLabel;
|
||||
use FML\Types\Scriptable;
|
||||
@ -11,115 +12,179 @@ use FML\Types\Scriptable;
|
||||
* Script Feature for a Control related script
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ControlScript extends ScriptFeature {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
/** @var Control $control */
|
||||
protected $control = null;
|
||||
protected $labelName = null;
|
||||
protected $text = null;
|
||||
class ControlScript extends ScriptFeature
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct a new Control Script
|
||||
*
|
||||
* @param Control $control Event Control
|
||||
* @param string $text Script text
|
||||
* @param string $labelName (optional) Script Label name
|
||||
*/
|
||||
public function __construct(Control $control, $text, $labelName = ScriptLabel::MOUSECLICK) {
|
||||
$this->setControl($control);
|
||||
$this->setText($text);
|
||||
$this->setLabelName($labelName);
|
||||
}
|
||||
/**
|
||||
* @var Control $control Control
|
||||
*/
|
||||
protected $control = null;
|
||||
|
||||
/**
|
||||
* Set the Control
|
||||
*
|
||||
* @param Control $control Event Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control) {
|
||||
$this->control = $control->checkId();
|
||||
$this->updateScriptEvents();
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var string $labelName Script Label name
|
||||
*/
|
||||
protected $labelName = null;
|
||||
|
||||
/**
|
||||
* Set the script text
|
||||
*
|
||||
* @param string $text Script text
|
||||
* @return static
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = (string)$text;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var string $scriptText Script text
|
||||
*/
|
||||
protected $scriptText = null;
|
||||
|
||||
/**
|
||||
* Set the label name
|
||||
*
|
||||
* @param string $labelName Script Label name
|
||||
* @return static
|
||||
*/
|
||||
public function setLabelName($labelName) {
|
||||
$this->labelName = (string)$labelName;
|
||||
$this->updateScriptEvents();
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new Control Script
|
||||
*
|
||||
* @api
|
||||
* @param Control $control (optional) Control
|
||||
* @param string $scriptText (optional) Script text
|
||||
* @param string $labelName (optional) Script Label name
|
||||
*/
|
||||
public function __construct(Control $control = null, $scriptText = null, $labelName = ScriptLabel::MOUSECLICK)
|
||||
{
|
||||
if ($control) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
if ($scriptText) {
|
||||
$this->setScriptText($scriptText);
|
||||
}
|
||||
if ($labelName) {
|
||||
$this->setLabelName($labelName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable Script Events on the Control if needed
|
||||
*/
|
||||
protected function updateScriptEvents() {
|
||||
if (!$this->control || !ScriptLabel::isEventLabel($this->labelName)) {
|
||||
return;
|
||||
}
|
||||
if ($this->control instanceof Scriptable) {
|
||||
$this->control->setScriptEvents(true);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the Control
|
||||
*
|
||||
* @api
|
||||
* @return Control
|
||||
*/
|
||||
public function getControl()
|
||||
{
|
||||
return $this->control;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Script\Features\ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script) {
|
||||
$isolated = !ScriptLabel::isEventLabel($this->labelName);
|
||||
$script->appendGenericScriptLabel($this->labelName, $this->buildScriptText(), $isolated);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Set the Control
|
||||
*
|
||||
* @api
|
||||
* @param Control $control Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control)
|
||||
{
|
||||
$control->checkId();
|
||||
$this->control = $control;
|
||||
$this->updateScriptEvents();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getScriptText()
|
||||
{
|
||||
return $this->scriptText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the script text
|
||||
*
|
||||
* @api
|
||||
* @param string $scriptText Script text
|
||||
* @return static
|
||||
*/
|
||||
public function setScriptText($scriptText)
|
||||
{
|
||||
$this->scriptText = (string)$scriptText;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Script Label name
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getLabelName()
|
||||
{
|
||||
return $this->labelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Script Label name
|
||||
*
|
||||
* @api
|
||||
* @param string $labelName Script Label name
|
||||
* @return static
|
||||
*/
|
||||
public function setLabelName($labelName)
|
||||
{
|
||||
$this->labelName = (string)$labelName;
|
||||
$this->updateScriptEvents();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable Script Events on the Control if needed
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
protected function updateScriptEvents()
|
||||
{
|
||||
if (!$this->control || !ScriptLabel::isEventLabel($this->labelName)) {
|
||||
return $this;
|
||||
}
|
||||
if ($this->control instanceof Scriptable) {
|
||||
$this->control->setScriptEvents(true);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$isolated = !ScriptLabel::isEventLabel($this->labelName);
|
||||
$script->appendGenericScriptLabel($this->labelName, $this->buildScriptText(), $isolated);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the script text for the Control
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildScriptText()
|
||||
{
|
||||
$controlId = Builder::escapeText($this->control->getId());
|
||||
$scriptText = '';
|
||||
$closeBlock = false;
|
||||
if (ScriptLabel::isEventLabel($this->labelName)) {
|
||||
$scriptText .= "
|
||||
if (Event.ControlId == {$controlId}) {
|
||||
declare Control <=> Event.Control;";
|
||||
$closeBlock = true;
|
||||
} else {
|
||||
$scriptText .= "
|
||||
declare Control <=> Page.GetFirstChild({$controlId});";
|
||||
}
|
||||
$class = $this->control->getManiaScriptClass();
|
||||
$name = preg_replace('/^CMl/', '', $class, 1);
|
||||
$scriptText .= "
|
||||
declare {$name} <=> (Control as {$class});
|
||||
";
|
||||
$scriptText .= $this->scriptText . "
|
||||
";
|
||||
if ($closeBlock) {
|
||||
$scriptText .= "}";
|
||||
}
|
||||
return $scriptText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the script text for the Control
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildScriptText() {
|
||||
$controlId = $this->control->getId(true);
|
||||
$scriptText = '';
|
||||
$closeBlock = false;
|
||||
if (ScriptLabel::isEventLabel($this->labelName)) {
|
||||
$scriptText .= '
|
||||
if (Event.ControlId == "' . $controlId . '") {
|
||||
declare Control <=> Event.Control;';
|
||||
$closeBlock = true;
|
||||
} else {
|
||||
$scriptText .= '
|
||||
declare Control <=> Page.GetFirstChild("' . $controlId . '");';
|
||||
}
|
||||
$class = $this->control->getManiaScriptClass();
|
||||
$name = preg_replace('/^CMl/', '', $class, 1);
|
||||
$scriptText .= '
|
||||
declare ' . $name . ' <=> (Control as ' . $class . ');
|
||||
';
|
||||
$scriptText .= $this->text . '
|
||||
';
|
||||
if ($closeBlock) {
|
||||
$scriptText .= '}';
|
||||
}
|
||||
return $scriptText;
|
||||
}
|
||||
}
|
||||
|
@ -12,90 +12,131 @@ use FML\Script\ScriptLabel;
|
||||
* Script Feature for submitting an Entry
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class EntrySubmit extends ScriptFeature {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
/** @var Entry $entry */
|
||||
protected $entry = null;
|
||||
protected $url = null;
|
||||
class EntrySubmit extends ScriptFeature
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct a new Entry Submit Feature
|
||||
*
|
||||
* @param Entry $entry (optional) Entry Control
|
||||
* @param string $url (optional) Submit url
|
||||
*/
|
||||
public function __construct(Entry $entry = null, $url = null) {
|
||||
if ($entry !== null) {
|
||||
$this->setEntry($entry);
|
||||
}
|
||||
$this->setUrl($url);
|
||||
}
|
||||
/**
|
||||
* @var Entry $entry Entry
|
||||
*/
|
||||
protected $entry = null;
|
||||
|
||||
/**
|
||||
* Set the Entry
|
||||
*
|
||||
* @param Entry $entry Entry Control
|
||||
* @return static
|
||||
*/
|
||||
public function setEntry(Entry $entry) {
|
||||
$this->entry = $entry->checkId()->setScriptEvents(true);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var string $url Sumit url
|
||||
*/
|
||||
protected $url = null;
|
||||
|
||||
/**
|
||||
* Set the submit url
|
||||
*
|
||||
* @param string $url Submit url
|
||||
* @return static
|
||||
*/
|
||||
public function setUrl($url) {
|
||||
$this->url = (string)$url;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new Entry Submit
|
||||
*
|
||||
* @api
|
||||
* @param Entry $entry (optional) Entry Control
|
||||
* @param string $url (optional) Submit url
|
||||
*/
|
||||
public function __construct(Entry $entry = null, $url = null)
|
||||
{
|
||||
if ($entry) {
|
||||
$this->setEntry($entry);
|
||||
}
|
||||
if ($url) {
|
||||
$this->setUrl($url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Script\Features\ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script) {
|
||||
$script->setScriptInclude(ScriptInclude::TEXTLIB);
|
||||
$controlScript = new ControlScript($this->entry, $this->getScriptText(), ScriptLabel::ENTRYSUBMIT);
|
||||
$controlScript->prepare($script);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the Entry
|
||||
*
|
||||
* @api
|
||||
* @return Entry
|
||||
*/
|
||||
public function getEntry()
|
||||
{
|
||||
return $this->entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText() {
|
||||
$url = $this->buildCompatibleUrl();
|
||||
$entryName = $this->entry->getName();
|
||||
$link = Builder::escapeText($entryName . $url . '=', true);
|
||||
return "
|
||||
/**
|
||||
* Set the Entry
|
||||
*
|
||||
* @api
|
||||
* @param Entry $entry Entry Control
|
||||
* @return static
|
||||
*/
|
||||
public function setEntry(Entry $entry)
|
||||
{
|
||||
$entry->setScriptEvents(true)
|
||||
->checkId();
|
||||
$this->entry = $entry;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the submit url
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the submit url
|
||||
*
|
||||
* @api
|
||||
* @param string $url Submit url
|
||||
* @return static
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->url = (string)$url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$script->setScriptInclude(ScriptInclude::TEXTLIB);
|
||||
$controlScript = new ControlScript($this->entry, $this->getScriptText(), ScriptLabel::ENTRYSUBMIT);
|
||||
$controlScript->prepare($script);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText()
|
||||
{
|
||||
$url = $this->buildCompatibleUrl();
|
||||
$entryName = $this->entry->getName();
|
||||
$link = Builder::escapeText($entryName . $url . "=");
|
||||
return "
|
||||
declare Value = TextLib::URLEncode(Entry.Value);
|
||||
OpenLink({$link}^Value, CMlScript::LinkType::Goto);
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the submit url compatible for the Entry parameter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildCompatibleUrl()
|
||||
{
|
||||
$url = $this->url;
|
||||
$paramsBegin = stripos($url, '?');
|
||||
if (!is_int($paramsBegin) || $paramsBegin < 0) {
|
||||
$url .= '?';
|
||||
} else {
|
||||
$url .= '&';
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the submit url compatible for the Entry parameter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildCompatibleUrl() {
|
||||
$url = $this->url;
|
||||
$paramsBegin = stripos($url, '?');
|
||||
if (!is_int($paramsBegin) || $paramsBegin < 0) {
|
||||
$url .= '?';
|
||||
} else {
|
||||
$url .= '&';
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
303
libs/FML/Script/Features/GraphCurve.php
Normal file
303
libs/FML/Script/Features/GraphCurve.php
Normal file
@ -0,0 +1,303 @@
|
||||
<?php
|
||||
|
||||
namespace FML\Script\Features;
|
||||
|
||||
use FML\Controls\Graph;
|
||||
use FML\Script\Builder;
|
||||
use FML\Script\Script;
|
||||
use FML\Script\ScriptLabel;
|
||||
|
||||
/**
|
||||
* Script Feature adding a Curve to a Graph
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class GraphCurve extends ScriptFeature
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Graph $graph Graph
|
||||
*/
|
||||
protected $graph = null;
|
||||
|
||||
/**
|
||||
* @var array[] $points Points
|
||||
*/
|
||||
protected $points = array();
|
||||
|
||||
/**
|
||||
* @var bool $sortPoints Sort points
|
||||
*/
|
||||
protected $sortPoints = false;
|
||||
|
||||
/**
|
||||
* @var float[] $color Color
|
||||
*/
|
||||
protected $color = null;
|
||||
|
||||
/**
|
||||
* @var string $style Style
|
||||
*/
|
||||
protected $style = null;
|
||||
|
||||
/**
|
||||
* @var float $width Width
|
||||
*/
|
||||
protected $width = -1.;
|
||||
|
||||
/**
|
||||
* Construct a new Graph Curve
|
||||
*
|
||||
* @api
|
||||
* @param Graph $graph (optional) Graph
|
||||
* @param array[] $points (optional) Points
|
||||
*/
|
||||
public function __construct(Graph $graph = null, array $points = null)
|
||||
{
|
||||
if ($graph) {
|
||||
$this->setGraph($graph);
|
||||
}
|
||||
if ($points) {
|
||||
$this->setPoints($points);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Graph
|
||||
*
|
||||
* @api
|
||||
* @return Graph
|
||||
*/
|
||||
public function getGraph()
|
||||
{
|
||||
return $this->graph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Graph
|
||||
*
|
||||
* @api
|
||||
* @param Graph $graph Graph
|
||||
* @return static
|
||||
*/
|
||||
public function setGraph(Graph $graph)
|
||||
{
|
||||
$graph->checkId();
|
||||
$this->graph = $graph;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the points
|
||||
*
|
||||
* @api
|
||||
* @return array[]
|
||||
*/
|
||||
public function getPoints()
|
||||
{
|
||||
return $this->points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add point
|
||||
*
|
||||
* @api
|
||||
* @param float|float[] $coordX X-coordinate or point
|
||||
* @param float $coordY (optional) Y-coordinate
|
||||
* @return static
|
||||
*/
|
||||
public function addPoint($coordX, $coordY = null)
|
||||
{
|
||||
if (is_array($coordX)) {
|
||||
$coordY = (isset($coordX[1]) ? $coordX[1] : 0.);
|
||||
$coordX = (isset($coordX[0]) ? $coordX[0] : 0.);
|
||||
}
|
||||
array_push($this->points, array($coordX, $coordY));
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add points
|
||||
*
|
||||
* @api
|
||||
* @param array[] $points Points
|
||||
* @return static
|
||||
*/
|
||||
public function addPoints(array $points)
|
||||
{
|
||||
foreach ($points as $point) {
|
||||
$this->addPoint($point);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the points
|
||||
*
|
||||
* @api
|
||||
* @param array[] $points Points
|
||||
* @return static
|
||||
*/
|
||||
public function setPoints(array $points)
|
||||
{
|
||||
return $this->removeAllPoints()
|
||||
->addPoints($points);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all points
|
||||
*
|
||||
* @api
|
||||
* @return static
|
||||
*/
|
||||
public function removeAllPoints()
|
||||
{
|
||||
$this->points = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if point should be sorted
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function getSortPoints()
|
||||
{
|
||||
return $this->sortPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if point should be sorted
|
||||
*
|
||||
* @api
|
||||
* @param bool $sortPoints If point should be sorted
|
||||
* @return static
|
||||
*/
|
||||
public function setSortPoints($sortPoints)
|
||||
{
|
||||
$this->sortPoints = (bool)$sortPoints;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color
|
||||
*
|
||||
* @api
|
||||
* @return float[]
|
||||
*/
|
||||
public function getColor()
|
||||
{
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the color
|
||||
*
|
||||
* @api
|
||||
* @param float[] $color (optional) Color
|
||||
* @return static
|
||||
*/
|
||||
public function setColor(array $color = null)
|
||||
{
|
||||
$this->color = $color;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the style
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getStyle()
|
||||
{
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the style
|
||||
*
|
||||
* @api
|
||||
* @return static
|
||||
*/
|
||||
public function setStyle($style)
|
||||
{
|
||||
$this->style = (string)$style;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width
|
||||
*
|
||||
* @api
|
||||
* @return float
|
||||
*/
|
||||
public function getWidth()
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the width
|
||||
*
|
||||
* @api
|
||||
* @return static
|
||||
*/
|
||||
public function setWidth($width)
|
||||
{
|
||||
$this->width = (float)$width;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->getScriptText(), true);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText()
|
||||
{
|
||||
$graphId = Builder::escapeText($this->graph->getId(), false);
|
||||
$scriptText = "
|
||||
declare Graph <=> (Page.GetFirstChild(\"{$graphId}\") as CMlGraph);
|
||||
if (Graph != Null) {
|
||||
declare GraphCurve <=> Graph.AddCurve();
|
||||
";
|
||||
foreach ($this->points as $point) {
|
||||
$pointVec2 = Builder::getVec2($point);
|
||||
$scriptText .= "
|
||||
GraphCurve.Points.add({$pointVec2});";
|
||||
}
|
||||
if ($this->sortPoints) {
|
||||
$scriptText .= "
|
||||
GraphCurve.SortPoints();";
|
||||
}
|
||||
if ($this->color) {
|
||||
$colorVec3 = Builder::getVec3($this->color);
|
||||
$scriptText .= "
|
||||
GraphCurve.Color = {$colorVec3};";
|
||||
}
|
||||
if ($this->style) {
|
||||
$scriptText .= "
|
||||
GraphCurve.Style = {$this->style};";
|
||||
}
|
||||
if ($this->width > 0) {
|
||||
$scriptText .= "
|
||||
GraphCurve.Width = {$this->width};";
|
||||
}
|
||||
return $scriptText . "
|
||||
}";
|
||||
}
|
||||
|
||||
}
|
@ -11,114 +11,185 @@ use FML\Script\ScriptLabel;
|
||||
*
|
||||
* @author steeffeen
|
||||
* @link http://destroflyer.mania-community.de/maniascript/keycharid_table.php
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class KeyAction extends ScriptFeature {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
protected $actionName = null;
|
||||
protected $keyName = null;
|
||||
protected $keyCode = null;
|
||||
protected $charPressed = null;
|
||||
class KeyAction extends ScriptFeature
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct a new Key Action Feature
|
||||
*
|
||||
* @param string $actionName (optional) Triggered action
|
||||
* @param string $keyName (optional) Key name
|
||||
*/
|
||||
public function __construct($actionName = null, $keyName = null) {
|
||||
if ($actionName !== null) {
|
||||
$this->setActionName($actionName);
|
||||
}
|
||||
if ($keyName !== null) {
|
||||
$this->setKeyName($keyName);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @var string $actionName Action name
|
||||
*/
|
||||
protected $actionName = null;
|
||||
|
||||
/**
|
||||
* Set the action to trigger
|
||||
*
|
||||
* @param string $actionName Triggered action
|
||||
* @return static
|
||||
*/
|
||||
public function setActionName($actionName) {
|
||||
$this->actionName = (string)$actionName;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var string $keyName Key name
|
||||
*/
|
||||
protected $keyName = null;
|
||||
|
||||
/**
|
||||
* Set the key name for triggering the action
|
||||
*
|
||||
* @param string $keyName Key Name
|
||||
* @return static
|
||||
*/
|
||||
public function setKeyName($keyName) {
|
||||
$this->keyName = (string)$keyName;
|
||||
$this->keyCode = null;
|
||||
$this->charPressed = null;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var int $keyCode Key code
|
||||
*/
|
||||
protected $keyCode = null;
|
||||
|
||||
/**
|
||||
* Set the key code for triggering the action
|
||||
*
|
||||
* @param int $keyCode Key Code
|
||||
* @return static
|
||||
*/
|
||||
public function setKeyCode($keyCode) {
|
||||
$this->keyCode = (int)$keyCode;
|
||||
$this->keyName = null;
|
||||
$this->charPressed = null;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var string $charPressed Pressed character
|
||||
*/
|
||||
protected $charPressed = null;
|
||||
|
||||
/**
|
||||
* Set the char to press for triggering the action
|
||||
*
|
||||
* @param string $charPressed Pressed char
|
||||
* @return static
|
||||
*/
|
||||
public function setCharPressed($charPressed) {
|
||||
$this->charPressed = (string)$charPressed;
|
||||
$this->keyName = null;
|
||||
$this->keyCode = null;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new Key Action
|
||||
*
|
||||
* @api
|
||||
* @param string $actionName (optional) Triggered action
|
||||
* @param string $keyName (optional) Key name
|
||||
*/
|
||||
public function __construct($actionName = null, $keyName = null)
|
||||
{
|
||||
if ($actionName) {
|
||||
$this->setActionName($actionName);
|
||||
}
|
||||
if ($keyName) {
|
||||
$this->setKeyName($keyName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Script\Features\ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script) {
|
||||
$script->appendGenericScriptLabel(ScriptLabel::KEYPRESS, $this->getScriptText());
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the action to trigger
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getActionName()
|
||||
{
|
||||
return $this->actionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText() {
|
||||
$actionName = Builder::escapeText($this->actionName, true);
|
||||
$key = null;
|
||||
$value = null;
|
||||
if ($this->keyName !== null) {
|
||||
$key = 'KeyName';
|
||||
$value = $this->keyName;
|
||||
} else if ($this->keyCode !== null) {
|
||||
$key = 'KeyCode';
|
||||
$value = $this->keyCode;
|
||||
} else if ($this->charPressed !== null) {
|
||||
$key = 'CharPressed';
|
||||
$value = $this->charPressed;
|
||||
}
|
||||
$value = Builder::escapeText($value, true);
|
||||
return "
|
||||
/**
|
||||
* Set the action to trigger
|
||||
*
|
||||
* @api
|
||||
* @param string $actionName Triggered action
|
||||
* @return static
|
||||
*/
|
||||
public function setActionName($actionName)
|
||||
{
|
||||
$this->actionName = (string)$actionName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key name for triggering the action
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getKeyName()
|
||||
{
|
||||
return $this->keyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the key name for triggering the action
|
||||
*
|
||||
* @api
|
||||
* @param string $keyName Key Name
|
||||
* @return static
|
||||
*/
|
||||
public function setKeyName($keyName)
|
||||
{
|
||||
$this->keyName = (string)$keyName;
|
||||
$this->keyCode = null;
|
||||
$this->charPressed = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key code for triggering the action
|
||||
*
|
||||
* @api
|
||||
* @return int
|
||||
*/
|
||||
public function getKeyCode()
|
||||
{
|
||||
return $this->keyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the key code for triggering the action
|
||||
*
|
||||
* @api
|
||||
* @param int $keyCode Key Code
|
||||
* @return static
|
||||
*/
|
||||
public function setKeyCode($keyCode)
|
||||
{
|
||||
$this->keyName = null;
|
||||
$this->keyCode = (int)$keyCode;
|
||||
$this->charPressed = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the character to press for triggering the action
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getCharPressed()
|
||||
{
|
||||
return $this->charPressed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the character to press for triggering the action
|
||||
*
|
||||
* @api
|
||||
* @param string $charPressed Pressed character
|
||||
* @return static
|
||||
*/
|
||||
public function setCharPressed($charPressed)
|
||||
{
|
||||
$this->keyName = null;
|
||||
$this->keyCode = null;
|
||||
$this->charPressed = (string)$charPressed;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$script->appendGenericScriptLabel(ScriptLabel::KEYPRESS, $this->getScriptText());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText()
|
||||
{
|
||||
$actionName = Builder::escapeText($this->actionName);
|
||||
$key = null;
|
||||
$value = null;
|
||||
if ($this->keyName !== null) {
|
||||
$key = "KeyName";
|
||||
$value = $this->keyName;
|
||||
} else if ($this->keyCode !== null) {
|
||||
$key = "KeyCode";
|
||||
$value = $this->keyCode;
|
||||
} else if ($this->charPressed !== null) {
|
||||
$key = "CharPressed";
|
||||
$value = $this->charPressed;
|
||||
}
|
||||
$value = Builder::escapeText($value);
|
||||
return "
|
||||
if (Event.{$key} == {$value}) {
|
||||
TriggerPageAction({$actionName});
|
||||
}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,80 +12,119 @@ use FML\Types\Scriptable;
|
||||
* Script Feature for opening the map info
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class MapInfo extends ScriptFeature {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
/** @var Control $control */
|
||||
protected $control = null;
|
||||
protected $labelName = null;
|
||||
class MapInfo extends ScriptFeature
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct a new Map Info Feature
|
||||
*
|
||||
* @param Control $control (optional) Map Info Control
|
||||
* @param string $labelName (optional) Script Label name
|
||||
*/
|
||||
public function __construct(Control $control, $labelName = ScriptLabel::MOUSECLICK) {
|
||||
$this->setControl($control);
|
||||
$this->setLabelName($labelName);
|
||||
}
|
||||
/**
|
||||
* @var Control $control Map Info Control
|
||||
*/
|
||||
protected $control = null;
|
||||
|
||||
/**
|
||||
* Set the Control
|
||||
*
|
||||
* @param Control $control Map Info Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control) {
|
||||
$control->checkId();
|
||||
if ($control instanceof Scriptable) {
|
||||
$control->setScriptEvents(true);
|
||||
}
|
||||
$this->control = $control;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var string $labelName Script Label name
|
||||
*/
|
||||
protected $labelName = null;
|
||||
|
||||
/**
|
||||
* Set the label name
|
||||
*
|
||||
* @param string $labelName Script Label name
|
||||
* @return static
|
||||
*/
|
||||
public function setLabelName($labelName) {
|
||||
$this->labelName = (string)$labelName;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new Map Info
|
||||
*
|
||||
* @api
|
||||
* @param Control $control (optional) Map Info Control
|
||||
* @param string $labelName (optional) Script Label name
|
||||
*/
|
||||
public function __construct(Control $control = null, $labelName = ScriptLabel::MOUSECLICK)
|
||||
{
|
||||
if ($control) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
if ($labelName) {
|
||||
$this->setLabelName($labelName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Script\Features\ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script) {
|
||||
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the Control
|
||||
*
|
||||
* @api
|
||||
* @return Control
|
||||
*/
|
||||
public function getControl()
|
||||
{
|
||||
return $this->control;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText() {
|
||||
if ($this->control) {
|
||||
// Control event
|
||||
$controlId = Builder::escapeText($this->control->getId(), true);
|
||||
$scriptText = "
|
||||
/**
|
||||
* Set the Control
|
||||
*
|
||||
* @api
|
||||
* @param Control $control Map Info Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control)
|
||||
{
|
||||
$control->checkId();
|
||||
if ($control instanceof Scriptable) {
|
||||
$control->setScriptEvents(true);
|
||||
}
|
||||
$this->control = $control;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Script Label name
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getLabelName()
|
||||
{
|
||||
return $this->labelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Script Label name
|
||||
*
|
||||
* @api
|
||||
* @param string $labelName Script Label name
|
||||
* @return static
|
||||
*/
|
||||
public function setLabelName($labelName)
|
||||
{
|
||||
$this->labelName = (string)$labelName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText()
|
||||
{
|
||||
if ($this->control) {
|
||||
// Control event
|
||||
$controlId = Builder::escapeText($this->control->getId());
|
||||
return "
|
||||
if (Event.Control.ControlId == {$controlId}) {
|
||||
ShowCurChallengeCard();
|
||||
}";
|
||||
} else {
|
||||
// Other
|
||||
$scriptText = "
|
||||
}
|
||||
|
||||
// Other events
|
||||
return "
|
||||
ShowCurChallengeCard();";
|
||||
}
|
||||
return $scriptText;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,130 +11,173 @@ use FML\Script\ScriptLabel;
|
||||
* Script Feature realising a Menu showing specific Controls for the different items
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class Menu extends ScriptFeature {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const FUNCTION_UPDATE_MENU = 'FML_UpdateMenu';
|
||||
class Menu extends ScriptFeature
|
||||
{
|
||||
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
/** @var MenuElement[] $elements */
|
||||
protected $elements = array();
|
||||
/** @var MenuElement $startElement */
|
||||
protected $startElement = null;
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const FUNCTION_UPDATE_MENU = "FML_UpdateMenu";
|
||||
|
||||
/**
|
||||
* Construct a new Menu Feature
|
||||
*
|
||||
* @param Control $item (optional) Item Control in the Menu bar
|
||||
* @param Control $control (optional) Toggled Menu Control
|
||||
*/
|
||||
public function __construct(Control $item = null, Control $control = null) {
|
||||
if ($item && $control) {
|
||||
$this->addElement($item, $control);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @var MenuElement[] $elements Menu Elements
|
||||
*/
|
||||
protected $elements = array();
|
||||
|
||||
/**
|
||||
* Add a new Element to the Menu
|
||||
*
|
||||
* @param Control $item Item Control in the Menu bar
|
||||
* @param Control $control Toggled Menu Control
|
||||
* @param bool $isStartElement (optional) Whether the Menu should start with this Element
|
||||
* @return static
|
||||
*/
|
||||
public function addElement(Control $item, Control $control, $isStartElement = false) {
|
||||
$menuElement = new MenuElement($item, $control);
|
||||
$this->appendElement($menuElement, $isStartElement);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var MenuElement $startElement Start Element
|
||||
*/
|
||||
protected $startElement = null;
|
||||
|
||||
/**
|
||||
* Append an Element to the Menu
|
||||
*
|
||||
* @param MenuElement $menuElement Menu Element
|
||||
* @param bool $isStartElement (optional) Whether the Menu should start with this Element
|
||||
* @return static
|
||||
*/
|
||||
public function appendElement(MenuElement $menuElement, $isStartElement = false) {
|
||||
if (!in_array($menuElement, $this->elements, true)) {
|
||||
array_push($this->elements, $menuElement);
|
||||
if ($isStartElement) {
|
||||
$this->setStartElement($menuElement);
|
||||
} else if (count($this->elements) > 1) {
|
||||
$menuElement->getControl()->setVisible(false);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new Menu
|
||||
*
|
||||
* @api
|
||||
* @param Control $item (optional) Item Control in the Menu bar
|
||||
* @param Control $control (optional) Toggled Menu Control
|
||||
* @param bool $isStartElement (optional) Whether the Menu should start with the given Element
|
||||
*/
|
||||
public function __construct(Control $item = null, Control $control = null, $isStartElement = true)
|
||||
{
|
||||
if ($item && $control) {
|
||||
$this->addItem($item, $control, $isStartElement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Element to start with
|
||||
*
|
||||
* @param MenuElement $startElement Starting Element
|
||||
* @return static
|
||||
*/
|
||||
public function setStartElement(MenuElement $startElement) {
|
||||
$this->startElement = $startElement;
|
||||
if (!in_array($startElement, $this->elements, true)) {
|
||||
array_push($this->elements, $startElement);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the Menu Elements
|
||||
*
|
||||
* @api
|
||||
* @return MenuElement[]
|
||||
*/
|
||||
public function getElements()
|
||||
{
|
||||
return $this->elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Script\Features\ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script) {
|
||||
$updateFunctionName = self::FUNCTION_UPDATE_MENU;
|
||||
$elementsArrayText = $this->getElementsArrayText();
|
||||
/**
|
||||
* Add a Menu item
|
||||
*
|
||||
* @api
|
||||
* @param Control $item Item Control in the Menu bar
|
||||
* @param Control $control Toggled Menu Control
|
||||
* @param bool $isStartElement (optional) Whether the Menu should start with this Element
|
||||
* @return static
|
||||
*/
|
||||
public function addItem(Control $item, Control $control, $isStartElement = false)
|
||||
{
|
||||
$menuElement = new MenuElement($item, $control);
|
||||
$this->addElement($menuElement, $isStartElement);
|
||||
return $this;
|
||||
}
|
||||
|
||||
// OnInit
|
||||
if ($this->startElement) {
|
||||
$startControlId = $this->startElement->getControl()->getId(true, true);
|
||||
$initScriptText = "
|
||||
/**
|
||||
* Add a Menu Element
|
||||
*
|
||||
* @api
|
||||
* @param MenuElement $menuElement Menu Element
|
||||
* @param bool $isStartElement (optional) Whether the Menu should start with this Element
|
||||
* @return static
|
||||
*/
|
||||
public function addElement(MenuElement $menuElement, $isStartElement = false)
|
||||
{
|
||||
if (!in_array($menuElement, $this->elements, true)) {
|
||||
array_push($this->elements, $menuElement);
|
||||
if ($isStartElement) {
|
||||
// new start element
|
||||
$this->setStartElement($menuElement);
|
||||
} else {
|
||||
// additional element - set invisible
|
||||
$menuElement->getControl()
|
||||
->setVisible(false);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Element to start with
|
||||
*
|
||||
* @api
|
||||
* @return MenuElement
|
||||
*/
|
||||
public function getStartElement()
|
||||
{
|
||||
return $this->startElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Element to start with
|
||||
*
|
||||
* @api
|
||||
* @param MenuElement $startElement Start Element
|
||||
* @return static
|
||||
*/
|
||||
public function setStartElement(MenuElement $startElement = null)
|
||||
{
|
||||
$this->startElement = $startElement;
|
||||
if ($startElement && !in_array($startElement, $this->elements, true)) {
|
||||
array_push($this->elements, $startElement);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$updateFunctionName = self::FUNCTION_UPDATE_MENU;
|
||||
$elementsArrayText = $this->getElementsArrayText();
|
||||
|
||||
// OnInit
|
||||
if ($this->startElement) {
|
||||
$startControlId = Builder::escapeText($this->startElement->getControl()->getId());
|
||||
$initScriptText = "
|
||||
{$updateFunctionName}({$elementsArrayText}, {$startControlId});";
|
||||
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $initScriptText, true);
|
||||
}
|
||||
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $initScriptText, true);
|
||||
}
|
||||
|
||||
// MouseClick
|
||||
$scriptText = "
|
||||
// MouseClick
|
||||
$scriptText = "
|
||||
declare MenuElements = {$elementsArrayText};
|
||||
if (MenuElements.existskey(Event.Control.ControlId)) {
|
||||
declare ShownControlId = MenuElements[Event.Control.ControlId];
|
||||
{$updateFunctionName}(MenuElements, ShownControlId);
|
||||
}";
|
||||
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $scriptText, true);
|
||||
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $scriptText, true);
|
||||
|
||||
// Update menu function
|
||||
$updateFunctionText = "
|
||||
// Update menu function
|
||||
$updateFunctionText = "
|
||||
Void {$updateFunctionName}(Text[Text] _Elements, Text _ShownControlId) {
|
||||
foreach (ItemId => ControlId in _Elements) {
|
||||
declare Control <=> (Page.GetFirstChild(ControlId));
|
||||
Control.Visible = (ControlId == _ShownControlId);
|
||||
}
|
||||
}";
|
||||
$script->addScriptFunction($updateFunctionName, $updateFunctionText);
|
||||
$script->addScriptFunction($updateFunctionName, $updateFunctionText);
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the array text for the Elements
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getElementsArrayText()
|
||||
{
|
||||
$elements = array();
|
||||
foreach ($this->elements as $element) {
|
||||
$elementId = $element->getItem()
|
||||
->getId();
|
||||
$elements[$elementId] = $element->getControl()
|
||||
->getId();
|
||||
}
|
||||
return Builder::getArray($elements, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the array text for the Elements
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getElementsArrayText() {
|
||||
$elements = array();
|
||||
foreach ($this->elements as $element) {
|
||||
$elementId = $element->getItem()->getId();
|
||||
$elements[$elementId] = $element->getControl()->getId();
|
||||
}
|
||||
return Builder::getArray($elements, true);
|
||||
}
|
||||
}
|
||||
|
@ -9,72 +9,90 @@ use FML\Types\Scriptable;
|
||||
* Menu Element for the Menu Feature
|
||||
*
|
||||
* @author steeffeen <mail@steeffeen.com>
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class MenuElement {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
protected $item = null;
|
||||
protected $control = null;
|
||||
class MenuElement
|
||||
{
|
||||
|
||||
/**
|
||||
* Create a new Menu Element
|
||||
*
|
||||
* @param Control $item (optional) Item Control in the Menu bar
|
||||
* @param Control $control (optional) Toggled Menu Control
|
||||
*/
|
||||
public function __construct(Control $item = null, Control $control = null) {
|
||||
if ($item !== null) {
|
||||
$this->setItem($item);
|
||||
}
|
||||
if ($control !== null) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @var Control $item Menu Item
|
||||
*/
|
||||
protected $item = null;
|
||||
|
||||
/**
|
||||
* Set the Item Control
|
||||
*
|
||||
* @param Control $item Item Control in the Menu bar
|
||||
* @return static
|
||||
*/
|
||||
public function setItem(Control $item) {
|
||||
$item->checkId();
|
||||
if ($item instanceof Scriptable) {
|
||||
$item->setScriptEvents(true);
|
||||
}
|
||||
$this->item = $item;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var Control $control Menu Control
|
||||
*/
|
||||
protected $control = null;
|
||||
|
||||
/**
|
||||
* Get the Item Control
|
||||
*
|
||||
* @return \FML\Controls\Control
|
||||
*/
|
||||
public function getItem() {
|
||||
return $this->item;
|
||||
}
|
||||
/**
|
||||
* Create a new Menu Element
|
||||
*
|
||||
* @api
|
||||
* @param Control $item (optional) Item Control in the Menu bar
|
||||
* @param Control $control (optional) Toggled Menu Control
|
||||
*/
|
||||
public function __construct(Control $item = null, Control $control = null)
|
||||
{
|
||||
if ($item) {
|
||||
$this->setItem($item);
|
||||
}
|
||||
if ($control) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Menu Control
|
||||
*
|
||||
* @param Control $control Toggled Menu Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control) {
|
||||
$this->control = $control->checkId();
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the Item Control
|
||||
*
|
||||
* @api
|
||||
* @return Control
|
||||
*/
|
||||
public function getItem()
|
||||
{
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Item Control
|
||||
*
|
||||
* @api
|
||||
* @param Control $item Item Control
|
||||
* @return static
|
||||
*/
|
||||
public function setItem(Control $item)
|
||||
{
|
||||
$item->checkId();
|
||||
if ($item instanceof Scriptable) {
|
||||
$item->setScriptEvents(true);
|
||||
}
|
||||
$this->item = $item;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Menu Control
|
||||
*
|
||||
* @api
|
||||
* @return Control
|
||||
*/
|
||||
public function getControl()
|
||||
{
|
||||
return $this->control;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Menu Control
|
||||
*
|
||||
* @api
|
||||
* @param Control $control Menu Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control)
|
||||
{
|
||||
$control->checkId();
|
||||
$this->control = $control;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Menu Control
|
||||
*
|
||||
* @return \FML\Controls\Control
|
||||
*/
|
||||
public function getControl() {
|
||||
return $this->control;
|
||||
}
|
||||
}
|
||||
|
@ -10,235 +10,418 @@ use FML\Script\ScriptInclude;
|
||||
use FML\Script\ScriptLabel;
|
||||
|
||||
/**
|
||||
* Script Feature realising a mechanism for browsing through Pages
|
||||
* Script Feature realizing a mechanism for browsing through Pages
|
||||
*
|
||||
* @author steeffeen <mail@steeffeen.com>
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class Paging extends ScriptFeature {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const VAR_CURRENT_PAGE = 'FML_Paging_CurrentPage';
|
||||
const FUNCTION_UPDATE_CURRENT_PAGE = 'FML_UpdateCurrentPage';
|
||||
class Paging extends ScriptFeature
|
||||
{
|
||||
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
/** @var PagingPage[] $pages */
|
||||
protected $pages = array();
|
||||
/** @var PagingButton[] $buttons */
|
||||
protected $buttons = array();
|
||||
/** @var Label $label */
|
||||
protected $label = null;
|
||||
protected $startPageNumber = null;
|
||||
protected $customMaxPageNumber = null;
|
||||
protected $previousChunkAction = null;
|
||||
protected $nextChunkAction = null;
|
||||
protected $chunkActionAppendsPageNumber = null;
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const VAR_CURRENT_PAGE = "FML_Paging_CurrentPage";
|
||||
const FUNCTION_UPDATE_CURRENT_PAGE = "FML_UpdateCurrentPage";
|
||||
|
||||
/**
|
||||
* Construct a new Paging Script Feature
|
||||
*
|
||||
* @param Label $label (optional) Page number Label
|
||||
*/
|
||||
public function __construct(Label $label = null) {
|
||||
if ($label !== null) {
|
||||
$this->setLabel($label);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @var Label $label Page number Label
|
||||
*/
|
||||
protected $label = null;
|
||||
|
||||
/**
|
||||
* Add a new Page Control
|
||||
*
|
||||
* @param Control $pageControl Page Control
|
||||
* @param string $pageNumber (optional) Page number
|
||||
* @return static
|
||||
*/
|
||||
public function addPage(Control $pageControl, $pageNumber = null) {
|
||||
if ($pageNumber === null) {
|
||||
$pageNumber = count($this->pages) + 1;
|
||||
}
|
||||
$page = new PagingPage($pageControl, $pageNumber);
|
||||
$this->appendPage($page);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var PagingPage[] $pages Pages
|
||||
*/
|
||||
protected $pages = array();
|
||||
|
||||
/**
|
||||
* Append a Page
|
||||
*
|
||||
* @param PagingPage $page Paging Page
|
||||
* @return static
|
||||
*/
|
||||
public function appendPage(PagingPage $page) {
|
||||
if (!in_array($page, $this->pages, true)) {
|
||||
array_push($this->pages, $page);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var PagingButton[] $buttons Paging Buttons
|
||||
*/
|
||||
protected $buttons = array();
|
||||
|
||||
/**
|
||||
* Add a new Button to browse through the Pages
|
||||
*
|
||||
* @param Control $buttonControl Button used for browsing
|
||||
* @param int $browseAction (optional) Number of browsed Pages per click
|
||||
* @return static
|
||||
*/
|
||||
public function addButton(Control $buttonControl, $browseAction = null) {
|
||||
if ($browseAction === null) {
|
||||
$buttonCount = count($this->buttons);
|
||||
if ($buttonCount % 2 === 0) {
|
||||
$browseAction = $buttonCount / 2 + 1;
|
||||
} else {
|
||||
$browseAction = $buttonCount / -2 - 1;
|
||||
}
|
||||
}
|
||||
$button = new PagingButton($buttonControl, $browseAction);
|
||||
$this->appendButton($button);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var int $startPageNumber Start Page number
|
||||
*/
|
||||
protected $startPageNumber = null;
|
||||
|
||||
/**
|
||||
* Append a Button to browse through Pages
|
||||
*
|
||||
* @param PagingButton $button Paging Button
|
||||
* @return static
|
||||
*/
|
||||
public function appendButton(PagingButton $button) {
|
||||
if (!in_array($button, $this->buttons, true)) {
|
||||
array_push($this->buttons, $button);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var int $customMaxPageNumber Custom maximum page number
|
||||
*/
|
||||
protected $customMaxPageNumber = null;
|
||||
|
||||
/**
|
||||
* Set the Label showing the Page number
|
||||
*
|
||||
* @param Label $label Page number Label
|
||||
* @return static
|
||||
*/
|
||||
public function setLabel(Label $label) {
|
||||
$this->label = $label->checkId();
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var string $previousChunkAction Previous chunk action name
|
||||
*/
|
||||
protected $previousChunkAction = null;
|
||||
|
||||
/**
|
||||
* Set the Start Page number
|
||||
*
|
||||
* @param int $startPageNumber Page number to start with
|
||||
* @return static
|
||||
*/
|
||||
public function setStartPageNumber($startPageNumber) {
|
||||
$this->startPageNumber = (int)$startPageNumber;
|
||||
}
|
||||
/**
|
||||
* @var string $nextChunkAction Next chunk action name
|
||||
*/
|
||||
protected $nextChunkAction = null;
|
||||
|
||||
/**
|
||||
* Set a custom maximum Page number for using chunks
|
||||
*
|
||||
* @param int $maxPageNumber Custom maximum Page number
|
||||
* @return static
|
||||
*/
|
||||
public function setCustomMaxPageNumber($maxPageNumber) {
|
||||
$this->customMaxPageNumber = (int)$maxPageNumber;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var bool $chunkActionAppendsPageNumber Chunk action appended with Page number
|
||||
*/
|
||||
protected $chunkActionAppendsPageNumber = null;
|
||||
|
||||
/**
|
||||
* Set the action triggered when the previous chunk is needed
|
||||
*
|
||||
* @param string $previousChunkAction Triggered action
|
||||
* @return static
|
||||
*/
|
||||
public function setPreviousChunkAction($previousChunkAction) {
|
||||
$this->previousChunkAction = (string)$previousChunkAction;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new Paging
|
||||
*
|
||||
* @api
|
||||
* @param Label $label (optional) Page number Label
|
||||
* @param PagingPage[] $pages (optional) Pages
|
||||
* @param PagingButton[] $buttons (optional) Pageing Buttons
|
||||
*/
|
||||
public function __construct(Label $label = null, array $pages = null, array $buttons = null)
|
||||
{
|
||||
if ($label) {
|
||||
$this->setLabel($label);
|
||||
}
|
||||
if ($pages) {
|
||||
$this->setPages($pages);
|
||||
}
|
||||
if ($buttons) {
|
||||
$this->setButtons($buttons);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the action triggered when the next chunk is needed
|
||||
*
|
||||
* @param string $nextChunkAction Triggered action
|
||||
* @return static
|
||||
*/
|
||||
public function setNextChunkAction($nextChunkAction) {
|
||||
$this->nextChunkAction = (string)$nextChunkAction;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the Label showing the Page number
|
||||
*
|
||||
* @api
|
||||
* @return Label
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the actions triggered when another chunk is needed
|
||||
*
|
||||
* @param string $chunkAction Triggered action
|
||||
* @return static
|
||||
*/
|
||||
public function setChunkActions($chunkAction) {
|
||||
$this->setNextChunkAction($chunkAction);
|
||||
$this->setPreviousChunkAction($chunkAction);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Set the Label showing the Page number
|
||||
*
|
||||
* @api
|
||||
* @param Label $label Page number Label
|
||||
* @return static
|
||||
*/
|
||||
public function setLabel(Label $label)
|
||||
{
|
||||
$label->checkId();
|
||||
$this->label = $label;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the chunk action should get the needed Page number appended
|
||||
*
|
||||
* @param bool $appendPageNumber Whether to append the needed Page number
|
||||
* @return static
|
||||
*/
|
||||
public function setChunkActionAppendsPageNumber($appendPageNumber) {
|
||||
$this->chunkActionAppendsPageNumber = (bool)$appendPageNumber;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the Pages
|
||||
*
|
||||
* @api
|
||||
* @return PagingPage[]
|
||||
*/
|
||||
public function getPages()
|
||||
{
|
||||
return $this->pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Script\Features\ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script) {
|
||||
if (empty($this->pages)) {
|
||||
return $this;
|
||||
}
|
||||
$script->setScriptInclude(ScriptInclude::TEXTLIB);
|
||||
/**
|
||||
* Add a new Page Control
|
||||
*
|
||||
* @api
|
||||
* @param Control $pageControl Page Control
|
||||
* @param string $pageNumber (optional) Page number
|
||||
* @return static
|
||||
*/
|
||||
public function addPageControl(Control $pageControl, $pageNumber = null)
|
||||
{
|
||||
if ($pageNumber === null) {
|
||||
$pageNumber = count($this->pages) + 1;
|
||||
}
|
||||
$page = new PagingPage($pageControl, $pageNumber);
|
||||
return $this->addPage($page);
|
||||
}
|
||||
|
||||
$currentPageVariable = self::VAR_CURRENT_PAGE;
|
||||
$updatePageFunction = self::FUNCTION_UPDATE_CURRENT_PAGE;
|
||||
/**
|
||||
* Add a new Page
|
||||
*
|
||||
* @api
|
||||
* @param PagingPage $page Page
|
||||
* @return static
|
||||
*/
|
||||
public function addPage(PagingPage $page)
|
||||
{
|
||||
if (!in_array($page, $this->pages, true)) {
|
||||
array_push($this->pages, $page);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
$minPageNumber = 1;
|
||||
$startPageNumber = (is_int($this->startPageNumber) ? $this->startPageNumber : $minPageNumber);
|
||||
$maxPage = $this->getMaxPage();
|
||||
$maxPageNumber = $this->customMaxPageNumber;
|
||||
if (!is_int($maxPageNumber)) {
|
||||
$maxPageNumber = $maxPage->getPageNumber();
|
||||
}
|
||||
/**
|
||||
* Add new Pages
|
||||
*
|
||||
* @api
|
||||
* @param PagingPage[] $pages Pages
|
||||
* @return static
|
||||
*/
|
||||
public function setPages(array $pages)
|
||||
{
|
||||
$this->pages = array();
|
||||
foreach ($pages as $page) {
|
||||
$this->addPage($page);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
$pagingId = $maxPage->getControl()->getId(true, true);
|
||||
$pageLabelId = '""';
|
||||
if ($this->label) {
|
||||
$pageLabelId = $this->label->getId(true, true);
|
||||
}
|
||||
$pagesArrayText = $this->getPagesArrayText();
|
||||
$pageButtonsArrayText = $this->getPageButtonsArrayText();
|
||||
/**
|
||||
* Get the Buttons
|
||||
*
|
||||
* @api
|
||||
* @return PagingButton[]
|
||||
*/
|
||||
public function getButtons()
|
||||
{
|
||||
return $this->buttons;
|
||||
}
|
||||
|
||||
$previousChunkAction = Builder::escapeText($this->previousChunkAction, true);
|
||||
$nextChunkAction = Builder::escapeText($this->nextChunkAction, true);
|
||||
$chunkActionAppendsPageNumber = Builder::getBoolean($this->chunkActionAppendsPageNumber);
|
||||
/**
|
||||
* Add a new Button Control to browse through the Pages
|
||||
*
|
||||
* @api
|
||||
* @param Control $buttonControl Button used for browsing
|
||||
* @param int $browseAction (optional) Number of browsed Pages per click
|
||||
* @return static
|
||||
*/
|
||||
public function addButtonControl(Control $buttonControl, $browseAction = null)
|
||||
{
|
||||
if ($browseAction === null) {
|
||||
$buttonCount = count($this->buttons);
|
||||
if ($buttonCount % 2 === 0) {
|
||||
$browseAction = $buttonCount / 2 + 1;
|
||||
} else {
|
||||
$browseAction = $buttonCount / -2 - 1;
|
||||
}
|
||||
}
|
||||
$button = new PagingButton($buttonControl, $browseAction);
|
||||
return $this->addButton($button);
|
||||
}
|
||||
|
||||
// Init
|
||||
$initScriptText = "
|
||||
/**
|
||||
* Add a new Button to browse through Pages
|
||||
*
|
||||
* @api
|
||||
* @param PagingButton $button Paging Button
|
||||
* @return static
|
||||
*/
|
||||
public function addButton(PagingButton $button)
|
||||
{
|
||||
if (!in_array($button, $this->buttons, true)) {
|
||||
array_push($this->buttons, $button);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Paging Buttons
|
||||
*
|
||||
* @api
|
||||
* @param PagingButton[] $buttons Paging Buttons
|
||||
* @return static
|
||||
*/
|
||||
public function setButtons(array $buttons)
|
||||
{
|
||||
$this->buttons = array();
|
||||
foreach ($buttons as $button) {
|
||||
$this->addButton($button);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the start Page number
|
||||
*
|
||||
* @api
|
||||
* @return int
|
||||
*/
|
||||
public function getStartPageNumber()
|
||||
{
|
||||
return $this->startPageNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the start Page number
|
||||
*
|
||||
* @api
|
||||
* @param int $startPageNumber Page number to start with
|
||||
* @return static
|
||||
*/
|
||||
public function setStartPageNumber($startPageNumber)
|
||||
{
|
||||
$this->startPageNumber = (int)$startPageNumber;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a custom maximum Page number for using chunks
|
||||
*
|
||||
* @api
|
||||
* @return int
|
||||
*/
|
||||
public function getCustomMaxPageNumber()
|
||||
{
|
||||
return $this->customMaxPageNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a custom maximum Page number for using chunks
|
||||
*
|
||||
* @api
|
||||
* @param int $maxPageNumber Custom maximum Page number
|
||||
* @return static
|
||||
*/
|
||||
public function setCustomMaxPageNumber($maxPageNumber)
|
||||
{
|
||||
$this->customMaxPageNumber = (int)$maxPageNumber;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the action triggered when the previous chunk is needed
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getPreviousChunkAction()
|
||||
{
|
||||
return $this->previousChunkAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the action triggered when the previous chunk is needed
|
||||
*
|
||||
* @api
|
||||
* @param string $previousChunkAction Triggered action
|
||||
* @return static
|
||||
*/
|
||||
public function setPreviousChunkAction($previousChunkAction)
|
||||
{
|
||||
$this->previousChunkAction = (string)$previousChunkAction;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the action triggered when the next chunk is needed
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getNextChunkAction()
|
||||
{
|
||||
return $this->nextChunkAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the action triggered when the next chunk is needed
|
||||
*
|
||||
* @api
|
||||
* @param string $nextChunkAction Triggered action
|
||||
* @return static
|
||||
*/
|
||||
public function setNextChunkAction($nextChunkAction)
|
||||
{
|
||||
$this->nextChunkAction = (string)$nextChunkAction;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the actions triggered when another chunk is needed
|
||||
*
|
||||
* @api
|
||||
* @param string $chunkAction Triggered action
|
||||
* @return static
|
||||
*/
|
||||
public function setChunkActions($chunkAction)
|
||||
{
|
||||
return $this->setNextChunkAction($chunkAction)
|
||||
->setPreviousChunkAction($chunkAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the chunk action should append the needed Page number
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function getChunkActionAppendsPageNumber()
|
||||
{
|
||||
return $this->chunkActionAppendsPageNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the chunk action should append the needed Page number
|
||||
*
|
||||
* @api
|
||||
* @param bool $appendPageNumber Append the needed Page number
|
||||
* @return static
|
||||
*/
|
||||
public function setChunkActionAppendsPageNumber($appendPageNumber)
|
||||
{
|
||||
$this->chunkActionAppendsPageNumber = (bool)$appendPageNumber;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
if (empty($this->pages)) {
|
||||
return $this;
|
||||
}
|
||||
$script->setScriptInclude(ScriptInclude::TEXTLIB);
|
||||
|
||||
$currentPageVariable = self::VAR_CURRENT_PAGE;
|
||||
$updatePageFunction = self::FUNCTION_UPDATE_CURRENT_PAGE;
|
||||
|
||||
$minPageNumber = 1;
|
||||
$startPageNumber = (is_int($this->startPageNumber) ? $this->startPageNumber : $minPageNumber);
|
||||
$maxPage = $this->getMaxPage();
|
||||
$maxPageNumber = $this->customMaxPageNumber;
|
||||
if (!is_int($maxPageNumber)) {
|
||||
$maxPageNumber = $maxPage->getPageNumber();
|
||||
}
|
||||
|
||||
$pagingId = $maxPage->getControl()
|
||||
->getId(true, true);
|
||||
$pagingId = Builder::escapeText($maxPage->getControl()
|
||||
->getId());
|
||||
$pageLabelId = Builder::EMPTY_STRING;
|
||||
if ($this->label) {
|
||||
$pageLabelId = Builder::escapeText($this->label->getId());
|
||||
}
|
||||
|
||||
$pagesArrayText = $this->getPagesArrayText();
|
||||
$pageButtonsArrayText = $this->getPageButtonsArrayText();
|
||||
|
||||
$previousChunkAction = Builder::escapeText($this->previousChunkAction);
|
||||
$nextChunkAction = Builder::escapeText($this->nextChunkAction);
|
||||
$chunkActionAppendsPageNumber = Builder::getBoolean($this->chunkActionAppendsPageNumber);
|
||||
|
||||
// Init
|
||||
$initScriptText = "
|
||||
declare {$currentPageVariable} for This = Integer[Text];
|
||||
{$currentPageVariable}[{$pagingId}] = {$startPageNumber};
|
||||
{$updatePageFunction}({$pagingId}, {$pageLabelId}, 0, {$minPageNumber}, {$maxPageNumber}, {$pagesArrayText}, {$previousChunkAction}, {$nextChunkAction}, {$chunkActionAppendsPageNumber});";
|
||||
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $initScriptText, true);
|
||||
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $initScriptText, true);
|
||||
|
||||
// MouseClick
|
||||
$clickScriptText = "
|
||||
// MouseClick
|
||||
$clickScriptText = "
|
||||
declare PageButtons = {$pageButtonsArrayText};
|
||||
if (PageButtons.existskey(Event.Control.ControlId)) {
|
||||
declare BrowseAction = PageButtons[Event.Control.ControlId];
|
||||
{$updatePageFunction}({$pagingId}, {$pageLabelId}, BrowseAction, {$minPageNumber}, {$maxPageNumber}, {$pagesArrayText}, {$previousChunkAction}, {$nextChunkAction}, {$chunkActionAppendsPageNumber});
|
||||
}";
|
||||
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $clickScriptText, true);
|
||||
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $clickScriptText, true);
|
||||
|
||||
// Update function
|
||||
$functionText = "
|
||||
// Update function
|
||||
$functionText = "
|
||||
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];
|
||||
if (!{$currentPageVariable}.existskey(_PagingId)) return;
|
||||
@ -274,75 +457,82 @@ Void {$updatePageFunction}(Text _PagingId, Text _PageLabelId, Integer _BrowseAct
|
||||
if (PageLabel == Null) return;
|
||||
PageLabel.Value = CurrentPage^\"/\"^_MaxPageNumber;
|
||||
}";
|
||||
$script->addScriptFunction($updatePageFunction, $functionText);
|
||||
return $this;
|
||||
}
|
||||
$script->addScriptFunction($updatePageFunction, $functionText);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum Page
|
||||
*
|
||||
* @return \FML\Script\Features\PagingPage
|
||||
*/
|
||||
protected function getMinPage() {
|
||||
$minPageNumber = null;
|
||||
$minPage = null;
|
||||
foreach ($this->pages as $page) {
|
||||
$pageNumber = $page->getPageNumber();
|
||||
if ($minPageNumber === null || $pageNumber < $minPageNumber) {
|
||||
$minPageNumber = $pageNumber;
|
||||
$minPage = $page;
|
||||
}
|
||||
}
|
||||
return $minPage;
|
||||
}
|
||||
/**
|
||||
* Get the minimum Page
|
||||
*
|
||||
* @return PagingPage
|
||||
*/
|
||||
protected function getMinPage()
|
||||
{
|
||||
$minPageNumber = null;
|
||||
$minPage = null;
|
||||
foreach ($this->pages as $page) {
|
||||
$pageNumber = $page->getPageNumber();
|
||||
if ($minPageNumber === null || $pageNumber < $minPageNumber) {
|
||||
$minPageNumber = $pageNumber;
|
||||
$minPage = $page;
|
||||
}
|
||||
}
|
||||
return $minPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum Page
|
||||
*
|
||||
* @return \FML\Script\Features\PagingPage
|
||||
*/
|
||||
protected function getMaxPage() {
|
||||
$maxPageNumber = null;
|
||||
$maxPage = null;
|
||||
foreach ($this->pages as $page) {
|
||||
$pageNumber = $page->getPageNumber();
|
||||
if ($maxPageNumber === null || $pageNumber > $maxPageNumber) {
|
||||
$maxPageNumber = $pageNumber;
|
||||
$maxPage = $page;
|
||||
}
|
||||
}
|
||||
return $maxPage;
|
||||
}
|
||||
/**
|
||||
* Get the maximum Page
|
||||
*
|
||||
* @return PagingPage
|
||||
*/
|
||||
protected function getMaxPage()
|
||||
{
|
||||
$maxPageNumber = null;
|
||||
$maxPage = null;
|
||||
foreach ($this->pages as $page) {
|
||||
$pageNumber = $page->getPageNumber();
|
||||
if ($maxPageNumber === null || $pageNumber > $maxPageNumber) {
|
||||
$maxPageNumber = $pageNumber;
|
||||
$maxPage = $page;
|
||||
}
|
||||
}
|
||||
return $maxPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the array text for the Pages
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getPagesArrayText() {
|
||||
if (empty($this->pages)) {
|
||||
return Builder::getArray(array(0 => ''), true);
|
||||
}
|
||||
$pages = array();
|
||||
foreach ($this->pages as $page) {
|
||||
$pages[$page->getPageNumber()] = $page->getControl()->getId();
|
||||
}
|
||||
return Builder::getArray($pages, true);
|
||||
}
|
||||
/**
|
||||
* Build the array text for the Pages
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getPagesArrayText()
|
||||
{
|
||||
if (empty($this->pages)) {
|
||||
return Builder::getArray(array(0 => ''), true);
|
||||
}
|
||||
$pages = array();
|
||||
foreach ($this->pages as $page) {
|
||||
$pages[$page->getPageNumber()] = $page->getControl()
|
||||
->getId();
|
||||
}
|
||||
return Builder::getArray($pages, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the array text for the Page Buttons
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getPageButtonsArrayText()
|
||||
{
|
||||
if (empty($this->buttons)) {
|
||||
return Builder::getArray(array('' => 0), true);
|
||||
}
|
||||
$pageButtons = array();
|
||||
foreach ($this->buttons as $pageButton) {
|
||||
$pageButtons[$pageButton->getControl()
|
||||
->getId()] = $pageButton->getPagingCount();
|
||||
}
|
||||
return Builder::getArray($pageButtons, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the array text for the Page Buttons
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getPageButtonsArrayText() {
|
||||
if (empty($this->buttons)) {
|
||||
return Builder::getArray(array('' => 0), true);
|
||||
}
|
||||
$pageButtons = array();
|
||||
foreach ($this->buttons as $pageButton) {
|
||||
$pageButtons[$pageButton->getControl()->getId()] = $pageButton->getBrowseAction();
|
||||
}
|
||||
return Builder::getArray($pageButtons, true);
|
||||
}
|
||||
}
|
||||
|
@ -9,73 +9,89 @@ use FML\Types\Scriptable;
|
||||
* Paging Button for browsing through Pages
|
||||
*
|
||||
* @author steeffeen <mail@steeffeen.com>
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PagingButton {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
/** @var Control $control */
|
||||
protected $control = null;
|
||||
protected $browseAction = null;
|
||||
class PagingButton
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct a new Paging Button
|
||||
*
|
||||
* @param Control $control (optional) Browse Control
|
||||
* @param int $browseAction (optional) Number of browsed Pages per Click
|
||||
*/
|
||||
public function __construct(Control $control = null, $browseAction = null) {
|
||||
if ($control !== null) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
if ($browseAction !== null) {
|
||||
$this->setBrowseAction($browseAction);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @var Control $control Paging Control
|
||||
*/
|
||||
protected $control = null;
|
||||
|
||||
/**
|
||||
* Set the Button Control
|
||||
*
|
||||
* @param Control $control Browse Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control) {
|
||||
$control->checkId();
|
||||
if ($control instanceof Scriptable) {
|
||||
$control->setScriptEvents(true);
|
||||
}
|
||||
$this->control = $control;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var int Paging count
|
||||
*/
|
||||
protected $pagingCount = 1;
|
||||
|
||||
/**
|
||||
* Get the Button Control
|
||||
*
|
||||
* @return \FML\Controls\Control
|
||||
*/
|
||||
public function getControl() {
|
||||
return $this->control;
|
||||
}
|
||||
/**
|
||||
* Construct a new Paging Button
|
||||
*
|
||||
* @api
|
||||
* @param Control $control (optional) Paging Control
|
||||
* @param int $pagingCount (optional) Number of browsed pages per click
|
||||
*/
|
||||
public function __construct(Control $control = null, $pagingCount = 1)
|
||||
{
|
||||
if ($control) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
if ($pagingCount) {
|
||||
$this->setPagingCount($pagingCount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the browse action
|
||||
*
|
||||
* @param int $browseAction Number of browsed Pages per click
|
||||
* @return static
|
||||
*/
|
||||
public function setBrowseAction($browseAction) {
|
||||
$this->browseAction = (int)$browseAction;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the paging Control
|
||||
*
|
||||
* @api
|
||||
* @return Control
|
||||
*/
|
||||
public function getControl()
|
||||
{
|
||||
return $this->control;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the paging Control
|
||||
*
|
||||
* @api
|
||||
* @param Control $control Paging Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control)
|
||||
{
|
||||
$control->checkId();
|
||||
if ($control instanceof Scriptable) {
|
||||
$control->setScriptEvents(true);
|
||||
}
|
||||
$this->control = $control;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the paging count
|
||||
*
|
||||
* @api
|
||||
* @return int
|
||||
*/
|
||||
public function getPagingCount()
|
||||
{
|
||||
return $this->pagingCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the paging count
|
||||
*
|
||||
* @api
|
||||
* @param int $pagingCount Number of browsed pages per click
|
||||
* @return static
|
||||
*/
|
||||
public function setPagingCount($pagingCount)
|
||||
{
|
||||
$this->pagingCount = (int)$pagingCount;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the browse action
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getBrowseAction() {
|
||||
return $this->browseAction;
|
||||
}
|
||||
}
|
||||
|
@ -8,67 +8,86 @@ use FML\Controls\Control;
|
||||
* Paging Page
|
||||
*
|
||||
* @author steeffeen <mail@steeffeen.com>
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PagingPage {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
/** @var Control $control */
|
||||
protected $control = null;
|
||||
protected $number = null;
|
||||
class PagingPage
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct a new Paging Page
|
||||
*
|
||||
* @param Control $control (optional) Page Control
|
||||
* @param int $pageNumber (optional) Number of the Page
|
||||
*/
|
||||
public function __construct(Control $control = null, $pageNumber = 1) {
|
||||
if ($control !== null) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
$this->setPageNumber($pageNumber);
|
||||
}
|
||||
/**
|
||||
* @var Control $control Page Control
|
||||
*/
|
||||
protected $control = null;
|
||||
|
||||
/**
|
||||
* Set the Page Control
|
||||
*
|
||||
* @param Control $control Page Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control) {
|
||||
$this->control = $control->checkId();
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var int $pageNumber Page number
|
||||
*/
|
||||
protected $pageNumber = null;
|
||||
|
||||
/**
|
||||
* Get the Page Control
|
||||
*
|
||||
* @return \FML\Controls\Control
|
||||
*/
|
||||
public function getControl() {
|
||||
return $this->control;
|
||||
}
|
||||
/**
|
||||
* Construct a new Paging Page
|
||||
*
|
||||
* @api
|
||||
* @param Control $control (optional) Page Control
|
||||
* @param int $pageNumber (optional) Number of the Page
|
||||
*/
|
||||
public function __construct(Control $control = null, $pageNumber = null)
|
||||
{
|
||||
if ($control) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
if ($pageNumber) {
|
||||
$this->setPageNumber($pageNumber);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Page number
|
||||
*
|
||||
* @param int $pageNumber Number of the Page
|
||||
* @return static
|
||||
*/
|
||||
public function setPageNumber($pageNumber) {
|
||||
$this->number = (int)$pageNumber;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the Page Control
|
||||
*
|
||||
* @api
|
||||
* @return Control
|
||||
*/
|
||||
public function getControl()
|
||||
{
|
||||
return $this->control;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Page Control
|
||||
*
|
||||
* @api
|
||||
* @param Control $control Page Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control)
|
||||
{
|
||||
$control->checkId();
|
||||
$this->control = $control;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Page number
|
||||
*
|
||||
* @api
|
||||
* @return int
|
||||
*/
|
||||
public function getPageNumber()
|
||||
{
|
||||
return $this->pageNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Page number
|
||||
*
|
||||
* @api
|
||||
* @param int $pageNumber Number of the Page
|
||||
* @return static
|
||||
*/
|
||||
public function setPageNumber($pageNumber)
|
||||
{
|
||||
$this->pageNumber = (int)$pageNumber;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Page number
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPageNumber() {
|
||||
return $this->number;
|
||||
}
|
||||
}
|
||||
|
@ -12,97 +12,154 @@ use FML\Types\Scriptable;
|
||||
* Script Feature for opening a player profile
|
||||
*
|
||||
* @author steeffeen <mail@steeffeen.com>
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PlayerProfile extends ScriptFeature {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
protected $login = null;
|
||||
/** @var Control $control */
|
||||
protected $control = null;
|
||||
protected $labelName = null;
|
||||
class PlayerProfile extends ScriptFeature
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct a new Player Profile Feature
|
||||
*
|
||||
* @param string $login (optional) Player login
|
||||
* @param Control $control (optional) Action Control
|
||||
* @param string $labelName (optional) Script Label name
|
||||
*/
|
||||
public function __construct($login = null, Control $control = null, $labelName = ScriptLabel::MOUSECLICK) {
|
||||
$this->setLogin($login);
|
||||
if ($control !== null) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
$this->setLabelName($labelName);
|
||||
}
|
||||
/**
|
||||
* @var string $login Player login
|
||||
*/
|
||||
protected $login = null;
|
||||
|
||||
/**
|
||||
* Set the login of the opened player
|
||||
*
|
||||
* @param string $login Player login
|
||||
* @return static
|
||||
*/
|
||||
public function setLogin($login) {
|
||||
$this->login = $login;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var Control $control Profile Control
|
||||
*/
|
||||
protected $control = null;
|
||||
|
||||
/**
|
||||
* Set the Control
|
||||
*
|
||||
* @param Control $control Profile Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control) {
|
||||
$control->checkId();
|
||||
if ($control instanceof Scriptable) {
|
||||
$control->setScriptEvents(true);
|
||||
}
|
||||
$this->control = $control;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var string $labelName Script Label name
|
||||
*/
|
||||
protected $labelName = null;
|
||||
|
||||
/**
|
||||
* Set the label name
|
||||
*
|
||||
* @param string $labelName Script Label name
|
||||
* @return static
|
||||
*/
|
||||
public function setLabelName($labelName) {
|
||||
$this->labelName = (string)$labelName;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new Player Profile
|
||||
*
|
||||
* @api
|
||||
* @param string $login (optional) Player login
|
||||
* @param Control $control (optional) Profile Control
|
||||
* @param string $labelName (optional) Script Label name
|
||||
*/
|
||||
public function __construct($login = null, Control $control = null, $labelName = ScriptLabel::MOUSECLICK)
|
||||
{
|
||||
if ($login) {
|
||||
$this->setLogin($login);
|
||||
}
|
||||
if ($control) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
if ($labelName) {
|
||||
$this->setLabelName($labelName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Script\Features\ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script) {
|
||||
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the login of the opened player
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getLogin()
|
||||
{
|
||||
return $this->login;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText() {
|
||||
$login = Builder::escapeText($this->login, true);
|
||||
if ($this->control) {
|
||||
// Control event
|
||||
$controlId = Builder::escapeText($this->control->getId(), true);
|
||||
$scriptText = "
|
||||
/**
|
||||
* Set the login of the opened player
|
||||
*
|
||||
* @api
|
||||
* @param string $login Player login
|
||||
* @return static
|
||||
*/
|
||||
public function setLogin($login)
|
||||
{
|
||||
$this->login = (string)$login;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Profile Control
|
||||
*
|
||||
* @api
|
||||
* @return Control
|
||||
*/
|
||||
public function getControl()
|
||||
{
|
||||
return $this->control;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Profile Control
|
||||
*
|
||||
* @api
|
||||
* @param Control $control Profile Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control)
|
||||
{
|
||||
$control->checkId();
|
||||
if ($control instanceof Scriptable) {
|
||||
$control->setScriptEvents(true);
|
||||
}
|
||||
$this->control = $control;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Script Label name
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getLabelName()
|
||||
{
|
||||
return $this->labelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Script Label name
|
||||
*
|
||||
* @api
|
||||
* @param string $labelName Script Label name
|
||||
* @return static
|
||||
*/
|
||||
public function setLabelName($labelName)
|
||||
{
|
||||
$this->labelName = (string)$labelName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText()
|
||||
{
|
||||
$login = Builder::escapeText($this->login);
|
||||
|
||||
if ($this->control) {
|
||||
// Control event
|
||||
$controlId = Builder::escapeText($this->control->getId());
|
||||
return "
|
||||
if (Event.Control.ControlId == {$controlId}) {
|
||||
ShowProfile({$login});
|
||||
}";
|
||||
} else {
|
||||
// Other
|
||||
$scriptText = "
|
||||
}
|
||||
|
||||
// Other events
|
||||
return "
|
||||
ShowProfile({$login});";
|
||||
}
|
||||
return $scriptText;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
113
libs/FML/Script/Features/Preload.php
Normal file
113
libs/FML/Script/Features/Preload.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace FML\Script\Features;
|
||||
|
||||
use FML\Script\Builder;
|
||||
use FML\Script\Script;
|
||||
use FML\Script\ScriptLabel;
|
||||
|
||||
/**
|
||||
* Script Feature for Image Preloading
|
||||
*
|
||||
* @author steeffeen <mail@steeffeen.com>
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class Preload extends ScriptFeature
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string[] $imageUrls Image urls
|
||||
*/
|
||||
protected $imageUrls = array();
|
||||
|
||||
/**
|
||||
* Construct a new Preload
|
||||
*
|
||||
* @api
|
||||
* @param string[] $imageUrls (optional) Image urls
|
||||
*/
|
||||
public function __construct(array $imageUrls = null)
|
||||
{
|
||||
if ($imageUrls) {
|
||||
$this->setImageUrls($imageUrls);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Image Urls to preload
|
||||
*
|
||||
* @api
|
||||
* @return string[]
|
||||
*/
|
||||
public function getImageUrls()
|
||||
{
|
||||
return $this->imageUrls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an Image Url to preload
|
||||
*
|
||||
* @api
|
||||
* @param string $imageUrl Image Url
|
||||
* @return static
|
||||
*/
|
||||
public function addImageUrl($imageUrl)
|
||||
{
|
||||
if (!in_array($imageUrl, $this->imageUrls)) {
|
||||
array_push($this->imageUrls, $imageUrl);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Image Urls to preload
|
||||
*
|
||||
* @api
|
||||
* @param string[] $imageUrls Image Urls
|
||||
* @return static
|
||||
*/
|
||||
public function setImageUrls(array $imageUrls = array())
|
||||
{
|
||||
$this->imageUrls = $imageUrls;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all Image Urls
|
||||
*
|
||||
* @api
|
||||
* @return static
|
||||
*/
|
||||
public function removeAllImageUrls()
|
||||
{
|
||||
$this->imageUrls = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->getScriptText());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText()
|
||||
{
|
||||
$scriptText = "";
|
||||
foreach ($this->imageUrls as $imageUrl) {
|
||||
$escapedImageUrl = Builder::escapeText($imageUrl);
|
||||
$scriptText .= "
|
||||
PreloadImage({$escapedImageUrl});";
|
||||
}
|
||||
return $scriptText;
|
||||
}
|
||||
|
||||
}
|
@ -9,34 +9,37 @@ use FML\Types\ScriptFeatureable;
|
||||
* ManiaLink Script Feature Class
|
||||
*
|
||||
* @author steeffeen <mail@steeffeen.com>
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
abstract class ScriptFeature {
|
||||
abstract class ScriptFeature
|
||||
{
|
||||
|
||||
/**
|
||||
* Collect the Script Features of the given objects
|
||||
*
|
||||
* @return ScriptFeature[]
|
||||
*/
|
||||
public static function collect() {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
return $scriptFeatures;
|
||||
}
|
||||
/**
|
||||
* Collect the Script Features of the given objects
|
||||
*
|
||||
* @return ScriptFeature[]
|
||||
*/
|
||||
public static function collect()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
||||
return $scriptFeatures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the given Script for rendering by adding the needed Labels, etc.
|
||||
*
|
||||
* @param Script $script Script to prepare
|
||||
* @return static
|
||||
*/
|
||||
public abstract function prepare(Script $script);
|
||||
|
||||
/**
|
||||
* Prepare the given Script for rendering by adding the needed Labels, etc.
|
||||
*
|
||||
* @param Script $script Script to prepare
|
||||
* @return static
|
||||
*/
|
||||
public abstract function prepare(Script $script);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace FML\Script\Features;
|
||||
|
||||
use FML\Controls\Control;
|
||||
use FML\Script\Builder;
|
||||
use FML\Script\Script;
|
||||
use FML\Script\ScriptLabel;
|
||||
use FML\Types\Scriptable;
|
||||
@ -11,128 +12,231 @@ use FML\Types\Scriptable;
|
||||
* Script Feature for toggling Controls
|
||||
*
|
||||
* @author steeffeen <mail@steeffeen.com>
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class Toggle extends ScriptFeature {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
/** @var Control $togglingControl */
|
||||
protected $togglingControl = null;
|
||||
/** @var Control $toggledControl */
|
||||
protected $toggledControl = null;
|
||||
protected $labelName = null;
|
||||
protected $onlyShow = null;
|
||||
protected $onlyHide = null;
|
||||
class Toggle extends ScriptFeature
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct a new Toggle Feature
|
||||
*
|
||||
* @param Control $togglingControl (optional) Toggling Control
|
||||
* @param Control $toggledControl (optional) Toggled Control
|
||||
* @param string $labelName (optional) Script Label name
|
||||
* @param bool $onlyShow (optional) Whether it should only show the Control but not toggle
|
||||
* @param bool $onlyHide (optional) Whether it should only hide the Control but not toggle
|
||||
*/
|
||||
public function __construct(Control $togglingControl = null, Control $toggledControl = null, $labelName = ScriptLabel::MOUSECLICK,
|
||||
$onlyShow = false, $onlyHide = false) {
|
||||
if ($togglingControl !== null) {
|
||||
$this->setTogglingControl($togglingControl);
|
||||
}
|
||||
if ($toggledControl !== null) {
|
||||
$this->setToggledControl($toggledControl);
|
||||
}
|
||||
$this->setLabelName($labelName);
|
||||
$this->setOnlyShow($onlyShow);
|
||||
$this->setOnlyHide($onlyHide);
|
||||
}
|
||||
/**
|
||||
* @var Control $togglingControl Toggling Control
|
||||
*/
|
||||
protected $togglingControl = null;
|
||||
|
||||
/**
|
||||
* Set the toggling Control
|
||||
*
|
||||
* @param Control $control Toggling Control
|
||||
* @return static
|
||||
*/
|
||||
public function setTogglingControl(Control $control) {
|
||||
$control->checkId();
|
||||
if ($control instanceof Scriptable) {
|
||||
$control->setScriptEvents(true);
|
||||
}
|
||||
$this->togglingControl = $control;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var Control $toggledControl Toggled Control
|
||||
*/
|
||||
protected $toggledControl = null;
|
||||
|
||||
/**
|
||||
* Set the toggled Control
|
||||
*
|
||||
* @param Control $control Toggling Control
|
||||
* @return static
|
||||
*/
|
||||
public function setToggledControl(Control $control) {
|
||||
$this->toggledControl = $control->checkId();
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var $labelName Script Label name
|
||||
*/
|
||||
protected $labelName = null;
|
||||
|
||||
/**
|
||||
* Set the label name
|
||||
*
|
||||
* @param string $labelName Script Label Name
|
||||
* @return static
|
||||
*/
|
||||
public function setLabelName($labelName) {
|
||||
$this->labelName = (string)$labelName;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var bool $onlyShow Show only
|
||||
*/
|
||||
protected $onlyShow = null;
|
||||
|
||||
/**
|
||||
* Set to only show
|
||||
*
|
||||
* @param bool $onlyShow Whether it should only show the Control but not toggle
|
||||
* @return static
|
||||
*/
|
||||
public function setOnlyShow($onlyShow) {
|
||||
$this->onlyShow = (bool)$onlyShow;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var bool $onlyHide Hide only
|
||||
*/
|
||||
protected $onlyHide = null;
|
||||
|
||||
/**
|
||||
* Set to only hide
|
||||
*
|
||||
* @param bool $onlyHide Whether it should only hide the Control but not toggle
|
||||
* @return static
|
||||
*/
|
||||
public function setOnlyHide($onlyHide) {
|
||||
$this->onlyHide = (bool)$onlyHide;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new Toggle
|
||||
*
|
||||
* @api
|
||||
* @param Control $togglingControl (optional) Toggling Control
|
||||
* @param Control $toggledControl (optional) Toggled Control
|
||||
* @param string $labelName (optional) Script Label name
|
||||
* @param bool $onlyShow (optional) If it should only show the Control but not toggle
|
||||
* @param bool $onlyHide (optional) If it should only hide the Control but not toggle
|
||||
*/
|
||||
public function __construct(
|
||||
Control $togglingControl = null,
|
||||
Control $toggledControl = null,
|
||||
$labelName = ScriptLabel::MOUSECLICK,
|
||||
$onlyShow = false,
|
||||
$onlyHide = false
|
||||
) {
|
||||
if ($togglingControl) {
|
||||
$this->setTogglingControl($togglingControl);
|
||||
}
|
||||
if ($toggledControl) {
|
||||
$this->setToggledControl($toggledControl);
|
||||
}
|
||||
if ($labelName) {
|
||||
$this->setLabelName($labelName);
|
||||
}
|
||||
if ($onlyShow) {
|
||||
$this->setOnlyShow($onlyShow);
|
||||
}
|
||||
if ($onlyHide) {
|
||||
$this->setOnlyHide($onlyHide);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Script\Features\ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script) {
|
||||
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the toggling Control
|
||||
*
|
||||
* @api
|
||||
* @return Control
|
||||
*/
|
||||
public function getTogglingControl()
|
||||
{
|
||||
return $this->togglingControl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText() {
|
||||
$togglingControlId = $this->togglingControl->getId(true, true);
|
||||
$toggledControlId = $this->toggledControl->getId(true, true);
|
||||
$visibility = '!ToggleControl.Visible';
|
||||
if ($this->onlyShow) {
|
||||
$visibility = 'True';
|
||||
} else if ($this->onlyHide) {
|
||||
$visibility = 'False';
|
||||
}
|
||||
return "
|
||||
/**
|
||||
* Set the toggling Control
|
||||
*
|
||||
* @api
|
||||
* @param Control $control Toggling Control
|
||||
* @return static
|
||||
*/
|
||||
public function setTogglingControl(Control $control)
|
||||
{
|
||||
$control->checkId();
|
||||
if ($control instanceof Scriptable) {
|
||||
$control->setScriptEvents(true);
|
||||
}
|
||||
$this->togglingControl = $control;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the toggled Control
|
||||
*
|
||||
* @api
|
||||
* @return Control
|
||||
*/
|
||||
public function getToggledControl()
|
||||
{
|
||||
return $this->toggledControl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the toggled Control
|
||||
*
|
||||
* @api
|
||||
* @param Control $control Toggled Control
|
||||
* @return static
|
||||
*/
|
||||
public function setToggledControl(Control $control)
|
||||
{
|
||||
$control->checkId();
|
||||
$this->toggledControl = $control;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Script Label name
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getLabelName()
|
||||
{
|
||||
return $this->labelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Script Label name
|
||||
*
|
||||
* @api
|
||||
* @param string $labelName Script Label Name
|
||||
* @return static
|
||||
*/
|
||||
public function setLabelName($labelName)
|
||||
{
|
||||
$this->labelName = (string)$labelName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Show Only
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function getOnlyShow()
|
||||
{
|
||||
return $this->onlyShow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Show Only
|
||||
*
|
||||
* @api
|
||||
* @param bool $onlyShow If it should only show the Control but not toggle
|
||||
* @return static
|
||||
*/
|
||||
public function setOnlyShow($onlyShow)
|
||||
{
|
||||
$this->onlyShow = (bool)$onlyShow;
|
||||
if ($this->onlyShow) {
|
||||
$this->onlyHide = null;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Hide Only
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function getOnlyHide()
|
||||
{
|
||||
return $this->onlyHide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Hide Only
|
||||
*
|
||||
* @api
|
||||
* @param bool $onlyHide If it should only hide the Control but not toggle
|
||||
* @return static
|
||||
*/
|
||||
public function setOnlyHide($onlyHide)
|
||||
{
|
||||
$this->onlyHide = (bool)$onlyHide;
|
||||
if ($this->onlyHide) {
|
||||
$this->onlyShow = null;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText()
|
||||
{
|
||||
$togglingControlId = Builder::escapeText($this->togglingControl->getId());
|
||||
$toggledControlId = Builder::escapeText($this->toggledControl->getId());
|
||||
$visibility = "!ToggleControl.Visible";
|
||||
if ($this->onlyShow) {
|
||||
$visibility = "True";
|
||||
} else if ($this->onlyHide) {
|
||||
$visibility = "False";
|
||||
}
|
||||
return "
|
||||
if (Event.Control.ControlId == {$togglingControlId}) {
|
||||
declare ToggleControl = Page.GetFirstChild({$toggledControlId});
|
||||
ToggleControl.Visible = {$visibility};
|
||||
}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,150 +13,241 @@ use FML\Types\Scriptable;
|
||||
* Script Feature for showing Tooltips
|
||||
*
|
||||
* @author steeffeen <mail@steeffeen.com>
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class Tooltip extends ScriptFeature {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
/** @var Control $hoverControl */
|
||||
protected $hoverControl = null;
|
||||
/** @var Control $tooltipControl */
|
||||
protected $tooltipControl = null;
|
||||
protected $stayOnClick = null;
|
||||
protected $invert = null;
|
||||
protected $text = null;
|
||||
class Tooltip extends ScriptFeature
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct a new Tooltip Feature
|
||||
*
|
||||
* @param Control $hoverControl (optional) Hover Control
|
||||
* @param Control $tooltipControl (optional) Tooltip Control
|
||||
* @param bool $stayOnClick (optional) Whether the Tooltip should stay on click
|
||||
* @param bool $invert (optional) Whether the visibility toggling should be inverted
|
||||
* @param string $text (optional) Text to display if the TooltipControl is a Label
|
||||
*/
|
||||
public function __construct(Control $hoverControl = null, Control $tooltipControl = null, $stayOnClick = false, $invert = false, $text = null) {
|
||||
if ($hoverControl !== null) {
|
||||
$this->setHoverControl($hoverControl);
|
||||
}
|
||||
if ($tooltipControl !== null) {
|
||||
$this->setTooltipControl($tooltipControl);
|
||||
}
|
||||
$this->setStayOnClick($stayOnClick);
|
||||
$this->setInvert($invert);
|
||||
if ($text !== null) {
|
||||
$this->setText($text);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @var Control $hoverControl Hover Control
|
||||
*/
|
||||
protected $hoverControl = null;
|
||||
|
||||
/**
|
||||
* Set the Hover Control
|
||||
*
|
||||
* @param Control $hoverControl Hover Control
|
||||
* @return static
|
||||
*/
|
||||
public function setHoverControl(Control $hoverControl) {
|
||||
$hoverControl->checkId();
|
||||
if ($hoverControl instanceof Scriptable) {
|
||||
$hoverControl->setScriptEvents(true);
|
||||
}
|
||||
$this->hoverControl = $hoverControl;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var Control $tooltipControl Tooltip Control
|
||||
*/
|
||||
protected $tooltipControl = null;
|
||||
|
||||
/**
|
||||
* Set the Tooltip Control
|
||||
*
|
||||
* @param Control $tooltipControl Tooltip Control
|
||||
* @return static
|
||||
*/
|
||||
public function setTooltipControl(Control $tooltipControl) {
|
||||
$this->tooltipControl = $tooltipControl->checkId()->setVisible(false);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var bool $stayOnClick Stay on click
|
||||
*/
|
||||
protected $stayOnClick = null;
|
||||
|
||||
/**
|
||||
* Set to only show
|
||||
*
|
||||
* @param bool $stayOnClick (optional) Whether the Tooltip should stay on click
|
||||
* @return static
|
||||
*/
|
||||
public function setStayOnClick($stayOnClick) {
|
||||
$this->stayOnClick = (bool)$stayOnClick;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var bool $invert Inverted visibility toggling
|
||||
*/
|
||||
protected $invert = null;
|
||||
|
||||
/**
|
||||
* Set to only hide
|
||||
*
|
||||
* @param bool $invert (optional) Whether the visibility toggling should be inverted
|
||||
* @return static
|
||||
*/
|
||||
public function setInvert($invert) {
|
||||
$this->invert = (bool)$invert;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var string $text Tooltip Text
|
||||
*/
|
||||
protected $text = null;
|
||||
|
||||
/**
|
||||
* Set text
|
||||
*
|
||||
* @param string $text (optional) Text to display if the TooltipControl is a Label
|
||||
* @return static
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = (string)$text;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new Tooltip
|
||||
*
|
||||
* @api
|
||||
* @param Control $hoverControl (optional) Hover Control
|
||||
* @param Control $tooltipControl (optional) Tooltip Control
|
||||
* @param bool $stayOnClick (optional) If the Tooltip should stay on click
|
||||
* @param bool $invert (optional) If the visibility toggling should be inverted
|
||||
* @param string $text (optional) Text to display if the TooltipControl is a Label
|
||||
*/
|
||||
public function __construct(Control $hoverControl = null, Control $tooltipControl = null, $stayOnClick = null, $invert = null, $text = null)
|
||||
{
|
||||
if ($hoverControl) {
|
||||
$this->setHoverControl($hoverControl);
|
||||
}
|
||||
if ($tooltipControl) {
|
||||
$this->setTooltipControl($tooltipControl);
|
||||
}
|
||||
if ($stayOnClick) {
|
||||
$this->setStayOnClick($stayOnClick);
|
||||
}
|
||||
if ($invert) {
|
||||
$this->setInvert($invert);
|
||||
}
|
||||
if ($text) {
|
||||
$this->setText($text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Script\Features\ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script) {
|
||||
$hoverControlId = $this->hoverControl->getId(true, true);
|
||||
$tooltipControlId = $this->tooltipControl->getId(true, true);
|
||||
/**
|
||||
* Get the Hover Control
|
||||
*
|
||||
* @api
|
||||
* @return Control
|
||||
*/
|
||||
public function getHoverControl()
|
||||
{
|
||||
return $this->hoverControl;
|
||||
}
|
||||
|
||||
// MouseOver
|
||||
$visibility = ($this->invert ? 'False' : 'True');
|
||||
$scriptText = "
|
||||
/**
|
||||
* Set the Hover Control
|
||||
*
|
||||
* @api
|
||||
* @param Control $hoverControl Hover Control
|
||||
* @return static
|
||||
*/
|
||||
public function setHoverControl(Control $hoverControl)
|
||||
{
|
||||
$hoverControl->checkId();
|
||||
if ($hoverControl instanceof Scriptable) {
|
||||
$hoverControl->setScriptEvents(true);
|
||||
}
|
||||
$this->hoverControl = $hoverControl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Tooltip Control
|
||||
*
|
||||
* @api
|
||||
* @return Control
|
||||
*/
|
||||
public function getTooltipControl()
|
||||
{
|
||||
return $this->tooltipControl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Tooltip Control
|
||||
*
|
||||
* @api
|
||||
* @param Control $tooltipControl Tooltip Control
|
||||
* @return static
|
||||
*/
|
||||
public function setTooltipControl(Control $tooltipControl)
|
||||
{
|
||||
$tooltipControl->checkId();
|
||||
$tooltipControl->setVisible(false);
|
||||
$this->tooltipControl = $tooltipControl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the staying on click
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function getStayOnClick()
|
||||
{
|
||||
return $this->stayOnClick;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the staying on click
|
||||
*
|
||||
* @api
|
||||
* @param bool $stayOnClick If the Tooltip should stay on click
|
||||
* @return static
|
||||
*/
|
||||
public function setStayOnClick($stayOnClick)
|
||||
{
|
||||
$this->stayOnClick = (bool)$stayOnClick;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get inverting of the visibility
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function getInvert()
|
||||
{
|
||||
return $this->invert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set inverting of the visibility
|
||||
*
|
||||
* @api
|
||||
* @param bool $invert If the visibility toggling should be inverted
|
||||
* @return static
|
||||
*/
|
||||
public function setInvert($invert)
|
||||
{
|
||||
$this->invert = (bool)$invert;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getText()
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text
|
||||
*
|
||||
* @api
|
||||
* @param string $text Text to display if the TooltipControl is a Label
|
||||
* @return static
|
||||
*/
|
||||
public function setText($text)
|
||||
{
|
||||
$this->text = (string)$text;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$hoverControlId = Builder::escapeText($this->hoverControl->getId());
|
||||
$tooltipControlId = Builder::escapeText($this->tooltipControl->getId());
|
||||
|
||||
// MouseOver
|
||||
$visibility = Builder::getBoolean(!$this->invert);
|
||||
$scriptText = "
|
||||
if (Event.Control.ControlId == {$hoverControlId}) {
|
||||
declare TooltipControl = Page.GetFirstChild({$tooltipControlId});
|
||||
TooltipControl.Visible = {$visibility};";
|
||||
if (is_string($this->text) && ($this->tooltipControl instanceof Label)) {
|
||||
$tooltipText = Builder::escapeText($this->text, true);
|
||||
$scriptText .= "
|
||||
if (is_string($this->text) && ($this->tooltipControl instanceof Label)) {
|
||||
$tooltipText = Builder::escapeText($this->text);
|
||||
$scriptText .= "
|
||||
declare TooltipLabel = (TooltipControl as CMlLabel);
|
||||
TooltipLabel.Value = {$tooltipText};";
|
||||
}
|
||||
$scriptText .= "
|
||||
}
|
||||
$scriptText .= "
|
||||
}";
|
||||
$script->appendGenericScriptLabel(ScriptLabel::MOUSEOVER, $scriptText);
|
||||
$script->appendGenericScriptLabel(ScriptLabel::MOUSEOVER, $scriptText);
|
||||
|
||||
// MouseOut
|
||||
$visibility = ($this->invert ? 'True' : 'False');
|
||||
$scriptText = "
|
||||
// MouseOut
|
||||
$visibility = Builder::getBoolean($this->invert);
|
||||
$scriptText = "
|
||||
if (Event.Control.ControlId == {$hoverControlId}) {
|
||||
declare TooltipControl = Page.GetFirstChild({$tooltipControlId});";
|
||||
if ($this->stayOnClick) {
|
||||
$scriptText .= "
|
||||
if ($this->stayOnClick) {
|
||||
$scriptText .= "
|
||||
declare FML_Clicked for Event.Control = False;
|
||||
if (!FML_Clicked) ";
|
||||
}
|
||||
$scriptText .= "
|
||||
}
|
||||
$scriptText .= "
|
||||
TooltipControl.Visible = {$visibility};
|
||||
}";
|
||||
$script->appendGenericScriptLabel(ScriptLabel::MOUSEOUT, $scriptText);
|
||||
$script->appendGenericScriptLabel(ScriptLabel::MOUSEOUT, $scriptText);
|
||||
|
||||
// MouseClick
|
||||
if ($this->stayOnClick) {
|
||||
$scriptText = "
|
||||
// MouseClick
|
||||
if ($this->stayOnClick) {
|
||||
$scriptText = "
|
||||
if (Event.Control.ControlId == {$hoverControlId}) {
|
||||
declare FML_Clicked for Event.Control = False;
|
||||
FML_Clicked = !FML_Clicked;
|
||||
}";
|
||||
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $scriptText);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $scriptText);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,157 +12,249 @@ use FML\Types\Scriptable;
|
||||
* Script Feature for playing a UISound
|
||||
*
|
||||
* @author steeffeen <mail@steeffeen.com>
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class UISound extends ScriptFeature {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const Bonus = 'Bonus';
|
||||
const Capture = 'Capture';
|
||||
const Checkpoint = 'Checkpoint';
|
||||
const Combo = 'Combo';
|
||||
const Custom1 = 'Custom1';
|
||||
const Custom2 = 'Custom2';
|
||||
const Custom3 = 'Custom3';
|
||||
const Custom4 = 'Custom4';
|
||||
const Default_ = 'Default';
|
||||
const EndMatch = 'EndMatch';
|
||||
const EndRound = 'EndRound';
|
||||
const Finish = 'Finish';
|
||||
const FirstHit = 'FirstHit';
|
||||
const Notice = 'Notice';
|
||||
const PhaseChange = 'PhaseChange';
|
||||
const PlayerEliminated = 'PlayerEliminated';
|
||||
const PlayerHit = 'PlayerHit';
|
||||
const PlayersRemaining = 'PlayersRemaining';
|
||||
const RankChange = 'RankChange';
|
||||
const Record = 'Record';
|
||||
const ScoreProgress = 'ScoreProgress';
|
||||
const Silence = 'Silence';
|
||||
const StartMatch = 'StartMatch';
|
||||
const StartRound = 'StartRound';
|
||||
const TieBreakPoint = 'TieBreakPoint';
|
||||
const TiePoint = 'TiePoint';
|
||||
const TimeOut = 'TimeOut';
|
||||
const VictoryPoint = 'VictoryPoint';
|
||||
const Warning = 'Warning';
|
||||
class UISound extends ScriptFeature
|
||||
{
|
||||
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
protected $soundName = null;
|
||||
/** @var Control $control */
|
||||
protected $control = null;
|
||||
protected $variant = 0;
|
||||
protected $volume = 1.;
|
||||
protected $labelName = null;
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const Bonus = "Bonus";
|
||||
const Capture = "Capture";
|
||||
const Checkpoint = "Checkpoint";
|
||||
const Combo = "Combo";
|
||||
const Custom1 = "Custom1";
|
||||
const Custom2 = "Custom2";
|
||||
const Custom3 = "Custom3";
|
||||
const Custom4 = "Custom4";
|
||||
const Default_ = "Default";
|
||||
const EndMatch = "EndMatch";
|
||||
const EndRound = "EndRound";
|
||||
const Finish = "Finish";
|
||||
const FirstHit = "FirstHit";
|
||||
const Notice = "Notice";
|
||||
const PhaseChange = "PhaseChange";
|
||||
const PlayerEliminated = "PlayerEliminated";
|
||||
const PlayerHit = "PlayerHit";
|
||||
const PlayersRemaining = "PlayersRemaining";
|
||||
const RankChange = "RankChange";
|
||||
const Record = "Record";
|
||||
const ScoreProgress = "ScoreProgress";
|
||||
const Silence = "Silence";
|
||||
const StartMatch = "StartMatch";
|
||||
const StartRound = "StartRound";
|
||||
const TieBreakPoint = "TieBreakPoint";
|
||||
const TiePoint = "TiePoint";
|
||||
const TimeOut = "TimeOut";
|
||||
const VictoryPoint = "VictoryPoint";
|
||||
const Warning = "Warning";
|
||||
|
||||
/**
|
||||
* Construct a new UISound Feature
|
||||
*
|
||||
* @param string $soundName (optional) Played sound
|
||||
* @param Control $control (optional) Action Control
|
||||
* @param int $variant (optional) Sound variant
|
||||
* @param string $labelName (optional) Script Label name
|
||||
*/
|
||||
public function __construct($soundName = null, Control $control = null, $variant = 0, $labelName = ScriptLabel::MOUSECLICK) {
|
||||
if ($soundName !== null) {
|
||||
$this->setSoundName($soundName);
|
||||
}
|
||||
if ($control !== null) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
$this->setVariant($variant);
|
||||
$this->setLabelName($labelName);
|
||||
}
|
||||
/**
|
||||
* @var string $soundName Sound name
|
||||
*/
|
||||
protected $soundName = null;
|
||||
|
||||
/**
|
||||
* Set the sound to play
|
||||
*
|
||||
* @param string $soundName Sound name
|
||||
* @return static
|
||||
*/
|
||||
public function setSoundName($soundName) {
|
||||
$this->soundName = (string)$soundName;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var Control $control Sound Control
|
||||
*/
|
||||
protected $control = null;
|
||||
|
||||
/**
|
||||
* Set the Control
|
||||
*
|
||||
* @param Control $control Action Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control) {
|
||||
$control->checkId();
|
||||
if ($control instanceof Scriptable) {
|
||||
$control->setScriptEvents(true);
|
||||
}
|
||||
$this->control = $control;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var int $variant Sound variant
|
||||
*/
|
||||
protected $variant = 0;
|
||||
|
||||
/**
|
||||
* Set the sound variant
|
||||
*
|
||||
* @param int $variant Sound variant
|
||||
* @return static
|
||||
*/
|
||||
public function setVariant($variant) {
|
||||
$this->variant = (int)$variant;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var string $labelName Script Label name
|
||||
*/
|
||||
protected $labelName = null;
|
||||
|
||||
/**
|
||||
* Set the volume
|
||||
*
|
||||
* @param float $volume Sound volume
|
||||
* @return static
|
||||
*/
|
||||
public function setVolume($volume) {
|
||||
$this->volume = (float)$volume;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var float $volume Volume
|
||||
*/
|
||||
protected $volume = 1.;
|
||||
|
||||
/**
|
||||
* Set the label name
|
||||
*
|
||||
* @param string $labelName Script Label name
|
||||
* @return static
|
||||
*/
|
||||
public function setLabelName($labelName) {
|
||||
$this->labelName = (string)$labelName;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new UISound
|
||||
*
|
||||
* @api
|
||||
* @param string $soundName (optional) Sound name
|
||||
* @param Control $control (optional) Sound Control
|
||||
* @param int $variant (optional) Sound variant
|
||||
* @param string $labelName (optional) Script Label name
|
||||
*/
|
||||
public function __construct($soundName = null, Control $control = null, $variant = 0, $labelName = ScriptLabel::MOUSECLICK)
|
||||
{
|
||||
if ($soundName) {
|
||||
$this->setSoundName($soundName);
|
||||
}
|
||||
if ($control) {
|
||||
$this->setControl($control);
|
||||
}
|
||||
if ($variant) {
|
||||
$this->setVariant($variant);
|
||||
}
|
||||
if ($labelName) {
|
||||
$this->setLabelName($labelName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Script\Features\ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script) {
|
||||
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the sound to play
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getSoundName()
|
||||
{
|
||||
return $this->soundName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText() {
|
||||
if ($this->control) {
|
||||
// Control event
|
||||
$controlId = Builder::escapeText($this->control->getId(), true);
|
||||
$scriptText = "
|
||||
/**
|
||||
* Set the sound to play
|
||||
*
|
||||
* @api
|
||||
* @param string $soundName Sound name
|
||||
* @return static
|
||||
*/
|
||||
public function setSoundName($soundName)
|
||||
{
|
||||
$this->soundName = (string)$soundName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sound Control
|
||||
*
|
||||
* @api
|
||||
* @return Control
|
||||
*/
|
||||
public function getControl()
|
||||
{
|
||||
return $this->control;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sound Control
|
||||
*
|
||||
* @api
|
||||
* @param Control $control (optional) Sound Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control = null)
|
||||
{
|
||||
if ($control) {
|
||||
$control->checkId();
|
||||
if ($control instanceof Scriptable) {
|
||||
$control->setScriptEvents(true);
|
||||
}
|
||||
}
|
||||
$this->control = $control;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sound variant
|
||||
*
|
||||
* @api
|
||||
* @return int
|
||||
*/
|
||||
public function getVariant()
|
||||
{
|
||||
return $this->variant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sound variant
|
||||
*
|
||||
* @api
|
||||
* @param int $variant Sound variant
|
||||
* @return static
|
||||
*/
|
||||
public function setVariant($variant)
|
||||
{
|
||||
$this->variant = (int)$variant;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Script Label name
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getLabelName()
|
||||
{
|
||||
return $this->labelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Script Label name
|
||||
*
|
||||
* @api
|
||||
* @param string $labelName Script Label name
|
||||
* @return static
|
||||
*/
|
||||
public function setLabelName($labelName)
|
||||
{
|
||||
$this->labelName = (string)$labelName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the volume
|
||||
*
|
||||
* @api
|
||||
* @return float
|
||||
*/
|
||||
public function getVolume()
|
||||
{
|
||||
return $this->volume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the volume
|
||||
*
|
||||
* @api
|
||||
* @param float $volume Sound volume
|
||||
* @return static
|
||||
*/
|
||||
public function setVolume($volume)
|
||||
{
|
||||
$this->volume = (float)$volume;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptText()
|
||||
{
|
||||
if ($this->control) {
|
||||
// Control event
|
||||
$controlId = Builder::escapeText($this->control->getId());
|
||||
return "
|
||||
if (Event.Control.ControlId == {$controlId}) {
|
||||
PlayUiSound(CMlScriptIngame::EUISound::{$this->soundName}, {$this->variant}, {$this->volume});
|
||||
}";
|
||||
} else {
|
||||
// Other
|
||||
$scriptText = "
|
||||
}
|
||||
|
||||
// Other events
|
||||
return "
|
||||
PlayUiSound(CMlScriptIngame::EUISound::{$this->soundName}, {$this->variant}, {$this->volume});";
|
||||
}
|
||||
return $scriptText;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,150 +13,211 @@ use FML\Script\ScriptLabel;
|
||||
* Script Feature for creating a ValuePicker behavior
|
||||
*
|
||||
* @author steeffeen <mail@steeffeen.com>
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 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';
|
||||
class ValuePickerFeature extends ScriptFeature
|
||||
{
|
||||
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
/** @var Label $label */
|
||||
protected $label = null;
|
||||
/** @var Entry $entry */
|
||||
protected $entry = null;
|
||||
protected $values = array();
|
||||
protected $default = null;
|
||||
/*
|
||||
* 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";
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if ($label !== null) {
|
||||
$this->setLabel($label);
|
||||
}
|
||||
if ($entry !== null) {
|
||||
$this->setEntry($entry);
|
||||
}
|
||||
if (!empty($values)) {
|
||||
$this->setValues($values);
|
||||
}
|
||||
if ($default !== null) {
|
||||
$this->setDefault($default);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @var Label $label Label
|
||||
*/
|
||||
protected $label = null;
|
||||
|
||||
/**
|
||||
* Set the ValuePicker Label
|
||||
*
|
||||
* @param Label $label ValuePicker Label
|
||||
* @return static
|
||||
*/
|
||||
public function setLabel(Label $label) {
|
||||
$this->label = $label->checkId()->setScriptEvents(true);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var Entry $entry Hidden Entry
|
||||
*/
|
||||
protected $entry = null;
|
||||
|
||||
/**
|
||||
* Get the ValuePicker Label
|
||||
*
|
||||
* @return \FML\Controls\Label
|
||||
*/
|
||||
public function getLabel() {
|
||||
return $this->label;
|
||||
}
|
||||
/**
|
||||
* @var string[] $values Possible values
|
||||
*/
|
||||
protected $values = array();
|
||||
|
||||
/**
|
||||
* Set the hidden Entry
|
||||
*
|
||||
* @param Entry $entry Hidden Entry
|
||||
* @return static
|
||||
*/
|
||||
public function setEntry(Entry $entry) {
|
||||
$this->entry = $entry->checkId();
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var string $default Default value
|
||||
*/
|
||||
protected $default = null;
|
||||
|
||||
/**
|
||||
* Get the hidden Entry
|
||||
*
|
||||
* @return \FML\Controls\Entry
|
||||
*/
|
||||
public function getEntry() {
|
||||
return $this->entry;
|
||||
}
|
||||
/**
|
||||
* Construct a new ValuePicker Feature
|
||||
*
|
||||
* @api
|
||||
* @param Label $label (optional) Label
|
||||
* @param Entry $entry (optional) Hidden Entry
|
||||
* @param string[] $values (optional) Possible values
|
||||
* @param string $default (optional) Default value
|
||||
*/
|
||||
public function __construct(Label $label = null, Entry $entry = null, array $values = null, $default = null)
|
||||
{
|
||||
if ($label) {
|
||||
$this->setLabel($label);
|
||||
}
|
||||
if ($entry) {
|
||||
$this->setEntry($entry);
|
||||
}
|
||||
if ($values && !empty($values)) {
|
||||
$this->setValues($values);
|
||||
}
|
||||
if ($default !== null) {
|
||||
$this->setDefault($default);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the possible values
|
||||
*
|
||||
* @param array $values Possible values
|
||||
* @return static
|
||||
*/
|
||||
public function setValues(array $values) {
|
||||
$this->values = array();
|
||||
foreach ($values as $value) {
|
||||
array_push($this->values, (string)$value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the Label
|
||||
*
|
||||
* @api
|
||||
* @return Label
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default value
|
||||
*
|
||||
* @param string $default Default value
|
||||
* @return static
|
||||
*/
|
||||
public function setDefault($default) {
|
||||
$this->default = (string)$default;
|
||||
}
|
||||
/**
|
||||
* Set the Label
|
||||
*
|
||||
* @api
|
||||
* @param Label $label Label
|
||||
* @return static
|
||||
*/
|
||||
public function setLabel(Label $label)
|
||||
{
|
||||
$label->checkId();
|
||||
$label->setScriptEvents(true);
|
||||
$this->label = $label;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefault() {
|
||||
if ($this->default) {
|
||||
return $this->default;
|
||||
}
|
||||
if (!empty($this->values)) {
|
||||
return reset($this->values);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Get the hidden Entry
|
||||
*
|
||||
* @api
|
||||
* @return Entry
|
||||
*/
|
||||
public function getEntry()
|
||||
{
|
||||
return $this->entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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::MOUSECLICK, $this->buildClickScriptText());
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Set the hidden Entry
|
||||
*
|
||||
* @api
|
||||
* @param Entry $entry Hidden Entry
|
||||
* @return static
|
||||
*/
|
||||
public function setEntry(Entry $entry)
|
||||
{
|
||||
$entry->checkId();
|
||||
$this->entry = $entry;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the function text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildUpdatePickerValueFunction() {
|
||||
return "
|
||||
/**
|
||||
* Get the possible values
|
||||
*
|
||||
* @api
|
||||
* @return string[]
|
||||
*/
|
||||
public function getValues()
|
||||
{
|
||||
return $this->values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a possible value
|
||||
*
|
||||
* @api
|
||||
* @param string $value Possible value
|
||||
* @return static
|
||||
*/
|
||||
public function addValue($value)
|
||||
{
|
||||
array_push($this->values, (string)$value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the possible values
|
||||
*
|
||||
* @api
|
||||
* @param string[] $values Possible values
|
||||
* @return static
|
||||
*/
|
||||
public function setValues(array $values)
|
||||
{
|
||||
$this->values = array();
|
||||
foreach ($values as $value) {
|
||||
$this->addValue($value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default value
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
if ($this->default) {
|
||||
return $this->default;
|
||||
}
|
||||
if (!empty($this->values)) {
|
||||
return reset($this->values);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default value
|
||||
*
|
||||
* @api
|
||||
* @param string $default Default value
|
||||
* @return static
|
||||
*/
|
||||
public function setDefault($default)
|
||||
{
|
||||
$this->default = (string)$default;
|
||||
if ($this->default && !in_array($this->default, $this->values, true)) {
|
||||
$this->addValue($this->default);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see 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::MOUSECLICK, $this->buildClickScriptText());
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the function text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildUpdatePickerValueFunction()
|
||||
{
|
||||
return "
|
||||
Void " . self::FUNCTION_UPDATE_PICKER_VALUE . "(CMlLabel _Label) {
|
||||
declare " . self::VAR_PICKER_VALUES . " as Values for _Label = Text[];
|
||||
declare NewValueIndex = -1;
|
||||
@ -169,58 +230,63 @@ Void " . self::FUNCTION_UPDATE_PICKER_VALUE . "(CMlLabel _Label) {
|
||||
NewValueIndex = 0;
|
||||
}
|
||||
}
|
||||
declare NewValue = " . Builder::EMPTY_STRING . ";
|
||||
declare NewValue = \"\";
|
||||
if (Values.existskey(NewValueIndex)) {
|
||||
NewValue = Values[NewValueIndex];
|
||||
} else {
|
||||
declare " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for _Label = " . Builder::EMPTY_STRING . ";
|
||||
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 = " . Builder::EMPTY_STRING . ";
|
||||
if (EntryId != " . Builder::EMPTY_STRING . ") {
|
||||
declare " . self::VAR_PICKER_ENTRY_ID . " as EntryId for _Label = \"\";
|
||||
if (EntryId != \"\") {
|
||||
declare Entry <=> (Page.GetFirstChild(EntryId) as CMlEntry);
|
||||
Entry.Value = NewValue;
|
||||
}
|
||||
}";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the init script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildInitScriptText() {
|
||||
$labelId = $this->label->getId(true, true);
|
||||
$entryId = '""';
|
||||
if ($this->entry) {
|
||||
$entryId = $this->entry->getId(true, true);
|
||||
}
|
||||
$values = Builder::getArray($this->values);
|
||||
$default = Builder::escapeText($this->getDefault(), true);
|
||||
return "
|
||||
declare Label_Picker <=> (Page.GetFirstChild({$labelId}) as CMlLabel);
|
||||
/**
|
||||
* Build the init script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildInitScriptText()
|
||||
{
|
||||
$labelId = Builder::getId($this->label);
|
||||
$entryId = Builder::EMPTY_STRING;
|
||||
if ($this->entry) {
|
||||
$entryId = Builder::getId($this->entry);
|
||||
}
|
||||
|
||||
$values = Builder::getArray($this->values);
|
||||
$default = Builder::escapeText($this->getDefault());
|
||||
|
||||
return "
|
||||
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};
|
||||
EntryId = \"{$entryId}\";
|
||||
" . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker);
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the script text for Label clicks
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildClickScriptText() {
|
||||
$labelId = $this->label->getId(true, true);
|
||||
return "
|
||||
if (Event.ControlId == {$labelId}) {
|
||||
/**
|
||||
* Build the script text for Label clicks
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildClickScriptText()
|
||||
{
|
||||
$labelId = Builder::getId($this->label);
|
||||
return "
|
||||
if (Event.ControlId == \"{$labelId}\") {
|
||||
declare Label_Picker <=> (Event.Control as CMlLabel);
|
||||
" . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker);
|
||||
}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user