some parts of the jukebox

This commit is contained in:
kremsy 2013-12-28 23:24:54 +01:00
parent 19a8f3e2dc
commit 3b0f478e6e
4 changed files with 52 additions and 14 deletions

View File

@ -79,16 +79,16 @@ class Jukebox implements CallbackListener {
} }
public function endMap(){ public function endMap(){
var_dump("endmap");
//TODO setting admin no skip //TODO setting admin no skip
//TODO setting skip map if requester left //TODO setting skip map if requester left
//Skip Map if requester has left //Skip Map if requester has left
for($i = 0; $i < count($this->jukedMaps); $i++){ for($i = 0; $i < count($this->jukedMaps); $i++){
$jukedMap = reset($this->jukedMaps); $jukedMap = reset($this->jukedMaps);
//found player, so play this map //found player, so play this map
if($this->maniaControl->playerManager->getPlayer($jukedMap[0]) == null){ if($this->maniaControl->playerManager->getPlayer($jukedMap[0]) != null){
break; break;
} }
@ -104,18 +104,23 @@ class Jukebox implements CallbackListener {
$nextMap = array_shift($this->jukedMaps); $nextMap = array_shift($this->jukedMaps);
//Check if Jukebox is empty //Check if Jukebox is empty
if(!isset($nextMap)) if($nextMap == null)
return; return;
$nextMap = $nextMap[1]; $nextMap = $nextMap[1];
//var_dump($nextMap);
var_dump($nextMap->name);
$this->printAllMaps();
//Set pointer back to last map //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(){ public function printAllMaps(){
foreach($this->jukedMaps as $map){ foreach($this->jukedMaps as $map){
$map = $map[1]; $map = $map[1];

View File

@ -46,7 +46,7 @@ class Map {
* @param array $rpc_infos * @param array $rpc_infos
*/ */
public function __construct(ManiaControl $maniaControl, $rpc_infos = null) { public function __construct(ManiaControl $maniaControl, $rpc_infos = null) {
// $this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->startTime = time(); $this->startTime = time();
if (!$rpc_infos) { if (!$rpc_infos) {
@ -67,7 +67,7 @@ class Map {
$this->authorNick = $this->authorLogin; $this->authorNick = $this->authorLogin;
/*$mapsDirectory = $this->maniaControl->server->getMapsDirectory(); $mapsDirectory = $this->maniaControl->server->getMapsDirectory();
if ($this->maniaControl->server->checkAccess($mapsDirectory)) { if ($this->maniaControl->server->checkAccess($mapsDirectory)) {
$this->mapFetcher = new \GBXChallMapFetcher(true); $this->mapFetcher = new \GBXChallMapFetcher(true);
try { try {
@ -86,6 +86,6 @@ class Map {
// TODO: define timeout if mx is down,todo fetch all map infos at once (maybe way faster) // TODO: define timeout if mx is down,todo fetch all map infos at once (maybe way faster)
$serverInfo = $this->maniaControl->server->getSystemInfo(); $serverInfo = $this->maniaControl->server->getSystemInfo();
$title = strtoupper(substr($serverInfo['TitleId'], 0, 2)); $title = strtoupper(substr($serverInfo['TitleId'], 0, 2));
$this->mx = new \MXInfoFetcher($title, $this->uid, false);*/ $this->mx = new \MXInfoFetcher($title, $this->uid, false);
} }
} }

View File

@ -36,12 +36,14 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
const ACTION_SWITCH_MAP = 'MapList.SwitchMap'; const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
const ACTION_JUKE_MAP = 'MapList.JukeMap'; const ACTION_JUKE_MAP = 'MapList.JukeMap';
const MAX_MAPS_PER_PAGE = 15; const MAX_MAPS_PER_PAGE = 15;
const SHOW_MX_LIST = 1;
const SHOW_MAP_LIST = 2;
/** /**
* Private properties * Private properties
*/ */
private $maniaControl = null; private $maniaControl = null;
private $mapListShown = array();
private $width; private $width;
private $height; private $height;
private $quadStyle; private $quadStyle;
@ -60,6 +62,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,
'handleManialinkPageAnswer'); '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 //settings
$this->width = 150; $this->width = 150;
$this->height = 80; $this->height = 80;
@ -74,6 +79,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @param Player $player * @param Player $player
*/ */
public function showManiaExchangeList(array $chatCallback, Player $player){ public function showManiaExchangeList(array $chatCallback, Player $player){
$this->mapListShown[$player->login] = self::SHOW_MX_LIST;
$params = explode(' ', $chatCallback[1][2]); $params = explode(' ', $chatCallback[1][2]);
$serverInfo = $this->maniaControl->server->getSystemInfo(); $serverInfo = $this->maniaControl->server->getSystemInfo();
@ -210,6 +217,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @param Player $player * @param Player $player
*/ */
public function showMapList(Player $player){ public function showMapList(Player $player){
$this->mapListShown[$player->login] = self::SHOW_MAP_LIST;
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$frame = $this->buildMainFrame(); $frame = $this->buildMainFrame();
$maniaLink->add($frame); $maniaLink->add($frame);
@ -250,7 +259,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$jukeQuad->setSize(4,4); $jukeQuad->setSize(4,4);
$jukeQuad->setSubStyle($jukeQuad::SUBSTYLE_Erase); $jukeQuad->setSubStyle($jukeQuad::SUBSTYLE_Erase);
$jukeQuad->setAction(self::ACTION_JUKE_MAP . "." . $map->uid); $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 if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)){ //TODO SET as setting who can add maps
//erase map quad //erase map quad
@ -348,7 +357,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @param Player $player * @param Player $player
*/ */
public function closeWidget(array $callback, 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]);
}
}
}
}
} }

View File

@ -23,7 +23,7 @@ class MapManager implements CallbackListener {
* Constants * Constants
*/ */
const TABLE_MAPS = 'mc_maps'; const TABLE_MAPS = 'mc_maps';
const CB_MAPLIST_UPDATED = 'MapManager.MapListUpdated';
/** /**
* Private properties * Private properties
*/ */
@ -177,6 +177,9 @@ class MapManager implements CallbackListener {
//restore Sorted Maplist //restore Sorted Maplist
$this->mapList = $tempList; $this->mapList = $tempList;
// Trigger own callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPLIST_UPDATED, array(self::CB_MAPLIST_UPDATED));
} }
/** /**