TrackManiaControl/core/Manialinks/CustomUIManager.php

228 lines
5.9 KiB
PHP
Raw Normal View History

2013-12-30 14:52:48 +01:00
<?php
namespace ManiaControl\Manialinks;
2013-12-31 10:05:38 +01:00
use FML\CustomUI;
2013-12-30 14:52:48 +01:00
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\Structures\Common\UIPropertiesBaseStructure;
2014-01-31 00:04:40 +01:00
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\General\UsageInformationAble;
use ManiaControl\General\UsageInformationTrait;
2014-01-28 15:56:50 +01:00
use ManiaControl\ManiaControl;
2013-12-30 14:52:48 +01:00
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
2013-12-31 10:05:38 +01:00
2013-12-30 14:52:48 +01:00
/**
2015-02-26 15:18:24 +01:00
* Class managing the Custom UI in ManiaPlanet
2013-12-30 14:52:48 +01:00
*
2014-05-02 17:50:30 +02:00
* @author ManiaControl Team <mail@maniacontrol.com>
2017-02-04 11:49:23 +01:00
* @copyright 2014-2017 ManiaControl Team
2014-05-02 17:50:30 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2013-12-30 14:52:48 +01:00
*/
class CustomUIManager implements CallbackListener, TimerListener, UsageInformationAble {
use UsageInformationTrait;
/*
2013-12-30 14:52:48 +01:00
* Constants
*/
const CUSTOMUI_MLID = 'CustomUI.MLID';
2014-01-28 15:56:50 +01:00
/*
* Private properties
2013-12-30 14:52:48 +01:00
*/
/** @var ManiaControl $maniaControl */
2013-12-30 14:52:48 +01:00
private $maniaControl = null;
2014-03-02 14:22:43 +01:00
/** @var customUI $customUI */
2015-02-26 15:18:24 +01:00
private $customUI = null;
2013-12-30 14:52:48 +01:00
private $updateManialink = false;
/**
* ShootMania UI Properties
*
* @var \ManiaControl\Callbacks\Structures\Common\UIPropertiesBaseStructure
*/
private $shootManiaUIProperties;
2013-12-30 14:52:48 +01:00
/**
* Create a custom UI manager instance
2013-12-30 14:52:48 +01:00
*
2013-12-31 12:06:34 +01:00
* @param ManiaControl $maniaControl
2013-12-30 14:52:48 +01:00
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->prepareManialink();
2014-01-28 15:56:50 +01:00
// Callbacks
2014-08-13 11:05:52 +02:00
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handle1Second', 1000);
//Initilize on Init the Properties
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, function () {
$this->maniaControl->getModeScriptEventManager()->getShootmaniaUIProperties();
});
//Update the Structure if its Changed
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::SM_UIPROPERTIES, $this, function (UIPropertiesBaseStructure $structure) {
$this->shootManiaUIProperties = $structure;
//var_dump("UI_PROP");
//var_dump($structure->getUiPropertiesXML());
});
}
/**
* Enable the Notices
*/
public function enableNotices() { //TODO what happens if you set severall at once, than you propably mistakly use the old JSON, so there is the need to update internal json
$xml = str_replace("<notices visible=\"false\" />", "<notices visible=\"true\" />", $this->shootManiaUIProperties->getUiPropertiesXML());
$this->maniaControl->getModeScriptEventManager()->setShootmaniaUIProperties($xml);
}
/**
* Disables the Notices
*/
public function disableNotices() {
$xml = str_replace("<notices visible=\"true\" />", "<notices visible=\"false\" />", $this->shootManiaUIProperties->getUiPropertiesXML());
$this->maniaControl->getModeScriptEventManager()->setShootmaniaUIProperties($xml);
2013-12-30 14:52:48 +01:00
}
/**
* Create the ManiaLink and CustomUI instances
*/
private function prepareManialink() {
$this->customUI = new CustomUI();
}
/**
* Handle 1 Second Callback
2013-12-30 14:52:48 +01:00
*/
public function handle1Second() {
2014-05-02 17:50:30 +02:00
if (!$this->updateManialink) {
2013-12-30 14:52:48 +01:00
return;
}
2014-05-02 17:50:30 +02:00
$this->updateManialink = false;
$this->updateManialink();
2013-12-30 14:52:48 +01:00
}
/**
2014-05-02 17:50:30 +02:00
* Update the CustomUI Manialink
2013-12-30 14:52:48 +01:00
*
2014-05-02 17:50:30 +02:00
* @param Player $player
2013-12-30 14:52:48 +01:00
*/
2014-05-06 10:29:07 +02:00
public function updateManialink(Player $player = null) {
2014-05-02 17:50:30 +02:00
if ($player) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getManialinkManager()->sendManialink($this->customUI, $player);
2014-01-28 15:56:50 +01:00
return;
}
2014-08-13 11:05:52 +02:00
$this->maniaControl->getManialinkManager()->sendManialink($this->customUI);
2013-12-30 14:52:48 +01:00
}
/**
* Handle PlayerJoined Callback
*
* @param Player $player
2013-12-30 14:52:48 +01:00
*/
public function handlePlayerJoined(Player $player) {
2013-12-30 14:52:48 +01:00
$this->updateManialink($player);
2014-03-02 14:18:10 +01:00
2014-05-06 10:29:07 +02:00
//TODO: validate necessity
2014-03-02 14:18:10 +01:00
//send it again after 500ms
2014-08-13 11:05:52 +02:00
$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use (&$player) {
2014-08-25 15:33:22 +02:00
$this->updateManialink($player);
}, 500);
2013-12-30 14:52:48 +01:00
}
/**
* Set Showing of Notices
*
* @see \ManiaControl\Manialinks\CustomUIManager::enableNotices()
* @deprecated
2013-12-31 12:06:34 +01:00
* @param bool $visible
2013-12-30 14:52:48 +01:00
*/
public function setNoticeVisible($visible) {
$this->customUI->setNoticeVisible($visible);
$this->updateManialink = true;
}
/**
* Set Showing of the Challenge Info
*
2013-12-31 12:06:34 +01:00
* @param bool $visible
2013-12-30 14:52:48 +01:00
*/
public function setChallengeInfoVisible($visible) {
$this->customUI->setChallengeInfoVisible($visible);
$this->updateManialink = true;
}
/**
* Set Showing of the Net Infos
*
2013-12-31 12:06:34 +01:00
* @param bool $visible
2013-12-30 14:52:48 +01:00
*/
public function setNetInfosVisible($visible) {
$this->customUI->setNetInfosVisible($visible);
$this->updateManialink = true;
}
/**
* Set Showing of the Chat
*
2013-12-31 12:06:34 +01:00
* @param bool $visible
2013-12-30 14:52:48 +01:00
*/
public function setChatVisible($visible) {
$this->customUI->setChatVisible($visible);
$this->updateManialink = true;
}
/**
* Set Showing of the Checkpoint List
*
2013-12-31 12:06:34 +01:00
* @param bool $visible
2013-12-30 14:52:48 +01:00
*/
public function setCheckpointListVisible($visible) {
$this->customUI->setCheckpointListVisible($visible);
$this->updateManialink = true;
}
/**
* Set Showing of Round Scores
*
2013-12-31 12:06:34 +01:00
* @param bool $visible
2013-12-30 14:52:48 +01:00
*/
public function setRoundScoresVisible($visible) {
$this->customUI->setRoundScoresVisible($visible);
$this->updateManialink = true;
}
/**
* Set Showing of the Scoretable
*
2013-12-31 12:06:34 +01:00
* @param bool $visible
2013-12-30 14:52:48 +01:00
*/
public function setScoretableVisible($visible) {
$this->customUI->setScoretableVisible($visible);
$this->updateManialink = true;
}
/**
* Set Global Showing
*
2013-12-31 12:06:34 +01:00
* @param bool $visible
2013-12-30 14:52:48 +01:00
*/
public function setGlobalVisible($visible) {
$this->customUI->setGlobalVisible($visible);
$this->updateManialink = true;
}
/**
* Get the Shootmania UI Properties
*
* @return \ManiaControl\Callbacks\Structures\Common\UIPropertiesBaseStructure
*/
public function getShootManiaUIProperties() {
return $this->shootManiaUIProperties;
}
2013-12-30 14:52:48 +01:00
}