improved paging code

This commit is contained in:
Steffen Schröder 2014-05-15 17:45:08 +02:00
parent d37acbd116
commit 74658044fc
10 changed files with 50 additions and 120 deletions

View File

@ -189,17 +189,14 @@ class HelpManager implements CommandListener, CallbackListener {
$array = array("Command" => $x + 5, "Description" => $x + 50); $array = array("Command" => $x + 5, "Description" => $x + 50);
$this->maniaControl->manialinkManager->labelLine($headFrame, $array); $this->maniaControl->manialinkManager->labelLine($headFrame, $array);
$i = 1; $i = 1;
$y = $y - 10; $y = $y - 10;
$pageFrames = array(); $pageFrame = null;
foreach ($commands as $command) { foreach ($commands as $command) {
if (!isset($pageFrame)) { if ($i % 15 === 1) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10; $y = $height / 2 - 10;
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
} }
@ -225,9 +222,6 @@ class HelpManager implements CommandListener, CallbackListener {
$y -= 4; $y -= 4;
$i++; $i++;
if (($i - 1) % 15 == 0) {
unset($pageFrame);
}
} }
// Render and display xml // Render and display xml

View File

@ -182,7 +182,6 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
$pagerSize = 9.; $pagerSize = 9.;
$settingHeight = 5.; $settingHeight = 5.;
$labelTextSize = 2; $labelTextSize = 2;
$pageMaxCount = 13;
// Pagers // Pagers
$pagerPrev = new Quad_Icons64x64_1(); $pagerPrev = new Quad_Icons64x64_1();
@ -210,8 +209,9 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
$paging->setLabel($pageCountLabel); $paging->setLabel($pageCountLabel);
// Setting pages // Setting pages
$pageFrames = array(); $pageFrame = null;
$y = 0.; $y = 0.;
foreach ($scriptParams as $index => $scriptParam) { foreach ($scriptParams as $index => $scriptParam) {
/** @var \Maniaplanet\DedicatedServer\Structures\ScriptSettings $scriptParam */ /** @var \Maniaplanet\DedicatedServer\Structures\ScriptSettings $scriptParam */
$settingName = $scriptParam->name; $settingName = $scriptParam->name;
@ -220,13 +220,9 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
continue; continue;
} }
if (!isset($pageFrame)) { if ($index % 13 === 0) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height * 0.41; $y = $height * 0.41;
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
} }
@ -285,9 +281,6 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
$nameLabel->addTooltipFeature($descriptionLabel); $nameLabel->addTooltipFeature($descriptionLabel);
$y -= $settingHeight; $y -= $settingHeight;
if ($index % $pageMaxCount == $pageMaxCount - 1) {
unset($pageFrame);
}
} }
return $frame; return $frame;

View File

@ -169,9 +169,10 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
$paging->setLabel($pageCountLabel); $paging->setLabel($pageCountLabel);
// Setting pages // Setting pages
$pageFrames = array(); $y = 0.;
$y = 0.; $id = 0;
$id = 0; $pageFrame = null;
foreach ($serverSettings as $name => $value) { foreach ($serverSettings as $name => $value) {
// Continue on CurrentMaxPlayers... // Continue on CurrentMaxPlayers...
$pos = strpos($name, "Current"); // TODO maybe display current somewhere $pos = strpos($name, "Current"); // TODO maybe display current somewhere
@ -179,13 +180,9 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
continue; continue;
} }
if (!isset($pageFrame)) { if ($id % 13 === 0) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height * 0.41; $y = $height * 0.41;
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
} }
@ -244,10 +241,6 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
} }
$y -= $settingHeight; $y -= $settingHeight;
if ($id % $pageMaxCount == $pageMaxCount - 1) {
unset($pageFrame);
}
$id++; $id++;
} }

View File

@ -16,8 +16,6 @@ use FML\ManiaLink;
use FML\Script\Features\Paging; use FML\Script\Features\Paging;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Utils\ColorUtil;
use ManiaControl\Utils\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\IconManager; use ManiaControl\Manialinks\IconManager;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
@ -25,6 +23,8 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Maps\MapCommands; use ManiaControl\Maps\MapCommands;
use ManiaControl\Maps\MapManager; use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Utils\ColorUtil;
use ManiaControl\Utils\Formatter;
/** /**
* ManiaExchange List Widget Class * ManiaExchange List Widget Class
@ -175,20 +175,17 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$array = array('$oId' => $x + 3.5, '$oName' => $x + 12.5, '$oAuthor' => $x + 59, '$oKarma' => $x + 85, '$oType' => $x + 103, '$oMood' => $x + 118, '$oLast Update' => $x + 130); $array = array('$oId' => $x + 3.5, '$oName' => $x + 12.5, '$oAuthor' => $x + 59, '$oKarma' => $x + 85, '$oType' => $x + 103, '$oMood' => $x + 118, '$oLast Update' => $x + 130);
$this->maniaControl->manialinkManager->labelLine($headFrame, $array); $this->maniaControl->manialinkManager->labelLine($headFrame, $array);
$i = 0; $i = 0;
$y = $height / 2 - 16; $y = $height / 2 - 16;
$pageFrames = array(); $pageFrame = null;
foreach ($maps as $map) { //TODO order possibilities
foreach ($maps as $map) {
//TODO order possibilities
/** @var MxMapInfo $map */ /** @var MxMapInfo $map */
if (!isset($pageFrame)) { if ($i % self::MAX_MX_MAPS_PER_PAGE === 0) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 16; $y = $height / 2 - 16;
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
} }
@ -285,9 +282,6 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$y -= 4; $y -= 4;
$i++; $i++;
if ($i % self::MAX_MX_MAPS_PER_PAGE == 0) {
unset($pageFrame);
}
} }
$label = new Label_Text(); $label = new Label_Text();

View File

@ -216,9 +216,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK; $pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK;
$paging->setStartPageNumber($pageIndex + 1); $paging->setStartPageNumber($pageIndex + 1);
$id = 1 + $mapsBeginIndex; $id = 1 + $mapsBeginIndex;
$y = $height / 2 - 10; $y = $height / 2 - 10;
$pageFrames = array(); $pageFrame = null;
/** @var Map $map */ /** @var Map $map */
$currentMap = $this->maniaControl->mapManager->getCurrentMap(); $currentMap = $this->maniaControl->mapManager->getCurrentMap();
$mxIcon = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON); $mxIcon = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON);
@ -227,15 +228,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$mxIconGreenHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN_MOVER); $mxIconGreenHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN_MOVER);
foreach ($mapList as $map) { foreach ($mapList as $map) {
if (!isset($pageFrame)) { if ($id % self::MAX_MAPS_PER_PAGE === 0) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10; $y = $height / 2 - 10;
$paging->addPage($pageFrame, $pageNumber); $paging->addPage($pageFrame, $pageNumber);
$pageNumber++; $pageNumber++;
} }
@ -466,9 +462,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
} }
$y -= 4; $y -= 4;
if ($id % self::MAX_MAPS_PER_PAGE == 0) {
unset($pageFrame);
}
$id++; $id++;
} }

View File

@ -67,9 +67,8 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
$pagerSize = 9.; $pagerSize = 9.;
$entryHeight = 5.; $entryHeight = 5.;
$labelTextSize = 2; $labelTextSize = 2;
$pageMaxCount = 10;
$y = 0.; $y = 0.;
$pageFrames = array(); $pageFrame = null;
// Pagers // Pagers
$pagerPrev = new Quad_Icons64x64_1(); $pagerPrev = new Quad_Icons64x64_1();
@ -110,14 +109,9 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
foreach ($pluginList as $plugin) { foreach ($pluginList as $plugin) {
if (!in_array($plugin->id, $pluginIds)) { if (!in_array($plugin->id, $pluginIds)) {
if (!isset($pageFrame)) { if ($index % 10 === 0) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
$y = $height * 0.41; $y = $height * 0.41;
} }
@ -159,10 +153,6 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
$installButton->setAction(self::ACTION_PREFIX_INSTALLPLUGIN . $plugin->id); $installButton->setAction(self::ACTION_PREFIX_INSTALLPLUGIN . $plugin->id);
$y -= $entryHeight; $y -= $entryHeight;
if ($index % $pageMaxCount == $pageMaxCount - 1) {
unset($pageFrame);
}
$index++; $index++;
} }
} }

View File

@ -1078,17 +1078,14 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$array = array("Rank" => $x + 5, "Nickname" => $x + 18, "Login" => $x + 70, "Time" => $x + 101); $array = array("Rank" => $x + 5, "Nickname" => $x + 18, "Login" => $x + 70, "Time" => $x + 101);
$this->maniaControl->manialinkManager->labelLine($headFrame, $array); $this->maniaControl->manialinkManager->labelLine($headFrame, $array);
$i = 0; $i = 0;
$y = $height / 2 - 10; $y = $height / 2 - 10;
$pageFrames = array(); $pageFrame = null;
foreach ($records as $listRecord) { foreach ($records as $listRecord) {
if (!isset($pageFrame)) { if ($i % 15 === 0) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10; $y = $height / 2 - 10;
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
} }
@ -1114,9 +1111,6 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$y -= 4; $y -= 4;
$i++; $i++;
if ($i % 15 == 0) {
unset($pageFrame);
}
} }
// Render and display xml // Render and display xml

View File

@ -484,22 +484,18 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$array = array('$oId' => $x + 5, '$oNickname' => $x + 18, '$oDonated planets' => $x + 70); $array = array('$oId' => $x + 5, '$oNickname' => $x + 18, '$oDonated planets' => $x + 70);
$this->maniaControl->manialinkManager->labelLine($headFrame, $array); $this->maniaControl->manialinkManager->labelLine($headFrame, $array);
$i = 1; $i = 1;
$y = $y - 10; $y = $y - 10;
$pageFrames = array(); $pageFrame = null;
foreach ($stats as $playerIndex => $donations) { foreach ($stats as $playerIndex => $donations) {
if (!isset($pageFrame)) { if ($i % 15 === 1) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10; $y = $height / 2 - 10;
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
} }
$playerFrame = new Frame(); $playerFrame = new Frame();
$pageFrame->add($playerFrame); $pageFrame->add($playerFrame);
$playerFrame->setY($y); $playerFrame->setY($y);
@ -518,9 +514,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$y -= 4; $y -= 4;
$i++; $i++;
if (($i - 1) % 15 == 0) {
unset($pageFrame);
}
if ($i > 100) { if ($i > 100) {
break; break;

View File

@ -573,19 +573,15 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$array = array("Rank" => $x + 5, "Nickname" => $x + 18, "Login" => $x + 70, "Time" => $x + 101); $array = array("Rank" => $x + 5, "Nickname" => $x + 18, "Login" => $x + 70, "Time" => $x + 101);
$this->maniaControl->manialinkManager->labelLine($headFrame, $array); $this->maniaControl->manialinkManager->labelLine($headFrame, $array);
$i = 0; $i = 0;
$y = $height / 2 - 10; $y = $height / 2 - 10;
$pageFrames = array(); $pageFrame = null;
foreach ($records as $listRecord) { foreach ($records as $listRecord) {
if (!isset($pageFrame)) { if ($i % 15 === 0) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10; $y = $height / 2 - 10;
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
} }
@ -610,9 +606,6 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$y -= 4; $y -= 4;
$i++; $i++;
if ($i % 15 == 0) {
unset($pageFrame);
}
} }
// Render and display xml // Render and display xml

View File

@ -487,22 +487,18 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$array = array('$oRank' => $x + 5, '$oNickname' => $x + 18, '$oAverage' => $x + 70); $array = array('$oRank' => $x + 5, '$oNickname' => $x + 18, '$oAverage' => $x + 70);
$this->maniaControl->manialinkManager->labelLine($headFrame, $array); $this->maniaControl->manialinkManager->labelLine($headFrame, $array);
$i = 1; $i = 1;
$y = $y - 10; $y = $y - 10;
$pageFrames = array(); $pageFrame = null;
while ($rankedPlayer = $result->fetch_object()) { while ($rankedPlayer = $result->fetch_object()) {
if (!isset($pageFrame)) { if ($i % 15 === 1) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10; $y = $height / 2 - 10;
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
} }
$playerFrame = new Frame(); $playerFrame = new Frame();
$pageFrame->add($playerFrame); $pageFrame->add($playerFrame);
$playerFrame->setY($y); $playerFrame->setY($y);
@ -521,9 +517,6 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$y -= 4; $y -= 4;
$i++; $i++;
if (($i - 1) % 15 == 0) {
unset($pageFrame);
}
} }
// Render and display xml // Render and display xml