arrowarrow current map, starting restructuring mapmanager

This commit is contained in:
kremsy 2013-12-15 17:52:16 +01:00
parent cc6b6cbfa1
commit 96e6717493
2 changed files with 86 additions and 55 deletions

View File

@ -13,6 +13,7 @@ use FML\Controls\Labels\Label_Text;
use FML\Controls\Quads\Quad_Icons64x64_1; use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Script\Script; use FML\Script\Script;
use FML\Script\Tooltips; use FML\Script\Tooltips;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
@ -72,11 +73,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
*/ */
public function showManiaExchangeList(array $chatCallback, Player $player){ public function showManiaExchangeList(array $chatCallback, Player $player){
$params = explode(' ', $chatCallback[1][2]); $params = explode(' ', $chatCallback[1][2]);
//$commandCount = count(explode(' ', $chatCallback[1][2]));
//var_dump($chatCallback[1][2]);
//echo $commandCount;
$section = 'SM'; //TODO get from mc $serverInfo = $this->maniaControl->server->getSystemInfo();
$title = strtoupper(substr($serverInfo['TitleId'], 0, 2));
$mapName = ''; $mapName = '';
$author = ''; $author = '';
$environment = ''; //TODO also get actual environment $environment = ''; //TODO also get actual environment
@ -102,7 +102,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
} }
// search for matching maps // search for matching maps
$maps = new MXInfoSearcher($section, $mapName, $author, $environment, $recent); $maps = new MXInfoSearcher($title, $mapName, $author, $environment, $recent);
//check if there are any results //check if there are any results
if(!$maps->valid()){ if(!$maps->valid()){
@ -143,27 +143,27 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->manialinkManager->labelLine($mapFrame,$array); $this->maniaControl->manialinkManager->labelLine($mapFrame,$array);
$mapFrame->setY($y); $mapFrame->setY($y);
//TODO only for admins: if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)){ //todoSET as setting who can add maps
//Add-Map-Button //Add-Map-Button
$addQuad = new Quad_Icons64x64_1(); $addQuad = new Quad_Icons64x64_1();
$mapFrame->add($addQuad); $mapFrame->add($addQuad);
$addQuad->setX($x + 15); $addQuad->setX($x + 15);
$addQuad->setZ(-0.1); $addQuad->setZ(-0.1);
$addQuad->setSubStyle($addQuad::SUBSTYLE_Add); $addQuad->setSubStyle($addQuad::SUBSTYLE_Add);
$addQuad->setSize(4,4); $addQuad->setSize(4,4);
$addQuad->setAction(self::ACTION_ADD_MAP . "." .$map->id); $addQuad->setAction(self::ACTION_ADD_MAP . "." .$map->id);
//Description Label
$descriptionLabel = new Label();
$frame->add($descriptionLabel);
$descriptionLabel->setAlign(Control::LEFT, Control::TOP);
$descriptionLabel->setPosition($x + 10, -$this->height / 2 + 5);
$descriptionLabel->setSize($this->width * 0.7, 4);
$descriptionLabel->setTextSize(2);
$descriptionLabel->setVisible(false);
$descriptionLabel->setText("Add-Map: {$map->name}");
$tooltips->add($addQuad, $descriptionLabel);
//Description Label
$descriptionLabel = new Label();
$frame->add($descriptionLabel);
$descriptionLabel->setAlign(Control::LEFT, Control::TOP);
$descriptionLabel->setPosition($x + 10, -$this->height / 2 + 5);
$descriptionLabel->setSize($this->width * 0.7, 4);
$descriptionLabel->setTextSize(2);
$descriptionLabel->setVisible(false);
$descriptionLabel->setText("Add-Map: {$map->name}");
$tooltips->add($addQuad, $descriptionLabel);
}
$y -= 4; $y -= 4;
$i++; $i++;
@ -252,11 +252,20 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @param Frame $frame * @param Frame $frame
*/ */
private function displayMap($id, Map $map, Frame $frame){ private function displayMap($id, Map $map, Frame $frame){
$frame->setZ(-0.01); $frame->setZ(0.1);
//set starting x-value //set starting x-value
$x = -$this->width / 2; $x = -$this->width / 2;
if($this->maniaControl->mapManager->getCurrentMap() == $map){
echo "test";
$currentQuad = new Quad_Icons64x64_1();
$frame->add($currentQuad);
$currentQuad->setX($x + 3.5);
$currentQuad->setZ(0.2);
$currentQuad->setSize(4, 4);
$currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue);
}
$mxId = ''; $mxId = '';
if(isset($map->mx->id)) if(isset($map->mx->id))

View File

@ -9,9 +9,7 @@ use ManiaControl\FileUtil;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Players\Player;
// TODO: xlist command
/** /**
* Manager for maps * Manager for maps
@ -30,6 +28,8 @@ class MapManager implements CallbackListener {
private $maniaControl = null; private $maniaControl = null;
private $mapCommands = null; private $mapCommands = null;
private $mapList = array(); private $mapList = array();
private $mapListUids = array();
private $currentMap = null;
/** /**
* Construct map manager * Construct map manager
@ -119,19 +119,47 @@ class MapManager implements CallbackListener {
* @param \ManiaControl\Maps\Map $map * @param \ManiaControl\Maps\Map $map
* @return bool * @return bool
*/ */
private function addMap(Map $map) { private function addMap(Map $map) { //TODO needed?
$this->saveMap($map); $this->saveMap($map);
$this->mapList[$map->uid] = $map; $this->mapListUids[$map->uid] = $map;
$this->mapList[] = $map;
return true; return true;
} }
/**
* Updates the full Map list, needed on Init, addMap and on ShuffleMaps
* @return null
*/
private function updateFullMapList(){
if(!$this->maniaControl->client->query('GetMapList', 100,0)){ //fetch 100 Maps
trigger_error("Couldn't fetch mapList. " . $this->maniaControl->getClientErrorText());
return null;
}
$tempList = array();
$mapList = $this->maniaControl->client->getResponse();
foreach($mapList as $rpcMap){
if(array_key_exists($rpcMap["UId"], $this->mapListUids)){ //Map already exists, only update index
$tempList[] = $this->mapListUids[$rpcMap["UId"]];
}else{ //Insert Map Object
$map = new Map($this->maniaControl, $rpcMap);
$this->saveMap($map);
$tempList[] = $map;
$this->mapListUids[$map->uid] = $map;
}
}
//restore Sorted Maplist
$this->mapList = $tempList;
}
/** /**
* Fetch current map * Fetch current map
* *
* @return \ManiaControl\Maps\Map * @return \ManiaControl\Maps\Map
*/ */
public function getCurrentMap() { private function fetchCurrentMapInfo() {
if (!$this->maniaControl->client->query('GetCurrentMapInfo')) { if (!$this->maniaControl->client->query('GetCurrentMapInfo')) {
trigger_error("Couldn't fetch map info. " . $this->maniaControl->getClientErrorText()); trigger_error("Couldn't fetch map info. " . $this->maniaControl->getClientErrorText());
return null; return null;
@ -148,41 +176,34 @@ class MapManager implements CallbackListener {
* @param array $callback * @param array $callback
*/ */
public function handleOnInit(array $callback) { public function handleOnInit(array $callback) {
$map = $this->getCurrentMap(); $this->updateFullMapList();
if (!$map) { $this->currentMap = $this->fetchCurrentMapInfo();
return;
}
$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);
}
} }
/**
* @return null
*/
public function getCurrentMap(){
return $this->currentMap;
}
/** /**
* Handle BeginMap callback * Handle BeginMap callback
* *
* @param array $callback * @param array $callback
*/ */
public function handleBeginMap(array $callback) { public function handleBeginMap(array $callback) {
$map = $this->getCurrentMap(); if(array_key_exists($callback[1][0]["UId"], $this->mapListUids)){ //Map already exists, only update index
if (!$map) { $this->currentMap = $this->mapListUids[$rpcMap["UId"]];
return; }else{ //can this ever happen?
$this->currentMap = $this->fetchCurrentMapInfo();
} }
$this->addMap($map);
//TODO restrucutre, make current as first
} }
/** /**
* @return array * @return array
*/ */
@ -266,7 +287,8 @@ class MapManager implements CallbackListener {
return; return;
} }
$this->maniaControl->chat->sendSuccess('Map $<' . $mapInfo['Name'] . '$> added!'); $this->maniaControl->chat->sendSuccess('Map $<' . $mapInfo['Name'] . '$> added!');
return;
$this->updateFullMapList();
} }
// TODO: add local map by filename // TODO: add local map by filename
} }