begin xlist, general Widget ID, close and enable funktions
This commit is contained in:
parent
43b46aaf01
commit
7112917a76
@ -2,6 +2,7 @@
|
||||
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
use FML\ManiaLink;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
@ -16,6 +17,8 @@ require_once __DIR__ . '/../FML/autoload.php';
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class ManialinkManager implements CallbackListener {
|
||||
|
||||
const MAIN_MLID = 'Main.ManiaLinkId';
|
||||
/**
|
||||
* Public properties
|
||||
*/
|
||||
@ -160,4 +163,30 @@ class ManialinkManager implements CallbackListener {
|
||||
public function disableAltMenu(Player $player) {
|
||||
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]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,12 +28,14 @@ class MapCommands implements CommandListener {
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Register for admin chat commands
|
||||
$this->maniaControl->commandManager->registerCommandListener('nextmap', $this, 'command_NextMap', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('restartmap', $this, 'command_RestartMap', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('addmap', $this, 'command_AddMap', 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('maps', $this, 'command_List');
|
||||
}
|
||||
@ -190,8 +192,17 @@ class MapCommands implements CommandListener {
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_List(array $chatCallback, Player $player) {
|
||||
// var_dump($chatCallback);
|
||||
$mapList = new MapList($this->maniaControl);
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ use FML\Controls\Control;
|
||||
use FML\Controls\Label;
|
||||
use FML\Controls\Labels\Label_Text;
|
||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Maps\Map;
|
||||
use FML\Controls\Frame;
|
||||
@ -19,15 +20,19 @@ use FML\Controls\Quads\Quad_BgRaceScore2;
|
||||
use FML\ManiaLink;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use MXInfoSearcher;
|
||||
|
||||
class MapList implements ManialinkPageAnswerListener {
|
||||
const ACTION_CLOSEWIDGET = 'MapList.CloseWidget';
|
||||
const MLID_WIDGET = 'MapList.WidgetId';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $width;
|
||||
private $height;
|
||||
private $quadStyle;
|
||||
private $quadSubstyle;
|
||||
|
||||
/**
|
||||
* Create a new server commands instance
|
||||
@ -41,66 +46,124 @@ class MapList implements ManialinkPageAnswerListener {
|
||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET , $this,
|
||||
'closeWidget');
|
||||
|
||||
// Register for player commands
|
||||
//$this->maniaControl->commandManager->registerCommandListener('list', $this, 'command_list');
|
||||
//settings
|
||||
$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){
|
||||
$maniaLink = new ManiaLink(self::MLID_WIDGET);
|
||||
$section = 'SM'; //TODO get from mc
|
||||
$mapName = '';
|
||||
$author = '';
|
||||
$environment = ''; //TODO also get actual environment
|
||||
$recent = true;
|
||||
|
||||
//settings
|
||||
$width = 150;
|
||||
$height = 80;
|
||||
$quadStyle = Quad_BgRaceScore2::STYLE; //TODO add default menu style to style manager
|
||||
$quadSubstyle = Quad_BgRaceScore2::SUBSTYLE_HandleSelectable;
|
||||
if(count($params) > 1){
|
||||
foreach($params as $param){
|
||||
if($param == '/xlist')
|
||||
continue;
|
||||
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
|
||||
$frame = new Frame();
|
||||
$maniaLink->add($frame);
|
||||
$frame->setSize($width,$height);
|
||||
$frame->setSize($this->width,$this->height);
|
||||
$frame->setPosition(0, 0);
|
||||
|
||||
//Background Quad
|
||||
$backgroundQuad = new Quad();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setSize($width,$height);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
$backgroundQuad->setSize($this->width,$this->height);
|
||||
$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
|
||||
$mapList = $this->maniaControl->mapManager->getMapList();
|
||||
|
||||
$id = 1;
|
||||
$y = $height / 2 - 10;
|
||||
$y = $this->height / 2 - 10;
|
||||
foreach($mapList as $map){
|
||||
$mapFrame = new Frame();
|
||||
$frame->add($mapFrame);
|
||||
$this->displayMap($id, $map, $mapFrame, $width, $height);
|
||||
$this->displayMap($id, $map, $mapFrame);
|
||||
$mapFrame->setY($y);
|
||||
$y -= 4;
|
||||
$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
|
||||
$maniaLinkText = $maniaLink->render()->saveXML();
|
||||
$this->maniaControl->manialinkManager->sendManialink($maniaLinkText, $player->login);
|
||||
$this->maniaControl->manialinkManager->disableAltMenu($player);
|
||||
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player);
|
||||
}
|
||||
|
||||
private function displayMap($id, Map $map, Frame $frame, $width){
|
||||
private function displayMap($id, Map $map, Frame $frame){
|
||||
|
||||
$frame->setZ(-0.01);
|
||||
|
||||
$x = -$width / 2;
|
||||
$x = -$this->width / 2;
|
||||
|
||||
//TODO detailed mx info page with link to mx
|
||||
$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) {
|
||||
$emptyManialink = new ManiaLink(self::MLID_WIDGET);
|
||||
$manialinkText = $emptyManialink->render()->saveXML();
|
||||
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
||||
$this->maniaControl->manialinkManager->enableAltMenu($player);
|
||||
unset($this->playersMenuShown[$player->login]);
|
||||
$this->maniaControl->manialinkManager->closeWidget($player);
|
||||
}
|
||||
|
||||
}
|
@ -175,6 +175,7 @@ class MapManager implements CallbackListener {
|
||||
}
|
||||
$this->addMap($map);
|
||||
|
||||
|
||||
//TODO restrucutre, make current as first
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user