improved manialink sending code

This commit is contained in:
Steffen Schröder 2014-03-02 13:00:23 +01:00
parent 2f9cab62fa
commit 795366e542
11 changed files with 30 additions and 55 deletions

View File

@ -140,8 +140,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
$players = $this->maniaControl->playerManager->getPlayers(); $players = $this->maniaControl->playerManager->getPlayers();
foreach($players as $player) { foreach($players as $player) {
$manialink = $this->buildMenuIconsManialink($player); $manialink = $this->buildMenuIconsManialink($player);
$manialinkText = $manialink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($manialink, $player->login);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
} }
} }
@ -151,8 +150,8 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* @param Player $player * @param Player $player
*/ */
public function handlePlayerJoined(Player $player) { public function handlePlayerJoined(Player $player) {
$manialinkText = $this->buildMenuIconsManialink($player)->render()->saveXML(); $maniaLink = $this->buildMenuIconsManialink($player);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login); $this->maniaControl->manialinkManager->sendManialink($maniaLink, $player->login);
} }
/** /**

View File

@ -55,12 +55,11 @@ class CustomUIManager implements CallbackListener, TimerListener {
* @param Player $player * @param Player $player
*/ */
private function updateManialink(Player $player = null) { private function updateManialink(Player $player = null) {
$manialinkText = $this->customUI->render()->saveXML();
if ($player) { if ($player) {
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login); $this->maniaControl->manialinkManager->sendManialink($this->customUI, $player->login);
return; return;
} }
$this->maniaControl->manialinkManager->sendManialink($manialinkText); $this->maniaControl->manialinkManager->sendManialink($this->customUI);
} }
/** /**

View File

@ -121,7 +121,6 @@ class IconManager implements CallbackListener {
} }
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($maniaLink, $player);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player);
} }
} }

View File

@ -129,7 +129,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
* @return bool * @return bool
*/ */
public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) { public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) {
$manialinkText = (string)$manialinkText; $manialinkText = (string) $manialinkText;
try { try {
if (!$logins) { if (!$logins) {
@ -211,7 +211,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
*/ */
public function displayWidget($maniaLink, Player $player, $widgetName = '') { public function displayWidget($maniaLink, Player $player, $widgetName = '') {
// render and display xml // render and display xml
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $player->login); $this->sendManialink($maniaLink, $player->login);
if ($widgetName != '') { //TODO make check by manialinkId, getter is needed to avoid uses on non main widgets if ($widgetName != '') { //TODO make check by manialinkId, getter is needed to avoid uses on non main widgets
$this->disableAltMenu($player); $this->disableAltMenu($player);
@ -239,16 +239,14 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
public function closeWidget(Player $player, $widgetId = false) { public function closeWidget(Player $player, $widgetId = false) {
if (!$widgetId) { if (!$widgetId) {
$emptyManialink = new ManiaLink(self::MAIN_MLID); $emptyManialink = new ManiaLink(self::MAIN_MLID);
$manialinkText = $emptyManialink->render()->saveXML(); $this->sendManialink($emptyManialink, $player->login);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
$this->enableAltMenu($player); $this->enableAltMenu($player);
// Trigger callback // Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAIN_WINDOW_CLOSED, $player); $this->maniaControl->callbackManager->triggerCallback(self::CB_MAIN_WINDOW_CLOSED, $player);
} else { } else {
$emptyManialink = new ManiaLink($widgetId); $emptyManialink = new ManiaLink($widgetId);
$manialinkText = $emptyManialink->render()->saveXML(); $this->sendManialink($emptyManialink, $player->login);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
} }
} }

View File

@ -181,8 +181,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$this->destroyVote(); $this->destroyVote();
$emptyManialink = new ManiaLink(self::MLID_ICON); $emptyManialink = new ManiaLink(self::MLID_ICON);
$manialinkText = $emptyManialink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($emptyManialink);
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
$this->maniaControl->commandManager->unregisterCommandListener($this); $this->maniaControl->commandManager->unregisterCommandListener($this);
$this->maniaControl->callbackManager->unregisterCallbackListener($this); $this->maniaControl->callbackManager->unregisterCallbackListener($this);
$this->maniaControl->manialinkManager->unregisterManialinkPageAnswerListener($this); $this->maniaControl->manialinkManager->unregisterManialinkPageAnswerListener($this);
@ -491,8 +490,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
*/ */
private function destroyVote() { private function destroyVote() {
$emptyManialink = new ManiaLink(self::MLID_WIDGET); $emptyManialink = new ManiaLink(self::MLID_WIDGET);
$manialinkText = $emptyManialink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($emptyManialink);
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
unset($this->currentVote); unset($this->currentVote);
} }
@ -624,8 +622,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$label->setText("F8"); $label->setText("F8");
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($maniaLink);
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
} }
/** /**
@ -729,8 +726,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
} }

View File

@ -85,7 +85,6 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 12); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 12);
//TODO what was CB_IC_ClientUpdated?
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'handleMapEnd'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'handleMapEnd');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
@ -730,8 +729,6 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
* Build simple player list for callbacks * Build simple player list for callbacks
*/ */
private function getPlayerList() { private function getPlayerList() {
$client = null;
$players = $this->maniaControl->playerManager->getPlayers(); $players = $this->maniaControl->playerManager->getPlayers();
if (count($players) == 0) { if (count($players) == 0) {
@ -957,7 +954,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
$timeLabel->setTextEmboss(true); $timeLabel->setTextEmboss(true);
} }
return $manialink->render()->saveXML(); return $manialink;
} }
/** /**

View File

@ -100,8 +100,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
*/ */
public function unload() { public function unload() {
$emptyManialink = new ManiaLink(self::MLID_DONATE_WIDGET); $emptyManialink = new ManiaLink(self::MLID_DONATE_WIDGET);
$manialinkText = $emptyManialink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($emptyManialink);
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
$this->maniaControl->callbackManager->unregisterCallbackListener($this); $this->maniaControl->callbackManager->unregisterCallbackListener($this);
$this->maniaControl->commandManager->unregisterCommandListener($this); $this->maniaControl->commandManager->unregisterCommandListener($this);
@ -284,8 +283,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
} }
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
} }
/** /**

View File

@ -117,8 +117,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
*/ */
public function unload() { public function unload() {
$emptyManialink = new ManiaLink(self::MLID_KARMA); $emptyManialink = new ManiaLink(self::MLID_KARMA);
$manialinkText = $emptyManialink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($emptyManialink);
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
$this->maniaControl->callbackManager->unregisterCallbackListener($this); $this->maniaControl->callbackManager->unregisterCallbackListener($this);
$this->maniaControl->timerManager->unregisterTimerListenings($this); $this->maniaControl->timerManager->unregisterTimerListenings($this);
unset($this->maniaControl); unset($this->maniaControl);
@ -210,8 +209,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$votesFrame->removeChildren(); $votesFrame->removeChildren();
// Send manialink // Send manialink
$manialinkText = $this->manialink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($this->manialink, $login);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
} }
} }

View File

@ -354,7 +354,7 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
$timeLabel->setTextEmboss(true); $timeLabel->setTextEmboss(true);
} }
return $manialink->render()->saveXML(); return $manialink;
} }
/** /**

View File

@ -358,8 +358,7 @@ class SlotMachinePlugin implements Plugin, CallbackListener, ManialinkPageAnswer
// Send manialink // Send manialink
if ($showSelf) { if ($showSelf) {
$manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($maniaLink, $player->login);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
} else { } else {
return $frame; return $frame;
} }
@ -418,8 +417,7 @@ class SlotMachinePlugin implements Plugin, CallbackListener, ManialinkPageAnswer
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
} }
/** /**
@ -757,12 +755,10 @@ class SlotMachinePlugin implements Plugin, CallbackListener, ManialinkPageAnswer
*/ */
public function unload() { public function unload() {
$emptyManialink = new ManiaLink(self::SLOT_MAIN_ML); $emptyManialink = new ManiaLink(self::SLOT_MAIN_ML);
$manialinkText = $emptyManialink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($emptyManialink);
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
$emptyManialink = new ManiaLink(self::SLOT_ICON_ML); $emptyManialink = new ManiaLink(self::SLOT_ICON_ML);
$manialinkText = $emptyManialink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($emptyManialink);
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
$this->maniaControl->callbackManager->unregisterCallbackListener($this); $this->maniaControl->callbackManager->unregisterCallbackListener($this);
$this->maniaControl->manialinkManager->unregisterManialinkPageAnswerListener($this); $this->maniaControl->manialinkManager->unregisterManialinkPageAnswerListener($this);

View File

@ -227,8 +227,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
} }
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
} }
/** /**
@ -270,8 +269,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$script->addTimeLabel($label, true); $script->addTimeLabel($label, true);
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
} }
/** /**
@ -374,8 +372,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$quad->setManialink('mcontrol?favorite=' . urlencode($this->maniaControl->server->login)); $quad->setManialink('mcontrol?favorite=' . urlencode($this->maniaControl->server->login));
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
} }
/** /**
@ -398,8 +395,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
*/ */
public function closeWidget($widgetId) { public function closeWidget($widgetId) {
$emptyManialink = new ManiaLink($widgetId); $emptyManialink = new ManiaLink($widgetId);
$manialinkText = $emptyManialink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($emptyManialink);
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
} }
/** /**
@ -509,8 +505,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
} }
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
} }
/** /**