arrowarrow current map, starting restructuring mapmanager
This commit is contained in:
parent
cc6b6cbfa1
commit
96e6717493
@ -13,6 +13,7 @@ use FML\Controls\Labels\Label_Text;
|
||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||
use FML\Script\Script;
|
||||
use FML\Script\Tooltips;
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
@ -72,11 +73,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
*/
|
||||
public function showManiaExchangeList(array $chatCallback, Player $player){
|
||||
$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 = '';
|
||||
$author = '';
|
||||
$environment = ''; //TODO also get actual environment
|
||||
@ -102,7 +102,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
}
|
||||
|
||||
// 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
|
||||
if(!$maps->valid()){
|
||||
@ -143,7 +143,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$this->maniaControl->manialinkManager->labelLine($mapFrame,$array);
|
||||
$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
|
||||
$addQuad = new Quad_Icons64x64_1();
|
||||
$mapFrame->add($addQuad);
|
||||
@ -163,7 +163,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$descriptionLabel->setVisible(false);
|
||||
$descriptionLabel->setText("Add-Map: {$map->name}");
|
||||
$tooltips->add($addQuad, $descriptionLabel);
|
||||
|
||||
}
|
||||
|
||||
$y -= 4;
|
||||
$i++;
|
||||
@ -252,11 +252,20 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
* @param Frame $frame
|
||||
*/
|
||||
private function displayMap($id, Map $map, Frame $frame){
|
||||
$frame->setZ(-0.01);
|
||||
$frame->setZ(0.1);
|
||||
|
||||
//set starting x-value
|
||||
$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 = '';
|
||||
if(isset($map->mx->id))
|
||||
|
@ -9,9 +9,7 @@ use ManiaControl\FileUtil;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
// TODO: xlist command
|
||||
|
||||
/**
|
||||
* Manager for maps
|
||||
@ -30,6 +28,8 @@ class MapManager implements CallbackListener {
|
||||
private $maniaControl = null;
|
||||
private $mapCommands = null;
|
||||
private $mapList = array();
|
||||
private $mapListUids = array();
|
||||
private $currentMap = null;
|
||||
|
||||
/**
|
||||
* Construct map manager
|
||||
@ -119,19 +119,47 @@ class MapManager implements CallbackListener {
|
||||
* @param \ManiaControl\Maps\Map $map
|
||||
* @return bool
|
||||
*/
|
||||
private function addMap(Map $map) {
|
||||
private function addMap(Map $map) { //TODO needed?
|
||||
$this->saveMap($map);
|
||||
$this->mapList[$map->uid] = $map;
|
||||
$this->mapListUids[$map->uid] = $map;
|
||||
$this->mapList[] = $map;
|
||||
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
|
||||
*
|
||||
* @return \ManiaControl\Maps\Map
|
||||
*/
|
||||
public function getCurrentMap() {
|
||||
private function fetchCurrentMapInfo() {
|
||||
if (!$this->maniaControl->client->query('GetCurrentMapInfo')) {
|
||||
trigger_error("Couldn't fetch map info. " . $this->maniaControl->getClientErrorText());
|
||||
return null;
|
||||
@ -148,41 +176,34 @@ class MapManager implements CallbackListener {
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleOnInit(array $callback) {
|
||||
$map = $this->getCurrentMap();
|
||||
if (!$map) {
|
||||
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);
|
||||
$this->updateFullMapList();
|
||||
$this->currentMap = $this->fetchCurrentMapInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getCurrentMap(){
|
||||
return $this->currentMap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handle BeginMap callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleBeginMap(array $callback) {
|
||||
$map = $this->getCurrentMap();
|
||||
if (!$map) {
|
||||
return;
|
||||
if(array_key_exists($callback[1][0]["UId"], $this->mapListUids)){ //Map already exists, only update index
|
||||
$this->currentMap = $this->mapListUids[$rpcMap["UId"]];
|
||||
}else{ //can this ever happen?
|
||||
$this->currentMap = $this->fetchCurrentMapInfo();
|
||||
}
|
||||
$this->addMap($map);
|
||||
|
||||
|
||||
//TODO restrucutre, make current as first
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@ -266,7 +287,8 @@ class MapManager implements CallbackListener {
|
||||
return;
|
||||
}
|
||||
$this->maniaControl->chat->sendSuccess('Map $<' . $mapInfo['Name'] . '$> added!');
|
||||
return;
|
||||
|
||||
$this->updateFullMapList();
|
||||
}
|
||||
// TODO: add local map by filename
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user