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
namespace ManiaControl\Maps;
use FML\Controls\Control;
use FML\Controls\Frame;
use FML\Controls\Gauge;
use FML\Controls\Label;
use FML\Controls\Labels\Label_Button;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_BgsPlayerCard;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink;
use FML\Script\Script;
use KarmaPlugin;
use ManiaControl\Admin\AuthenticationManager;
@ -15,12 +19,9 @@ use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ColorUtil;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use FML\Controls\Frame;
use FML\Controls\Quad;
use FML\ManiaLink;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use MXInfoSearcher;
@ -39,6 +40,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
const ACTION_ERASE_MAP = 'MapList.EraseMap';
const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
const ACTION_QUEUED_MAP = 'MapList.QueueMap';
const ACTION_CONFIRM_ERASE_MAP = 'MapList.ConfirmEraseMap';
const ACTION_CONFIRM_SWITCHTO_MAP = 'MapList.ConfirmSwitchToMap';
const MAX_MAPS_PER_PAGE = 15;
const SHOW_MX_LIST = 1;
const SHOW_MAP_LIST = 2;
@ -78,15 +81,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
/** @var just a test $itemQuad
$itemQuad = new Quad();
$itemQuad->setStyles('Icons128x32_1', Quad_Icons128x128_1::SUBSTYLE_Create);
$itemQuad->setAction(self::ACTION_ADD_MAP);
$this->maniaControl->adminMenu->addMenuItem($itemQuad, 4);*/
* $itemQuad = new Quad();
* $itemQuad->setStyles('Icons128x32_1', Quad_Icons128x128_1::SUBSTYLE_Create);
* $itemQuad->setAction(self::ACTION_ADD_MAP);
* $this->maniaControl->adminMenu->addMenuItem($itemQuad, 4);*/
}
/**
* Displays the Mania Exchange List
*
* @param array $chatCallback
* @param Player $player
*/
@ -105,19 +109,22 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
if(count($params) > 1) {
foreach($params as $param) {
if($param == '/xlist')
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 == '')
if($mapName == '') {
$mapName = $param;
else // concatenate words in name
} else // concatenate words in name
{
$mapName .= '%20' . $param;
}
}
}
$recent = false;
}
@ -128,8 +135,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
//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 != '')
if($maps->error != '') {
trigger_error($maps->error, E_USER_WARNING);
}
return;
}
@ -187,9 +195,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$y -= 4;
$i++;
if($i == self::MAX_MAPS_PER_PAGE)
if($i == self::MAX_MAPS_PER_PAGE) {
break;
}
}
//TODO add MX info screen
@ -199,6 +208,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/**
* Builds the mainFrame
*
* @return Frame $frame
*/
public function buildMainFrame() {
@ -223,11 +233,13 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
return $frame;
}
/**
* Displayes a MapList on the screen
*
* @param Player $player
*/
public function showMapList(Player $player){
public function showMapList(Player $player, $confirmAction = null, $confirmMapId = '') {
$this->mapListShown[$player->login] = self::SHOW_MAP_LIST;
@ -235,6 +247,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$frame = $this->buildMainFrame();
$maniaLink->add($frame);
// Create script and features
$script = new Script();
$maniaLink->setScript($script);
@ -275,7 +290,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
}
if($this->maniaControl->mapManager->getCurrentMap() === $map) {
$currentQuad = new Quad_Icons64x64_1();
$mapFrame->add($currentQuad);
@ -286,8 +300,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
}
$mxId = '-';
if(isset($map->mx->id))
if(isset($map->mx->id)) {
$mxId = $map->mx->id;
}
//Display Maps
$array = array($id => $x + 5, $mxId => $x + 10, $map->name => $x + 20, $map->authorNick => $x + 68);
@ -345,7 +360,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$eraseQuad->setTextSize(1);
$eraseQuad->setText("x");
$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
$descriptionLabel = new Label();
@ -366,11 +382,12 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$switchToQuad->setX($this->width / 2 - 10);
$switchToQuad->setZ(0.2);
$switchToQuad->setSize(3, 3);
$switchToQuad->setTextSize(2);
//$switchToQuad->setSubStyle($switchToQuad::SUBSTYLE_ArrowFastNext);
$switchToQuad->setText("»");
$switchToQuad->setTextColor("0F0");
$switchToQuad->setAction(self::ACTION_SWITCH_MAP . "." .($id-1));
$switchToQuad->setAction(self::ACTION_CONFIRM_SWITCHTO_MAP . "." . ($id));
$descriptionLabel = new Label();
$frame->add($descriptionLabel);
@ -411,11 +428,61 @@ 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;
$id++;
if($id == self::MAX_MAPS_PER_PAGE + 1)
if($id == self::MAX_MAPS_PER_PAGE + 1) {
break;
}
}
//TODO pages
@ -427,6 +494,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/**
* Closes the widget
*
* @param array $callback
*/
public function closeWidget(array $callback) {
@ -439,37 +507,45 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
*/
public function handleManialinkPageAnswer(array $callback) {
$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);
if(count($actionArray) <= 2) {
return;
}
$action = $actionArray[0] . "." . $actionArray[1];
$player = $this->maniaControl->playerManager->getPlayer($callback[1][1]);
if($addMap){ //TODO log and chat message
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
}else if($eraseMap){ //TODO log and chat message
break;
case self::ACTION_ERASE_MAP:
$this->maniaControl->mapManager->eraseMap(intval($actionArray[2]), $actionArray[3]); //TODO bestätigung
$this->showMapList($player);
}else if($switchMap){ //TODO log and chat message
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 . '$>!'));
}else if($queueMap){
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
*
* @param array $callback
*/
public function updateWidget(array $callback) {