2014-05-03 21:57:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MCTeam;
|
|
|
|
|
|
|
|
use FML\Controls\Frame;
|
|
|
|
use FML\Controls\Labels\Label_Text;
|
|
|
|
use FML\Controls\Quad;
|
|
|
|
use FML\Controls\Quads\Quad_Icons128x128_1;
|
|
|
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
|
|
|
use FML\ManiaLink;
|
|
|
|
use FML\Script\Script;
|
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\Callbacks;
|
2017-05-08 20:26:28 +02:00
|
|
|
use ManiaControl\Callbacks\Structures\Common\UIPropertiesBaseStructure;
|
2014-05-03 21:57:38 +02:00
|
|
|
use ManiaControl\Callbacks\TimerListener;
|
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use ManiaControl\Manialinks\IconManager;
|
|
|
|
use ManiaControl\Players\Player;
|
|
|
|
use ManiaControl\Players\PlayerManager;
|
|
|
|
use ManiaControl\Plugins\Plugin;
|
2014-07-04 18:48:39 +02:00
|
|
|
use ManiaControl\Settings\Setting;
|
|
|
|
use ManiaControl\Settings\SettingManager;
|
2014-05-18 21:59:21 +02:00
|
|
|
use ManiaControl\Utils\Formatter;
|
2014-10-24 19:48:33 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\FaultException;
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ManiaControl Widget Plugin
|
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2017-02-04 11:49:23 +01:00
|
|
|
* @copyright 2014-2017 ManiaControl Team
|
2014-05-03 21:57:38 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
|
|
|
*/
|
|
|
|
class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
|
2014-05-03 23:49:58 +02:00
|
|
|
/*
|
2014-05-03 21:57:38 +02:00
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
const PLUGIN_ID = 1;
|
|
|
|
const PLUGIN_VERSION = 0.1;
|
|
|
|
const PLUGIN_NAME = 'WidgetPlugin';
|
|
|
|
const PLUGIN_AUTHOR = 'kremsy';
|
|
|
|
|
|
|
|
// MapWidget Properties
|
2014-06-17 23:35:56 +02:00
|
|
|
const MLID_MAP_WIDGET = 'WidgetPlugin.MapWidget';
|
2014-05-03 21:57:38 +02: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';
|
|
|
|
|
|
|
|
// ClockWidget Properties
|
2014-06-17 23:35:56 +02:00
|
|
|
const MLID_CLOCK_WIDGET = 'WidgetPlugin.ClockWidget';
|
2014-05-03 21:57:38 +02: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';
|
|
|
|
|
|
|
|
// NextMapWidget Properties
|
2014-06-17 23:35:56 +02:00
|
|
|
const MLID_NEXTMAP_WIDGET = 'WidgetPlugin.NextMapWidget';
|
2014-05-03 21:57:38 +02: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';
|
|
|
|
|
|
|
|
// ServerInfoWidget Properties
|
2014-06-17 23:35:56 +02:00
|
|
|
const MLID_SERVERINFO_WIDGET = 'WidgetPlugin.ServerInfoWidget';
|
2014-05-03 21:57:38 +02: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';
|
|
|
|
|
2014-05-03 23:49:58 +02:00
|
|
|
/*
|
2014-08-02 22:31:46 +02:00
|
|
|
* Private properties
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-05-03 23:49:58 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2017-05-10 14:22:51 +02:00
|
|
|
private $maniaControl = null;
|
|
|
|
private $lastWidgetUpdateTime = 0;
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::prepare()
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public static function prepare(ManiaControl $maniaControl) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::getId()
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public static function getId() {
|
|
|
|
return self::PLUGIN_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::getName()
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public static function getName() {
|
|
|
|
return self::PLUGIN_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public static function getVersion() {
|
|
|
|
return self::PLUGIN_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public static function getAuthor() {
|
|
|
|
return self::PLUGIN_AUTHOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public static function getDescription() {
|
|
|
|
return 'Plugin offers some Widgets';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::load()
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public function load(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Callbacks
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleOnBeginMap');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleOnEndMap');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updateWidgets');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'updateWidgets');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings');
|
2014-08-03 01:34:18 +02:00
|
|
|
|
|
|
|
// Settings
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED, true);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_POSX, 160 - 20);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_POSY, 90 - 4.5);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_WIDTH, 40);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_HEIGHT, 9.);
|
|
|
|
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED, true);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_POSX, -160 + 17.5);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_POSY, 90 - 4.5);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_WIDTH, 35);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT, 9.);
|
|
|
|
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED, true);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_POSX, 160 - 20);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_POSY, 90 - 25.5);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_WIDTH, 40);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT, 12.);
|
|
|
|
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED, true);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_POSX, 160 - 5);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_POSY, 90 - 11);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_WIDTH, 10);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_HEIGHT, 5.5);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
$this->displayWidgets();
|
|
|
|
|
2017-05-08 20:26:28 +02:00
|
|
|
|
|
|
|
// Set CustomUI Setting
|
|
|
|
$this->maniaControl->getManialinkManager()->getCustomUIManager()->setChallengeInfoVisible(false);
|
|
|
|
|
|
|
|
//TrackMania
|
|
|
|
$this->maniaControl->getModeScriptEventManager()->getTrackmaniaUIProperties()->setCallable(function (UIPropertiesBaseStructure $structure) {
|
|
|
|
$xml = str_replace("<map_info visible=\"true\"", "<map_info visible=\"false\"", $structure->getUiPropertiesXML());
|
|
|
|
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaUIProperties($xml);
|
|
|
|
});
|
|
|
|
|
2014-05-03 21:57:38 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the Widgets
|
|
|
|
*/
|
|
|
|
private function displayWidgets() {
|
|
|
|
// Display Map Widget
|
2017-03-25 19:15:50 +01:00
|
|
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getClient()->triggerModeScriptEvent("Siege_SetProgressionLayerPosition", array("160.", "-67.", "0."));
|
2014-05-03 21:57:38 +02:00
|
|
|
$this->displayMapWidget();
|
|
|
|
}
|
2017-03-25 19:15:50 +01:00
|
|
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
|
2014-05-03 21:57:38 +02:00
|
|
|
$this->displayClockWidget();
|
|
|
|
}
|
2017-03-25 19:15:50 +01:00
|
|
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
|
2014-05-03 21:57:38 +02:00
|
|
|
$this->displayServerInfoWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the Map Widget
|
|
|
|
*
|
|
|
|
* @param string $login
|
|
|
|
*/
|
|
|
|
public function displayMapWidget($login = null) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_POSX);
|
|
|
|
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_POSY);
|
|
|
|
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_WIDTH);
|
|
|
|
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_HEIGHT);
|
|
|
|
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-06-17 23:35:56 +02:00
|
|
|
$maniaLink = new ManiaLink(self::MLID_MAP_WIDGET);
|
2014-05-03 21:57:38 +02:00
|
|
|
$script = new Script();
|
|
|
|
$maniaLink->setScript($script);
|
|
|
|
|
|
|
|
// mainframe
|
|
|
|
$frame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$maniaLink->addChild($frame);
|
2014-05-03 21:57:38 +02:00
|
|
|
$frame->setSize($width, $height);
|
2014-06-14 15:48:27 +02:00
|
|
|
$frame->setPosition($posX, $posY);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
// Background Quad
|
|
|
|
$backgroundQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($backgroundQuad);
|
2014-05-03 21:57:38 +02:00
|
|
|
$backgroundQuad->setSize($width, $height);
|
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
2014-08-27 11:32:04 +02:00
|
|
|
//$backgroundQuad->addMapInfoFeature();
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-08-13 11:14:29 +02:00
|
|
|
$map = $this->maniaControl->getMapManager()->getCurrentMap();
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-05-18 21:59:21 +02:00
|
|
|
$label->setPosition(0, 1.5, 0.2);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setTextSize(1.3);
|
|
|
|
$label->setText(Formatter::stripDirtyCodes($map->name));
|
2014-08-03 01:34:18 +02:00
|
|
|
$label->setTextColor('fff');
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setSize($width - 5, $height);
|
|
|
|
|
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-05-18 21:59:21 +02:00
|
|
|
$label->setPosition(0, -1.4, 0.2);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setTextSize(1);
|
|
|
|
$label->setScale(0.8);
|
|
|
|
$label->setText($map->authorLogin);
|
2014-08-03 01:34:18 +02:00
|
|
|
$label->setTextColor('fff');
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setSize($width - 5, $height);
|
|
|
|
|
|
|
|
if (isset($map->mx->pageurl)) {
|
|
|
|
$quad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($quad);
|
|
|
|
$quad->setImageFocusUrl($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_MOVER));
|
|
|
|
$quad->setImageUrl($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON));
|
2014-05-03 21:57:38 +02:00
|
|
|
$quad->setPosition(-$width / 2 + 4, -1.5, -0.5);
|
|
|
|
$quad->setSize(4, 4);
|
|
|
|
$quad->setUrl($map->mx->pageurl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send manialink
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the Clock Widget
|
|
|
|
*
|
|
|
|
* @param bool $login
|
|
|
|
*/
|
|
|
|
public function displayClockWidget($login = false) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_POSX);
|
|
|
|
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_POSY);
|
|
|
|
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_WIDTH);
|
|
|
|
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_HEIGHT);
|
|
|
|
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-06-17 23:35:56 +02:00
|
|
|
$maniaLink = new ManiaLink(self::MLID_CLOCK_WIDGET);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
// mainframe
|
|
|
|
$frame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$maniaLink->addChild($frame);
|
2014-05-03 21:57:38 +02:00
|
|
|
$frame->setSize($width, $height);
|
2014-06-14 15:48:27 +02:00
|
|
|
$frame->setPosition($posX, $posY);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
// Background Quad
|
|
|
|
$backgroundQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($backgroundQuad);
|
2014-05-03 21:57:38 +02:00
|
|
|
$backgroundQuad->setSize($width, $height);
|
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
|
|
|
|
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-05-18 21:59:21 +02:00
|
|
|
$label->setPosition(0, 1.5, 0.2);
|
2017-03-25 19:15:50 +01:00
|
|
|
$label->setVerticalAlign($label::TOP);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setTextSize(1);
|
2014-06-22 19:02:18 +02:00
|
|
|
$label->setTextColor('fff');
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->addClockFeature(false);
|
|
|
|
|
|
|
|
// Send manialink
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the Server Info Widget
|
|
|
|
*
|
|
|
|
* @param string $login
|
|
|
|
*/
|
|
|
|
public function displayServerInfoWidget($login = null) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_POSX);
|
|
|
|
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_POSY);
|
|
|
|
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_WIDTH);
|
|
|
|
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT);
|
|
|
|
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-06-17 23:35:56 +02:00
|
|
|
$maniaLink = new ManiaLink(self::MLID_SERVERINFO_WIDGET);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
// mainframe
|
|
|
|
$frame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$maniaLink->addChild($frame);
|
2014-05-03 21:57:38 +02:00
|
|
|
$frame->setSize($width, $height);
|
2014-06-14 15:48:27 +02:00
|
|
|
$frame->setPosition($posX, $posY);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
// Background Quad
|
|
|
|
$backgroundQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($backgroundQuad);
|
2014-05-03 21:57:38 +02:00
|
|
|
$backgroundQuad->setSize($width, $height);
|
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
|
|
|
|
2014-08-13 11:14:29 +02:00
|
|
|
$serverName = $this->maniaControl->getClient()->getServerName();
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-08-13 11:14:29 +02:00
|
|
|
$playerCount = $this->maniaControl->getPlayerManager()->getPlayerCount(true);
|
|
|
|
$maxPlayers = $this->maniaControl->getClient()->getMaxPlayers();
|
2014-05-27 22:44:22 +02:00
|
|
|
|
2014-08-13 11:14:29 +02:00
|
|
|
$spectatorCount = $this->maniaControl->getPlayerManager()->getSpectatorCount();
|
|
|
|
$maxSpectators = $this->maniaControl->getClient()->getMaxSpectators();
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setPosition(0, 1.5, 0.2);
|
|
|
|
$label->setSize($width - 5, $height);
|
|
|
|
$label->setTextSize(1.3);
|
|
|
|
$label->setText(Formatter::stripDirtyCodes($serverName));
|
2014-06-22 19:02:18 +02:00
|
|
|
$label->setTextColor('fff');
|
2014-05-03 21:57:38 +02:00
|
|
|
//$label->setAutoNewLine(true);
|
2014-06-22 19:02:18 +02:00
|
|
|
|
2014-05-03 21:57:38 +02:00
|
|
|
// Player Quad / Label
|
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setPosition(-$width / 2 + 9, -1.5, 0.2);
|
2017-03-25 19:15:50 +01:00
|
|
|
$label->setHorizontalAlign($label::LEFT);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setTextSize(1);
|
|
|
|
$label->setScale(0.8);
|
|
|
|
$label->setText($playerCount . " / " . $maxPlayers['NextValue']);
|
2014-06-22 19:02:18 +02:00
|
|
|
$label->setTextColor('fff');
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
$quad = new Quad_Icons128x128_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($quad);
|
2014-05-03 21:57:38 +02:00
|
|
|
$quad->setSubStyle($quad::SUBSTYLE_Multiplayer);
|
|
|
|
$quad->setPosition(-$width / 2 + 7, -1.6, 0.2);
|
|
|
|
$quad->setSize(2.5, 2.5);
|
|
|
|
|
|
|
|
// Spectator Quad / Label
|
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setPosition(2, -1.5, 0.2);
|
2017-03-25 19:15:50 +01:00
|
|
|
$label->setHorizontalAlign($label::LEFT);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setTextSize(1);
|
|
|
|
$label->setScale(0.8);
|
|
|
|
$label->setText($spectatorCount . " / " . $maxSpectators['NextValue']);
|
2014-06-22 19:02:18 +02:00
|
|
|
$label->setTextColor('fff');
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
$quad = new Quad_Icons64x64_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($quad);
|
2014-05-03 21:57:38 +02:00
|
|
|
$quad->setSubStyle($quad::SUBSTYLE_Camera);
|
|
|
|
$quad->setPosition(0, -1.6, 0.2);
|
|
|
|
$quad->setSize(3.3, 2.5);
|
|
|
|
|
|
|
|
// Favorite quad
|
|
|
|
$quad = new Quad_Icons64x64_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($quad);
|
2014-05-03 21:57:38 +02:00
|
|
|
$quad->setSubStyle($quad::SUBSTYLE_StateFavourite);
|
|
|
|
$quad->setPosition($width / 2 - 4, -1.5, -0.5);
|
|
|
|
$quad->setSize(3, 3);
|
2014-08-03 01:34:18 +02:00
|
|
|
$quad->setManialink('maniacontrol?favorite=' . urlencode($this->maniaControl->getServer()->login));
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
// Send manialink
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public function unload() {
|
|
|
|
//Restore Siege Progression Layer
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getClient()->triggerModeScriptEvent('Siege_SetProgressionLayerPosition', array("160.", "90.", "0."));
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-06-17 23:35:56 +02:00
|
|
|
$this->closeWidget(self::MLID_CLOCK_WIDGET);
|
|
|
|
$this->closeWidget(self::MLID_SERVERINFO_WIDGET);
|
|
|
|
$this->closeWidget(self::MLID_MAP_WIDGET);
|
|
|
|
$this->closeWidget(self::MLID_NEXTMAP_WIDGET);
|
2017-05-08 20:26:28 +02:00
|
|
|
|
|
|
|
// Set CustomUI Setting
|
|
|
|
$this->maniaControl->getManialinkManager()->getCustomUIManager()->setChallengeInfoVisible(true);
|
|
|
|
|
|
|
|
//TrackMania
|
|
|
|
$this->maniaControl->getModeScriptEventManager()->getTrackmaniaUIProperties()->setCallable(function (UIPropertiesBaseStructure $structure) {
|
|
|
|
$xml = str_replace("<map_info visible=\"false\"", "<map_info visible=\"true\"", $structure->getUiPropertiesXML());
|
|
|
|
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaUIProperties($xml);
|
|
|
|
});
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* Close a Widget
|
2014-05-03 21:57:38 +02:00
|
|
|
*
|
2014-05-03 23:49:58 +02:00
|
|
|
* @param string $widgetId
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public function closeWidget($widgetId) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->hideManialink($widgetId);
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-14 15:48:27 +02:00
|
|
|
* Handle Begin Map Callback
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-06-14 15:48:27 +02:00
|
|
|
public function handleOnBeginMap() {
|
2017-03-25 19:15:50 +01:00
|
|
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
2014-05-03 21:57:38 +02:00
|
|
|
$this->displayMapWidget();
|
|
|
|
}
|
2014-06-17 23:35:56 +02:00
|
|
|
$this->closeWidget(self::MLID_NEXTMAP_WIDGET);
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-14 15:48:27 +02:00
|
|
|
* Handle End Map Callback
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-06-14 15:48:27 +02:00
|
|
|
public function handleOnEndMap() {
|
2017-03-25 19:15:50 +01:00
|
|
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED)) {
|
2014-05-03 21:57:38 +02:00
|
|
|
$this->displayNextMapWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-13 16:03:26 +02:00
|
|
|
* Display the Next Map (Only at the end of the Map)
|
2014-05-03 21:57:38 +02:00
|
|
|
*
|
2014-05-13 16:03:26 +02:00
|
|
|
* @param string $login
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-05-13 16:03:26 +02:00
|
|
|
public function displayNextMapWidget($login = null) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_POSX);
|
|
|
|
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_POSY);
|
|
|
|
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_WIDTH);
|
|
|
|
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT);
|
|
|
|
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
|
|
|
|
$labelStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultLabelStyle();
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-06-17 23:35:56 +02:00
|
|
|
$maniaLink = new ManiaLink(self::MLID_NEXTMAP_WIDGET);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
// mainframe
|
|
|
|
$frame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$maniaLink->addChild($frame);
|
2014-05-03 21:57:38 +02:00
|
|
|
$frame->setSize($width, $height);
|
2014-06-14 15:48:27 +02:00
|
|
|
$frame->setPosition($posX, $posY);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
// Background Quad
|
|
|
|
$backgroundQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($backgroundQuad);
|
2014-05-03 21:57:38 +02:00
|
|
|
$backgroundQuad->setSize($width, $height);
|
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
|
|
|
|
|
|
|
// Check if the Next Map is a queued Map
|
2014-08-13 11:14:29 +02:00
|
|
|
$queuedMap = $this->maniaControl->getMapManager()->getMapQueue()->getNextMap();
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-10-24 19:48:33 +02:00
|
|
|
/** @var Player $requester */
|
2014-05-03 21:57:38 +02:00
|
|
|
$requester = null;
|
2014-10-24 19:48:33 +02:00
|
|
|
$map = null;
|
|
|
|
$name = '-';
|
|
|
|
$author = '-';
|
2014-05-03 21:57:38 +02:00
|
|
|
// if the nextmap is not a queued map, get it from map info
|
2014-10-24 19:48:33 +02:00
|
|
|
if ($queuedMap) {
|
2014-05-03 21:57:38 +02:00
|
|
|
$requester = $queuedMap[0];
|
|
|
|
$map = $queuedMap[1];
|
2014-10-25 22:02:36 +02:00
|
|
|
$name = $map->name;
|
|
|
|
$author = $map->authorLogin;
|
2014-10-24 19:48:33 +02:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
$map = $this->maniaControl->getClient()->getNextMapInfo();
|
2014-10-25 22:02:36 +02:00
|
|
|
$name = Formatter::stripDirtyCodes($map->name);
|
|
|
|
$author = $map->author;
|
2014-10-24 19:48:33 +02:00
|
|
|
} catch (FaultException $exception) {
|
|
|
|
// TODO: replace by more specific exception as soon as it's available (No next map currently defined.)
|
|
|
|
}
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-05-18 21:59:21 +02:00
|
|
|
$label->setPosition(0, $height / 2 - 2.3, 0.2);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setTextSize(1);
|
2014-08-03 01:34:18 +02:00
|
|
|
$label->setText('Next Map');
|
|
|
|
$label->setTextColor('fff');
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setStyle($labelStyle);
|
|
|
|
|
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-05-18 21:59:21 +02:00
|
|
|
$label->setPosition(0, $height / 2 - 5.5, 0.2);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setTextSize(1.3);
|
|
|
|
$label->setText($name);
|
2014-08-03 01:34:18 +02:00
|
|
|
$label->setTextColor('fff');
|
2015-01-18 19:14:09 +01:00
|
|
|
$label->setSize($width - 5, $height);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-05-18 21:59:21 +02:00
|
|
|
$label->setPosition(0, -$height / 2 + 4);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setZ(0.2);
|
|
|
|
$label->setTextSize(1);
|
|
|
|
$label->setScale(0.8);
|
|
|
|
$label->setText($author);
|
2014-08-03 01:34:18 +02:00
|
|
|
$label->setTextColor('fff');
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
if ($requester) {
|
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-05-18 21:59:21 +02:00
|
|
|
$label->setPosition(0, -$height / 2 + 2, 0.2);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setTextSize(1);
|
|
|
|
$label->setScale(0.7);
|
|
|
|
$label->setText($author);
|
2014-08-03 01:34:18 +02:00
|
|
|
$label->setTextColor('f80');
|
|
|
|
$label->setText('Requested by ' . $requester->getEscapedNickname());
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send manialink
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle PlayerConnect callback
|
|
|
|
*
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function handlePlayerConnect(Player $player) {
|
|
|
|
// Display Map Widget
|
2017-03-25 19:15:50 +01:00
|
|
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
2014-05-03 21:57:38 +02:00
|
|
|
$this->displayMapWidget($player->login);
|
|
|
|
}
|
2017-03-25 19:15:50 +01:00
|
|
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
|
2014-05-03 21:57:38 +02:00
|
|
|
$this->displayClockWidget($player->login);
|
|
|
|
}
|
2017-03-25 19:15:50 +01:00
|
|
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
|
2014-05-03 21:57:38 +02:00
|
|
|
$this->displayServerInfoWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-04 18:48:39 +02:00
|
|
|
/**
|
|
|
|
* Update Widgets on Setting Changes
|
|
|
|
*
|
|
|
|
* @param Setting $setting
|
|
|
|
*/
|
2014-08-05 02:17:41 +02:00
|
|
|
public function updateSettings(Setting $setting) {
|
|
|
|
if ($setting->belongsToClass($this)) {
|
2014-07-04 18:48:39 +02:00
|
|
|
$this->displayWIdgets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-03 21:57:38 +02:00
|
|
|
/**
|
2014-07-04 10:12:17 +02:00
|
|
|
* Update Widget on certain callbacks
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-07-04 10:12:17 +02:00
|
|
|
public function updateWidgets() {
|
2017-03-25 19:15:50 +01:00
|
|
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
|
2017-05-10 14:22:51 +02:00
|
|
|
$time = time();
|
|
|
|
//Update Max once per second
|
|
|
|
if ($this->lastWidgetUpdateTime < ($time - 1)) {
|
|
|
|
$this->displayServerInfoWidget();
|
|
|
|
$this->lastWidgetUpdateTime = $time;
|
|
|
|
}
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-03 01:34:18 +02:00
|
|
|
}
|