update serverwidget on player connect / disconnect
This commit is contained in:
parent
f555af5f4a
commit
98dfae02bd
@ -26,42 +26,42 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const PLUGIN_ID = 8;
|
||||
const PLUGIN_ID = 8;
|
||||
const PLUGIN_VERSION = 0.1;
|
||||
const PLUGIN_NAME = 'WidgetPlugin';
|
||||
const PLUGIN_AUTHOR = 'kremsy';
|
||||
const PLUGIN_NAME = 'WidgetPlugin';
|
||||
const PLUGIN_AUTHOR = 'kremsy';
|
||||
|
||||
// MapWidget Properties
|
||||
const MLID_MAPWIDGET = 'WidgetPlugin.MapWidget';
|
||||
const MLID_MAPWIDGET = 'WidgetPlugin.MapWidget';
|
||||
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';
|
||||
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
|
||||
const MLID_CLOCKWIDGET = 'WidgetPlugin.ClockWidget';
|
||||
const MLID_CLOCKWIDGET = 'WidgetPlugin.ClockWidget';
|
||||
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';
|
||||
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
|
||||
const MLID_NEXTMAPWIDGET = 'WidgetPlugin.NextMapWidget';
|
||||
const MLID_NEXTMAPWIDGET = 'WidgetPlugin.NextMapWidget';
|
||||
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';
|
||||
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
|
||||
const MLID_SERVERINFOWIDGET = 'WidgetPlugin.ServerInfoWidget';
|
||||
const MLID_SERVERINFOWIDGET = 'WidgetPlugin.ServerInfoWidget';
|
||||
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';
|
||||
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';
|
||||
|
||||
/**
|
||||
* Private Properties
|
||||
@ -73,7 +73,6 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
private $maniaControl = null;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the plugin
|
||||
*
|
||||
@ -91,6 +90,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'handleOnBeginMap');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ENDMAP, $this, 'handleOnEndMap');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerConnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECTED, $this, 'handlePlayerDisconnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_MINUTE, $this, 'handleEveryMinute');
|
||||
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED, true);
|
||||
@ -136,13 +136,13 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
*/
|
||||
public function handleOnInit(array $callback) {
|
||||
// Display Map Widget
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
||||
$this->displayMapWidget();
|
||||
}
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
|
||||
$this->displayClockWidget();
|
||||
}
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
|
||||
$this->displayServerInfoWidget();
|
||||
}
|
||||
}
|
||||
@ -153,15 +153,15 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
* @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();
|
||||
$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();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
|
||||
$maniaLink = new ManiaLink(self::MLID_MAPWIDGET);
|
||||
$script = new Script();
|
||||
$script = new Script();
|
||||
$maniaLink->setScript($script);
|
||||
|
||||
// mainframe
|
||||
@ -201,7 +201,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
$label->setText($map->authorLogin);
|
||||
$label->setTextColor("FFF");
|
||||
|
||||
if (isset($map->mx->pageurl)) {
|
||||
if(isset($map->mx->pageurl)) {
|
||||
$quad = new Quad();
|
||||
$frame->add($quad);
|
||||
$quad->setImage($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON));
|
||||
@ -222,11 +222,11 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
* @param bool $login
|
||||
*/
|
||||
public function displayClockWidget($login = false) {
|
||||
$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();
|
||||
$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();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
|
||||
$maniaLink = new ManiaLink(self::MLID_CLOCKWIDGET);
|
||||
@ -266,11 +266,11 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
* @param String $login
|
||||
*/
|
||||
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();
|
||||
$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();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
|
||||
$maniaLink = new ManiaLink(self::MLID_SERVERINFOWIDGET);
|
||||
@ -295,18 +295,17 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
|
||||
$serverName = $this->maniaControl->server->getName();
|
||||
|
||||
$players = $this->maniaControl->playerManager->getPlayers();
|
||||
$playerCount = 0;
|
||||
$players = $this->maniaControl->playerManager->getPlayers();
|
||||
$playerCount = 0;
|
||||
$spectatorCount = 0;
|
||||
/**
|
||||
*
|
||||
* @var Player $player
|
||||
*/
|
||||
foreach ($players as $player) {
|
||||
if ($player->isSpectator) {
|
||||
foreach($players as $player) {
|
||||
if($player->isSpectator) {
|
||||
$spectatorCount++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$playerCount++;
|
||||
}
|
||||
}
|
||||
@ -375,7 +374,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
*/
|
||||
public function handleOnBeginMap(array $callback) {
|
||||
// Display Map Widget
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
||||
$this->displayMapWidget();
|
||||
}
|
||||
$this->closeWidget(self::MLID_NEXTMAPWIDGET);
|
||||
@ -388,7 +387,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
*/
|
||||
public function closeWidget($widgetId) {
|
||||
$emptyManialink = new ManiaLink($widgetId);
|
||||
$manialinkText = $emptyManialink->render()->saveXML();
|
||||
$manialinkText = $emptyManialink->render()->saveXML();
|
||||
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
|
||||
}
|
||||
|
||||
@ -399,7 +398,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
*/
|
||||
public function handleOnEndMap(array $callback) {
|
||||
// Display Map Widget
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED)) {
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED)) {
|
||||
$this->displayNextMapWidget();
|
||||
}
|
||||
}
|
||||
@ -410,13 +409,13 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
* @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();
|
||||
$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();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
||||
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
||||
|
||||
$maniaLink = new ManiaLink(self::MLID_NEXTMAPWIDGET);
|
||||
|
||||
@ -441,17 +440,16 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
*/
|
||||
$requester = null;
|
||||
// if the nextmap is not a queued map, get it from map info
|
||||
if ($queuedMap == null) {
|
||||
if($queuedMap == null) {
|
||||
$this->maniaControl->client->query("GetNextMapInfo");
|
||||
$map = $this->maniaControl->client->getResponse();
|
||||
$name = $map['Name'];
|
||||
$map = $this->maniaControl->client->getResponse();
|
||||
$name = $map['Name'];
|
||||
$author = $map['Author'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$requester = $queuedMap[0];
|
||||
$map = $queuedMap[1];
|
||||
$name = $map->name;
|
||||
$author = $map->authorLogin;
|
||||
$map = $queuedMap[1];
|
||||
$name = $map->name;
|
||||
$author = $map->authorLogin;
|
||||
}
|
||||
|
||||
$label = new Label_Text();
|
||||
@ -487,7 +485,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
$label->setText($author);
|
||||
$label->setTextColor("FFF");
|
||||
|
||||
if ($requester != null) {
|
||||
if($requester != null) {
|
||||
$label = new Label_Text();
|
||||
$frame->add($label);
|
||||
$label->setX(0);
|
||||
@ -514,14 +512,25 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
public function handlePlayerConnect(array $callback) {
|
||||
$player = $callback[1];
|
||||
// Display Map Widget
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
||||
$this->displayMapWidget($player->login);
|
||||
}
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
|
||||
$this->displayClockWidget($player->login);
|
||||
}
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
|
||||
$this->displayServerInfoWidget($player->login);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -531,7 +540,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleEveryMinute(array $callback) {
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
|
||||
$this->displayClockWidget();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user