added paging chunks to maplist
This commit is contained in:
parent
cac3550856
commit
8b83825344
@ -29,7 +29,7 @@ class Paging extends ScriptFeature {
|
||||
protected $pages = array();
|
||||
protected $buttons = array();
|
||||
protected $label = null;
|
||||
protected $customMinPageNumber = null;
|
||||
protected $startPageNumber = null;
|
||||
protected $customMaxPageNumber = null;
|
||||
protected $previousChunkAction = null;
|
||||
protected $nextChunkAction = null;
|
||||
@ -119,14 +119,13 @@ class Paging extends ScriptFeature {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a custom Minimum Page Number for using Chunks
|
||||
* Set the Start Page Number
|
||||
*
|
||||
* @param int $minPageNumber Custom Minimum Page Number
|
||||
* @param int $startPageNumber Page Number to start with
|
||||
* @return \FML\Script\Features\Paging
|
||||
*/
|
||||
public function setCustomMinPageNumber($minPageNumber) {
|
||||
$this->customMinPageNumber = (int) $minPageNumber;
|
||||
return $this;
|
||||
public function setStartPageNumber($startPageNumber) {
|
||||
$this->startPageNumber = (int) $startPageNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,6 +161,18 @@ class Paging extends ScriptFeature {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Actions triggered when another Chunk is needed
|
||||
*
|
||||
* @param string $chunkAction Triggered Action
|
||||
* @return \FML\Script\Features\Paging
|
||||
*/
|
||||
public function setChunkActions($chunkAction) {
|
||||
$this->setNextChunkAction($chunkAction);
|
||||
$this->setPreviousChunkAction($chunkAction);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the Chunk Action should get the needed Page Number appended
|
||||
*
|
||||
@ -187,19 +198,15 @@ class Paging extends ScriptFeature {
|
||||
$currentPageVariable = self::VAR_CURRENT_PAGE;
|
||||
$updatePageFunction = self::FUNCTION_UPDATE_CURRENT_PAGE;
|
||||
|
||||
$minPage = $this->getMinPage();
|
||||
$startPageNumber = $minPage->getPageNumber();
|
||||
$minPageNumber = $startPageNumber;
|
||||
if (is_int($this->customMinPageNumber)) {
|
||||
$minPageNumber = $this->customMinPageNumber;
|
||||
}
|
||||
$minPageNumber = 1;
|
||||
$startPageNumber = (is_int($this->startPageNumber) ? $this->startPageNumber : $minPageNumber);
|
||||
$maxPage = $this->getMaxPage();
|
||||
$maxPageNumber = $maxPage->getPageNumber();
|
||||
if (is_int($this->customMaxPageNumber)) {
|
||||
$maxPageNumber = $this->customMaxPageNumber;
|
||||
$maxPageNumber = $this->customMaxPageNumber;
|
||||
if (!is_int($maxPageNumber)) {
|
||||
$maxPageNumber = $maxPage->getPageNumber();
|
||||
}
|
||||
|
||||
$pagingId = $minPage->getControl()->getId(true);
|
||||
$pagingId = $maxPage->getControl()->getId(true);
|
||||
$pageLabelId = '';
|
||||
if ($this->label) {
|
||||
$pageLabelId = $this->label->getId(true);
|
||||
@ -247,6 +254,7 @@ Void {$updatePageFunction}(Text _PagingId, Text _PageLabelId, Integer _BrowseAct
|
||||
PageFound = True;
|
||||
}
|
||||
}
|
||||
log(Now^PageFound^CurrentPage^_Pages);
|
||||
if (!PageFound && _BrowseAction != 0) {
|
||||
declare Text ChunkAction;
|
||||
if (_BrowseAction < 0) {
|
||||
@ -257,6 +265,7 @@ Void {$updatePageFunction}(Text _PagingId, Text _PageLabelId, Integer _BrowseAct
|
||||
if (_ChunkActionAppendPageNumber) {
|
||||
ChunkAction ^= CurrentPage;
|
||||
}
|
||||
log(Now^ChunkAction);
|
||||
TriggerPageAction(ChunkAction);
|
||||
}
|
||||
if (_PageLabelId == \"\") return;
|
||||
|
@ -81,7 +81,9 @@ class Script {
|
||||
else {
|
||||
$scriptFunction = new ScriptFunction($name, $text);
|
||||
}
|
||||
$this->functions[$scriptFunction->getName()] = $scriptFunction;
|
||||
if (!in_array($scriptFunction, $this->functions)) {
|
||||
array_push($this->functions, $scriptFunction);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -38,15 +38,6 @@ class ScriptFunction {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Text
|
||||
*
|
||||
|
@ -45,7 +45,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
const ACTION_UNQUEUE_MAP = 'MapList.UnQueueMap';
|
||||
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 MAX_PAGES_PER_CHUNK = 2;
|
||||
const DEFAULT_KARMA_PLUGIN = 'MCTeam\KarmaPlugin';
|
||||
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'CustomVotesPlugin';
|
||||
|
||||
@ -103,11 +105,14 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Displayes a MapList on the screen
|
||||
* Display a MapList on the Screen
|
||||
*
|
||||
* @param Player $player
|
||||
* @param array $maps
|
||||
* @param int $chunk
|
||||
* @param int $startPage
|
||||
*/
|
||||
public function showMapList(Player $player, $maps = null) {
|
||||
public function showMapList(Player $player, $maps = null, $chunk = 0, $startPage = null) {
|
||||
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
||||
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
||||
|
||||
@ -115,16 +120,15 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$queueBuffer = $this->maniaControl->mapManager->mapQueue->getQueueBuffer();
|
||||
|
||||
// Get Maps
|
||||
if (is_null($maps) && $maps != 'redirect') {
|
||||
$mapList = $this->maniaControl->mapManager->getMaps();
|
||||
$mapList = array();
|
||||
if (is_array($maps)) {
|
||||
$mapList = $maps;
|
||||
}
|
||||
else {
|
||||
if (array_key_exists($player->login, $this->mapsInListShown) && $maps == 'redirect') {
|
||||
$mapList = $this->mapsInListShown[$player->login];
|
||||
}
|
||||
else {
|
||||
$mapList = $maps;
|
||||
}
|
||||
else if ($maps !== 'redirect') {
|
||||
$mapList = $this->maniaControl->mapManager->getMaps($chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
|
||||
}
|
||||
else if (array_key_exists($player->login, $this->mapsInListShown)) {
|
||||
$mapList = $this->mapsInListShown[$player->login];
|
||||
}
|
||||
|
||||
$this->mapsInListShown[$player->login] = $mapList;
|
||||
@ -134,6 +138,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$script = $maniaLink->getScript();
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
$paging->setCustomMaxPageNumber($this->maniaControl->mapManager->getMapsCount() / self::MAX_MAPS_PER_PAGE);
|
||||
$paging->setChunkActionAppendsPageNumber(true);
|
||||
$paging->setChunkActions(self::ACTION_PAGING_CHUNKS);
|
||||
|
||||
// Main frame
|
||||
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
|
||||
@ -205,7 +212,11 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
*/
|
||||
$karmaPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_KARMA_PLUGIN);
|
||||
|
||||
$id = 1;
|
||||
$pageNumber = 1 + $chunk * self::MAX_PAGES_PER_CHUNK;
|
||||
$startPageNumber = (is_int($startPage) ? $startPage : $pageNumber);
|
||||
$paging->setStartPageNumber($startPageNumber);
|
||||
|
||||
$id = 1 + $chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE;
|
||||
$y = $height / 2 - 10;
|
||||
$pageFrames = array();
|
||||
/**
|
||||
@ -228,7 +239,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
array_push($pageFrames, $pageFrame);
|
||||
$y = $height / 2 - 10;
|
||||
|
||||
$paging->addPage($pageFrame);
|
||||
$paging->addPage($pageFrame, $pageNumber);
|
||||
$pageNumber++;
|
||||
}
|
||||
|
||||
// Map Frame
|
||||
@ -293,6 +305,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$labels = $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
|
||||
if (isset($labels[3])) {
|
||||
/**
|
||||
*
|
||||
* @var Label $label
|
||||
*/
|
||||
$label = $labels[3];
|
||||
@ -536,6 +549,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
public function handleManialinkPageAnswer(array $callback) {
|
||||
$actionId = $callback[1][2];
|
||||
$actionArray = explode('.', $actionId);
|
||||
|
||||
if (count($actionArray) <= 2) {
|
||||
return;
|
||||
}
|
||||
@ -575,6 +589,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
break;
|
||||
case self::ACTION_START_SWITCH_VOTE:
|
||||
/**
|
||||
*
|
||||
* @var $votesPlugin CustomVotesPlugin
|
||||
*/
|
||||
$votesPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
|
||||
@ -584,6 +599,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$message = '$<' . $player->nickname . '$>$s started a vote to switch to $<' . $map->name . '$>!';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Map $map
|
||||
*/
|
||||
$votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message);
|
||||
@ -613,6 +629,14 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$this->maniaControl->mapManager->mapQueue->removeFromMapQueue($player, $actionArray[2]);
|
||||
$this->showMapList($player, 'redirect');
|
||||
break;
|
||||
default:
|
||||
if (substr($actionId, 0, strlen(self::ACTION_PAGING_CHUNKS)) === self::ACTION_PAGING_CHUNKS) {
|
||||
// Paging chunks
|
||||
$neededPage = (int) substr($actionId, strlen(self::ACTION_PAGING_CHUNKS));
|
||||
$chunk = (int) ($neededPage / self::MAX_PAGES_PER_CHUNK - 0.5);
|
||||
$this->showMapList($player, null, $chunk, $neededPage);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -562,8 +562,23 @@ class MapManager implements CallbackListener {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMaps() {
|
||||
return array_values($this->maps);
|
||||
public function getMaps($offset = null, $length = null) {
|
||||
if ($offset === null) {
|
||||
return array_values($this->maps);
|
||||
}
|
||||
if ($length === null) {
|
||||
return array_slice($this->maps, $offset);
|
||||
}
|
||||
return array_slice($this->maps, $offset, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Number of Maps
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMapsCount() {
|
||||
return count($this->maps);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user