From 42f6212c3d850f2e8ad3bd9b11507488fa25a7e7 Mon Sep 17 00:00:00 2001 From: kremsy Date: Sat, 11 Jan 2014 17:24:03 +0100 Subject: [PATCH] handle when another mainwidget get opened on map and playerlist --- .../core/Manialinks/ManialinkManager.php | 12 +++++++++--- application/core/Maps/MapList.php | 17 +++++++++++++++-- application/core/Players/PlayerList.php | 17 ++++++++++++++++- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/application/core/Manialinks/ManialinkManager.php b/application/core/Manialinks/ManialinkManager.php index 56a89e78..78aceb0e 100644 --- a/application/core/Manialinks/ManialinkManager.php +++ b/application/core/Manialinks/ManialinkManager.php @@ -29,6 +29,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener const MAIN_MLID = 'Main.ManiaLinkId'; const ACTION_CLOSEWIDGET = 'ManiaLinkManager.CloseWidget'; const CB_MAIN_WINDOW_CLOSED = 'ManialinkManagerCallback.MainWindowClosed'; + const CB_MAIN_WINDOW_OPENED = 'ManialinkManagerCallback.MainWindowOpened'; /** * Public properties @@ -127,7 +128,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener * @return bool */ public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) { - $manialinkText = (string) $manialinkText; + $manialinkText = (string)$manialinkText; if(!$logins) { return $this->maniaControl->client->query('SendDisplayManialinkPage', $manialinkText, $timeout, $hideOnClick); } @@ -172,13 +173,18 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener /** * Displays a ManiaLink Widget to a certain Player * - * @param mixed $maniaLink + * @param mixed $maniaLink * @param Player $player */ - public function displayWidget($maniaLink, Player $player) { + public function displayWidget($maniaLink, Player $player, $widgetName = '') { // render and display xml $this->maniaControl->manialinkManager->sendManialink($maniaLink, $player->login); $this->disableAltMenu($player); + + if($widgetName != '') { + // Trigger callback + $this->maniaControl->callbackManager->triggerCallback(self::CB_MAIN_WINDOW_OPENED, array(self::CB_MAIN_WINDOW_OPENED, $player, $widgetName)); + } } /** diff --git a/application/core/Maps/MapList.php b/application/core/Maps/MapList.php index a3d1d62c..168aca9d 100644 --- a/application/core/Maps/MapList.php +++ b/application/core/Maps/MapList.php @@ -63,6 +63,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { // Register for Callbacks $this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget'); + $this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->callbackManager->registerCallbackListener(MapQueue::CB_MAPQUEUE_CHANGED, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget'); @@ -310,7 +311,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { $quad->setAction(self::ACTION_SEARCH_AUTHOR); // render and display xml - $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player); + $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'MxList'); } /** @@ -582,7 +583,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { } $id++; } - $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player); + $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'MapList'); } /** @@ -641,6 +642,18 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { return $confirmFrame; } + /** + * Unset the player if he opened another Main Widget + * @param array $callback + */ + public function handleWidgetOpened(array $callback){ + $player = $callback[1]; + $openedWidget = $callback[2]; + //unset when another main widget got opened + if($openedWidget != 'MapList' && $openedWidget != 'MxList'){ + unset($this->mapListShown[$player->login]); + } + } /** * Closes the widget * diff --git a/application/core/Players/PlayerList.php b/application/core/Players/PlayerList.php index ef6723c8..cbe2e66e 100644 --- a/application/core/Players/PlayerList.php +++ b/application/core/Players/PlayerList.php @@ -66,6 +66,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLOSE_PLAYER_ADV, $this, 'closePlayerAdvancedWidget'); $this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget'); + $this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); // Update Widget Events @@ -330,7 +331,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { } // Render and display xml - $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player); + $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'PlayerList'); } /** @@ -538,6 +539,20 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { return $frame; } + /** + * Unset the player if he opened another Main Widget + * + * @param array $callback + */ + public function handleWidgetOpened(array $callback) { + $player = $callback[1]; + $openedWidget = $callback[2]; + //unset when another main widget got opened + if($openedWidget != 'PlayerList') { + unset($this->playersListShown[$player->login]); + } + } + /** * Closes the widget *