handle when another mainwidget get opened on map and playerlist

This commit is contained in:
kremsy 2014-01-11 17:24:03 +01:00 committed by Steffen Schröder
parent 8afdfeb450
commit 42f6212c3d
3 changed files with 40 additions and 6 deletions

View File

@ -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));
}
}
/**

View File

@ -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
*

View File

@ -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
*