2013-12-31 17:09:29 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Manialinks;
|
|
|
|
|
|
|
|
use FML\Controls\Frame;
|
|
|
|
use FML\Controls\Quad;
|
|
|
|
use FML\ManiaLink;
|
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
2014-05-24 16:39:12 +02:00
|
|
|
use ManiaControl\Callbacks\Callbacks;
|
2013-12-31 17:09:29 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
2014-02-19 15:44:00 +01:00
|
|
|
use ManiaControl\Players\Player;
|
2014-05-02 17:50:30 +02:00
|
|
|
use ManiaControl\Players\PlayerManager;
|
2013-12-31 17:09:29 +01:00
|
|
|
|
2014-01-05 13:32:59 +01:00
|
|
|
/**
|
|
|
|
* Class managing Icons
|
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2017-02-04 11:49:23 +01:00
|
|
|
* @copyright 2014-2017 ManiaControl Team
|
2014-05-02 17:50:30 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-01-05 13:32:59 +01:00
|
|
|
*/
|
2013-12-31 17:09:29 +01:00
|
|
|
class IconManager implements CallbackListener {
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2013-12-31 17:09:29 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
2017-03-16 21:45:48 +01:00
|
|
|
const DEFAULT_IMG_URL = 'https://images.maniacontrol.com/icons/';
|
2014-01-09 17:26:59 +01:00
|
|
|
const PRELOAD_MLID = 'IconManager.Preload.MLID';
|
|
|
|
|
2014-08-02 22:31:46 +02:00
|
|
|
/*
|
2014-07-25 16:28:47 +02:00
|
|
|
* Default icons
|
2013-12-31 17:09:29 +01:00
|
|
|
*/
|
2014-01-09 17:26:59 +01:00
|
|
|
const MX_ICON = 'ManiaExchange.png';
|
2014-01-05 00:43:46 +01:00
|
|
|
const MX_ICON_MOVER = 'ManiaExchange_logo_press.png';
|
2014-01-09 17:26:59 +01:00
|
|
|
|
2014-01-14 18:19:29 +01:00
|
|
|
const MX_ICON_GREEN = 'ManiaExchangeGreen.png';
|
2014-01-12 00:28:06 +01:00
|
|
|
const MX_ICON_GREEN_MOVER = 'ManiaExchange_logo_pressGreen.png';
|
|
|
|
|
2014-08-02 22:31:46 +02:00
|
|
|
/*
|
2014-07-25 16:28:47 +02:00
|
|
|
* Private properties
|
2013-12-31 17:09:29 +01:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2013-12-31 17:09:29 +01:00
|
|
|
private $maniaControl = null;
|
2015-01-17 15:59:26 +01:00
|
|
|
private $icons = array();
|
2013-12-31 17:09:29 +01:00
|
|
|
|
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Construct a new icon manager instance
|
2013-12-31 17:09:29 +01:00
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-01-05 13:32:59 +01:00
|
|
|
$this->addDefaultIcons();
|
2014-01-09 17:26:59 +01:00
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Callbacks
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
2013-12-31 17:09:29 +01:00
|
|
|
}
|
|
|
|
|
2014-01-05 13:32:59 +01:00
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Add the set of default icons
|
2014-01-05 13:32:59 +01:00
|
|
|
*/
|
|
|
|
private function addDefaultIcons() {
|
|
|
|
$this->addIcon(self::MX_ICON);
|
|
|
|
$this->addIcon(self::MX_ICON_MOVER);
|
2014-01-14 18:19:29 +01:00
|
|
|
$this->addIcon(self::MX_ICON_GREEN);
|
|
|
|
$this->addIcon(self::MX_ICON_GREEN_MOVER);
|
2014-01-05 13:32:59 +01:00
|
|
|
}
|
2013-12-31 17:09:29 +01:00
|
|
|
|
|
|
|
/**
|
2014-01-05 13:32:59 +01:00
|
|
|
* Add 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) {
|
2014-01-05 13:32:59 +01:00
|
|
|
$this->icons[$iconName] = $iconLink . '/' . $iconName;
|
2013-12-31 17:09:29 +01:00
|
|
|
}
|
|
|
|
|
2015-01-17 15:59:26 +01:00
|
|
|
/**
|
|
|
|
* Adds an Icon by it's full URL
|
|
|
|
*
|
|
|
|
* @param $iconName
|
|
|
|
* @param $iconUrl
|
|
|
|
*/
|
|
|
|
public function addIconFullUrl($iconName, $iconUrl) {
|
|
|
|
$this->icons[$iconName] = $iconUrl;
|
|
|
|
}
|
|
|
|
|
2013-12-31 17:09:29 +01:00
|
|
|
/**
|
2014-05-13 16:40:05 +02:00
|
|
|
* Get an Icon by its Name
|
2013-12-31 17:11:53 +01:00
|
|
|
*
|
2014-05-13 16:40:05 +02:00
|
|
|
* @param string $iconName
|
2013-12-31 17:09:29 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
2013-12-31 17:11:53 +01:00
|
|
|
public function getIcon($iconName) {
|
2014-01-28 15:56:50 +01:00
|
|
|
if (!isset($this->icons[$iconName])) {
|
2014-01-05 13:32:59 +01:00
|
|
|
return null;
|
|
|
|
}
|
2013-12-31 17:09:29 +01:00
|
|
|
return $this->icons[$iconName];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-01-05 13:32:59 +01:00
|
|
|
* Handle OnInit Callback
|
2013-12-31 17:09:29 +01:00
|
|
|
*/
|
2014-03-01 11:11:50 +01:00
|
|
|
public function handleAfterInit() {
|
2013-12-31 17:09:29 +01:00
|
|
|
$this->preloadIcons();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Preload Icons
|
2014-01-05 13:32:59 +01:00
|
|
|
*
|
2014-02-19 15:44:00 +01:00
|
|
|
* @param Player $player
|
2013-12-31 17:09:29 +01:00
|
|
|
*/
|
2014-02-19 15:44:00 +01:00
|
|
|
public function preloadIcons($player = null) {
|
2014-01-05 13:32:59 +01:00
|
|
|
$maniaLink = new ManiaLink(self::PRELOAD_MLID);
|
2014-01-09 17:26:59 +01:00
|
|
|
$frame = new Frame();
|
2013-12-31 17:09:29 +01:00
|
|
|
$maniaLink->add($frame);
|
|
|
|
$frame->setPosition(500, 500);
|
2014-01-09 17:26:59 +01:00
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
foreach ($this->icons as $iconUrl) {
|
2013-12-31 17:09:29 +01:00
|
|
|
$iconQuad = new Quad();
|
|
|
|
$iconQuad->setImage($iconUrl);
|
2014-01-05 13:32:59 +01:00
|
|
|
$iconQuad->setSize(1, 1);
|
2013-12-31 17:09:29 +01:00
|
|
|
$frame->add($iconQuad);
|
|
|
|
}
|
2014-01-09 17:26:59 +01:00
|
|
|
|
2013-12-31 17:09:29 +01:00
|
|
|
// Send manialink
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $player);
|
2013-12-31 17:09:29 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle PlayerConnect Callback
|
|
|
|
*
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function handlePlayerConnect(Player $player) {
|
|
|
|
$this->preloadIcons($player);
|
|
|
|
}
|
2014-07-25 16:28:47 +02:00
|
|
|
}
|