From ac1ea81b94421123cfbdcea0b109cd6a1356e882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Sun, 16 Feb 2014 13:59:28 +0100 Subject: [PATCH] FML Update --- application/core/FML/Controls/Entry.php | 3 -- application/core/FML/ManiaLink.php | 17 ++++++-- application/core/FML/ManiaLinks.php | 6 +-- application/core/FML/Script/Builder.php | 14 +++++++ application/core/FML/Script/Parts/Main.txt | 6 ++- application/core/FML/Script/Script.php | 45 ++++++++++++++++++++++ 6 files changed, 80 insertions(+), 11 deletions(-) diff --git a/application/core/FML/Controls/Entry.php b/application/core/FML/Controls/Entry.php index 2513fba5..a0b7d1f8 100644 --- a/application/core/FML/Controls/Entry.php +++ b/application/core/FML/Controls/Entry.php @@ -146,9 +146,6 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF */ public function render(\DOMDocument $domDocument) { $xmlElement = parent::render($domDocument); - if (false) { - $xmlElement->setAttribute('action', 'TestAction'); - } if ($this->name) { $xmlElement->setAttribute('name', $this->name); } diff --git a/application/core/FML/ManiaLink.php b/application/core/FML/ManiaLink.php index dd49a35b..d415500c 100644 --- a/application/core/FML/ManiaLink.php +++ b/application/core/FML/ManiaLink.php @@ -39,7 +39,7 @@ class ManiaLink { /** * Create a new ManiaLink Object * - * @param string $id (optional) Manialink Id + * @param string $id (optional) ManiaLink Id * @return \FML\ManiaLink */ public static function create($id = null) { @@ -50,7 +50,7 @@ class ManiaLink { /** * Construct a new ManiaLink Object * - * @param string $id (optional) Manialink Id + * @param string $id (optional) ManiaLink Id */ public function __construct($id = null) { if ($id !== null) { @@ -70,9 +70,9 @@ class ManiaLink { } /** - * Set Manialink Id + * Set ManiaLink Id * - * @param string $id Manialink Id + * @param string $id ManiaLink Id * @return \FML\ManiaLink */ public function setId($id) { @@ -80,6 +80,15 @@ class ManiaLink { return $this; } + /** + * Get ManiaLink Id + * + * @return string + */ + public function getId() { + return $this->id; + } + /** * Set Background * diff --git a/application/core/FML/ManiaLinks.php b/application/core/FML/ManiaLinks.php index 0d77bdab..d9a430e2 100644 --- a/application/core/FML/ManiaLinks.php +++ b/application/core/FML/ManiaLinks.php @@ -44,9 +44,9 @@ class ManiaLinks { } /** - * Add a Child Manialink + * Add a Child ManiaLink * - * @param ManiaLink $child Child Manialink + * @param ManiaLink $child Child ManiaLink * @return \FML\ManiaLinks */ public function add(ManiaLink $child) { @@ -57,7 +57,7 @@ class ManiaLinks { } /** - * Remove all Child Manialinks + * Remove all Child ManiaLinks * * @return \FML\ManiaLinks */ diff --git a/application/core/FML/Script/Builder.php b/application/core/FML/Script/Builder.php index 0fd8731e..033c8c03 100644 --- a/application/core/FML/Script/Builder.php +++ b/application/core/FML/Script/Builder.php @@ -47,4 +47,18 @@ abstract class Builder { if (!fmod($value, 1)) $stringVal .= '.'; return $stringVal; } + + /** + * Get the Boolean String-Representation of the given Value + * + * @param bool $value The Value to convert to a ManiaScript Boolean + * @return string + */ + public static function getBoolean($value) { + $bool = (bool) $value; + if ($bool) { + return "True"; + } + return "False"; + } } diff --git a/application/core/FML/Script/Parts/Main.txt b/application/core/FML/Script/Parts/Main.txt index 558de16a..1262b5d3 100644 --- a/application/core/FML/Script/Parts/Main.txt +++ b/application/core/FML/Script/Parts/Main.txt @@ -3,6 +3,7 @@ main() { declare FML_ScriptStart = Now; +++OnInit+++ declare FML_LoopCounter = 0; + declare FML_LastTick = 0; while (True) { yield; foreach (Event in PendingEvents) { @@ -24,7 +25,10 @@ main() { } } } - +++Loop+++ FML_LoopCounter += 1; + +++Loop+++ + if (FML_LastTick + 250 > Now) continue; + FML_LastTick = Now; + +++Tick+++ } } \ No newline at end of file diff --git a/application/core/FML/Script/Script.php b/application/core/FML/Script/Script.php index 9e848934..9c5d8188 100644 --- a/application/core/FML/Script/Script.php +++ b/application/core/FML/Script/Script.php @@ -28,14 +28,17 @@ class Script { const CLASS_TOGGLE = 'FML_Toggle'; const CLASS_SPECTATE = 'FML_Spectate'; const CLASS_PAGEACTION = 'FML_PageAction'; + const CLASS_TIME = 'FML_Time'; const OPTION_TOOLTIP_STAYONCLICK = 'FML_StayOnClick_Tooltip'; const OPTION_TOOLTIP_INVERT = 'FML_Invert_Tooltip'; const OPTION_TOOLTIP_TEXT = 'FML_Text_Tooltip'; const OPTION_TOGGLE_SHOW = 'FML_Show_Toggle'; const OPTION_TOGGLE_HIDE = 'FML_Hide_Toggle'; const OPTION_PROFILE_OWN = 'FML_Own_Profile'; + const OPTION_TIME_FULLDATE = 'FML_FullDate_Time'; const LABEL_ONINIT = 'OnInit'; const LABEL_LOOP = 'Loop'; + const LABEL_TICK = 'Tick'; const LABEL_ENTRYSUBMIT = 'EntrySubmit'; const LABEL_KEYPRESS = 'KeyPress'; const LABEL_MOUSECLICK = 'MouseClick'; @@ -63,6 +66,7 @@ class Script { protected $toggles = false; protected $spectate = false; protected $pageActions = false; + protected $times = false; /** * Create a new Script Object @@ -365,6 +369,7 @@ class Script { * * @param Control $actionControl The Control triggering the Action * @param string $action (optional) The Action to trigger (if empty the Action of the Control will be triggered) + * @return \FML\Script\Script */ public function addPageActionTrigger(Control $actionControl, $action = null) { if (!($actionControl instanceof Scriptable)) { @@ -387,6 +392,22 @@ class Script { return $this; } + /** + * Add a Label showing the current Time + * + * @param Label $timeLabel The Label showing the current Time + * @param bool $showFullDate Whether to show the full Date Text + * @return \FML\Script\Script + */ + public function addTimeLabel(Label $timeLabel, $showFullDate = false) { + $timeLabel->addClass(self::CLASS_TIME); + if ($showFullDate) { + $timeLabel->addClass(self::OPTION_TIME_FULLDATE); + } + $this->times = true; + return $this; + } + /** * Create the Script XML Tag * @@ -553,6 +574,7 @@ Text " . self::FUNCTION_GETTOOLTIPCONTROLID . "(Text _ControlClass) { $labelsText .= $this->getSoundLabels(); $labelsText .= $this->getToggleLabels(); $labelsText .= $this->getSpectateLabels(); + $labelsText .= $this->getTimeLabels(); return $labelsText; } @@ -898,6 +920,29 @@ if (Event.Control.HasClass(\"" . self::CLASS_PAGEACTION . "\")) { return $pageActionScript; } + /** + * Get the Time Labels + * + * @return string + */ + private function getTimeLabels() { + if (!$this->times) return ''; + $this->setInclude('TextLib', 'TextLib'); + $timesScript = " +Page.GetClassChildren(\"" . self::CLASS_TIME . "\", Page.MainFrame, True); +foreach (TimeLabelControl in Page.GetClassChildren_Result) { + declare TimeLabel = (TimeLabelControl as CMlLabel); + declare ShowFullDate = TimeLabel.HasClass(\"" . self::OPTION_TIME_FULLDATE . "\"); + if (ShowFullDate) { + TimeLabel.Value = CurrentLocalDateText; + } else { + TimeLabel.Value = TextLib::SubText(CurrentLocalDateText, 11, 8); + } +}"; + $timesScript = Builder::getLabelImplementationBlock(self::LABEL_TICK, $timesScript); + return $timesScript; + } + /** * Get the Main Function *