2014-04-27 14:44:40 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FML\Script\Features;
|
|
|
|
|
|
|
|
use FML\Controls\Control;
|
2014-05-14 23:24:00 +02:00
|
|
|
use FML\Script\Builder;
|
2014-04-27 14:44:40 +02:00
|
|
|
use FML\Script\Script;
|
|
|
|
use FML\Script\ScriptLabel;
|
2014-05-14 23:24:00 +02:00
|
|
|
use FML\Types\Scriptable;
|
2014-04-27 14:44:40 +02:00
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Script Feature for opening the map info
|
2014-04-27 14:44:40 +02:00
|
|
|
*
|
2014-05-14 23:24:00 +02:00
|
|
|
* @author steeffeen
|
2014-04-27 14:44:40 +02:00
|
|
|
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
2014-05-14 23:24:00 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-04-27 14:44:40 +02:00
|
|
|
*/
|
|
|
|
class MapInfo extends ScriptFeature {
|
|
|
|
/*
|
2014-06-21 03:18:21 +02:00
|
|
|
* Protected properties
|
2014-04-27 14:44:40 +02:00
|
|
|
*/
|
2014-05-14 23:24:00 +02:00
|
|
|
/** @var Control $control */
|
2014-04-27 14:44:40 +02:00
|
|
|
protected $control = null;
|
|
|
|
protected $labelName = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new Map Info Feature
|
|
|
|
*
|
2014-05-14 23:24:00 +02:00
|
|
|
* @param Control $control (optional) Map Info Control
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $labelName (optional) Script Label name
|
2014-04-27 14:44:40 +02:00
|
|
|
*/
|
|
|
|
public function __construct(Control $control, $labelName = ScriptLabel::MOUSECLICK) {
|
|
|
|
$this->setControl($control);
|
|
|
|
$this->setLabelName($labelName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the Control
|
|
|
|
*
|
2014-05-14 23:24:00 +02:00
|
|
|
* @param Control $control Map Info Control
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-04-27 14:44:40 +02:00
|
|
|
*/
|
|
|
|
public function setControl(Control $control) {
|
|
|
|
$control->checkId();
|
2014-05-14 23:24:00 +02:00
|
|
|
if ($control instanceof Scriptable) {
|
|
|
|
$control->setScriptEvents(true);
|
|
|
|
}
|
2014-04-27 14:44:40 +02:00
|
|
|
$this->control = $control;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Set the label name
|
2014-04-27 14:44:40 +02:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $labelName Script Label name
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-04-27 14:44:40 +02:00
|
|
|
*/
|
|
|
|
public function setLabelName($labelName) {
|
2014-06-21 03:18:21 +02:00
|
|
|
$this->labelName = (string)$labelName;
|
2014-04-27 14:44:40 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \FML\Script\Features\ScriptFeature::prepare()
|
|
|
|
*/
|
|
|
|
public function prepare(Script $script) {
|
|
|
|
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Get the script text
|
2014-04-27 14:44:40 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getScriptText() {
|
|
|
|
if ($this->control) {
|
|
|
|
// Control event
|
2014-06-21 03:18:21 +02:00
|
|
|
$controlId = Builder::escapeText($this->control->getId(), true);
|
2014-04-27 14:44:40 +02:00
|
|
|
$scriptText = "
|
2014-06-21 03:18:21 +02:00
|
|
|
if (Event.Control.ControlId == {$controlId}) {
|
2014-04-27 14:44:40 +02:00
|
|
|
ShowCurChallengeCard();
|
|
|
|
}";
|
2014-05-14 23:24:00 +02:00
|
|
|
} else {
|
2014-04-27 14:44:40 +02:00
|
|
|
// Other
|
|
|
|
$scriptText = "
|
|
|
|
ShowCurChallengeCard();";
|
|
|
|
}
|
|
|
|
return $scriptText;
|
|
|
|
}
|
|
|
|
}
|