mapqueue improvements

This commit is contained in:
kremsy
2014-01-28 20:09:09 +01:00
committed by Steffen Schröder
parent fc91133f77
commit 9505fdf974
4 changed files with 90 additions and 46 deletions

View File

@ -3,7 +3,6 @@ use FML\Controls\Frame;
use FML\Controls\Labels\Label_Button;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink;
use ManiaControl\Callbacks\CallbackListener;
@ -74,7 +73,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$this->maniaControl->settingManager->initSetting($this, self::QUEUE_MAX, 8);
foreach($this->maniaControl->playerManager->getPlayers() as $player) {
if($player->isSpectator) {
if ($player->isSpectator) {
$this->spectators[$player->login] = $player->login;
$this->maniaControl->client->forceSpectator($player->login, 1);
$this->showJoinQueueWidget($player);
@ -158,12 +157,12 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$login = $callback[1]->login;
$player = $this->maniaControl->playerManager->getPlayer($login);
if($player->isSpectator) {
if ($player->isSpectator) {
$this->spectators[$player->login] = $player->login;
$this->maniaControl->client->forceSpectator($player->login, 1);
$this->showJoinQueueWidget($player);
} else {
if(count($this->queue) != 0) {
if (count($this->queue) != 0) {
$this->maniaControl->client->forceSpectator($player->login, 1);
$this->spectators[$player->login] = $player->login;
$this->showJoinQueueWidget($player);
@ -179,7 +178,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
public function handlePlayerDisconnect(array $callback) {
/** @var Player $player */
$player = $callback[1];
if(isset($this->spectators[$player->login])) {
if (isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]);
}
$this->removePlayerFromQueue($player->login);
@ -195,25 +194,29 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$login = $callback[1][0]['Login'];
$player = $this->maniaControl->playerManager->getPlayer($login);
if(!is_null($player)) {
if($player->isSpectator) {
if(!isset($this->spectators[$player->login])) {
if (!is_null($player)) {
if ($player->isSpectator) {
if (!isset($this->spectators[$player->login])) {
$this->maniaControl->client->forceSpectator($player->login, 1);
$this->spectators[$player->login] = $player->login;
$this->showJoinQueueWidget($player);
}
} else {
$this->removePlayerFromQueue($player->login);
if(isset($this->spectators[$player->login])) unset($this->spectators[$player->login]);
if (isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]);
}
$found = false;
foreach($this->showPlay as $showPlay) {
if($showPlay['player']->login == $player->login) {
if ($showPlay['player']->login == $player->login) {
$found = true;
}
}
if(!$found) $this->hideQueueWidget($player);
if (!$found) {
$this->hideQueueWidget($player);
}
}
}
}
@ -222,7 +225,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* Function called on every second.
*/
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();
}
@ -232,7 +235,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
}
foreach($this->showPlay as $showPlay) {
if(($showPlay['time'] + 5) < time()) {
if (($showPlay['time'] + 5) < time()) {
$this->hideQueueWidget($showPlay['player']);
unset($this->showPlay[$showPlay['player']->login]);
}
@ -265,7 +268,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* Function used to move the first queued player to the
*/
private function moveFirstPlayerToPlay() {
if(count($this->queue) > 0) {
if (count($this->queue) > 0) {
$firstPlayer = $this->maniaControl->playerManager->getPlayer($this->queue[0]->login);
$this->forcePlayerToPlay($firstPlayer);
}
@ -277,10 +280,10 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @param Player $player
*/
private function forcePlayerToPlay(Player $player) {
if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > count($this->maniaControl->playerManager->players)) {
if ($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > count($this->maniaControl->playerManager->players)) {
$this->maniaControl->client->forceSpectator($player->login, 2);
$this->maniaControl->client->forceSpectator($player->login, 0);
if(isset($this->spectators[$player->login])) {
if (isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]);
}
$this->removePlayerFromQueue($player->login);
@ -297,13 +300,13 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
*/
private function addPlayerToQueue(Player $player) {
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);
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->maniaControl->chat->sendChat('$z$s$090[Queue] $<$fff' . $player->nickname . '$> just joined the queue!');
}
@ -318,7 +321,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$count = 0;
$newQueue = array();
foreach($this->queue as $queuePlayer) {
if($queuePlayer->login != $login) {
if ($queuePlayer->login != $login) {
$newQueue[$count] = $queuePlayer;
$count++;
}
@ -375,17 +378,17 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$inQueue = false;
foreach($this->queue as $queuedPlayer) {
if($queuedPlayer->login == $player->login) {
if ($queuedPlayer->login == $player->login) {
$inQueue = true;
}
}
if($inQueue) {
if ($inQueue) {
$message = '$fff$sYou\'re in the queue (click to unqueue).';
$position = 0;
foreach(array_values($this->queue) as $i => $queuePlayer) {
if($player->login == $queuePlayer->login) {
if ($player->login == $queuePlayer->login) {
$position = ($i + 1);
}
}
@ -396,7 +399,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$statusLabel->setAction(self::ML_REMOVEFROMQUEUE);
$cameraQuad->setAction(self::ML_REMOVEFROMQUEUE);
} else {
if(count($this->queue) < $max_queue) {
if (count($this->queue) < $max_queue) {
$message = '$0ff$sClick to join spectator waiting list.';
$messageLabel->setAction(self::ML_ADDTOQUEUE);
$backgroundQuad->setAction(self::ML_ADDTOQUEUE);
@ -412,7 +415,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$messageLabel->setText($message);
$messageLabel->setStyle(Label_Text::STYLE_TextStaticSmall);
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'Queue');
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player);
}
/**