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
/**
* Class managing Icon
*
* @author steeffeen & kremsy
*/
namespace ManiaControl\Manialinks;
use FML\Controls\Frame;
use FML\Controls\Quad;
use FML\ManiaLink;
@ -15,19 +9,24 @@ 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
*/
const MX_ICON = 'ManiaExchange.png';
const MX_ICON_MOVER = 'ManiaExchange_logo_press.png';
/**
* Private Properties
*/
@ -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,29 +88,33 @@ 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);
foreach ($this->icons as $iconUrl) {
$iconQuad = new Quad();
$iconQuad->setImage($iconUrl);
$iconQuad->setSize(10, 10);
$iconQuad->setSize(1, 1);
$frame->add($iconQuad);
}
// Send manialink
$manialinkText = $maniaLink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);

View File

@ -20,15 +20,15 @@ use WidgetPlugin;
*
* @author steeffeen & kremsy
*/
class MapCommands implements CommandListener, ManialinkPageAnswerListener,CallbackListener {
class MapCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener {
/**
* Constants
*/
const ACTION_OPEN_MAPLIST = 'MapList.OpenMapList';
const ACTION_OPEN_XLIST = 'MapList.OpenMXList';
const ACTION_RESTART_MAP = 'MapList.RestartMap';
const ACTION_SKIP_MAP = 'MapList.NextMap';
const ACTION_OPEN_XLIST = 'MapList.OpenMXList';
const ACTION_RESTART_MAP = 'MapList.RestartMap';
const ACTION_SKIP_MAP = 'MapList.NextMap';
/**
* Private properties
*/
@ -42,22 +42,21 @@ 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);
$this->maniaControl->commandManager->registerCommandListener('restartmap', $this, 'command_RestartMap', true);
$this->maniaControl->commandManager->registerCommandListener('addmap', $this, 'command_AddMap', true);
$this->maniaControl->commandManager->registerCommandListener('removemap', $this, 'command_RemoveMap', true);
// Register for player chat commands
$this->maniaControl->commandManager->registerCommandListener('xlist', $this, 'command_xList');
$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,55 +64,54 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
}
/**
* Handle on Init
* @param array $callback
* Add all Actions Menu Buttons
*/
public function handleOnInit(array $callback){
//Menu Open xList
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');
//Menu Open 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');
//Menu RestartMap
$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');
//Menu NextMap
$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
*
* @param array $chat
* @param array $chat
* @param \ManiaControl\Players\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);
return;
}
// Get map
$map = $this->maniaControl->mapManager->getCurrentMap();
if(!$map) {
if (!$map) {
$this->maniaControl->chat->sendError("Couldn't remove map.", $player->login);
return;
}
// 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());
$this->maniaControl->chat->sendError("Couldn't remove map.", $player->login);
return;
@ -124,33 +122,33 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
/**
* Handle addmap command
*
* @param array $chatCallback
* @param array $chatCallback
* @param \ManiaControl\Players\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);
return;
}
// TODO: user mx fetcher
$params = explode(' ', $chatCallback[1][2], 2);
if(count($params) < 2) {
if (count($params) < 2) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //addmap 1234', $player->login);
return;
}
//add Map from Mania Exchange
// add Map from Mania Exchange
$this->maniaControl->mapManager->addMapFromMx($params[1], $player->login);
}
/**
* Handle nextmap command
*
* @param array $chat
* @param array $chat
* @param \ManiaControl\Players\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);
return;
}
@ -160,11 +158,11 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
/**
* Handle restartmap command
*
* @param array $chat
* @param array $chat
* @param \ManiaControl\Players\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);
return;
}
@ -174,7 +172,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
/**
* Handle list maps command
*
* @param array $chatCallback
* @param array $chatCallback
* @param Player $player
*/
public function command_List(array $chatCallback, Player $player) {
@ -184,7 +182,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener,Callba
/**
* Handle ManiaExchange list command
*
* @param array $chatCallback
* @param array $chatCallback
* @param Player $player
*/
public function command_xList(array $chatCallback, Player $player) {

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_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;
}