TrackManiaControl/application/plugins/WidgetPlugin.php

595 lines
20 KiB
PHP
Raw Normal View History

2013-12-29 22:52:07 +01:00
<?php
2014-04-27 16:22:12 +02:00
namespace MCTeam;
2013-12-29 22:52:07 +01:00
use FML\Controls\Control;
use FML\Controls\Frame;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
2013-12-30 23:53:42 +01:00
use FML\Controls\Quads\Quad_Icons128x128_1;
use FML\Controls\Quads\Quad_Icons64x64_1;
2013-12-29 22:52:07 +01:00
use FML\ManiaLink;
2013-12-31 15:53:06 +01:00
use FML\Script\Script;
2013-12-29 22:52:07 +01:00
use ManiaControl\Callbacks\CallbackListener;
2014-04-28 20:50:38 +02:00
use ManiaControl\Callbacks\Callbacks;
2014-01-31 00:04:40 +01:00
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Formatter;
2013-12-29 22:52:07 +01:00
use ManiaControl\ManiaControl;
2013-12-31 17:09:29 +01:00
use ManiaControl\Manialinks\IconManager;
2014-04-13 19:05:54 +02:00
use ManiaControl\Maps\Map;
use ManiaControl\Maps\MapManager;
2013-12-30 16:45:26 +01:00
use ManiaControl\Players\Player;
2013-12-29 22:52:07 +01:00
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
2013-12-30 16:45:26 +01:00
2013-12-30 13:10:26 +01:00
/**
* ManiaControl Widget Plugin
*
2014-04-13 19:05:54 +02:00
* @author steeffeen and kremsy
2014-04-13 12:00:08 +02:00
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
2014-04-13 19:05:54 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2013-12-30 13:10:26 +01:00
*/
2014-01-31 00:04:40 +01:00
class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
2013-12-29 22:52:07 +01:00
/**
* Constants
*/
2014-02-25 18:53:43 +01:00
const PLUGIN_ID = 1;
2013-12-29 22:52:07 +01:00
const PLUGIN_VERSION = 0.1;
const PLUGIN_NAME = 'WidgetPlugin';
const PLUGIN_AUTHOR = 'kremsy';
2013-12-30 14:52:48 +01:00
// MapWidget Properties
const MLID_MAPWIDGET = 'WidgetPlugin.MapWidget';
2013-12-29 23:39:30 +01:00
const SETTING_MAP_WIDGET_ACTIVATED = 'Map-Widget Activated';
const SETTING_MAP_WIDGET_POSX = 'Map-Widget-Position: X';
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';
2013-12-30 14:52:48 +01:00
// ClockWidget Properties
const MLID_CLOCKWIDGET = 'WidgetPlugin.ClockWidget';
2013-12-29 23:39:30 +01:00
const SETTING_CLOCK_WIDGET_ACTIVATED = 'Clock-Widget Activated';
const SETTING_CLOCK_WIDGET_POSX = 'Clock-Widget-Position: X';
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';
2013-12-30 14:52:48 +01:00
// NextMapWidget Properties
const MLID_NEXTMAPWIDGET = 'WidgetPlugin.NextMapWidget';
2013-12-30 11:23:00 +01:00
const SETTING_NEXTMAP_WIDGET_ACTIVATED = 'Nextmap-Widget Activated';
const SETTING_NEXTMAP_WIDGET_POSX = 'Nextmap-Widget-Position: X';
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';
2013-12-30 23:04:38 +01:00
// ServerInfoWidget Properties
const MLID_SERVERINFOWIDGET = 'WidgetPlugin.ServerInfoWidget';
2013-12-30 23:04:38 +01:00
const SETTING_SERVERINFO_WIDGET_ACTIVATED = 'ServerInfo-Widget Activated';
const SETTING_SERVERINFO_WIDGET_POSX = 'ServerInfo-Widget-Position: X';
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';
2013-12-31 17:09:29 +01:00
2013-12-29 22:52:07 +01:00
/**
2013-12-30 14:52:48 +01:00
* Private Properties
2013-12-29 22:52:07 +01:00
*/
2013-12-31 12:06:13 +01:00
/**
* @var maniaControl $maniaControl
*/
2013-12-29 22:52:07 +01:00
private $maniaControl = null;
2014-01-27 20:39:10 +01:00
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
2014-01-27 21:05:02 +01:00
//do nothing
2014-01-27 20:39:10 +01:00
}
2013-12-31 16:11:19 +01:00
2013-12-30 14:52:48 +01:00
/**
2013-12-29 22:52:07 +01:00
* Load the plugin
*
2013-12-31 12:06:13 +01:00
* @param ManiaControl $maniaControl
2013-12-29 22:52:07 +01:00
* @return bool
*/
2013-12-31 16:11:19 +01:00
public function load(ManiaControl $maniaControl) {
2013-12-29 22:52:07 +01:00
$this->maniaControl = $maniaControl;
2013-12-30 14:52:48 +01:00
// Set CustomUI Setting
$this->maniaControl->manialinkManager->customUIManager->setChallengeInfoVisible(false);
2013-12-29 22:52:07 +01:00
// Register for callbacks
2014-04-28 20:50:38 +02:00
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleOnBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleOnEndMap');
2014-02-19 10:43:37 +01:00
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
2014-01-31 00:04:40 +01:00
2013-12-29 23:01:51 +01:00
$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);
2013-12-29 22:52:07 +01:00
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_WIDTH, 40);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_HEIGHT, 9.);
2013-12-30 23:04:38 +01:00
$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);
2013-12-31 02:27:40 +01:00
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_WIDTH, 35);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT, 9.);
2013-12-30 11:23:00 +01:00
$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);
2013-12-30 11:23:00 +01:00
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_WIDTH, 40);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT, 12.);
2013-12-29 23:39:30 +01:00
$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);
2013-12-29 23:39:30 +01:00
$this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_WIDTH, 10);
2013-12-29 23:42:50 +01:00
$this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_HEIGHT, 5.5);
2014-01-18 10:26:32 +01:00
$this->displayWidgets();
2014-04-29 21:06:38 +02:00
2013-12-29 22:52:07 +01:00
return true;
}
/**
* Unload the plugin and its resources
*/
2013-12-31 16:11:19 +01:00
public function unload() {
2014-01-18 10:32:33 +01:00
$this->closeWidget(self::MLID_CLOCKWIDGET);
$this->closeWidget(self::MLID_SERVERINFOWIDGET);
$this->closeWidget(self::MLID_MAPWIDGET);
$this->closeWidget(self::MLID_NEXTMAPWIDGET);
2013-12-29 22:52:07 +01:00
$this->maniaControl->callbackManager->unregisterCallbackListener($this);
$this->maniaControl->timerManager->unregisterTimerListenings($this);
2013-12-29 22:52:07 +01:00
unset($this->maniaControl);
}
2013-12-30 23:04:38 +01:00
/**
2014-01-18 10:26:32 +01:00
* Displays the Widgets onLoad
2013-12-31 15:53:06 +01:00
*
2013-12-31 16:11:19 +01:00
* @param array $callback
2013-12-30 23:04:38 +01:00
*/
2014-01-18 10:26:32 +01:00
private function displayWidgets() {
2013-12-31 16:11:19 +01:00
// Display Map Widget
2014-01-31 00:04:40 +01:00
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
2014-04-29 21:06:38 +02:00
2013-12-31 16:11:19 +01:00
$this->displayMapWidget();
}
2014-01-31 00:04:40 +01:00
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
2013-12-31 16:11:19 +01:00
$this->displayClockWidget();
}
2014-01-31 00:04:40 +01:00
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
2013-12-31 16:11:19 +01:00
$this->displayServerInfoWidget();
}
}
/**
* Displays the Map Widget
*
* @param String $login
*/
public function displayMapWidget($login = false) {
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_POSX);
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_POSY);
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_WIDTH);
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
2013-12-29 23:39:30 +01:00
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
2013-12-31 16:11:19 +01:00
$maniaLink = new ManiaLink(self::MLID_MAPWIDGET);
$script = new Script();
2013-12-31 16:11:19 +01:00
$maniaLink->setScript($script);
2013-12-30 14:52:48 +01:00
// mainframe
2013-12-29 23:39:30 +01:00
$frame = new Frame();
$maniaLink->add($frame);
2013-12-30 14:52:48 +01:00
$frame->setSize($width, $height);
2013-12-29 23:39:30 +01:00
$frame->setPosition($pos_x, $pos_y);
2013-12-30 14:52:48 +01:00
// Background Quad
2013-12-29 23:39:30 +01:00
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
2013-12-30 14:52:48 +01:00
$backgroundQuad->setSize($width, $height);
2013-12-29 23:39:30 +01:00
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
2014-04-27 16:22:12 +02:00
$backgroundQuad->addMapInfoFeature();
2013-12-31 16:11:19 +01:00
$map = $this->maniaControl->mapManager->getCurrentMap();
2013-12-29 23:39:30 +01:00
$label = new Label_Text();
$frame->add($label);
$label->setY(1.5);
$label->setX(0);
2013-12-31 16:11:19 +01:00
$label->setAlign(Control::CENTER, Control::CENTER);
$label->setZ(0.2);
$label->setTextSize(1.3);
$label->setText(Formatter::stripDirtyCodes($map->name));
2013-12-31 16:11:19 +01:00
$label->setTextColor("FFF");
2014-03-02 18:56:55 +01:00
$label->setSize($width - 5, $height);
2013-12-31 16:11:19 +01:00
$label = new Label_Text();
$frame->add($label);
$label->setX(0);
$label->setY(-1.4);
2013-12-31 16:11:19 +01:00
$label->setAlign(Control::CENTER, Control::CENTER);
2013-12-29 23:39:30 +01:00
$label->setZ(0.2);
2013-12-29 23:42:50 +01:00
$label->setTextSize(1);
2013-12-31 16:11:19 +01:00
$label->setScale(0.8);
$label->setText($map->authorLogin);
2013-12-29 23:39:30 +01:00
$label->setTextColor("FFF");
2014-03-02 18:56:55 +01:00
$label->setSize($width - 5, $height);
2014-01-31 00:04:40 +01:00
if (isset($map->mx->pageurl)) {
2013-12-31 16:11:19 +01:00
$quad = new Quad();
$frame->add($quad);
2014-01-05 00:43:46 +01:00
$quad->setImageFocus($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER));
2013-12-31 17:09:29 +01:00
$quad->setImage($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON));
2013-12-31 16:11:19 +01:00
$quad->setPosition(-$width / 2 + 4, -1.5, -0.5);
$quad->setSize(4, 4);
$quad->setHAlign(Control::CENTER);
$quad->setUrl($map->mx->pageurl);
}
2013-12-30 14:52:48 +01:00
// Send manialink
2014-03-02 13:00:23 +01:00
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
2013-12-29 23:39:30 +01:00
}
2013-12-30 11:23:00 +01:00
/**
2013-12-31 16:11:19 +01:00
* Displays the Clock Widget
2013-12-30 14:52:48 +01:00
*
2013-12-31 12:06:13 +01:00
* @param bool $login
2013-12-30 11:23:00 +01:00
*/
2013-12-31 16:11:19 +01:00
public function displayClockWidget($login = false) {
2014-04-29 21:06:38 +02:00
$this->maniaControl->client->triggerModeScriptEventArray("Siege_SetProgressionLayerPosition", array("0.", "0.", "0."));
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_POSX);
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_POSY);
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_WIDTH);
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
2013-12-30 11:23:00 +01:00
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
2013-12-31 16:11:19 +01:00
$maniaLink = new ManiaLink(self::MLID_CLOCKWIDGET);
2013-12-30 14:52:48 +01:00
// mainframe
2013-12-30 11:23:00 +01:00
$frame = new Frame();
$maniaLink->add($frame);
2013-12-30 14:52:48 +01:00
$frame->setSize($width, $height);
2013-12-30 11:23:00 +01:00
$frame->setPosition($pos_x, $pos_y);
2013-12-30 14:52:48 +01:00
// Background Quad
2013-12-30 11:23:00 +01:00
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
2013-12-30 14:52:48 +01:00
$backgroundQuad->setSize($width, $height);
2013-12-30 11:23:00 +01:00
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
2013-12-30 11:23:00 +01:00
$label = new Label_Text();
$frame->add($label);
2013-12-31 16:11:19 +01:00
$label->setY(1.5);
2013-12-30 11:23:00 +01:00
$label->setX(0);
2013-12-31 16:11:19 +01:00
$label->setAlign(Control::CENTER, Control::TOP);
2013-12-30 11:23:00 +01:00
$label->setZ(0.2);
$label->setTextSize(1);
$label->setTextColor("FFF");
2014-04-29 20:32:21 +02:00
$label->addClockFeature(false);
2013-12-30 14:52:48 +01:00
// Send manialink
2014-03-02 13:00:23 +01:00
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
2013-12-30 11:23:00 +01:00
}
2013-12-29 23:39:30 +01:00
2013-12-30 23:04:38 +01:00
/**
2013-12-30 23:53:42 +01:00
* Displays the Server Info Widget
2013-12-30 23:04:38 +01:00
*
* @param String $login
*/
2013-12-31 16:11:19 +01:00
public function displayServerInfoWidget($login = false) {
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_POSX);
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_POSY);
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_WIDTH);
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
2013-12-30 23:04:38 +01:00
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
2013-12-30 23:04:38 +01:00
$maniaLink = new ManiaLink(self::MLID_SERVERINFOWIDGET);
2013-12-30 23:04:38 +01:00
// mainframe
$frame = new Frame();
$maniaLink->add($frame);
$frame->setSize($width, $height);
$frame->setPosition($pos_x, $pos_y);
2013-12-30 23:04:38 +01:00
// Background Quad
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
2014-01-16 18:49:52 +01:00
$maxPlayers = $this->maniaControl->client->getMaxPlayers();
2014-01-16 18:49:52 +01:00
$maxSpectators = $this->maniaControl->client->getMaxSpectators();
2014-02-15 13:04:31 +01:00
$serverName = $this->maniaControl->client->getServerName();
$players = $this->maniaControl->playerManager->getPlayers();
$playerCount = 0;
2013-12-30 23:53:42 +01:00
$spectatorCount = 0;
2013-12-31 12:06:13 +01:00
/**
* @var Player $player
*/
foreach($players as $player) {
2014-01-31 00:04:40 +01:00
if ($player->isSpectator) {
2013-12-30 23:53:42 +01:00
$spectatorCount++;
} else {
2013-12-30 23:53:42 +01:00
$playerCount++;
2013-12-31 16:11:19 +01:00
}
2013-12-30 23:53:42 +01:00
}
2013-12-30 23:04:38 +01:00
$label = new Label_Text();
$frame->add($label);
2013-12-30 23:53:42 +01:00
$label->setPosition(0, 1.5, 0.2);
2013-12-30 23:04:38 +01:00
$label->setAlign(Control::CENTER, Control::CENTER);
$label->setSize($width - 5, $height);
2013-12-30 23:04:38 +01:00
$label->setTextSize(1.3);
2014-01-03 20:29:42 +01:00
$label->setText(Formatter::stripDirtyCodes($serverName));
2013-12-30 23:04:38 +01:00
$label->setTextColor("FFF");
//$label->setAutoNewLine(true);
2013-12-31 14:09:04 +01:00
// Player Quad / Label
2013-12-30 23:53:42 +01:00
$label = new Label_Text();
$frame->add($label);
2013-12-31 15:53:06 +01:00
$label->setPosition(-$width / 2 + 9, -1.5, 0.2);
2013-12-31 14:09:04 +01:00
$label->setAlign(Control::LEFT, Control::CENTER);
2013-12-30 23:53:42 +01:00
$label->setTextSize(1);
$label->setScale(0.8);
$label->setText($playerCount . " / " . $maxPlayers['NextValue']);
$label->setTextColor("FFF");
2013-12-30 23:53:42 +01:00
$quad = new Quad_Icons128x128_1();
$frame->add($quad);
$quad->setSubStyle($quad::SUBSTYLE_Multiplayer);
2013-12-31 15:53:06 +01:00
$quad->setPosition(-$width / 2 + 7, -1.6, 0.2);
2013-12-30 23:53:42 +01:00
$quad->setSize(2.5, 2.5);
$quad->setHAlign(Control::CENTER);
2013-12-31 12:06:13 +01:00
// Spectator Quad / Label
2013-12-30 23:53:42 +01:00
$label = new Label_Text();
$frame->add($label);
2013-12-31 14:09:04 +01:00
$label->setPosition(2, -1.5, 0.2);
$label->setAlign(Control::LEFT, Control::CENTER);
2013-12-30 23:53:42 +01:00
$label->setTextSize(1);
$label->setScale(0.8);
$label->setText($spectatorCount . " / " . $maxSpectators['NextValue']);
$label->setTextColor("FFF");
2013-12-30 23:53:42 +01:00
$quad = new Quad_Icons64x64_1();
$frame->add($quad);
$quad->setSubStyle($quad::SUBSTYLE_Camera);
2013-12-31 14:09:04 +01:00
$quad->setPosition(0, -1.6, 0.2);
2013-12-31 12:06:13 +01:00
$quad->setSize(3.3, 2.5);
2013-12-30 23:53:42 +01:00
$quad->setHAlign(Control::CENTER);
2013-12-31 12:06:13 +01:00
// Favorite quad
$quad = new Quad_Icons64x64_1();
2013-12-31 02:27:40 +01:00
$frame->add($quad);
$quad->setSubStyle($quad::SUBSTYLE_StateFavourite);
2013-12-31 02:27:40 +01:00
$quad->setPosition($width / 2 - 4, -1.5, -0.5);
$quad->setSize(3, 3);
2013-12-31 02:27:40 +01:00
$quad->setHAlign(Control::CENTER);
$quad->setManialink('mcontrol?favorite=' . urlencode($this->maniaControl->server->login));
2013-12-30 23:04:38 +01:00
// Send manialink
2014-03-02 13:00:23 +01:00
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
2013-12-30 23:04:38 +01:00
}
2013-12-29 22:52:07 +01:00
/**
2013-12-31 16:11:19 +01:00
* Handle on Begin Map
2013-12-30 14:52:48 +01:00
*
* @param Map $map
2013-12-29 22:52:07 +01:00
*/
public function handleOnBeginMap(Map $map) {
2013-12-31 16:11:19 +01:00
// Display Map Widget
2014-01-31 00:04:40 +01:00
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
2013-12-31 16:11:19 +01:00
$this->displayMapWidget();
}
$this->closeWidget(self::MLID_NEXTMAPWIDGET);
}
/**
* Closes a Widget
*
* @param $widgetId
*/
public function closeWidget($widgetId) {
$emptyManialink = new ManiaLink($widgetId);
2014-03-02 13:00:23 +01:00
$this->maniaControl->manialinkManager->sendManialink($emptyManialink);
2013-12-31 16:11:19 +01:00
}
/**
* Handle on End Map
*
* @param Map $map
2013-12-31 16:11:19 +01:00
*/
public function handleOnEndMap(Map $map) {
2013-12-31 16:11:19 +01:00
// Display Map Widget
2014-01-31 00:04:40 +01:00
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED)) {
2013-12-31 16:11:19 +01:00
$this->displayNextMapWidget();
}
}
/**
* Displays the Next Map (Only at the end of the Map)
*
* @param bool $login
*/
public function displayNextMapWidget($login = false) {
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_POSX);
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_POSY);
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_WIDTH);
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
2013-12-29 22:52:07 +01:00
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
2013-12-31 16:11:19 +01:00
$maniaLink = new ManiaLink(self::MLID_NEXTMAPWIDGET);
2013-12-30 14:52:48 +01:00
// mainframe
2013-12-29 22:52:07 +01:00
$frame = new Frame();
$maniaLink->add($frame);
2013-12-30 14:52:48 +01:00
$frame->setSize($width, $height);
2013-12-29 22:52:07 +01:00
$frame->setPosition($pos_x, $pos_y);
2013-12-30 14:52:48 +01:00
// Background Quad
2013-12-29 22:52:07 +01:00
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
2013-12-30 14:52:48 +01:00
$backgroundQuad->setSize($width, $height);
2013-12-29 22:52:07 +01:00
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
2013-12-31 16:11:19 +01:00
// Check if the Next Map is a queued Map
$queuedMap = $this->maniaControl->mapManager->mapQueue->getNextMap();
2013-12-31 16:11:19 +01:00
/**
* @var Player $requester
*/
$requester = null;
// if the nextmap is not a queued map, get it from map info
if (!$queuedMap) {
2014-01-16 18:49:52 +01:00
$map = $this->maniaControl->client->getNextMapInfo();
2014-01-16 21:30:11 +01:00
$name = Formatter::stripDirtyCodes($map->name);
2014-01-16 18:49:52 +01:00
$author = $map->author;
} else {
2013-12-31 16:11:19 +01:00
$requester = $queuedMap[0];
$map = $queuedMap[1];
2014-04-14 19:30:51 +02:00
$name = $map->name;
$author = $map->authorLogin;
2013-12-31 16:11:19 +01:00
}
2013-12-29 22:52:07 +01:00
$label = new Label_Text();
$frame->add($label);
2013-12-31 16:11:19 +01:00
$label->setY($height / 2 - 2.3);
$label->setX(0);
$label->setAlign(Control::CENTER, Control::CENTER);
$label->setZ(0.2);
$label->setTextSize(1);
$label->setText("Next Map");
$label->setTextColor("FFF");
$label->setStyle($labelStyle);
2013-12-31 16:11:19 +01:00
$label = new Label_Text();
$frame->add($label);
$label->setY($height / 2 - 5.5);
2013-12-29 22:52:07 +01:00
$label->setX(0);
2013-12-30 14:52:48 +01:00
$label->setAlign(Control::CENTER, Control::CENTER);
2013-12-29 22:52:07 +01:00
$label->setZ(0.2);
$label->setTextSize(1.3);
2013-12-31 16:11:19 +01:00
$label->setText($name);
2013-12-29 22:52:07 +01:00
$label->setTextColor("FFF");
2013-12-29 22:52:07 +01:00
$label = new Label_Text();
$frame->add($label);
$label->setX(0);
2013-12-31 16:11:19 +01:00
$label->setY(-$height / 2 + 4);
2013-12-30 14:52:48 +01:00
$label->setAlign(Control::CENTER, Control::CENTER);
2013-12-29 22:52:07 +01:00
$label->setZ(0.2);
$label->setTextSize(1);
2013-12-29 23:01:51 +01:00
$label->setScale(0.8);
2013-12-31 16:11:19 +01:00
$label->setText($author);
2013-12-29 22:52:07 +01:00
$label->setTextColor("FFF");
if ($requester) {
2013-12-31 16:11:19 +01:00
$label = new Label_Text();
$frame->add($label);
$label->setX(0);
$label->setY(-$height / 2 + 2);
$label->setAlign(Control::CENTER, Control::CENTER);
$label->setZ(0.2);
$label->setTextSize(1);
$label->setScale(0.7);
$label->setText($author);
$label->setTextColor("F80");
$label->setText("Requested by " . $requester->nickname);
2013-12-31 00:32:50 +01:00
}
2013-12-30 14:52:48 +01:00
// Send manialink
2014-03-02 13:00:23 +01:00
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
2013-12-29 22:52:07 +01:00
}
/**
* Handle PlayerConnect callback
*
* @param Player $player
2013-12-29 22:52:07 +01:00
*/
public function handlePlayerConnect(Player $player) {
2013-12-30 14:52:48 +01:00
// Display Map Widget
2014-01-31 00:04:40 +01:00
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
2013-12-29 23:01:51 +01:00
$this->displayMapWidget($player->login);
}
2014-01-31 00:04:40 +01:00
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
2013-12-30 23:04:38 +01:00
$this->displayClockWidget($player->login);
}
2014-01-31 00:04:40 +01:00
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
$this->displayServerInfoWidget();
}
}
/**
* Handle PlayerConnect callback
*
* @param Player $player
*/
public function handlePlayerDisconnect(Player $player) {
2014-01-31 00:04:40 +01:00
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
$this->displayServerInfoWidget();
2013-12-29 23:39:30 +01:00
}
2013-12-29 22:52:07 +01:00
}
2013-12-31 16:25:59 +01:00
/**
* Get plugin id
*
* @return int
*/
public static function getId() {
return self::PLUGIN_ID;
}
/**
* Get Plugin Name
*
* @return string
*/
public static function getName() {
return self::PLUGIN_NAME;
}
/**
* Get Plugin Version
*
* @return float,,
*/
public static function getVersion() {
return self::PLUGIN_VERSION;
}
/**
* Get Plugin Author
*
* @return string
*/
public static function getAuthor() {
return self::PLUGIN_AUTHOR;
}
/**
* Get Plugin Description
*
* @return string
*/
public static function getDescription() {
2014-01-18 10:32:33 +01:00
return 'Plugin offers some Widgets';
2013-12-31 16:25:59 +01:00
}
2013-12-29 22:52:07 +01:00
}