moved menu buttons

This commit is contained in:
Steffen Schröder 2013-12-31 12:24:54 +01:00
parent fd7a229e2c
commit 50f79ddec2

View File

@ -18,7 +18,7 @@ use ManiaControl\Players\PlayerManager;
* *
* @author steeffeen & kremsy * @author steeffeen & kremsy
*/ */
class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { //TODO rename class, its not only an admin menu class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TODO rename class, its not only an admin menu
/** /**
* Constants * Constants
*/ */
@ -26,10 +26,9 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { //TOD
const SETTING_MENU_POSX = 'Menu Position: X'; const SETTING_MENU_POSX = 'Menu Position: X';
const SETTING_MENU_POSY = 'Menu Position: Y'; const SETTING_MENU_POSY = 'Menu Position: Y';
const SETTING_MENU_ITEMSIZE = 'Menu Item Size'; const SETTING_MENU_ITEMSIZE = 'Menu Item Size';
const ACTION_OPEN_ADMIN_MEN = 'AdminMenu.OpenAdminMenu'; const ACTION_OPEN_ADMIN_MEN = 'AdminMenu.OpenAdminMenu';
const ACTION_OPEN_PLAYER_MEN = 'AdminMenu.OpenPlayerMenu'; const ACTION_OPEN_PLAYER_MEN = 'AdminMenu.OpenPlayerMenu';
/** /**
* Private properties * Private properties
*/ */
@ -40,18 +39,18 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { //TOD
/** /**
* Create a new admin menu * Create a new admin menu
* *
* @param ManiaControl $maniaControl * @param ManiaControl $maniaControl
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Init settings // Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 156.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 156.);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, -60.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, -37.);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.);
// Register for callbacks // Register for callbacks
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_ADMIN_MEN , $this, 'openAdminMenu'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_ADMIN_MEN, $this, 'openAdminMenu');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_ONINIT, $this, 'handleOnInit'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_ONINIT, $this, 'handleOnInit');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerJoined'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerJoined');
} }
@ -60,7 +59,7 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { //TOD
* Add a new menu item * Add a new menu item
* *
* @param Control $control * @param Control $control
* @param int $order * @param int $order
*/ */
public function addMenuItem(Control $control, $order = 0) { public function addMenuItem(Control $control, $order = 0) {
if (!isset($this->menuItems[$order])) { if (!isset($this->menuItems[$order])) {
@ -72,7 +71,7 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { //TOD
/** /**
* Handle ManiaControl OnInit callback * Handle ManiaControl OnInit callback
* *
* @param array $callback * @param array $callback
*/ */
public function handleOnInit(array $callback) { public function handleOnInit(array $callback) {
$this->buildIcons(); $this->buildIcons();
@ -87,7 +86,7 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { //TOD
/** /**
* Handle PlayerConnect callback * Handle PlayerConnect callback
* *
* @param array $callback * @param array $callback
*/ */
public function handlePlayerJoined(array $callback) { public function handlePlayerJoined(array $callback) {
$player = $callback[1]; $player = $callback[1];
@ -97,9 +96,9 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { //TOD
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
} }
/** /**
* Called on ManialinkPageAnswer * Called on ManialinkPageAnswer
*
* @param array $callback * @param array $callback
*/ */
public function openAdminMenu(array $callback, Player $player) { public function openAdminMenu(array $callback, Player $player) {
@ -107,10 +106,11 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { //TOD
$manialinkText = $this->manialink->render()->saveXML(); $manialinkText = $this->manialink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
} }
/** /**
* Check if the player has access to the admin menu * Check if the player has access to the admin menu
* *
* @param Player $player * @param Player $player
* @return bool * @return bool
*/ */
private function checkPlayerRight(Player $player) { private function checkPlayerRight(Player $player) {
@ -119,11 +119,12 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { //TOD
/** /**
* Build the icons * Build the icons
*
* @param bool $forceBuild * @param bool $forceBuild
*/ */
private function buildIcons($forceBuild = false) { private function buildIcons($forceBuild = false) {
if (is_object($this->manialink) && !$forceBuild) return; if (is_object($this->manialink) && !$forceBuild) return;
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX); $posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY); $posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
$itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE); $itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE);
@ -131,57 +132,56 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { //TOD
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$itemMarginFactorX = 1.3; $itemMarginFactorX = 1.3;
$itemMarginFactorY = 1.2; $itemMarginFactorY = 1.2;
$manialink = new ManiaLink(self::MLID_MENU); $manialink = new ManiaLink(self::MLID_MENU);
//Player Menu Icon Frame // Player Menu Icon Frame
$frame = new Frame(); $frame = new Frame();
$manialink->add($frame); $manialink->add($frame);
$frame->setPosition($posX, $posY); $frame->setPosition($posX, $posY);
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY); $backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$iconFrame = new Frame(); $iconFrame = new Frame();
$frame->add($iconFrame); $frame->add($iconFrame);
$iconFrame->setSize($itemSize, $itemSize); $iconFrame->setSize($itemSize, $itemSize);
$itemQuad = new Quad_Icons128x128_1(); $itemQuad = new Quad_Icons128x128_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Options); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Options);
$itemQuad->setSize($itemSize, $itemSize); $itemQuad->setSize($itemSize, $itemSize);
$iconFrame->add($itemQuad); $iconFrame->add($itemQuad);
$itemQuad->setAction(self::ACTION_OPEN_ADMIN_MEN); $itemQuad->setAction(self::ACTION_OPEN_ADMIN_MEN);
//Admin Menu Icon Frame // Admin Menu Icon Frame
$frame = new Frame(); $frame = new Frame();
$manialink->add($frame); $manialink->add($frame);
$frame->setPosition($posX, $posY - $itemSize * $itemMarginFactorY); $frame->setPosition($posX, $posY - $itemSize * $itemMarginFactorY);
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY); $backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$iconFrame = new Frame(); $iconFrame = new Frame();
$frame->add($iconFrame); $frame->add($iconFrame);
$iconFrame->setSize($itemSize, $itemSize); $iconFrame->setSize($itemSize, $itemSize);
$itemQuad = new Quad_Icons128x128_1(); $itemQuad = new Quad_Icons128x128_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Custom); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Custom);
$itemQuad->setSize($itemSize, $itemSize); $itemQuad->setSize($itemSize, $itemSize);
$iconFrame->add($itemQuad); $iconFrame->add($itemQuad);
$itemQuad->setAction(self::ACTION_OPEN_PLAYER_MEN); $itemQuad->setAction(self::ACTION_OPEN_PLAYER_MEN);
$this->manialink = $manialink; $this->manialink = $manialink;
} }
/** /**
* Build the menu manialink if necessary * Build the menu manialink if necessary
* *
* @param bool $forceBuild * @param bool $forceBuild
*/ */
private function buildManialink($forceBuild = false) { private function buildManialink($forceBuild = false) {
if (is_object($this->manialink) && !$forceBuild) return; if (is_object($this->manialink) && !$forceBuild) return;
@ -191,7 +191,7 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { //TOD
$itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE); $itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE);
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$itemCount = count($this->menuItems); $itemCount = count($this->menuItems);
$itemMarginFactorX = 1.3; $itemMarginFactorX = 1.3;
$itemMarginFactorY = 1.2; $itemMarginFactorY = 1.2;