2014-01-31 13:40:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Admin;
|
|
|
|
|
|
|
|
use FML\Controls\Frame;
|
2014-01-31 14:19:39 +01:00
|
|
|
use FML\Controls\Labels\Label_Button;
|
2014-01-31 13:40:07 +01:00
|
|
|
use FML\Controls\Labels\Label_Text;
|
|
|
|
use FML\Controls\Quads\Quad_BgRaceScore2;
|
|
|
|
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
|
|
|
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
|
|
|
use FML\ManiaLink;
|
2014-04-27 16:22:12 +02:00
|
|
|
use FML\Script\Features\Paging;
|
2014-01-31 14:19:39 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2014-01-31 13:40:07 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use ManiaControl\Manialinks\ManialinkManager;
|
|
|
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
|
|
|
use ManiaControl\Players\Player;
|
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/**
|
|
|
|
* Widget Class listing Authorized Players
|
2014-05-02 17:31:10 +02:00
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
|
|
|
* @copyright 2014 ManiaControl Team
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-04-12 12:14:37 +02:00
|
|
|
*/
|
2014-01-31 14:19:39 +01:00
|
|
|
class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-01-31 13:40:07 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
2014-06-17 23:35:56 +02:00
|
|
|
const ACTION_OPEN_ADMIN_LIST = 'AdminList.OpenAdminList';
|
|
|
|
const ACTION_REVOKE_RIGHTS = 'AdminList.RevokeRights';
|
|
|
|
const MAX_PLAYERS_PER_PAGE = 15;
|
2014-01-31 13:40:07 +01:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-01-31 14:29:39 +01:00
|
|
|
* Private Properties
|
|
|
|
*/
|
|
|
|
private $adminListShown = array();
|
|
|
|
|
2014-01-31 13:40:07 +01:00
|
|
|
/**
|
|
|
|
* Create a PlayerList Instance
|
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
2014-01-31 14:29:39 +01:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'updateWidget');
|
|
|
|
|
|
|
|
// Menu Entry AdminList
|
2014-06-17 23:35:56 +02:00
|
|
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_ADMIN_LIST, $this, 'openAdminList');
|
2014-01-31 13:40:07 +01:00
|
|
|
$itemQuad = new Quad_UIConstruction_Buttons();
|
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Author);
|
2014-06-17 23:35:56 +02:00
|
|
|
$itemQuad->setAction(self::ACTION_OPEN_ADMIN_LIST);
|
2014-05-13 18:26:38 +02:00
|
|
|
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 50, 'Open AdminList');
|
2014-01-31 13:40:07 +01:00
|
|
|
}
|
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/**
|
|
|
|
* Open Admin List Action
|
2014-05-02 17:31:10 +02:00
|
|
|
*
|
|
|
|
* @param array $callback
|
2014-04-12 12:14:37 +02:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
2014-01-31 13:40:07 +01:00
|
|
|
public function openAdminList(array $callback, Player $player) {
|
|
|
|
$this->showAdminLists($player);
|
|
|
|
}
|
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/**
|
|
|
|
* Show the Admin List
|
2014-05-02 17:31:10 +02:00
|
|
|
*
|
2014-04-12 12:14:37 +02:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
2014-01-31 13:40:07 +01:00
|
|
|
public function showAdminLists(Player $player) {
|
2014-01-31 14:29:39 +01:00
|
|
|
$this->adminListShown[$player->login] = true;
|
|
|
|
|
2014-08-02 22:31:46 +02:00
|
|
|
$width = $this->maniaControl->manialinkManager->getStyleManager()->getListWidgetsWidth();
|
|
|
|
$height = $this->maniaControl->manialinkManager->getStyleManager()->getListWidgetsHeight();
|
2014-01-31 13:40:07 +01:00
|
|
|
|
2014-01-31 14:19:39 +01:00
|
|
|
// get Admins
|
2014-05-15 15:13:30 +02:00
|
|
|
$admins = $this->maniaControl->authenticationManager->getAdmins();
|
2014-01-31 13:40:07 +01:00
|
|
|
|
2014-01-31 14:19:39 +01:00
|
|
|
//Create ManiaLink
|
2014-01-31 13:40:07 +01:00
|
|
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
|
|
|
$script = $maniaLink->getScript();
|
2014-05-02 17:31:10 +02:00
|
|
|
$paging = new Paging();
|
|
|
|
$script->addFeature($paging);
|
2014-01-31 13:40:07 +01:00
|
|
|
|
|
|
|
// Main frame
|
2014-08-02 22:31:46 +02:00
|
|
|
$frame = $this->maniaControl->manialinkManager->getStyleManager()->getDefaultListFrame($script, $paging);
|
2014-01-31 13:40:07 +01:00
|
|
|
$maniaLink->add($frame);
|
|
|
|
|
|
|
|
// Start offsets
|
2014-06-14 15:48:27 +02:00
|
|
|
$posX = -$width / 2;
|
|
|
|
$posY = $height / 2;
|
2014-01-31 14:19:39 +01:00
|
|
|
|
2014-01-31 13:40:07 +01:00
|
|
|
//Predefine description Label
|
2014-08-02 22:31:46 +02:00
|
|
|
$descriptionLabel = $this->maniaControl->manialinkManager->getStyleManager()->getDefaultDescriptionLabel();
|
2014-01-31 13:40:07 +01:00
|
|
|
$frame->add($descriptionLabel);
|
|
|
|
|
2014-01-31 14:19:39 +01:00
|
|
|
// Headline
|
|
|
|
$headFrame = new Frame();
|
|
|
|
$frame->add($headFrame);
|
2014-06-14 15:48:27 +02:00
|
|
|
$headFrame->setY($posY - 5);
|
|
|
|
$array = array("Id" => $posX + 5, "Nickname" => $posX + 18, "Login" => $posX + 70, "Actions" => $posX + 120);
|
2014-01-31 14:19:39 +01:00
|
|
|
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
|
2014-01-31 13:40:07 +01:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$index = 1;
|
|
|
|
$posY -= 10;
|
2014-05-15 15:13:30 +02:00
|
|
|
$pageFrame = null;
|
|
|
|
|
2014-05-02 17:31:10 +02:00
|
|
|
foreach ($admins as $admin) {
|
2014-06-14 15:48:27 +02:00
|
|
|
if ($index % self::MAX_PLAYERS_PER_PAGE === 1) {
|
2014-01-31 13:40:07 +01:00
|
|
|
$pageFrame = new Frame();
|
|
|
|
$frame->add($pageFrame);
|
2014-05-15 15:13:30 +02:00
|
|
|
|
2014-05-02 17:31:10 +02:00
|
|
|
$paging->addPage($pageFrame);
|
2014-06-14 15:48:27 +02:00
|
|
|
$posY = $height / 2 - 10;
|
2014-01-31 13:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$playerFrame = new Frame();
|
|
|
|
$pageFrame->add($playerFrame);
|
2014-06-14 15:48:27 +02:00
|
|
|
$playerFrame->setY($posY);
|
2014-01-31 13:40:07 +01:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
if ($index % 2 !== 0) {
|
2014-01-31 13:40:07 +01:00
|
|
|
$lineQuad = new Quad_BgsPlayerCard();
|
|
|
|
$playerFrame->add($lineQuad);
|
|
|
|
$lineQuad->setSize($width, 4);
|
|
|
|
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
|
|
|
|
$lineQuad->setZ(0.001);
|
|
|
|
}
|
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$array = array($index => $posX + 5, $admin->nickname => $posX + 18, $admin->login => $posX + 70);
|
2014-01-31 13:40:07 +01:00
|
|
|
$this->maniaControl->manialinkManager->labelLine($playerFrame, $array);
|
|
|
|
|
|
|
|
|
|
|
|
// Level Quad
|
|
|
|
$rightQuad = new Quad_BgRaceScore2();
|
|
|
|
$playerFrame->add($rightQuad);
|
2014-06-14 15:48:27 +02:00
|
|
|
$rightQuad->setX($posX + 13);
|
2014-01-31 13:40:07 +01:00
|
|
|
$rightQuad->setZ(5);
|
|
|
|
$rightQuad->setSubStyle($rightQuad::SUBSTYLE_CupFinisher);
|
|
|
|
$rightQuad->setSize(7, 3.5);
|
|
|
|
|
|
|
|
$rightLabel = new Label_Text();
|
|
|
|
$playerFrame->add($rightLabel);
|
2014-06-14 15:48:27 +02:00
|
|
|
$rightLabel->setX($posX + 13.9);
|
2014-01-31 13:40:07 +01:00
|
|
|
$rightLabel->setTextSize(0.8);
|
|
|
|
$rightLabel->setZ(10);
|
2014-04-27 16:22:12 +02:00
|
|
|
$rightLabel->setText($this->maniaControl->authenticationManager->getAuthLevelAbbreviation($admin));
|
2014-05-02 17:31:10 +02:00
|
|
|
$description = $this->maniaControl->authenticationManager->getAuthLevelName($admin) . " " . $admin->nickname;
|
|
|
|
$rightLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
2014-01-31 13:40:07 +01:00
|
|
|
|
2014-01-31 14:19:39 +01:00
|
|
|
//Revoke Button
|
|
|
|
if ($admin->authLevel > 0 && $this->maniaControl->authenticationManager->checkRight($player, $admin->authLevel + 1)) {
|
|
|
|
//Settings
|
|
|
|
$style = Label_Text::STYLE_TextCardSmall;
|
|
|
|
$textColor = 'FFF';
|
|
|
|
$quadWidth = 24;
|
|
|
|
$quadHeight = 3.4;
|
|
|
|
|
|
|
|
// Quad
|
|
|
|
$quad = new Quad_BgsPlayerCard();
|
|
|
|
$playerFrame->add($quad);
|
|
|
|
$quad->setZ(11);
|
2014-06-14 15:48:27 +02:00
|
|
|
$quad->setX($posX + 130);
|
2014-01-31 14:19:39 +01:00
|
|
|
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
|
|
|
|
$quad->setSize($quadWidth, $quadHeight);
|
|
|
|
$quad->setAction(self::ACTION_REVOKE_RIGHTS . "." . $admin->login);
|
|
|
|
|
|
|
|
//Label
|
|
|
|
$label = new Label_Button();
|
|
|
|
$playerFrame->add($label);
|
2014-06-14 15:48:27 +02:00
|
|
|
$label->setX($posX + 130);
|
2014-01-31 14:19:39 +01:00
|
|
|
$quad->setZ(12);
|
|
|
|
$label->setStyle($style);
|
|
|
|
$label->setTextSize(1);
|
|
|
|
$label->setTextColor($textColor);
|
|
|
|
$label->setText("Revoke Rights");
|
|
|
|
}
|
2014-01-31 13:40:07 +01:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$posY -= 4;
|
|
|
|
$index++;
|
2014-01-31 13:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Render and display xml
|
|
|
|
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'AdminList');
|
|
|
|
}
|
|
|
|
|
2014-01-31 14:19:39 +01:00
|
|
|
/**
|
|
|
|
* Called on ManialinkPageAnswer
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handleManialinkPageAnswer(array $callback) {
|
|
|
|
$actionId = $callback[1][2];
|
|
|
|
$actionArray = explode('.', $actionId, 3);
|
|
|
|
if (count($actionArray) <= 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-24 17:22:48 +02:00
|
|
|
$action = $actionArray[0] . '.' . $actionArray[1];
|
2014-01-31 14:19:39 +01:00
|
|
|
$adminLogin = $callback[1][1];
|
|
|
|
$targetLogin = $actionArray[2];
|
|
|
|
|
2014-05-02 17:31:10 +02:00
|
|
|
switch ($action) {
|
2014-01-31 14:19:39 +01:00
|
|
|
case self::ACTION_REVOKE_RIGHTS:
|
2014-08-02 22:31:46 +02:00
|
|
|
$this->maniaControl->playerManager->getPlayerActions()->revokeAuthLevel($adminLogin, $targetLogin);
|
2014-01-31 14:19:39 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-31 14:29:39 +01:00
|
|
|
/**
|
|
|
|
* Reopen the widget on Map Begin, MapListChanged, etc.
|
|
|
|
*
|
2014-05-02 16:13:45 +02:00
|
|
|
* @param Player $player
|
2014-01-31 14:29:39 +01:00
|
|
|
*/
|
2014-02-27 13:16:34 +01:00
|
|
|
public function updateWidget(Player $player) {
|
2014-05-02 17:31:10 +02:00
|
|
|
foreach ($this->adminListShown as $login => $shown) {
|
2014-01-31 14:29:39 +01:00
|
|
|
if ($shown) {
|
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
2014-03-31 21:41:05 +02:00
|
|
|
if ($player) {
|
2014-01-31 14:29:39 +01:00
|
|
|
$this->showAdminLists($player);
|
|
|
|
} else {
|
|
|
|
unset($this->adminListShown[$login]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the widget
|
|
|
|
*
|
2014-02-19 17:37:37 +01:00
|
|
|
* @param \ManiaControl\Players\Player $player
|
2014-01-31 14:29:39 +01:00
|
|
|
*/
|
2014-02-19 17:37:37 +01:00
|
|
|
public function closeWidget(Player $player) {
|
2014-01-31 14:29:39 +01:00
|
|
|
unset($this->adminListShown[$player->login]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unset the player if he opened another Main Widget
|
|
|
|
*
|
2014-02-19 17:37:37 +01:00
|
|
|
* @param Player $player
|
|
|
|
* @param $openedWidget
|
2014-01-31 14:29:39 +01:00
|
|
|
*/
|
2014-02-19 17:37:37 +01:00
|
|
|
public function handleWidgetOpened(Player $player, $openedWidget) {
|
2014-01-31 14:29:39 +01:00
|
|
|
//unset when another main widget got opened
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($openedWidget !== 'AdminList') {
|
2014-01-31 14:29:39 +01:00
|
|
|
unset($this->adminListShown[$player->login]);
|
|
|
|
}
|
|
|
|
}
|
2014-01-31 13:40:07 +01:00
|
|
|
}
|