extra ask on skip to and erase

This commit is contained in:
kremsy 2014-01-02 10:38:46 +01:00
parent f37d506867
commit 442b6d1f7b

View File

@ -1,13 +1,17 @@
<?php <?php
namespace ManiaControl\Maps; namespace ManiaControl\Maps;
use FML\Controls\Control; use FML\Controls\Control;
use FML\Controls\Frame;
use FML\Controls\Gauge; use FML\Controls\Gauge;
use FML\Controls\Label; use FML\Controls\Label;
use FML\Controls\Labels\Label_Button; use FML\Controls\Labels\Label_Button;
use FML\Controls\Labels\Label_Text; use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_BgsPlayerCard; use FML\Controls\Quads\Quad_BgsPlayerCard;
use FML\Controls\Quads\Quad_Icons64x64_1; use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink;
use FML\Script\Script; use FML\Script\Script;
use KarmaPlugin; use KarmaPlugin;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
@ -15,12 +19,9 @@ use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ColorUtil; use ManiaControl\ColorUtil;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use FML\Controls\Frame;
use FML\Controls\Quad;
use FML\ManiaLink;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use MXInfoSearcher; use MXInfoSearcher;
@ -35,13 +36,15 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/** /**
* Constants * Constants
*/ */
const ACTION_ADD_MAP = 'MapList.AddMap'; const ACTION_ADD_MAP = 'MapList.AddMap';
const ACTION_ERASE_MAP = 'MapList.EraseMap'; const ACTION_ERASE_MAP = 'MapList.EraseMap';
const ACTION_SWITCH_MAP = 'MapList.SwitchMap'; const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
const ACTION_QUEUED_MAP = 'MapList.QueueMap'; const ACTION_QUEUED_MAP = 'MapList.QueueMap';
const MAX_MAPS_PER_PAGE = 15; const ACTION_CONFIRM_ERASE_MAP = 'MapList.ConfirmEraseMap';
const SHOW_MX_LIST = 1; const ACTION_CONFIRM_SWITCHTO_MAP = 'MapList.ConfirmSwitchToMap';
const SHOW_MAP_LIST = 2; const MAX_MAPS_PER_PAGE = 15;
const SHOW_MX_LIST = 1;
const SHOW_MAP_LIST = 2;
const DEFAULT_KARMA_PLUGIN = 'KarmaPlugin'; const DEFAULT_KARMA_PLUGIN = 'KarmaPlugin';
/** /**
@ -62,8 +65,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this,'closeWidget'); $this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,'handleManialinkPageAnswer'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
//Update Widget actions //Update Widget actions
$this->maniaControl->callbackManager->registerCallbackListener(MapQueue::CB_MAPQUEUE_CHANGED, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapQueue::CB_MAPQUEUE_CHANGED, $this, 'updateWidget');
@ -72,50 +75,54 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
//TODO update on Karma Update //TODO update on Karma Update
//settings //settings
$this->width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth(); $this->width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$this->height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight(); $this->height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
$this->quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle(); $this->quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
$this->quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle(); $this->quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
/** @var just a test $itemQuad /** @var just a test $itemQuad
$itemQuad = new Quad(); * $itemQuad = new Quad();
$itemQuad->setStyles('Icons128x32_1', Quad_Icons128x128_1::SUBSTYLE_Create); * $itemQuad->setStyles('Icons128x32_1', Quad_Icons128x128_1::SUBSTYLE_Create);
$itemQuad->setAction(self::ACTION_ADD_MAP); * $itemQuad->setAction(self::ACTION_ADD_MAP);
$this->maniaControl->adminMenu->addMenuItem($itemQuad, 4);*/ * $this->maniaControl->adminMenu->addMenuItem($itemQuad, 4);*/
} }
/** /**
* Displays the Mania Exchange List * Displays the Mania Exchange List
*
* @param array $chatCallback * @param array $chatCallback
* @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; $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();
$title = strtoupper(substr($serverInfo['TitleId'], 0, 2)); $title = strtoupper(substr($serverInfo['TitleId'], 0, 2));
$mapName = ''; $mapName = '';
$author = ''; $author = '';
$environment = ''; //TODO also get actual environment $environment = ''; //TODO also get actual environment
$recent = true; $recent = true;
if(count($params) > 1){ if(count($params) > 1) {
foreach($params as $param){ foreach($params as $param) {
if($param == '/xlist') if($param == '/xlist') {
continue; continue;
if (strtolower(substr($param, 0, 5)) == 'auth:') { }
if(strtolower(substr($param, 0, 5)) == 'auth:') {
$author = substr($param, 5); $author = substr($param, 5);
} elseif (strtolower(substr($param, 0, 4)) == 'env:') { } elseif(strtolower(substr($param, 0, 4)) == 'env:') {
$environment = substr($param, 4); $environment = substr($param, 4);
} else { } else {
if ($mapName == '') if($mapName == '') {
$mapName = $param; $mapName = $param;
else // concatenate words in name } else // concatenate words in name
{
$mapName .= '%20' . $param; $mapName .= '%20' . $param;
}
} }
} }
@ -126,16 +133,17 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$maps = new MXInfoSearcher($title, $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()) {
$this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login); $this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login);
if($maps->error != '') if($maps->error != '') {
trigger_error($maps->error, E_USER_WARNING); trigger_error($maps->error, E_USER_WARNING);
}
return; return;
} }
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$frame = $this->buildMainFrame(); $frame = $this->buildMainFrame();
$maniaLink->add($frame); $maniaLink->add($frame);
// Create script and features // Create script and features
@ -151,26 +159,26 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$frame->add($headFrame); $frame->add($headFrame);
$headFrame->setY($y - 5); $headFrame->setY($y - 5);
$array = array("Id" => $x + 5, "Name" => $x + 17, "Author" => $x + 65, "Mood" => $x + 100, "Type" => $x + 115); $array = array("Id" => $x + 5, "Name" => $x + 17, "Author" => $x + 65, "Mood" => $x + 100, "Type" => $x + 115);
$this->maniaControl->manialinkManager->labelLine($headFrame,$array); $this->maniaControl->manialinkManager->labelLine($headFrame, $array);
$i = 0; $i = 0;
$y -= 10; $y -= 10;
foreach($maps as $map){ foreach($maps as $map) {
$mapFrame = new Frame(); $mapFrame = new Frame();
$frame->add($mapFrame); $frame->add($mapFrame);
$array = array($map->id => $x + 5, $map->name => $x + 17, $map->author => $x + 65, $map->mood => $x + 100, $map->maptype => $x + 115); $array = array($map->id => $x + 5, $map->name => $x + 17, $map->author => $x + 65, $map->mood => $x + 100, $map->maptype => $x + 115);
$this->maniaControl->manialinkManager->labelLine($mapFrame,$array); $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
$mapFrame->setY($y); $mapFrame->setY($y);
if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)){ //todoSET as setting who can add maps 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 //Description Label
$descriptionLabel = new Label(); $descriptionLabel = new Label();
@ -187,8 +195,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$y -= 4; $y -= 4;
$i++; $i++;
if($i == self::MAX_MAPS_PER_PAGE) if($i == self::MAX_MAPS_PER_PAGE) {
break; break;
}
} }
//TODO add MX info screen //TODO add MX info screen
@ -199,18 +208,19 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/** /**
* Builds the mainFrame * Builds the mainFrame
*
* @return Frame $frame * @return Frame $frame
*/ */
public function buildMainFrame(){ public function buildMainFrame() {
//mainframe //mainframe
$frame = new Frame(); $frame = new Frame();
$frame->setSize($this->width,$this->height); $frame->setSize($this->width, $this->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($this->width,$this->height); $backgroundQuad->setSize($this->width, $this->height);
$backgroundQuad->setStyles($this->quadStyle, $this->quadSubstyle); $backgroundQuad->setStyles($this->quadStyle, $this->quadSubstyle);
// Add Close Quad (X) // Add Close Quad (X)
@ -223,18 +233,23 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
return $frame; return $frame;
} }
/** /**
* Displayes a MapList on the screen * Displayes a MapList on the screen
*
* @param Player $player * @param Player $player
*/ */
public function showMapList(Player $player){ public function showMapList(Player $player, $confirmAction = null, $confirmMapId = '') {
$this->mapListShown[$player->login] = self::SHOW_MAP_LIST; $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);
// Create script and features // Create script and features
$script = new Script(); $script = new Script();
$maniaLink->setScript($script); $maniaLink->setScript($script);
@ -243,9 +258,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$headFrame = new Frame(); $headFrame = new Frame();
$frame->add($headFrame); $frame->add($headFrame);
$headFrame->setY($this->height / 2 - 5); $headFrame->setY($this->height / 2 - 5);
$x = -$this->width / 2; $x = -$this->width / 2;
$array = array("Id" => $x + 5, "Mx ID" => $x + 10, "MapName" => $x + 20, "Author" => $x + 68, "Karma" => $x + 115, "Actions" => $this->width / 2 - 15); $array = array("Id" => $x + 5, "Mx ID" => $x + 10, "MapName" => $x + 20, "Author" => $x + 68, "Karma" => $x + 115, "Actions" => $this->width / 2 - 15);
$this->maniaControl->manialinkManager->labelLine($headFrame,$array); $this->maniaControl->manialinkManager->labelLine($headFrame, $array);
//Get Maplist //Get Maplist
$mapList = $this->maniaControl->mapManager->getMapList(); $mapList = $this->maniaControl->mapManager->getMapList();
@ -257,16 +272,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$karmaPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_KARMA_PLUGIN); $karmaPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_KARMA_PLUGIN);
$id = 1; $id = 1;
$y = $this->height / 2 - 10; $y = $this->height / 2 - 10;
/** @var Map $map */ /** @var Map $map */
foreach($mapList as $map){ foreach($mapList as $map) {
//Map Frame //Map Frame
$mapFrame = new Frame(); $mapFrame = new Frame();
$frame->add($mapFrame); $frame->add($mapFrame);
$mapFrame->setZ(0.1); $mapFrame->setZ(0.1);
$mapFrame->setY($y); $mapFrame->setY($y);
if($id % 2 != 0){ if($id % 2 != 0) {
$lineQuad = new Quad_BgsPlayerCard(); $lineQuad = new Quad_BgsPlayerCard();
$mapFrame->add($lineQuad); $mapFrame->add($lineQuad);
$lineQuad->setSize($this->width, 4); $lineQuad->setSize($this->width, 4);
@ -275,8 +290,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
} }
if($this->maniaControl->mapManager->getCurrentMap() === $map) {
if($this->maniaControl->mapManager->getCurrentMap() === $map){
$currentQuad = new Quad_Icons64x64_1(); $currentQuad = new Quad_Icons64x64_1();
$mapFrame->add($currentQuad); $mapFrame->add($currentQuad);
$currentQuad->setX($x + 3.5); $currentQuad->setX($x + 3.5);
@ -286,12 +300,13 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
} }
$mxId = '-'; $mxId = '-';
if(isset($map->mx->id)) if(isset($map->mx->id)) {
$mxId = $map->mx->id; $mxId = $map->mx->id;
}
//Display Maps //Display Maps
$array = array($id => $x + 5, $mxId => $x + 10, $map->name => $x + 20, $map->authorNick => $x + 68); $array = array($id => $x + 5, $mxId => $x + 10, $map->name => $x + 20, $map->authorNick => $x + 68);
$this->maniaControl->manialinkManager->labelLine($mapFrame,$array); $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
//TODO detailed mx info page with link to mxo //TODO detailed mx info page with link to mxo
//TODO action detailed map info //TODO action detailed map info
//TODO side switch //TODO side switch
@ -307,11 +322,11 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$descriptionLabel->setVisible(false); $descriptionLabel->setVisible(false);
//Map-Queue-Map-Label //Map-Queue-Map-Label
if(isset($queuedMaps[$map->uid])){ if(isset($queuedMaps[$map->uid])) {
$label = new Label_Text(); $label = new Label_Text();
$mapFrame->add($label); $mapFrame->add($label);
$label->setX($this->width/2 - 15); $label->setX($this->width / 2 - 15);
$label->setAlign(Control::CENTER,Control::CENTER); $label->setAlign(Control::CENTER, Control::CENTER);
$label->setZ(0.2); $label->setZ(0.2);
$label->setTextSize(1.5); $label->setTextSize(1.5);
$label->setText($queuedMaps[$map->uid]); $label->setText($queuedMaps[$map->uid]);
@ -319,13 +334,13 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$descriptionLabel->setText("{$map->name} \$zis on Map-Queue Position: {$queuedMaps[$map->uid]}"); $descriptionLabel->setText("{$map->name} \$zis on Map-Queue Position: {$queuedMaps[$map->uid]}");
//$tooltips->add($jukeLabel, $descriptionLabel); //$tooltips->add($jukeLabel, $descriptionLabel);
}else{ } else {
//Map-Queue-Map-Button //Map-Queue-Map-Button
$buttLabel = new Label_Button(); $buttLabel = new Label_Button();
$mapFrame->add($buttLabel); $mapFrame->add($buttLabel);
$buttLabel->setX($this->width/2 - 15); $buttLabel->setX($this->width / 2 - 15);
$buttLabel->setZ(0.2); $buttLabel->setZ(0.2);
$buttLabel->setSize(3,3); $buttLabel->setSize(3, 3);
$buttLabel->setAction(self::ACTION_QUEUED_MAP . "." . $map->uid); $buttLabel->setAction(self::ACTION_QUEUED_MAP . "." . $map->uid);
$buttLabel->setText("+"); $buttLabel->setText("+");
$buttLabel->setTextColor("09F"); $buttLabel->setTextColor("09F");
@ -335,17 +350,18 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$script->addTooltip($buttLabel, $descriptionLabel); $script->addTooltip($buttLabel, $descriptionLabel);
} }
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
$eraseQuad = new Label_Button(); //TODO change name to label $eraseQuad = new Label_Button(); //TODO change name to label
$mapFrame->add($eraseQuad); $mapFrame->add($eraseQuad);
$eraseQuad->setX($this->width/2 - 5); $eraseQuad->setX($this->width / 2 - 5);
$eraseQuad->setZ(0.2); $eraseQuad->setZ(0.2);
$eraseQuad->setSize(3,3); $eraseQuad->setSize(3, 3);
$eraseQuad->setTextSize(1); $eraseQuad->setTextSize(1);
$eraseQuad->setText("x"); $eraseQuad->setText("x");
$eraseQuad->setTextColor("A00"); $eraseQuad->setTextColor("A00");
$eraseQuad->setAction(self::ACTION_ERASE_MAP . "." .($id-1) . "." . $map->uid); //$eraseQuad->setAction(self::ACTION_ERASE_MAP . "." . ($id - 1) . "." . $map->uid);
$eraseQuad->setAction(self::ACTION_CONFIRM_ERASE_MAP . "." . ($id));
//Description Label //Description Label
$descriptionLabel = new Label(); $descriptionLabel = new Label();
@ -358,19 +374,20 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$descriptionLabel->setText("Remove Map: {$map->name}"); $descriptionLabel->setText("Remove Map: {$map->name}");
$script->addTooltip($eraseQuad, $descriptionLabel); $script->addTooltip($eraseQuad, $descriptionLabel);
} }
if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)){ //TODO SET as setting who can add maps if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { //TODO SET as setting who can add maps
//switch to map quad //switch to map quad
//$switchToQuad = new Quad_Icons64x64_1(); //TODO change name to label //$switchToQuad = new Quad_Icons64x64_1(); //TODO change name to label
$switchToQuad = new Label_Button(); $switchToQuad = new Label_Button();
$mapFrame->add($switchToQuad); $mapFrame->add($switchToQuad);
$switchToQuad->setX($this->width/2 - 10); $switchToQuad->setX($this->width / 2 - 10);
$switchToQuad->setZ(0.2); $switchToQuad->setZ(0.2);
$switchToQuad->setSize(3, 3); $switchToQuad->setSize(3, 3);
$switchToQuad->setTextSize(2);
//$switchToQuad->setSubStyle($switchToQuad::SUBSTYLE_ArrowFastNext); //$switchToQuad->setSubStyle($switchToQuad::SUBSTYLE_ArrowFastNext);
$switchToQuad->setText("»"); $switchToQuad->setText("»");
$switchToQuad->setTextColor("0F0"); $switchToQuad->setTextColor("0F0");
$switchToQuad->setAction(self::ACTION_SWITCH_MAP . "." .($id-1)); $switchToQuad->setAction(self::ACTION_CONFIRM_SWITCHTO_MAP . "." . ($id));
$descriptionLabel = new Label(); $descriptionLabel = new Label();
$frame->add($descriptionLabel); $frame->add($descriptionLabel);
@ -384,10 +401,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
} }
//Display Karma bar //Display Karma bar
if($karmaPlugin != null){ if($karmaPlugin != null) {
$karma = $karmaPlugin->getMapKarma($map); $karma = $karmaPlugin->getMapKarma($map);
$votes = $karmaPlugin->getMapVotes($map); $votes = $karmaPlugin->getMapVotes($map);
if(is_numeric($karma)){ if(is_numeric($karma)) {
$karmaGauge = new Gauge(); $karmaGauge = new Gauge();
$mapFrame->add($karmaGauge); $mapFrame->add($karmaGauge);
$karmaGauge->setZ(2); $karmaGauge->setZ(2);
@ -411,10 +428,60 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
} }
} }
//Confirm Frame
if($id == $confirmMapId && ($confirmAction == self::ACTION_CONFIRM_SWITCHTO_MAP || $confirmAction == self::ACTION_CONFIRM_ERASE_MAP)){
$confirmFrame = new Frame();
$maniaLink->add($confirmFrame);
$confirmFrame->setPosition($this->width / 2 + 6, $y);
$quad = new Quad();
$confirmFrame->add($quad);
$quad->setStyles($this->quadStyle, $this->quadSubstyle);
$quad->setSize(12, 4);
$quad = new Quad_BgsPlayerCard();
$confirmFrame->add($quad);
//$quad->setX(0);
//$quad->setY($y);
$quad->setSubStyle($quad::SUBSTYLE_BgCardSystem);
$quad->setSize(11,3.5);
$label = new Label_Button();
$confirmFrame->add($label);
$label->setAlign(Control::CENTER, Control::CENTER);
$label->setText("Sure");
$label->setTextSize(1);
$label->setScale(0.90);
$label->setX(-1.3);
$buttLabel = new Label_Button();
$confirmFrame->add($buttLabel);
$buttLabel->setPosition(3.2,0.4,0.2);
$buttLabel->setSize(3, 3);
// $buttLabel->setTextSize(1);
$buttLabel->setAlign(Control::CENTER, Control::CENTER);
if($confirmAction == self::ACTION_CONFIRM_SWITCHTO_MAP){
$quad->setAction(self::ACTION_SWITCH_MAP . "." . ($id - 1));
$buttLabel->setText("»");
$buttLabel->setTextColor("0F0");
$buttLabel->setTextSize(2);
}else{
$buttLabel->setTextSize(1);
$buttLabel->setText("x");
$buttLabel->setTextColor("A00");
$quad->setAction(self::ACTION_ERASE_MAP . "." . ($id - 1) . "." . $map->uid);
}
}
$y -= 4; $y -= 4;
$id++; $id++;
if($id == self::MAX_MAPS_PER_PAGE + 1) if($id == self::MAX_MAPS_PER_PAGE + 1) {
break; break;
}
} }
//TODO pages //TODO pages
@ -427,7 +494,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/** /**
* Closes the widget * Closes the widget
* @param array $callback *
* @param array $callback
*/ */
public function closeWidget(array $callback) { public function closeWidget(array $callback) {
$player = $callback[1]; $player = $callback[1];
@ -437,52 +505,60 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/** /**
* @param array $callback * @param array $callback
*/ */
public function handleManialinkPageAnswer(array $callback){ public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2]; $actionId = $callback[1][2];
$addMap = (strpos($actionId, self::ACTION_ADD_MAP) === 0);
$eraseMap = (strpos($actionId, self::ACTION_ERASE_MAP) === 0);
$switchMap = (strpos($actionId, self::ACTION_SWITCH_MAP) === 0);
$queueMap = (strpos($actionId, self::ACTION_QUEUED_MAP) === 0);
if(!$addMap && !$eraseMap && !$switchMap && !$queueMap)
return;
$actionArray = explode(".", $actionId); $actionArray = explode(".", $actionId);
if(count($actionArray) <= 2) {
$player = $this->maniaControl->playerManager->getPlayer($callback[1][1]); return;
if($addMap){ //TODO log and chat message
$this->maniaControl->mapManager->addMapFromMx(intval($actionArray[2]),$callback[1][1]); //TODO bestätigung
}else if($eraseMap){ //TODO log and chat message
$this->maniaControl->mapManager->eraseMap(intval($actionArray[2]), $actionArray[3]); //TODO bestätigung
$this->showMapList($player);
}else if($switchMap){ //TODO log and chat message
$this->maniaControl->client->query('JumpToMapIndex', intval($actionArray[2])); //TODO bestätigung
$mapList = $this->maniaControl->mapManager->getMapList();
$this->maniaControl->chat->sendSuccess('Map switched to $z$<' . $mapList[$actionArray[2]]->name . '$>!'); //TODO specified message, who done it?
$this->maniaControl->log(Formatter::stripCodes('Skipped to $z$<' . $mapList[$actionArray[2]]->name . '$>!'));
}else if($queueMap){
$this->maniaControl->mapManager->mapQueue->addMapToMapQueue($callback[1][1], $actionArray[2]);
} }
$action = $actionArray[0] . "." . $actionArray[1];
$player = $this->maniaControl->playerManager->getPlayer($callback[1][1]);
switch($action) {
case self::ACTION_CONFIRM_SWITCHTO_MAP:
$this->showMapList($player, self::ACTION_CONFIRM_SWITCHTO_MAP, $actionArray[2]);
break;
case self::ACTION_CONFIRM_ERASE_MAP:
$this->showMapList($player, self::ACTION_CONFIRM_ERASE_MAP, $actionArray[2]);
break;
case self::ACTION_ADD_MAP:
$this->maniaControl->mapManager->addMapFromMx(intval($actionArray[2]), $callback[1][1]); //TODO bestätigung
break;
case self::ACTION_ERASE_MAP:
$this->maniaControl->mapManager->eraseMap(intval($actionArray[2]), $actionArray[3]); //TODO bestätigung
$this->showMapList($player);
break;
case self::ACTION_SWITCH_MAP:
$this->maniaControl->client->query('JumpToMapIndex', intval($actionArray[2])); //TODO bestätigung
$mapList = $this->maniaControl->mapManager->getMapList();
$this->maniaControl->chat->sendSuccess('Map switched to $z$<' . $mapList[$actionArray[2]]->name . '$>!'); //TODO specified message, who done it?
$this->maniaControl->log(Formatter::stripCodes('Skipped to $z$<' . $mapList[$actionArray[2]]->name . '$>!'));
break;
case self::ACTION_QUEUED_MAP:
$this->maniaControl->mapManager->mapQueue->addMapToMapQueue($callback[1][1], $actionArray[2]);
break;
}
return;
} }
/** /**
* Reopen the widget on Map Begin, MapListChanged * Reopen the widget on Map Begin, MapListChanged
*
* @param array $callback * @param array $callback
*/ */
public function updateWidget(array $callback){ public function updateWidget(array $callback) {
foreach($this->mapListShown as $login => $shown){ foreach($this->mapListShown as $login => $shown) {
if($shown){ if($shown) {
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if($player != null){ if($player != null) {
if($shown == self::SHOW_MX_LIST){ if($shown == self::SHOW_MX_LIST) {
//TODO //TODO
}else if($shown == self::SHOW_MAP_LIST){ } else if($shown == self::SHOW_MAP_LIST) {
$this->showMapList($player); $this->showMapList($player);
} }
}else{ } else {
unset($this->mapListShown[$login]); unset($this->mapListShown[$login]);
} }
} }