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,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);
|
||||
|
Reference in New Issue
Block a user