Updated to ManiaLink v3
This commit is contained in:
		| @@ -12,97 +12,154 @@ use FML\Types\Scriptable; | ||||
|  * Script Feature for opening a player profile | ||||
|  * | ||||
|  * @author    steeffeen <mail@steeffeen.com> | ||||
|  * @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 PlayerProfile extends ScriptFeature { | ||||
| 	/* | ||||
| 	 * Protected properties | ||||
| 	 */ | ||||
| 	protected $login = null; | ||||
| 	/** @var Control $control */ | ||||
| 	protected $control = null; | ||||
| 	protected $labelName = null; | ||||
| class PlayerProfile extends ScriptFeature | ||||
| { | ||||
|  | ||||
| 	/** | ||||
| 	 * 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); | ||||
| 	} | ||||
|     /** | ||||
|      * @var string $login Player login | ||||
|      */ | ||||
|     protected $login = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * Set the login of the opened player | ||||
| 	 * | ||||
| 	 * @param string $login Player login | ||||
| 	 * @return static | ||||
| 	 */ | ||||
| 	public function setLogin($login) { | ||||
| 		$this->login = $login; | ||||
| 		return $this; | ||||
| 	} | ||||
|     /** | ||||
|      * @var Control $control Profile Control | ||||
|      */ | ||||
|     protected $control = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * 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; | ||||
| 	} | ||||
|     /** | ||||
|      * @var string $labelName Script Label name | ||||
|      */ | ||||
|     protected $labelName = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * Set the label name | ||||
| 	 * | ||||
| 	 * @param string $labelName Script Label name | ||||
| 	 * @return static | ||||
| 	 */ | ||||
| 	public function setLabelName($labelName) { | ||||
| 		$this->labelName = (string)$labelName; | ||||
| 		return $this; | ||||
| 	} | ||||
|     /** | ||||
|      * Construct a new Player Profile | ||||
|      * | ||||
|      * @api | ||||
|      * @param string  $login     (optional) Player login | ||||
|      * @param Control $control   (optional) Profile Control | ||||
|      * @param string  $labelName (optional) Script Label name | ||||
|      */ | ||||
|     public function __construct($login = null, Control $control = null, $labelName = ScriptLabel::MOUSECLICK) | ||||
|     { | ||||
|         if ($login) { | ||||
|             $this->setLogin($login); | ||||
|         } | ||||
|         if ($control) { | ||||
|             $this->setControl($control); | ||||
|         } | ||||
|         if ($labelName) { | ||||
|             $this->setLabelName($labelName); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| 	/** | ||||
| 	 * @see \FML\Script\Features\ScriptFeature::prepare() | ||||
| 	 */ | ||||
| 	public function prepare(Script $script) { | ||||
| 		$script->appendGenericScriptLabel($this->labelName, $this->getScriptText()); | ||||
| 		return $this; | ||||
| 	} | ||||
|     /** | ||||
|      * Get the login of the opened player | ||||
|      * | ||||
|      * @api | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getLogin() | ||||
|     { | ||||
|         return $this->login; | ||||
|     } | ||||
|  | ||||
| 	/** | ||||
| 	 * 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 = " | ||||
|     /** | ||||
|      * Set the login of the opened player | ||||
|      * | ||||
|      * @api | ||||
|      * @param string $login Player login | ||||
|      * @return static | ||||
|      */ | ||||
|     public function setLogin($login) | ||||
|     { | ||||
|         $this->login = (string)$login; | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the Profile Control | ||||
|      * | ||||
|      * @api | ||||
|      * @return Control | ||||
|      */ | ||||
|     public function getControl() | ||||
|     { | ||||
|         return $this->control; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set the Profile Control | ||||
|      * | ||||
|      * @api | ||||
|      * @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; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the Script Label name | ||||
|      * | ||||
|      * @api | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getLabelName() | ||||
|     { | ||||
|         return $this->labelName; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set the Script Label name | ||||
|      * | ||||
|      * @api | ||||
|      * @param string $labelName Script Label name | ||||
|      * @return static | ||||
|      */ | ||||
|     public function setLabelName($labelName) | ||||
|     { | ||||
|         $this->labelName = (string)$labelName; | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @see 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); | ||||
|  | ||||
|         if ($this->control) { | ||||
|             // Control event | ||||
|             $controlId = Builder::escapeText($this->control->getId()); | ||||
|             return " | ||||
| if (Event.Control.ControlId == {$controlId}) { | ||||
| 	ShowProfile({$login}); | ||||
| }"; | ||||
| 		} else { | ||||
| 			// Other | ||||
| 			$scriptText = " | ||||
|         } | ||||
|  | ||||
|         // Other events | ||||
|         return " | ||||
| ShowProfile({$login});"; | ||||
| 		} | ||||
| 		return $scriptText; | ||||
| 	} | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user