splitted maplist and mx list

This commit is contained in:
kremsy 2014-01-28 16:54:23 +01:00 committed by Steffen Schröder
parent d6a34bdeea
commit 4bd71d7a87
6 changed files with 426 additions and 313 deletions

View File

@ -0,0 +1,363 @@
<?php
namespace ManiaControl\ManiaExchange;
use FML\Controls\Control;
use FML\Controls\Entry;
use FML\Controls\Frame;
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 ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\IconManager;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Maps\MapCommands;
use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player;
/**
* ManiaExchange List Widget Class
*
* @author steeffeen & kremsy
*/
class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener {
/**
* Constants
*/
const ACTION_ADD_MAP = 'ManiaExchangeList.AddMap';
const ACTION_SEARCH_MAPNAME = 'ManiaExchangeList.SearchMapName';
const ACTION_SEARCH_AUTHOR = 'ManiaExchangeList.SearchAuthor';
const ACTION_GET_MAPS_FROM_AUTHOR = 'ManiaExchangeList.GetMapsFromAuthor';
const MAX_MX_MAPS_PER_PAGE = 14;
/**
* Private Properties
*/
private $maniaControl = null;
private $mapListShown = array();
/**
* Create a new MapList Instance
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
// Register for Callbacks
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SEARCH_MAPNAME, $this, 'showManiaExchangeList');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SEARCH_AUTHOR, $this, 'showManiaExchangeList');
}
public function showList(array $chatCallback, Player $player) {
$this->showManiaExchangeList($chatCallback, $player);
}
/**
* Display the Mania Exchange List
*
* @param array $chatCallback
* @param Player $player
*/
public function showManiaExchangeList(array $chatCallback, Player $player) {
$this->mapListShown[$player->login] = true;
$params = explode(' ', $chatCallback[1][2]);
$searchString = '';
$author = '';
$environment = '';
if (count($params) >= 1) {
foreach($params as $param) {
if ($param == '/xlist' || $param == MapCommands::ACTION_OPEN_XLIST) {
continue;
}
if ($param == self::ACTION_SEARCH_MAPNAME) {
$searchString = $chatCallback[1][3][0]['Value'];
} else if ($param == self::ACTION_SEARCH_AUTHOR) {
$author = $chatCallback[1][3][0]['Value'];
} else if (strtolower(substr($param, 0, 5)) == 'auth:') {
$author = substr($param, 5);
} else if (strtolower(substr($param, 0, 4)) == 'env:') {
$environment = substr($param, 4);
} else {
if ($searchString == '') {
$searchString = $param;
} else { // concatenate words in name
$searchString .= '%20' . $param;
}
}
}
}
// search for matching maps
$maps = $this->maniaControl->mapManager->mxManager->getMaps($searchString, $author, $environment);
// check if there are any results
if ($maps == null) {
$this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login);
return;
}
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$frame = $this->maniaControl->manialinkManager->styleManager->defaultListFrame();
$maniaLink->add($frame);
$frame->setZ(10);
// Create script and features
$script = new Script();
$maniaLink->setScript($script);
// Start offsets
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
$x = -$width / 2;
$y = $height / 2;
// Pagers
// Config
$pagerSize = 6.;
$pagesId = 'MxListPages';
$pagerPrev = new Quad_Icons64x64_1();
$frame->add($pagerPrev);
$pagerPrev->setPosition($width * 0.42, $height * -0.44, 2);
$pagerPrev->setSize($pagerSize, $pagerSize);
$pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev);
$pagerNext = new Quad_Icons64x64_1();
$frame->add($pagerNext);
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
$pagerNext->setSize($pagerSize, $pagerSize);
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
$script->addPager($pagerPrev, -1, $pagesId);
$script->addPager($pagerNext, 1, $pagesId);
$pageCountLabel = new Label_Text();
$frame->add($pageCountLabel);
$pageCountLabel->setHAlign(Control::RIGHT);
$pageCountLabel->setPosition($width * 0.40, $height * -0.44, 1);
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
$pageCountLabel->setTextSize(1.3);
$script->addPageLabel($pageCountLabel, $pagesId);
// Predefine Description Label
$descriptionLabel = new Label();
$frame->add($descriptionLabel);
$descriptionLabel->setAlign(Control::LEFT, Control::TOP);
$descriptionLabel->setPosition($x + 10, -$height / 2 + 5);
$descriptionLabel->setSize($width * 0.7, 4);
$descriptionLabel->setTextSize(2);
$descriptionLabel->setVisible(false);
// Headline
$headFrame = new Frame();
$frame->add($headFrame);
$headFrame->setY($y - 12);
$array = array('$oMx Id' => $x + 5, '$oName' => $x + 17, '$oAuthor' => $x + 65, '$oType' => $x + 100, '$oMood' => $x + 115, '$oLast Update' => $x + 130);
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
$i = 0;
$y = $height / 2 - 16;
$pageFrames = array();
foreach($maps as $map) { //TODO order possabilities
if (!isset($pageFrame)) {
$pageFrame = new Frame();
$frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 16;
$script->addPage($pageFrame, count($pageFrames), $pagesId);
}
// Map Frame
$mapFrame = new Frame();
$pageFrame->add($mapFrame);
if ($i % 2 == 0) {
$lineQuad = new Quad_BgsPlayerCard();
$mapFrame->add($lineQuad);
$lineQuad->setSize($width, 4);
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
$lineQuad->setZ(0.001);
}
/** @var MxMapInfo $map */
$time = Formatter::time_elapsed_string(strtotime($map->updated));
$array = array($map->id => $x + 5, $map->name => $x + 17, $map->author => $x + 65, str_replace("Arena", "", $map->maptype) => $x + 100, $map->mood => $x + 115, $time => $x + 130);
$labels = $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
/** @var Label_Text $authorLabel */
$authorLabel = $labels[2];
$authorLabel->setAction(self::ACTION_GET_MAPS_FROM_AUTHOR . '.' . $map->author);
$mapFrame->setY($y);
$mxQuad = new Quad();
$mapFrame->add($mxQuad);
$mxQuad->setSize(3, 3);
$mxQuad->setImage($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON));
$mxQuad->setImageFocus($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER));
$mxQuad->setX($x + 62);
$mxQuad->setUrl($map->pageurl);
$mxQuad->setZ(0.01);
$script->addTooltip($mxQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "View " . $map->name . " on Mania-Exchange"));
//TODO permission Clear Jukebox
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
$addQuad = new Quad_Icons64x64_1();
$mapFrame->add($addQuad);
$addQuad->setX($x + 59);
$addQuad->setZ(-0.1);
$addQuad->setSubStyle($addQuad::SUBSTYLE_Add);
$addQuad->setSize(4, 4);
$addQuad->setAction(self::ACTION_ADD_MAP . '.' . $map->id);
$addQuad->setZ(0.01);
$script->addTooltip($addQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => 'Add-Map: $<' . $map->name . '$>'));
}
//Award Quad
if ($map->awards > 0) {
$awardQuad = new Quad_Icons64x64_1();
$mapFrame->add($awardQuad);
$awardQuad->setSize(3, 3);
$awardQuad->setSubStyle($awardQuad::SUBSTYLE_OfficialRace);
$awardQuad->setX($x + 93);
$awardQuad->setZ(0.01);
$awardLabel = new Label_Text();
$mapFrame->add($awardLabel);
$awardLabel->setX($x + 94.5);
$awardLabel->setHAlign(Control::LEFT);
$awardLabel->setText($map->awards);
$awardLabel->setTextSize(1.3);
}
$y -= 4;
$i++;
if ($i % self::MAX_MX_MAPS_PER_PAGE == 0) {
unset($pageFrame);
}
}
$label = new Label_Text();
$frame->add($label);
$label->setPosition(-$width / 2 + 5, $height / 2 - 5);
$label->setHAlign(Control::LEFT);
$label->setTextSize(1.3);
$label->setText("Search:");
$entry = new Entry();
$frame->add($entry);
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
$entry->setHAlign(Control::LEFT);
$entry->setPosition(-$width / 2 + 15, $height / 2 - 5);
$entry->setTextSize(1);
$entry->setSize($width * 0.25, 4);
$entry->setName('SearchString');
//Search for Map-Name
$label = new Label_Button();
$frame->add($label);
$label->setPosition(-$width / 2 + 63, $height / 2 - 5);
$label->setText("MapName");
$label->setTextSize(1.3);
$quad = new Quad_BgsPlayerCard();
$frame->add($quad);
$quad->setPosition(-$width / 2 + 63, $height / 2 - 5, 0.01);
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
$quad->setSize(18, 5);
$quad->setAction(self::ACTION_SEARCH_MAPNAME);
//Search for Author
$label = new Label_Button();
$frame->add($label);
$label->setPosition(-$width / 2 + 82, $height / 2 - 5);
$label->setText("Author");
$label->setTextSize(1.3);
$quad = new Quad_BgsPlayerCard();
$frame->add($quad);
$quad->setPosition(-$width / 2 + 82, $height / 2 - 5, 0.01);
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
$quad->setSize(18, 5);
$quad->setAction(self::ACTION_SEARCH_AUTHOR);
// render and display xml
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'ManiaExchangeList');
}
/**
* Handle ManialinkPageAnswer Callback
*
* @param array $callback
*/
public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2];
$actionArray = explode('.', $actionId);
if (count($actionArray) <= 2) {
return;
}
$action = $actionArray[0] . '.' . $actionArray[1];
$login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login);
$mapId = (int)$actionArray[2];
switch($action) {
case self::ACTION_GET_MAPS_FROM_AUTHOR:
$callback[1][2] = 'auth:' . $actionArray[2];
$this->showManiaExchangeList($callback, $player);
break;
case self::ACTION_ADD_MAP:
$this->maniaControl->mapManager->addMapFromMx($mapId, $player->login);
break;
}
}
/**
* Unset the player if he opened another Main Widget
*
* @param array $callback
*/
public function handleWidgetOpened(array $callback) {
$player = $callback[1];
$openedWidget = $callback[2];
//unset when another main widget got opened
if ($openedWidget != 'ManiaExchangeList') {
unset($this->mapListShown[$player->login]);
}
}
/**
* Closes the widget
*
* @param array $callback
*/
public function closeWidget(array $callback) {
$player = $callback[1];
unset($this->mapListShown[$player->login]);
}
}

View File

@ -2,7 +2,10 @@
namespace ManiaControl\Manialinks; namespace ManiaControl\Manialinks;
use FML\Controls\Frame;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_BgRaceScore2; use FML\Controls\Quads\Quad_BgRaceScore2;
use FML\Controls\Quads\Quad_Icons64x64_1;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
/** /**
@ -123,4 +126,37 @@ class StyleManager {
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_LIST_WIDGETS_HEIGHT); return $this->maniaControl->settingManager->getSetting($this, self::SETTING_LIST_WIDGETS_HEIGHT);
} }
/**
* Builds the Default List Frame
*
* @return Frame $frame
*/
public function defaultListFrame() {
$width = $this->getListWidgetsWidth();
$height = $this->getListWidgetsHeight();
$quadStyle = $this->getDefaultMainWindowStyle();
$quadSubstyle = $this->getDefaultMainWindowSubStyle();
// mainframe
$frame = new Frame();
$frame->setSize($width, $height);
$frame->setPosition(0, 0);
// Background Quad
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
// 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(ManialinkManager::ACTION_CLOSEWIDGET);
return $frame;
}
} }

View File

@ -3,6 +3,7 @@
namespace ManiaControl\Maps; namespace ManiaControl\Maps;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaExchange\MXMapInfo;
/** /**
* Map Class * Map Class

View File

@ -98,7 +98,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
*/ */
public function command_ShowNextMap(array $chat, Player $player) { public function command_ShowNextMap(array $chat, Player $player) {
$nextQueued = $this->maniaControl->mapManager->mapQueue->getNextQueuedMap(); $nextQueued = $this->maniaControl->mapManager->mapQueue->getNextQueuedMap();
if($nextQueued != null) { if ($nextQueued != null) {
/** @var Player $requester */ /** @var Player $requester */
$requester = $nextQueued[0]; $requester = $nextQueued[0];
/** @var Map $map */ /** @var Map $map */
@ -119,13 +119,13 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_RemoveMap(array $chat, Player $player) { public function command_RemoveMap(array $chat, Player $player) {
if(!$this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) { if (!$this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
// Get map // Get map
$map = $this->maniaControl->mapManager->getCurrentMap(); $map = $this->maniaControl->mapManager->getCurrentMap();
if(!$map) { if (!$map) {
$this->maniaControl->chat->sendError("Couldn't remove map.", $player->login); $this->maniaControl->chat->sendError("Couldn't remove map.", $player->login);
return; return;
} }
@ -141,7 +141,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_ShuffleMaps(array $chatCallback, Player $player) { public function command_ShuffleMaps(array $chatCallback, Player $player) {
if(!$this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_SHUFFLE_MAPS)) { if (!$this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_SHUFFLE_MAPS)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
@ -157,12 +157,12 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_AddMap(array $chatCallback, Player $player) { public function command_AddMap(array $chatCallback, Player $player) {
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chatCallback[1][2], 2); $params = explode(' ', $chatCallback[1][2], 2);
if(count($params) < 2) { if (count($params) < 2) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //addmap 1234', $player->login); $this->maniaControl->chat->sendUsageInfo('Usage example: //addmap 1234', $player->login);
return; return;
} }
@ -178,7 +178,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_NextMap(array $chat, Player $player) { public function command_NextMap(array $chat, Player $player) {
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
@ -195,7 +195,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_RestartMap(array $chat, Player $player) { public function command_RestartMap(array $chat, Player $player) {
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
@ -222,6 +222,6 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param Player $player * @param Player $player
*/ */
public function command_xList(array $chatCallback, Player $player) { public function command_xList(array $chatCallback, Player $player) {
$this->maniaControl->mapManager->mapList->showManiaExchangeList($chatCallback, $player); $this->maniaControl->mapManager->mxList->showManiaExchangeList($chatCallback, $player);
} }
} }

View File

@ -3,7 +3,6 @@
namespace ManiaControl\Maps; namespace ManiaControl\Maps;
use FML\Controls\Control; use FML\Controls\Control;
use FML\Controls\Entry;
use FML\Controls\Frame; use FML\Controls\Frame;
use FML\Controls\Gauge; use FML\Controls\Gauge;
use FML\Controls\Label; use FML\Controls\Label;
@ -34,21 +33,14 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/** /**
* Constants * Constants
*/ */
const ACTION_ADD_MAP = 'MapList.AddMap'; const ACTION_UPDATE_MAP = 'MapList.UpdateMap';
const ACTION_UPDATE_MAP = 'MapList.UpdateMap'; const ACTION_ERASE_MAP = 'MapList.EraseMap';
const ACTION_SEARCH_MAPNAME = 'MapList.SearchMapName'; const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
const ACTION_SEARCH_AUTHOR = 'MapList.SearchAuthor'; const ACTION_QUEUED_MAP = 'MapList.QueueMap';
const ACTION_GET_MAPS_FROM_AUTHOR = 'MapList.GetMapsFromAuthor'; const ACTION_CHECK_UPDATE = 'MapList.CheckUpdate';
const ACTION_ERASE_MAP = 'MapList.EraseMap'; const ACTION_CLEAR_MAPQUEUE = 'MapList.ClearMapQueue';
const ACTION_SWITCH_MAP = 'MapList.SwitchMap'; const MAX_MAPS_PER_PAGE = 15;
const ACTION_QUEUED_MAP = 'MapList.QueueMap'; const DEFAULT_KARMA_PLUGIN = 'KarmaPlugin';
const ACTION_CHECK_UPDATE = 'MapList.CheckUpdate';
const ACTION_CLEAR_MAPQUEUE = 'MapList.ClearMapQueue';
const MAX_MAPS_PER_PAGE = 15;
const MAX_MX_MAPS_PER_PAGE = 14;
const SHOW_MX_LIST = 1;
const SHOW_MAP_LIST = 2;
const DEFAULT_KARMA_PLUGIN = 'KarmaPlugin';
/** /**
* Private Properties * Private Properties
@ -73,8 +65,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'updateWidget');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SEARCH_MAPNAME, $this, 'showManiaExchangeList');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SEARCH_AUTHOR, $this, 'showManiaExchangeList');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CHECK_UPDATE, $this, 'checkUpdates'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CHECK_UPDATE, $this, 'checkUpdates');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue');
} }
@ -103,277 +93,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->showMapList($player); $this->showMapList($player);
} }
/**
* Display the Mania Exchange List
*
* @param array $chatCallback
* @param Player $player
*/
public function showManiaExchangeList(array $chatCallback, Player $player) {
$this->mapListShown[$player->login] = self::SHOW_MX_LIST;
$params = explode(' ', $chatCallback[1][2]);
$searchString = '';
$author = '';
$environment = '';
if (count($params) >= 1) {
foreach($params as $param) {
if ($param == '/xlist' || $param == MapCommands::ACTION_OPEN_XLIST) {
continue;
}
if ($param == self::ACTION_SEARCH_MAPNAME) {
$searchString = $chatCallback[1][3][0]['Value'];
} else if ($param == self::ACTION_SEARCH_AUTHOR) {
$author = $chatCallback[1][3][0]['Value'];
} else if (strtolower(substr($param, 0, 5)) == 'auth:') {
$author = substr($param, 5);
} else if (strtolower(substr($param, 0, 4)) == 'env:') {
$environment = substr($param, 4);
} else {
if ($searchString == '') {
$searchString = $param;
} else { // concatenate words in name
$searchString .= '%20' . $param;
}
}
}
}
// search for matching maps
$maps = $this->maniaControl->mapManager->mxManager->getMaps($searchString, $author, $environment);
// check if there are any results
if ($maps == null) {
$this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login);
return;
}
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$frame = $this->buildMainFrame();
$maniaLink->add($frame);
$frame->setZ(10);
// Create script and features
$script = new Script();
$maniaLink->setScript($script);
// Start offsets
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
$x = -$width / 2;
$y = $height / 2;
// Pagers
// Config
$pagerSize = 6.;
$pagesId = 'MxListPages';
$pagerPrev = new Quad_Icons64x64_1();
$frame->add($pagerPrev);
$pagerPrev->setPosition($width * 0.42, $height * -0.44, 2);
$pagerPrev->setSize($pagerSize, $pagerSize);
$pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev);
$pagerNext = new Quad_Icons64x64_1();
$frame->add($pagerNext);
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
$pagerNext->setSize($pagerSize, $pagerSize);
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
$script->addPager($pagerPrev, -1, $pagesId);
$script->addPager($pagerNext, 1, $pagesId);
$pageCountLabel = new Label_Text();
$frame->add($pageCountLabel);
$pageCountLabel->setHAlign(Control::RIGHT);
$pageCountLabel->setPosition($width * 0.40, $height * -0.44, 1);
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
$pageCountLabel->setTextSize(1.3);
$script->addPageLabel($pageCountLabel, $pagesId);
// Predefine Description Label
$descriptionLabel = new Label();
$frame->add($descriptionLabel);
$descriptionLabel->setAlign(Control::LEFT, Control::TOP);
$descriptionLabel->setPosition($x + 10, -$height / 2 + 5);
$descriptionLabel->setSize($width * 0.7, 4);
$descriptionLabel->setTextSize(2);
$descriptionLabel->setVisible(false);
// Headline
$headFrame = new Frame();
$frame->add($headFrame);
$headFrame->setY($y - 12);
$array = array('$oMx Id' => $x + 5, '$oName' => $x + 17, '$oAuthor' => $x + 65, '$oType' => $x + 100, '$oMood' => $x + 115, '$oLast Update' => $x + 130);
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
$i = 0;
$y = $height / 2 - 16;
$pageFrames = array();
foreach($maps as $map) { //TODO order possabilities
if (!isset($pageFrame)) {
$pageFrame = new Frame();
$frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 16;
$script->addPage($pageFrame, count($pageFrames), $pagesId);
}
// Map Frame
$mapFrame = new Frame();
$pageFrame->add($mapFrame);
if ($i % 2 == 0) {
$lineQuad = new Quad_BgsPlayerCard();
$mapFrame->add($lineQuad);
$lineQuad->setSize($width, 4);
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
$lineQuad->setZ(0.001);
}
/** @var MxMapInfo $map */
$time = Formatter::time_elapsed_string(strtotime($map->updated));
$array = array($map->id => $x + 5, $map->name => $x + 17, $map->author => $x + 65, str_replace("Arena", "", $map->maptype) => $x + 100, $map->mood => $x + 115, $time => $x + 130);
$labels = $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
/** @var Label_Text $authorLabel */
$authorLabel = $labels[2];
$authorLabel->setAction(self::ACTION_GET_MAPS_FROM_AUTHOR . '.' . $map->author);
$mapFrame->setY($y);
$mxQuad = new Quad();
$mapFrame->add($mxQuad);
$mxQuad->setSize(3, 3);
$mxQuad->setImage($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON));
$mxQuad->setImageFocus($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER));
$mxQuad->setX($x + 62);
$mxQuad->setUrl($map->pageurl);
$mxQuad->setZ(0.01);
$script->addTooltip($mxQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "View " . $map->name . " on Mania-Exchange"));
//TODO permission Clear Jukebox
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
$addQuad = new Quad_Icons64x64_1();
$mapFrame->add($addQuad);
$addQuad->setX($x + 59);
$addQuad->setZ(-0.1);
$addQuad->setSubStyle($addQuad::SUBSTYLE_Add);
$addQuad->setSize(4, 4);
$addQuad->setAction(self::ACTION_ADD_MAP . '.' . $map->id);
$addQuad->setZ(0.01);
$script->addTooltip($addQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => 'Add-Map: $<' . $map->name . '$>'));
}
//Award Quad
if ($map->awards > 0) {
$awardQuad = new Quad_Icons64x64_1();
$mapFrame->add($awardQuad);
$awardQuad->setSize(3, 3);
$awardQuad->setSubStyle($awardQuad::SUBSTYLE_OfficialRace);
$awardQuad->setX($x + 93);
$awardQuad->setZ(0.01);
$awardLabel = new Label_Text();
$mapFrame->add($awardLabel);
$awardLabel->setX($x + 94.5);
$awardLabel->setHAlign(Control::LEFT);
$awardLabel->setText($map->awards);
$awardLabel->setTextSize(1.3);
}
$y -= 4;
$i++;
if ($i % self::MAX_MX_MAPS_PER_PAGE == 0) {
unset($pageFrame);
}
}
$label = new Label_Text();
$frame->add($label);
$label->setPosition(-$width / 2 + 5, $height / 2 - 5);
$label->setHAlign(Control::LEFT);
$label->setTextSize(1.3);
$label->setText("Search:");
$entry = new Entry();
$frame->add($entry);
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
$entry->setHAlign(Control::LEFT);
$entry->setPosition(-$width / 2 + 15, $height / 2 - 5);
$entry->setTextSize(1);
$entry->setSize($width * 0.25, 4);
$entry->setName('SearchString');
//Search for Map-Name
$label = new Label_Button();
$frame->add($label);
$label->setPosition(-$width / 2 + 63, $height / 2 - 5);
$label->setText("MapName");
$label->setTextSize(1.3);
$quad = new Quad_BgsPlayerCard();
$frame->add($quad);
$quad->setPosition(-$width / 2 + 63, $height / 2 - 5, 0.01);
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
$quad->setSize(18, 5);
$quad->setAction(self::ACTION_SEARCH_MAPNAME);
//Search for Author
$label = new Label_Button();
$frame->add($label);
$label->setPosition(-$width / 2 + 82, $height / 2 - 5);
$label->setText("Author");
$label->setTextSize(1.3);
$quad = new Quad_BgsPlayerCard();
$frame->add($quad);
$quad->setPosition(-$width / 2 + 82, $height / 2 - 5, 0.01);
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
$quad->setSize(18, 5);
$quad->setAction(self::ACTION_SEARCH_AUTHOR);
// render and display xml
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'MxList');
}
/**
* Builds the mainFrame
*
* @return Frame $frame
*/
public function buildMainFrame() {
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
// mainframe
$frame = new Frame();
$frame->setSize($width, $height);
$frame->setPosition(0, 0);
// Background Quad
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
// 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(ManialinkManager::ACTION_CLOSEWIDGET);
return $frame;
}
/** /**
* Displayes a MapList on the screen * Displayes a MapList on the screen
@ -387,10 +106,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
// Get Maplist // Get Maplist
$mapList = $this->maniaControl->mapManager->getMaps(); $mapList = $this->maniaControl->mapManager->getMaps();
$this->mapListShown[$player->login] = self::SHOW_MAP_LIST; $this->mapListShown[$player->login] = true;
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$frame = $this->buildMainFrame(); $frame = $this->maniaControl->manialinkManager->styleManager->defaultListFrame();
$maniaLink->add($frame); $maniaLink->add($frame);
$frame->setZ(10); $frame->setZ(10);
@ -740,7 +459,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$player = $callback[1]; $player = $callback[1];
$openedWidget = $callback[2]; $openedWidget = $callback[2];
//unset when another main widget got opened //unset when another main widget got opened
if ($openedWidget != 'MapList' && $openedWidget != 'MxList') { if ($openedWidget != 'MapList') {
unset($this->mapListShown[$player->login]); unset($this->mapListShown[$player->login]);
} }
} }
@ -783,13 +502,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$mapId = (int)$actionArray[2]; $mapId = (int)$actionArray[2];
switch($action) { switch($action) {
case self::ACTION_GET_MAPS_FROM_AUTHOR:
$callback[1][2] = 'auth:' . $actionArray[2];
$this->showManiaExchangeList($callback, $player);
break;
case self::ACTION_ADD_MAP:
$this->maniaControl->mapManager->addMapFromMx($mapId, $player->login);
break;
case self::ACTION_UPDATE_MAP: case self::ACTION_UPDATE_MAP:
$mapUid = $actionArray[2]; $mapUid = $actionArray[2];
$this->maniaControl->mapManager->updateMap($player, $mapUid); $this->maniaControl->mapManager->updateMap($player, $mapUid);
@ -831,9 +543,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
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) {
//nothing to update yet
} else if ($shown == self::SHOW_MAP_LIST) {
$this->showMapList($player); $this->showMapList($player);
} }
} else { } else {

View File

@ -8,6 +8,7 @@ use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\FileUtil; use ManiaControl\FileUtil;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\ManiaExchange\ManiaExchangeList;
use ManiaControl\ManiaExchange\ManiaExchangeManager; use ManiaControl\ManiaExchange\ManiaExchangeManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
@ -34,6 +35,7 @@ class MapManager implements CallbackListener {
public $mapQueue = null; public $mapQueue = null;
public $mapCommands = null; public $mapCommands = null;
public $mapList = null; public $mapList = null;
public $mxList = null;
public $mxManager = null; public $mxManager = null;
/** /**
@ -54,10 +56,11 @@ class MapManager implements CallbackListener {
$this->initTables(); $this->initTables();
// Create map commands instance // Create map commands instance
$this->mxManager = new ManiaExchangeManager($this->maniaControl);
$this->mapList = new MapList($this->maniaControl); $this->mapList = new MapList($this->maniaControl);
$this->mxList = new ManiaExchangeList($this->maniaControl);
$this->mapCommands = new MapCommands($maniaControl); $this->mapCommands = new MapCommands($maniaControl);
$this->mapQueue = new MapQueue($this->maniaControl); $this->mapQueue = new MapQueue($this->maniaControl);
$this->mxManager = new ManiaExchangeManager($this->maniaControl);
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');