SidebarMenuManager now uses the Position object instead of an array
This commit is contained in:
parent
6be20432ba
commit
023581c195
@ -141,8 +141,8 @@ class ActionsMenu implements SidebarMenuEntryRenderable, CallbackListener, Mania
|
||||
/**
|
||||
* Builds the Manialink
|
||||
*
|
||||
* @param Player $player
|
||||
* @return ManiaLink
|
||||
* @param bool $admin
|
||||
* @return \FML\ManiaLink
|
||||
*/
|
||||
private function buildMenuIconsManialink($admin = false) {
|
||||
$adminPos = $this->maniaControl->getManialinkManager()->getSidebarMenuManager()->getEntryPosition(self::ADMIN_MENU_ID);
|
||||
@ -165,7 +165,7 @@ class ActionsMenu implements SidebarMenuEntryRenderable, CallbackListener, Mania
|
||||
// Admin Menu Icon Frame
|
||||
$iconFrame = new Frame();
|
||||
$frame->addChild($iconFrame);
|
||||
$iconFrame->setPosition($adminPos['x'], $adminPos['y']);
|
||||
$iconFrame->setPosition($adminPos->getX(), $adminPos->getY());
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$iconFrame->addChild($backgroundQuad);
|
||||
@ -180,7 +180,7 @@ class ActionsMenu implements SidebarMenuEntryRenderable, CallbackListener, Mania
|
||||
// Admin Menu Description
|
||||
$descriptionLabel = new Label();
|
||||
$frame->addChild($descriptionLabel);
|
||||
$descriptionLabel->setPosition($adminPos['x'] - count($this->adminMenuItems) * $itemSize * 1.05 - 5, $adminPos['y']);
|
||||
$descriptionLabel->setPosition($adminPos->getX() - count($this->adminMenuItems) * $itemSize * 1.05 - 5, $adminPos->getY());
|
||||
$descriptionLabel->setAlign($descriptionLabel::RIGHT, $descriptionLabel::TOP);
|
||||
$descriptionLabel->setSize(40, 4);
|
||||
$descriptionLabel->setTextSize(1.4);
|
||||
@ -189,7 +189,7 @@ class ActionsMenu implements SidebarMenuEntryRenderable, CallbackListener, Mania
|
||||
// Admin Menu
|
||||
$popoutFrame = new Frame();
|
||||
$frame->addChild($popoutFrame);
|
||||
$popoutFrame->setPosition($adminPos['x'] - $itemSize * 0.5, $adminPos['y']);
|
||||
$popoutFrame->setPosition($adminPos->getX() - $itemSize * 0.5, $adminPos->getY());
|
||||
$popoutFrame->setHorizontalAlign($popoutFrame::RIGHT);
|
||||
$popoutFrame->setVisible(false);
|
||||
|
||||
@ -228,7 +228,7 @@ class ActionsMenu implements SidebarMenuEntryRenderable, CallbackListener, Mania
|
||||
// Player Menu Icon Frame
|
||||
$iconFrame = new Frame();
|
||||
$frame->addChild($iconFrame);
|
||||
$iconFrame->setPosition($playerPos['x'], $playerPos['y']);
|
||||
$iconFrame->setPosition($playerPos->getX(), $playerPos->getY());
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$iconFrame->addChild($backgroundQuad);
|
||||
@ -243,7 +243,7 @@ class ActionsMenu implements SidebarMenuEntryRenderable, CallbackListener, Mania
|
||||
// Player Menu Description
|
||||
$descriptionLabel = new Label();
|
||||
$frame->addChild($descriptionLabel);
|
||||
$descriptionLabel->setPosition($playerPos['x'] - count($this->playerMenuItems) * $itemSize * 1.05 - 5, $playerPos['y']);
|
||||
$descriptionLabel->setPosition($playerPos->getX() - count($this->playerMenuItems) * $itemSize * 1.05 - 5, $playerPos->getY());
|
||||
$descriptionLabel->setAlign($descriptionLabel::RIGHT, $descriptionLabel::TOP);
|
||||
$descriptionLabel->setSize(40, 4);
|
||||
$descriptionLabel->setTextSize(1.4);
|
||||
@ -252,7 +252,7 @@ class ActionsMenu implements SidebarMenuEntryRenderable, CallbackListener, Mania
|
||||
// Player Menu
|
||||
$popoutFrame = new Frame();
|
||||
$frame->addChild($popoutFrame);
|
||||
$popoutFrame->setPosition($playerPos['x'] - $itemSize * 0.5, $playerPos['y']);
|
||||
$popoutFrame->setPosition($playerPos->getX() - $itemSize * 0.5, $playerPos->getY());
|
||||
$popoutFrame->setHorizontalAlign($popoutFrame::RIGHT);
|
||||
$popoutFrame->setVisible(false);
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\Structures\ShootMania\Models\Position;
|
||||
use ManiaControl\General\UsageInformationAble;
|
||||
use ManiaControl\General\UsageInformationTrait;
|
||||
use ManiaControl\ManiaControl;
|
||||
@ -47,9 +48,9 @@ class SidebarMenuManager implements UsageInformationAble, CallbackListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array('x' => xPosition, 'y' => yPosition) of the Sidebar
|
||||
* Returns Position of the Sidebar (PositionObject with x and y)
|
||||
*
|
||||
* @return array
|
||||
* @return Position
|
||||
* @api
|
||||
*/
|
||||
public function getSidebarPosition() {
|
||||
@ -61,32 +62,36 @@ class SidebarMenuManager implements UsageInformationAble, CallbackListener {
|
||||
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SIDEBAR_POSY_TRACKMANIA);
|
||||
}
|
||||
|
||||
return array('x' => $posX, 'y' => $posY);
|
||||
$pos = new Position();
|
||||
$pos->setX($posX);
|
||||
$pos->setY($posY);
|
||||
|
||||
return $pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array('x' => xPosition, 'y' => yPosition) of a menu item of the sidebar
|
||||
* Returns PositionObject of a menu item of the sidebar, or null if it's not found
|
||||
*
|
||||
* @param string $id
|
||||
* @return array|null
|
||||
* @return Position|null
|
||||
* @api
|
||||
*/
|
||||
public function getEntryPosition($id) {
|
||||
$itemSize = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_ITEMSIZE);
|
||||
$itemMarginFactor = 1.2;
|
||||
$pos = $this->getSidebarPosition();
|
||||
$posX = $pos['x'];
|
||||
$posY = $pos['y'];
|
||||
|
||||
if (isset($this->yPositions[$id])) {
|
||||
return array('x' => $posX, 'y' => $this->yPositions[$id]);
|
||||
$pos->setY($this->yPositions[$id]);
|
||||
return $pos;
|
||||
}
|
||||
|
||||
foreach ($this->menuEntries as $entry) {
|
||||
if ($entry == $id) {
|
||||
$this->yPositions[$id] = $posY;
|
||||
return array('x' => $posX, 'y' => $posY);
|
||||
$this->yPositions[$id] = $pos->getY();
|
||||
return $pos;
|
||||
}
|
||||
$posY -= $itemSize * 1.05;
|
||||
$pos->setY($pos->getY() - $itemSize * $itemMarginFactor);
|
||||
}
|
||||
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('SidebarMenuEntry id:' . $id . ' not found');
|
||||
@ -133,7 +138,7 @@ class SidebarMenuManager implements UsageInformationAble, CallbackListener {
|
||||
|
||||
|
||||
/**
|
||||
* @param \ManiaControl\Manialinks\SidebarMenuEntryRenderable $render
|
||||
* @param SidebarMenuEntryRenderable $render
|
||||
* @param $id
|
||||
* @param bool $unregisterClass
|
||||
* @api
|
||||
@ -146,13 +151,15 @@ class SidebarMenuManager implements UsageInformationAble, CallbackListener {
|
||||
}
|
||||
}
|
||||
|
||||
if($unregisterClass){
|
||||
foreach($this->registeredClasses as $k => $class){
|
||||
if($class == $render){
|
||||
foreach ($this->registeredClasses as $k => $class) {
|
||||
if ($class == $render && $unregisterClass) {
|
||||
array_splice($this->registeredClasses, $k, 1);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$class->renderMenuEntry();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -283,7 +283,7 @@ class CustomVotesPlugin implements SidebarMenuEntryRenderable, CommandListener,
|
||||
//Custom Vote Menu Iconsframe
|
||||
$frame = new Frame();
|
||||
$maniaLink->addChild($frame);
|
||||
$frame->setPosition($pos['x'], $pos['y']);
|
||||
$frame->setPosition($pos->getX(), $pos->getY());
|
||||
$frame->setZ(ManialinkManager::MAIN_MANIALINK_Z_VALUE);
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
@ -304,7 +304,7 @@ class CustomVotesPlugin implements SidebarMenuEntryRenderable, CommandListener,
|
||||
$menuEntries = count($this->voteMenuItems);
|
||||
$descriptionFrame = new Frame();
|
||||
$maniaLink->addChild($descriptionFrame);
|
||||
$descriptionFrame->setPosition($pos['x'] - $menuEntries * $itemSize * 1.05 - 5, $pos['y']);
|
||||
$descriptionFrame->setPosition($pos->getX() - $menuEntries * $itemSize * 1.05 - 5, $pos->getY());
|
||||
|
||||
$descriptionLabel = new Label();
|
||||
$descriptionFrame->addChild($descriptionLabel);
|
||||
@ -316,7 +316,7 @@ class CustomVotesPlugin implements SidebarMenuEntryRenderable, CommandListener,
|
||||
//Popout Frame
|
||||
$popoutFrame = new Frame();
|
||||
$maniaLink->addChild($popoutFrame);
|
||||
$popoutFrame->setPosition($pos['x'] - $itemSize * 0.5, $pos['y']);
|
||||
$popoutFrame->setPosition($pos->getX() - $itemSize * 0.5, $pos->getY());
|
||||
$popoutFrame->setHorizontalAlign($popoutFrame::RIGHT);
|
||||
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
||||
$popoutFrame->setVisible(false);
|
||||
@ -350,7 +350,6 @@ class CustomVotesPlugin implements SidebarMenuEntryRenderable, CommandListener,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Send manialink
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin, Sideb
|
||||
// Donate Menu Icon Frame
|
||||
$frame = new Frame();
|
||||
$maniaLink->addChild($frame);
|
||||
$frame->setPosition($pos['x'], $pos['y']);
|
||||
$frame->setPosition($pos->getX(), $pos->getY());
|
||||
$frame->setZ(ManialinkManager::MAIN_MANIALINK_Z_VALUE);
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
|
Loading…
Reference in New Issue
Block a user