2013-12-31 17:09:29 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Class managing Icon
|
|
|
|
*
|
|
|
|
* @author steeffeen & kremsy
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace ManiaControl\Manialinks;
|
|
|
|
|
|
|
|
|
|
|
|
use FML\Controls\Frame;
|
|
|
|
use FML\Controls\Quad;
|
|
|
|
use FML\ManiaLink;
|
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use ManiaControl\Players\PlayerManager;
|
|
|
|
|
|
|
|
class IconManager implements CallbackListener {
|
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
const DEFAULT_IMG_URL = "http://images.maniacontrol.com/icons/";
|
2013-12-31 17:11:53 +01:00
|
|
|
const PRELOAD_ML_ID = "IconManager.Preload";
|
2013-12-31 17:09:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Some Default icons
|
|
|
|
*/
|
|
|
|
const MX_ICON = 'ManiaExchange.png';
|
2014-01-05 00:43:46 +01:00
|
|
|
const MX_ICON_MOVER = 'ManiaExchange_logo_press.png';
|
2013-12-31 17:09:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private Properties
|
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
|
|
|
private $icons = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Icon Manager
|
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
|
|
|
// Register for callbacks
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_ONINIT, $this, 'handleOnInit');
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerConnect');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an Icon
|
2013-12-31 17:11:53 +01:00
|
|
|
*
|
2013-12-31 17:09:29 +01:00
|
|
|
* @param string $iconName
|
|
|
|
* @param string $iconLink
|
|
|
|
*/
|
2013-12-31 17:11:53 +01:00
|
|
|
public function addIcon($iconName, $iconLink = self::DEFAULT_IMG_URL) {
|
|
|
|
$this->icons[$iconName] = $iconLink . "/" . $iconName;
|
2013-12-31 17:09:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an Icon by its name
|
2013-12-31 17:11:53 +01:00
|
|
|
*
|
2013-12-31 17:09:29 +01:00
|
|
|
* @param $iconName
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-12-31 17:11:53 +01:00
|
|
|
public function getIcon($iconName) {
|
2013-12-31 17:09:29 +01:00
|
|
|
return $this->icons[$iconName];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
2013-12-31 17:11:53 +01:00
|
|
|
public function handleOnInit(array $callback) {
|
2013-12-31 17:09:29 +01:00
|
|
|
$this->preloadIcons();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
2013-12-31 17:11:53 +01:00
|
|
|
public function handlePlayerConnect(array $callback) {
|
2013-12-31 17:09:29 +01:00
|
|
|
$this->preloadIcons($callback[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Preload Icons
|
|
|
|
*/
|
2013-12-31 17:11:53 +01:00
|
|
|
private function preloadIcons($login = false) {
|
2013-12-31 17:09:29 +01:00
|
|
|
$maniaLink = new ManiaLink(self::PRELOAD_ML_ID);
|
|
|
|
|
|
|
|
$frame = new Frame();
|
|
|
|
$maniaLink->add($frame);
|
|
|
|
$frame->setPosition(500, 500);
|
|
|
|
|
2013-12-31 17:11:53 +01:00
|
|
|
foreach ($this->icons as $iconUrl) {
|
2013-12-31 17:09:29 +01:00
|
|
|
$iconQuad = new Quad();
|
|
|
|
$iconQuad->setImage($iconUrl);
|
|
|
|
$iconQuad->setSize(10, 10);
|
|
|
|
$frame->add($iconQuad);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send manialink
|
|
|
|
$manialinkText = $maniaLink->render()->saveXML();
|
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
|
|
|
|
}
|
|
|
|
}
|