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