2013-11-13 01:43:12 +01:00
|
|
|
<?php
|
|
|
|
|
2013-11-28 03:47:08 +01:00
|
|
|
namespace ManiaControl\Admin;
|
2013-11-13 01:43:12 +01:00
|
|
|
|
2013-12-29 15:52:01 +01:00
|
|
|
use FML\Controls\Quads\Quad_Icons128x128_1;
|
2013-11-28 03:47:08 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use FML\ManiaLink;
|
|
|
|
use FML\Controls\Control;
|
|
|
|
use FML\Controls\Frame;
|
|
|
|
use FML\Controls\Quad;
|
2013-12-29 15:52:01 +01:00
|
|
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
2013-11-28 03:47:08 +01:00
|
|
|
use ManiaControl\Players\Player;
|
|
|
|
use ManiaControl\Players\PlayerManager;
|
2013-12-31 13:21:45 +01:00
|
|
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
2013-11-28 03:47:08 +01:00
|
|
|
|
|
|
|
/**
|
2013-12-31 12:42:07 +01:00
|
|
|
* Class managing Actions Menus
|
2013-11-28 03:47:08 +01:00
|
|
|
*
|
|
|
|
* @author steeffeen & kremsy
|
|
|
|
*/
|
2013-12-31 12:42:07 +01:00
|
|
|
class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
2013-11-28 03:47:08 +01:00
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
2013-12-31 12:42:07 +01:00
|
|
|
const MLID_MENU = 'ActionsMenu.MLID';
|
2013-11-28 03:47:08 +01:00
|
|
|
const SETTING_MENU_POSX = 'Menu Position: X';
|
|
|
|
const SETTING_MENU_POSY = 'Menu Position: Y';
|
|
|
|
const SETTING_MENU_ITEMSIZE = 'Menu Item Size';
|
2013-12-31 12:42:07 +01:00
|
|
|
const ACTION_OPEN_ADMIN_MENU = 'ActionsMenu.OpenAdminMenu';
|
|
|
|
const ACTION_OPEN_PLAYER_MENU = 'ActionsMenu.OpenPlayerMenu';
|
2013-12-31 12:24:54 +01:00
|
|
|
|
2013-11-28 03:47:08 +01:00
|
|
|
/**
|
2013-12-31 12:42:07 +01:00
|
|
|
* Private Properties
|
2013-11-28 03:47:08 +01:00
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
2013-12-31 12:42:07 +01:00
|
|
|
private $adminMenuItems = array();
|
|
|
|
private $playerMenuItems = array();
|
2013-11-28 03:47:08 +01:00
|
|
|
|
|
|
|
/**
|
2013-12-31 12:42:07 +01:00
|
|
|
* Create a new Actions Menu
|
2013-11-28 03:47:08 +01:00
|
|
|
*
|
2013-12-31 12:24:54 +01:00
|
|
|
* @param ManiaControl $maniaControl
|
2013-11-28 03:47:08 +01:00
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
|
|
|
// Init settings
|
2013-12-29 19:21:29 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 156.);
|
2013-12-31 12:24:54 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, -37.);
|
2013-11-28 03:47:08 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.);
|
|
|
|
|
|
|
|
// Register for callbacks
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_ONINIT, $this, 'handleOnInit');
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerJoined');
|
2013-12-31 12:42:07 +01:00
|
|
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_ADMIN_MENU, $this,
|
|
|
|
'openAdminMenu');
|
|
|
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYER_MENU, $this,
|
|
|
|
'openPlayerMenu');
|
2013-11-28 03:47:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 12:42:07 +01:00
|
|
|
* Add a new Menu Item
|
2013-11-28 03:47:08 +01:00
|
|
|
*
|
2013-12-09 19:45:40 +01:00
|
|
|
* @param Control $control
|
2013-12-31 12:42:07 +01:00
|
|
|
* @param bool $playerAction
|
2013-12-31 12:24:54 +01:00
|
|
|
* @param int $order
|
2013-11-28 03:47:08 +01:00
|
|
|
*/
|
2013-12-31 12:42:07 +01:00
|
|
|
public function addMenuItem(Control $control, $playerAction = true, $order = 0) {
|
|
|
|
if ($playerAction) {
|
|
|
|
$this->addPlayerMenuItem($control, $order);
|
2013-11-28 03:47:08 +01:00
|
|
|
}
|
2013-12-31 12:42:07 +01:00
|
|
|
else {
|
|
|
|
$this->addAdminMenuItem($control, $order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new Player Menu Item
|
|
|
|
*
|
|
|
|
* @param Control $control
|
|
|
|
* @param int $order
|
|
|
|
*/
|
|
|
|
public function addPlayerMenuItem(Control $control, $order = 0) {
|
|
|
|
if (!isset($this->playerMenuItems[$order])) {
|
|
|
|
$this->playerMenuItems[$order] = array();
|
|
|
|
}
|
|
|
|
array_push($this->playerMenuItems[$order], $control);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new Admin Menu Item
|
|
|
|
*
|
|
|
|
* @param Control $control
|
|
|
|
* @param int $order
|
|
|
|
*/
|
|
|
|
public function addAdminMenuItem(Control $control, $order = 0) {
|
|
|
|
if (!isset($this->adminMenuItems[$order])) {
|
|
|
|
$this->adminMenuItems[$order] = array();
|
|
|
|
}
|
|
|
|
array_push($this->adminMenuItems[$order], $control);
|
2013-11-28 03:47:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle ManiaControl OnInit callback
|
|
|
|
*
|
2013-12-31 12:24:54 +01:00
|
|
|
* @param array $callback
|
2013-11-28 03:47:08 +01:00
|
|
|
*/
|
|
|
|
public function handleOnInit(array $callback) {
|
2013-12-31 13:21:45 +01:00
|
|
|
$manialinkText = $this->buildMenuIconsManialink()->render()->saveXML();
|
2013-11-28 03:47:08 +01:00
|
|
|
$players = $this->maniaControl->playerManager->getPlayers();
|
|
|
|
foreach ($players as $player) {
|
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 13:21:45 +01:00
|
|
|
* Handle PlayerJoined callback
|
2013-11-28 03:47:08 +01:00
|
|
|
*
|
2013-12-31 12:24:54 +01:00
|
|
|
* @param array $callback
|
2013-11-28 03:47:08 +01:00
|
|
|
*/
|
2013-12-31 13:32:23 +01:00
|
|
|
public function handlePlayerJoined(array $callback) {
|
|
|
|
$player = $callback[1];
|
2013-12-31 13:21:45 +01:00
|
|
|
$manialinkText = $this->buildMenuIconsManialink()->render()->saveXML();
|
2013-11-28 03:47:08 +01:00
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
|
|
|
}
|
|
|
|
|
2013-12-29 15:52:01 +01:00
|
|
|
/**
|
2013-12-31 12:42:07 +01:00
|
|
|
* Handle OpenAdminMenu Action
|
|
|
|
*
|
2013-12-29 15:52:01 +01:00
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function openAdminMenu(array $callback, Player $player) {
|
2014-01-01 21:05:45 +01:00
|
|
|
if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)){
|
|
|
|
$this->maniaControl->configurator->toggleMenu($player);
|
|
|
|
}
|
2013-12-29 15:52:01 +01:00
|
|
|
}
|
2013-12-31 12:24:54 +01:00
|
|
|
|
2013-12-31 12:42:07 +01:00
|
|
|
/**
|
|
|
|
* Handle OpenPlayerMenu Action
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function openPlayerMenu(array $callback, Player $player) {
|
2013-11-28 03:47:08 +01:00
|
|
|
}
|
|
|
|
|
2013-12-31 13:21:45 +01:00
|
|
|
private function buildMenuIconsManialink() {
|
2013-12-29 15:52:01 +01:00
|
|
|
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
|
|
|
|
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
|
|
|
|
$itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE);
|
|
|
|
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
|
|
|
$itemMarginFactorX = 1.3;
|
|
|
|
$itemMarginFactorY = 1.2;
|
2013-12-31 12:24:54 +01:00
|
|
|
|
2013-12-29 15:52:01 +01:00
|
|
|
$manialink = new ManiaLink(self::MLID_MENU);
|
2013-12-31 12:24:54 +01:00
|
|
|
|
2013-12-31 13:34:10 +01:00
|
|
|
// Admin Menu Icon Frame
|
2013-12-29 15:52:01 +01:00
|
|
|
$frame = new Frame();
|
|
|
|
$manialink->add($frame);
|
|
|
|
$frame->setPosition($posX, $posY);
|
2013-12-31 12:24:54 +01:00
|
|
|
|
2013-12-29 15:52:01 +01:00
|
|
|
$backgroundQuad = new Quad();
|
|
|
|
$frame->add($backgroundQuad);
|
|
|
|
$backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
2014-01-01 21:05:45 +01:00
|
|
|
|
|
|
|
|
2013-12-29 15:52:01 +01:00
|
|
|
$iconFrame = new Frame();
|
|
|
|
$frame->add($iconFrame);
|
2013-12-31 12:24:54 +01:00
|
|
|
|
2013-12-29 15:52:01 +01:00
|
|
|
$iconFrame->setSize($itemSize, $itemSize);
|
2013-12-31 13:21:45 +01:00
|
|
|
$itemQuad = new Quad_Icons64x64_1();
|
2013-12-31 13:34:10 +01:00
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconServers);
|
2013-12-29 15:52:01 +01:00
|
|
|
$itemQuad->setSize($itemSize, $itemSize);
|
|
|
|
$iconFrame->add($itemQuad);
|
2013-12-31 13:34:10 +01:00
|
|
|
$itemQuad->setAction(self::ACTION_OPEN_ADMIN_MENU);
|
2013-12-31 12:24:54 +01:00
|
|
|
|
2013-12-31 13:34:10 +01:00
|
|
|
// Player Menu Icon Frame
|
2013-12-29 15:57:11 +01:00
|
|
|
$frame = new Frame();
|
|
|
|
$manialink->add($frame);
|
|
|
|
$frame->setPosition($posX, $posY - $itemSize * $itemMarginFactorY);
|
2013-12-31 12:24:54 +01:00
|
|
|
|
2013-12-29 15:57:11 +01:00
|
|
|
$backgroundQuad = new Quad();
|
|
|
|
$frame->add($backgroundQuad);
|
|
|
|
$backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
2013-12-31 12:24:54 +01:00
|
|
|
|
2013-12-29 15:57:11 +01:00
|
|
|
$iconFrame = new Frame();
|
|
|
|
$frame->add($iconFrame);
|
2013-12-31 12:24:54 +01:00
|
|
|
|
2013-12-29 15:57:11 +01:00
|
|
|
$iconFrame->setSize($itemSize, $itemSize);
|
2013-12-31 13:21:45 +01:00
|
|
|
$itemQuad = new Quad_Icons64x64_1();
|
2013-12-31 13:34:10 +01:00
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconPlayers);
|
2013-12-29 15:57:11 +01:00
|
|
|
$itemQuad->setSize($itemSize, $itemSize);
|
|
|
|
$iconFrame->add($itemQuad);
|
2013-12-31 13:34:10 +01:00
|
|
|
$itemQuad->setAction(self::ACTION_OPEN_PLAYER_MENU);
|
2013-12-31 12:24:54 +01:00
|
|
|
|
2013-12-31 13:21:45 +01:00
|
|
|
return $manialink;
|
2013-12-29 15:52:01 +01:00
|
|
|
}
|
2013-12-31 12:24:54 +01:00
|
|
|
|
2013-12-31 13:21:45 +01:00
|
|
|
private function buildMenuIconsManialink2() {
|
2013-11-28 03:47:08 +01:00
|
|
|
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
|
|
|
|
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
|
|
|
|
$itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE);
|
|
|
|
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
2013-12-31 12:24:54 +01:00
|
|
|
|
2013-11-28 03:47:08 +01:00
|
|
|
$itemCount = count($this->menuItems);
|
|
|
|
$itemMarginFactorX = 1.3;
|
|
|
|
$itemMarginFactorY = 1.2;
|
|
|
|
|
|
|
|
$manialink = new ManiaLink(self::MLID_MENU);
|
|
|
|
|
|
|
|
$frame = new Frame();
|
|
|
|
$manialink->add($frame);
|
|
|
|
$frame->setPosition($posX, $posY);
|
|
|
|
|
|
|
|
$backgroundQuad = new Quad();
|
|
|
|
$frame->add($backgroundQuad);
|
|
|
|
$backgroundQuad->setSize($itemCount * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
|
|
|
|
|
|
|
$itemsFrame = new Frame();
|
|
|
|
$frame->add($itemsFrame);
|
|
|
|
|
|
|
|
// Add items
|
|
|
|
$x = 0.5 * $itemSize * $itemMarginFactorX;
|
2013-12-09 13:45:58 +01:00
|
|
|
foreach ($this->menuItems as $menuItems) {
|
2013-11-28 03:47:08 +01:00
|
|
|
foreach ($menuItems as $menuItem) {
|
|
|
|
$menuItem->setSize($itemSize, $itemSize);
|
|
|
|
$itemsFrame->add($menuItem);
|
|
|
|
|
|
|
|
$x += $itemSize * $itemMarginFactorX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->manialink = $manialink;
|
|
|
|
}
|
|
|
|
}
|