TrackManiaControl/application/core/Manialinks/CustomUIManager.php

174 lines
3.8 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 Settings
*
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
/*
2013-12-30 14:52:48 +01:00
* Private Properties
*/
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
*
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
2013-12-30 14:52:48 +01:00
// Register for callbacks
2014-01-31 00:04:40 +01:00
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
2014-02-19 10:43:37 +01:00
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
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-05-06 10:29:07 +02:00
$this->maniaControl->manialinkManager->sendManialink($this->customUI, $player);
2014-01-28 15:56:50 +01:00
return;
}
2014-05-02 17:50:30 +02:00
$this->maniaControl->manialinkManager->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-04-20 14:52:26 +02:00
$self = $this;
2014-05-02 17:50:30 +02:00
$this->maniaControl->timerManager->registerOneTimeListening($this, function ($time) use (&$self, &$player) {
2014-04-20 14:52:26 +02:00
$self->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;
}
}