Updated to ManiaLink v3

This commit is contained in:
Jocy Wolff
2017-03-25 18:40:15 +01:00
parent 1010c1db6b
commit 120a0e2169
133 changed files with 16194 additions and 8949 deletions

View File

@ -3,6 +3,7 @@
namespace FML\Script\Features;
use FML\Controls\Label;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptInclude;
use FML\Script\ScriptLabel;
@ -11,95 +12,149 @@ use FML\Script\ScriptLabel;
* Script Feature showing the current time on a Label
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Clock extends ScriptFeature {
/*
* Protected properties
*/
/** @var Label $label */
protected $label = null;
protected $showSeconds = null;
protected $showFullDate = null;
class Clock extends ScriptFeature
{
/**
* Construct a new Clock Feature
*
* @param Label $label (optional) Clock Label
* @param bool $showSeconds (optional) Whether the seconds should be shown
* @param bool $showFullDate (optional) Whether the date should be shown
*/
public function __construct(Label $label = null, $showSeconds = true, $showFullDate = false) {
if ($label !== null) {
$this->setLabel($label);
}
$this->setShowSeconds($showSeconds);
$this->setShowFullDate($showFullDate);
}
/**
* @var Label $label Clock Label
*/
protected $label = null;
/**
* Set the Label
*
* @param Label $label Clock Label
* @return static
*/
public function setLabel(Label $label) {
$this->label = $label->checkId();
return $this;
}
/**
* @var bool $showSeconds Show the seconds
*/
protected $showSeconds = null;
/**
* Set whether seconds should be shown
*
* @param bool $showSeconds Whether seconds should be shown
* @return static
*/
public function setShowSeconds($showSeconds) {
$this->showSeconds = (bool)$showSeconds;
return $this;
}
/**
* @var bool $showFullDate Show the date
*/
protected $showFullDate = null;
/**
* Set whether the full date should be shown
*
* @param bool $showFullDate Whether the full date should be shown
* @return static
*/
public function setShowFullDate($showFullDate) {
$this->showFullDate = (bool)$showFullDate;
return $this;
}
/**
* Construct a new Clock
*
* @api
* @param Label $label (optional) Clock Label
* @param bool $showSeconds (optional) Show the seconds
* @param bool $showFullDate (optional) Show the date
*/
public function __construct(Label $label = null, $showSeconds = true, $showFullDate = false)
{
if ($label) {
$this->setLabel($label);
}
$this->setShowSeconds($showSeconds)
->setShowFullDate($showFullDate);
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$script->setScriptInclude(ScriptInclude::TEXTLIB);
$script->appendGenericScriptLabel(ScriptLabel::TICK, $this->getScriptText(), true);
return $this;
}
/**
* Get the Label
*
* @api
* @return Label
*/
public function getLabel()
{
return $this->label;
}
/**
* Get the script text
*
* @return string
*/
protected function getScriptText() {
$controlId = $this->label->getId(true, true);
$scriptText = "
/**
* Set the Label
*
* @api
* @param Label $label Clock Label
* @return static
*/
public function setLabel(Label $label)
{
$label->checkId();
$this->label = $label;
return $this;
}
/**
* Get if seconds should be shown
*
* @api
* @return bool
*/
public function getShowSeconds()
{
return $this->showSeconds;
}
/**
* Set if seconds should be shown
*
* @api
* @param bool $showSeconds If seconds should be shown
* @return static
*/
public function setShowSeconds($showSeconds)
{
$this->showSeconds = (bool)$showSeconds;
return $this;
}
/**
* Get if the full date should be shown
*
* @api
* @return bool
*/
public function getShowFullDate()
{
return $this->showFullDate;
}
/**
* Set if the full date should be shown
*
* @api
* @param bool $showFullDate If the full date should be shown
* @return static
*/
public function setShowFullDate($showFullDate)
{
$this->showFullDate = (bool)$showFullDate;
return $this;
}
/**
* @see ScriptFeature::prepare()
*/
public function prepare(Script $script)
{
$script->setScriptInclude(ScriptInclude::TEXTLIB)
->appendGenericScriptLabel(ScriptLabel::TICK, $this->getScriptText(), true);
return $this;
}
/**
* Get the script text
*
* @return string
*/
protected function getScriptText()
{
$controlId = Builder::escapeText($this->label->getId());
$scriptText = "
declare ClockLabel <=> (Page.GetFirstChild({$controlId}) as CMlLabel);
declare TimeText = CurrentLocalDateText;";
if (!$this->showSeconds) {
$scriptText .= "
if (!$this->showSeconds) {
$scriptText .= "
TimeText = TextLib::SubText(TimeText, 0, 16);";
}
if (!$this->showFullDate) {
$scriptText .= "
}
if (!$this->showFullDate) {
$scriptText .= "
TimeText = TextLib::SubText(TimeText, 11, 9);";
}
$scriptText .= "
}
$scriptText .= "
ClockLabel.Value = TimeText;";
return $scriptText;
}
return $scriptText;
}
}