allow login string parameter in manialink manager methods

This commit is contained in:
Steffen Schröder 2014-05-15 15:07:03 +02:00
parent ee0e55c10b
commit d68031e052

View File

@ -160,19 +160,22 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
} }
/** /**
* Hide the Manialink with the given Id * Displays a ManiaLink Widget to a certain Player (Should only be used on Main Widgets)
* *
* @param mixed $manialinkId * @param mixed $maniaLink
* @param mixed $logins * @param mixed $player
* @param string $widgetName
*/ */
public function hideManialink($manialinkId, $logins = null) { public function displayWidget($maniaLink, $player, $widgetName = null) {
if (is_array($manialinkId)) { // render and display xml
foreach ($manialinkId as $mlId) { $this->sendManialink($maniaLink, $player);
$this->hideManialink($mlId, $logins);
} if ($widgetName) {
} else { // TODO make check by manialinkId, getter is needed to avoid uses on non main widgets
$emptyManialink = new ManiaLink($manialinkId); $this->disableAltMenu($player);
$this->sendManialink($emptyManialink, $logins); // Trigger callback
$player = $this->maniaControl->playerManager->getPlayer($player);
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAIN_WINDOW_OPENED, $player, $widgetName);
} }
} }
@ -207,12 +210,11 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
if (is_array($logins)) { if (is_array($logins)) {
$success = true; $success = true;
foreach ($logins as $login) { foreach ($logins as $login) {
$subSuccess = $this->maniaControl->client->sendDisplayManialinkPage($login, $manialinkText, $timeout, $hideOnClick); $subSuccess = $this->sendManialink($manialinkText, $login, $timeout, $hideOnClick);
if (!$subSuccess) { if (!$subSuccess) {
$success = false; $success = false;
} }
} }
return $success; return $success;
} }
} catch (UnknownPlayerException $e) { } catch (UnknownPlayerException $e) {
@ -222,34 +224,16 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
return true; return true;
} }
/**
* Displays a ManiaLink Widget to a certain Player (Should only be used on Main Widgets)
*
* @param mixed $maniaLink
* @param Player $player
* @param string $widgetName
*/
public function displayWidget($maniaLink, Player $player, $widgetName = '') {
// render and display xml
$this->sendManialink($maniaLink, $player->login);
if ($widgetName != '') {
// TODO make check by manialinkId, getter is needed to avoid uses on non main widgets
$this->disableAltMenu($player);
// Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAIN_WINDOW_OPENED, $player, $widgetName);
}
}
/** /**
* Disable the alt menu for the player * Disable the alt menu for the player
* *
* @param Player $player * @param mixed $player
* @return bool * @return bool
*/ */
public function disableAltMenu(Player $player) { public function disableAltMenu($player) {
$login = Player::parseLogin($player);
try { try {
$success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_DisableAltMenu', $player->login); $success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_DisableAltMenu', $login);
} catch (GameModeException $e) { } catch (GameModeException $e) {
return false; return false;
} }
@ -269,32 +253,49 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
/** /**
* Closes a Manialink Widget * Closes a Manialink Widget
* *
* @param Player $player * @param mixed $player
* @param bool $widgetId * @param bool $widgetId
*/ */
public function closeWidget(Player $player, $widgetId = false) { public function closeWidget($player, $widgetId = false) {
if (!$widgetId) { if (!$widgetId) {
$emptyManialink = new ManiaLink(self::MAIN_MLID); $this->hideManialink(self::MAIN_MLID);
$this->sendManialink($emptyManialink, $player->login);
$this->enableAltMenu($player); $this->enableAltMenu($player);
// Trigger callback // Trigger callback
$player = $this->maniaControl->playerManager->getPlayer($player);
$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); $this->hideManialink($widgetId, $player);
$this->sendManialink($emptyManialink, $player->login); }
}
/**
* Hide the Manialink with the given Id
*
* @param mixed $manialinkId
* @param mixed $logins
*/
public function hideManialink($manialinkId, $logins = null) {
if (is_array($manialinkId)) {
foreach ($manialinkId as $mlId) {
$this->hideManialink($mlId, $logins);
}
} else {
$emptyManialink = new ManiaLink($manialinkId);
$this->sendManialink($emptyManialink, $logins);
} }
} }
/** /**
* Enable the alt menu for the player * Enable the alt menu for the player
* *
* @param Player $player * @param mixed $player
* @return bool * @return bool
*/ */
public function enableAltMenu(Player $player) { public function enableAltMenu($player) {
$login = Player::parseLogin($player);
try { try {
$success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_EnableAltMenu', $player->login); $success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_EnableAltMenu', $login);
} catch (GameModeException $e) { } catch (GameModeException $e) {
return false; return false;
} }