2013-11-28 03:47:08 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Configurators;
|
|
|
|
|
|
|
|
use ManiaControl\ManiaControl;
|
2013-11-28 04:48:04 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2013-11-28 03:47:08 +01:00
|
|
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
|
|
|
use ManiaControl\Players\Player;
|
2013-11-28 04:48:04 +01:00
|
|
|
use FML\ManiaLink;
|
2013-11-28 03:47:08 +01:00
|
|
|
use FML\Controls\Quad;
|
2013-11-28 04:48:04 +01:00
|
|
|
use FML\Controls\Frame;
|
|
|
|
use FML\Controls\Quads\Quad_UiSMSpectatorScoreBig;
|
|
|
|
use FML\Controls\Quads\Quad_EnergyBar;
|
|
|
|
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
|
|
|
use FML\Controls\Quads\Quad_BgRaceScore2;
|
2013-11-28 03:47:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class managing ingame ManiaControl configuration
|
|
|
|
*
|
|
|
|
* @author steeffeen & kremsy
|
|
|
|
*/
|
2013-11-28 04:48:04 +01:00
|
|
|
class Configurator implements CallbackListener, ManialinkPageAnswerListener {
|
2013-11-28 03:47:08 +01:00
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
2013-11-28 04:48:04 +01:00
|
|
|
const MLID_MENU = 'Configurator.Menu.MLID';
|
|
|
|
const ACTION_TOGGLEMENU = 'Configurator.ToggleMenuAction';
|
2013-11-28 03:47:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private properties
|
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
2013-11-28 04:48:04 +01:00
|
|
|
private $playersMenuShown = array();
|
|
|
|
private $manialink = null;
|
|
|
|
private $emptyManialink = null;
|
2013-11-28 03:47:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Configurator
|
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
$this->addAdminMenuItem();
|
|
|
|
|
2013-11-28 04:48:04 +01:00
|
|
|
// Register for page answers
|
|
|
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this,
|
|
|
|
'handleToggleMenuAction');
|
|
|
|
|
|
|
|
// Register for callbacks
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this,
|
|
|
|
'handlePlayerDisconnect');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle toggle menu action
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function handleToggleMenuAction(array $callback, Player $player) {
|
|
|
|
if (isset($this->playersMenuShown[$player->login])) {
|
|
|
|
$this->hideMenu($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->showMenu($player);
|
2013-11-28 03:47:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-11-28 04:48:04 +01:00
|
|
|
* Handle PlayerDisconnect callback
|
2013-11-28 03:47:08 +01:00
|
|
|
*
|
|
|
|
* @param array $callback
|
2013-11-28 04:48:04 +01:00
|
|
|
*/
|
|
|
|
public function handlePlayerDisconnect(array $callback) {
|
|
|
|
$login = $callback[1][0];
|
|
|
|
if (isset($this->playersMenuShown[$login])) {
|
|
|
|
unset($this->playersMenuShown[$login]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the menu to the player
|
|
|
|
*
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
private function showMenu(Player $player) {
|
|
|
|
$this->buildManialink();
|
|
|
|
$manialinkText = $this->manialink->render()->saveXML();
|
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
|
|
|
$this->maniaControl->manialinkManager->disableAltMenu($player);
|
|
|
|
$this->playersMenuShown[$player->login] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the menu for the player
|
|
|
|
*
|
2013-11-28 03:47:08 +01:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
2013-11-28 04:48:04 +01:00
|
|
|
private function hideMenu(Player $player) {
|
|
|
|
$this->buildManialink();
|
|
|
|
$manialinkText = $this->emptyManialink->render()->saveXML();
|
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
|
|
|
$this->maniaControl->manialinkManager->enableAltMenu($player);
|
|
|
|
unset($this->playersMenuShown[$player->login]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build menu manialink if necessary
|
|
|
|
*
|
|
|
|
* @param bool $forceBuild
|
|
|
|
*/
|
|
|
|
private function buildManialink($forceBuild = false) {
|
|
|
|
if (is_object($this->manialink) && !$forceBuild) return;
|
|
|
|
|
|
|
|
$this->emptyManialink = new ManiaLink(self::MLID_MENU);
|
|
|
|
|
|
|
|
$manialink = new ManiaLink(self::MLID_MENU);
|
|
|
|
|
|
|
|
$frame = new Frame();
|
|
|
|
$manialink->add($frame);
|
|
|
|
|
|
|
|
$backgroundQuad = new Quad_BgRaceScore2();
|
|
|
|
$frame->add($backgroundQuad);
|
|
|
|
$backgroundQuad->setSize(100, 70);
|
|
|
|
$backgroundQuad->setSubStyle($backgroundQuad::SUBSTYLE_HandleSelectable);
|
|
|
|
|
|
|
|
$this->manialink = $manialink;
|
2013-11-28 03:47:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add menu item to the admin menu
|
|
|
|
*/
|
|
|
|
private function addAdminMenuItem() {
|
|
|
|
$itemQuad = new Quad();
|
|
|
|
$itemQuad->setStyles('Icons128x32_1', 'Settings');
|
2013-11-28 04:48:04 +01:00
|
|
|
$itemQuad->setAction(self::ACTION_TOGGLEMENU);
|
2013-11-28 03:47:08 +01:00
|
|
|
$this->maniaControl->adminMenu->addMenuItem($itemQuad, 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|