From 17f18a2cdbad273c699fec231c4beb241e246209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Tue, 31 Dec 2013 12:42:07 +0100 Subject: [PATCH] Renamed AdminMenu to ActionsMenu --- .../Admin/{AdminMenu.php => ActionsMenu.php} | 82 ++++++++++++++----- .../core/Configurators/Configurator.php | 65 +++++++-------- application/core/ManiaControl.php | 25 +++--- 3 files changed, 108 insertions(+), 64 deletions(-) rename application/core/Admin/{AdminMenu.php => ActionsMenu.php} (76%) diff --git a/application/core/Admin/AdminMenu.php b/application/core/Admin/ActionsMenu.php similarity index 76% rename from application/core/Admin/AdminMenu.php rename to application/core/Admin/ActionsMenu.php index 00eda54b..e9598251 100644 --- a/application/core/Admin/AdminMenu.php +++ b/application/core/Admin/ActionsMenu.php @@ -14,30 +14,31 @@ use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; /** - * Class offering and managing the admin menu + * Class managing Actions Menus * * @author steeffeen & kremsy */ -class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TODO rename class, its not only an admin menu +class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener { /** * Constants */ - const MLID_MENU = 'AdminMenu.MLID'; + const MLID_MENU = 'ActionsMenu.MLID'; const SETTING_MENU_POSX = 'Menu Position: X'; const SETTING_MENU_POSY = 'Menu Position: Y'; const SETTING_MENU_ITEMSIZE = 'Menu Item Size'; - const ACTION_OPEN_ADMIN_MEN = 'AdminMenu.OpenAdminMenu'; - const ACTION_OPEN_PLAYER_MEN = 'AdminMenu.OpenPlayerMenu'; + const ACTION_OPEN_ADMIN_MENU = 'ActionsMenu.OpenAdminMenu'; + const ACTION_OPEN_PLAYER_MENU = 'ActionsMenu.OpenPlayerMenu'; /** - * Private properties + * Private Properties */ private $maniaControl = 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 */ @@ -50,22 +51,54 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TO $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.); // 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_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 int $order */ - public function addMenuItem(Control $control, $order = 0) { - if (!isset($this->menuItems[$order])) { - $this->menuItems[$order] = array(); + public function addPlayerMenuItem(Control $control, $order = 0) { + if (!isset($this->playerMenuItems[$order])) { + $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,8 +130,8 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TO } /** - * Called on ManialinkPageAnswer - * + * Handle OpenAdminMenu Action + * * @param array $callback */ public function openAdminMenu(array $callback, Player $player) { @@ -107,6 +140,17 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TO $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 * @@ -119,7 +163,7 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TO /** * Build the icons - * + * * @param bool $forceBuild */ private function buildIcons($forceBuild = false) { @@ -153,7 +197,7 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TO $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Options); $itemQuad->setSize($itemSize, $itemSize); $iconFrame->add($itemQuad); - $itemQuad->setAction(self::ACTION_OPEN_ADMIN_MEN); + $itemQuad->setAction(self::ACTION_OPEN_ADMIN_MENU); // Admin Menu Icon Frame $frame = new Frame(); @@ -173,7 +217,7 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TO $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Custom); $itemQuad->setSize($itemSize, $itemSize); $iconFrame->add($itemQuad); - $itemQuad->setAction(self::ACTION_OPEN_PLAYER_MEN); + $itemQuad->setAction(self::ACTION_OPEN_PLAYER_MENU); $this->manialink = $manialink; } diff --git a/application/core/Configurators/Configurator.php b/application/core/Configurators/Configurator.php index cef6a259..77a0c636 100644 --- a/application/core/Configurators/Configurator.php +++ b/application/core/Configurators/Configurator.php @@ -54,7 +54,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { /** * Create a new Configurator * - * @param ManiaControl $maniaControl + * @param ManiaControl $maniaControl */ public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; @@ -72,16 +72,16 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { // Register for page answers $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this, 'handleToggleMenuAction'); - + $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this, 'handleSaveConfigAction'); // Register for callbacks $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); - + $this->maniaControl->callbackManager->registerCallbackListener(ScriptSettings::CB_SCRIPTSETTINGS_CHANGED, $this, 'reopenMenu'); - + // Create script settings $this->scriptSettings = new ScriptSettings($maniaControl); $this->addMenu($this->scriptSettings); @@ -90,7 +90,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { /** * Add a configurator menu * - * @param ConfiguratorMenu $menu + * @param ConfiguratorMenu $menu */ public function addMenu(ConfiguratorMenu $menu) { array_push($this->menus, $menu); @@ -98,21 +98,23 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { /** * Reopens the Menu + * * @param array $callback */ - public function reopenMenu(array $callback){ - foreach($this->playersMenuShown as $login => $shown){ - if($shown == true){ + public function reopenMenu(array $callback) { + foreach ($this->playersMenuShown as $login => $shown) { + if ($shown == true) { $player = $this->maniaControl->playerManager->getPlayer($login); $this->showMenu($player); } } } + /** * Handle toggle menu action * - * @param array $callback - * @param Player $player + * @param array $callback + * @param Player $player */ public function handleToggleMenuAction(array $callback, Player $player) { if (isset($this->playersMenuShown[$player->login])) { @@ -125,8 +127,8 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { /** * Save the config data received from the manialink * - * @param array $callback - * @param Player $player + * @param array $callback + * @param Player $player */ public function handleSaveConfigAction(array $callback, Player $player) { foreach ($this->menus as $menu) { @@ -137,7 +139,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { /** * Handle PlayerDisconnect callback * - * @param array $callback + * @param array $callback */ public function handlePlayerDisconnect(array $callback) { $login = $callback[1][0]; @@ -147,7 +149,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { /** * Show the menu to the player * - * @param Player $player + * @param Player $player */ public function showMenu(Player $player) { $this->buildManialink(); @@ -160,7 +162,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { /** * Hide the menu for the player * - * @param Player $player + * @param Player $player */ public function hideMenu(Player $player) { $emptyManialink = new ManiaLink(ManialinkManager::MAIN_MLID); @@ -173,7 +175,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { /** * Build menu manialink if necessary * - * @param bool $forceBuild + * @param bool $forceBuild */ private function buildManialink($forceBuild = false) { $menuPosX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX); @@ -218,20 +220,15 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { // Create script and features $script = new Script(); $manialink->setScript($script); - - $pages = null; - /*$pages = new Pages(); - $script->addFeature($pages); - $tooltips = new Tooltips(); - $script->addFeature($tooltips); - - $menus = new Menus(); - $script->addFeature($menus);*/ - - //$script->addPager() - - + $pages = null; + /* + * $pages = new Pages(); $script->addFeature($pages); $tooltips = new Tooltips(); $script->addFeature($tooltips); $menus = new + * Menus(); $script->addFeature($menus); + */ + + // $script->addPager() + $menuRelationships = array(); $menuItemY = $menuHeight * 0.42; foreach ($this->menus as $index => $menu) { @@ -241,7 +238,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { $menuItemLabel->setY($menuItemY); $menuItemLabel->setSize($menuListWidth * 0.9, $menuItemHeight * 0.9); $menuItemLabel->setStyle(Label_Text::STYLE_TextCardRaceRank); - //$menuItemLabel->setText('$z' . $menu->getTitle() . '$z'); + // $menuItemLabel->setText('$z' . $menu->getTitle() . '$z'); // Add menu $menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $pages, $script); @@ -251,12 +248,12 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { $menusFrame->add($menuControl); // Add menu relationship - //array_push($menuRelationships, array($menuItemLabel, $menuControl)); + // array_push($menuRelationships, array($menuItemLabel, $menuControl)); $script->addMenu($menuItemLabel, $menuControl); $menuItemY -= $menuItemHeight * 1.1; } - - //$menus->add($menuRelationships); + + // $menus->add($menuRelationships); // Add Close Quad (X) $closeQuad = new Quad_Icons64x64_1(); @@ -298,6 +295,6 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { $itemQuad = new Quad(); $itemQuad->setStyles('Icons128x32_1', 'Settings'); $itemQuad->setAction(self::ACTION_TOGGLEMENU); - $this->maniaControl->adminMenu->addMenuItem($itemQuad, 5); + $this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 10); } } diff --git a/application/core/ManiaControl.php b/application/core/ManiaControl.php index 65a16a97..80f2162e 100644 --- a/application/core/ManiaControl.php +++ b/application/core/ManiaControl.php @@ -3,7 +3,7 @@ namespace ManiaControl; use IXR_Client_Gbx; -use ManiaControl\Admin\AdminMenu; +use ManiaControl\Admin\ActionsMenu; use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Commands\CommandListener; @@ -15,10 +15,11 @@ use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; use ManiaControl\Plugins\PluginManager; use ManiaControl\Server\Server; + require_once __DIR__ . '/Callbacks/CallbackListener.php'; require_once __DIR__ . '/Commands/CommandListener.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__ . '/Callbacks/CallbackManager.php'; require_once __DIR__ . '/Chat.php'; @@ -67,12 +68,14 @@ class ManiaControl implements CommandListener { /** * Public properties */ - public $adminMenu = null; + public $actionsMenu = null; public $authenticationManager = null; public $callbackManager = null; public $chat = null; public $configurator = null; - /** @var IXR_Client_Gbx */ + /** + * @var IXR_Client_Gbx + */ public $client = null; public $commandManager = null; public $database = null; @@ -100,7 +103,7 @@ class ManiaControl implements CommandListener { $this->callbackManager = new CallbackManager($this); $this->settingManager = new SettingManager($this); $this->manialinkManager = new ManialinkManager($this); - $this->adminMenu = new AdminMenu($this); + $this->actionsMenu = new ActionsMenu($this); $this->chat = new Chat($this); $this->commandManager = new CommandManager($this); $this->server = new Server($this); @@ -117,8 +120,8 @@ class ManiaControl implements CommandListener { /** * Print a message to console and log - * - * @param string $message + * + * @param string $message */ public function log($message) { logMessage($message); @@ -127,7 +130,7 @@ class ManiaControl implements CommandListener { /** * Return message composed of client error message and error code * - * @param object $client + * @param object $client * @return string */ public function getClientErrorText($client = null) { @@ -140,8 +143,8 @@ class ManiaControl implements CommandListener { /** * Send ManiaControl version * - * @param array $chat - * @param Player $player + * @param array $chat + * @param Player $player * @return bool */ public function command_Version(array $chat, Player $player) { @@ -152,7 +155,7 @@ class ManiaControl implements CommandListener { /** * Quit ManiaControl and log the given message * - * @param string $message + * @param string $message */ public function quit($message = '') { // OnShutdown callback