removed 'application' folder to have everything in the root directory

This commit is contained in:
Steffen Schröder
2014-09-29 18:20:09 +02:00
parent 1569fd5488
commit 9642433363
284 changed files with 4 additions and 50 deletions

View File

@ -0,0 +1,112 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for triggering a manialink page action
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 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;
/**
* 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);
}
}
/**
* Set the action to trigger
*
* @param string $actionName
* @return static
*/
public function setActionName($actionName) {
$this->actionName = (string)$actionName;
return $this;
}
/**
* 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;
}
/**
* Set the label name
*
* @param string $labelName Script Label name
* @return static
*/
public function setLabelName($labelName) {
$this->labelName = (string)$labelName;
return $this;
}
/**
* @see \FML\Script\Features\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, true);
if ($this->control) {
// Control event
$controlId = Builder::escapeText($this->control->getId(), true);
$scriptText = "
if (Event.Control.ControlId == {$controlId}) {
TriggerPageAction({$actionName});
}";
} else {
// Other
$scriptText = "
TriggerPageAction({$actionName});";
}
return $scriptText;
}
}

View File

@ -0,0 +1,221 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Entry;
use FML\Controls\Quad;
use FML\Models\CheckBoxDesign;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptInclude;
use FML\Script\ScriptLabel;
/**
* Script Feature for creating a CheckBox behavior
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 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';
/*
* 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;
/**
* 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());
}
/**
* Set the CheckBox Quad
*
* @param Quad $quad CheckBox Quad
* @return static
*/
public function setQuad(Quad $quad) {
$this->quad = $quad->checkId()->setScriptEvents(true);
return $this;
}
/**
* Get the CheckBox Quad
*
* @return \FML\Controls\Quad
*/
public function getQuad() {
return $this->quad;
}
/**
* Set the CheckBox Entry
*
* @param Entry $entry CheckBox Entry
* @return static
*/
public function setEntry(Entry $entry) {
$this->entry = $entry->checkId();
return $this;
}
/**
* Get the managed Entry
*
* @return \FML\Controls\Entry
*/
public function getEntry() {
return $this->entry;
}
/**
* Set the default value
*
* @param bool $default Default value
* @return static
*/
public function setDefault($default) {
$this->default = (bool)$default;
return $this;
}
/**
* Set the enabled Design
*
* @param CheckBoxDesign $checkBoxDesign Enabled CheckBox Design
* @return static
*/
public function setEnabledDesign(CheckBoxDesign $checkBoxDesign) {
$this->enabledDesign = $checkBoxDesign;
return $this;
}
/**
* Set the disabled Design
*
* @param CheckBoxDesign $checkBoxDesign Disabled CheckBox Design
* @return static
*/
public function setDisabledDesign(CheckBoxDesign $checkBoxDesign) {
$this->disabledDesign = $checkBoxDesign;
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;
}
/**
* 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;
_Quad.StyleSelected = Enabled;
declare " . self::VAR_CHECKBOX_DESIGNS . " as Designs for _Quad = Text[Boolean];
declare Design = Designs[Enabled];
declare DesignParts = TextLib::Split(\"|\", Design);
if (DesignParts.count > 1) {
_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 Entry <=> (Page.GetFirstChild(EntryId) as CMlEntry);
Entry.Value = Value;
}
}";
}
/**
* 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);
declare Text[Boolean] " . self::VAR_CHECKBOX_DESIGNS . " as Designs for Quad_CheckBox;
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};
" . 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}) {
declare Quad_CheckBox <=> (Event.Control as CMlQuad);
" . self::FUNCTION_UPDATE_QUAD_DESIGN . "(Quad_CheckBox);
}";
}
}

View File

@ -0,0 +1,105 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Label;
use FML\Script\Script;
use FML\Script\ScriptInclude;
use FML\Script\ScriptLabel;
/**
* Script Feature showing the current time on a Label
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 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;
/**
* 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);
}
/**
* Set the Label
*
* @param Label $label Clock Label
* @return static
*/
public function setLabel(Label $label) {
$this->label = $label->checkId();
return $this;
}
/**
* 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;
}
/**
* 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;
}
/**
* @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 script text
*
* @return string
*/
protected function getScriptText() {
$controlId = $this->label->getId(true, true);
$scriptText = "
declare ClockLabel <=> (Page.GetFirstChild({$controlId}) as CMlLabel);
declare TimeText = CurrentLocalDateText;";
if (!$this->showSeconds) {
$scriptText .= "
TimeText = TextLib::SubText(TimeText, 0, 16);";
}
if (!$this->showFullDate) {
$scriptText .= "
TimeText = TextLib::SubText(TimeText, 11, 9);";
}
$scriptText .= "
ClockLabel.Value = TimeText;";
return $scriptText;
}
}

View File

@ -0,0 +1,125 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for a Control related script
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 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;
/**
* 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);
}
/**
* Set the Control
*
* @param Control $control Event Control
* @return static
*/
public function setControl(Control $control) {
$this->control = $control->checkId();
$this->updateScriptEvents();
return $this;
}
/**
* Set the script text
*
* @param string $text Script text
* @return static
*/
public function setText($text) {
$this->text = (string)$text;
return $this;
}
/**
* Set the label name
*
* @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
*/
protected function updateScriptEvents() {
if (!$this->control || !ScriptLabel::isEventLabel($this->labelName)) {
return;
}
if ($this->control instanceof Scriptable) {
$this->control->setScriptEvents(true);
}
}
/**
* @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;
}
/**
* 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;
}
}

View File

@ -0,0 +1,101 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Entry;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptInclude;
use FML\Script\ScriptLabel;
/**
* Script Feature for submitting an Entry
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 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;
/**
* 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);
}
/**
* Set the Entry
*
* @param Entry $entry Entry Control
* @return static
*/
public function setEntry(Entry $entry) {
$this->entry = $entry->checkId()->setScriptEvents(true);
return $this;
}
/**
* Set the submit url
*
* @param string $url Submit url
* @return static
*/
public function setUrl($url) {
$this->url = (string)$url;
return $this;
}
/**
* @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 script text
*
* @return string
*/
protected function getScriptText() {
$url = $this->buildCompatibleUrl();
$entryName = $this->entry->getName();
$link = Builder::escapeText($entryName . $url . '=', true);
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;
}
}

View File

@ -0,0 +1,124 @@
<?php
namespace FML\Script\Features;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptLabel;
/**
* Script Feature for triggering a manialink page action on key press
*
* @author steeffeen
* @link http://destroflyer.mania-community.de/maniascript/keycharid_table.php
* @copyright FancyManiaLinks Copyright © 2014 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;
/**
* 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);
}
}
/**
* Set the action to trigger
*
* @param string $actionName Triggered action
* @return static
*/
public function setActionName($actionName) {
$this->actionName = (string)$actionName;
return $this;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* @see \FML\Script\Features\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, 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 "
if (Event.{$key} == {$value}) {
TriggerPageAction({$actionName});
}";
}
}

View File

@ -0,0 +1,91 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for opening the map info
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 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;
/**
* 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);
}
/**
* 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;
}
/**
* Set the label name
*
* @param string $labelName Script Label name
* @return static
*/
public function setLabelName($labelName) {
$this->labelName = (string)$labelName;
return $this;
}
/**
* @see \FML\Script\Features\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(), true);
$scriptText = "
if (Event.Control.ControlId == {$controlId}) {
ShowCurChallengeCard();
}";
} else {
// Other
$scriptText = "
ShowCurChallengeCard();";
}
return $scriptText;
}
}

View File

@ -0,0 +1,140 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Builder;
use FML\Script\Script;
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
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Menu extends ScriptFeature {
/*
* Constants
*/
const FUNCTION_UPDATE_MENU = 'FML_UpdateMenu';
/*
* Protected properties
*/
/** @var MenuElement[] $elements */
protected $elements = array();
/** @var MenuElement $startElement */
protected $startElement = null;
/**
* 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);
}
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$updateFunctionName = self::FUNCTION_UPDATE_MENU;
$elementsArrayText = $this->getElementsArrayText();
// OnInit
if ($this->startElement) {
$startControlId = $this->startElement->getControl()->getId(true, true);
$initScriptText = "
{$updateFunctionName}({$elementsArrayText}, {$startControlId});";
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $initScriptText, true);
}
// 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);
// 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);
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);
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Types\Scriptable;
/**
* Menu Element for the Menu Feature
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 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;
/**
* 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);
}
}
/**
* 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;
}
/**
* Get the Item Control
*
* @return \FML\Controls\Control
*/
public function getItem() {
return $this->item;
}
/**
* 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 Menu Control
*
* @return \FML\Controls\Control
*/
public function getControl() {
return $this->control;
}
}

View File

@ -0,0 +1,348 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Controls\Label;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptInclude;
use FML\Script\ScriptLabel;
/**
* Script Feature realising a mechanism for browsing through Pages
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 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';
/*
* 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;
/**
* 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);
}
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* Set the Start Page number
*
* @param int $startPageNumber Page number to start with
* @return static
*/
public function setStartPageNumber($startPageNumber) {
$this->startPageNumber = (int)$startPageNumber;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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 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;
}
/**
* @see \FML\Script\Features\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);
$pageLabelId = '""';
if ($this->label) {
$pageLabelId = $this->label->getId(true, true);
}
$pagesArrayText = $this->getPagesArrayText();
$pageButtonsArrayText = $this->getPageButtonsArrayText();
$previousChunkAction = Builder::escapeText($this->previousChunkAction, true);
$nextChunkAction = Builder::escapeText($this->nextChunkAction, true);
$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);
// 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);
// 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;
declare CurrentPage = {$currentPageVariable}[_PagingId] + _BrowseAction;
if (CurrentPage < _MinPageNumber) {
CurrentPage = _MinPageNumber;
} else if (CurrentPage > _MaxPageNumber) {
CurrentPage = _MaxPageNumber;
}
{$currentPageVariable}[_PagingId] = CurrentPage;
declare PageFound = False;
foreach (PageNumber => PageId in _Pages) {
declare PageControl <=> Page.GetFirstChild(PageId);
PageControl.Visible = (CurrentPage == PageNumber);
if (PageControl.Visible) {
PageFound = True;
}
}
if (!PageFound && _BrowseAction != 0) {
declare Text ChunkAction;
if (_BrowseAction < 0) {
ChunkAction = _PreviousChunkAction;
} else {
ChunkAction = _NextChunkAction;
}
if (_ChunkActionAppendPageNumber) {
ChunkAction ^= CurrentPage;
}
TriggerPageAction(ChunkAction);
}
if (_PageLabelId == " . Builder::EMPTY_STRING . ") return;
declare PageLabel <=> (Page.GetFirstChild(_PageLabelId) as CMlLabel);
if (PageLabel == Null) return;
PageLabel.Value = CurrentPage^\"/\"^_MaxPageNumber;
}";
$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 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;
}
/**
* 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->getBrowseAction();
}
return Builder::getArray($pageButtons, true);
}
}

View File

@ -0,0 +1,81 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Types\Scriptable;
/**
* Paging Button for browsing through Pages
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 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;
/**
* 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);
}
}
/**
* 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;
}
/**
* Get the Button Control
*
* @return \FML\Controls\Control
*/
public function getControl() {
return $this->control;
}
/**
* 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 browse action
*
* @return int
*/
public function getBrowseAction() {
return $this->browseAction;
}
}

View File

@ -0,0 +1,74 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
/**
* Paging Page
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 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;
/**
* 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);
}
/**
* Set the Page Control
*
* @param Control $control Page Control
* @return static
*/
public function setControl(Control $control) {
$this->control = $control->checkId();
return $this;
}
/**
* Get the Page Control
*
* @return \FML\Controls\Control
*/
public function getControl() {
return $this->control;
}
/**
* 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 number
*
* @return int
*/
public function getPageNumber() {
return $this->number;
}
}

View File

@ -0,0 +1,108 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for opening a player profile
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 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;
/**
* 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);
}
/**
* Set the login of the opened player
*
* @param string $login Player login
* @return static
*/
public function setLogin($login) {
$this->login = $login;
return $this;
}
/**
* 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;
}
/**
* Set the label name
*
* @param string $labelName Script Label name
* @return static
*/
public function setLabelName($labelName) {
$this->labelName = (string)$labelName;
return $this;
}
/**
* @see \FML\Script\Features\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, true);
if ($this->control) {
// Control event
$controlId = Builder::escapeText($this->control->getId(), true);
$scriptText = "
if (Event.Control.ControlId == {$controlId}) {
ShowProfile({$login});
}";
} else {
// Other
$scriptText = "
ShowProfile({$login});";
}
return $scriptText;
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace FML\Script\Features;
use FML\Script\Script;
use FML\Types\ScriptFeatureable;
/**
* ManiaLink Script Feature Class
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
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;
}
/**
* 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);
}

View File

@ -0,0 +1,138 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for toggling Controls
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 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;
/**
* 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);
}
/**
* 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;
}
/**
* Set the toggled Control
*
* @param Control $control Toggling Control
* @return static
*/
public function setToggledControl(Control $control) {
$this->toggledControl = $control->checkId();
return $this;
}
/**
* Set the label name
*
* @param string $labelName Script Label Name
* @return static
*/
public function setLabelName($labelName) {
$this->labelName = (string)$labelName;
return $this;
}
/**
* 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;
}
/**
* 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;
}
/**
* @see \FML\Script\Features\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 = $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 "
if (Event.Control.ControlId == {$togglingControlId}) {
declare ToggleControl = Page.GetFirstChild({$toggledControlId});
ToggleControl.Visible = {$visibility};
}";
}
}

View File

@ -0,0 +1,162 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Controls\Label;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for showing Tooltips
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 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;
/**
* 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);
}
}
/**
* 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;
}
/**
* Set the Tooltip Control
*
* @param Control $tooltipControl Tooltip Control
* @return static
*/
public function setTooltipControl(Control $tooltipControl) {
$this->tooltipControl = $tooltipControl->checkId()->setVisible(false);
return $this;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$hoverControlId = $this->hoverControl->getId(true, true);
$tooltipControlId = $this->tooltipControl->getId(true, true);
// MouseOver
$visibility = ($this->invert ? 'False' : 'True');
$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 .= "
declare TooltipLabel = (TooltipControl as CMlLabel);
TooltipLabel.Value = {$tooltipText};";
}
$scriptText .= "
}";
$script->appendGenericScriptLabel(ScriptLabel::MOUSEOVER, $scriptText);
// MouseOut
$visibility = ($this->invert ? 'True' : 'False');
$scriptText = "
if (Event.Control.ControlId == {$hoverControlId}) {
declare TooltipControl = Page.GetFirstChild({$tooltipControlId});";
if ($this->stayOnClick) {
$scriptText .= "
declare FML_Clicked for Event.Control = False;
if (!FML_Clicked) ";
}
$scriptText .= "
TooltipControl.Visible = {$visibility};
}";
$script->appendGenericScriptLabel(ScriptLabel::MOUSEOUT, $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;
}
}

View File

@ -0,0 +1,168 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for playing a UISound
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 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';
/*
* Protected properties
*/
protected $soundName = null;
/** @var Control $control */
protected $control = null;
protected $variant = 0;
protected $volume = 1.;
protected $labelName = null;
/**
* 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);
}
/**
* Set the sound to play
*
* @param string $soundName Sound name
* @return static
*/
public function setSoundName($soundName) {
$this->soundName = (string)$soundName;
return $this;
}
/**
* 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;
}
/**
* Set the sound variant
*
* @param int $variant Sound variant
* @return static
*/
public function setVariant($variant) {
$this->variant = (int)$variant;
return $this;
}
/**
* Set the volume
*
* @param float $volume Sound volume
* @return static
*/
public function setVolume($volume) {
$this->volume = (float)$volume;
return $this;
}
/**
* Set the label name
*
* @param string $labelName Script Label name
* @return static
*/
public function setLabelName($labelName) {
$this->labelName = (string)$labelName;
return $this;
}
/**
* @see \FML\Script\Features\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(), true);
$scriptText = "
if (Event.Control.ControlId == {$controlId}) {
PlayUiSound(CMlScriptIngame::EUISound::{$this->soundName}, {$this->variant}, {$this->volume});
}";
} else {
// Other
$scriptText = "
PlayUiSound(CMlScriptIngame::EUISound::{$this->soundName}, {$this->variant}, {$this->volume});";
}
return $scriptText;
}
}

View File

@ -0,0 +1,226 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Entry;
use FML\Controls\Label;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptInclude;
use FML\Script\ScriptLabel;
/**
* Script Feature for creating a ValuePicker behavior
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 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';
/*
* Protected properties
*/
/** @var Label $label */
protected $label = null;
/** @var Entry $entry */
protected $entry = null;
protected $values = array();
protected $default = null;
/**
* 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);
}
}
/**
* Set the ValuePicker Label
*
* @param Label $label ValuePicker Label
* @return static
*/
public function setLabel(Label $label) {
$this->label = $label->checkId()->setScriptEvents(true);
return $this;
}
/**
* Get the ValuePicker Label
*
* @return \FML\Controls\Label
*/
public function getLabel() {
return $this->label;
}
/**
* Set the hidden Entry
*
* @param Entry $entry Hidden Entry
* @return static
*/
public function setEntry(Entry $entry) {
$this->entry = $entry->checkId();
return $this;
}
/**
* Get the hidden Entry
*
* @return \FML\Controls\Entry
*/
public function getEntry() {
return $this->entry;
}
/**
* 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;
}
/**
* Set the default value
*
* @param string $default Default value
* @return static
*/
public function setDefault($default) {
$this->default = (string)$default;
}
/**
* 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;
}
/**
* @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;
}
/**
* 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;
if (Values.exists(_Label.Value)) {
declare ValueIndex = Values.keyof(_Label.Value);
ValueIndex += 1;
if (Values.existskey(ValueIndex)) {
NewValueIndex = ValueIndex;
} else {
NewValueIndex = 0;
}
}
declare NewValue = " . Builder::EMPTY_STRING . ";
if (Values.existskey(NewValueIndex)) {
NewValue = Values[NewValueIndex];
} else {
declare " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for _Label = " . Builder::EMPTY_STRING . ";
NewValue = Default;
}
_Label.Value = NewValue;
declare " . self::VAR_PICKER_ENTRY_ID . " as EntryId for _Label = " . Builder::EMPTY_STRING . ";
if (EntryId != " . Builder::EMPTY_STRING . ") {
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);
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};
" . 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}) {
declare Label_Picker <=> (Event.Control as CMlLabel);
" . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker);
}";
}
}