From 6bb13fb2dfbcbc7eda87a98bf4a9435e18203355 Mon Sep 17 00:00:00 2001 From: kremsy Date: Sat, 14 Dec 2013 22:00:59 +0100 Subject: [PATCH] begin Maplist widget --- application/core/ManiaControl.php | 1 + application/core/Maps/Map.php | 9 +- application/core/Maps/MapCommands.php | 11 ++ application/core/Maps/MapList.php | 170 ++++++++++++++++++++ application/core/Maps/MapManager.php | 24 ++- application/core/Players/PlayerCommands.php | 3 +- application/core/Plugins/PluginMenu.php | 2 +- 7 files changed, 214 insertions(+), 6 deletions(-) create mode 100644 application/core/Maps/MapList.php diff --git a/application/core/ManiaControl.php b/application/core/ManiaControl.php index 0f26ac32..c7269f4e 100644 --- a/application/core/ManiaControl.php +++ b/application/core/ManiaControl.php @@ -33,6 +33,7 @@ require_once __DIR__ . '/ManiaExchange/mxinfosearcher.inc.php'; require_once __DIR__ . '/Manialinks/ManialinkManager.php'; require_once __DIR__ . '/Maps/Map.php'; require_once __DIR__ . '/Maps/MapManager.php'; +require_once __DIR__ . '/Maps/MapList.php'; require_once __DIR__ . '/Players/PlayerManager.php'; require_once __DIR__ . '/Plugins/PluginManager.php'; require_once __DIR__ . '/Server/Server.php'; diff --git a/application/core/Maps/Map.php b/application/core/Maps/Map.php index 7948436c..3f2c56e1 100644 --- a/application/core/Maps/Map.php +++ b/application/core/Maps/Map.php @@ -61,8 +61,10 @@ class Map { $this->copperPrice = $rpc_infos['CopperPrice']; $this->mapType = $rpc_infos['MapType']; $this->mapStyle = $rpc_infos['MapStyle']; - $this->nbCheckpoints = $rpc_infos['NbCheckpoints']; - + //$this->nbCheckpoints = $rpc_infos['NbCheckpoints']; //TODO check if key exists, only for trackmania + + $this->authorNick = $this->authorLogin; //initialize (if nick from map cant get readen) + $mapsDirectory = $this->maniaControl->server->getMapsDirectory(); if ($this->maniaControl->server->checkAccess($mapsDirectory)) { $this->mapFetcher = new \GBXChallMapFetcher(true); @@ -72,12 +74,13 @@ class Map { catch (\Exception $e) { trigger_error($e->getMessage(), E_USER_WARNING); } + $this->authorNick = $this->mapFetcher->authorNick; $this->authorEInfo = $this->mapFetcher->authorEInfo; $this->authorZone = $this->mapFetcher->authorZone; $this->comment = $this->mapFetcher->comment; } - + // TODO: define timeout if mx is down $serverInfo = $this->maniaControl->server->getSystemInfo(); $title = strtoupper(substr($serverInfo['TitleId'], 0, 2)); diff --git a/application/core/Maps/MapCommands.php b/application/core/Maps/MapCommands.php index bd286824..df36d698 100644 --- a/application/core/Maps/MapCommands.php +++ b/application/core/Maps/MapCommands.php @@ -7,6 +7,7 @@ use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Commands\CommandListener; use ManiaControl\FileUtil; use ManiaControl\Players\Player; +use ManiaControl\Players\PlayerManager; /** * Class offering commands to manage maps @@ -31,6 +32,9 @@ class MapCommands implements CommandListener { $this->maniaControl->commandManager->registerCommandListener('restartmap', $this, 'command_RestartMap',true); $this->maniaControl->commandManager->registerCommandListener('addmap', $this, 'command_AddMap',true); $this->maniaControl->commandManager->registerCommandListener('removemap', $this, 'command_RemoveMap',true); + + // Register for player commands + $this->maniaControl->commandManager->registerCommandListener('list', $this, 'command_list'); } /** @@ -183,6 +187,13 @@ class MapCommands implements CommandListener { } return $this->maniaControl->client->query('RestartMap'); } + + public function command_list(array $chatCallback, Player $player){ + // var_dump($chatCallback); + + $mapList = new MapList($this->maniaControl); + $mapList->showMapList($player); + } } ?> diff --git a/application/core/Maps/MapList.php b/application/core/Maps/MapList.php new file mode 100644 index 00000000..fdd2d7bb --- /dev/null +++ b/application/core/Maps/MapList.php @@ -0,0 +1,170 @@ +maniaControl = $maniaControl; + + + $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET , $this, + 'closeWidget'); + + // Register for player commands + //$this->maniaControl->commandManager->registerCommandListener('list', $this, 'command_list'); + } + + + + public function showMapList(Player $player){ + $maniaLink = new ManiaLink(self::MLID_WIDGET); + + //settings + $width = 150; + $height = 80; + $quadStyle = Quad_BgRaceScore2::STYLE; //TODO add default menu style to style manager + $quadSubstyle = Quad_BgRaceScore2::SUBSTYLE_HandleSelectable; + + //mainframe + $frame = new Frame(); + $maniaLink->add($frame); + $frame->setSize($width,$height); + $frame->setPosition(0, 0); + + //Background Quad + $backgroundQuad = new Quad(); + $frame->add($backgroundQuad); + $backgroundQuad->setSize($width,$height); + $backgroundQuad->setStyles($quadStyle, $quadSubstyle); + + //TODO headline + $mapList = $this->maniaControl->mapManager->getMapList(); + + $id = 1; + $y = $height / 2 - 10; + foreach($mapList as $map){ + $mapFrame = new Frame(); + $frame->add($mapFrame); + $this->displayMap($id, $map, $mapFrame, $width, $height); + $mapFrame->setY($y); + $y -= 4; + $id++; + } + + // Add Close Quad (X) + $closeQuad = new Quad_Icons64x64_1(); + $frame->add($closeQuad); + $closeQuad->setPosition($width * 0.483, $height * 0.467, 3); + $closeQuad->setSize(6, 6); + $closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace); + $closeQuad->setAction(self::ACTION_CLOSEWIDGET ); + + //render and display xml + $maniaLinkText = $maniaLink->render()->saveXML(); + $this->maniaControl->manialinkManager->sendManialink($maniaLinkText, $player->login); + $this->maniaControl->manialinkManager->disableAltMenu($player); + } + + private function displayMap($id, Map $map, Frame $frame, $width){ + + $frame->setZ(-0.01); + + $x = -$width / 2; + + //TODO detailed mx info page with link to mx + $x +=5; + $idLabel = new Label_Text(); + $frame->add($idLabel); + $idLabel->setHAlign(Control::LEFT); + $idLabel->setX($x); + // $mxIdLabel->setSize($width * 0.5, 2); + $idLabel->setStyle($idLabel::STYLE_TextCardSmall); + $idLabel->setTextSize(1.5); + $idLabel->setText($id); + $idLabel->setTextColor('FFF'); + + //TODO detailed mx info page with link to mx + $x +=5; + $mxIdLabel = new Label_Text(); + $frame->add($mxIdLabel); + $mxIdLabel->setHAlign(Control::LEFT); + $mxIdLabel->setX($x); + // $mxIdLabel->setSize($width * 0.5, 2); + $mxIdLabel->setStyle($mxIdLabel::STYLE_TextCardSmall); + $mxIdLabel->setTextSize(1.5); + if(isset($map->mx->id)) + $mxIdLabel->setText($map->mx->id); + else + $mxIdLabel->setText("-"); + $mxIdLabel->setTextColor('FFF'); + + //TODO action detailed map info + $x +=10; + $nameLabel = new Label_Text(); + $frame->add($nameLabel); + $nameLabel->setHAlign(Control::LEFT); + $nameLabel->setX($x); + //$nameLabel->setSize($width * 0.5, 2); + $nameLabel->setStyle($nameLabel::STYLE_TextCardSmall); + $nameLabel->setTextSize(1.5); + $nameLabel->setText($map->name); + + //TODO action detailed map info + $x +=50; + $authorLabel = new Label_Text(); + $frame->add($authorLabel); + $authorLabel->setHAlign(Control::LEFT); + $authorLabel->setX($x); + //$nameLabel->setSize($width * 0.5, 2); + $authorLabel->setStyle($authorLabel::STYLE_TextCardSmall); + $authorLabel->setTextSize(1.5); + $authorLabel->setText($map->authorNick); + $authorLabel->setTextColor('FFF'); + + + //TODO later add buttons for jukebox, admin control buttons (remove map, change to map) + //TODO side switch + //var_dump($map); + } + + + public function closeWidget(array $callback, Player $player) { + $emptyManialink = new ManiaLink(self::MLID_WIDGET); + $manialinkText = $emptyManialink->render()->saveXML(); + $this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login); + $this->maniaControl->manialinkManager->enableAltMenu($player); + unset($this->playersMenuShown[$player->login]); + } + +} \ No newline at end of file diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index a352a25e..54d00f0c 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -149,7 +149,18 @@ class MapManager implements CallbackListener { if (!$map) { return; } - $this->addMap($map); + $this->addMap($map); //TODO needed? + //var_dump($map); + //add Maplist on Init once + if(!$this->maniaControl->client->query('GetMapList', 100,0)){ //fetch 100 maps, first map is always current map + trigger_error("Couldn't fetch mapList. " . $this->maniaControl->getClientErrorText()); + return null; + } + $mapList = $this->maniaControl->client->getResponse(); + foreach($mapList as $rpcMap){ + $map = new Map($this->maniaControl, $rpcMap); + $this->addMap($map); + } } /** @@ -163,5 +174,16 @@ class MapManager implements CallbackListener { return; } $this->addMap($map); + + //TODO restrucutre, make current as first } + + + /** + * @return array + */ + public function getMapList(){ + return $this->mapList; + } + } diff --git a/application/core/Players/PlayerCommands.php b/application/core/Players/PlayerCommands.php index 4990c3b0..2219e4fb 100644 --- a/application/core/Players/PlayerCommands.php +++ b/application/core/Players/PlayerCommands.php @@ -2,6 +2,7 @@ namespace ManiaControl\Players; +use FML\Controls\Quad; use ManiaControl\ManiaControl; use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Commands\CommandListener; @@ -25,7 +26,7 @@ class PlayerCommands implements CommandListener { public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; - // Register for commands + // Register for admin commands $this->maniaControl->commandManager->registerCommandListener('teambalance', $this, 'command_TeamBalance',true); $this->maniaControl->commandManager->registerCommandListener('autoteambalance', $this, 'command_TeamBalance',true); $this->maniaControl->commandManager->registerCommandListener('kick', $this, 'command_Kick',true); diff --git a/application/core/Plugins/PluginMenu.php b/application/core/Plugins/PluginMenu.php index 7f1d2e18..72854695 100644 --- a/application/core/Plugins/PluginMenu.php +++ b/application/core/Plugins/PluginMenu.php @@ -99,7 +99,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu { array_push($pageFrames, $pageFrame); $y = $height * 0.41; } - + $active = $this->maniaControl->pluginManager->getPluginStatus($pluginClass); $pluginFrame = new Frame();