From 05f487aafafd525f1fee9b8e5a4c805828ce55af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Tue, 31 Dec 2013 16:19:39 +0100 Subject: [PATCH] host mx icon on maniacontrol homepage --- application/plugins/WidgetPlugin.php | 145 ++++++++++++++------------- 1 file changed, 74 insertions(+), 71 deletions(-) diff --git a/application/plugins/WidgetPlugin.php b/application/plugins/WidgetPlugin.php index 3859142f..60c4a83e 100644 --- a/application/plugins/WidgetPlugin.php +++ b/application/plugins/WidgetPlugin.php @@ -20,7 +20,7 @@ use ManiaControl\Plugins\Plugin; * @author kremsy */ class WidgetPlugin implements CallbackListener, Plugin { - + /** * Constants */ @@ -28,7 +28,7 @@ class WidgetPlugin implements CallbackListener, Plugin { const PLUGIN_VERSION = 0.1; const PLUGIN_NAME = 'WidgetPlugin'; const PLUGIN_AUTHOR = 'kremsy'; - + // MapWidget Properties const MLID_MAPWIDGET = 'WidgetPlugin.MapWidget'; const SETTING_MAP_WIDGET_ACTIVATED = 'Map-Widget Activated'; @@ -36,7 +36,7 @@ class WidgetPlugin implements CallbackListener, Plugin { const SETTING_MAP_WIDGET_POSY = 'Map-Widget-Position: Y'; const SETTING_MAP_WIDGET_WIDTH = 'Map-Widget-Size: Width'; const SETTING_MAP_WIDGET_HEIGHT = 'Map-Widget-Size: Height'; - + // ClockWidget Properties const MLID_CLOCKWIDGET = 'WidgetPlugin.ClockWidget'; const SETTING_CLOCK_WIDGET_ACTIVATED = 'Clock-Widget Activated'; @@ -44,7 +44,7 @@ class WidgetPlugin implements CallbackListener, Plugin { const SETTING_CLOCK_WIDGET_POSY = 'Clock-Widget-Position: Y'; const SETTING_CLOCK_WIDGET_WIDTH = 'Clock-Widget-Size: Width'; const SETTING_CLOCK_WIDGET_HEIGHT = 'Clock-Widget-Size: Height'; - + // NextMapWidget Properties const MLID_NEXTMAPWIDGET = 'WidgetPlugin.NextMapWidget'; const SETTING_NEXTMAP_WIDGET_ACTIVATED = 'Nextmap-Widget Activated'; @@ -52,7 +52,7 @@ class WidgetPlugin implements CallbackListener, Plugin { const SETTING_NEXTMAP_WIDGET_POSY = 'Nextmap-Widget-Position: Y'; const SETTING_NEXTMAP_WIDGET_WIDTH = 'Nextmap-Widget-Size: Width'; const SETTING_NEXTMAP_WIDGET_HEIGHT = 'Nextmap-Widget-Size: Height'; - + // ServerInfoWidget Properties const MLID_SERVERINFOWIDGET = 'WidgetPlugin.ServerInfoWidget'; const SETTING_SERVERINFO_WIDGET_ACTIVATED = 'ServerInfo-Widget Activated'; @@ -60,11 +60,12 @@ 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 */ /** + * * @var maniaControl $maniaControl */ private $maniaControl = null; @@ -122,41 +123,41 @@ class WidgetPlugin implements CallbackListener, Plugin { */ public function load(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; - + // Set CustomUI Setting $this->maniaControl->manialinkManager->customUIManager->setChallengeInfoVisible(false); - + // Register for callbacks $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'handleOnBeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ENDMAP, $this, 'handleOnEndMap'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_MINUTE, $this, 'handleEveryMinute'); - + $this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED, true); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_POSX, 160 - 20); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_POSY, 90 - 4.5); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_WIDTH, 40); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_HEIGHT, 9.); - + $this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED, true); $this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_POSX, -160 + 17.5); $this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_POSY, 90 - 4.5); $this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_WIDTH, 35); $this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT, 9.); - + $this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED, true); $this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_POSX, 160 - 20); $this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_POSY, 90 - 25.5); $this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_WIDTH, 40); $this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT, 12.); - + $this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED, true); $this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_POSX, 160 - 5); $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); - + return true; } @@ -175,13 +176,13 @@ class WidgetPlugin implements CallbackListener, Plugin { */ public function handleOnInit(array $callback) { // Display Map Widget - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) { + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) { $this->displayMapWidget(); } - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) { + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) { $this->displayClockWidget(); } - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) { + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) { $this->displayServerInfoWidget(); } } @@ -198,26 +199,26 @@ class WidgetPlugin implements CallbackListener, Plugin { $height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_HEIGHT); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); - + $maniaLink = new ManiaLink(self::MLID_MAPWIDGET); $script = new Script(); $maniaLink->setScript($script); - + // mainframe $frame = new Frame(); $maniaLink->add($frame); $frame->setSize($width, $height); $frame->setPosition($pos_x, $pos_y); - + // Background Quad $backgroundQuad = new Quad(); $frame->add($backgroundQuad); $backgroundQuad->setSize($width, $height); $backgroundQuad->setStyles($quadStyle, $quadSubstyle); $script->addMapInfoButton($backgroundQuad); - + $map = $this->maniaControl->mapManager->getCurrentMap(); - + $label = new Label_Text(); $frame->add($label); $label->setY(1.5); @@ -227,30 +228,29 @@ class WidgetPlugin implements CallbackListener, Plugin { $label->setTextSize(1.3); $label->setText($map->name); $label->setTextColor("FFF"); - + $label = new Label_Text(); $frame->add($label); $label->setX(0); $label->setY(-1.4); - + $label->setAlign(Control::CENTER, Control::CENTER); $label->setZ(0.2); $label->setTextSize(1); $label->setScale(0.8); $label->setText($map->authorLogin); $label->setTextColor("FFF"); - - if(isset($map->mx->pageurl)) { + + if (isset($map->mx->pageurl)) { $quad = new Quad(); $frame->add($quad); - $quad->setImage("http://wiki.maniaplanet.com/pool/images/b/bf/ManiaExchange_logo.png"); // TODO include image into - // maniacontrol + $quad->setImage("http://images.maniacontrol.com/icons/ManiaExchange.png"); $quad->setPosition(-$width / 2 + 4, -1.5, -0.5); $quad->setSize(4, 4); $quad->setHAlign(Control::CENTER); $quad->setUrl($map->mx->pageurl); } - + // Send manialink $manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $login); @@ -268,23 +268,23 @@ class WidgetPlugin implements CallbackListener, Plugin { $height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_HEIGHT); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); - + $maniaLink = new ManiaLink(self::MLID_CLOCKWIDGET); - + // mainframe $frame = new Frame(); $maniaLink->add($frame); $frame->setSize($width, $height); $frame->setPosition($pos_x, $pos_y); - + // Background Quad $backgroundQuad = new Quad(); $frame->add($backgroundQuad); $backgroundQuad->setSize($width, $height); $backgroundQuad->setStyles($quadStyle, $quadSubstyle); - + $localTime = date("H:i", time()); - + $label = new Label_Text(); $frame->add($label); $label->setY(1.5); @@ -294,7 +294,7 @@ class WidgetPlugin implements CallbackListener, Plugin { $label->setTextSize(1); $label->setText($localTime); $label->setTextColor("FFF"); - + // Send manialink $manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $login); @@ -312,44 +312,45 @@ class WidgetPlugin implements CallbackListener, Plugin { $height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); - + $maniaLink = new ManiaLink(self::MLID_SERVERINFOWIDGET); - + // mainframe $frame = new Frame(); $maniaLink->add($frame); $frame->setSize($width, $height); $frame->setPosition($pos_x, $pos_y); - + // Background Quad $backgroundQuad = new Quad(); $frame->add($backgroundQuad); $backgroundQuad->setSize($width, $height); $backgroundQuad->setStyles($quadStyle, $quadSubstyle); - + $this->maniaControl->client->query('GetMaxPlayers'); $maxPlayers = $this->maniaControl->client->getResponse(); - + $this->maniaControl->client->query('GetMaxSpectators'); $maxSpectators = $this->maniaControl->client->getResponse(); - + $serverName = $this->maniaControl->server->getName(); - + $players = $this->maniaControl->playerManager->getPlayers(); $playerCount = 0; $spectatorCount = 0; /** + * * @var Player $player */ foreach ($players as $player) { - if($player->isSpectator) { + if ($player->isSpectator) { $spectatorCount++; - } else { + } + else { $playerCount++; } } - - + $label = new Label_Text(); $frame->add($label); $label->setPosition(0, 1.5, 0.2); @@ -357,7 +358,7 @@ class WidgetPlugin implements CallbackListener, Plugin { $label->setTextSize(1.3); $label->setText($serverName); $label->setTextColor("FFF"); - + // Player Quad / Label $label = new Label_Text(); $frame->add($label); @@ -367,14 +368,14 @@ class WidgetPlugin implements CallbackListener, Plugin { $label->setScale(0.8); $label->setText($playerCount . " / " . $maxPlayers['NextValue']); $label->setTextColor("FFF"); - + $quad = new Quad_Icons128x128_1(); $frame->add($quad); $quad->setSubStyle($quad::SUBSTYLE_Multiplayer); $quad->setPosition(-$width / 2 + 7, -1.6, 0.2); $quad->setSize(2.5, 2.5); $quad->setHAlign(Control::CENTER); - + // Spectator Quad / Label $label = new Label_Text(); $frame->add($label); @@ -384,14 +385,14 @@ class WidgetPlugin implements CallbackListener, Plugin { $label->setScale(0.8); $label->setText($spectatorCount . " / " . $maxSpectators['NextValue']); $label->setTextColor("FFF"); - + $quad = new Quad_Icons64x64_1(); $frame->add($quad); $quad->setSubStyle($quad::SUBSTYLE_Camera); $quad->setPosition(0, -1.6, 0.2); $quad->setSize(3.3, 2.5); $quad->setHAlign(Control::CENTER); - + // Favorite quad $quad = new Quad_Icons64x64_1(); $quad = new Quad_Icons128x128_1(); @@ -402,7 +403,7 @@ class WidgetPlugin implements CallbackListener, Plugin { $quad->setSize(4, 4); $quad->setHAlign(Control::CENTER); // $TODO add server to favorite - + // Send manialink $manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $login); @@ -415,7 +416,7 @@ class WidgetPlugin implements CallbackListener, Plugin { */ public function handleOnBeginMap(array $callback) { // Display Map Widget - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) { + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) { $this->displayMapWidget(); } $this->closeWidget(self::MLID_NEXTMAPWIDGET); @@ -439,7 +440,7 @@ class WidgetPlugin implements CallbackListener, Plugin { */ public function handleOnEndMap(array $callback) { // Display Map Widget - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED)) { + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED)) { $this->displayNextMapWidget(); } } @@ -457,41 +458,43 @@ class WidgetPlugin implements CallbackListener, Plugin { $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); $labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle(); - + $maniaLink = new ManiaLink(self::MLID_NEXTMAPWIDGET); - + // mainframe $frame = new Frame(); $maniaLink->add($frame); $frame->setSize($width, $height); $frame->setPosition($pos_x, $pos_y); - + // Background Quad $backgroundQuad = new Quad(); $frame->add($backgroundQuad); $backgroundQuad->setSize($width, $height); $backgroundQuad->setStyles($quadStyle, $quadSubstyle); - + // Check if the Next Map is a queued Map $queuedMap = $this->maniaControl->mapManager->mapQueue->getNextMap(); - + /** + * * @var Player $requester */ $requester = null; // if the nextmap is not a queued map, get it from map info - if($queuedMap == null) { + if ($queuedMap == null) { $this->maniaControl->client->query("GetNextMapInfo"); $map = $this->maniaControl->client->getResponse(); $name = $map['Name']; $author = $map['Author']; - } else { + } + else { $requester = $queuedMap[0]; $map = $queuedMap[1]; $name = $map->name; $author = $map->authorLogin; } - + $label = new Label_Text(); $frame->add($label); $label->setY($height / 2 - 2.3); @@ -502,7 +505,7 @@ class WidgetPlugin implements CallbackListener, Plugin { $label->setText("Next Map"); $label->setTextColor("FFF"); $label->setStyle($labelStyle); - + $label = new Label_Text(); $frame->add($label); $label->setY($height / 2 - 5.5); @@ -512,20 +515,20 @@ class WidgetPlugin implements CallbackListener, Plugin { $label->setTextSize(1.3); $label->setText($name); $label->setTextColor("FFF"); - + $label = new Label_Text(); $frame->add($label); $label->setX(0); $label->setY(-$height / 2 + 4); - + $label->setAlign(Control::CENTER, Control::CENTER); $label->setZ(0.2); $label->setTextSize(1); $label->setScale(0.8); $label->setText($author); $label->setTextColor("FFF"); - - if($requester != null) { + + if ($requester != null) { $label = new Label_Text(); $frame->add($label); $label->setX(0); @@ -538,7 +541,7 @@ class WidgetPlugin implements CallbackListener, Plugin { $label->setTextColor("F80"); $label->setText("Requested by " . $requester->nickname); } - + // Send manialink $manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $login); @@ -552,13 +555,13 @@ class WidgetPlugin implements CallbackListener, Plugin { public function handlePlayerConnect(array $callback) { $player = $callback[1]; // Display Map Widget - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) { + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) { $this->displayMapWidget($player->login); } - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) { + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) { $this->displayClockWidget($player->login); } - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) { + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) { $this->displayServerInfoWidget($player->login); } } @@ -569,7 +572,7 @@ class WidgetPlugin implements CallbackListener, Plugin { * @param array $callback */ public function handleEveryMinute(array $callback) { - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) { + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) { $this->displayClockWidget(); } }