This commit is contained in:
kremsy 2013-12-31 15:53:06 +01:00
parent 36d75064e2
commit eeb2a89c4f

View File

@ -1,29 +1,27 @@
<?php <?php
use FML\Controls\Control; use FML\Controls\Control;
use FML\Controls\Frame; use FML\Controls\Frame;
use FML\Controls\Labels\Label_Button;
use FML\Controls\Labels\Label_Text; use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad; use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Bgs1;
use FML\Controls\Quads\Quad_Bgs1InRace;
use FML\Controls\Quads\Quad_Icons128x128_1; use FML\Controls\Quads\Quad_Icons128x128_1;
use FML\Controls\Quads\Quad_Icons64x64_1; use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink; use FML\ManiaLink;
use FML\Script\Script;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
use ManiaControl\Callbacks\CallbackManager;
use FML\Script\Script;
/** /**
* ManiaControl Widget Plugin * ManiaControl Widget Plugin
* *
* @author kremsy * @author kremsy
*/ */
class WidgetPlugin implements CallbackListener, Plugin { class WidgetPlugin implements CallbackListener, Plugin
{
/** /**
* Constants * Constants
*/ */
@ -31,7 +29,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
const PLUGIN_VERSION = 0.1; const PLUGIN_VERSION = 0.1;
const PLUGIN_NAME = 'WidgetPlugin'; const PLUGIN_NAME = 'WidgetPlugin';
const PLUGIN_AUTHOR = 'kremsy'; const PLUGIN_AUTHOR = 'kremsy';
// MapWidget Properties // MapWidget Properties
const MLID_MAPWIDGET = 'WidgetPlugin.MapWidget'; const MLID_MAPWIDGET = 'WidgetPlugin.MapWidget';
const SETTING_MAP_WIDGET_ACTIVATED = 'Map-Widget Activated'; const SETTING_MAP_WIDGET_ACTIVATED = 'Map-Widget Activated';
@ -39,7 +37,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
const SETTING_MAP_WIDGET_POSY = 'Map-Widget-Position: Y'; const SETTING_MAP_WIDGET_POSY = 'Map-Widget-Position: Y';
const SETTING_MAP_WIDGET_WIDTH = 'Map-Widget-Size: Width'; const SETTING_MAP_WIDGET_WIDTH = 'Map-Widget-Size: Width';
const SETTING_MAP_WIDGET_HEIGHT = 'Map-Widget-Size: Height'; const SETTING_MAP_WIDGET_HEIGHT = 'Map-Widget-Size: Height';
// ClockWidget Properties // ClockWidget Properties
const MLID_CLOCKWIDGET = 'WidgetPlugin.ClockWidget'; const MLID_CLOCKWIDGET = 'WidgetPlugin.ClockWidget';
const SETTING_CLOCK_WIDGET_ACTIVATED = 'Clock-Widget Activated'; const SETTING_CLOCK_WIDGET_ACTIVATED = 'Clock-Widget Activated';
@ -47,7 +45,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
const SETTING_CLOCK_WIDGET_POSY = 'Clock-Widget-Position: Y'; const SETTING_CLOCK_WIDGET_POSY = 'Clock-Widget-Position: Y';
const SETTING_CLOCK_WIDGET_WIDTH = 'Clock-Widget-Size: Width'; const SETTING_CLOCK_WIDGET_WIDTH = 'Clock-Widget-Size: Width';
const SETTING_CLOCK_WIDGET_HEIGHT = 'Clock-Widget-Size: Height'; const SETTING_CLOCK_WIDGET_HEIGHT = 'Clock-Widget-Size: Height';
// NextMapWidget Properties // NextMapWidget Properties
const MLID_NEXTMAPWIDGET = 'WidgetPlugin.NextMapWidget'; const MLID_NEXTMAPWIDGET = 'WidgetPlugin.NextMapWidget';
const SETTING_NEXTMAP_WIDGET_ACTIVATED = 'Nextmap-Widget Activated'; const SETTING_NEXTMAP_WIDGET_ACTIVATED = 'Nextmap-Widget Activated';
@ -55,7 +53,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
const SETTING_NEXTMAP_WIDGET_POSY = 'Nextmap-Widget-Position: Y'; const SETTING_NEXTMAP_WIDGET_POSY = 'Nextmap-Widget-Position: Y';
const SETTING_NEXTMAP_WIDGET_WIDTH = 'Nextmap-Widget-Size: Width'; const SETTING_NEXTMAP_WIDGET_WIDTH = 'Nextmap-Widget-Size: Width';
const SETTING_NEXTMAP_WIDGET_HEIGHT = 'Nextmap-Widget-Size: Height'; const SETTING_NEXTMAP_WIDGET_HEIGHT = 'Nextmap-Widget-Size: Height';
// ServerInfoWidget Properties // ServerInfoWidget Properties
const MLID_SERVERINFOWIDGET = 'WidgetPlugin.ServerInfoWidget'; const MLID_SERVERINFOWIDGET = 'WidgetPlugin.ServerInfoWidget';
const SETTING_SERVERINFO_WIDGET_ACTIVATED = 'ServerInfo-Widget Activated'; const SETTING_SERVERINFO_WIDGET_ACTIVATED = 'ServerInfo-Widget Activated';
@ -63,7 +61,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
const SETTING_SERVERINFO_WIDGET_POSY = 'ServerInfo-Widget-Position: Y'; const SETTING_SERVERINFO_WIDGET_POSY = 'ServerInfo-Widget-Position: Y';
const SETTING_SERVERINFO_WIDGET_WIDTH = 'ServerInfo-Widget-Size: Width'; const SETTING_SERVERINFO_WIDGET_WIDTH = 'ServerInfo-Widget-Size: Width';
const SETTING_SERVERINFO_WIDGET_HEIGHT = 'ServerInfo-Widget-Size: Height'; const SETTING_SERVERINFO_WIDGET_HEIGHT = 'ServerInfo-Widget-Size: Height';
/** /**
* Private Properties * Private Properties
*/ */
@ -78,83 +76,86 @@ class WidgetPlugin implements CallbackListener, Plugin {
* @param ManiaControl $maniaControl * @param ManiaControl $maniaControl
* @return bool * @return bool
*/ */
public function load(ManiaControl $maniaControl) { public function load(ManiaControl $maniaControl)
{
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Set CustomUI Setting // Set CustomUI Setting
$this->maniaControl->manialinkManager->customUIManager->setChallengeInfoVisible(false); $this->maniaControl->manialinkManager->customUIManager->setChallengeInfoVisible(false);
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit'); $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_BEGINMAP, $this, 'handleOnBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ENDMAP, $this, 'handleOnEndMap'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ENDMAP, $this, 'handleOnEndMap');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_MINUTE, $this, 'handleEveryMinute'); $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_ACTIVATED, true);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_POSX, 160 - 20); $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_POSY, 90 - 4.5);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_WIDTH, 40); $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_MAP_WIDGET_HEIGHT, 9.);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED, true); $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_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_POSY, 90 - 4.5);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_WIDTH, 35); $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_SERVERINFO_WIDGET_HEIGHT, 9.);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED, true); $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_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_POSY, 90 - 25.5);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_WIDTH, 40); $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_NEXTMAP_WIDGET_HEIGHT, 12.);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED, true); $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_POSX, 160 - 5);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_POSY, 90 - 11); $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_WIDTH, 10);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_HEIGHT, 5.5); $this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_HEIGHT, 5.5);
return true; return true;
} }
/** /**
* Unload the plugin and its resources * Unload the plugin and its resources
*/ */
public function unload() { public function unload()
{
$this->maniaControl->callbackManager->unregisterCallbackListener($this); $this->maniaControl->callbackManager->unregisterCallbackListener($this);
unset($this->maniaControl); unset($this->maniaControl);
} }
/** /**
* Displays the Clock Widget * Displays the Clock Widget
* *
* @param bool $login * @param bool $login
*/ */
public function displayClockWidget($login = false) { public function displayClockWidget($login = false)
{
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_POSX); $pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_POSX);
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_POSY); $pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_POSY);
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_WIDTH); $width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_WIDTH);
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_HEIGHT); $height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$maniaLink = new ManiaLink(self::MLID_CLOCKWIDGET); $maniaLink = new ManiaLink(self::MLID_CLOCKWIDGET);
// mainframe // mainframe
$frame = new Frame(); $frame = new Frame();
$maniaLink->add($frame); $maniaLink->add($frame);
$frame->setSize($width, $height); $frame->setSize($width, $height);
$frame->setPosition($pos_x, $pos_y); $frame->setPosition($pos_x, $pos_y);
// Background Quad // Background Quad
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height); $backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$localTime = date("H:i", time()); $localTime = date("H:i", time());
$label = new Label_Text(); $label = new Label_Text();
$frame->add($label); $frame->add($label);
$label->setY(1.5); $label->setY(1.5);
@ -164,7 +165,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
$label->setTextSize(1); $label->setTextSize(1);
$label->setText($localTime); $label->setText($localTime);
$label->setTextColor("FFF"); $label->setTextColor("FFF");
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $manialinkText = $maniaLink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
@ -175,7 +176,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @param bool $login * @param bool $login
*/ */
public function displayNextMapWidget($login = false) { public function displayNextMapWidget($login = false)
{
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_POSX); $pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_POSX);
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_POSY); $pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_POSY);
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_WIDTH); $width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_WIDTH);
@ -183,24 +185,24 @@ class WidgetPlugin implements CallbackListener, Plugin {
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle(); $labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
$maniaLink = new ManiaLink(self::MLID_NEXTMAPWIDGET); $maniaLink = new ManiaLink(self::MLID_NEXTMAPWIDGET);
// mainframe // mainframe
$frame = new Frame(); $frame = new Frame();
$maniaLink->add($frame); $maniaLink->add($frame);
$frame->setSize($width, $height); $frame->setSize($width, $height);
$frame->setPosition($pos_x, $pos_y); $frame->setPosition($pos_x, $pos_y);
// Background Quad // Background Quad
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height); $backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
// Check if the Next Map is a queued Map // Check if the Next Map is a queued Map
$queuedMap = $this->maniaControl->mapManager->mapQueue->getNextMap(); $queuedMap = $this->maniaControl->mapManager->mapQueue->getNextMap();
/** /**
* @var Player $requester * @var Player $requester
*/ */
@ -211,14 +213,13 @@ class WidgetPlugin implements CallbackListener, Plugin {
$map = $this->maniaControl->client->getResponse(); $map = $this->maniaControl->client->getResponse();
$name = $map['Name']; $name = $map['Name'];
$author = $map['Author']; $author = $map['Author'];
} } else {
else {
$requester = $queuedMap[0]; $requester = $queuedMap[0];
$map = $queuedMap[1]; $map = $queuedMap[1];
$name = $map->name; $name = $map->name;
$author = $map->authorLogin; $author = $map->authorLogin;
} }
$label = new Label_Text(); $label = new Label_Text();
$frame->add($label); $frame->add($label);
$label->setY($height / 2 - 2.3); $label->setY($height / 2 - 2.3);
@ -229,7 +230,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
$label->setText("Next Map"); $label->setText("Next Map");
$label->setTextColor("FFF"); $label->setTextColor("FFF");
$label->setStyle($labelStyle); $label->setStyle($labelStyle);
$label = new Label_Text(); $label = new Label_Text();
$frame->add($label); $frame->add($label);
$label->setY($height / 2 - 5.5); $label->setY($height / 2 - 5.5);
@ -239,19 +240,19 @@ class WidgetPlugin implements CallbackListener, Plugin {
$label->setTextSize(1.3); $label->setTextSize(1.3);
$label->setText($name); $label->setText($name);
$label->setTextColor("FFF"); $label->setTextColor("FFF");
$label = new Label_Text(); $label = new Label_Text();
$frame->add($label); $frame->add($label);
$label->setX(0); $label->setX(0);
$label->setY(-$height / 2 + 4); $label->setY(-$height / 2 + 4);
$label->setAlign(Control::CENTER, Control::CENTER); $label->setAlign(Control::CENTER, Control::CENTER);
$label->setZ(0.2); $label->setZ(0.2);
$label->setTextSize(1); $label->setTextSize(1);
$label->setScale(0.8); $label->setScale(0.8);
$label->setText($author); $label->setText($author);
$label->setTextColor("FFF"); $label->setTextColor("FFF");
if ($requester != null) { if ($requester != null) {
$label = new Label_Text(); $label = new Label_Text();
$frame->add($label); $frame->add($label);
@ -265,7 +266,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
$label->setTextColor("F80"); $label->setTextColor("F80");
$label->setText("Requested by " . $requester->nickname); $label->setText("Requested by " . $requester->nickname);
} }
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $manialinkText = $maniaLink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
@ -276,36 +277,37 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @param String $login * @param String $login
*/ */
public function displayServerInfoWidget($login = false) { public function displayServerInfoWidget($login = false)
{
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_POSX); $pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_POSX);
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_POSY); $pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_POSY);
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_WIDTH); $width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_WIDTH);
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT); $height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$maniaLink = new ManiaLink(self::MLID_SERVERINFOWIDGET); $maniaLink = new ManiaLink(self::MLID_SERVERINFOWIDGET);
// mainframe // mainframe
$frame = new Frame(); $frame = new Frame();
$maniaLink->add($frame); $maniaLink->add($frame);
$frame->setSize($width, $height); $frame->setSize($width, $height);
$frame->setPosition($pos_x, $pos_y); $frame->setPosition($pos_x, $pos_y);
// Background Quad // Background Quad
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height); $backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$this->maniaControl->client->query('GetMaxPlayers'); $this->maniaControl->client->query('GetMaxPlayers');
$maxPlayers = $this->maniaControl->client->getResponse(); $maxPlayers = $this->maniaControl->client->getResponse();
$this->maniaControl->client->query('GetMaxSpectators'); $this->maniaControl->client->query('GetMaxSpectators');
$maxSpectators = $this->maniaControl->client->getResponse(); $maxSpectators = $this->maniaControl->client->getResponse();
$serverName = $this->maniaControl->server->getName(); $serverName = $this->maniaControl->server->getName();
$players = $this->maniaControl->playerManager->getPlayers(); $players = $this->maniaControl->playerManager->getPlayers();
$playerCount = 0; $playerCount = 0;
$spectatorCount = 0; $spectatorCount = 0;
@ -318,7 +320,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
else else
$playerCount++; $playerCount++;
} }
$label = new Label_Text(); $label = new Label_Text();
$frame->add($label); $frame->add($label);
@ -331,20 +333,20 @@ class WidgetPlugin implements CallbackListener, Plugin {
// Player Quad / Label // Player Quad / Label
$label = new Label_Text(); $label = new Label_Text();
$frame->add($label); $frame->add($label);
$label->setPosition(-$width /2 + 9, -1.5, 0.2); $label->setPosition(-$width / 2 + 9, -1.5, 0.2);
$label->setAlign(Control::LEFT, Control::CENTER); $label->setAlign(Control::LEFT, Control::CENTER);
$label->setTextSize(1); $label->setTextSize(1);
$label->setScale(0.8); $label->setScale(0.8);
$label->setText($playerCount . " / " . $maxPlayers['NextValue']); $label->setText($playerCount . " / " . $maxPlayers['NextValue']);
$label->setTextColor("FFF"); $label->setTextColor("FFF");
$quad = new Quad_Icons128x128_1(); $quad = new Quad_Icons128x128_1();
$frame->add($quad); $frame->add($quad);
$quad->setSubStyle($quad::SUBSTYLE_Multiplayer); $quad->setSubStyle($quad::SUBSTYLE_Multiplayer);
$quad->setPosition(-$width /2 + 7, -1.6, 0.2); $quad->setPosition(-$width / 2 + 7, -1.6, 0.2);
$quad->setSize(2.5, 2.5); $quad->setSize(2.5, 2.5);
$quad->setHAlign(Control::CENTER); $quad->setHAlign(Control::CENTER);
// Spectator Quad / Label // Spectator Quad / Label
$label = new Label_Text(); $label = new Label_Text();
$frame->add($label); $frame->add($label);
@ -354,16 +356,16 @@ class WidgetPlugin implements CallbackListener, Plugin {
$label->setScale(0.8); $label->setScale(0.8);
$label->setText($spectatorCount . " / " . $maxSpectators['NextValue']); $label->setText($spectatorCount . " / " . $maxSpectators['NextValue']);
$label->setTextColor("FFF"); $label->setTextColor("FFF");
$quad = new Quad_Icons64x64_1(); $quad = new Quad_Icons64x64_1();
$frame->add($quad); $frame->add($quad);
$quad->setSubStyle($quad::SUBSTYLE_Camera); $quad->setSubStyle($quad::SUBSTYLE_Camera);
$quad->setPosition(0, -1.6, 0.2); $quad->setPosition(0, -1.6, 0.2);
$quad->setSize(3.3, 2.5); $quad->setSize(3.3, 2.5);
$quad->setHAlign(Control::CENTER); $quad->setHAlign(Control::CENTER);
// Favorite quad // Favorite quad
$quad = new Quad_Icons64x64_1(); $quad = new Quad_Icons64x64_1();
$quad = new Quad_Icons128x128_1(); $quad = new Quad_Icons128x128_1();
$frame->add($quad); $frame->add($quad);
// $quad->setSubStyle($quad::SUBSTYLE_StateFavourite); // $quad->setSubStyle($quad::SUBSTYLE_StateFavourite);
@ -372,7 +374,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
$quad->setSize(4, 4); $quad->setSize(4, 4);
$quad->setHAlign(Control::CENTER); $quad->setHAlign(Control::CENTER);
// $TODO add server to favorite // $TODO add server to favorite
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $manialinkText = $maniaLink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
@ -383,33 +385,34 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @param String $login * @param String $login
*/ */
public function displayMapWidget($login = false) { public function displayMapWidget($login = false)
{
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_POSX); $pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_POSX);
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_POSY); $pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_POSY);
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_WIDTH); $width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_WIDTH);
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_HEIGHT); $height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$maniaLink = new ManiaLink(self::MLID_MAPWIDGET); $maniaLink = new ManiaLink(self::MLID_MAPWIDGET);
$script = new Script(); $script = new Script();
$maniaLink->setScript($script); $maniaLink->setScript($script);
// mainframe // mainframe
$frame = new Frame(); $frame = new Frame();
$maniaLink->add($frame); $maniaLink->add($frame);
$frame->setSize($width, $height); $frame->setSize($width, $height);
$frame->setPosition($pos_x, $pos_y); $frame->setPosition($pos_x, $pos_y);
// Background Quad // Background Quad
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height); $backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$script->addMapInfoButton($backgroundQuad); $script->addMapInfoButton($backgroundQuad);
$map = $this->maniaControl->mapManager->getCurrentMap(); $map = $this->maniaControl->mapManager->getCurrentMap();
$label = new Label_Text(); $label = new Label_Text();
$frame->add($label); $frame->add($label);
$label->setY(1.5); $label->setY(1.5);
@ -419,30 +422,30 @@ class WidgetPlugin implements CallbackListener, Plugin {
$label->setTextSize(1.3); $label->setTextSize(1.3);
$label->setText($map->name); $label->setText($map->name);
$label->setTextColor("FFF"); $label->setTextColor("FFF");
$label = new Label_Text(); $label = new Label_Text();
$frame->add($label); $frame->add($label);
$label->setX(0); $label->setX(0);
$label->setY(-1.4); $label->setY(-1.4);
$label->setAlign(Control::CENTER, Control::CENTER); $label->setAlign(Control::CENTER, Control::CENTER);
$label->setZ(0.2); $label->setZ(0.2);
$label->setTextSize(1); $label->setTextSize(1);
$label->setScale(0.8); $label->setScale(0.8);
$label->setText($map->authorLogin); $label->setText($map->authorLogin);
$label->setTextColor("FFF"); $label->setTextColor("FFF");
if (isset($map->mx->pageurl)) { if (isset($map->mx->pageurl)) {
$quad = new Quad(); $quad = new Quad();
$frame->add($quad); $frame->add($quad);
$quad->setImage("http://wiki.maniaplanet.com/pool/images/b/bf/ManiaExchange_logo.png"); // TODO include image into $quad->setImage("http://wiki.maniaplanet.com/pool/images/b/bf/ManiaExchange_logo.png"); // TODO include image into
// maniacontrol // maniacontrol
$quad->setPosition(-$width / 2 + 4, -1.5, -0.5); $quad->setPosition(-$width / 2 + 4, -1.5, -0.5);
$quad->setSize(4, 4); $quad->setSize(4, 4);
$quad->setHAlign(Control::CENTER); $quad->setHAlign(Control::CENTER);
$quad->setUrl($map->mx->pageurl); $quad->setUrl($map->mx->pageurl);
} }
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $manialinkText = $maniaLink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
@ -453,7 +456,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @param $widgetId * @param $widgetId
*/ */
public function closeWidget($widgetId) { public function closeWidget($widgetId)
{
$emptyManialink = new ManiaLink($widgetId); $emptyManialink = new ManiaLink($widgetId);
$manialinkText = $emptyManialink->render()->saveXML(); $manialinkText = $emptyManialink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText); $this->maniaControl->manialinkManager->sendManialink($manialinkText);
@ -464,7 +468,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @param array $callback * @param array $callback
*/ */
public function handleOnInit(array $callback) { public function handleOnInit(array $callback)
{
// Display Map Widget // 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->displayMapWidget();
@ -482,7 +487,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @param array $callback * @param array $callback
*/ */
public function handleOnBeginMap(array $callback) { public function handleOnBeginMap(array $callback)
{
// Display Map Widget // 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->displayMapWidget();
@ -495,7 +501,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @param array $callback * @param array $callback
*/ */
public function handleOnEndMap(array $callback) { public function handleOnEndMap(array $callback)
{
// Display Map Widget // 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(); $this->displayNextMapWidget();
@ -507,7 +514,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @param array $callback * @param array $callback
*/ */
public function handlePlayerConnect(array $callback) { public function handlePlayerConnect(array $callback)
{
$player = $callback[1]; $player = $callback[1];
// Display Map Widget // 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)) {
@ -526,7 +534,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @param array $callback * @param array $callback
*/ */
public function handleEveryMinute(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(); $this->displayClockWidget();
} }
@ -537,7 +546,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @return int * @return int
*/ */
public static function getId() { public static function getId()
{
return self::PLUGIN_ID; return self::PLUGIN_ID;
} }
@ -546,7 +556,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @return string * @return string
*/ */
public static function getName() { public static function getName()
{
return self::PLUGIN_NAME; return self::PLUGIN_NAME;
} }
@ -555,7 +566,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @return float,, * @return float,,
*/ */
public static function getVersion() { public static function getVersion()
{
return self::PLUGIN_VERSION; return self::PLUGIN_VERSION;
} }
@ -564,7 +576,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @return string * @return string
*/ */
public static function getAuthor() { public static function getAuthor()
{
return self::PLUGIN_AUTHOR; return self::PLUGIN_AUTHOR;
} }
@ -573,7 +586,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
* *
* @return string * @return string
*/ */
public static function getDescription() { public static function getDescription()
{
return null; return null;
} }
} }