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;
|
2014-01-31 00:04:40 +01:00
|
|
|
use ManiaControl\Callbacks\TimerListener;
|
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
|
|
|
*/
|
2014-01-31 00:04:40 +01:00
|
|
|
class CustomUIManager implements CallbackListener, TimerListener {
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2013-12-30 14:52:48 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
const CUSTOMUI_MLID = 'CustomUI.MLID';
|
2014-01-28 15:56:50 +01:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-07-25 16:28:47 +02:00
|
|
|
* Private properties
|
2013-12-30 14:52:48 +01:00
|
|
|
*/
|
2014-08-02 22:31:46 +02: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;
|
|
|
|
|
|
|
|
/**
|
2014-07-25 16:28:47 +02: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
|
|
|
|
2014-08-03 01:34:18 +02: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);
|
2013-12-30 14:52:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the ManiaLink and CustomUI instances
|
|
|
|
*/
|
|
|
|
private function prepareManialink() {
|
|
|
|
$this->customUI = new CustomUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-13 16:40:05 +02:00
|
|
|
* Handle 1 Second Callback
|
2013-12-30 14:52:48 +01:00
|
|
|
*/
|
2014-05-13 16:40:05 +02: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-03-02 13:40:32 +01:00
|
|
|
}
|
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
|
|
|
|
*
|
2014-02-19 15:44:00 +01:00
|
|
|
* @param Player $player
|
2013-12-30 14:52:48 +01:00
|
|
|
*/
|
2014-02-19 15:44:00 +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
|
|
|
|
*
|
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;
|
|
|
|
}
|
|
|
|
}
|