2013-12-14 22:00:59 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Maps;
|
2014-01-02 10:38:46 +01:00
|
|
|
|
|
|
|
use FML\Controls\Frame;
|
2013-12-29 19:21:29 +01:00
|
|
|
use FML\Controls\Gauge;
|
2013-12-14 22:00:59 +01:00
|
|
|
use FML\Controls\Label;
|
2013-12-31 02:27:40 +01:00
|
|
|
use FML\Controls\Labels\Label_Button;
|
2013-12-28 23:52:09 +01:00
|
|
|
use FML\Controls\Labels\Label_Text;
|
2014-01-02 10:38:46 +01:00
|
|
|
use FML\Controls\Quad;
|
2013-12-31 02:27:40 +01:00
|
|
|
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
2013-12-14 22:00:59 +01:00
|
|
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
2014-05-03 21:12:44 +02:00
|
|
|
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
2014-01-02 10:38:46 +01:00
|
|
|
use FML\ManiaLink;
|
2014-04-27 16:22:12 +02:00
|
|
|
use FML\Script\Features\Paging;
|
2023-10-09 10:18:33 +02:00
|
|
|
use ManiaControl\Admin\AuthenticationManager;
|
2013-12-15 15:13:56 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2014-04-28 20:50:38 +02:00
|
|
|
use ManiaControl\Callbacks\Callbacks;
|
2014-08-05 01:49:13 +02:00
|
|
|
use ManiaControl\Logger;
|
2014-01-02 10:38:46 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
2014-01-09 18:19:37 +01:00
|
|
|
use ManiaControl\Manialinks\IconManager;
|
2017-04-01 18:48:36 +02:00
|
|
|
use ManiaControl\Manialinks\LabelLine;
|
2013-12-15 11:29:49 +01:00
|
|
|
use ManiaControl\Manialinks\ManialinkManager;
|
2013-12-14 22:00:59 +01:00
|
|
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
|
|
|
use ManiaControl\Players\Player;
|
2014-05-13 17:59:37 +02:00
|
|
|
use ManiaControl\Utils\ColorUtil;
|
|
|
|
use ManiaControl\Utils\Formatter;
|
2014-06-23 23:11:16 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\ChangeInProgressException;
|
2014-08-03 13:06:43 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\FileException;
|
2014-06-14 18:43:56 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\NextMapException;
|
2014-05-13 17:59:37 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\NotInListException;
|
2014-05-02 17:50:30 +02:00
|
|
|
use MCTeam\CustomVotesPlugin;
|
2014-04-27 16:22:12 +02:00
|
|
|
use MCTeam\KarmaPlugin;
|
2013-12-14 22:00:59 +01:00
|
|
|
|
2013-12-24 13:09:39 +01:00
|
|
|
/**
|
|
|
|
* MapList Widget Class
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2020-01-22 10:39:35 +01:00
|
|
|
* @copyright 2014-2020 ManiaControl Team
|
2014-05-02 17:50:30 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2013-12-24 13:09:39 +01:00
|
|
|
*/
|
2013-12-15 15:13:56 +01:00
|
|
|
class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2013-12-18 15:48:33 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
2018-07-11 17:49:00 +02:00
|
|
|
const ACTION_UPDATE_MAP = 'MapList.UpdateMap';
|
|
|
|
const ACTION_REMOVE_MAP = 'MapList.RemoveMap';
|
|
|
|
const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
|
|
|
|
const ACTION_START_SWITCH_VOTE = 'MapList.StartMapSwitchVote';
|
|
|
|
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 ACTION_PAGING_CHUNKS = 'MapList.PagingChunk.';
|
|
|
|
const ACTION_SEARCH_MAP_NAME = 'MapList.SearchMapName';
|
|
|
|
const ACTION_SEARCH_AUTHOR = 'MapList.SearchAuthor';
|
|
|
|
const ACTION_RESET = 'MapList.ResetMapList';
|
|
|
|
const MAX_PAGES_PER_CHUNK = 2;
|
|
|
|
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
|
|
|
|
const CACHE_CURRENT_PAGE = 'CurrentPage';
|
|
|
|
const WIDGET_NAME = 'MapList';
|
2023-10-09 10:18:33 +02:00
|
|
|
const SETTING_PERMISSION_MAPLIST = 'Show the Map List';
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-07-25 16:28:47 +02:00
|
|
|
* Private properties
|
2013-12-14 22:00:59 +01:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2014-04-27 18:59:21 +02:00
|
|
|
private $maniaControl = null;
|
2013-12-14 22:00:59 +01:00
|
|
|
|
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Construct a new map list instance
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2013-12-14 22:00:59 +01:00
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2023-10-09 10:18:33 +02:00
|
|
|
// Permissions
|
|
|
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_MAPLIST, AuthenticationManager::AUTH_LEVEL_PLAYER, AuthenticationManager::AUTH_LEVEL_PLAYER);
|
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Callbacks
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(MapQueue::CB_MAPQUEUE_CHANGED, $this, 'updateWidget');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'updateWidget');
|
|
|
|
|
|
|
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_CHECK_UPDATE, $this, 'checkUpdates');
|
|
|
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue');
|
2017-04-12 17:56:43 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SEARCH_MAP_NAME, $this, 'searchByMapName');
|
|
|
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SEARCH_AUTHOR, $this, 'searchByAuthor');
|
2017-05-07 20:46:12 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_RESET, $this, 'resetMapList');
|
2017-04-12 17:56:43 +02:00
|
|
|
|
2013-12-14 22:00:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-17 22:35:14 +01:00
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Clear the Map Queue
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
2014-01-17 22:35:14 +01:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
2014-04-27 18:59:21 +02:00
|
|
|
public function clearMapQueue(array $chatCallback, Player $player) {
|
|
|
|
// Clears the Map Queue
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getMapManager()->getMapQueue()->clearMapQueue($player);
|
2014-01-17 22:35:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for Map Updates
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
2014-01-17 22:35:14 +01:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function checkUpdates(array $chatCallback, Player $player) {
|
2014-04-27 18:59:21 +02:00
|
|
|
// Update Mx Infos
|
2023-08-14 18:18:10 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_CHECK_UPDATE)) return;
|
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getMapManager()->getMXManager()->fetchManiaExchangeMapInformation();
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-27 18:59:21 +02:00
|
|
|
// Reshow the Maplist
|
2014-01-17 22:35:14 +01:00
|
|
|
$this->showMapList($player);
|
|
|
|
}
|
2014-01-09 16:41:17 +01:00
|
|
|
|
2013-12-15 11:29:49 +01:00
|
|
|
/**
|
2014-04-28 16:59:55 +02:00
|
|
|
* Display a MapList on the Screen
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2013-12-15 11:29:49 +01:00
|
|
|
* @param Player $player
|
2014-05-27 22:32:54 +02:00
|
|
|
* @param Map[] $mapList
|
2014-05-09 19:05:08 +02:00
|
|
|
* @param int $pageIndex
|
2013-12-15 11:29:49 +01:00
|
|
|
*/
|
2022-04-03 11:57:36 +02:00
|
|
|
public function showMapList(Player $player, $mapList = null, $pageIndex = -1, $entryvalue = "") {
|
2023-10-09 10:18:33 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_MAPLIST)) return;
|
|
|
|
|
2017-04-01 18:48:36 +02:00
|
|
|
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
|
|
|
|
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
|
2023-09-08 12:19:12 +02:00
|
|
|
$buttonY = $height * -0.39;
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-09 19:05:08 +02:00
|
|
|
if ($pageIndex < 0) {
|
2015-01-21 17:47:29 +01:00
|
|
|
$pageIndex = (int) $player->getCache($this, self::CACHE_CURRENT_PAGE);
|
2014-05-09 19:05:08 +02:00
|
|
|
}
|
2014-05-18 16:27:08 +02:00
|
|
|
$player->setCache($this, self::CACHE_CURRENT_PAGE, $pageIndex);
|
2014-08-13 11:05:52 +02:00
|
|
|
$queueBuffer = $this->maniaControl->getMapManager()->getMapQueue()->getQueueBuffer();
|
2014-05-09 19:05:08 +02:00
|
|
|
|
|
|
|
$chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex);
|
|
|
|
$mapsBeginIndex = $this->getChunkMapsBeginIndex($chunkIndex);
|
2023-09-08 12:19:12 +02:00
|
|
|
$pageMaxCount = $this->getMapPerPage();
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-28 19:28:17 +01:00
|
|
|
// Get Maps
|
2014-05-09 19:05:08 +02:00
|
|
|
if (!is_array($mapList)) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$mapList = $this->maniaControl->getMapManager()->getMaps();
|
2014-04-28 16:59:55 +02:00
|
|
|
}
|
2023-09-08 12:19:12 +02:00
|
|
|
$mapList = array_slice($mapList, $mapsBeginIndex, self::MAX_PAGES_PER_CHUNK * $pageMaxCount);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$totalMapsCount = $this->maniaControl->getMapManager()->getMapsCount();
|
2023-09-08 12:19:12 +02:00
|
|
|
$pagesCount = ceil($totalMapsCount / $pageMaxCount);
|
2014-05-09 09:37:37 +02:00
|
|
|
|
2014-04-27 18:59:21 +02:00
|
|
|
// Create ManiaLink
|
2014-01-28 19:28:17 +01:00
|
|
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
2014-05-02 17:50:30 +02:00
|
|
|
$script = $maniaLink->getScript();
|
|
|
|
$paging = new Paging();
|
2014-04-27 18:59:21 +02:00
|
|
|
$script->addFeature($paging);
|
2014-05-09 19:05:08 +02:00
|
|
|
$paging->setCustomMaxPageNumber($pagesCount);
|
2014-04-28 16:59:55 +02:00
|
|
|
$paging->setChunkActionAppendsPageNumber(true);
|
|
|
|
$paging->setChunkActions(self::ACTION_PAGING_CHUNKS);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-28 19:28:17 +01:00
|
|
|
// Main frame
|
2014-08-13 11:05:52 +02:00
|
|
|
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
|
2017-03-25 19:15:50 +01:00
|
|
|
$maniaLink->addChild($frame);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-27 18:59:21 +02:00
|
|
|
// Admin Buttons
|
2017-04-01 18:48:36 +02:00
|
|
|
if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
2020-05-07 18:39:27 +02:00
|
|
|
$clearMapQueueButton = $this->maniaControl->getManialinkManager()->getElementBuilder()->buildRoundTextButton(
|
|
|
|
'Clear Map-Queue',
|
|
|
|
30,
|
|
|
|
4,
|
|
|
|
self::ACTION_CLEAR_MAPQUEUE
|
|
|
|
);
|
|
|
|
$frame->addChild($clearMapQueueButton);
|
|
|
|
$clearMapQueueButton->setPosition($width/2 - 5 - 30/2, $buttonY);
|
2014-01-28 20:14:21 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2017-04-01 18:48:36 +02:00
|
|
|
if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_CHECK_UPDATE)) {
|
2020-05-07 18:39:27 +02:00
|
|
|
$mxCheckForUpdatesButton = $this->maniaControl->getManialinkManager()->getElementBuilder()->buildRoundTextButton(
|
|
|
|
'Check MX for Updates',
|
|
|
|
36,
|
|
|
|
4,
|
|
|
|
self::ACTION_CHECK_UPDATE,
|
|
|
|
$this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_GREEN)
|
|
|
|
);
|
|
|
|
$frame->addChild($mxCheckForUpdatesButton);
|
|
|
|
$mxCheckForUpdatesButton->setPosition($width/2 - 5 - 30 - 5 - 36/2, $buttonY);
|
2014-01-17 22:35:14 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2017-04-01 18:48:36 +02:00
|
|
|
if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
2020-05-07 18:39:27 +02:00
|
|
|
$browserButton = $this->maniaControl->getManialinkManager()->getElementBuilder()->buildRoundTextButton(
|
|
|
|
'Directory Browser',
|
|
|
|
36,
|
|
|
|
4,
|
|
|
|
DirectoryBrowser::ACTION_SHOW
|
|
|
|
);
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($browserButton);
|
2020-05-07 18:39:27 +02:00
|
|
|
$browserButton->setPosition(-$width/2 + 5 + 36/2, $buttonY);
|
2014-06-30 00:33:11 +02:00
|
|
|
}
|
|
|
|
|
2014-01-06 15:54:22 +01:00
|
|
|
// Headline
|
2013-12-15 11:55:44 +01:00
|
|
|
$headFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($headFrame);
|
2014-01-06 15:54:22 +01:00
|
|
|
$headFrame->setY($height / 2 - 5);
|
2017-04-01 18:48:36 +02:00
|
|
|
$posX = -$width / 2;
|
|
|
|
|
|
|
|
$labelLine = new LabelLine($headFrame);
|
|
|
|
$labelLine->addLabelEntryText('Id', $posX + 5);
|
|
|
|
$labelLine->addLabelEntryText('Mx Id', $posX + 10);
|
2018-07-11 17:49:00 +02:00
|
|
|
$labelLine->addLabelEntryText('Map Name', $posX + 20);
|
|
|
|
$labelLine->addLabelEntryText('Author', $posX + 68);
|
2017-04-01 18:48:36 +02:00
|
|
|
$labelLine->addLabelEntryText('Actions', $width / 2 - 16);
|
2017-04-12 17:56:43 +02:00
|
|
|
$labelLine->setY(-7);
|
2017-04-01 18:48:36 +02:00
|
|
|
$labelLine->render();
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2022-04-03 11:57:36 +02:00
|
|
|
$searchFrame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMapSearch(self::ACTION_SEARCH_MAP_NAME, self::ACTION_SEARCH_AUTHOR, self::ACTION_RESET, $entryvalue);
|
2017-04-12 17:56:43 +02:00
|
|
|
$headFrame->addChild($searchFrame);
|
|
|
|
|
2014-04-27 18:59:21 +02:00
|
|
|
// Predefine description Label
|
2014-08-13 11:05:52 +02:00
|
|
|
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($descriptionLabel);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$queuedMaps = $this->maniaControl->getMapManager()->getMapQueue()->getQueuedMapsRanking();
|
2014-04-28 16:59:55 +02:00
|
|
|
|
2014-05-09 19:05:08 +02:00
|
|
|
$pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK;
|
|
|
|
$paging->setStartPageNumber($pageIndex + 1);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-18 16:27:08 +02:00
|
|
|
$index = 0;
|
2014-06-14 15:48:27 +02:00
|
|
|
$mapListId = 1 + $mapsBeginIndex;
|
2017-04-12 17:56:43 +02:00
|
|
|
$posY = $height / 2 - 16;
|
2014-05-15 17:45:08 +02:00
|
|
|
$pageFrame = null;
|
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
|
|
|
|
$mxIcon = $this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON);
|
|
|
|
$mxIconHover = $this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_MOVER);
|
|
|
|
$mxIconGreen = $this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_GREEN);
|
|
|
|
$mxIconGreenHover = $this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_GREEN_MOVER);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-27 18:59:21 +02:00
|
|
|
foreach ($mapList as $map) {
|
2014-06-14 15:48:27 +02:00
|
|
|
/** @var Map $map */
|
2023-09-08 12:19:12 +02:00
|
|
|
if ($index % $pageMaxCount === 0) {
|
2014-01-02 20:50:09 +01:00
|
|
|
$pageFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($pageFrame);
|
2017-04-12 17:56:43 +02:00
|
|
|
$posY = $height / 2 - 16;
|
2017-03-25 18:40:15 +01:00
|
|
|
$paging->addPageControl($pageFrame, $pageNumber);
|
2014-04-28 16:59:55 +02:00
|
|
|
$pageNumber++;
|
2014-01-02 20:50:09 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-06 15:54:22 +01:00
|
|
|
// Map Frame
|
2013-12-14 22:00:59 +01:00
|
|
|
$mapFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$pageFrame->addChild($mapFrame);
|
2014-06-14 15:48:27 +02:00
|
|
|
$mapFrame->setY($posY);
|
2013-12-30 16:58:35 +01:00
|
|
|
$mapFrame->setZ(0.1);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
if ($mapListId % 2 !== 0) {
|
2013-12-31 02:27:40 +01:00
|
|
|
$lineQuad = new Quad_BgsPlayerCard();
|
2017-03-25 19:15:50 +01:00
|
|
|
$mapFrame->addChild($lineQuad);
|
2014-01-06 15:54:22 +01:00
|
|
|
$lineQuad->setSize($width, 4);
|
2013-12-31 02:27:40 +01:00
|
|
|
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
|
2017-04-11 12:28:04 +02:00
|
|
|
$lineQuad->setZ(-0.1);
|
2013-12-31 02:27:40 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-19 22:05:18 +02:00
|
|
|
if ($currentMap === $map) {
|
2013-12-30 16:58:35 +01:00
|
|
|
$currentQuad = new Quad_Icons64x64_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$mapFrame->addChild($currentQuad);
|
2014-06-14 15:48:27 +02:00
|
|
|
$currentQuad->setX($posX + 3.5);
|
2013-12-30 16:58:35 +01:00
|
|
|
$currentQuad->setZ(0.2);
|
|
|
|
$currentQuad->setSize(4, 4);
|
|
|
|
$currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue);
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2013-12-30 16:58:35 +01:00
|
|
|
$mxId = '-';
|
2014-01-27 21:27:31 +01:00
|
|
|
if (isset($map->mx->id)) {
|
2013-12-30 16:58:35 +01:00
|
|
|
$mxId = $map->mx->id;
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-12 00:28:06 +01:00
|
|
|
$mxQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$mapFrame->addChild($mxQuad);
|
2014-01-12 00:28:06 +01:00
|
|
|
$mxQuad->setSize(3, 3);
|
2017-03-25 19:15:50 +01:00
|
|
|
$mxQuad->setImageUrl($mxIcon);
|
|
|
|
$mxQuad->setImageFocusUrl($mxIconHover);
|
2014-06-14 15:48:27 +02:00
|
|
|
$mxQuad->setX($posX + 65);
|
2014-01-12 00:28:06 +01:00
|
|
|
$mxQuad->setUrl($map->mx->pageurl);
|
|
|
|
$mxQuad->setZ(0.01);
|
2014-08-03 01:34:18 +02:00
|
|
|
$description = 'View ' . $map->getEscapedName() . ' on Mania-Exchange';
|
2014-04-27 18:59:21 +02:00
|
|
|
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-27 21:27:31 +01:00
|
|
|
if ($map->updateAvailable()) {
|
2014-01-12 00:28:06 +01:00
|
|
|
$mxQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$mapFrame->addChild($mxQuad);
|
2014-01-12 00:28:06 +01:00
|
|
|
$mxQuad->setSize(3, 3);
|
2017-03-25 19:15:50 +01:00
|
|
|
$mxQuad->setImageUrl($mxIconGreen);
|
|
|
|
$mxQuad->setImageFocusUrl($mxIconGreenHover);
|
2014-06-14 15:48:27 +02:00
|
|
|
$mxQuad->setX($posX + 62);
|
2014-01-12 00:28:06 +01:00
|
|
|
$mxQuad->setUrl($map->mx->pageurl);
|
|
|
|
$mxQuad->setZ(0.01);
|
2014-08-03 01:34:18 +02:00
|
|
|
$description = 'Update for ' . $map->getEscapedName() . ' available on Mania-Exchange!';
|
2014-04-27 18:59:21 +02:00
|
|
|
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-27 18:59:21 +02:00
|
|
|
// Update Button
|
2017-04-01 18:48:36 +02:00
|
|
|
if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
2014-01-15 20:49:01 +01:00
|
|
|
$mxQuad->setAction(self::ACTION_UPDATE_MAP . '.' . $map->uid);
|
|
|
|
}
|
2014-01-12 00:28:06 +01:00
|
|
|
}
|
2014-01-02 10:38:46 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-06 15:54:22 +01:00
|
|
|
// Display Maps
|
2017-04-01 18:48:36 +02:00
|
|
|
$labelLine = new LabelLine($mapFrame);
|
|
|
|
$labelLine->addLabelEntryText($mapListId, $posX + 5, 5);
|
|
|
|
$labelLine->addLabelEntryText($mxId, $posX + 10, 10);
|
2018-07-11 17:49:00 +02:00
|
|
|
$labelLine->addLabelEntryText(Formatter::stripDirtyCodes($map->name), $posX + 20, 42);
|
2017-04-01 18:48:36 +02:00
|
|
|
|
|
|
|
$label = new Label_Text();
|
|
|
|
$mapFrame->addChild($label);
|
|
|
|
$label->setText($map->authorNick);
|
2018-07-11 17:49:00 +02:00
|
|
|
$label->setX($posX + 68);
|
2017-04-01 18:48:36 +02:00
|
|
|
$label->setSize(47, 0);
|
|
|
|
$label->setAction(MapCommands::ACTION_SHOW_AUTHOR . $map->authorLogin);
|
|
|
|
$description = 'Click to checkout all maps by $<' . $map->authorLogin . '$>!';
|
|
|
|
$label->addTooltipLabelFeature($descriptionLabel, $description);
|
|
|
|
$labelLine->addLabel($label);
|
|
|
|
|
|
|
|
$labelLine->render();
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-09 19:00:37 +01:00
|
|
|
// TODO action detailed map info including mx info
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-06 15:54:22 +01:00
|
|
|
// Map-Queue-Map-Label
|
2014-01-27 21:27:31 +01:00
|
|
|
if (isset($queuedMaps[$map->uid])) {
|
2013-12-31 12:36:49 +01:00
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$mapFrame->addChild($label);
|
2014-05-09 11:58:33 +02:00
|
|
|
$label->setX($width / 2 - 13);
|
2013-12-31 12:36:49 +01:00
|
|
|
$label->setZ(0.2);
|
|
|
|
$label->setTextSize(1.5);
|
|
|
|
$label->setText($queuedMaps[$map->uid]);
|
2014-01-06 15:54:22 +01:00
|
|
|
$label->setTextColor('fff');
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-24 20:39:18 +02:00
|
|
|
// Checks if the Player who opened the Widget has queued the map
|
2014-08-13 11:05:52 +02:00
|
|
|
$queuer = $this->maniaControl->getMapManager()->getMapQueue()->getQueuer($map->uid);
|
2014-08-13 21:33:26 +02:00
|
|
|
if ($queuer && $queuer->login == $player->login) {
|
2014-08-03 01:34:18 +02:00
|
|
|
$description = 'Remove ' . $map->getEscapedName() . ' from the Map Queue';
|
2014-04-27 18:59:21 +02:00
|
|
|
$label->addTooltipLabelFeature($descriptionLabel, $description);
|
2014-01-28 20:09:09 +01:00
|
|
|
$label->setAction(self::ACTION_UNQUEUE_MAP . '.' . $map->uid);
|
2014-05-02 17:50:30 +02:00
|
|
|
} else {
|
2014-08-03 01:34:18 +02:00
|
|
|
$description = $map->getEscapedName() . ' is on Map-Queue Position: ' . $queuedMaps[$map->uid];
|
2014-04-27 18:59:21 +02:00
|
|
|
$label->addTooltipLabelFeature($descriptionLabel, $description);
|
|
|
|
}
|
2023-08-14 18:18:10 +02:00
|
|
|
} else if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapQueue::SETTING_PERMISSION_ADD_TO_QUEUE)) {
|
2014-01-06 15:54:22 +01:00
|
|
|
// Map-Queue-Map-Button
|
|
|
|
$queueLabel = new Label_Button();
|
2017-03-25 19:15:50 +01:00
|
|
|
$mapFrame->addChild($queueLabel);
|
2014-05-09 09:37:37 +02:00
|
|
|
$queueLabel->setX($width / 2 - 13);
|
2014-01-06 15:54:22 +01:00
|
|
|
$queueLabel->setZ(0.2);
|
|
|
|
$queueLabel->setSize(3, 3);
|
|
|
|
$queueLabel->setText('+');
|
2014-04-28 15:26:08 +02:00
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
if (in_array($map->uid, $queueBuffer)) {
|
2017-04-01 18:48:36 +02:00
|
|
|
if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
2014-04-28 15:26:08 +02:00
|
|
|
$queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid);
|
|
|
|
}
|
|
|
|
$queueLabel->setTextColor('f00');
|
2014-08-03 01:34:18 +02:00
|
|
|
$description = $map->getEscapedName() . ' has recently been played!';
|
2014-04-28 15:26:08 +02:00
|
|
|
$queueLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
|
|
|
} else {
|
|
|
|
$queueLabel->setTextColor('09f');
|
|
|
|
$queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid);
|
2014-08-03 01:34:18 +02:00
|
|
|
$description = 'Add ' . $map->getEscapedName() . ' to the Map Queue';
|
2014-04-28 15:26:08 +02:00
|
|
|
$queueLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
|
|
|
}
|
2014-01-06 15:54:22 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2017-04-01 18:48:36 +02:00
|
|
|
if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) {
|
2014-07-05 12:19:38 +02:00
|
|
|
// remove map button
|
|
|
|
$removeButton = new Label_Button();
|
2017-03-25 19:15:50 +01:00
|
|
|
$mapFrame->addChild($removeButton);
|
2014-07-05 12:19:38 +02:00
|
|
|
$removeButton->setX($width / 2 - 5);
|
|
|
|
$removeButton->setZ(0.2);
|
|
|
|
$removeButton->setSize(3, 3);
|
|
|
|
$removeButton->setTextSize(1);
|
|
|
|
$removeButton->setText('x');
|
|
|
|
$removeButton->setTextColor('a00');
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$confirmFrame = $this->buildConfirmFrame($maniaLink, $posY, $map->uid, true);
|
2014-07-05 12:19:38 +02:00
|
|
|
$removeButton->addToggleFeature($confirmFrame);
|
2014-08-03 01:34:18 +02:00
|
|
|
$description = 'Remove Map: ' . $map->getEscapedName();
|
2014-07-05 12:19:38 +02:00
|
|
|
$removeButton->addTooltipLabelFeature($descriptionLabel, $description);
|
2013-12-16 12:41:14 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2017-04-01 18:48:36 +02:00
|
|
|
if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
2014-07-05 12:19:38 +02:00
|
|
|
// Switch to button
|
2014-02-07 22:57:39 +01:00
|
|
|
$switchLabel = new Label_Button();
|
2017-03-25 19:15:50 +01:00
|
|
|
$mapFrame->addChild($switchLabel);
|
2014-05-09 09:37:37 +02:00
|
|
|
$switchLabel->setX($width / 2 - 9);
|
2014-02-07 22:57:39 +01:00
|
|
|
$switchLabel->setZ(0.2);
|
|
|
|
$switchLabel->setSize(3, 3);
|
|
|
|
$switchLabel->setTextSize(2);
|
|
|
|
$switchLabel->setText('»');
|
|
|
|
$switchLabel->setTextColor('0f0');
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$confirmFrame = $this->buildConfirmFrame($maniaLink, $posY, $map->uid);
|
2014-04-27 18:59:21 +02:00
|
|
|
$switchLabel->addToggleFeature($confirmFrame);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
$description = 'Switch Directly to Map: ' . $map->getEscapedName();
|
2014-04-27 18:59:21 +02:00
|
|
|
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
2014-05-03 21:12:44 +02:00
|
|
|
}
|
2017-04-01 18:48:36 +02:00
|
|
|
if ($this->maniaControl->getPluginManager()->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
|
|
|
|
if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
2014-05-03 21:12:44 +02:00
|
|
|
// Switch Map Voting for Admins
|
|
|
|
$switchQuad = new Quad_UIConstruction_Buttons();
|
2017-03-25 19:15:50 +01:00
|
|
|
$mapFrame->addChild($switchQuad);
|
2014-05-09 09:37:37 +02:00
|
|
|
$switchQuad->setX($width / 2 - 17);
|
2014-05-03 21:12:44 +02:00
|
|
|
$switchQuad->setZ(0.2);
|
|
|
|
$switchQuad->setSubStyle($switchQuad::SUBSTYLE_Validate_Step2);
|
|
|
|
$switchQuad->setSize(3.8, 3.8);
|
2014-05-08 23:43:30 +02:00
|
|
|
$switchQuad->setAction(self::ACTION_START_SWITCH_VOTE . '.' . $map->uid);
|
2014-05-03 21:12:44 +02:00
|
|
|
$description = 'Start Map-Switch Vote: $<' . $map->name . '$>';
|
|
|
|
$switchQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
|
|
|
} else {
|
|
|
|
// Switch Map Voting for Player
|
|
|
|
$switchLabel = new Label_Button();
|
2017-03-25 19:15:50 +01:00
|
|
|
$mapFrame->addChild($switchLabel);
|
2014-05-09 09:37:37 +02:00
|
|
|
$switchLabel->setX($width / 2 - 7);
|
2014-05-03 21:12:44 +02:00
|
|
|
$switchLabel->setZ(0.2);
|
|
|
|
$switchLabel->setSize(3, 3);
|
|
|
|
$switchLabel->setTextSize(2);
|
|
|
|
$switchLabel->setText('»');
|
|
|
|
$switchLabel->setTextColor('0f0');
|
2014-07-26 16:31:47 +02:00
|
|
|
$switchLabel->setAction(self::ACTION_START_SWITCH_VOTE . '.' . $map->uid);
|
|
|
|
$description = 'Start Map-Switch Vote: ' . $map->getEscapedName();
|
2014-05-03 21:12:44 +02:00
|
|
|
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
|
|
|
}
|
2013-12-16 12:41:14 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-06 15:54:22 +01:00
|
|
|
// Display Karma bar
|
2020-04-24 18:52:18 +02:00
|
|
|
$karmaGauge = $this->maniaControl->getManialinkManager()->getElementBuilder()->buildKarmaGauge(
|
|
|
|
$map,
|
|
|
|
20,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
if ($karmaGauge) {
|
|
|
|
$mapFrame->addChild($karmaGauge);
|
|
|
|
$karmaGauge->setX($posX + 120);
|
2013-12-29 19:21:29 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$posY -= 4;
|
|
|
|
$mapListId++;
|
2014-05-16 20:31:50 +02:00
|
|
|
$index++;
|
2014-01-02 20:50:09 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, self::WIDGET_NAME);
|
2013-12-14 22:00:59 +01:00
|
|
|
}
|
|
|
|
|
2023-09-08 12:19:12 +02:00
|
|
|
/**
|
|
|
|
* Get number of maps per page
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getMapPerPage() {
|
|
|
|
$pageheight = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
|
|
|
|
return floor(($pageheight - 16 - $pageheight * 0.11) / 4);
|
|
|
|
}
|
|
|
|
|
2014-05-09 19:05:08 +02:00
|
|
|
/**
|
|
|
|
* Get the Chunk Index with the given Page Index
|
|
|
|
*
|
|
|
|
* @param int $pageIndex
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
private function getChunkIndexFromPageNumber($pageIndex) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$mapsCount = $this->maniaControl->getMapManager()->getMapsCount();
|
2023-09-08 12:19:12 +02:00
|
|
|
$pagesCount = ceil($mapsCount / $this->getMapPerPage());
|
2014-05-09 19:05:08 +02:00
|
|
|
if ($pageIndex > $pagesCount - 1) {
|
|
|
|
$pageIndex = $pagesCount - 1;
|
|
|
|
}
|
|
|
|
return floor($pageIndex / self::MAX_PAGES_PER_CHUNK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the First Map Index to show for the given Chunk
|
|
|
|
*
|
|
|
|
* @param int $chunkIndex
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
private function getChunkMapsBeginIndex($chunkIndex) {
|
2023-09-08 12:19:12 +02:00
|
|
|
return $chunkIndex * self::MAX_PAGES_PER_CHUNK * $this->getMapPerPage();
|
2014-05-09 19:05:08 +02:00
|
|
|
}
|
|
|
|
|
2014-01-03 18:04:46 +01:00
|
|
|
/**
|
|
|
|
* Builds the confirmation frame
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-01-03 18:04:46 +01:00
|
|
|
* @param ManiaLink $maniaLink
|
2014-06-14 15:48:27 +02:00
|
|
|
* @param float $posY
|
2014-05-02 17:50:30 +02:00
|
|
|
* @param bool $mapUid
|
2014-07-05 12:19:38 +02:00
|
|
|
* @param bool $remove
|
2014-01-03 18:04:46 +01:00
|
|
|
* @return Frame
|
|
|
|
*/
|
2014-07-05 12:19:38 +02:00
|
|
|
public function buildConfirmFrame(Manialink $maniaLink, $posY, $mapUid, $remove = false) {
|
2014-05-09 19:05:08 +02:00
|
|
|
// TODO: get rid of the confirm frame to decrease xml size & network usage
|
2014-07-04 18:09:20 +02:00
|
|
|
// SUGGESTION: just send them as own manialink again on clicking?
|
2014-05-09 19:05:08 +02:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
|
|
|
|
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowSubStyle();
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-03 18:04:46 +01:00
|
|
|
$confirmFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$maniaLink->addChild($confirmFrame);
|
2014-06-14 15:48:27 +02:00
|
|
|
$confirmFrame->setPosition($width / 2 + 6, $posY);
|
2014-01-12 01:59:23 +01:00
|
|
|
$confirmFrame->setVisible(false);
|
2017-04-01 17:22:38 +02:00
|
|
|
$confirmFrame->setZ(ManialinkManager::MAIN_MANIALINK_Z_VALUE);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-03 18:04:46 +01:00
|
|
|
$quad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$confirmFrame->addChild($quad);
|
2014-01-06 15:54:22 +01:00
|
|
|
$quad->setStyles($quadStyle, $quadSubstyle);
|
2014-01-03 18:04:46 +01:00
|
|
|
$quad->setSize(12, 4);
|
2017-04-01 17:22:38 +02:00
|
|
|
$quad->setZ(-0.5);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-03 18:04:46 +01:00
|
|
|
$quad = new Quad_BgsPlayerCard();
|
2017-03-25 19:15:50 +01:00
|
|
|
$confirmFrame->addChild($quad);
|
2014-01-03 18:04:46 +01:00
|
|
|
$quad->setSubStyle($quad::SUBSTYLE_BgCardSystem);
|
|
|
|
$quad->setSize(11, 3.5);
|
2017-04-01 17:22:38 +02:00
|
|
|
$quad->setZ(-0.3);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-03 18:04:46 +01:00
|
|
|
$label = new Label_Button();
|
2017-03-25 19:15:50 +01:00
|
|
|
$confirmFrame->addChild($label);
|
2014-01-06 15:54:22 +01:00
|
|
|
$label->setText('Sure?');
|
2014-01-03 18:04:46 +01:00
|
|
|
$label->setTextSize(1);
|
|
|
|
$label->setScale(0.90);
|
|
|
|
$label->setX(-1.3);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-03 18:04:46 +01:00
|
|
|
$buttLabel = new Label_Button();
|
2017-03-25 19:15:50 +01:00
|
|
|
$confirmFrame->addChild($buttLabel);
|
2014-01-03 18:04:46 +01:00
|
|
|
$buttLabel->setPosition(3.2, 0.4, 0.2);
|
|
|
|
$buttLabel->setSize(3, 3);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-07-05 12:19:38 +02:00
|
|
|
if ($remove) {
|
2014-01-03 18:04:46 +01:00
|
|
|
$buttLabel->setTextSize(1);
|
2014-01-06 15:54:22 +01:00
|
|
|
$buttLabel->setTextColor('a00');
|
2014-07-05 12:19:38 +02:00
|
|
|
$buttLabel->setText('x');
|
|
|
|
$quad->setAction(self::ACTION_REMOVE_MAP . '.' . $mapUid);
|
|
|
|
} else {
|
|
|
|
$buttLabel->setTextSize(2);
|
|
|
|
$buttLabel->setTextColor('0f0');
|
|
|
|
$buttLabel->setText('»');
|
|
|
|
$quad->setAction(self::ACTION_SWITCH_MAP . '.' . $mapUid);
|
2014-01-03 18:04:46 +01:00
|
|
|
}
|
|
|
|
return $confirmFrame;
|
|
|
|
}
|
|
|
|
|
2014-01-11 17:24:03 +01:00
|
|
|
/**
|
|
|
|
* Unset the player if he opened another Main Widget
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-02-19 17:37:37 +01:00
|
|
|
* @param Player $player
|
2014-05-09 19:05:08 +02:00
|
|
|
* @param string $openedWidget
|
2014-01-11 17:24:03 +01:00
|
|
|
*/
|
2014-02-19 17:37:37 +01:00
|
|
|
public function handleWidgetOpened(Player $player, $openedWidget) {
|
2014-04-27 18:59:21 +02:00
|
|
|
// unset when another main widget got opened
|
2014-05-18 16:27:08 +02:00
|
|
|
if ($openedWidget !== self::WIDGET_NAME) {
|
|
|
|
$player->destroyCache($this, self::CACHE_CURRENT_PAGE);
|
2014-01-11 17:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-12 00:28:06 +01:00
|
|
|
|
2013-12-15 11:29:49 +01:00
|
|
|
/**
|
2014-05-09 19:05:08 +02:00
|
|
|
* Close the widget
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-05-09 19:05:08 +02:00
|
|
|
* @param Player $player
|
2013-12-15 11:29:49 +01:00
|
|
|
*/
|
2014-02-19 17:37:37 +01:00
|
|
|
public function closeWidget(Player $player) {
|
2014-05-09 19:05:08 +02:00
|
|
|
// TODO: resolve duplicate with 'playerCloseWidget'
|
2014-05-18 16:27:08 +02:00
|
|
|
$player->destroyCache($this, self::CACHE_CURRENT_PAGE);
|
2014-01-03 18:04:46 +01:00
|
|
|
}
|
|
|
|
|
2013-12-15 15:13:56 +01:00
|
|
|
/**
|
2014-01-06 15:54:22 +01:00
|
|
|
* Handle ManialinkPageAnswer Callback
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2013-12-15 15:13:56 +01:00
|
|
|
* @param array $callback
|
|
|
|
*/
|
2014-01-02 10:38:46 +01:00
|
|
|
public function handleManialinkPageAnswer(array $callback) {
|
2014-05-02 17:50:30 +02:00
|
|
|
$actionId = $callback[1][2];
|
2014-01-06 15:54:22 +01:00
|
|
|
$actionArray = explode('.', $actionId);
|
2014-01-27 21:27:31 +01:00
|
|
|
if (count($actionArray) <= 2) {
|
2014-01-08 18:07:09 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-06 15:54:22 +01:00
|
|
|
$action = $actionArray[0] . '.' . $actionArray[1];
|
2014-05-02 17:50:30 +02:00
|
|
|
$login = $callback[1][1];
|
2014-08-13 11:05:52 +02:00
|
|
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
2014-05-08 23:43:30 +02:00
|
|
|
$mapUid = $actionArray[2];
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-27 18:59:21 +02:00
|
|
|
switch ($action) {
|
2014-01-12 21:39:27 +01:00
|
|
|
case self::ACTION_UPDATE_MAP:
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getMapManager()->updateMap($player, $mapUid);
|
2014-05-08 22:33:01 +02:00
|
|
|
$this->showMapList($player);
|
2014-01-12 21:39:27 +01:00
|
|
|
break;
|
2014-07-05 12:19:38 +02:00
|
|
|
case self::ACTION_REMOVE_MAP:
|
2014-08-03 13:06:43 +02:00
|
|
|
try {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getMapManager()->removeMap($player, $mapUid);
|
2014-08-03 13:06:43 +02:00
|
|
|
} catch (FileException $e) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendException($e, $player);
|
2014-08-03 13:06:43 +02:00
|
|
|
}
|
2014-01-02 10:38:46 +01:00
|
|
|
break;
|
|
|
|
case self::ACTION_SWITCH_MAP:
|
2023-08-14 18:18:10 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_SKIP_MAP)) return;
|
|
|
|
|
2014-06-14 18:43:56 +02:00
|
|
|
// Don't queue on Map-Change
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getMapManager()->getMapQueue()->dontQueueNextMapChange();
|
2014-01-25 23:33:39 +01:00
|
|
|
try {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getClient()->jumpToMapIdent($mapUid);
|
2020-05-27 00:01:36 +02:00
|
|
|
} catch (NextMapException $e) {
|
|
|
|
$this->maniaControl->getChat()->sendException($e, $player);
|
2014-01-25 23:33:39 +01:00
|
|
|
break;
|
2020-05-27 00:01:36 +02:00
|
|
|
} catch (NotInListException $e) {
|
2014-07-19 23:55:01 +02:00
|
|
|
// TODO: "Map not found." -> how is that possible?
|
2020-05-27 00:01:36 +02:00
|
|
|
$this->maniaControl->getChat()->sendException($e, $player);
|
2014-07-19 23:55:01 +02:00
|
|
|
break;
|
2014-01-25 23:33:39 +01:00
|
|
|
}
|
2014-05-08 23:43:30 +02:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$map = $this->maniaControl->getMapManager()->getMapByUid($mapUid);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2020-05-27 00:01:36 +02:00
|
|
|
$message = $this->maniaControl->getChat()->formatMessage(
|
|
|
|
'%s skipped to Map %s!',
|
|
|
|
$player,
|
|
|
|
$map
|
|
|
|
);
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendSuccess($message);
|
2014-08-05 02:08:41 +02:00
|
|
|
Logger::logInfo($message, true);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-03 18:04:46 +01:00
|
|
|
$this->playerCloseWidget($player);
|
2014-01-02 10:38:46 +01:00
|
|
|
break;
|
2014-02-07 22:57:39 +01:00
|
|
|
case self::ACTION_START_SWITCH_VOTE:
|
2014-05-09 19:05:08 +02:00
|
|
|
/** @var CustomVotesPlugin $votesPlugin */
|
2014-08-13 11:05:52 +02:00
|
|
|
$votesPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
|
|
|
|
$map = $this->maniaControl->getMapManager()->getMapByUid($mapUid);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2020-05-27 00:01:36 +02:00
|
|
|
$message = $this->maniaControl->getChat()->formatMessage(
|
|
|
|
'%s started a vote to switch to Map %s!',
|
|
|
|
$player,
|
|
|
|
$map
|
|
|
|
);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$votesPlugin->defineVote('switchmap', 'Goto ' . $map->name, true, $message)->setStopCallback(Callbacks::ENDMAP);
|
2014-06-17 23:27:28 +02:00
|
|
|
$votesPlugin->startVote($player, 'switchmap', function ($result) use (&$votesPlugin, &$map) {
|
2020-05-27 00:01:36 +02:00
|
|
|
// will be only called, if successful
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2020-05-27 00:01:36 +02:00
|
|
|
$votesPlugin->undefineVote('switchmap');
|
|
|
|
|
|
|
|
// Don't queue on Map-Change
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getMapManager()->getMapQueue()->dontQueueNextMapChange();
|
2014-05-09 11:58:33 +02:00
|
|
|
|
2014-02-07 22:57:39 +01:00
|
|
|
try {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getClient()->JumpToMapIdent($map->uid);
|
2014-06-23 23:11:16 +02:00
|
|
|
} catch (NextMapException $exception) {
|
2014-06-23 16:17:39 +02:00
|
|
|
return;
|
2014-06-23 23:11:16 +02:00
|
|
|
} catch (NotInListException $exception) {
|
|
|
|
return;
|
|
|
|
} catch (ChangeInProgressException $exception) {
|
|
|
|
// TODO: delay skip if change is in progress
|
2014-06-23 16:17:39 +02:00
|
|
|
return;
|
2014-02-07 22:57:39 +01:00
|
|
|
}
|
2014-06-23 16:17:39 +02:00
|
|
|
|
2020-05-27 00:01:36 +02:00
|
|
|
$this->maniaControl->getChat()->sendSuccess('Vote Successful -> Map switched!');
|
2014-02-07 22:57:39 +01:00
|
|
|
});
|
|
|
|
break;
|
2014-01-02 10:38:46 +01:00
|
|
|
case self::ACTION_QUEUED_MAP:
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getMapManager()->getMapQueue()->addMapToMapQueue($callback[1][1], $mapUid);
|
2014-04-29 22:30:29 +02:00
|
|
|
$this->showMapList($player);
|
2014-01-02 10:38:46 +01:00
|
|
|
break;
|
2014-01-28 20:09:09 +01:00
|
|
|
case self::ACTION_UNQUEUE_MAP:
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getMapManager()->getMapQueue()->removeFromMapQueue($player, $mapUid);
|
2014-04-29 22:30:29 +02:00
|
|
|
$this->showMapList($player);
|
2014-01-28 20:09:09 +01:00
|
|
|
break;
|
2014-04-28 16:59:55 +02:00
|
|
|
default:
|
|
|
|
if (substr($actionId, 0, strlen(self::ACTION_PAGING_CHUNKS)) === self::ACTION_PAGING_CHUNKS) {
|
|
|
|
// Paging chunks
|
2015-01-21 17:47:29 +01:00
|
|
|
$neededPage = (int) substr($actionId, strlen(self::ACTION_PAGING_CHUNKS));
|
2014-05-09 19:05:08 +02:00
|
|
|
$this->showMapList($player, null, $neededPage - 1);
|
2014-04-28 16:59:55 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-01-02 10:38:46 +01:00
|
|
|
}
|
2013-12-15 15:13:56 +01:00
|
|
|
}
|
2013-12-28 23:24:54 +01:00
|
|
|
|
2017-05-07 20:46:12 +02:00
|
|
|
/**
|
|
|
|
* Resets the Maplist to the original view, clears previous search results
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
public function resetMapList(array $callback) {
|
|
|
|
$login = $callback[1][1];
|
|
|
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
|
|
|
$this->showMapList($player);
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:56:43 +02:00
|
|
|
/**
|
|
|
|
* Listener for search button
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
public function searchByMapName(array $callback) {
|
2017-04-19 19:37:36 +02:00
|
|
|
$login = $callback[1][1];
|
2017-04-12 17:56:43 +02:00
|
|
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
|
|
|
|
|
|
|
$searchString = $callback[1][3][0]['Value'];
|
|
|
|
|
2017-05-07 20:46:12 +02:00
|
|
|
if ($searchString) {
|
|
|
|
$maps = $this->maniaControl->getMapManager()->searchMapsByMapName($searchString);
|
|
|
|
} else {
|
|
|
|
$maps = null;
|
|
|
|
}
|
2022-04-03 11:57:36 +02:00
|
|
|
$this->showMapList($player, $maps, -1, $searchString);
|
2017-05-07 20:46:12 +02:00
|
|
|
|
2017-04-12 17:56:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listener for search button
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
public function searchByAuthor(array $callback) {
|
2017-04-19 19:37:36 +02:00
|
|
|
$login = $callback[1][1];
|
2017-04-12 17:56:43 +02:00
|
|
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
|
|
|
|
|
|
|
$searchString = $callback[1][3][0]['Value'];
|
2017-05-14 17:12:48 +02:00
|
|
|
if ($searchString) {
|
|
|
|
$maps = $this->maniaControl->getMapManager()->searchMapsByAuthor($searchString);
|
|
|
|
} else {
|
|
|
|
$maps = null;
|
|
|
|
}
|
2017-04-12 17:56:43 +02:00
|
|
|
|
2022-04-03 11:57:36 +02:00
|
|
|
$this->showMapList($player, $maps, -1, $searchString);
|
2017-04-12 17:56:43 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
/**
|
2014-05-09 19:05:08 +02:00
|
|
|
* Close the widget for
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function playerCloseWidget(Player $player) {
|
2014-05-18 16:27:08 +02:00
|
|
|
$player->destroyCache($this, self::CACHE_CURRENT_PAGE);
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->closeWidget($player);
|
2014-05-02 17:50:30 +02:00
|
|
|
}
|
|
|
|
|
2013-12-28 23:24:54 +01:00
|
|
|
/**
|
2014-01-06 15:54:22 +01:00
|
|
|
* Reopen the widget on Map Begin, MapListChanged, etc.
|
2013-12-28 23:24:54 +01:00
|
|
|
*/
|
2014-02-19 15:44:00 +01:00
|
|
|
public function updateWidget() {
|
2014-08-13 11:05:52 +02:00
|
|
|
$players = $this->maniaControl->getPlayerManager()->getPlayers();
|
2014-05-18 16:27:08 +02:00
|
|
|
foreach ($players as $player) {
|
|
|
|
$currentPage = $player->getCache($this, self::CACHE_CURRENT_PAGE);
|
|
|
|
if ($currentPage !== null) {
|
|
|
|
$this->showMapList($player, null, $currentPage);
|
2013-12-28 23:24:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-30 00:33:11 +02:00
|
|
|
}
|