ActionsMenu and Configurator Improvements
This commit is contained in:
parent
17f18a2cdb
commit
16b1550530
@ -12,6 +12,7 @@ use FML\Controls\Quad;
|
|||||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use ManiaControl\Players\PlayerManager;
|
use ManiaControl\Players\PlayerManager;
|
||||||
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class managing Actions Menus
|
* Class managing Actions Menus
|
||||||
@ -33,7 +34,6 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
|||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
private $manialink = null;
|
|
||||||
private $adminMenuItems = array();
|
private $adminMenuItems = array();
|
||||||
private $playerMenuItems = array();
|
private $playerMenuItems = array();
|
||||||
|
|
||||||
@ -107,25 +107,20 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
|||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function handleOnInit(array $callback) {
|
public function handleOnInit(array $callback) {
|
||||||
$this->buildIcons();
|
$manialinkText = $this->buildMenuIconsManialink()->render()->saveXML();
|
||||||
$manialinkText = $this->manialink->render()->saveXML();
|
|
||||||
$players = $this->maniaControl->playerManager->getPlayers();
|
$players = $this->maniaControl->playerManager->getPlayers();
|
||||||
foreach ($players as $player) {
|
foreach ($players as $player) {
|
||||||
if (!$this->checkPlayerRight($player)) continue;
|
|
||||||
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle PlayerConnect callback
|
* Handle PlayerJoined callback
|
||||||
*
|
*
|
||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function handlePlayerJoined(array $callback) {
|
public function handlePlayerJoined(array $callback, Player $player) {
|
||||||
$player = $callback[1];
|
$manialinkText = $this->buildMenuIconsManialink()->render()->saveXML();
|
||||||
if (!$player || !$this->checkPlayerRight($player)) return;
|
|
||||||
$this->buildIcons();
|
|
||||||
$manialinkText = $this->manialink->render()->saveXML();
|
|
||||||
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,9 +130,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
|||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function openAdminMenu(array $callback, Player $player) {
|
public function openAdminMenu(array $callback, Player $player) {
|
||||||
$this->buildManialink(true);
|
$this->maniaControl->configurator->toggleMenu($player);
|
||||||
$manialinkText = $this->manialink->render()->saveXML();
|
|
||||||
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -146,29 +139,9 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
|||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function openPlayerMenu(array $callback, Player $player) {
|
public function openPlayerMenu(array $callback, Player $player) {
|
||||||
$this->buildManialink(true);
|
|
||||||
$manialinkText = $this->manialink->render()->saveXML();
|
|
||||||
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function buildMenuIconsManialink() {
|
||||||
* 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;
|
|
||||||
|
|
||||||
$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);
|
||||||
@ -193,11 +166,11 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
|||||||
$frame->add($iconFrame);
|
$frame->add($iconFrame);
|
||||||
|
|
||||||
$iconFrame->setSize($itemSize, $itemSize);
|
$iconFrame->setSize($itemSize, $itemSize);
|
||||||
$itemQuad = new Quad_Icons128x128_1();
|
$itemQuad = new Quad_Icons64x64_1();
|
||||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Options);
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconPlayers);
|
||||||
$itemQuad->setSize($itemSize, $itemSize);
|
$itemQuad->setSize($itemSize, $itemSize);
|
||||||
$iconFrame->add($itemQuad);
|
$iconFrame->add($itemQuad);
|
||||||
$itemQuad->setAction(self::ACTION_OPEN_ADMIN_MENU);
|
$itemQuad->setAction(self::ACTION_OPEN_PLAYER_MENU);
|
||||||
|
|
||||||
// Admin Menu Icon Frame
|
// Admin Menu Icon Frame
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
@ -213,23 +186,16 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
|||||||
$frame->add($iconFrame);
|
$frame->add($iconFrame);
|
||||||
|
|
||||||
$iconFrame->setSize($itemSize, $itemSize);
|
$iconFrame->setSize($itemSize, $itemSize);
|
||||||
$itemQuad = new Quad_Icons128x128_1();
|
$itemQuad = new Quad_Icons64x64_1();
|
||||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Custom);
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconServers);
|
||||||
$itemQuad->setSize($itemSize, $itemSize);
|
$itemQuad->setSize($itemSize, $itemSize);
|
||||||
$iconFrame->add($itemQuad);
|
$iconFrame->add($itemQuad);
|
||||||
$itemQuad->setAction(self::ACTION_OPEN_PLAYER_MENU);
|
$itemQuad->setAction(self::ACTION_OPEN_ADMIN_MENU);
|
||||||
|
|
||||||
$this->manialink = $manialink;
|
return $manialink;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function buildMenuIconsManialink2() {
|
||||||
* Build the menu manialink if necessary
|
|
||||||
*
|
|
||||||
* @param bool $forceBuild
|
|
||||||
*/
|
|
||||||
private function buildManialink($forceBuild = false) {
|
|
||||||
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);
|
||||||
|
@ -20,6 +20,7 @@ use FML\Script\Menus;
|
|||||||
use FML\Script\Pages;
|
use FML\Script\Pages;
|
||||||
use FML\Script\Script;
|
use FML\Script\Script;
|
||||||
use FML\Script\Tooltips;
|
use FML\Script\Tooltips;
|
||||||
|
use ManiaControl\Commands\CommandListener;
|
||||||
|
|
||||||
require_once __DIR__ . '/ConfiguratorMenu.php';
|
require_once __DIR__ . '/ConfiguratorMenu.php';
|
||||||
require_once __DIR__ . '/ScriptSettings.php';
|
require_once __DIR__ . '/ScriptSettings.php';
|
||||||
@ -29,7 +30,7 @@ require_once __DIR__ . '/ScriptSettings.php';
|
|||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
*/
|
*/
|
||||||
class Configurator implements CallbackListener, ManialinkPageAnswerListener {
|
class Configurator implements CallbackListener, CommandListener, ManialinkPageAnswerListener {
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
@ -58,7 +59,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
|
|||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
$this->addAdminMenuItem();
|
$this->addActionsMenuItem();
|
||||||
|
|
||||||
// Init settings
|
// Init settings
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 0.);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 0.);
|
||||||
@ -72,19 +73,29 @@ 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);
|
||||||
|
|
||||||
|
// 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
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function handleToggleMenuAction(array $callback, Player $player) {
|
public function handleToggleMenuAction(array $callback, Player $player) {
|
||||||
if (isset($this->playersMenuShown[$player->login])) {
|
$this->toggleMenu($player);
|
||||||
$this->hideMenu($player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->showMenu($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
|
* @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
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
@ -172,6 +179,20 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
|
|||||||
unset($this->playersMenuShown[$player->login]);
|
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
|
* 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 = new Quad();
|
||||||
$itemQuad->setStyles('Icons128x32_1', 'Settings');
|
$itemQuad->setStyles('Icons128x32_1', 'Settings');
|
||||||
$itemQuad->setAction(self::ACTION_TOGGLEMENU);
|
$itemQuad->setAction(self::ACTION_TOGGLEMENU);
|
||||||
|
Loading…
Reference in New Issue
Block a user