From 3b0f478e6e5952f217ea9a204e341c2ca0bb7570 Mon Sep 17 00:00:00 2001 From: kremsy Date: Sat, 28 Dec 2013 23:24:54 +0100 Subject: [PATCH] some parts of the jukebox --- application/core/Maps/Jukebox.php | 19 +++++++++------ application/core/Maps/Map.php | 6 ++--- application/core/Maps/MapList.php | 36 +++++++++++++++++++++++++--- application/core/Maps/MapManager.php | 5 +++- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/application/core/Maps/Jukebox.php b/application/core/Maps/Jukebox.php index 6f91c33f..64e6316f 100644 --- a/application/core/Maps/Jukebox.php +++ b/application/core/Maps/Jukebox.php @@ -79,16 +79,16 @@ class Jukebox implements CallbackListener { } public function endMap(){ - var_dump("endmap"); //TODO setting admin no skip //TODO setting skip map if requester left + //Skip Map if requester has left for($i = 0; $i < count($this->jukedMaps); $i++){ $jukedMap = reset($this->jukedMaps); //found player, so play this map - if($this->maniaControl->playerManager->getPlayer($jukedMap[0]) == null){ + if($this->maniaControl->playerManager->getPlayer($jukedMap[0]) != null){ break; } @@ -104,18 +104,23 @@ class Jukebox implements CallbackListener { $nextMap = array_shift($this->jukedMaps); //Check if Jukebox is empty - if(!isset($nextMap)) + if($nextMap == null) return; $nextMap = $nextMap[1]; - //var_dump($nextMap); - var_dump($nextMap->name); - $this->printAllMaps(); //Set pointer back to last map - end($this->jukedMaps); + //end($this->jukedMaps); + + $success = $this->maniaControl->client->query('ChooseNextMap', $nextMap->fileName); + if (!$success) { + trigger_error('[' . $this->maniaControl->client->getErrorCode() . '] ChooseNextMap - ' . $this->maniaControl->client->getErrorCode(), E_USER_WARNING); + return; + } + } + public function printAllMaps(){ foreach($this->jukedMaps as $map){ $map = $map[1]; diff --git a/application/core/Maps/Map.php b/application/core/Maps/Map.php index 890fa9fb..c4ecca81 100644 --- a/application/core/Maps/Map.php +++ b/application/core/Maps/Map.php @@ -46,7 +46,7 @@ class Map { * @param array $rpc_infos */ public function __construct(ManiaControl $maniaControl, $rpc_infos = null) { - // $this->maniaControl = $maniaControl; + $this->maniaControl = $maniaControl; $this->startTime = time(); if (!$rpc_infos) { @@ -67,7 +67,7 @@ class Map { $this->authorNick = $this->authorLogin; - /*$mapsDirectory = $this->maniaControl->server->getMapsDirectory(); + $mapsDirectory = $this->maniaControl->server->getMapsDirectory(); if ($this->maniaControl->server->checkAccess($mapsDirectory)) { $this->mapFetcher = new \GBXChallMapFetcher(true); try { @@ -86,6 +86,6 @@ class Map { // TODO: define timeout if mx is down,todo fetch all map infos at once (maybe way faster) $serverInfo = $this->maniaControl->server->getSystemInfo(); $title = strtoupper(substr($serverInfo['TitleId'], 0, 2)); - $this->mx = new \MXInfoFetcher($title, $this->uid, false);*/ + $this->mx = new \MXInfoFetcher($title, $this->uid, false); } } \ No newline at end of file diff --git a/application/core/Maps/MapList.php b/application/core/Maps/MapList.php index 32196156..7b60658d 100644 --- a/application/core/Maps/MapList.php +++ b/application/core/Maps/MapList.php @@ -36,12 +36,14 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { const ACTION_SWITCH_MAP = 'MapList.SwitchMap'; const ACTION_JUKE_MAP = 'MapList.JukeMap'; const MAX_MAPS_PER_PAGE = 15; - + const SHOW_MX_LIST = 1; + const SHOW_MAP_LIST = 2; /** * Private properties */ private $maniaControl = null; + private $mapListShown = array(); private $width; private $height; private $quadStyle; @@ -60,6 +62,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); + $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPLIST_UPDATED, $this, 'updateWidget'); + $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'updateWidget'); //TODO not working yet + //settings $this->width = 150; $this->height = 80; @@ -74,6 +79,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { * @param Player $player */ public function showManiaExchangeList(array $chatCallback, Player $player){ + $this->mapListShown[$player->login] = self::SHOW_MX_LIST; + $params = explode(' ', $chatCallback[1][2]); $serverInfo = $this->maniaControl->server->getSystemInfo(); @@ -210,6 +217,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { * @param Player $player */ public function showMapList(Player $player){ + $this->mapListShown[$player->login] = self::SHOW_MAP_LIST; + $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $frame = $this->buildMainFrame(); $maniaLink->add($frame); @@ -250,7 +259,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { $jukeQuad->setSize(4,4); $jukeQuad->setSubStyle($jukeQuad::SUBSTYLE_Erase); $jukeQuad->setAction(self::ACTION_JUKE_MAP . "." . $map->uid); - //TODO description and jukebox button + //TODO description and jukebox button, change quad style if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)){ //TODO SET as setting who can add maps //erase map quad @@ -348,7 +357,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { * @param Player $player */ public function closeWidget(array $callback, Player $player) { - //TODO update player things + unset($this->mapListShown[$player->login]); } /** @@ -385,4 +394,25 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { } } + + /** + * Reopen the widget on Map Begin, MapListChanged + * @param array $callback + */ + public function updateWidget(array $callback){ + foreach($this->mapListShown as $login => $shown){ + if($shown){ + $player = $this->maniaControl->playerManager->getPlayer($login); + if($player != null){ + if($shown == self::SHOW_MX_LIST){ + //TODO + }else if($shown == self::SHOW_MAP_LIST){ + $this->showMapList($player); + } + }else{ + unset($this->mapListShown[$login]); + } + } + } + } } \ No newline at end of file diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index 5de8ec11..18c8f81a 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -23,7 +23,7 @@ class MapManager implements CallbackListener { * Constants */ const TABLE_MAPS = 'mc_maps'; - + const CB_MAPLIST_UPDATED = 'MapManager.MapListUpdated'; /** * Private properties */ @@ -177,6 +177,9 @@ class MapManager implements CallbackListener { //restore Sorted Maplist $this->mapList = $tempList; + + // Trigger own callback + $this->maniaControl->callbackManager->triggerCallback(self::CB_MAPLIST_UPDATED, array(self::CB_MAPLIST_UPDATED)); } /**