Made widgetposition changable in the settings

This commit is contained in:
Max Klaversma 2014-02-01 20:35:53 +01:00 committed by Steffen Schröder
parent 5ae3e43097
commit 8488ff4931

View File

@ -35,6 +35,8 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
const ML_REMOVEFROMQUEUE = 'Queue.Remove'; const ML_REMOVEFROMQUEUE = 'Queue.Remove';
const QUEUE_MAX = 'Maximum number in the queue'; const QUEUE_MAX = 'Maximum number in the queue';
const QUEUE_WIDGET_POS_X = 'X position of the widget';
const QUEUE_WIDGET_POS_Y = 'Y position of the widget';
/** /**
* Private properties * Private properties
@ -72,9 +74,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ML_REMOVEFROMQUEUE, $this, 'handleManiaLinkAnswerRemove'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ML_REMOVEFROMQUEUE, $this, 'handleManiaLinkAnswerRemove');
$this->maniaControl->settingManager->initSetting($this, self::QUEUE_MAX, 8); $this->maniaControl->settingManager->initSetting($this, self::QUEUE_MAX, 8);
$this->maniaControl->settingManager->initSetting($this, self::QUEUE_WIDGET_POS_X, 0);
$this->maniaControl->settingManager->initSetting($this, self::QUEUE_WIDGET_POS_Y, -46);
foreach($this->maniaControl->playerManager->getPlayers() as $player) { foreach($this->maniaControl->playerManager->getPlayers() as $player) {
if ($player->isSpectator) { if($player->isSpectator) {
$this->spectators[$player->login] = $player->login; $this->spectators[$player->login] = $player->login;
$this->maniaControl->client->forceSpectator($player->login, 1); $this->maniaControl->client->forceSpectator($player->login, 1);
$this->showJoinQueueWidget($player); $this->showJoinQueueWidget($player);
@ -159,12 +163,12 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$login = $callback[1]->login; $login = $callback[1]->login;
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if ($player->isSpectator) { if($player->isSpectator) {
$this->spectators[$player->login] = $player->login; $this->spectators[$player->login] = $player->login;
$this->maniaControl->client->forceSpectator($player->login, 1); $this->maniaControl->client->forceSpectator($player->login, 1);
$this->showJoinQueueWidget($player); $this->showJoinQueueWidget($player);
} else { } else {
if (count($this->queue) != 0) { if(count($this->queue) != 0) {
$this->maniaControl->client->forceSpectator($player->login, 1); $this->maniaControl->client->forceSpectator($player->login, 1);
$this->spectators[$player->login] = $player->login; $this->spectators[$player->login] = $player->login;
$this->showJoinQueueWidget($player); $this->showJoinQueueWidget($player);
@ -180,7 +184,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
public function handlePlayerDisconnect(array $callback) { public function handlePlayerDisconnect(array $callback) {
/** @var Player $player */ /** @var Player $player */
$player = $callback[1]; $player = $callback[1];
if (isset($this->spectators[$player->login])) { if(isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]); unset($this->spectators[$player->login]);
} }
$this->removePlayerFromQueue($player->login); $this->removePlayerFromQueue($player->login);
@ -196,27 +200,27 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$login = $callback[1][0]['Login']; $login = $callback[1][0]['Login'];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if (!is_null($player)) { if(!is_null($player)) {
if ($player->isSpectator) { if($player->isSpectator) {
if (!isset($this->spectators[$player->login])) { if(!isset($this->spectators[$player->login])) {
$this->maniaControl->client->forceSpectator($player->login, 1); $this->maniaControl->client->forceSpectator($player->login, 1);
$this->spectators[$player->login] = $player->login; $this->spectators[$player->login] = $player->login;
$this->showJoinQueueWidget($player); $this->showJoinQueueWidget($player);
} }
} else { } else {
$this->removePlayerFromQueue($player->login); $this->removePlayerFromQueue($player->login);
if (isset($this->spectators[$player->login])) { if(isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]); unset($this->spectators[$player->login]);
} }
$found = false; $found = false;
foreach($this->showPlay as $showPlay) { foreach($this->showPlay as $showPlay) {
if ($showPlay['player']->login == $player->login) { if($showPlay['player']->login == $player->login) {
$found = true; $found = true;
} }
} }
if (!$found) { if(!$found) {
$this->hideQueueWidget($player); $this->hideQueueWidget($player);
} }
} }
@ -227,7 +231,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* Function called on every second. * Function called on every second.
*/ */
public function handleEverySecond() { public function handleEverySecond() {
if ($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > (count($this->maniaControl->playerManager->players) - count($this->spectators))) { if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > (count($this->maniaControl->playerManager->players) - count($this->spectators))) {
$this->moveFirstPlayerToPlay(); $this->moveFirstPlayerToPlay();
} }
@ -237,7 +241,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
} }
foreach($this->showPlay as $showPlay) { foreach($this->showPlay as $showPlay) {
if (($showPlay['time'] + 5) < time()) { if(($showPlay['time'] + 5) < time()) {
$this->hideQueueWidget($showPlay['player']); $this->hideQueueWidget($showPlay['player']);
unset($this->showPlay[$showPlay['player']->login]); unset($this->showPlay[$showPlay['player']->login]);
} }
@ -270,7 +274,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* Function used to move the first queued player to the * Function used to move the first queued player to the
*/ */
private function moveFirstPlayerToPlay() { private function moveFirstPlayerToPlay() {
if (count($this->queue) > 0) { if(count($this->queue) > 0) {
$firstPlayer = $this->maniaControl->playerManager->getPlayer($this->queue[0]->login); $firstPlayer = $this->maniaControl->playerManager->getPlayer($this->queue[0]->login);
$this->forcePlayerToPlay($firstPlayer); $this->forcePlayerToPlay($firstPlayer);
} }
@ -282,7 +286,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @param Player $player * @param Player $player
*/ */
private function forcePlayerToPlay(Player $player) { private function forcePlayerToPlay(Player $player) {
if ($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > (count($this->maniaControl->playerManager->players) - count($this->spectators))) { if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > (count($this->maniaControl->playerManager->players) - count($this->spectators))) {
try { try {
$this->maniaControl->client->forceSpectator($player->login, 2); $this->maniaControl->client->forceSpectator($player->login, 2);
} catch(\Exception $e) { } catch(\Exception $e) {
@ -296,7 +300,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
//do nothing //do nothing
} }
if (isset($this->spectators[$player->login])) { if(isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]); unset($this->spectators[$player->login]);
} }
$this->removePlayerFromQueue($player->login); $this->removePlayerFromQueue($player->login);
@ -314,13 +318,13 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
*/ */
private function addPlayerToQueue(Player $player) { private function addPlayerToQueue(Player $player) {
foreach($this->queue as $queuedPlayer) { foreach($this->queue as $queuedPlayer) {
if ($queuedPlayer->login == $player->login) { if($queuedPlayer->login == $player->login) {
$this->maniaControl->chat->sendError('You\'re already in the queue!', $player->login); $this->maniaControl->chat->sendError('You\'re already in the queue!', $player->login);
return false; return false;
} }
} }
if ($this->maniaControl->settingManager->getSetting($this, self::QUEUE_MAX) > count($this->queue)) { if($this->maniaControl->settingManager->getSetting($this, self::QUEUE_MAX) > count($this->queue)) {
$this->queue[count($this->queue)] = $player; $this->queue[count($this->queue)] = $player;
$this->maniaControl->chat->sendChat('$z$s$090[Queue] $<$fff' . $player->nickname . '$> just joined the queue!'); $this->maniaControl->chat->sendChat('$z$s$090[Queue] $<$fff' . $player->nickname . '$> just joined the queue!');
} }
@ -335,7 +339,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$count = 0; $count = 0;
$newQueue = array(); $newQueue = array();
foreach($this->queue as $queuePlayer) { foreach($this->queue as $queuePlayer) {
if ($queuePlayer->login != $login) { if($queuePlayer->login != $login) {
$newQueue[$count] = $queuePlayer; $newQueue[$count] = $queuePlayer;
$count++; $count++;
} }
@ -355,13 +359,12 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
$max_queue = $this->maniaControl->settingManager->getSetting($this, self::QUEUE_MAX); $max_queue = $this->maniaControl->settingManager->getSetting($this, self::QUEUE_MAX);
//TODO position setting
// Main frame // Main frame
$frame = new Frame(); $frame = new Frame();
$maniaLink->add($frame); $maniaLink->add($frame);
$frame->setSize(60, 6); $frame->setSize(60, 6);
$frame->setPosition(0, -46, 0); $frame->setPosition($this->maniaControl->settingManager->getSetting($this, self::QUEUE_WIDGET_POS_X), $this->maniaControl->settingManager->getSetting($this, self::QUEUE_WIDGET_POS_Y), 0);
// Background // Background
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
@ -393,17 +396,17 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$inQueue = false; $inQueue = false;
foreach($this->queue as $queuedPlayer) { foreach($this->queue as $queuedPlayer) {
if ($queuedPlayer->login == $player->login) { if($queuedPlayer->login == $player->login) {
$inQueue = true; $inQueue = true;
} }
} }
if ($inQueue) { if($inQueue) {
$message = '$fff$sYou\'re in the queue (click to unqueue).'; $message = '$fff$sYou\'re in the queue (click to unqueue).';
$position = 0; $position = 0;
foreach(array_values($this->queue) as $i => $queuePlayer) { foreach(array_values($this->queue) as $i => $queuePlayer) {
if ($player->login == $queuePlayer->login) { if($player->login == $queuePlayer->login) {
$position = ($i + 1); $position = ($i + 1);
} }
} }
@ -414,7 +417,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$statusLabel->setAction(self::ML_REMOVEFROMQUEUE); $statusLabel->setAction(self::ML_REMOVEFROMQUEUE);
$cameraQuad->setAction(self::ML_REMOVEFROMQUEUE); $cameraQuad->setAction(self::ML_REMOVEFROMQUEUE);
} else { } else {
if (count($this->queue) < $max_queue) { if(count($this->queue) < $max_queue) {
$message = '$0ff$sClick to join spectator waiting list.'; $message = '$0ff$sClick to join spectator waiting list.';
$messageLabel->setAction(self::ML_ADDTOQUEUE); $messageLabel->setAction(self::ML_ADDTOQUEUE);
$backgroundQuad->setAction(self::ML_ADDTOQUEUE); $backgroundQuad->setAction(self::ML_ADDTOQUEUE);
@ -448,8 +451,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$frame = new Frame(); $frame = new Frame();
$maniaLink->add($frame); $maniaLink->add($frame);
$frame->setSize(60, 6); $frame->setSize(60, 6);
$frame->setPosition(0, -46, 0); $frame->setPosition($this->maniaControl->settingManager->getSetting($this, self::QUEUE_WIDGET_POS_X), $this->maniaControl->settingManager->getSetting($this, self::QUEUE_WIDGET_POS_Y), 0);
//TODO position setting
// Background // Background
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();