ActionsMenu and Configurator Improvements

This commit is contained in:
Steffen Schröder 2013-12-31 13:21:45 +01:00
parent 17f18a2cdb
commit 16b1550530
2 changed files with 49 additions and 62 deletions

View File

@ -12,6 +12,7 @@ use FML\Controls\Quad;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use FML\Controls\Quads\Quad_Icons64x64_1;
/**
* Class managing Actions Menus
@ -33,7 +34,6 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* Private Properties
*/
private $maniaControl = null;
private $manialink = null;
private $adminMenuItems = array();
private $playerMenuItems = array();
@ -107,25 +107,20 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* @param array $callback
*/
public function handleOnInit(array $callback) {
$this->buildIcons();
$manialinkText = $this->manialink->render()->saveXML();
$manialinkText = $this->buildMenuIconsManialink()->render()->saveXML();
$players = $this->maniaControl->playerManager->getPlayers();
foreach ($players as $player) {
if (!$this->checkPlayerRight($player)) continue;
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
}
}
/**
* Handle PlayerConnect callback
* Handle PlayerJoined callback
*
* @param array $callback
*/
public function handlePlayerJoined(array $callback) {
$player = $callback[1];
if (!$player || !$this->checkPlayerRight($player)) return;
$this->buildIcons();
$manialinkText = $this->manialink->render()->saveXML();
public function handlePlayerJoined(array $callback, Player $player) {
$manialinkText = $this->buildMenuIconsManialink()->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
}
@ -135,9 +130,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* @param array $callback
*/
public function openAdminMenu(array $callback, Player $player) {
$this->buildManialink(true);
$manialinkText = $this->manialink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
$this->maniaControl->configurator->toggleMenu($player);
}
/**
@ -146,29 +139,9 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* @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
*
* @param Player $player
* @return bool
*/
private function checkPlayerRight(Player $player) {
return AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR);
}
/**
* Build the icons
*
* @param bool $forceBuild
*/
private function buildIcons($forceBuild = false) {
if (is_object($this->manialink) && !$forceBuild) return;
private function buildMenuIconsManialink() {
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
$itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE);
@ -193,11 +166,11 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
$frame->add($iconFrame);
$iconFrame->setSize($itemSize, $itemSize);
$itemQuad = new Quad_Icons128x128_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Options);
$itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconPlayers);
$itemQuad->setSize($itemSize, $itemSize);
$iconFrame->add($itemQuad);
$itemQuad->setAction(self::ACTION_OPEN_ADMIN_MENU);
$itemQuad->setAction(self::ACTION_OPEN_PLAYER_MENU);
// Admin Menu Icon Frame
$frame = new Frame();
@ -213,23 +186,16 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
$frame->add($iconFrame);
$iconFrame->setSize($itemSize, $itemSize);
$itemQuad = new Quad_Icons128x128_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Custom);
$itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconServers);
$itemQuad->setSize($itemSize, $itemSize);
$iconFrame->add($itemQuad);
$itemQuad->setAction(self::ACTION_OPEN_PLAYER_MENU);
$itemQuad->setAction(self::ACTION_OPEN_ADMIN_MENU);
$this->manialink = $manialink;
return $manialink;
}
/**
* Build the menu manialink if necessary
*
* @param bool $forceBuild
*/
private function buildManialink($forceBuild = false) {
if (is_object($this->manialink) && !$forceBuild) return;
private function buildMenuIconsManialink2() {
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
$itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE);

View File

@ -20,6 +20,7 @@ use FML\Script\Menus;
use FML\Script\Pages;
use FML\Script\Script;
use FML\Script\Tooltips;
use ManiaControl\Commands\CommandListener;
require_once __DIR__ . '/ConfiguratorMenu.php';
require_once __DIR__ . '/ScriptSettings.php';
@ -29,7 +30,7 @@ require_once __DIR__ . '/ScriptSettings.php';
*
* @author steeffeen & kremsy
*/
class Configurator implements CallbackListener, ManialinkPageAnswerListener {
class Configurator implements CallbackListener, CommandListener, ManialinkPageAnswerListener {
/**
* Constants
*/
@ -58,7 +59,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->addAdminMenuItem();
$this->addActionsMenuItem();
// Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 0.);
@ -72,19 +73,29 @@ 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);
// Register for commands
$this->maniaControl->commandManager->registerCommandListener('config', $this, 'handleConfigCommand', true);
}
/**
* Handle Config Admin Aommand
*
* @param array $callback
*/
public function handleConfigCommand(array $callback, Player $player) {
$this->showMenu($player);
}
/**
@ -117,11 +128,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
* @param Player $player
*/
public function handleToggleMenuAction(array $callback, Player $player) {
if (isset($this->playersMenuShown[$player->login])) {
$this->hideMenu($player);
return;
}
$this->showMenu($player);
$this->toggleMenu($player);
}
/**
@ -147,7 +154,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
}
/**
* Show the menu to the player
* Show the Menu to the Player
*
* @param Player $player
*/
@ -160,7 +167,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
}
/**
* Hide the menu for the player
* Hide the Menu for the Player
*
* @param Player $player
*/
@ -172,6 +179,20 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
unset($this->playersMenuShown[$player->login]);
}
/**
* Toggle the Menu for the Player
*
* @param Player $player
*/
public function toggleMenu(Player $player) {
if (isset($this->playersMenuShown[$player->login])) {
$this->hideMenu($player);
}
else {
$this->showMenu($player);
}
}
/**
* Build menu manialink if necessary
*
@ -289,9 +310,9 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
}
/**
* Add menu item to the admin menu
* Add Menu Item to the Actions Menu
*/
private function addAdminMenuItem() {
private function addActionsMenuItem() {
$itemQuad = new Quad();
$itemQuad->setStyles('Icons128x32_1', 'Settings');
$itemQuad->setAction(self::ACTION_TOGGLEMENU);