Added search feature to map list

Enhanced mx list x values
Added setY to LabelLine
Renamed setPosZ to setZ (same as in FML)
This commit is contained in:
Jocy 2017-04-12 17:56:43 +02:00
parent 1ac702f29e
commit 09b974e2cc
6 changed files with 188 additions and 74 deletions

View File

@ -3,7 +3,6 @@
namespace ManiaControl\ManiaExchange;
use FML\Components\CheckBox;
use FML\Controls\Entry;
use FML\Controls\Frame;
use FML\Controls\Gauge;
use FML\Controls\Label;
@ -239,7 +238,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$labelLine->addLabelEntryText($map->id, $posX + 3.5, 9);
$labelLine->addLabelEntryText($map->name, $posX + 12.5, 38.5);
$labelLine->addLabelEntryText($map->author, $posX + 59, 44, self::ACTION_GET_MAPS_FROM_AUTHOR . '.' . $map->author);
$labelLine->addLabelEntryText($map->author, $posX + 59, 20, self::ACTION_GET_MAPS_FROM_AUTHOR . '.' . $map->author);
$labelLine->addLabelEntryText(str_replace('Arena', '', $map->maptype), $posX + 103, 15);
$labelLine->addLabelEntryText($map->mood, $posX + 118, 12);
$labelLine->addLabelEntryText($time, $posX + 130, $width - ($posX + 130));
@ -275,6 +274,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
}
//Award Quad
$map->awards = 12; //TODO delete
if ($map->awards > 0) {
$awardQuad = new Quad_Icons64x64_1();
$mapFrame->addChild($awardQuad);
@ -297,9 +297,10 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
if (is_numeric($karma) && $voteCount > 0) {
$karmaGauge = new Gauge();
$mapFrame->addChild($karmaGauge);
$karmaGauge->setZ(2);
$karmaGauge->setX($posX + 89);
$karmaGauge->setSize(16.5, 9);
$karmaGauge->setZ(-0.05);
$karmaGauge->setX($posX + 87);
$karmaGauge->setY(0.2);
$karmaGauge->setSize(20, 10);
$karmaGauge->setDrawBackground(false);
$karma = floatval($karma);
$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
@ -308,9 +309,10 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$karmaLabel = new Label();
$mapFrame->addChild($karmaLabel);
$karmaLabel->setZ(2);
$karmaLabel->setX($posX + 89);
$karmaLabel->setSize(16.5 * 0.9, 5);
$karmaLabel->setZ(1);
$karmaLabel->setX($posX + 87);
$karmaLabel->setSize(20 * 0.9, 5);
$karmaLabel->setY(-0.2);
$karmaLabel->setTextSize(0.9);
$karmaLabel->setTextColor('000');
$karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $voteCount . ')');
@ -321,52 +323,9 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$index++;
}
$label = new Label_Text();
$frame->addChild($label);
$label->setPosition(-$width / 2 + 5, $height / 2 - 5);
$label->setHorizontalAlign($label::LEFT);
$label->setTextSize(1.3);
$label->setText('Search: ');
$entry = new Entry();
$frame->addChild($entry);
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
$entry->setHorizontalAlign($entry::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->addChild($label);
$label->setPosition(-$width / 2 + 63, $height / 2 - 5);
$label->setText('MapName');
$label->setTextSize(1.3);
$quad = new Quad_BgsPlayerCard();
$frame->addChild($quad);
$quad->setPosition(-$width / 2 + 63, $height / 2 - 5);
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
$quad->setSize(18, 5);
$quad->setAction(self::ACTION_SEARCH_MAPNAME);
$quad->setZ(-0.1);
//Search for Author
$label = new Label_Button();
$frame->addChild($label);
$label->setPosition(-$width / 2 + 82, $height / 2 - 5);
$label->setText('Author');
$label->setTextSize(1.3);
$quad = new Quad_BgsPlayerCard();
$frame->addChild($quad);
$quad->setPosition(-$width / 2 + 82, $height / 2 - 5);
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
$quad->setSize(18, 5);
$quad->setAction(self::ACTION_SEARCH_AUTHOR);
$quad->setZ(-0.1);
$searchFrame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMapSearch(self::ACTION_SEARCH_MAPNAME,self::ACTION_SEARCH_AUTHOR);
$searchFrame->setY($height / 2 - 5);
$frame->addChild($searchFrame);
//Seach for MP4Maps
$quad = new Quad();

View File

@ -27,6 +27,7 @@ class LabelLine implements UsageInformationAble {
private $textColor = 'FFF';
private $posZ = 0;
private $prefix = '';
private $posY = 0;
public function __construct(Frame $frame) {
@ -78,6 +79,7 @@ class LabelLine implements UsageInformationAble {
$entry->setTextSize($this->textSize);
$entry->setTextColor($this->textColor);
$entry->setZ($this->posZ);
$entry->setY($this->posY);
$entry->setTextPrefix($this->prefix);
$this->frame->addChild($entry);
@ -143,17 +145,31 @@ class LabelLine implements UsageInformationAble {
/**
* @return int
*/
public function getPosZ() {
public function getZ() {
return $this->posZ;
}
/**
* @param int $posZ
*/
public function setPosZ($posZ) {
public function setZ($posZ) {
$this->posZ = $posZ;
}
/**
* @return int
*/
public function getY() {
return $this->posY;
}
/**
* @param int $posY
*/
public function setY($posY) {
$this->posY = $posY;
}
/**
* @return \FML\Controls\Labels\Label_Text[]
*/

View File

@ -377,7 +377,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener,
$labelLine->setStyle($style);
$labelLine->setTextSize($textSize);
$labelLine->setTextColor($textColor);
$labelLine->setPosZ($posZ);
$labelLine->setZ($posZ);
/**
* @var Label_Text $prevLabel

View File

@ -2,12 +2,15 @@
namespace ManiaControl\Manialinks;
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_BgRaceScore2;
use FML\Controls\Quads\Quad_Bgs1InRace;
use FML\Controls\Quads\Quad_BgsPlayerCard;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Script\Features\Paging;
use FML\Script\Script;
@ -118,6 +121,68 @@ class StyleManager implements UsageInformationAble {
return $descriptionLabel;
}
/**
* Gets the default buttons and textbox for a map search
*
* @param string $actionMapNameSearch
* @param string $actionAuthorSearch
* @return \FML\Controls\Frame
*/
public function getDefaultMapSearch($actionMapNameSearch, $actionAuthorSearch){
$width = $this->getListWidgetsWidth();
$frame = new Frame();
$label = new Label_Text();
$frame->addChild($label);
$label->setPosition(-$width / 2 + 5, 0);
$label->setHorizontalAlign($label::LEFT);
$label->setTextSize(1.3);
$label->setText('Search: ');
$entry = new Entry();
$frame->addChild($entry);
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
$entry->setHorizontalAlign($entry::LEFT);
$entry->setPosition(-$width / 2 + 15, 0);
$entry->setTextSize(1);
$entry->setSize($width * 0.25, 4);
$entry->setName('SearchString');
//Search for Map-Name
$label = new Label_Button();
$frame->addChild($label);
$label->setPosition(-$width / 2 + 63, 0);
$label->setText('MapName');
$label->setTextSize(1.3);
$quad = new Quad_BgsPlayerCard();
$frame->addChild($quad);
$quad->setPosition(-$width / 2 + 63, 0);
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
$quad->setSize(18, 5);
$quad->setAction($actionMapNameSearch);
$quad->setZ(-0.1);
//Search for Author
$label = new Label_Button();
$frame->addChild($label);
$label->setPosition(-$width / 2 + 82, 0);
$label->setText('Author');
$label->setTextSize(1.3);
$quad = new Quad_BgsPlayerCard();
$frame->addChild($quad);
$quad->setPosition(-$width / 2 + 82, 0);
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
$quad->setSize(18, 5);
$quad->setAction($actionAuthorSearch);
$quad->setZ(-0.1);
return $frame;
}
/**
* Get the Default List Widgets Width
*

View File

@ -52,7 +52,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
const ACTION_CHECK_UPDATE = 'MapList.CheckUpdate';
const ACTION_CLEAR_MAPQUEUE = 'MapList.ClearMapQueue';
const ACTION_PAGING_CHUNKS = 'MapList.PagingChunk.';
const MAX_MAPS_PER_PAGE = 15;
const ACTION_SEARCH_MAP_NAME = 'MapList.SearchMapName';
const ACTION_SEARCH_AUTHOR = 'MapList.SearchAuthor';
const MAX_MAPS_PER_PAGE = 13;
const MAX_PAGES_PER_CHUNK = 2;
const DEFAULT_KARMA_PLUGIN = 'MCTeam\KarmaPlugin';
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
@ -84,6 +86,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_CHECK_UPDATE, $this, 'checkUpdates');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SEARCH_MAP_NAME, $this, 'searchByMapName');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SEARCH_AUTHOR, $this, 'searchByAuthor');
}
/**
@ -186,7 +191,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$label->setWidth(30);
$label->setHorizontalAlign($label::RIGHT);
$quad = new Quad_BgsPlayerCard();
$frame->addChild($quad);
$quad->setPosition($mxCheckForUpdatesX, $buttonY, 0.01);
@ -201,8 +205,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$mxQuad->setImageUrl($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_GREEN));
$mxQuad->setImageFocusUrl($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_GREEN_MOVER));
$mxQuad->setPosition($mxCheckForUpdatesX - $buttonWidth + 3, $buttonY);
$mxQuad->setZ(0.02);
$mxQuad->setAction(self::ACTION_CHECK_UPDATE);
$mxQuad->setZ(0.2);
}
if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
@ -233,8 +236,12 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$labelLine->addLabelEntryText('Map Name', $posX + 20);
$labelLine->addLabelEntryText('Author', $posX + 68);
$labelLine->addLabelEntryText('Actions', $width / 2 - 16);
$labelLine->setY(-7);
$labelLine->render();
$searchFrame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMapSearch(self::ACTION_SEARCH_MAP_NAME,self::ACTION_SEARCH_AUTHOR);
$headFrame->addChild($searchFrame);
// Predefine description Label
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
$frame->addChild($descriptionLabel);
@ -248,7 +255,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$index = 0;
$mapListId = 1 + $mapsBeginIndex;
$posY = $height / 2 - 10;
$posY = $height / 2 - 16;
$pageFrame = null;
$currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
@ -262,7 +269,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
if ($index % self::MAX_MAPS_PER_PAGE === 0) {
$pageFrame = new Frame();
$frame->addChild($pageFrame);
$posY = $height / 2 - 10;
$posY = $height / 2 - 16;
$paging->addPageControl($pageFrame, $pageNumber);
$pageNumber++;
}
@ -488,9 +495,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$karmaGauge = new Gauge();
$mapFrame->addChild($karmaGauge);
$karmaGauge->setZ(2);
$karmaGauge->setZ(0.2);
$karmaGauge->setX($posX + 120);
$karmaGauge->setSize(20, 9);
$karmaGauge->setY(0.2);
$karmaGauge->setSize(20, 10);
$karmaGauge->setDrawBackground(false);
$karma = floatval($karma);
$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
@ -502,6 +510,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$karmaLabel->setZ(2);
$karmaLabel->setX($posX + 120);
$karmaLabel->setSize(20 * 0.9, 5);
$karmaLabel->setY(-0.2);
$karmaLabel->setTextSize(0.9);
$karmaLabel->setTextColor('000');
$karmaLabel->setText($karmaText);
@ -513,8 +522,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$index++;
}
//var_dump($this->maniaControl->getMapManager()->searchMaps('nadeolabs'));
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, self::WIDGET_NAME);
}
@ -725,6 +732,38 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
}
}
/**
* Listener for search button
*
* @param array $callback
* @internal
*/
public function searchByMapName(array $callback) {
$login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
$searchString = $callback[1][3][0]['Value'];
$maps = $this->maniaControl->getMapManager()->searchMapsByMapName($searchString);
$this->showMapList($player, $maps);
}
/**
* Listener for search button
*
* @param array $callback
* @internal
*/
public function searchByAuthor(array $callback) {
$login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
$searchString = $callback[1][3][0]['Value'];
$maps = $this->maniaControl->getMapManager()->searchMapsByAuthor($searchString);
$this->showMapList($player, $maps);
}
/**
* Close the widget for
*

View File

@ -56,6 +56,9 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
const SETTING_MAPLIST_FILE = 'File to write Maplist in';
const SETTING_WRITE_OWN_MAPLIST_FILE = 'Write a own Maplist File for every Server called serverlogin.txt';
const SEARCH_BY_AUTHOR = 'Author';
const SEARCH_BY_MAP_NAME = 'Mapname';
/*
* Private properties
@ -977,25 +980,57 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
});
}
/**
* Search maps by a given String for Author and Name
* Searches the current map list for an author
*
* @param $searchString
* @return array
*/
public function searchMaps($searchString) {
public function searchMapsByAuthor($searchString){
return $this->searchMaps($searchString,self::SEARCH_BY_AUTHOR);
}
/**
* Searches the current map list for a map name
*
* @param $searchString
* @return array
*/
public function searchMapsByMapName($searchString){
return $this->searchMaps($searchString,self::SEARCH_BY_MAP_NAME);
}
/**
* Searches the current map list
*
* @param $searchString
* @param string $searchBy
* @return array
*/
private function searchMaps($searchString, $searchBy = self::SEARCH_BY_MAP_NAME) {
$result = array();
$searchString = strtolower($searchString);
foreach ($this->maps as $map) {
if (strpos($map->name, $searchString) || strpos($map->authorLogin, $searchString)) {
;
}
{
array_push($result, $map);
switch ($searchBy) {
case self::SEARCH_BY_MAP_NAME:
$mapName = strtolower(Formatter::stripCodes($map->name));
if (strpos($mapName, $searchString) !== false) {
array_push($result, $map);
}
break;
case self::SEARCH_BY_AUTHOR:
if (strpos(strtolower($map->authorLogin), $searchString) !== false) {
array_push($result, $map);
}
}
}
return $result;
}
/**
* Initialize necessary database tables
*