From 1a1d957d69eb7e612d1f36b1ea1acf6023ef4312 Mon Sep 17 00:00:00 2001 From: kremsy Date: Tue, 31 Dec 2013 17:09:29 +0100 Subject: [PATCH] added icon manager --- application/core/Manialinks/IconManager.php | 103 ++++++++++++++++++ .../core/Manialinks/ManialinkManager.php | 7 +- application/plugins/WidgetPlugin.php | 8 +- 3 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 application/core/Manialinks/IconManager.php diff --git a/application/core/Manialinks/IconManager.php b/application/core/Manialinks/IconManager.php new file mode 100644 index 00000000..ef6f6a33 --- /dev/null +++ b/application/core/Manialinks/IconManager.php @@ -0,0 +1,103 @@ +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 + * @param string $iconName + * @param string $iconLink + */ + public function addIcon($iconName, $iconLink = self::DEFAULT_IMG_URL){ + $this->icons[$iconName] = $iconLink . "/" . $iconName; + } + + /** + * Gets an Icon by its name + * @param $iconName + * @return string + */ + public function getIcon($iconName){ + return $this->icons[$iconName]; + } + + /** + * @param array $callback + */ + public function handleOnInit(array $callback){ + $this->preloadIcons(); + } + + /** + * @param array $callback + */ + public function handlePlayerConnect(array $callback){ + $this->preloadIcons($callback[1]); + } + + /** + * Preload Icons + */ + private function preloadIcons($login = false){ + $maniaLink = new ManiaLink(self::PRELOAD_ML_ID); + + $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); + $frame->add($iconQuad); + } + + // Send manialink + $manialinkText = $maniaLink->render()->saveXML(); + $this->maniaControl->manialinkManager->sendManialink($manialinkText, $login); + } +} \ No newline at end of file diff --git a/application/core/Manialinks/ManialinkManager.php b/application/core/Manialinks/ManialinkManager.php index a2ba78dc..4afe32ee 100644 --- a/application/core/Manialinks/ManialinkManager.php +++ b/application/core/Manialinks/ManialinkManager.php @@ -13,6 +13,7 @@ use FML\Controls\Frame; use FML\Controls\Labels\Label_Text; require_once __DIR__ . '/StyleManager.php'; +require_once __DIR__ . '/IconManager.php'; require_once __DIR__ . '/CustomUIManager.php'; require_once __DIR__ . '/../FML/autoload.php'; @@ -35,7 +36,8 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener */ public $styleManager = null; public $customUIManager = null; - + public $iconManager = null; + /** * Private properties */ @@ -52,7 +54,8 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener $this->maniaControl = $maniaControl; $this->styleManager = new StyleManager($maniaControl); $this->customUIManager = new CustomUIManager($maniaControl); - + $this->iconManager = new IconManager($maniaControl); + // Register for callbacks $this->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET, $this, 'closeWidgetCallback'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, diff --git a/application/plugins/WidgetPlugin.php b/application/plugins/WidgetPlugin.php index c93372af..dcc65c3f 100644 --- a/application/plugins/WidgetPlugin.php +++ b/application/plugins/WidgetPlugin.php @@ -10,6 +10,7 @@ use FML\Script\Script; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; use ManiaControl\ManiaControl; +use ManiaControl\Manialinks\IconManager; use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; use ManiaControl\Plugins\Plugin; @@ -60,7 +61,7 @@ class WidgetPlugin implements CallbackListener, Plugin { const SETTING_SERVERINFO_WIDGET_POSY = 'ServerInfo-Widget-Position: Y'; const SETTING_SERVERINFO_WIDGET_WIDTH = 'ServerInfo-Widget-Size: Width'; const SETTING_SERVERINFO_WIDGET_HEIGHT = 'ServerInfo-Widget-Size: Height'; - + /** * Private Properties */ @@ -114,7 +115,8 @@ 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); return true; } @@ -201,7 +203,7 @@ class WidgetPlugin implements CallbackListener, Plugin { if (isset($map->mx->pageurl)) { $quad = new Quad(); $frame->add($quad); - $quad->setImage("http://images.maniacontrol.com/icons/ManiaExchange.png"); + $quad->setImage($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON)); $quad->setPosition(-$width / 2 + 4, -1.5, -0.5); $quad->setSize(4, 4); $quad->setHAlign(Control::CENTER);