testmover

This commit is contained in:
kremsy 2014-01-02 17:21:01 +01:00
parent f935fa9b43
commit 40219b7367

View File

@ -2,17 +2,17 @@
namespace ManiaControl\Admin; namespace ManiaControl\Admin;
use FML\Controls\Quads\Quad_Icons128x128_1;
use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener;
use FML\ManiaLink;
use FML\Controls\Control; use FML\Controls\Control;
use FML\Controls\Frame; use FML\Controls\Frame;
use FML\Controls\Quad; use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink;
use FML\Script\Script;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\ManiaControl;
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
@ -23,13 +23,13 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
/** /**
* Constants * Constants
*/ */
const MLID_MENU = 'ActionsMenu.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_MENU = 'ActionsMenu.OpenAdminMenu'; const ACTION_OPEN_ADMIN_MENU = 'ActionsMenu.OpenAdminMenu';
const ACTION_OPEN_PLAYER_MENU = 'ActionsMenu.OpenPlayerMenu'; const ACTION_OPEN_PLAYER_MENU = 'ActionsMenu.OpenPlayerMenu';
/** /**
* Private Properties * Private Properties
*/ */
@ -44,33 +44,30 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Init settings // Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 156.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 156.);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, -37.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, -37.);
$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->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, $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_ADMIN_MENU, $this, 'openAdminMenu');
'openAdminMenu'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYER_MENU, $this, 'openPlayerMenu');
$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 Control $control
* @param bool $playerAction * @param bool $playerAction
* @param int $order * @param int $order
*/ */
public function addMenuItem(Control $control, $playerAction = true, $order = 0) { public function addMenuItem(Control $control, $playerAction = true, $order = 0) {
if ($playerAction) { if($playerAction) {
$this->addPlayerMenuItem($control, $order); $this->addPlayerMenuItem($control, $order);
} } else {
else {
$this->addAdminMenuItem($control, $order); $this->addAdminMenuItem($control, $order);
} }
} }
@ -79,10 +76,10 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* Add a new Player Menu Item * Add a new Player Menu Item
* *
* @param Control $control * @param Control $control
* @param int $order * @param int $order
*/ */
public function addPlayerMenuItem(Control $control, $order = 0) { public function addPlayerMenuItem(Control $control, $order = 0) {
if (!isset($this->playerMenuItems[$order])) { if(!isset($this->playerMenuItems[$order])) {
$this->playerMenuItems[$order] = array(); $this->playerMenuItems[$order] = array();
} }
array_push($this->playerMenuItems[$order], $control); array_push($this->playerMenuItems[$order], $control);
@ -92,10 +89,10 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* Add a new Admin Menu Item * Add a new Admin Menu Item
* *
* @param Control $control * @param Control $control
* @param int $order * @param int $order
*/ */
public function addAdminMenuItem(Control $control, $order = 0) { public function addAdminMenuItem(Control $control, $order = 0) {
if (!isset($this->adminMenuItems[$order])) { if(!isset($this->adminMenuItems[$order])) {
$this->adminMenuItems[$order] = array(); $this->adminMenuItems[$order] = array();
} }
array_push($this->adminMenuItems[$order], $control); array_push($this->adminMenuItems[$order], $control);
@ -108,8 +105,8 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
*/ */
public function handleOnInit(array $callback) { public function handleOnInit(array $callback) {
$manialinkText = $this->buildMenuIconsManialink()->render()->saveXML(); $manialinkText = $this->buildMenuIconsManialink()->render()->saveXML();
$players = $this->maniaControl->playerManager->getPlayers(); $players = $this->maniaControl->playerManager->getPlayers();
foreach ($players as $player) { foreach($players as $player) {
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
} }
} }
@ -120,7 +117,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* @param array $callback * @param array $callback
*/ */
public function handlePlayerJoined(array $callback) { public function handlePlayerJoined(array $callback) {
$player = $callback[1]; $player = $callback[1];
$manialinkText = $this->buildMenuIconsManialink()->render()->saveXML(); $manialinkText = $this->buildMenuIconsManialink()->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
} }
@ -131,7 +128,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) {
if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)){ if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->configurator->toggleMenu($player); $this->maniaControl->configurator->toggleMenu($player);
} }
} }
@ -145,21 +142,21 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
} }
private function buildMenuIconsManialink() { private function buildMenuIconsManialink() {
$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);
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$itemMarginFactorX = 1.3; $itemMarginFactorX = 1.3;
$itemMarginFactorY = 1.2; $itemMarginFactorY = 1.2;
$manialink = new ManiaLink(self::MLID_MENU); $manialink = new ManiaLink(self::MLID_MENU);
// Admin Menu Icon Frame // Admin Menu Icon Frame
$frame = new Frame(); $frame = new Frame();
$manialink->add($frame); $manialink->add($frame);
$frame->setPosition($posX, $posY); $frame->setPosition($posX, $posY);
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY); $backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
@ -168,73 +165,141 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
$iconFrame = new Frame(); $iconFrame = new Frame();
$frame->add($iconFrame); $frame->add($iconFrame);
// Create script and features
$script = new Script();
$manialink->setScript($script);
$iconFrame->setSize($itemSize, $itemSize); $iconFrame->setSize($itemSize, $itemSize);
$itemQuad = new Quad_Icons64x64_1(); $itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconServers); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconServers);
$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_ADMIN_MENU);
// Player Menu Icon Frame // Player Menu Icon Frame
$frame = new Frame(); $frame = new Frame();
$manialink->add($frame); $manialink->add($frame);
$frame->setPosition($posX, $posY - $itemSize * $itemMarginFactorY); $frame->setPosition($posX, $posY - $itemSize * $itemMarginFactorY);
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY); $backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$iconFrame = new Frame(); $iconFrame = new Frame();
$frame->add($iconFrame); $frame->add($iconFrame);
$iconFrame->setSize($itemSize, $itemSize); $iconFrame->setSize($itemSize, $itemSize);
$itemQuad = new Quad_Icons64x64_1(); $itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconPlayers); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconPlayers);
$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_PLAYER_MENU);
/** TEST TOOLTIP */
$testf = new Frame();
$manialink->add($testf);
$testf->setPosition($posX - $itemSize * $itemMarginFactorX, $posY - $itemSize * $itemMarginFactorY);
//$testf->setHAlign(Control::RIGHT);
$testf->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$testq = new Quad();
$testf->add($testq);
//$testq->setPosition($posX - $itemSize * $itemMarginFactorX, $posY - $itemSize * $itemMarginFactorY);
$testq->setHAlign(Control::CENTER);
$testq->setStyles($quadStyle, $quadSubstyle);
$testq->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$testf->add($testq);
$script->addTooltip($itemQuad, $testf);
$script->addTooltip($testf, $testf);
/** TEST TOOLTIP */
return $manialink; return $manialink;
} }
private function buildMenuIconsManialink2() { private function playerMenuManialink(Player $player) {
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY); $posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
$itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE); $posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE);
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$itemCount = count($this->menuItems); $itemCount = count($this->playerMenuItems);
$manialink = new ManiaLink(self::MLID_MENU);
$itemMarginFactorX = 1.3; $itemMarginFactorX = 1.3;
$itemMarginFactorY = 1.2; $itemMarginFactorY = 1.2;
$manialink = new ManiaLink(self::MLID_MENU);
$frame = new Frame(); $frame = new Frame();
$manialink->add($frame); $manialink->add($frame);
$frame->setPosition($posX, $posY); $frame->setPosition($posX, $posY);
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setSize($itemCount * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY); $backgroundQuad->setSize($itemCount * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$itemsFrame = new Frame(); $itemsFrame = new Frame();
$frame->add($itemsFrame); $frame->add($itemsFrame);
// Add items // Add items
$x = 0.5 * $itemSize * $itemMarginFactorX; $x = 0.5 * $itemSize * $itemMarginFactorX;
foreach ($this->menuItems as $menuItems) { foreach($this->menuItems as $menuItems) {
foreach ($menuItems as $menuItem) { foreach($menuItems as $menuItem) {
$menuItem->setSize($itemSize, $itemSize); $menuItem->setSize($itemSize, $itemSize);
$itemsFrame->add($menuItem); $itemsFrame->add($menuItem);
$x += $itemSize * $itemMarginFactorX; $x += $itemSize * $itemMarginFactorX;
} }
} }
$maniaLinkText = $manialink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($maniaLinkText, $player->login);
}
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);
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$itemCount = count($this->menuItems);
$itemMarginFactorX = 1.3;
$itemMarginFactorY = 1.2;
$manialink = new ManiaLink(self::MLID_MENU);
$frame = new Frame();
$manialink->add($frame);
$frame->setPosition($posX, $posY);
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($itemCount * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$itemsFrame = new Frame();
$frame->add($itemsFrame);
// Add items
$x = 0.5 * $itemSize * $itemMarginFactorX;
foreach($this->menuItems as $menuItems) {
foreach($menuItems as $menuItem) {
$menuItem->setSize($itemSize, $itemSize);
$itemsFrame->add($menuItem);
$x += $itemSize * $itemMarginFactorX;
}
}
$this->manialink = $manialink; $this->manialink = $manialink;
} }
} }