improved icon manager
This commit is contained in:
		@@ -1,13 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Class managing Icon
 | 
			
		||||
 *
 | 
			
		||||
 * @author steeffeen & kremsy
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace ManiaControl\Manialinks;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
use FML\Controls\Frame;
 | 
			
		||||
use FML\Controls\Quad;
 | 
			
		||||
use FML\ManiaLink;
 | 
			
		||||
@@ -15,12 +9,17 @@ use ManiaControl\Callbacks\CallbackListener;
 | 
			
		||||
use ManiaControl\ManiaControl;
 | 
			
		||||
use ManiaControl\Players\PlayerManager;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Class managing Icons
 | 
			
		||||
 *
 | 
			
		||||
 * @author steeffeen & kremsy
 | 
			
		||||
 */
 | 
			
		||||
class IconManager implements CallbackListener {
 | 
			
		||||
	/**
 | 
			
		||||
	 * Constants
 | 
			
		||||
	 */
 | 
			
		||||
	const DEFAULT_IMG_URL = "http://images.maniacontrol.com/icons/";
 | 
			
		||||
	const PRELOAD_ML_ID   = "IconManager.Preload";
 | 
			
		||||
	const DEFAULT_IMG_URL = 'http://images.maniacontrol.com/icons/';
 | 
			
		||||
	const PRELOAD_MLID = 'IconManager.Preload.MLID';
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Some Default icons
 | 
			
		||||
@@ -41,34 +40,47 @@ class IconManager implements CallbackListener {
 | 
			
		||||
	 */
 | 
			
		||||
	public function __construct(ManiaControl $maniaControl) {
 | 
			
		||||
		$this->maniaControl = $maniaControl;
 | 
			
		||||
		$this->addDefaultIcons();
 | 
			
		||||
		
 | 
			
		||||
		// Register for callbacks
 | 
			
		||||
		$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_ONINIT, $this, 'handleOnInit');
 | 
			
		||||
		$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerConnect');
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Add the Set of default Icons
 | 
			
		||||
	 */
 | 
			
		||||
	private function addDefaultIcons() {
 | 
			
		||||
		$this->addIcon(self::MX_ICON);
 | 
			
		||||
		$this->addIcon(self::MX_ICON_MOVER);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Adds an Icon
 | 
			
		||||
	 * Add an Icon
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param string $iconName
 | 
			
		||||
	 * @param string $iconLink
 | 
			
		||||
	 */
 | 
			
		||||
	public function addIcon($iconName, $iconLink = self::DEFAULT_IMG_URL) {
 | 
			
		||||
		$this->icons[$iconName] = $iconLink . "/" . $iconName;
 | 
			
		||||
		$this->icons[$iconName] = $iconLink . '/' . $iconName;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Gets an Icon by its name
 | 
			
		||||
	 * Get an Icon by its name
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param $iconName
 | 
			
		||||
	 * @return string
 | 
			
		||||
	 */
 | 
			
		||||
	public function getIcon($iconName) {
 | 
			
		||||
		if (!isset($this->icons[$iconName])) {
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
		return $this->icons[$iconName];
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Handle OnInit Callback
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param array $callback
 | 
			
		||||
	 */
 | 
			
		||||
	public function handleOnInit(array $callback) {
 | 
			
		||||
@@ -76,18 +88,22 @@ class IconManager implements CallbackListener {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Handle PlayerConnect Callback
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param array $callback
 | 
			
		||||
	 */
 | 
			
		||||
	public function handlePlayerConnect(array $callback) {
 | 
			
		||||
		$this->preloadIcons($callback[1]);
 | 
			
		||||
		$login = $callback[1];
 | 
			
		||||
		$this->preloadIcons($login);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Preload Icons
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param string $login
 | 
			
		||||
	 */
 | 
			
		||||
	private function preloadIcons($login = false) {
 | 
			
		||||
		$maniaLink = new ManiaLink(self::PRELOAD_ML_ID);
 | 
			
		||||
 | 
			
		||||
		$maniaLink = new ManiaLink(self::PRELOAD_MLID);
 | 
			
		||||
		$frame = new Frame();
 | 
			
		||||
		$maniaLink->add($frame);
 | 
			
		||||
		$frame->setPosition(500, 500);
 | 
			
		||||
@@ -95,7 +111,7 @@ class IconManager implements CallbackListener {
 | 
			
		||||
		foreach ($this->icons as $iconUrl) {
 | 
			
		||||
			$iconQuad = new Quad();
 | 
			
		||||
			$iconQuad->setImage($iconUrl);
 | 
			
		||||
			$iconQuad->setSize(10, 10);
 | 
			
		||||
			$iconQuad->setSize(1, 1);
 | 
			
		||||
			$frame->add($iconQuad);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
 
 | 
			
		||||
@@ -42,6 +42,8 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
 | 
			
		||||
	 */
 | 
			
		||||
	public function __construct(ManiaControl $maniaControl) {
 | 
			
		||||
		$this->maniaControl = $maniaControl;
 | 
			
		||||
		$this->initActionsMenuButtons();
 | 
			
		||||
		$this->mapList = new MapList($this->maniaControl);
 | 
			
		||||
		
 | 
			
		||||
		// Register for admin chat commands
 | 
			
		||||
		$this->maniaControl->commandManager->registerCommandListener('nextmap', $this, 'command_NextMap', true);
 | 
			
		||||
@@ -54,10 +56,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
 | 
			
		||||
		$this->maniaControl->commandManager->registerCommandListener('list', $this, 'command_List');
 | 
			
		||||
		$this->maniaControl->commandManager->registerCommandListener('maps', $this, 'command_List');
 | 
			
		||||
		
 | 
			
		||||
		$this->mapList = new MapList($this->maniaControl);
 | 
			
		||||
 | 
			
		||||
		//Menus Buttons
 | 
			
		||||
		$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
 | 
			
		||||
		// Menu Buttons
 | 
			
		||||
		$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_XLIST, $this, 'command_xList');
 | 
			
		||||
		$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_MAPLIST, $this, 'command_List');
 | 
			
		||||
		$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_RESTART_MAP, $this, 'command_RestartMap');
 | 
			
		||||
@@ -65,36 +64,35 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Handle on Init
 | 
			
		||||
	 * @param array $callback
 | 
			
		||||
	 * Add all Actions Menu Buttons
 | 
			
		||||
	 */
 | 
			
		||||
	public function handleOnInit(array $callback){
 | 
			
		||||
	private function initActionsMenuButtons() {
 | 
			
		||||
		// Menu Open xList
 | 
			
		||||
		$itemQuad = new Quad();
 | 
			
		||||
		$itemQuad->setImage($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON));
 | 
			
		||||
		$itemQuad->setImageFocus($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER)); //TODO move the button to the image manager
 | 
			
		||||
		$itemQuad->setImageFocus($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER));
 | 
			
		||||
		$itemQuad->setAction(self::ACTION_OPEN_XLIST);
 | 
			
		||||
		$this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 5, 'Open MX List');
 | 
			
		||||
		$this->maniaControl->actionsMenu->addPlayerMenuItem($itemQuad, 5, 'Open MX List');
 | 
			
		||||
		
 | 
			
		||||
		// Menu Open List
 | 
			
		||||
		$itemQuad = new Quad_Icons64x64_1();
 | 
			
		||||
		$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ToolRoot);
 | 
			
		||||
		$itemQuad->setAction(self::ACTION_OPEN_MAPLIST);
 | 
			
		||||
		$this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 10,'Open MapList');
 | 
			
		||||
		$this->maniaControl->actionsMenu->addPlayerMenuItem($itemQuad, 10, 'Open MapList');
 | 
			
		||||
		
 | 
			
		||||
		// Menu RestartMap
 | 
			
		||||
		$itemQuad = new Quad_UIConstruction_Buttons();
 | 
			
		||||
		$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Reload);
 | 
			
		||||
		$itemQuad->setAction(self::ACTION_RESTART_MAP);
 | 
			
		||||
		$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 0, 'Restart Map');
 | 
			
		||||
		$this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 0, 'Restart Map');
 | 
			
		||||
		
 | 
			
		||||
		// Menu NextMap
 | 
			
		||||
		$itemQuad = new Quad_Icons64x64_1();
 | 
			
		||||
		$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowFastNext);
 | 
			
		||||
		$itemQuad->setAction(self::ACTION_SKIP_MAP);
 | 
			
		||||
		$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 1, 'Skip Map');
 | 
			
		||||
 | 
			
		||||
		$this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 1, 'Skip Map');
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Handle removemap command
 | 
			
		||||
	 *
 | 
			
		||||
 
 | 
			
		||||
@@ -116,9 +116,6 @@ class WidgetPlugin implements CallbackListener, Plugin {
 | 
			
		||||
		$this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_POSY, 90 - 11);
 | 
			
		||||
		$this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_WIDTH, 10);
 | 
			
		||||
		$this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_HEIGHT, 5.5);
 | 
			
		||||
 | 
			
		||||
		$this->maniaControl->manialinkManager->iconManager->addIcon(IconManager::MX_ICON);
 | 
			
		||||
		$this->maniaControl->manialinkManager->iconManager->addIcon(IconManager::MX_ICON_MOVER, "http://www.pictures.esc-clan.net/upload"); //TODO to mc website, icon manager
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user