Renamed AdminMenu to ActionsMenu

This commit is contained in:
Steffen Schröder 2013-12-31 12:42:07 +01:00
parent f23001e1fc
commit 17f18a2cdb
3 changed files with 108 additions and 64 deletions

View File

@ -14,30 +14,31 @@ use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
/** /**
* Class offering and managing the admin menu * Class managing Actions Menus
* *
* @author steeffeen & kremsy * @author steeffeen & kremsy
*/ */
class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TODO rename class, its not only an admin menu class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
/** /**
* Constants * Constants
*/ */
const MLID_MENU = 'AdminMenu.MLID'; const MLID_MENU = 'ActionsMenu.MLID';
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_MENU = 'ActionsMenu.OpenAdminMenu';
const ACTION_OPEN_PLAYER_MEN = 'AdminMenu.OpenPlayerMenu'; const ACTION_OPEN_PLAYER_MENU = 'ActionsMenu.OpenPlayerMenu';
/** /**
* Private properties * Private Properties
*/ */
private $maniaControl = null; private $maniaControl = null;
private $manialink = null; private $manialink = null;
private $menuItems = array(); private $adminMenuItems = array();
private $playerMenuItems = array();
/** /**
* Create a new admin menu * Create a new Actions Menu
* *
* @param ManiaControl $maniaControl * @param ManiaControl $maniaControl
*/ */
@ -50,22 +51,54 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TO
$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->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');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_ADMIN_MENU, $this,
'openAdminMenu');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYER_MENU, $this,
'openPlayerMenu');
} }
/** /**
* Add a new menu item * Add a new Menu Item
*
* @param Control $control
* @param bool $playerAction
* @param int $order
*/
public function addMenuItem(Control $control, $playerAction = true, $order = 0) {
if ($playerAction) {
$this->addPlayerMenuItem($control, $order);
}
else {
$this->addAdminMenuItem($control, $order);
}
}
/**
* Add a new Player Menu Item
* *
* @param Control $control * @param Control $control
* @param int $order * @param int $order
*/ */
public function addMenuItem(Control $control, $order = 0) { public function addPlayerMenuItem(Control $control, $order = 0) {
if (!isset($this->menuItems[$order])) { if (!isset($this->playerMenuItems[$order])) {
$this->menuItems[$order] = array(); $this->playerMenuItems[$order] = array();
} }
array_push($this->menuItems[$order], $control); 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);
} }
/** /**
@ -97,7 +130,7 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TO
} }
/** /**
* Called on ManialinkPageAnswer * Handle OpenAdminMenu Action
* *
* @param array $callback * @param array $callback
*/ */
@ -107,6 +140,17 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TO
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
} }
/**
* Handle OpenPlayerMenu Action
*
* @param array $callback
*/
public function openPlayerMenu(array $callback, Player $player) {
$this->buildManialink(true);
$manialinkText = $this->manialink->render()->saveXML();
$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
* *
@ -153,7 +197,7 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TO
$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_MENU);
// Admin Menu Icon Frame // Admin Menu Icon Frame
$frame = new Frame(); $frame = new Frame();
@ -173,7 +217,7 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TO
$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_MENU);
$this->manialink = $manialink; $this->manialink = $manialink;
} }

View File

@ -98,6 +98,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
/** /**
* Reopens the Menu * Reopens the Menu
*
* @param array $callback * @param array $callback
*/ */
public function reopenMenu(array $callback) { public function reopenMenu(array $callback) {
@ -108,6 +109,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
} }
} }
} }
/** /**
* Handle toggle menu action * Handle toggle menu action
* *
@ -220,18 +222,13 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
$manialink->setScript($script); $manialink->setScript($script);
$pages = null; $pages = null;
/*$pages = new Pages(); /*
$script->addFeature($pages); * $pages = new Pages(); $script->addFeature($pages); $tooltips = new Tooltips(); $script->addFeature($tooltips); $menus = new
* Menus(); $script->addFeature($menus);
$tooltips = new Tooltips(); */
$script->addFeature($tooltips);
$menus = new Menus();
$script->addFeature($menus);*/
// $script->addPager() // $script->addPager()
$menuRelationships = array(); $menuRelationships = array();
$menuItemY = $menuHeight * 0.42; $menuItemY = $menuHeight * 0.42;
foreach ($this->menus as $index => $menu) { foreach ($this->menus as $index => $menu) {
@ -298,6 +295,6 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
$itemQuad = new Quad(); $itemQuad = new Quad();
$itemQuad->setStyles('Icons128x32_1', 'Settings'); $itemQuad->setStyles('Icons128x32_1', 'Settings');
$itemQuad->setAction(self::ACTION_TOGGLEMENU); $itemQuad->setAction(self::ACTION_TOGGLEMENU);
$this->maniaControl->adminMenu->addMenuItem($itemQuad, 5); $this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 10);
} }
} }

View File

@ -3,7 +3,7 @@
namespace ManiaControl; namespace ManiaControl;
use IXR_Client_Gbx; use IXR_Client_Gbx;
use ManiaControl\Admin\AdminMenu; use ManiaControl\Admin\ActionsMenu;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
@ -15,10 +15,11 @@ use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\PluginManager; use ManiaControl\Plugins\PluginManager;
use ManiaControl\Server\Server; use ManiaControl\Server\Server;
require_once __DIR__ . '/Callbacks/CallbackListener.php'; require_once __DIR__ . '/Callbacks/CallbackListener.php';
require_once __DIR__ . '/Commands/CommandListener.php'; require_once __DIR__ . '/Commands/CommandListener.php';
require_once __DIR__ . '/Manialinks/ManialinkPageAnswerListener.php'; require_once __DIR__ . '/Manialinks/ManialinkPageAnswerListener.php';
require_once __DIR__ . '/Admin/AdminMenu.php'; require_once __DIR__ . '/Admin/ActionsMenu.php';
require_once __DIR__ . '/Admin/AuthenticationManager.php'; require_once __DIR__ . '/Admin/AuthenticationManager.php';
require_once __DIR__ . '/Callbacks/CallbackManager.php'; require_once __DIR__ . '/Callbacks/CallbackManager.php';
require_once __DIR__ . '/Chat.php'; require_once __DIR__ . '/Chat.php';
@ -67,12 +68,14 @@ class ManiaControl implements CommandListener {
/** /**
* Public properties * Public properties
*/ */
public $adminMenu = null; public $actionsMenu = null;
public $authenticationManager = null; public $authenticationManager = null;
public $callbackManager = null; public $callbackManager = null;
public $chat = null; public $chat = null;
public $configurator = null; public $configurator = null;
/** @var IXR_Client_Gbx */ /**
* @var IXR_Client_Gbx
*/
public $client = null; public $client = null;
public $commandManager = null; public $commandManager = null;
public $database = null; public $database = null;
@ -100,7 +103,7 @@ class ManiaControl implements CommandListener {
$this->callbackManager = new CallbackManager($this); $this->callbackManager = new CallbackManager($this);
$this->settingManager = new SettingManager($this); $this->settingManager = new SettingManager($this);
$this->manialinkManager = new ManialinkManager($this); $this->manialinkManager = new ManialinkManager($this);
$this->adminMenu = new AdminMenu($this); $this->actionsMenu = new ActionsMenu($this);
$this->chat = new Chat($this); $this->chat = new Chat($this);
$this->commandManager = new CommandManager($this); $this->commandManager = new CommandManager($this);
$this->server = new Server($this); $this->server = new Server($this);