Added SidebarMenuManager Fixed https://github.com/ManiaControl/ManiaControl/issues/97
This commit is contained in:
@ -15,6 +15,7 @@ use ManiaControl\General\UsageInformationTrait;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Manialinks\SidebarMenuManager;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
use ManiaControl\Settings\Setting;
|
||||
@ -41,6 +42,8 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
|
||||
const SETTING_MENU_ITEMSIZE = 'Menu Item Size';
|
||||
const ACTION_OPEN_ADMIN_MENU = 'ActionsMenu.OpenAdminMenu';
|
||||
const ACTION_OPEN_PLAYER_MENU = 'ActionsMenu.OpenPlayerMenu';
|
||||
const ADMIN_MENU_ID = 'ActionsMenu.AdminMenu';
|
||||
const PLAYER_MENU_ID = 'ActionsMenu.PlayerMenu';
|
||||
|
||||
/*
|
||||
* Private properties
|
||||
@ -71,6 +74,8 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'handlePlayerJoined');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChanged');
|
||||
|
||||
$this->maniaControl->getManialinkManager()->getSidebarMenuManager()->addMenuEntry(SidebarMenuManager::ORDER_ADMIN_MENU, self::ADMIN_MENU_ID);
|
||||
$this->maniaControl->getManialinkManager()->getSidebarMenuManager()->addMenuEntry(SidebarMenuManager::ORDER_PLAYER_MENU, self::PLAYER_MENU_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,19 +140,18 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
|
||||
/**
|
||||
* Builds the Manialink
|
||||
*
|
||||
* @param $admin
|
||||
* @param Player $player
|
||||
* @return ManiaLink
|
||||
*/
|
||||
private function buildMenuIconsManialink($admin = false) {
|
||||
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSX);
|
||||
$adminPos = $this->maniaControl->getManialinkManager()->getSidebarMenuManager()->getEntryPosition(self::ADMIN_MENU_ID);
|
||||
$playerPos = $this->maniaControl->getManialinkManager()->getSidebarMenuManager()->getEntryPosition(self::PLAYER_MENU_ID);
|
||||
$itemSize = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_ITEMSIZE);
|
||||
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
|
||||
$itemMarginFactorX = 1.3;
|
||||
$itemMarginFactorY = 1.2;
|
||||
|
||||
$posY = $this->getActionsMenuY();
|
||||
|
||||
$maniaLink = new ManiaLink(self::MLID_MENU);
|
||||
$frame = new Frame();
|
||||
$maniaLink->addChild($frame);
|
||||
@ -160,7 +164,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
|
||||
// Admin Menu Icon Frame
|
||||
$iconFrame = new Frame();
|
||||
$frame->addChild($iconFrame);
|
||||
$iconFrame->setPosition($posX, $posY);
|
||||
$iconFrame->setPosition($adminPos['x'], $adminPos['y']);
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$iconFrame->addChild($backgroundQuad);
|
||||
@ -175,7 +179,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
|
||||
// Admin Menu Description
|
||||
$descriptionLabel = new Label();
|
||||
$frame->addChild($descriptionLabel);
|
||||
$descriptionLabel->setPosition($posX - count($this->adminMenuItems) * $itemSize * 1.05 - 5, $posY);
|
||||
$descriptionLabel->setPosition($adminPos['x'] - count($this->adminMenuItems) * $itemSize * 1.05 - 5, $adminPos['y']);
|
||||
$descriptionLabel->setAlign($descriptionLabel::RIGHT, $descriptionLabel::TOP);
|
||||
$descriptionLabel->setSize(40, 4);
|
||||
$descriptionLabel->setTextSize(1.4);
|
||||
@ -184,7 +188,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
|
||||
// Admin Menu
|
||||
$popoutFrame = new Frame();
|
||||
$frame->addChild($popoutFrame);
|
||||
$popoutFrame->setPosition($posX - $itemSize * 0.5, $posY);
|
||||
$popoutFrame->setPosition($adminPos['x'] - $itemSize * 0.5, $adminPos['y']);
|
||||
$popoutFrame->setHorizontalAlign($popoutFrame::RIGHT);
|
||||
$popoutFrame->setVisible(false);
|
||||
|
||||
@ -223,7 +227,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
|
||||
// Player Menu Icon Frame
|
||||
$iconFrame = new Frame();
|
||||
$frame->addChild($iconFrame);
|
||||
$iconFrame->setPosition($posX, $posY - $itemSize * $itemMarginFactorY);
|
||||
$iconFrame->setPosition($playerPos['x'], $playerPos['y']);
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$iconFrame->addChild($backgroundQuad);
|
||||
@ -238,7 +242,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
|
||||
// Player Menu Description
|
||||
$descriptionLabel = new Label();
|
||||
$frame->addChild($descriptionLabel);
|
||||
$descriptionLabel->setPosition($posX - count($this->playerMenuItems) * $itemSize * 1.05 - 5, $posY - $itemSize * $itemMarginFactorY);
|
||||
$descriptionLabel->setPosition($playerPos['x'] - count($this->playerMenuItems) * $itemSize * 1.05 - 5, $playerPos['y']);
|
||||
$descriptionLabel->setAlign($descriptionLabel::RIGHT, $descriptionLabel::TOP);
|
||||
$descriptionLabel->setSize(40, 4);
|
||||
$descriptionLabel->setTextSize(1.4);
|
||||
@ -247,7 +251,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
|
||||
// Player Menu
|
||||
$popoutFrame = new Frame();
|
||||
$frame->addChild($popoutFrame);
|
||||
$popoutFrame->setPosition($posX - $itemSize * 0.5, $posY - $itemSize * $itemMarginFactorY);
|
||||
$popoutFrame->setPosition($playerPos['x'] - $itemSize * 0.5, $playerPos['y']);
|
||||
$popoutFrame->setHorizontalAlign($popoutFrame::RIGHT);
|
||||
$popoutFrame->setVisible(false);
|
||||
|
||||
@ -336,12 +340,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handlePlayerJoined(Player $player) {
|
||||
if ($this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
||||
$maniaLink = $this->buildMenuIconsManialink(true);
|
||||
} else {
|
||||
$maniaLink = $this->buildMenuIconsManialink(false);
|
||||
}
|
||||
|
||||
$maniaLink = $this->buildMenuIconsManialink($player);
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $player);
|
||||
}
|
||||
|
||||
@ -357,18 +356,4 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
|
||||
|
||||
$this->rebuildAndShowMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Y value of the Actionsmenu (dependent on game)
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getActionsMenuY() {
|
||||
if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() === 'sm') {
|
||||
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSY_SHOOTMANIA);
|
||||
} else {
|
||||
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSY_TRACKMANIA);
|
||||
}
|
||||
return $posY;
|
||||
}
|
||||
}
|
||||
|
@ -235,7 +235,6 @@ class CallbackManager implements UsageInformationAble {
|
||||
$startTime = microtime(true);
|
||||
$callbacks = $this->maniaControl->getClient()->executeCallbacks();
|
||||
$timings["executeCallbacks"] = microtime(true) - $startTime;
|
||||
|
||||
foreach ($callbacks as $key => $callback) {
|
||||
$time1 = microtime(true);
|
||||
$this->handleCallback($callback);
|
||||
|
@ -52,6 +52,9 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener,
|
||||
/** @var IconManager $iconManager */
|
||||
private $iconManager = null;
|
||||
|
||||
/** @var SidebarMenuManager $sidebarMenuManager */
|
||||
private $sidebarMenuManager = null;
|
||||
|
||||
// TODO: use listening class
|
||||
private $pageAnswerListeners = array();
|
||||
private $pageAnswerRegexListener = array();
|
||||
@ -65,9 +68,10 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener,
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Children
|
||||
$this->styleManager = new StyleManager($maniaControl);
|
||||
$this->customUIManager = new CustomUIManager($maniaControl);
|
||||
$this->iconManager = new IconManager($maniaControl);
|
||||
$this->styleManager = new StyleManager($maniaControl);
|
||||
$this->customUIManager = new CustomUIManager($maniaControl);
|
||||
$this->iconManager = new IconManager($maniaControl);
|
||||
$this->sidebarMenuManager = new SidebarMenuManager($maniaControl);
|
||||
|
||||
// Callbacks
|
||||
$this->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET, $this, 'closeWidgetCallback');
|
||||
@ -212,7 +216,6 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener,
|
||||
$this->sendManialink($maniaLink, $player);
|
||||
|
||||
if ($widgetName) {
|
||||
// TODO make check by manialinkId, getter is needed to avoid uses on non main widgets
|
||||
$this->disableAltMenu($player);
|
||||
// Trigger callback
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($player);
|
||||
@ -249,9 +252,9 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener,
|
||||
if (is_array($logins)) {
|
||||
$loginList = array();
|
||||
foreach ($logins as $login) {
|
||||
if($login instanceof Player){
|
||||
if ($login instanceof Player) {
|
||||
$loginList[] = $login->login;
|
||||
}else{
|
||||
} else {
|
||||
$loginList[] = $login;
|
||||
}
|
||||
}
|
||||
@ -388,4 +391,11 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener,
|
||||
|
||||
return $labelLine->getEntries();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SidebarMenuManager
|
||||
*/
|
||||
public function getSidebarMenuManager() {
|
||||
return $this->sidebarMenuManager;
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Manialinks\SidebarMenu;
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Quad;
|
||||
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
||||
use FML\ManiaLink;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\General\UsageInformationAble;
|
||||
use ManiaControl\General\UsageInformationTrait;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
|
||||
|
||||
class SidebarMenuManager implements UsageInformationAble {
|
||||
class SidebarMenuManager implements UsageInformationAble, CallbackListener {
|
||||
use UsageInformationTrait;
|
||||
|
||||
const SIDEBAR_MANIALINK_ID = 'SidebarMenuManager.SidebarMenu';
|
||||
const ADMIN_MENU_ORDER = 10;
|
||||
const PLAYER_MENU_ORDER = 20;
|
||||
|
||||
/* Settings */
|
||||
const SETTING_SIDEBAR_POSX = 'Sidebar X Position';
|
||||
const SETTING_SIDEBAR_POSY_SHOOTMANIA = 'Sidebar Y Position (Shootmania)';
|
||||
const SETTING_SIDEBAR_POSY_TRACKMANIA = 'Sidebar Y Position (Trackmania)';
|
||||
const SETTING_MENU_ITEMSIZE = 'Size of menu items';
|
||||
|
||||
const ORDER_ADMIN_MENU = 10;
|
||||
const ORDER_PLAYER_MENU = 20;
|
||||
|
||||
/* @var $maniaControl ManiaControl */
|
||||
private $maniaControl;
|
||||
private $menuEntries = array();
|
||||
private $yPositions = array();
|
||||
|
||||
function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
@ -35,72 +31,86 @@ class SidebarMenuManager implements UsageInformationAble {
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SIDEBAR_POSY_SHOOTMANIA, -37);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SIDEBAR_POSY_TRACKMANIA, 17);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6);
|
||||
|
||||
}
|
||||
|
||||
public function addMenuEntry(SidebarMenuEntry $entry, $order) {
|
||||
if (isset($this->menuEntries[$order])) {
|
||||
$this->addMenuEntry($entry, $order + 1);
|
||||
}
|
||||
array_push($menuEntries, $entry);
|
||||
ksort($this->menuEntries);
|
||||
$this->updateManiaLink();
|
||||
}
|
||||
/**
|
||||
* Returns array('x' => xPosition, 'y' => yPosition) of the Sidebar
|
||||
*
|
||||
* @return array
|
||||
* @api
|
||||
*/
|
||||
public function getSidebarPosition() {
|
||||
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SIDEBAR_POSX);
|
||||
|
||||
private function itemsBeforeAdmin() {
|
||||
$count = 0;
|
||||
foreach ($this->menuEntries as $key => $entry) {
|
||||
if ($key < self::ADMIN_MENU_ORDER) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
||||
private function updateManiaLink() {
|
||||
$itemSize = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_ITEMSIZE);
|
||||
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SIDEBAR_POSX);
|
||||
if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() === 'sm') {
|
||||
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SIDEBAR_POSY_SHOOTMANIA);
|
||||
} else {
|
||||
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SIDEBAR_POSY_TRACKMANIA);
|
||||
}
|
||||
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
|
||||
$itemMarginFactorX = 1.3;
|
||||
$itemMarginFactorY = 1.2;
|
||||
|
||||
//Calculate X relative to AdminMenu
|
||||
$posX -= $itemSize * 1.05 * $this->itemsBeforeAdmin();
|
||||
return array('x' => $posX, 'y' => $posY);
|
||||
}
|
||||
|
||||
$maniaLink = new ManiaLink(self::SIDEBAR_MANIALINK_ID);
|
||||
$frame = new Frame();
|
||||
$maniaLink->addChild($frame);
|
||||
$frame->setZ(ManialinkManager::MAIN_MANIALINK_Z_VALUE);
|
||||
$frame->setPosition($posX, $posY);
|
||||
/**
|
||||
* Returns array('x' => xPosition, 'y' => yPosition) of a menu item of the sidebar
|
||||
*
|
||||
* @param string $id
|
||||
* @return array|null
|
||||
*/
|
||||
public function getEntryPosition($id) {
|
||||
$itemSize = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_ITEMSIZE);
|
||||
$pos = $this->getSidebarPosition();
|
||||
$posX = $pos['x'];
|
||||
$posY = $pos['y'];
|
||||
|
||||
$posX = 0;
|
||||
/** @var SidebarMenuEntry $entry */
|
||||
foreach ($this->menuEntries as $entry) {
|
||||
$iconFrame = new Frame();
|
||||
$frame->addChild($iconFrame);
|
||||
$iconFrame->setX($posX);
|
||||
|
||||
$background = new Quad();
|
||||
$frame->addChild($background);
|
||||
$background->setStyles($quadStyle, $quadSubstyle);
|
||||
$background->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
||||
|
||||
$icon = $entry->getIcon();
|
||||
$frame->addChild($icon);
|
||||
if($entry->getDescription()){
|
||||
|
||||
}
|
||||
if (isset($this->yPositions[$id])) {
|
||||
return array('x' => $posX, 'y' => $this->yPositions[$id]);
|
||||
}
|
||||
|
||||
foreach ($this->menuEntries as $entry) {
|
||||
if ($entry == $id) {
|
||||
$this->yPositions[$id] = $posY;
|
||||
return array('x' => $posX, 'y' => $posY);
|
||||
}
|
||||
$posY -= $itemSize * 1.05;
|
||||
}
|
||||
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink);
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('SidebarMenuEntry id:' . $id . ' not found');
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an Entry to the SidebarMenu
|
||||
* Get the associated position with getEntryPosition($id)
|
||||
*
|
||||
* @param int $order
|
||||
* @param string $id
|
||||
* @api
|
||||
*/
|
||||
public function addMenuEntry($order, $id) {
|
||||
if (isset($this->menuEntries[$order])) {
|
||||
if ($this->menuEntries[$order] != $id) {
|
||||
$this->addMenuEntry($order + 1, $id);
|
||||
}
|
||||
}
|
||||
$this->menuEntries[$order] = $id;
|
||||
ksort($this->menuEntries);
|
||||
$this->yPositions = array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deletes an Entry from the SidebarMenu
|
||||
*
|
||||
* @param string $id
|
||||
*/
|
||||
public function deleteMenuEntry($id) {
|
||||
foreach ($this->menuEntries as $k => $entry) {
|
||||
if ($entry == $id) {
|
||||
array_splice($this->menuEntries, $k, 1);
|
||||
$this->yPositions = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user