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

@ -37,6 +37,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
const ACTION_ERASE_MAP = 'MapList.EraseMap';
const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
const ACTION_QUEUED_MAP = 'MapList.QueueMap';
const ACTION_UNQUEUE_MAP = 'MapList.UnQueueMap';
const ACTION_CHECK_UPDATE = 'MapList.CheckUpdate';
const ACTION_CLEAR_MAPQUEUE = 'MapList.ClearMapQueue';
const MAX_MAPS_PER_PAGE = 15;
@ -122,7 +123,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$maniaLink->add($frame);
//Admin Buttons
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
if ($this->maniaControl->authenticationManager->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
//Clear Map-Queue
$label = new Label_Button();
$frame->add($label);
@ -280,7 +281,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$label->setTextSize(1.5);
$label->setText($queuedMaps[$map->uid]);
$label->setTextColor('fff');
//Checks if the Player who openend the Widget has queued the map
$queuer = $this->maniaControl->mapManager->mapQueue->getQueuer($map->uid);
if ($queuer->login == $player->login) {
$script->addTooltip($label, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => 'Remove $<' . $map->name . '$> from the Map Queue'));
$label->setAction(self::ACTION_UNQUEUE_MAP . '.' . $map->uid);
} else {
$script->addTooltip($label, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => '$<' . $map->name . '$> is on Map-Queue Position: ' . $queuedMaps[$map->uid]));
}
} else {
// Map-Queue-Map-Button
$queueLabel = new Label_Button();
@ -292,7 +302,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$queueLabel->setText('+');
$queueLabel->setTextColor('09f');
$script->addTooltip($queueLabel, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => 'Add Map to the Map Queue: $<' . $map->name . '$>'));
$script->addTooltip($queueLabel, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => 'Add $<' . $map->name . '$> to the Map Queue'));
}
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) {
@ -504,6 +514,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
case self::ACTION_QUEUED_MAP:
$this->maniaControl->mapManager->mapQueue->addMapToMapQueue($callback[1][1], $actionArray[2]);
break;
case self::ACTION_UNQUEUE_MAP:
$this->maniaControl->mapManager->mapQueue->removeFromMapQueue($player, $actionArray[2]);
break;
}
}

View File

@ -205,7 +205,7 @@ class MapManager implements CallbackListener {
$map = $this->maps[$uid];
//Unset the Map everywhere
$this->mapQueue->removeFromMapQueue($admin->login, $map->uid);
$this->mapQueue->removeFromMapQueue($admin, $map->uid);
$this->mxManager->unsetMap($map->mx->id);
// Remove map

View File

@ -2,6 +2,7 @@
namespace ManiaControl\Maps;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener;
@ -22,6 +23,7 @@ class MapQueue implements CallbackListener, CommandListener {
const SETTING_SKIP_MAP_ON_LEAVE = 'Skip Map when the requester leaves';
const SETTING_SKIP_MAPQUEUE_ADMIN = 'Skip Map when admin leaves';
const SETTING_PERMISSION_CLEAR_MAPQUEUE = 'Clear Mapqueue';
const ADMIN_COMMAND_CLEAR_MAPQUEUE = 'clearmapqueue';
const ADMIN_COMMAND_CLEAR_JUKEBOX = 'clearjukebox';
@ -46,6 +48,8 @@ class MapQueue implements CallbackListener, CommandListener {
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE, true);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN, false);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CLEAR_MAPQUEUE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
//Register Admin Commands
$this->maniaControl->commandManager->registerCommandListener(self::ADMIN_COMMAND_CLEAR_JUKEBOX, $this, 'command_ClearMapQueue', true);
$this->maniaControl->commandManager->registerCommandListener(self::ADMIN_COMMAND_CLEAR_MAPQUEUE, $this, 'command_ClearMapQueue', true);
@ -67,6 +71,11 @@ class MapQueue implements CallbackListener, CommandListener {
* @param $admin
*/
public function clearMapQueue($admin) {
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
//Destroy map - queue list
@ -105,17 +114,26 @@ class MapQueue implements CallbackListener, CommandListener {
// Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('add', $this->queuedMaps[$uid]));
}
/**
* Revmoes a Map from the Map queue
*
* @param $login
* @param \ManiaControl\Players\Player $player
* @param $uid
* @internal param $login
*/
public function removeFromMapQueue($login, $uid) {
public function removeFromMapQueue(Player $player, $uid) {
if (!isset($this->queuedMaps[$uid])) {
return;
}
$map = $this->queuedMaps[$uid][1];
unset($this->queuedMaps[$uid]);
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> removed $<' . $map->name . '$> from the Map Queue');
// Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('remove', $map));
}
@ -163,10 +181,10 @@ class MapQueue implements CallbackListener, CommandListener {
$map = $this->nextMap[1];
$success = $this->maniaControl->client->chooseNextMap($map->fileName);
if(!$success) { //TODO error code?
//trigger_error('[' . $this->maniaControl->client->getErrorCode() . '] ChooseNextMap - ' . $this->maniaControl->client->getErrorCode(), E_USER_WARNING);
return;
try {
$this->maniaControl->client->chooseNextMap($map->fileName);
} catch(\Exception $e) {
//do nothing
}
}
@ -209,6 +227,16 @@ class MapQueue implements CallbackListener, CommandListener {
return $queuedMaps;
}
/**
* Returns the Queuer of a Map
*
* @param $uid
* @return mixed
*/
public function getQueuer($uid) {
return $this->queuedMaps[$uid][0];
}
/**
* Dummy Function for testing
*/

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;
@ -204,7 +203,9 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
}
} 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) {
@ -213,7 +214,9 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
}
}
if(!$found) $this->hideQueueWidget($player);
if (!$found) {
$this->hideQueueWidget($player);
}
}
}
}
@ -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);
}
/**