TrackManiaControl/application/core/Manialinks/CustomUIManager.php

179 lines
4.0 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;
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
/**
* Class managing the Custom UI in TrackMania
2013-12-30 14:52:48 +01:00
*
2014-05-02 17:50:30 +02:00
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @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 {
/*
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 */
2013-12-30 14:52:48 +01:00
private $customUI = null;
private $updateManialink = false;
/**
* 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-05 02:17:41 +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();
}
/**
* 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-05 02:17:41 +02:00
$this->maniaControl->getManialinkManager()
->sendManialink($this->customUI, $player);
2014-01-28 15:56:50 +01:00
return;
}
2014-08-05 02:17:41 +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-05 02:17:41 +02:00
$this->maniaControl->getTimerManager()
->registerOneTimeListening($this, function () use (&$player) {
2014-06-17 23:27:28 +02:00
$this->updateManialink($player);
2014-05-02 17:50:30 +02:00
}, 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;
}
}