2013-12-29 22:52:07 +01:00
|
|
|
<?php
|
|
|
|
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;
|
2013-12-31 15:53:06 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2014-01-01 20:27:14 +01:00
|
|
|
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;
|
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
|
|
|
|
*
|
|
|
|
* @author kremsy
|
|
|
|
*/
|
2013-12-31 16:11:19 +01:00
|
|
|
class WidgetPlugin implements CallbackListener, Plugin {
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-29 22:52:07 +01:00
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
2014-01-01 20:39:10 +01:00
|
|
|
const PLUGIN_ID = 8;
|
2013-12-29 22:52:07 +01:00
|
|
|
const PLUGIN_VERSION = 0.1;
|
2014-01-01 20:39:10 +01:00
|
|
|
const PLUGIN_NAME = 'WidgetPlugin';
|
|
|
|
const PLUGIN_AUTHOR = 'kremsy';
|
|
|
|
|
2013-12-30 14:52:48 +01:00
|
|
|
// MapWidget Properties
|
2014-01-01 20:39:10 +01:00
|
|
|
const MLID_MAPWIDGET = 'WidgetPlugin.MapWidget';
|
2013-12-29 23:39:30 +01:00
|
|
|
const SETTING_MAP_WIDGET_ACTIVATED = 'Map-Widget Activated';
|
2014-01-01 20:39:10 +01:00
|
|
|
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
|
2014-01-01 20:39:10 +01:00
|
|
|
const MLID_CLOCKWIDGET = 'WidgetPlugin.ClockWidget';
|
2013-12-29 23:39:30 +01:00
|
|
|
const SETTING_CLOCK_WIDGET_ACTIVATED = 'Clock-Widget Activated';
|
2014-01-01 20:39:10 +01:00
|
|
|
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
|
2014-01-01 20:39:10 +01:00
|
|
|
const MLID_NEXTMAPWIDGET = 'WidgetPlugin.NextMapWidget';
|
2013-12-30 11:23:00 +01:00
|
|
|
const SETTING_NEXTMAP_WIDGET_ACTIVATED = 'Nextmap-Widget Activated';
|
2014-01-01 20:39:10 +01:00
|
|
|
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
|
2014-01-01 20:39:10 +01:00
|
|
|
const MLID_SERVERINFOWIDGET = 'WidgetPlugin.ServerInfoWidget';
|
2013-12-30 23:04:38 +01:00
|
|
|
const SETTING_SERVERINFO_WIDGET_ACTIVATED = 'ServerInfo-Widget Activated';
|
2014-01-01 20:39:10 +01:00
|
|
|
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
|
|
|
/**
|
2013-12-31 16:19:39 +01:00
|
|
|
*
|
2013-12-31 12:06:13 +01:00
|
|
|
* @var maniaControl $maniaControl
|
|
|
|
*/
|
2013-12-29 22:52:07 +01:00
|
|
|
private $maniaControl = null;
|
|
|
|
|
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;
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-30 14:52:48 +01:00
|
|
|
// Set CustomUI Setting
|
|
|
|
$this->maniaControl->manialinkManager->customUIManager->setChallengeInfoVisible(false);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-29 22:52:07 +01:00
|
|
|
// Register for callbacks
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
|
2013-12-30 11:23:00 +01:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'handleOnBeginMap');
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ENDMAP, $this, 'handleOnEndMap');
|
2013-12-29 22:52:07 +01:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerConnect');
|
2014-01-01 20:39:10 +01:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECTED, $this, 'handlePlayerDisconnect');
|
2013-12-29 23:39:30 +01:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_MINUTE, $this, 'handleEveryMinute');
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-29 23:01:51 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED, true);
|
2013-12-29 22:52:07 +01:00
|
|
|
$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.);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-30 23:04:38 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED, true);
|
2013-12-31 02:27:40 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_POSX, -160 + 17.5);
|
2013-12-30 23:04:38 +01:00
|
|
|
$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);
|
2013-12-30 23:04:38 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT, 9.);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_WIDTH, 40);
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT, 12.);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
|
|
|
$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);
|
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() {
|
2013-12-29 22:52:07 +01:00
|
|
|
$this->maniaControl->callbackManager->unregisterCallbackListener($this);
|
|
|
|
unset($this->maniaControl);
|
|
|
|
}
|
|
|
|
|
2013-12-30 23:04:38 +01:00
|
|
|
/**
|
2013-12-31 16:11:19 +01:00
|
|
|
* Handle ManiaControl OnInit callback
|
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
|
|
|
*/
|
2013-12-31 16:11:19 +01:00
|
|
|
public function handleOnInit(array $callback) {
|
|
|
|
// Display Map Widget
|
2014-01-01 20:39:10 +01:00
|
|
|
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
2013-12-31 16:11:19 +01:00
|
|
|
$this->displayMapWidget();
|
|
|
|
}
|
2014-01-01 20:39:10 +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-01 20:39:10 +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) {
|
2014-01-01 20:39:10 +01:00
|
|
|
$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();
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-31 16:11:19 +01:00
|
|
|
$maniaLink = new ManiaLink(self::MLID_MAPWIDGET);
|
2014-01-01 20:39:10 +01:00
|
|
|
$script = new Script();
|
2013-12-31 16:11:19 +01:00
|
|
|
$maniaLink->setScript($script);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
2013-12-31 16:11:19 +01:00
|
|
|
$script->addMapInfoButton($backgroundQuad);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-31 16:11:19 +01:00
|
|
|
$map = $this->maniaControl->mapManager->getCurrentMap();
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
2014-01-01 20:27:14 +01:00
|
|
|
$label->setText(Formatter::stripDirtyCodes($map->name));
|
2013-12-31 16:11:19 +01:00
|
|
|
$label->setTextColor("FFF");
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-31 16:11:19 +01:00
|
|
|
$label = new Label_Text();
|
|
|
|
$frame->add($label);
|
|
|
|
$label->setX(0);
|
|
|
|
$label->setY(-1.4);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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-01-01 20:39:10 +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);
|
|
|
|
}
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-30 14:52:48 +01:00
|
|
|
// Send manialink
|
2013-12-29 23:39:30 +01:00
|
|
|
$manialinkText = $maniaLink->render()->saveXML();
|
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
|
|
|
|
}
|
|
|
|
|
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-01-01 20:39:10 +01:00
|
|
|
$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();
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-31 16:11:19 +01:00
|
|
|
$maniaLink = new ManiaLink(self::MLID_CLOCKWIDGET);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-31 16:11:19 +01:00
|
|
|
$localTime = date("H:i", time());
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
2013-12-31 16:11:19 +01:00
|
|
|
$label->setText($localTime);
|
2013-12-30 11:23:00 +01:00
|
|
|
$label->setTextColor("FFF");
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-30 14:52:48 +01:00
|
|
|
// Send manialink
|
2013-12-30 11:23:00 +01:00
|
|
|
$manialinkText = $maniaLink->render()->saveXML();
|
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
|
|
|
|
}
|
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) {
|
2014-01-01 20:39:10 +01:00
|
|
|
$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();
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-30 23:04:38 +01:00
|
|
|
$maniaLink = new ManiaLink(self::MLID_SERVERINFOWIDGET);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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-01 20:39:10 +01:00
|
|
|
|
2014-01-16 18:49:52 +01:00
|
|
|
$maxPlayers = $this->maniaControl->client->getMaxPlayers();
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2014-01-16 18:49:52 +01:00
|
|
|
$maxSpectators = $this->maniaControl->client->getMaxSpectators();
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-31 12:06:13 +01:00
|
|
|
$serverName = $this->maniaControl->server->getName();
|
2014-01-01 20:39:10 +01:00
|
|
|
|
|
|
|
$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
|
|
|
/**
|
2013-12-31 16:19:39 +01:00
|
|
|
*
|
2013-12-31 12:06:13 +01:00
|
|
|
* @var Player $player
|
|
|
|
*/
|
2014-01-01 20:39:10 +01:00
|
|
|
foreach($players as $player) {
|
|
|
|
if($player->isSpectator) {
|
2013-12-30 23:53:42 +01:00
|
|
|
$spectatorCount++;
|
2014-01-01 20:39:10 +01:00
|
|
|
} 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
|
|
|
}
|
2014-01-01 20:39:10 +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);
|
2014-01-06 22:16:41 +01:00
|
|
|
$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");
|
2014-01-06 22:16:41 +01:00
|
|
|
//$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");
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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");
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-31 12:06:13 +01:00
|
|
|
// Favorite quad
|
2014-01-06 22:16:41 +01:00
|
|
|
$quad = new Quad_Icons64x64_1();
|
2013-12-31 02:27:40 +01:00
|
|
|
$frame->add($quad);
|
2014-01-06 22:16:41 +01:00
|
|
|
$quad->setSubStyle($quad::SUBSTYLE_StateFavourite);
|
2013-12-31 02:27:40 +01:00
|
|
|
$quad->setPosition($width / 2 - 4, -1.5, -0.5);
|
2014-01-06 22:16:41 +01:00
|
|
|
$quad->setSize(3, 3);
|
2013-12-31 02:27:40 +01:00
|
|
|
$quad->setHAlign(Control::CENTER);
|
2014-01-10 19:36:28 +01:00
|
|
|
$quad->setManialink('mcontrol?favorite=' . urlencode($this->maniaControl->server->login));
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-30 23:04:38 +01:00
|
|
|
// Send manialink
|
|
|
|
$manialinkText = $maniaLink->render()->saveXML();
|
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*
|
2013-12-31 16:11:19 +01:00
|
|
|
* @param array $callback
|
2013-12-29 22:52:07 +01:00
|
|
|
*/
|
2013-12-31 16:11:19 +01:00
|
|
|
public function handleOnBeginMap(array $callback) {
|
|
|
|
// Display Map Widget
|
2014-01-01 20:39:10 +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-01-01 20:39:10 +01:00
|
|
|
$manialinkText = $emptyManialink->render()->saveXML();
|
2013-12-31 16:11:19 +01:00
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle on End Map
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handleOnEndMap(array $callback) {
|
|
|
|
// Display Map Widget
|
2014-01-01 20:39:10 +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) {
|
2014-01-01 20:39:10 +01:00
|
|
|
$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();
|
2014-01-01 20:39:10 +01:00
|
|
|
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
|
|
|
|
2013-12-31 16:11:19 +01:00
|
|
|
$maniaLink = new ManiaLink(self::MLID_NEXTMAPWIDGET);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-31 16:11:19 +01:00
|
|
|
// Check if the Next Map is a queued Map
|
|
|
|
$queuedMap = $this->maniaControl->mapManager->mapQueue->getNextMap();
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-31 16:11:19 +01:00
|
|
|
/**
|
2013-12-31 16:19:39 +01:00
|
|
|
*
|
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
|
2014-01-01 20:39:10 +01:00
|
|
|
if($queuedMap == null) {
|
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;
|
2014-01-01 20:39:10 +01:00
|
|
|
} else {
|
2013-12-31 16:11:19 +01:00
|
|
|
$requester = $queuedMap[0];
|
2014-01-01 20:39:10 +01:00
|
|
|
$map = $queuedMap[1];
|
|
|
|
$name = $map->name;
|
|
|
|
$author = $map->authorLogin;
|
2013-12-31 16:11:19 +01:00
|
|
|
}
|
2014-01-01 20:39:10 +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);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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");
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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);
|
2014-01-01 20:39:10 +01:00
|
|
|
|
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");
|
2014-01-01 20:39:10 +01:00
|
|
|
|
|
|
|
if($requester != null) {
|
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
|
|
|
}
|
2014-01-01 20:39:10 +01:00
|
|
|
|
2013-12-30 14:52:48 +01:00
|
|
|
// Send manialink
|
2013-12-29 22:52:07 +01:00
|
|
|
$manialinkText = $maniaLink->render()->saveXML();
|
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle PlayerConnect callback
|
|
|
|
*
|
2013-12-31 12:06:13 +01:00
|
|
|
* @param array $callback
|
2013-12-29 22:52:07 +01:00
|
|
|
*/
|
2013-12-31 16:11:19 +01:00
|
|
|
public function handlePlayerConnect(array $callback) {
|
2013-12-29 23:01:51 +01:00
|
|
|
$player = $callback[1];
|
2013-12-30 14:52:48 +01:00
|
|
|
// Display Map Widget
|
2014-01-01 20:39:10 +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-01 20:39:10 +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-01 20:39:10 +01:00
|
|
|
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
|
|
|
|
$this->displayServerInfoWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle PlayerConnect callback
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handlePlayerDisconnect(array $callback) {
|
|
|
|
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-29 23:39:30 +01:00
|
|
|
/**
|
|
|
|
* Aktualize the clock widget every minute
|
2013-12-30 14:52:48 +01:00
|
|
|
*
|
2013-12-31 12:06:13 +01:00
|
|
|
* @param array $callback
|
2013-12-29 23:39:30 +01:00
|
|
|
*/
|
2013-12-31 16:11:19 +01:00
|
|
|
public function handleEveryMinute(array $callback) {
|
2014-01-01 20:39:10 +01:00
|
|
|
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
|
2013-12-29 23:39:30 +01:00
|
|
|
$this->displayClockWidget();
|
|
|
|
}
|
|
|
|
}
|
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() {
|
|
|
|
return null;
|
|
|
|
}
|
2013-12-29 22:52:07 +01:00
|
|
|
}
|