This commit is contained in:
kremsy 2014-01-11 17:36:46 +01:00 committed by Steffen Schröder
parent 42f6212c3d
commit 09131aa6e1
2 changed files with 31 additions and 8 deletions

View File

@ -77,6 +77,8 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
// Create server settings // Create server settings
$this->serverSettings = new ServerSettings($maniaControl); $this->serverSettings = new ServerSettings($maniaControl);
@ -144,6 +146,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
*/ */
public function handleSaveConfigAction(array $callback, Player $player) { public function handleSaveConfigAction(array $callback, Player $player) {
foreach($this->menus as $menu) { foreach($this->menus as $menu) {
/** @var ConfiguratorMenu $menu */
$menu->saveConfigData($callback[1], $player); $menu->saveConfigData($callback[1], $player);
} }
} }
@ -165,24 +168,43 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
* @param int $menuId * @param int $menuId
*/ */
public function showMenu(Player $player, $menuId = 0) { public function showMenu(Player $player, $menuId = 0) {
$manialink = $this->buildManialink($menuId); $manialink = $this->buildManialink($menuId);
$manialinkText = $manialink->render()->saveXML(); $this->maniaControl->manialinkManager->displayWidget($manialink, $player, "Configurator");
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
$this->maniaControl->manialinkManager->disableAltMenu($player);
$this->playersMenuShown[$player->login] = true; $this->playersMenuShown[$player->login] = true;
} }
/**
* 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 != 'Configurator') {
unset($this->playersMenuShown[$player->login]);
}
}
/**
* Widget get closed -> unset player
*
* @param array $callback
*/
public function closeWidget(array $callback) {
$player = $callback[1];
unset($this->playersMenuShown[$player->login]);
}
/** /**
* Hide the Menu for the Player * Hide the Menu for the Player
* *
* @param Player $player * @param Player $player
*/ */
public function hideMenu(Player $player) { public function hideMenu(Player $player) {
$emptyManialink = new ManiaLink(ManialinkManager::MAIN_MLID);
$manialinkText = $emptyManialink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
$this->maniaControl->manialinkManager->enableAltMenu($player);
unset($this->playersMenuShown[$player->login]); unset($this->playersMenuShown[$player->login]);
$this->maniaControl->manialinkManager->closeWidget($player);
} }
/** /**

View File

@ -175,6 +175,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
* *
* @param mixed $maniaLink * @param mixed $maniaLink
* @param Player $player * @param Player $player
* @param string $widgetName
*/ */
public function displayWidget($maniaLink, Player $player, $widgetName = '') { public function displayWidget($maniaLink, Player $player, $widgetName = '') {
// render and display xml // render and display xml