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,8 +130,8 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TO
} }
/** /**
* Called on ManialinkPageAnswer * Handle OpenAdminMenu Action
* *
* @param array $callback * @param array $callback
*/ */
public function openAdminMenu(array $callback, Player $player) { public function openAdminMenu(array $callback, Player $player) {
@ -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
* *
@ -119,7 +163,7 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { // TO
/** /**
* Build the icons * Build the icons
* *
* @param bool $forceBuild * @param bool $forceBuild
*/ */
private function buildIcons($forceBuild = false) { private function buildIcons($forceBuild = false) {
@ -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

@ -54,7 +54,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
/** /**
* Create a new Configurator * Create a new Configurator
* *
* @param ManiaControl $maniaControl * @param ManiaControl $maniaControl
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
@ -72,16 +72,16 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
// Register for page answers // Register for page answers
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this, $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this,
'handleToggleMenuAction'); 'handleToggleMenuAction');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this, $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this,
'handleSaveConfigAction'); 'handleSaveConfigAction');
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this,
'handlePlayerDisconnect'); 'handlePlayerDisconnect');
$this->maniaControl->callbackManager->registerCallbackListener(ScriptSettings::CB_SCRIPTSETTINGS_CHANGED, $this, 'reopenMenu'); $this->maniaControl->callbackManager->registerCallbackListener(ScriptSettings::CB_SCRIPTSETTINGS_CHANGED, $this, 'reopenMenu');
// Create script settings // Create script settings
$this->scriptSettings = new ScriptSettings($maniaControl); $this->scriptSettings = new ScriptSettings($maniaControl);
$this->addMenu($this->scriptSettings); $this->addMenu($this->scriptSettings);
@ -90,7 +90,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
/** /**
* Add a configurator menu * Add a configurator menu
* *
* @param ConfiguratorMenu $menu * @param ConfiguratorMenu $menu
*/ */
public function addMenu(ConfiguratorMenu $menu) { public function addMenu(ConfiguratorMenu $menu) {
array_push($this->menus, $menu); array_push($this->menus, $menu);
@ -98,21 +98,23 @@ 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) {
foreach($this->playersMenuShown as $login => $shown){ foreach ($this->playersMenuShown as $login => $shown) {
if($shown == true){ if ($shown == true) {
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
$this->showMenu($player); $this->showMenu($player);
} }
} }
} }
/** /**
* Handle toggle menu action * Handle toggle menu action
* *
* @param array $callback * @param array $callback
* @param Player $player * @param Player $player
*/ */
public function handleToggleMenuAction(array $callback, Player $player) { public function handleToggleMenuAction(array $callback, Player $player) {
if (isset($this->playersMenuShown[$player->login])) { if (isset($this->playersMenuShown[$player->login])) {
@ -125,8 +127,8 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
/** /**
* Save the config data received from the manialink * Save the config data received from the manialink
* *
* @param array $callback * @param array $callback
* @param Player $player * @param Player $player
*/ */
public function handleSaveConfigAction(array $callback, Player $player) { public function handleSaveConfigAction(array $callback, Player $player) {
foreach ($this->menus as $menu) { foreach ($this->menus as $menu) {
@ -137,7 +139,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
/** /**
* Handle PlayerDisconnect callback * Handle PlayerDisconnect callback
* *
* @param array $callback * @param array $callback
*/ */
public function handlePlayerDisconnect(array $callback) { public function handlePlayerDisconnect(array $callback) {
$login = $callback[1][0]; $login = $callback[1][0];
@ -147,7 +149,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
/** /**
* Show the menu to the player * Show the menu to the player
* *
* @param Player $player * @param Player $player
*/ */
public function showMenu(Player $player) { public function showMenu(Player $player) {
$this->buildManialink(); $this->buildManialink();
@ -160,7 +162,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
/** /**
* Hide the menu for the player * Hide the menu for the player
* *
* @param Player $player * @param Player $player
*/ */
public function hideMenu(Player $player) { public function hideMenu(Player $player) {
$emptyManialink = new ManiaLink(ManialinkManager::MAIN_MLID); $emptyManialink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -173,7 +175,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
/** /**
* Build menu manialink if necessary * Build menu manialink if necessary
* *
* @param bool $forceBuild * @param bool $forceBuild
*/ */
private function buildManialink($forceBuild = false) { private function buildManialink($forceBuild = false) {
$menuPosX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX); $menuPosX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
@ -218,20 +220,15 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
// Create script and features // Create script and features
$script = new Script(); $script = new Script();
$manialink->setScript($script); $manialink->setScript($script);
$pages = null;
/*$pages = new Pages();
$script->addFeature($pages);
$tooltips = new Tooltips(); $pages = null;
$script->addFeature($tooltips); /*
* $pages = new Pages(); $script->addFeature($pages); $tooltips = new Tooltips(); $script->addFeature($tooltips); $menus = new
$menus = new Menus(); * Menus(); $script->addFeature($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) {
@ -241,7 +238,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
$menuItemLabel->setY($menuItemY); $menuItemLabel->setY($menuItemY);
$menuItemLabel->setSize($menuListWidth * 0.9, $menuItemHeight * 0.9); $menuItemLabel->setSize($menuListWidth * 0.9, $menuItemHeight * 0.9);
$menuItemLabel->setStyle(Label_Text::STYLE_TextCardRaceRank); $menuItemLabel->setStyle(Label_Text::STYLE_TextCardRaceRank);
//$menuItemLabel->setText('$z' . $menu->getTitle() . '$z'); // $menuItemLabel->setText('$z' . $menu->getTitle() . '$z');
// Add menu // Add menu
$menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $pages, $script); $menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $pages, $script);
@ -251,12 +248,12 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
$menusFrame->add($menuControl); $menusFrame->add($menuControl);
// Add menu relationship // Add menu relationship
//array_push($menuRelationships, array($menuItemLabel, $menuControl)); // array_push($menuRelationships, array($menuItemLabel, $menuControl));
$script->addMenu($menuItemLabel, $menuControl); $script->addMenu($menuItemLabel, $menuControl);
$menuItemY -= $menuItemHeight * 1.1; $menuItemY -= $menuItemHeight * 1.1;
} }
//$menus->add($menuRelationships); // $menus->add($menuRelationships);
// Add Close Quad (X) // Add Close Quad (X)
$closeQuad = new Quad_Icons64x64_1(); $closeQuad = new Quad_Icons64x64_1();
@ -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);
@ -117,8 +120,8 @@ class ManiaControl implements CommandListener {
/** /**
* Print a message to console and log * Print a message to console and log
* *
* @param string $message * @param string $message
*/ */
public function log($message) { public function log($message) {
logMessage($message); logMessage($message);
@ -127,7 +130,7 @@ class ManiaControl implements CommandListener {
/** /**
* Return message composed of client error message and error code * Return message composed of client error message and error code
* *
* @param object $client * @param object $client
* @return string * @return string
*/ */
public function getClientErrorText($client = null) { public function getClientErrorText($client = null) {
@ -140,8 +143,8 @@ class ManiaControl implements CommandListener {
/** /**
* Send ManiaControl version * Send ManiaControl version
* *
* @param array $chat * @param array $chat
* @param Player $player * @param Player $player
* @return bool * @return bool
*/ */
public function command_Version(array $chat, Player $player) { public function command_Version(array $chat, Player $player) {
@ -152,7 +155,7 @@ class ManiaControl implements CommandListener {
/** /**
* Quit ManiaControl and log the given message * Quit ManiaControl and log the given message
* *
* @param string $message * @param string $message
*/ */
public function quit($message = '') { public function quit($message = '') {
// OnShutdown callback // OnShutdown callback