begin xlist, general Widget ID, close and enable funktions

This commit is contained in:
kremsy 2013-12-15 11:29:49 +01:00
parent 43b46aaf01
commit 7112917a76
4 changed files with 142 additions and 37 deletions

View File

@ -2,6 +2,7 @@
namespace ManiaControl\Manialinks; namespace ManiaControl\Manialinks;
use FML\ManiaLink;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
@ -16,6 +17,8 @@ require_once __DIR__ . '/../FML/autoload.php';
* @author steeffeen & kremsy * @author steeffeen & kremsy
*/ */
class ManialinkManager implements CallbackListener { class ManialinkManager implements CallbackListener {
const MAIN_MLID = 'Main.ManiaLinkId';
/** /**
* Public properties * Public properties
*/ */
@ -160,4 +163,30 @@ class ManialinkManager implements CallbackListener {
public function disableAltMenu(Player $player) { public function disableAltMenu(Player $player) {
return $this->maniaControl->client->query('TriggerModeScriptEvent', 'LibXmlRpc_DisableAltMenu', $player->login); return $this->maniaControl->client->query('TriggerModeScriptEvent', 'LibXmlRpc_DisableAltMenu', $player->login);
} }
/**
* Displays a ManiaLink Widget to a certain Player
* @param String $maniaLink
* @param Player $player
*/
public function displayWidget($maniaLink, Player $player) {
//render and display xml
$maniaLinkText = $maniaLink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($maniaLinkText, $player->login);
$this->maniaControl->manialinkManager->disableAltMenu($player);
}
/**
* Closes the Manialink Widget and enables the Alt Menu
* @param Player $player
*/
public function closeWidget(Player $player) {
$emptyManialink = new ManiaLink(self::MAIN_MLID);
$manialinkText = $emptyManialink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
$this->maniaControl->manialinkManager->enableAltMenu($player);
//unset($this->playersMenuShown[$player->login]);
}
} }

View File

@ -27,13 +27,15 @@ class MapCommands implements CommandListener {
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Register for admin chat commands
$this->maniaControl->commandManager->registerCommandListener('nextmap', $this, 'command_NextMap', true); $this->maniaControl->commandManager->registerCommandListener('nextmap', $this, 'command_NextMap', true);
$this->maniaControl->commandManager->registerCommandListener('restartmap', $this, 'command_RestartMap', true); $this->maniaControl->commandManager->registerCommandListener('restartmap', $this, 'command_RestartMap', true);
$this->maniaControl->commandManager->registerCommandListener('addmap', $this, 'command_AddMap', true); $this->maniaControl->commandManager->registerCommandListener('addmap', $this, 'command_AddMap', true);
$this->maniaControl->commandManager->registerCommandListener('removemap', $this, 'command_RemoveMap', true); $this->maniaControl->commandManager->registerCommandListener('removemap', $this, 'command_RemoveMap', true);
// Register for chat commands // Register for player chat commands
$this->maniaControl->commandManager->registerCommandListener('xlist', $this, 'command_xList');
$this->maniaControl->commandManager->registerCommandListener('list', $this, 'command_List'); $this->maniaControl->commandManager->registerCommandListener('list', $this, 'command_List');
$this->maniaControl->commandManager->registerCommandListener('maps', $this, 'command_List'); $this->maniaControl->commandManager->registerCommandListener('maps', $this, 'command_List');
} }
@ -190,8 +192,17 @@ class MapCommands implements CommandListener {
* @param Player $player * @param Player $player
*/ */
public function command_List(array $chatCallback, Player $player) { public function command_List(array $chatCallback, Player $player) {
// var_dump($chatCallback);
$mapList = new MapList($this->maniaControl); $mapList = new MapList($this->maniaControl);
$mapList->showMapList($player); $mapList->showMapList($player);
} }
/**
* Handle ManiaExchange list command
* @param array $chatCallback
* @param Player $player
*/
public function command_xList(array $chatCallback, Player $player) {
$mapList = new MapList($this->maniaControl);
$mapList->showManiaExchangeList($chatCallback, $player);
}
} }

View File

@ -11,6 +11,7 @@ use FML\Controls\Control;
use FML\Controls\Label; use FML\Controls\Label;
use FML\Controls\Labels\Label_Text; use FML\Controls\Labels\Label_Text;
use FML\Controls\Quads\Quad_Icons64x64_1; use FML\Controls\Quads\Quad_Icons64x64_1;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Maps\Map; use ManiaControl\Maps\Map;
use FML\Controls\Frame; use FML\Controls\Frame;
@ -19,15 +20,19 @@ use FML\Controls\Quads\Quad_BgRaceScore2;
use FML\ManiaLink; use FML\ManiaLink;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use MXInfoSearcher;
class MapList implements ManialinkPageAnswerListener { class MapList implements ManialinkPageAnswerListener {
const ACTION_CLOSEWIDGET = 'MapList.CloseWidget'; const ACTION_CLOSEWIDGET = 'MapList.CloseWidget';
const MLID_WIDGET = 'MapList.WidgetId';
/** /**
* Private properties * Private properties
*/ */
private $maniaControl = null; private $maniaControl = null;
private $width;
private $height;
private $quadStyle;
private $quadSubstyle;
/** /**
* Create a new server commands instance * Create a new server commands instance
@ -41,66 +46,124 @@ class MapList implements ManialinkPageAnswerListener {
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET , $this, $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET , $this,
'closeWidget'); 'closeWidget');
// Register for player commands //settings
//$this->maniaControl->commandManager->registerCommandListener('list', $this, 'command_list'); $this->width = 150;
$this->height = 80;
$this->quadStyle = Quad_BgRaceScore2::STYLE; //TODO add default menu style to style manager
$this->quadSubstyle = Quad_BgRaceScore2::SUBSTYLE_HandleSelectable;
} }
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;
public function showMapList(Player $player){ $section = 'SM'; //TODO get from mc
$maniaLink = new ManiaLink(self::MLID_WIDGET); $mapName = '';
$author = '';
$environment = ''; //TODO also get actual environment
$recent = true;
//settings if(count($params) > 1){
$width = 150; foreach($params as $param){
$height = 80; if($param == '/xlist')
$quadStyle = Quad_BgRaceScore2::STYLE; //TODO add default menu style to style manager continue;
$quadSubstyle = Quad_BgRaceScore2::SUBSTYLE_HandleSelectable; if (strtolower(substr($param, 0, 5)) == 'auth:') {
$author = substr($param, 5);
} elseif (strtolower(substr($param, 0, 4)) == 'env:') {
$environment = substr($param, 4);
} else {
if ($mapName == '')
$mapName = $param;
else // concatenate words in name
$mapName .= '%20' . $param;
}
}
$recent = false;
}
// search for matching maps
$maps = new MXInfoSearcher($section, $mapName, $author, $environment, $recent);
//check if there are any results
if(!$maps->valid()){
$this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login);
if($maps->error != '')
trigger_error($maps->error, E_USER_WARNING);
return;
}
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$frame = $this->buildMainFrame();
//render and display xml
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player);
}
/**
* Builds the mainFrame
* @return Frame $frame
*/
public function buildMainFrame(){
//mainframe //mainframe
$frame = new Frame(); $frame = new Frame();
$maniaLink->add($frame); $frame->setSize($this->width,$this->height);
$frame->setSize($width,$height);
$frame->setPosition(0, 0); $frame->setPosition(0, 0);
//Background Quad //Background Quad
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setSize($width,$height); $backgroundQuad->setSize($this->width,$this->height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($this->quadStyle, $this->quadSubstyle);
// Add Close Quad (X)
$closeQuad = new Quad_Icons64x64_1();
$frame->add($closeQuad);
$closeQuad->setPosition($this->width * 0.483, $this->height * 0.467, 3);
$closeQuad->setSize(6, 6);
$closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace);
$closeQuad->setAction(self::ACTION_CLOSEWIDGET );
return $frame;
}
/**
* Displayes a MapList on the screen
* @param Player $player
*/
public function showMapList(Player $player){
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$frame = $this->buildMainFrame();
$maniaLink->add($frame);
//TODO headline //TODO headline
$mapList = $this->maniaControl->mapManager->getMapList(); $mapList = $this->maniaControl->mapManager->getMapList();
$id = 1; $id = 1;
$y = $height / 2 - 10; $y = $this->height / 2 - 10;
foreach($mapList as $map){ foreach($mapList as $map){
$mapFrame = new Frame(); $mapFrame = new Frame();
$frame->add($mapFrame); $frame->add($mapFrame);
$this->displayMap($id, $map, $mapFrame, $width, $height); $this->displayMap($id, $map, $mapFrame);
$mapFrame->setY($y); $mapFrame->setY($y);
$y -= 4; $y -= 4;
$id++; $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 //render and display xml
$maniaLinkText = $maniaLink->render()->saveXML(); $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player);
$this->maniaControl->manialinkManager->sendManialink($maniaLinkText, $player->login);
$this->maniaControl->manialinkManager->disableAltMenu($player);
} }
private function displayMap($id, Map $map, Frame $frame, $width){ private function displayMap($id, Map $map, Frame $frame){
$frame->setZ(-0.01); $frame->setZ(-0.01);
$x = -$width / 2; $x = -$this->width / 2;
//TODO detailed mx info page with link to mx //TODO detailed mx info page with link to mx
$x +=5; $x +=5;
@ -159,12 +222,13 @@ class MapList implements ManialinkPageAnswerListener {
} }
/**
* Closes the widget
* @param array $callback
* @param Player $player
*/
public function closeWidget(array $callback, Player $player) { public function closeWidget(array $callback, Player $player) {
$emptyManialink = new ManiaLink(self::MLID_WIDGET); $this->maniaControl->manialinkManager->closeWidget($player);
$manialinkText = $emptyManialink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
$this->maniaControl->manialinkManager->enableAltMenu($player);
unset($this->playersMenuShown[$player->login]);
} }
} }

View File

@ -175,6 +175,7 @@ class MapManager implements CallbackListener {
} }
$this->addMap($map); $this->addMap($map);
//TODO restrucutre, make current as first //TODO restrucutre, make current as first
} }