FML Update

This commit is contained in:
kremsy 2017-07-02 17:45:32 +02:00
parent c9d96a30b2
commit 22e1e24284
9 changed files with 2141 additions and 6 deletions

View File

@ -76,6 +76,9 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener,
// Callbacks // Callbacks
$this->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET, $this, 'closeWidgetCallback'); $this->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET, $this, 'closeWidgetCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
//Set ManiaLink version 3 as Default Version in FML
ManiaLink::setDefaultVersion(ManiaLink::VERSION_3);
} }
/** /**

View File

@ -0,0 +1,186 @@
<?php
namespace FML\Components;
use FML\Controls\Entry;
use FML\Controls\Frame;
use FML\Script\Features\RadioButtonGroupFeature;
use FML\Script\Features\ScriptFeature;
use FML\Types\Renderable;
use FML\Types\ScriptFeatureable;
/**
* RadioButtonGroup Component
*
* @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 RadioButtonGroup implements Renderable, ScriptFeatureable
{
/**
* @var string $name RadioButtonGroup name
*/
protected $name = null;
/**
* @var RadioButtonGroupFeature $feature RadioButtonGroup Feature
*/
protected $feature = null;
/**
* Construct a new RadioButtonGroup
*
* @api
* @param string $name (optional) RadioButtonGroup name
*/
public function __construct($name = null)
{
$this->feature = new RadioButtonGroupFeature();
if ($name) {
$this->setName($name);
}
}
/**
* Get the name
*
* @api
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set the name
*
* @api
* @param string $name RadioButtonGroup name
* @return static
*/
public function setName($name)
{
$this->name = (string)$name;
$this->getEntry()
->setName($this->name);
return $this;
}
/**
* Get the hidden Entry
*
* @return Entry
*/
public function getEntry()
{
$entry = $this->feature->getEntry();
if ($entry) {
return $entry;
}
return $this->createEntry();
}
/**
* Create the hidden Entry
*
* @return Entry
*/
protected function createEntry()
{
$entry = new Entry();
$entry->setVisible(false);
if ($this->name) {
$entry->setName($this->name);
}
$this->feature->setEntry($entry);
return $entry;
}
/**
* Get RadioButtons
*
* @api
* @return CheckBox[]
*/
public function getRadioButtons()
{
return $this->feature->getRadioButtons();
}
/**
* Set RadioButtons
*
* @api
* @param CheckBox[] $radioButtons RadioButtons
* @return static
*/
public function setRadioButtons(array $radioButtons)
{
$this->removeAllRadioButtons()
->addRadioButtons($radioButtons);
return $this;
}
/**
* Add a new RadioButton to the group
*
* @api
* @param CheckBox $radioButton RadioButton
* @return static
*/
public function addRadioButton(CheckBox $radioButton)
{
$this->feature->addRadioButton($radioButton);
return $this;
}
/**
* Add new RadioButtons to the group
*
* @api
* @param CheckBox[] $radioButtons RadioButtons
* @return static
*/
public function addRadioButtons(array $radioButtons)
{
$this->feature->addRadioButtons($radioButtons);
return $this;
}
/**
* Remove all RadioButtons
*
* @api
* @return static
*/
public function removeAllRadioButtons()
{
$this->feature->removeAllRadioButtons();
return $this;
}
/**
* @see ScriptFeatureable::getScriptFeatures()
*/
public function getScriptFeatures()
{
return ScriptFeature::collect($this->feature, $this->getEntry());
}
/**
* @see Renderable::render()
*/
public function render(\DOMDocument $domDocument)
{
$frame = new Frame();
$entry = $this->getEntry();
$frame->addChild($entry);
return $frame->render($domDocument);
}
}

View File

@ -36,10 +36,15 @@ class ManiaLink
*/ */
protected $maniaLinkId = null; protected $maniaLinkId = null;
/**
* @var int $defaultVersion Default ManiaLink version
*/
static protected $defaultVersion = self::VERSION_1;
/** /**
* @var int $version ManiaLink version * @var int $version ManiaLink version
*/ */
protected $version = 0; protected $version = self::VERSION_1;
/** /**
* @var string $name ManiaLink name * @var string $name ManiaLink name
@ -91,7 +96,7 @@ class ManiaLink
* @param Renderable[] $children (optional) Children * @param Renderable[] $children (optional) Children
* @return static * @return static
*/ */
public static function create($maniaLinkId = null, $version = ManiaLink::VERSION_1, $name = null, array $children = null) public static function create($maniaLinkId = null, $version = null, $name = null, array $children = null)
{ {
return new static($maniaLinkId, $version, $name, $children); return new static($maniaLinkId, $version, $name, $children);
} }
@ -105,18 +110,20 @@ class ManiaLink
* @param string $name (optional) Name * @param string $name (optional) Name
* @param Renderable[] $children (optional) Children * @param Renderable[] $children (optional) Children
*/ */
public function __construct($maniaLinkId = null, $version = ManiaLink::VERSION_3, $name = null, array $children = null) public function __construct($maniaLinkId = null, $version = null, $name = null, array $children = null)
{ {
if (is_string($version) && (!$name || is_array($name)) && !$children) { if (is_string($version) && (!$name || is_array($name)) && !$children) {
// backwards-compatibility (version has been introduced later) // backwards-compatibility (version has been introduced later, if it's a string it's supposed to be the name)
$children = $name; $children = $name;
$name = $version; $name = $version;
$version = ManiaLink::VERSION_3; $version = null;
} }
if ($maniaLinkId) { if ($maniaLinkId) {
$this->setId($maniaLinkId); $this->setId($maniaLinkId);
} }
if ($version) { if ($version === null) {
$this->setVersion(static::$defaultVersion);
} else {
$this->setVersion($version); $this->setVersion($version);
} }
if ($name) { if ($name) {
@ -154,6 +161,17 @@ class ManiaLink
return $this; return $this;
} }
/**
* Get the default version
*
* @api
* @return int
*/
public static function getDefaultVersion()
{
return static::$defaultVersion;
}
/** /**
* Get the version * Get the version
* *
@ -165,6 +183,17 @@ class ManiaLink
return $this->version; return $this->version;
} }
/**
* Set the default version
*
* @api
* @param int $defaultVersion Default ManiaLink version
*/
public static function setDefaultVersion($defaultVersion)
{
static::$defaultVersion = (int)$defaultVersion;
}
/** /**
* Set the version * Set the version
* *

View 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 . "
}";
}
}

View 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;
}
}

View 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 . "
}";
}
}

View File

@ -0,0 +1,144 @@
<?php
namespace FML\XmlRpc;
/**
* Class representing ShootMania UI Properties
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class SMUIProperties extends UIProperties
{
/**
* @var array $noticesProperties Notices properties
*/
protected $noticesProperties = array();
/**
* @var array $crosshairProperties Crosshair properties
*/
protected $crosshairProperties = array();
/**
* @var array $gaugesProperties Gauges properties
*/
protected $gaugesProperties = array();
/**
* @var array $consumablesProperties Consumables properties
*/
protected $consumablesProperties = array();
/**
* Get the notices visibility
*
* @api
* @return bool
*/
public function getNoticesVisible()
{
return $this->getVisibleProperty($this->noticesProperties);
}
/**
* Set the notices visibility
*
* @api
* @param bool $visible If the notices should be visible
* @return static
*/
public function setNoticesVisible($visible)
{
$this->setVisibleProperty($this->noticesProperties, $visible);
return $this;
}
/**
* Get the crosshair visibility
*
* @api
* @return bool
*/
public function getCrosshairVisible()
{
return $this->getVisibleProperty($this->crosshairProperties);
}
/**
* Set the crosshair visibility
*
* @api
* @param bool $visible If the crosshair should be visible
* @return static
*/
public function setCrosshairVisible($visible)
{
$this->setVisibleProperty($this->crosshairProperties, $visible);
return $this;
}
/**
* Get the gauges visibility
*
* @api
* @return bool
*/
public function getGaugesVisible()
{
return $this->getVisibleProperty($this->gaugesProperties);
}
/**
* Set the gauges visibility
*
* @api
* @param bool $visible If the gauges should be visible
* @return static
*/
public function setGaugesVisible($visible)
{
$this->setVisibleProperty($this->gaugesProperties, $visible);
return $this;
}
/**
* Get the consumables visibility
*
* @api
* @return bool
*/
public function getConsumablesVisible()
{
return $this->getVisibleProperty($this->consumablesProperties);
}
/**
* Set the consumables visibility
*
* @api
* @param bool $visible If the consumables should be visible
* @return static
*/
public function setConsumablesVisible($visible)
{
$this->setVisibleProperty($this->consumablesProperties, $visible);
return $this;
}
/**
* @see UIProperties::getProperties()
*/
protected function getProperties()
{
return array_merge(parent::getProperties(), array(
"notices" => $this->noticesProperties,
"crosshair" => $this->crosshairProperties,
"gauges" => $this->gaugesProperties,
"consumables" => $this->consumablesProperties
));
}
}

View File

@ -0,0 +1,726 @@
<?php
namespace FML\XmlRpc;
/**
* Class representing TrackMania UI Properties
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class TMUIProperties extends UIProperties
{
/**
* @var array $liveInfoProperties Live info properties
*/
protected $liveInfoProperties = array();
/**
* @var array $spectatorInfoProperties Spectator info properties
*/
protected $spectatorInfoProperties = array();
/**
* @var array $opponentsInfoProperties Opponents info properties
*/
protected $opponentsInfoProperties = array();
/**
* @var array $checkpointListProperties Checkpoint list properties
*/
protected $checkpointListProperties = array();
/**
* @var array $roundScoresProperties Round scores properties
*/
protected $roundScoresProperties = array();
/**
* @var array $chronoProperties Chrono properties
*/
protected $chronoProperties = array();
/**
* @var array $speedAndDistanceProperties Speed and distance properties
*/
protected $speedAndDistanceProperties = array();
/**
* @var array $personalBestAndRankProperties Personal best and rank properties
*/
protected $personalBestAndRankProperties = array();
/**
* @var array $positionProperties Position properties
*/
protected $positionProperties = array();
/**
* @var array $checkpointTimeProperties Checkpoint time properties
*/
protected $checkpointTimeProperties = array();
/**
* @var array $warmUpProperties Warm-up properties
*/
protected $warmUpProperties = array();
/**
* @var array $multiLapInfoProperties Multi-lap info properties
*/
protected $multiLapInfoProperties = array();
/**
* @var array $checkpointRankingProperties Checkpoint ranking properties
*/
protected $checkpointRankingProperties = array();
/**
* Get the live info visibility
*
* @api
* @return bool
*/
public function getLiveInfoVisible()
{
return $this->getVisibleProperty($this->liveInfoProperties);
}
/**
* Set the live info visibility
*
* @api
* @param bool $visible If the live info should be visible
* @return static
*/
public function setLiveInfoVisible($visible)
{
$this->setVisibleProperty($this->liveInfoProperties, $visible);
return $this;
}
/**
* Get the live info position
*
* @api
* @return string
*/
public function getLiveInfoPosition()
{
return $this->getPositionProperty($this->liveInfoProperties);
}
/**
* Set the live info position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setLiveInfoPosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->liveInfoProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* Get the spectator info visibility
*
* @api
* @return bool
*/
public function getSpectatorInfoVisible()
{
return $this->getVisibleProperty($this->spectatorInfoProperties);
}
/**
* Set the spectator info visibility
*
* @api
* @param bool $visible If the spectator info should be visible
* @return static
*/
public function setSpectatorInfoVisible($visible)
{
$this->setVisibleProperty($this->spectatorInfoProperties, $visible);
return $this;
}
/**
* Get the spectator info position
*
* @api
* @return string
*/
public function getSpectatorInfoPosition()
{
return $this->getPositionProperty($this->spectatorInfoProperties);
}
/**
* Set the spectator info position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setSpectatorInfoPosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->spectatorInfoProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* Get the opponents info visibility
*
* @api
* @return bool
*/
public function getOpponentsInfoVisible()
{
return $this->getVisibleProperty($this->opponentsInfoProperties);
}
/**
* Set the opponents info visibility
*
* @api
* @param bool $visible If the opponents info should be visible
* @return static
*/
public function setOpponentsInfoVisible($visible)
{
$this->setVisibleProperty($this->opponentsInfoProperties, $visible);
return $this;
}
/**
* Get the checkpoint list visibility
*
* @api
* @return bool
*/
public function getCheckpointListVisible()
{
return $this->getVisibleProperty($this->checkpointListProperties);
}
/**
* Set the checkpoint list visibility
*
* @api
* @param bool $visible If the checkpoint list should be visible
* @return static
*/
public function setCheckpointListVisible($visible)
{
$this->setVisibleProperty($this->checkpointListProperties, $visible);
return $this;
}
/**
* Get the checkpoint list position
*
* @api
* @return string
*/
public function getCheckpointListPosition()
{
return $this->getPositionProperty($this->checkpointListProperties);
}
/**
* Set the checkpoint list position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setCheckpointListPosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->checkpointListProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* Get the round scores visibility
*
* @api
* @return bool
*/
public function getRoundScoresVisible()
{
return $this->getVisibleProperty($this->roundScoresProperties);
}
/**
* Set the round scores visibility
*
* @api
* @param bool $visible If the round scores should be visible
* @return static
*/
public function setRoundScoresVisible($visible)
{
$this->setVisibleProperty($this->roundScoresProperties, $visible);
return $this;
}
/**
* Get the round scores position
*
* @api
* @return string
*/
public function getRoundScoresPosition()
{
return $this->getPositionProperty($this->roundScoresProperties);
}
/**
* Set the round scores position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setRoundScoresPosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->roundScoresProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* Get the chrono visibility
*
* @api
* @return bool
*/
public function getChronoVisible()
{
return $this->getVisibleProperty($this->chronoProperties);
}
/**
* Set the chrono visibility
*
* @api
* @param bool $visible If the chrono should be visible
* @return static
*/
public function setChronoVisible($visible)
{
$this->setVisibleProperty($this->chronoProperties, $visible);
return $this;
}
/**
* Get the chrono position
*
* @api
* @return string
*/
public function getChronoPosition()
{
return $this->getPositionProperty($this->chronoProperties);
}
/**
* Set the chrono position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setChronoPosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->chronoProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* Get the speed and distance visibility
*
* @api
* @return bool
*/
public function getSpeedAndDistanceVisible()
{
return $this->getVisibleProperty($this->speedAndDistanceProperties);
}
/**
* Set the speed and distance visibility
*
* @api
* @param bool $visible If the speed and distance should be visible
* @return static
*/
public function setSpeedAndDistanceVisible($visible)
{
$this->setVisibleProperty($this->speedAndDistanceProperties, $visible);
return $this;
}
/**
* Get the speed and distance position
*
* @api
* @return string
*/
public function getSpeedAndDistancePosition()
{
return $this->getPositionProperty($this->speedAndDistanceProperties);
}
/**
* Set the speed and distance position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setSpeedAndDistancePosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->speedAndDistanceProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* Get the personal best and rank visibility
*
* @api
* @return bool
*/
public function getPersonalBestAndRankVisible()
{
return $this->getVisibleProperty($this->personalBestAndRankProperties);
}
/**
* Set the personal best and rank visibility
*
* @api
* @param bool $visible If the personal best and rank should be visible
* @return static
*/
public function setPersonalBestAndRankVisible($visible)
{
$this->setVisibleProperty($this->personalBestAndRankProperties, $visible);
return $this;
}
/**
* Get the personal best and rank position
*
* @api
* @return string
*/
public function getPersonalBestAndRankPosition()
{
return $this->getPositionProperty($this->personalBestAndRankProperties);
}
/**
* Set the personal best and rank position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setPersonalBestAndRankPosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->personalBestAndRankProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* Get the position visibility
*
* @api
* @return bool
*/
public function getPositionVisible()
{
return $this->getVisibleProperty($this->positionProperties);
}
/**
* Set the position visibility
*
* @api
* @param bool $visible If the position should be visible
* @return static
*/
public function setPositionVisible($visible)
{
$this->setVisibleProperty($this->positionProperties, $visible);
return $this;
}
/**
* Get the position position
*
* @api
* @return string
*/
public function getPositionPosition()
{
return $this->getPositionProperty($this->positionProperties);
}
/**
* Set the position position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setPositionPosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->positionProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* Get the checkpoint time visibility
*
* @api
* @return bool
*/
public function getCheckpointTimeVisible()
{
return $this->getVisibleProperty($this->checkpointTimeProperties);
}
/**
* Set the checkpoint time visibility
*
* @api
* @param bool $visible If the checkpoint time should be visible
* @return static
*/
public function setCheckpointTimeVisible($visible)
{
$this->setVisibleProperty($this->checkpointTimeProperties, $visible);
return $this;
}
/**
* Get the checkpoint time position
*
* @api
* @return string
*/
public function getCheckpointTimePosition()
{
return $this->getPositionProperty($this->checkpointTimeProperties);
}
/**
* Set the checkpoint time position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setCheckpointTimePosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->checkpointTimeProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* Get the warm-up visibility
*
* @api
* @return bool
*/
public function getWarmUpVisible()
{
return $this->getVisibleProperty($this->warmUpProperties);
}
/**
* Set the warm-up visibility
*
* @api
* @param bool $visible If the warm-up should be visible
* @return static
*/
public function setWarmUpVisible($visible)
{
$this->setVisibleProperty($this->warmUpProperties, $visible);
return $this;
}
/**
* Get the warm-up position
*
* @api
* @return string
*/
public function getWarmUpPosition()
{
return $this->getPositionProperty($this->warmUpProperties);
}
/**
* Set the warm-up position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setWarmUpPosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->warmUpProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* Get the multi-lap info visibility
*
* @api
* @return bool
*/
public function getMultiLapInfoVisible()
{
return $this->getVisibleProperty($this->multiLapInfoProperties);
}
/**
* Set the multi-lap info visibility
*
* @api
* @param bool $visible If the multi-lap info should be visible
* @return static
*/
public function setMultiLapInfoVisible($visible)
{
$this->setVisibleProperty($this->multiLapInfoProperties, $visible);
return $this;
}
/**
* Get the multi-lap info position
*
* @api
* @return string
*/
public function getMultiLapInfoPosition()
{
return $this->getPositionProperty($this->multiLapInfoProperties);
}
/**
* Set the multi-lap info position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setMultiLapInfoPosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->multiLapInfoProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* Get the checkpoint ranking visibility
*
* @api
* @return bool
*/
public function getCheckpointRankingVisible()
{
return $this->getVisibleProperty($this->checkpointRankingProperties);
}
/**
* Set the checkpoint ranking visibility
*
* @api
* @param bool $visible If the checkpoint ranking should be visible
* @return static
*/
public function setCheckpointRankingVisible($visible)
{
$this->setVisibleProperty($this->checkpointRankingProperties, $visible);
return $this;
}
/**
* Get the checkpoint ranking position
*
* @api
* @return string
*/
public function getCheckpointRankingPosition()
{
return $this->getPositionProperty($this->checkpointRankingProperties);
}
/**
* Set the checkpoint ranking position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setCheckpointRankingPosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->checkpointRankingProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* @see UIProperties::getProperties()
*/
protected function getProperties()
{
return array_merge(parent::getProperties(), array(
"live_info" => $this->liveInfoProperties,
"spectator_info" => $this->spectatorInfoProperties,
"opponents_info" => $this->opponentsInfoProperties,
"checkpoint_list" => $this->checkpointListProperties,
"round_scores" => $this->roundScoresProperties,
"chrono" => $this->chronoProperties,
"speed_and_distance" => $this->speedAndDistanceProperties,
"personal_best_and_rank" => $this->personalBestAndRankProperties,
"position" => $this->positionProperties,
"checkpoint_time" => $this->checkpointTimeProperties,
"warmup" => $this->warmUpProperties,
"multilap_info" => $this->multiLapInfoProperties,
"checkpoint_ranking" => $this->checkpointRankingProperties
));
}
}

View File

@ -0,0 +1,471 @@
<?php
namespace FML\XmlRpc;
/**
* Class representing common UI Properties
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class UIProperties
{
/**
* @var array $chatProperties Chat properties
*/
protected $chatProperties = array();
/**
* @var array $chatAvatarProperties Chat avatar properties
*/
protected $chatAvatarProperties = array();
/**
* @var array $mapInfoProperties Map info properties
*/
protected $mapInfoProperties = array();
/**
* @var array $countdownProperties Countdown properties
*/
protected $countdownProperties = array();
/**
* @var array $goProperties Go! properties
*/
protected $goProperties = array();
/**
* @var array $endMapLadderRecapProperties End map ladder recap properties
*/
protected $endMapLadderRecapProperties = array();
/**
* @var array $scoresTableProperties Scores table properties
*/
protected $scoresTableProperties = array();
/**
* Create new UI Properties
*
* @api
* @return static
*/
public static function create()
{
return new static();
}
/**
* Get the chat visibility
*
* @api
* @return bool
*/
public function getChatVisible()
{
return $this->getVisibleProperty($this->chatProperties);
}
/**
* Set the chat visibility
*
* @api
* @param bool $visible If the chat should be visible
* @return static
*/
public function setChatVisible($visible)
{
$this->setVisibleProperty($this->chatProperties, $visible);
return $this;
}
/**
* Get the chat offset
*
* @api
* @return string
*/
public function getChatOffset()
{
return $this->getProperty($this->chatProperties, "offset");
}
/**
* Set the chat offset
*
* @api
* @param float $offsetX X offset
* @param float $offsetY Y offset
* @return static
*/
public function setChatOffset($offsetX, $offsetY)
{
$offset = array((float)$offsetX, (float)$offsetY);
$this->setProperty($this->chatProperties, "offset", implode(" ", $offset));
return $this;
}
/**
* Get the chat line count
*
* @api
* @return int
*/
public function getChatLineCount()
{
return $this->getProperty($this->chatProperties, "linecount");
}
/**
* Set the chat line count
*
* @api
* @param int $lineCount Line count
* @return static
*/
public function setChatLineCount($lineCount)
{
$this->setProperty($this->chatProperties, "linecount", (int)$lineCount);
return $this;
}
/**
* Get the chat avatar visibility
*
* @api
* @return bool
*/
public function getChatAvatarVisible()
{
return $this->getVisibleProperty($this->chatAvatarProperties);
}
/**
* Set the chat avatar visibility
*
* @api
* @param bool $visible If the chat avatar should be visible
* @return static
*/
public function setChatAvatarVisible($visible)
{
$this->setVisibleProperty($this->chatAvatarProperties, $visible);
return $this;
}
/**
* Get the map info visibility
*
* @api
* @return bool
*/
public function getMapInfoVisible()
{
return $this->getVisibleProperty($this->mapInfoProperties);
}
/**
* Set the map info visibility
*
* @api
* @param bool $visible If the map info should be visible
* @return static
*/
public function setMapInfoVisible($visible)
{
$this->setVisibleProperty($this->mapInfoProperties, $visible);
return $this;
}
/**
* Get the map info position
*
* @api
* @return string
*/
public function getMapInfoPosition()
{
return $this->getPositionProperty($this->mapInfoProperties);
}
/**
* Set the map info position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setMapInfoPosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->mapInfoProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* Get the countdown visibility
*
* @api
* @return bool
*/
public function getCountdownVisible()
{
return $this->getVisibleProperty($this->countdownProperties);
}
/**
* Set the countdown visibility
*
* @api
* @param bool $visible If the countdown should be visible
* @return static
*/
public function setCountdownVisible($visible)
{
$this->setVisibleProperty($this->countdownProperties, $visible);
return $this;
}
/**
* Get the countdown position
*
* @api
* @return string
*/
public function getCountdownPosition()
{
return $this->getPositionProperty($this->countdownProperties);
}
/**
* Set the countdown position
*
* @api
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
public function setCountdownPosition($positionX, $positionY, $positionZ = null)
{
$this->setPositionProperty($this->countdownProperties, $positionX, $positionY, $positionZ);
return $this;
}
/**
* Get the Go! visibility
*
* @api
* @return bool
*/
public function getGoVisible()
{
return $this->getVisibleProperty($this->goProperties);
}
/**
* Set the Go! visibility
*
* @api
* @param bool $visible If Go! should be visible
* @return static
*/
public function setGoVisible($visible)
{
$this->setVisibleProperty($this->goProperties, $visible);
return $this;
}
/**
* Get the end map ladder recap visibility
*
* @api
* @return bool
*/
public function getEndMapLadderRecapVisible()
{
return $this->getVisibleProperty($this->endMapLadderRecapProperties);
}
/**
* Set the end map ladder recap visibility
*
* @api
* @param bool $visible If the end map ladder recap should be visible
* @return static
*/
public function setEndMapLadderRecapVisible($visible)
{
$this->setVisibleProperty($this->endMapLadderRecapProperties, $visible);
return $this;
}
/**
* Get the scores table alt visibility
*
* @api
* @return bool
*/
public function getScoresTableAltVisible()
{
return $this->getProperty($this->scoresTableProperties, "alt_visible");
}
/**
* Set the scores table alt visibility
*
* @api
* @param bool $altVisible If the scores table should be visible on alt
* @return static
*/
public function setScoresTableAltVisible($altVisible)
{
$this->setProperty($this->scoresTableProperties, "alt_visible", (bool)$altVisible);
return $this;
}
/**
* Render the UI Properties standalone
*
* @return \DOMDocument
*/
public function renderStandalone()
{
$domDocument = new \DOMDocument("1.0", "utf-8");
$domDocument->xmlStandalone = true;
$domElement = $domDocument->createElement("ui_properties");
$domDocument->appendChild($domElement);
$allProperties = $this->getProperties();
foreach ($allProperties as $property => $propertySettings) {
if (!$propertySettings) {
continue;
}
$propertyDomElement = $domDocument->createElement($property);
$domElement->appendChild($propertyDomElement);
foreach ($propertySettings as $settingName => $settingValue) {
$settingValueString = (is_string($settingValue) ? $settingValue : var_export($settingValue, true));
$propertyDomElement->setAttribute($settingName, $settingValueString);
}
}
return $domDocument;
}
/**
* Get string representation
*
* @return string
*/
public function __toString()
{
return $this->renderStandalone()
->saveXML();
}
/**
* Get associative array of all properties
*
* @return array
*/
protected function getProperties()
{
return array(
"chat" => $this->chatProperties,
"chat_avatar" => $this->chatAvatarProperties,
"map_info" => $this->mapInfoProperties,
"countdown" => $this->countdownProperties,
"go" => $this->goProperties,
"endmap_ladder_recap" => $this->endMapLadderRecapProperties,
"scorestable" => $this->scoresTableProperties
);
}
/**
* Get a property value if it's set
*
* @param array $properties Properties array
* @param string $name Property name
* @return mixed
*/
protected function getProperty(array $properties, $name)
{
return (isset($properties[$name]) ? $properties[$name] : null);
}
/**
* Set a property value
*
* @param array $properties Properties array
* @param string $name Property name
* @param mixed $value Property value
* @return static
*/
protected function setProperty(array &$properties, $name, $value)
{
$properties[$name] = $value;
return $this;
}
/**
* Set the Visible property value
*
* @param array $properties Properties array
* @return bool
*/
protected function getVisibleProperty(array &$properties)
{
return $this->getProperty($properties, "visible");
}
/**
* Set the Visible property value
*
* @param array $properties Properties array
* @param bool $visible Visibility value
* @return static
*/
protected function setVisibleProperty(array &$properties, $visible)
{
$this->setProperty($properties, "visible", (bool)$visible);
return $this;
}
/**
* Get the Position property value
*
* @param array $properties Properties array
* @return string
*/
protected function getPositionProperty(array &$properties)
{
return $this->getProperty($properties, "pos");
}
/**
* Set the Position property value
*
* @param array $properties Properties array
* @param float $positionX X position
* @param float $positionY Y position
* @param float $positionZ (optional) Z position (Z-index)
* @return static
*/
protected function setPositionProperty(array &$properties, $positionX, $positionY, $positionZ = null)
{
$position = array((float)$positionX, (float)$positionY);
if ($positionZ) {
array_push($position, (float)$positionZ);
}
$this->setProperty($properties, "pos", implode(" ", $position));
return $this;
}
}