Fix various interfaces to adapt with different sizes

This commit is contained in:
Beu 2023-09-08 12:19:12 +02:00
parent d6745370b2
commit 2440de9b92
9 changed files with 60 additions and 29 deletions

View File

@ -108,7 +108,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
$pagerSize = 9.;
$settingHeight = 5.;
$labelTextSize = 2;
$pageMaxCount = 10;
$pageMaxCount = floor(($height * 0.78) / $settingHeight);
// Pagers
$pagerPrev = new Quad_Icons64x64_1();
@ -270,7 +270,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
$pagerSize = 9.;
$settingHeight = 5.;
$labelTextSize = 2;
$pageMaxCount = 10;
$pageMaxCount = floor(($height * 0.78) / $settingHeight);
// Pagers
$pagerPrev = new Quad_Icons64x64_1();
@ -387,7 +387,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
// Config
$pagerSize = 9.;
$settingHeight = 5.;
$pageMaxCount = 13;
$pageMaxCount = floor(($height * 0.78) / $settingHeight);
$posY = 0;
// Pagers

View File

@ -125,30 +125,36 @@ class StyleManager implements UsageInformationAble {
$frame = new Frame();
$posX = -$width / 2 + 5;
$label = new Label_Text();
$frame->addChild($label);
$label->setPosition(-$width / 2 + 5, 0);
$label->setPosition($posX, 0);
$label->setHorizontalAlign($label::LEFT);
$label->setTextSize(1);
$label->setText('Search: ');
$posX += 10;
$entry = new Entry();
$frame->addChild($entry);
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
$entry->setHorizontalAlign($entry::LEFT);
$entry->setPosition(-$width / 2 + 15, 0);
$entry->setPosition($posX, 0);
$entry->setTextSize(1);
$entry->setSize($width * 0.28, 4);
$entry->setName('SearchString');
$entry->setDefault($entryvalue);
$posX += $width * 0.28 + 10;
if ($actionReset) {
$quad = new Quad_Icons64x64_1();
$frame->addChild($quad);
$quad->setSubStyle($quad::SUBSTYLE_QuitRace);
$quad->setColorize('aaa');
$quad->setSize(5, 5);
$quad->setPosition(-$width / 2 + 20 + $width * 0.25 - 2, 0);
$quad->setPosition($posX - 12, 0);
$quad->setZ(1);
$quad->setAction($actionReset);
}
@ -161,7 +167,9 @@ class StyleManager implements UsageInformationAble {
$actionMapNameSearch
);
$frame->addChild($mapNameButton);
$mapNameButton->setX(-$width / 2 + 68);
$mapNameButton->setX($posX);
$posX += 20;
//Search for Author
$authorButton = $this->maniaControl->getManialinkManager()->getElementBuilder()->buildRoundTextButton(
@ -171,7 +179,7 @@ class StyleManager implements UsageInformationAble {
$actionAuthorSearch
);
$frame->addChild($authorButton);
$authorButton->setX(-$width / 2 + 87);
$authorButton->setX($posX);
return $frame;
}

View File

@ -140,6 +140,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$index = 0;
$posY = $height / 2 - 10;
$pageFrame = null;
$pageMaxCount = floor(($height * 0.85) / 4);
$navigateRootQuad = new Quad_Icons64x64_1();
$frame->addChild($navigateRootQuad);
@ -178,7 +179,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
foreach ($mapFiles as $filePath => $fileName) {
$shortFilePath = substr($filePath, strlen($folderPath));
if ($index % 15 === 0) {
if ($index % $pageMaxCount === 0) {
// New Page
$pageFrame = new Frame();
$frame->addChild($pageFrame);

View File

@ -55,7 +55,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
const ACTION_SEARCH_MAP_NAME = 'MapList.SearchMapName';
const ACTION_SEARCH_AUTHOR = 'MapList.SearchAuthor';
const ACTION_RESET = 'MapList.ResetMapList';
const MAX_MAPS_PER_PAGE = 13;
const MAX_PAGES_PER_CHUNK = 2;
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
const CACHE_CURRENT_PAGE = 'CurrentPage';
@ -129,7 +128,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
public function showMapList(Player $player, $mapList = null, $pageIndex = -1, $entryvalue = "") {
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
$buttonY = -$height / 2 + 9;
$buttonY = $height * -0.39;
if ($pageIndex < 0) {
$pageIndex = (int) $player->getCache($this, self::CACHE_CURRENT_PAGE);
@ -139,15 +138,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex);
$mapsBeginIndex = $this->getChunkMapsBeginIndex($chunkIndex);
$pageMaxCount = $this->getMapPerPage();
// Get Maps
if (!is_array($mapList)) {
$mapList = $this->maniaControl->getMapManager()->getMaps();
}
$mapList = array_slice($mapList, $mapsBeginIndex, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
$mapList = array_slice($mapList, $mapsBeginIndex, self::MAX_PAGES_PER_CHUNK * $pageMaxCount);
$totalMapsCount = $this->maniaControl->getMapManager()->getMapsCount();
$pagesCount = ceil($totalMapsCount / self::MAX_MAPS_PER_PAGE);
$pagesCount = ceil($totalMapsCount / $pageMaxCount);
// Create ManiaLink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -237,7 +237,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
foreach ($mapList as $map) {
/** @var Map $map */
if ($index % self::MAX_MAPS_PER_PAGE === 0) {
if ($index % $pageMaxCount === 0) {
$pageFrame = new Frame();
$frame->addChild($pageFrame);
$posY = $height / 2 - 16;
@ -447,6 +447,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, self::WIDGET_NAME);
}
/**
* Get number of maps per page
*
* @return int
*/
public function getMapPerPage() {
$pageheight = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
return floor(($pageheight - 16 - $pageheight * 0.11) / 4);
}
/**
* Get the Chunk Index with the given Page Index
*
@ -455,7 +465,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
*/
private function getChunkIndexFromPageNumber($pageIndex) {
$mapsCount = $this->maniaControl->getMapManager()->getMapsCount();
$pagesCount = ceil($mapsCount / self::MAX_MAPS_PER_PAGE);
$pagesCount = ceil($mapsCount / $this->getMapPerPage());
if ($pageIndex > $pagesCount - 1) {
$pageIndex = $pagesCount - 1;
}
@ -469,7 +479,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @return int
*/
private function getChunkMapsBeginIndex($chunkIndex) {
return $chunkIndex * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE;
return $chunkIndex * self::MAX_PAGES_PER_CHUNK * $this->getMapPerPage();
}
/**

View File

@ -757,7 +757,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
$currentIndex = $this->getMapIndex($this->getCurrentMap());
// No RestructureNeeded
if ($currentIndex < Maplist::MAX_MAPS_PER_PAGE - 1) {
if ($currentIndex < $this->mapList->getMapPerPage() - 1) {
return true;
}

View File

@ -62,7 +62,6 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
const CACHE_CURRENT_PAGE = 'PlayerList.CurrentPage';
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
const SHOWN_MAIN_WINDOW = -1;
const MAX_PLAYERS_PER_PAGE = 15;
const MAX_PAGES_PER_CHUNK = 2;
/*
@ -157,8 +156,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$totalPlayersCount = count($players);
$chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount);
$playerBeginIndex = $this->getChunkStatsBeginIndex($chunkIndex);
$pagesCount = ceil($totalPlayersCount / self::MAX_PLAYERS_PER_PAGE);
$pageMaxCount = $this->getPlayersPerPage();
$pagesCount = ceil($totalPlayersCount / $pageMaxCount);
//create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -207,11 +206,11 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$playerIndex = 1 + $playerBeginIndex;
//Slice Array to chunk length
$players = array_slice($players, $playerBeginIndex, self::MAX_PAGES_PER_CHUNK * self::MAX_PLAYERS_PER_PAGE, true);
$players = array_slice($players, $playerBeginIndex, self::MAX_PAGES_PER_CHUNK * $pageMaxCount , true);
$pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK;
foreach ($players as $listPlayer) {
if ($index % self::MAX_PLAYERS_PER_PAGE === 1) {
if ($index % $pageMaxCount === 1) {
$pageFrame = new Frame();
$frame->addChild($pageFrame);
@ -628,7 +627,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
* @return int
*/
private function getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount) {
$pagesCount = ceil($totalPlayersCount / self::MAX_PLAYERS_PER_PAGE);
$pagesCount = ceil($totalPlayersCount / $this->getPlayersPerPage());
if ($pageIndex > $pagesCount - 1) {
$pageIndex = $pagesCount - 1;
}
@ -642,7 +641,18 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
* @return int
*/
private function getChunkStatsBeginIndex($chunkIndex) {
return $chunkIndex * self::MAX_PAGES_PER_CHUNK * self::MAX_PLAYERS_PER_PAGE;
return $chunkIndex * self::MAX_PAGES_PER_CHUNK * $this->getPlayersPerPage();
}
/**
* Get number of players per page
*
* @return int
*/
public function getPlayersPerPage() {
$pageheight = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
return floor($pageheight * 0.82 / 4);
}
/**

View File

@ -79,6 +79,7 @@ class InstallMenu implements ConfiguratorMenu, ManialinkPageAnswerListener {
// Config
$pagerSize = 9.;
$entryHeight = 5.;
$pageMaxCount = floor(($height * 0.85) / $entryHeight);
$posY = 0.;
$pageFrame = null;
@ -135,7 +136,7 @@ class InstallMenu implements ConfiguratorMenu, ManialinkPageAnswerListener {
continue;
}
if ($index % 10 === 0) {
if ($index % $pageMaxCount === 0) {
// New page
$pageFrame = new Frame();
$frame->addChild($pageFrame);

View File

@ -107,7 +107,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
// Config
$pagerSize = 9.;
$entryHeight = 5.;
$pageMaxCount = 10;
$pageMaxCount = floor(($height * 0.85) / $entryHeight);
// Pagers
$pagerPrev = new Quad_Icons64x64_1();
@ -274,10 +274,10 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$settings = $this->maniaControl->getSettingManager()->getSettingsByClass($settingClass);
$isunlinkable = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getSettingManager(), SettingManager::SETTING_ALLOW_UNLINK_SERVER);
$pageSettingsMaxCount = 10;
$posY = 0;
$index = 0;
$settingHeight = 5.;
$pageSettingsMaxCount = floor(($height * 0.78) / $settingHeight);
$pageFrame = null;
//Headline Label
@ -409,10 +409,10 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
public function getManageSettingsLink(Frame $frame, $width, $height, Paging $paging, Player $player, $settingClass) {
$settings = $this->maniaControl->getSettingManager()->getSettingsByClass($settingClass);
$pageSettingsMaxCount = 10;
$posY = 0;
$index = 0;
$settingHeight = 5.;
$pageSettingsMaxCount = floor(($height * 0.78) / $settingHeight);
$pageFrame = null;
if (count($settings) > 64) {

View File

@ -291,12 +291,13 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
$posY = 0.;
$index = 0;
$pageFrame = null;
$pageMaxCount = floor(($height * 0.8) / $optionHeight);
foreach ($serverOptionsArray as $name => $value) {
// Continue on CurrentMaxPlayers...
if (strpos($name, 'Current') !== false) continue; // TODO: display 'Current...' somewhere
if ($index % 13 === 0) {
if ($index % $pageMaxCount === 0) {
$pageFrame = new Frame();
$frame->addChild($pageFrame);
$posY = $height * 0.41;