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

@ -191,15 +191,12 @@ class HelpManager implements CommandListener, CallbackListener {
$i = 1;
$y = $y - 10;
$pageFrames = array();
$pageFrame = null;
foreach ($commands as $command) {
if (!isset($pageFrame)) {
if ($i % 15 === 1) {
$pageFrame = new Frame();
$frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10;
$paging->addPage($pageFrame);
}
@ -225,9 +222,6 @@ class HelpManager implements CommandListener, CallbackListener {
$y -= 4;
$i++;
if (($i - 1) % 15 == 0) {
unset($pageFrame);
}
}
// Render and display xml

View File

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

View File

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

View File

@ -16,8 +16,6 @@ use FML\ManiaLink;
use FML\Script\Features\Paging;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Utils\ColorUtil;
use ManiaControl\Utils\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\IconManager;
use ManiaControl\Manialinks\ManialinkManager;
@ -25,6 +23,8 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Maps\MapCommands;
use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player;
use ManiaControl\Utils\ColorUtil;
use ManiaControl\Utils\Formatter;
/**
* ManiaExchange List Widget Class
@ -177,18 +177,15 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$i = 0;
$y = $height / 2 - 16;
$pageFrames = array();
foreach ($maps as $map) { //TODO order possibilities
$pageFrame = null;
foreach ($maps as $map) {
//TODO order possibilities
/** @var MxMapInfo $map */
if (!isset($pageFrame)) {
if ($i % self::MAX_MX_MAPS_PER_PAGE === 0) {
$pageFrame = new Frame();
$frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 16;
$paging->addPage($pageFrame);
}
@ -285,9 +282,6 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$y -= 4;
$i++;
if ($i % self::MAX_MX_MAPS_PER_PAGE == 0) {
unset($pageFrame);
}
}
$label = new Label_Text();

View File

@ -218,7 +218,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$id = 1 + $mapsBeginIndex;
$y = $height / 2 - 10;
$pageFrames = array();
$pageFrame = null;
/** @var Map $map */
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
$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);
foreach ($mapList as $map) {
if (!isset($pageFrame)) {
if ($id % self::MAX_MAPS_PER_PAGE === 0) {
$pageFrame = new Frame();
$frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10;
$paging->addPage($pageFrame, $pageNumber);
$pageNumber++;
}
@ -466,9 +462,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
}
$y -= 4;
if ($id % self::MAX_MAPS_PER_PAGE == 0) {
unset($pageFrame);
}
$id++;
}

View File

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

View File

@ -1080,15 +1080,12 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$i = 0;
$y = $height / 2 - 10;
$pageFrames = array();
$pageFrame = null;
foreach ($records as $listRecord) {
if (!isset($pageFrame)) {
if ($i % 15 === 0) {
$pageFrame = new Frame();
$frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10;
$paging->addPage($pageFrame);
}
@ -1114,9 +1111,6 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$y -= 4;
$i++;
if ($i % 15 == 0) {
unset($pageFrame);
}
}
// Render and display xml

View File

@ -486,20 +486,16 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$i = 1;
$y = $y - 10;
$pageFrames = array();
$pageFrame = null;
foreach ($stats as $playerIndex => $donations) {
if (!isset($pageFrame)) {
if ($i % 15 === 1) {
$pageFrame = new Frame();
$frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10;
$paging->addPage($pageFrame);
}
$playerFrame = new Frame();
$pageFrame->add($playerFrame);
$playerFrame->setY($y);
@ -518,9 +514,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$y -= 4;
$i++;
if (($i - 1) % 15 == 0) {
unset($pageFrame);
}
if ($i > 100) {
break;

View File

@ -575,17 +575,13 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$i = 0;
$y = $height / 2 - 10;
$pageFrames = array();
$pageFrame = null;
foreach ($records as $listRecord) {
if (!isset($pageFrame)) {
if ($i % 15 === 0) {
$pageFrame = new Frame();
$frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10;
$paging->addPage($pageFrame);
}
@ -610,9 +606,6 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$y -= 4;
$i++;
if ($i % 15 == 0) {
unset($pageFrame);
}
}
// Render and display xml

View File

@ -489,20 +489,16 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$i = 1;
$y = $y - 10;
$pageFrames = array();
$pageFrame = null;
while ($rankedPlayer = $result->fetch_object()) {
if (!isset($pageFrame)) {
if ($i % 15 === 1) {
$pageFrame = new Frame();
$frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10;
$paging->addPage($pageFrame);
}
$playerFrame = new Frame();
$pageFrame->add($playerFrame);
$playerFrame->setY($y);
@ -521,9 +517,6 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$y -= 4;
$i++;
if (($i - 1) % 15 == 0) {
unset($pageFrame);
}
}
// Render and display xml