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
*
* @author steeffeen & kremsy
* @copyright ManiaControl 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();
}
/**
* Update the CustomUI Manialink
*
2013-12-31 12:06:34 +01:00
* @param Player $player
2013-12-30 14:52:48 +01:00
*/
private function updateManialink(Player $player = null) {
if ($player) {
2014-03-02 13:55:58 +01:00
$this->maniaControl->manialinkManager->sendManialink($this->customUI, $player->login);
2013-12-30 14:52:48 +01:00
return;
}
2014-03-02 13:55:58 +01:00
$this->maniaControl->manialinkManager->sendManialink($this->customUI);
2013-12-30 14:52:48 +01:00
}
/**
2014-01-31 00:04:40 +01:00
* Handle 1Second
2013-12-30 14:52:48 +01:00
*
2014-01-31 00:04:40 +01:00
* @param $time
2013-12-30 14:52:48 +01:00
*/
2014-01-31 00:04:40 +01:00
public function handle1Second($time) {
2014-01-28 15:56:50 +01:00
if (!$this->updateManialink) {
return;
}
2013-12-30 14:52:48 +01:00
$this->updateManialink = false;
$this->updateManialink();
}
/**
* 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
//send it again after 500ms
2014-03-02 13:55:58 +01:00
$this->maniaControl->timerManager->registerOneTimeListening($this, function($time) use (&$player){
$this->updateManialink($player);
2014-03-02 14:18:10 +01: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;
}
}