FML Update
This commit is contained in:
156
libs/FML/Script/Features/GraphSettings.php
Normal file
156
libs/FML/Script/Features/GraphSettings.php
Normal file
@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace FML\Script\Features;
|
||||
|
||||
use FML\Controls\Graph;
|
||||
use FML\Script\Builder;
|
||||
use FML\Script\Script;
|
||||
use FML\Script\ScriptLabel;
|
||||
|
||||
/**
|
||||
* Script Feature setting up a Graph
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class GraphSettings extends ScriptFeature
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Graph $graph Graph
|
||||
*/
|
||||
protected $graph = null;
|
||||
|
||||
/**
|
||||
* @var float[] $minimumCoordinates Minimum Coordinates
|
||||
*/
|
||||
protected $minimumCoordinates = null;
|
||||
|
||||
/**
|
||||
* @var float[] $maximumCoordinates Maximum Coordinates
|
||||
*/
|
||||
protected $maximumCoordinates = null;
|
||||
|
||||
/**
|
||||
* Construct new Graph Settings
|
||||
*
|
||||
* @api
|
||||
* @param Graph $graph (optional) Graph
|
||||
*/
|
||||
public function __construct(Graph $graph = null)
|
||||
{
|
||||
if ($graph) {
|
||||
$this->setGraph($graph);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 minimum coordinates
|
||||
*
|
||||
* @api
|
||||
* @return float[]
|
||||
*/
|
||||
public function getMinimumCoordinates()
|
||||
{
|
||||
return $this->minimumCoordinates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum coordinates
|
||||
*
|
||||
* @api
|
||||
* @param float[] $minimumCoordinates Minimum coordinates
|
||||
* @return static
|
||||
*/
|
||||
public function setMinimumCoordinates(array $minimumCoordinates)
|
||||
{
|
||||
$this->minimumCoordinates = $minimumCoordinates;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum coordinates
|
||||
*
|
||||
* @api
|
||||
* @return float[]
|
||||
*/
|
||||
public function getMaximumCoordinates()
|
||||
{
|
||||
return $this->maximumCoordinates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum coordinates
|
||||
*
|
||||
* @api
|
||||
* @param float[] $maximumCoordinates Maximum coordinates
|
||||
* @return static
|
||||
*/
|
||||
public function setMaximumCoordinates(array $maximumCoordinates)
|
||||
{
|
||||
$this->maximumCoordinates = $maximumCoordinates;
|
||||
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) {
|
||||
";
|
||||
if ($this->minimumCoordinates) {
|
||||
$coordsMinValue = Builder::getVec2($this->minimumCoordinates);
|
||||
$scriptText .= "
|
||||
Graph.CoordsMin = {$coordsMinValue};";
|
||||
}
|
||||
if ($this->maximumCoordinates) {
|
||||
$coordsMinValue = Builder::getVec2($this->maximumCoordinates);
|
||||
$scriptText .= "
|
||||
Graph.CoordsMax = {$coordsMinValue};";
|
||||
}
|
||||
return $scriptText . "
|
||||
}";
|
||||
}
|
||||
|
||||
}
|
233
libs/FML/Script/Features/RadioButtonGroupFeature.php
Normal file
233
libs/FML/Script/Features/RadioButtonGroupFeature.php
Normal file
@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace FML\Script\Features;
|
||||
|
||||
use FML\Components\CheckBox;
|
||||
use FML\Controls\Entry;
|
||||
use FML\Script\Builder;
|
||||
use FML\Script\Script;
|
||||
use FML\Script\ScriptLabel;
|
||||
|
||||
/**
|
||||
* Script Feature for creating a RadioButtonGroup behavior
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class RadioButtonGroupFeature extends ScriptFeature
|
||||
{
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const FUNCTION_ON_RADIO_BUTTON_CLICK = "FML_OnRadioButtonClick";
|
||||
const CONSTANT_RADIO_BUTTON_IDS_PREFIX = "FML_RadioButtonGroup_";
|
||||
|
||||
/**
|
||||
* @var Entry $entry Hidden Entry for submitting the value
|
||||
*/
|
||||
protected $entry = null;
|
||||
|
||||
/**
|
||||
* @var CheckBox[] $radioButtons RadioButtons
|
||||
*/
|
||||
protected $radioButtons = array();
|
||||
|
||||
/**
|
||||
* Construct a new RadioButtonGroup Feature
|
||||
*
|
||||
* @api
|
||||
* @param Entry $entry (optional) Hidden Entry
|
||||
*/
|
||||
public function __construct(Entry $entry = null)
|
||||
{
|
||||
if ($entry) {
|
||||
$this->setEntry($entry);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hidden Entry
|
||||
*
|
||||
* @api
|
||||
* @return Entry
|
||||
*/
|
||||
public function getEntry()
|
||||
{
|
||||
return $this->entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 RadioButtons
|
||||
*
|
||||
* @api
|
||||
* @return CheckBox[]
|
||||
*/
|
||||
public function getRadioButtons()
|
||||
{
|
||||
return $this->radioButtons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set RadioButtons
|
||||
*
|
||||
* @api
|
||||
* @param CheckBox[] $radioButtons RadioButtons
|
||||
* @return static
|
||||
*/
|
||||
public function setRadioButtons(array $radioButtons)
|
||||
{
|
||||
$this->radioButtons = $radioButtons;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new RadioButton
|
||||
*
|
||||
* @api
|
||||
* @param CheckBox $radioButton RadioButton
|
||||
* @return static
|
||||
*/
|
||||
public function addRadioButton(CheckBox $radioButton)
|
||||
{
|
||||
if (!in_array($radioButton, $this->radioButtons, true)) {
|
||||
array_push($this->radioButtons, $radioButton);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new RadioButtons
|
||||
*
|
||||
* @api
|
||||
* @param CheckBox[] $radioButtons RadioButtons
|
||||
* @return static
|
||||
*/
|
||||
public function addRadioButtons(array $radioButtons)
|
||||
{
|
||||
foreach ($radioButtons as $radioButton) {
|
||||
$this->addRadioButton($radioButton);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all RadioButtons
|
||||
*
|
||||
* @api
|
||||
* @return static
|
||||
*/
|
||||
public function removeAllRadioButtons()
|
||||
{
|
||||
$this->radioButtons = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
if (!$this->entry || !$this->getRadioButtons()) {
|
||||
return $this;
|
||||
}
|
||||
$this->prepareRadioButtonIdsConstant($script);
|
||||
$this->prepareOnRadioButtonClickFunction($script);
|
||||
$this->prepareRadioButtonClickScript($script);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the name of the Constant contain the RadioButton Ids
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getRadioButtonIdsConstantName()
|
||||
{
|
||||
return self::CONSTANT_RADIO_BUTTON_IDS_PREFIX . $this->entry->checkId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the Constant containing the RadioButton Ids
|
||||
*
|
||||
* @param Script $script Script
|
||||
* @return static
|
||||
*/
|
||||
protected function prepareRadioButtonIdsConstant(Script $script)
|
||||
{
|
||||
$radioButtonIds = array();
|
||||
foreach ($this->radioButtons as $radioButton) {
|
||||
$radioButtonIds[$radioButton->getName()] = Builder::getId($radioButton->getQuad());
|
||||
}
|
||||
$script->addScriptConstant($this->getRadioButtonIdsConstantName(), $radioButtonIds);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the RadioButton click handler function
|
||||
*
|
||||
* @param Script $script Script
|
||||
* @return static
|
||||
*/
|
||||
protected function prepareOnRadioButtonClickFunction(Script $script)
|
||||
{
|
||||
$script->addScriptFunction(self::FUNCTION_ON_RADIO_BUTTON_CLICK, "
|
||||
Void " . self::FUNCTION_ON_RADIO_BUTTON_CLICK . "(CMlQuad _RadioButtonQuad, CMlEntry _RadioButtonGroupEntry, Text[Text] _RadioButtonIds) {
|
||||
// update group entry with name of selected radio button
|
||||
declare " . CheckBoxFeature::VAR_CHECKBOX_ENABLED . " as RadioButtonEnabled for _RadioButtonQuad = False;
|
||||
if (_RadioButtonGroupEntry != Null) {
|
||||
declare RadioButtonGroupValue = \"\";
|
||||
if (RadioButtonEnabled && _RadioButtonIds.exists(_RadioButtonQuad.ControlId)) {
|
||||
RadioButtonGroupValue = _RadioButtonIds.keyof(_RadioButtonQuad.ControlId);
|
||||
}
|
||||
_RadioButtonGroupEntry.Value = RadioButtonGroupValue;
|
||||
}
|
||||
// disable other radio buttons
|
||||
if (RadioButtonEnabled) {
|
||||
foreach (OtherRadioButtonId in _RadioButtonIds) {
|
||||
declare OtherRadioButtonQuad <=> (Page.GetFirstChild(OtherRadioButtonId) as CMlQuad);
|
||||
if (OtherRadioButtonQuad != Null && OtherRadioButtonQuad != _RadioButtonQuad) {
|
||||
declare " . CheckBoxFeature::VAR_CHECKBOX_ENABLED . " as OtherRadioButtonEnabled for OtherRadioButtonQuad = False;
|
||||
if (OtherRadioButtonEnabled) {
|
||||
" . CheckBoxFeature::FUNCTION_UPDATE_QUAD_DESIGN . "(OtherRadioButtonQuad);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}");
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the script for RadioButton clicks
|
||||
*
|
||||
* @param Script $script Script
|
||||
* @return static
|
||||
*/
|
||||
protected function prepareRadioButtonClickScript(Script $script)
|
||||
{
|
||||
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK2, "
|
||||
if (" . $this->getRadioButtonIdsConstantName() . ".exists(Event.ControlId)) {
|
||||
declare RadioButtonQuad <=> (Event.Control as CMlQuad);
|
||||
declare RadioButtonGroupEntry <=> (Page.GetFirstChild(\"" . Builder::getId($this->entry) . "\") as CMlEntry);
|
||||
" . self::FUNCTION_ON_RADIO_BUTTON_CLICK . "(RadioButtonQuad, RadioButtonGroupEntry, " . $this->getRadioButtonIdsConstantName() . ");
|
||||
}");
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
187
libs/FML/Script/Features/ToggleInterface.php
Normal file
187
libs/FML/Script/Features/ToggleInterface.php
Normal file
@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace FML\Script\Features;
|
||||
|
||||
use FML\Script\Builder;
|
||||
use FML\Script\Script;
|
||||
use FML\Script\ScriptLabel;
|
||||
|
||||
/**
|
||||
* Script Feature for toggling the complete ManiaLink via Key Press
|
||||
*
|
||||
* @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 ToggleInterface extends ScriptFeature
|
||||
{
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const VAR_STATE = "FML_ToggleInterface_State";
|
||||
|
||||
/**
|
||||
* @var string $keyName Key name
|
||||
*/
|
||||
protected $keyName = null;
|
||||
|
||||
/**
|
||||
* @var int $keyCode Key code
|
||||
*/
|
||||
protected $keyCode = null;
|
||||
|
||||
/**
|
||||
* @var bool $rememberState Remember the current state
|
||||
*/
|
||||
protected $rememberState = true;
|
||||
|
||||
/**
|
||||
* Construct a new ToggleInterface
|
||||
*
|
||||
* @api
|
||||
* @param string|int $keyNameOrCode (optional) Key name or code
|
||||
* @param bool $rememberState (optional) Remember the current state
|
||||
*/
|
||||
public function __construct($keyNameOrCode = null, $rememberState = true)
|
||||
{
|
||||
if (is_string($keyNameOrCode)) {
|
||||
$this->setKeyName($keyNameOrCode);
|
||||
} else if (is_int($keyNameOrCode)) {
|
||||
$this->setKeyCode($keyNameOrCode);
|
||||
}
|
||||
$this->setRememberState($rememberState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key name
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getKeyName()
|
||||
{
|
||||
return $this->keyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the key name
|
||||
*
|
||||
* @api
|
||||
* @param string $keyName Key name
|
||||
* @return static
|
||||
*/
|
||||
public function setKeyName($keyName)
|
||||
{
|
||||
$this->keyName = (string)$keyName;
|
||||
$this->keyCode = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key code
|
||||
*
|
||||
* @api
|
||||
* @return int
|
||||
*/
|
||||
public function getKeyCode()
|
||||
{
|
||||
return $this->keyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the key code
|
||||
*
|
||||
* @api
|
||||
* @param int $keyCode Key code
|
||||
* @return static
|
||||
*/
|
||||
public function setKeyCode($keyCode)
|
||||
{
|
||||
$this->keyCode = (int)$keyCode;
|
||||
$this->keyName = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the state should get remembered
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function getRememberState()
|
||||
{
|
||||
return $this->rememberState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the state should get remembered
|
||||
*
|
||||
* @api
|
||||
* @param bool $rememberState Remember the current state
|
||||
* @return static
|
||||
*/
|
||||
public function setRememberState($rememberState)
|
||||
{
|
||||
$this->rememberState = (bool)$rememberState;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeature::prepare()
|
||||
*/
|
||||
public function prepare(Script $script)
|
||||
{
|
||||
$script->appendGenericScriptLabel(ScriptLabel::KEYPRESS, $this->getKeyPressScriptText());
|
||||
if ($this->rememberState) {
|
||||
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->getOnInitScriptText());
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the on init script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getOnInitScriptText()
|
||||
{
|
||||
$stateVariableName = $this::VAR_STATE;
|
||||
return "
|
||||
declare persistent {$stateVariableName} as CurrentState for LocalUser = True;
|
||||
Page.MainFrame.Visible = CurrentState;
|
||||
";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key press script text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getKeyPressScriptText()
|
||||
{
|
||||
$keyProperty = null;
|
||||
$keyValue = null;
|
||||
if ($this->keyName) {
|
||||
$keyProperty = "KeyName";
|
||||
$keyValue = Builder::getText($this->keyName);
|
||||
} else if ($this->keyCode) {
|
||||
$keyProperty = "KeyCode";
|
||||
$keyValue = Builder::getInteger($this->keyCode);
|
||||
}
|
||||
$scriptText = "
|
||||
if (Event.{$keyProperty} == {$keyValue}) {
|
||||
Page.MainFrame.Visible = !Page.MainFrame.Visible;
|
||||
";
|
||||
if ($this->rememberState) {
|
||||
$stateVariableName = $this::VAR_STATE;
|
||||
$scriptText .= "
|
||||
declare persistent {$stateVariableName} as CurrentState for LocalUser = True;
|
||||
CurrentState = Page.MainFrame.Visible;
|
||||
";
|
||||
}
|
||||
return $scriptText . "
|
||||
}";
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user