TrackManiaControl/libs/FML/Script/Features/PlayerProfile.php

206 lines
4.2 KiB
PHP
Raw Normal View History

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 a player profile
2014-04-27 14:44:40 +02:00
*
2014-05-20 15:44:45 +02:00
* @author steeffeen <mail@steeffeen.com>
2017-03-25 18:40:15 +01:00
* @copyright FancyManiaLinks Copyright © 2017 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
*/
2017-03-25 18:40:15 +01:00
class PlayerProfile extends ScriptFeature
{
/**
* @var string $login Player login
*/
protected $login = null;
/**
* @var Control $control Profile Control
*/
protected $control = null;
/**
* @var string $labelName Script Label name
*/
protected $labelName = null;
2022-04-14 00:57:52 +02:00
/**
* @var string $titleId Script Label name
*/
protected $titleId = null;
2017-03-25 18:40:15 +01:00
/**
* 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
*/
2022-04-14 00:57:52 +02:00
public function __construct($login = null, Control $control = null, $labelName = ScriptLabel::MOUSECLICK, $titleId = "Trackmania")
2017-03-25 18:40:15 +01:00
{
if ($login) {
$this->setLogin($login);
}
if ($control) {
$this->setControl($control);
}
if ($labelName) {
$this->setLabelName($labelName);
}
2022-04-14 00:57:52 +02:00
if ($titleId) {
$this->setTitleId($titleId);
}
2017-03-25 18:40:15 +01:00
}
/**
* Get the login of the opened player
*
* @api
* @return string
*/
public function getLogin()
{
return $this->login;
}
/**
* 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;
}
2022-04-14 00:57:52 +02:00
/**
* Get the Script Label name
*
* @api
* @return string
*/
public function getTitleId()
{
return $this->titleId;
}
/**
* Set the Script Label name
*
* @api
* @param string $labelName Script Label name
* @return static
*/
public function setTitleId($titleId)
{
$this->titleId = (string)$titleId;
return $this;
}
2017-03-25 18:40:15 +01:00
/**
* @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);
2022-04-14 00:57:52 +02:00
if ($this->titleId == "Trackmania") {
2023-09-27 17:55:40 +02:00
$apicall = "declare Text TMGame_ScoresTable_OpenProfileUserId for ClientUI = \"\";
TMGame_ScoresTable_OpenProfileUserId = {$login};";
2022-04-14 00:57:52 +02:00
} else {
$apicall = "ShowProfile({$login});";
}
2017-03-25 18:40:15 +01:00
if ($this->control) {
// Control event
$controlId = Builder::escapeText($this->control->getId());
2022-04-14 00:57:52 +02:00
2017-03-25 18:40:15 +01:00
return "
2014-06-21 03:18:21 +02:00
if (Event.Control.ControlId == {$controlId}) {
2022-04-14 00:57:52 +02:00
{$apicall}
2014-04-27 14:44:40 +02:00
}";
2017-03-25 18:40:15 +01:00
}
// Other events
return "
2022-04-14 00:57:52 +02:00
{$apicall}";
2017-03-25 18:40:15 +01:00
}
2014-04-27 14:44:40 +02:00
}