mxlist adjustments for mp4

This commit is contained in:
kremsy 2017-05-12 21:16:54 +02:00
parent 84eec14b8d
commit b202ea7dc8
3 changed files with 16 additions and 47 deletions

View File

@ -2,11 +2,9 @@
namespace ManiaControl\ManiaExchange;
use FML\Components\CheckBox;
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;
@ -41,9 +39,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
const ACTION_SEARCH_MAPNAME = 'ManiaExchangeList.SearchMapName';
const ACTION_SEARCH_AUTHOR = 'ManiaExchangeList.SearchAuthor';
const ACTION_GET_MAPS_FROM_AUTHOR = 'ManiaExchangeList.GetMapsFromAuthor';
const ACTION_TOGGLE_MP4 = 'ManiaExchangeList.ToggleMp4';
const MAX_MX_MAPS_PER_PAGE = 14;
const CACHE_SHOWMP4ONLY = 'ManiaExchangeList.Mp4Only';
/*
* Private properties
@ -67,7 +63,6 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SEARCH_MAPNAME, $this, 'showListCommand');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SEARCH_AUTHOR, $this, 'showListCommand');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_TOGGLE_MP4, $this, 'toggleMP4MapsOnly');
}
/**
@ -152,9 +147,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$mxSearch->setAuthorName($author);
$mxSearch->setEnvironments($environment);
$mxSearch->setMapName($searchString);
if ($player->getCache($this, self::CACHE_SHOWMP4ONLY)) {
$mxSearch->setMapGroup(2);
}
$mxSearch->fetchMapsAsync(function (array $maps) use (&$player) {
if (!$maps) {
$this->maniaControl->getChat()->sendError('No maps found, or MX is down!', $player->login);
@ -326,40 +319,11 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$searchFrame->setY($height / 2 - 5);
$frame->addChild($searchFrame);
//Seach for MP4Maps
$quad = new Quad();
$quad->setPosition($width / 2 - 30, $height / 2 - 5, -0.01)->setSize(4, 4);
$checkBox = new CheckBox(self::ACTION_TOGGLE_MP4, $player->getCache($this, self::CACHE_SHOWMP4ONLY), $quad);
$quad->setAction(self::ACTION_TOGGLE_MP4);
$frame->addChild($checkBox);
$label = new Label_Button();
$frame->addChild($label);
$label->setPosition($width / 2 - 28, $height / 2 - 5);
$label->setText('Only MP4-Maps');
$label->setTextSize(1.3);
$label->setHorizontalAlign($label::LEFT);
// render and display xml
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'ManiaExchangeList');
}
/**
* Toggle to view mp4 maps only for a player
*
* @param array $callback
* @param \ManiaControl\Players\Player $player
*/
public function toggleMP4MapsOnly(array $callback, Player $player) {
if ($player->getCache($this, self::CACHE_SHOWMP4ONLY) === true) {
$player->setCache($this, self::CACHE_SHOWMP4ONLY, false);
} else {
$player->setCache($this, self::CACHE_SHOWMP4ONLY, true);
}
$this->getMXMapsAndShowList($player);
}
/**
* Unset the player if he opened another Main Widget
*

View File

@ -64,7 +64,7 @@ class ManiaExchangeManager implements UsageInformationAble {
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MX_KEY, "");
//$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MX_KEY, "");
}
/**
@ -166,9 +166,9 @@ class ManiaExchangeManager implements UsageInformationAble {
// compile search URL
$url = "https://api.mania-exchange.com/{$titlePrefix}/maps/?ids={$string}";
if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KEY)) {
/*if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KEY)) {
$url .= "&key=" . $key;
}
}*/
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $url);
$asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON);
@ -267,9 +267,9 @@ class ManiaExchangeManager implements UsageInformationAble {
// compile search URL
$url = 'https://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $mapId;
if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KEY)) {
/*if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KEY)) {
$url .= "&key=" . $key;
}
}*/
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $url);
$asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON);

View File

@ -85,6 +85,7 @@ class ManiaExchangeMapSearch implements UsageInformationAble {
private $ghostBlocks = null;
private $embeddedObjects = null;
private $key = null;
private $mp4 = null;
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
@ -105,19 +106,20 @@ class ManiaExchangeMapSearch implements UsageInformationAble {
$this->url = 'https://' . $this->titlePrefix . '.mania-exchange.com/tracksearch2/search?api=on';
if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getMapManager()->getMXManager(), ManiaExchangeManager::SETTING_MX_KEY)) {
/*if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getMapManager()->getMXManager(), ManiaExchangeManager::SETTING_MX_KEY)) {
$this->url .= "&key=" . $key;
}
}*/
//Set some defaults:
$this->mapLimit = 100;
$this->priorityOrder = self::SEARCH_ORDER_UPDATED_NEWEST;
$this->mp4 = true;
//Set Min Exe Build Default for games which are not Trackmania
if ($this->titlePrefix !== "tm") {
/*if ($this->titlePrefix !== "tm") {
$this->minExeBuild = ManiaExchangeManager::MIN_EXE_BUILD;
}
}*/
//Set MapTypes
try {
@ -222,6 +224,9 @@ class ManiaExchangeMapSearch implements UsageInformationAble {
if (isset($this->key)) {
$parameters .= "&key=" . $this->key;
}
if (isset($this->mp4)){
$parameters .= "&mp4=" . $this->mp4;
}
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $this->url . $parameters);
$asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON);