improved icon manager

This commit is contained in:
Steffen Schröder 2014-01-05 13:32:59 +01:00
parent 7ac39fc164
commit 85c293965b
3 changed files with 77 additions and 66 deletions

View File

@ -1,13 +1,7 @@
<?php <?php
/**
* Class managing Icon
*
* @author steeffeen & kremsy
*/
namespace ManiaControl\Manialinks; namespace ManiaControl\Manialinks;
use FML\Controls\Frame; use FML\Controls\Frame;
use FML\Controls\Quad; use FML\Controls\Quad;
use FML\ManiaLink; use FML\ManiaLink;
@ -15,12 +9,17 @@ use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
/**
* Class managing Icons
*
* @author steeffeen & kremsy
*/
class IconManager implements CallbackListener { class IconManager implements CallbackListener {
/** /**
* Constants * Constants
*/ */
const DEFAULT_IMG_URL = "http://images.maniacontrol.com/icons/"; const DEFAULT_IMG_URL = 'http://images.maniacontrol.com/icons/';
const PRELOAD_ML_ID = "IconManager.Preload"; const PRELOAD_MLID = 'IconManager.Preload.MLID';
/** /**
* Some Default icons * Some Default icons
@ -41,34 +40,47 @@ class IconManager implements CallbackListener {
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->addDefaultIcons();
// 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, 'handlePlayerConnect'); $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 $iconName
* @param string $iconLink * @param string $iconLink
*/ */
public function addIcon($iconName, $iconLink = self::DEFAULT_IMG_URL) { 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 * @param $iconName
* @return string * @return string
*/ */
public function getIcon($iconName) { public function getIcon($iconName) {
if (!isset($this->icons[$iconName])) {
return null;
}
return $this->icons[$iconName]; return $this->icons[$iconName];
} }
/** /**
* Handle OnInit Callback
*
* @param array $callback * @param array $callback
*/ */
public function handleOnInit(array $callback) { public function handleOnInit(array $callback) {
@ -76,18 +88,22 @@ class IconManager implements CallbackListener {
} }
/** /**
* Handle PlayerConnect Callback
*
* @param array $callback * @param array $callback
*/ */
public function handlePlayerConnect(array $callback) { public function handlePlayerConnect(array $callback) {
$this->preloadIcons($callback[1]); $login = $callback[1];
$this->preloadIcons($login);
} }
/** /**
* Preload Icons * Preload Icons
*
* @param string $login
*/ */
private function preloadIcons($login = false) { private function preloadIcons($login = false) {
$maniaLink = new ManiaLink(self::PRELOAD_ML_ID); $maniaLink = new ManiaLink(self::PRELOAD_MLID);
$frame = new Frame(); $frame = new Frame();
$maniaLink->add($frame); $maniaLink->add($frame);
$frame->setPosition(500, 500); $frame->setPosition(500, 500);
@ -95,7 +111,7 @@ class IconManager implements CallbackListener {
foreach ($this->icons as $iconUrl) { foreach ($this->icons as $iconUrl) {
$iconQuad = new Quad(); $iconQuad = new Quad();
$iconQuad->setImage($iconUrl); $iconQuad->setImage($iconUrl);
$iconQuad->setSize(10, 10); $iconQuad->setSize(1, 1);
$frame->add($iconQuad); $frame->add($iconQuad);
} }

View File

@ -20,7 +20,7 @@ use WidgetPlugin;
* *
* @author steeffeen & kremsy * @author steeffeen & kremsy
*/ */
class MapCommands implements CommandListener, ManialinkPageAnswerListener,CallbackListener { class MapCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener {
/** /**
* Constants * Constants
*/ */
@ -42,6 +42,8 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->initActionsMenuButtons();
$this->mapList = new MapList($this->maniaControl);
// Register for admin chat commands // Register for admin chat commands
$this->maniaControl->commandManager->registerCommandListener('nextmap', $this, 'command_NextMap', true); $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('list', $this, 'command_List');
$this->maniaControl->commandManager->registerCommandListener('maps', $this, 'command_List'); $this->maniaControl->commandManager->registerCommandListener('maps', $this, 'command_List');
$this->mapList = new MapList($this->maniaControl); // Menu Buttons
//Menus Buttons
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_XLIST, $this, 'command_xList'); $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_OPEN_MAPLIST, $this, 'command_List');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_RESTART_MAP, $this, 'command_RestartMap'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_RESTART_MAP, $this, 'command_RestartMap');
@ -65,36 +64,35 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
} }
/** /**
* Handle on Init * Add all Actions Menu Buttons
* @param array $callback
*/ */
public function handleOnInit(array $callback){ private function initActionsMenuButtons() {
//Menu Open xList // Menu Open xList
$itemQuad = new Quad(); $itemQuad = new Quad();
$itemQuad->setImage($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON)); $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); $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 // Menu Open List
$itemQuad = new Quad_Icons64x64_1(); $itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ToolRoot); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_ToolRoot);
$itemQuad->setAction(self::ACTION_OPEN_MAPLIST); $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 // Menu RestartMap
$itemQuad = new Quad_UIConstruction_Buttons(); $itemQuad = new Quad_UIConstruction_Buttons();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Reload); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Reload);
$itemQuad->setAction(self::ACTION_RESTART_MAP); $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 // Menu NextMap
$itemQuad = new Quad_Icons64x64_1(); $itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowFastNext); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowFastNext);
$itemQuad->setAction(self::ACTION_SKIP_MAP); $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 * Handle removemap command
* *
@ -102,18 +100,18 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_RemoveMap(array $chat, Player $player) { public function command_RemoveMap(array $chat, Player $player) {
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
// Get map // Get map
$map = $this->maniaControl->mapManager->getCurrentMap(); $map = $this->maniaControl->mapManager->getCurrentMap();
if(!$map) { if (!$map) {
$this->maniaControl->chat->sendError("Couldn't remove map.", $player->login); $this->maniaControl->chat->sendError("Couldn't remove map.", $player->login);
return; return;
} }
// Remove map // Remove map
if(!$this->maniaControl->client->query('RemoveMap', $map->fileName)) { if (!$this->maniaControl->client->query('RemoveMap', $map->fileName)) {
trigger_error("Couldn't remove current map. " . $this->maniaControl->getClientErrorText()); trigger_error("Couldn't remove current map. " . $this->maniaControl->getClientErrorText());
$this->maniaControl->chat->sendError("Couldn't remove map.", $player->login); $this->maniaControl->chat->sendError("Couldn't remove map.", $player->login);
return; return;
@ -128,18 +126,18 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_AddMap(array $chatCallback, Player $player) { public function command_AddMap(array $chatCallback, Player $player) {
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
// TODO: user mx fetcher // TODO: user mx fetcher
$params = explode(' ', $chatCallback[1][2], 2); $params = explode(' ', $chatCallback[1][2], 2);
if(count($params) < 2) { if (count($params) < 2) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //addmap 1234', $player->login); $this->maniaControl->chat->sendUsageInfo('Usage example: //addmap 1234', $player->login);
return; return;
} }
//add Map from Mania Exchange // add Map from Mania Exchange
$this->maniaControl->mapManager->addMapFromMx($params[1], $player->login); $this->maniaControl->mapManager->addMapFromMx($params[1], $player->login);
} }
@ -150,7 +148,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_NextMap(array $chat, Player $player) { public function command_NextMap(array $chat, Player $player) {
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
@ -164,7 +162,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_RestartMap(array $chat, Player $player) { public function command_RestartMap(array $chat, Player $player) {
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }

View File

@ -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_POSY, 90 - 11);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_WIDTH, 10); $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->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; return true;
} }