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

View File

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

View File

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

View File

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

View File

@ -62,7 +62,6 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
const CACHE_CURRENT_PAGE = 'PlayerList.CurrentPage'; const CACHE_CURRENT_PAGE = 'PlayerList.CurrentPage';
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin'; const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
const SHOWN_MAIN_WINDOW = -1; const SHOWN_MAIN_WINDOW = -1;
const MAX_PLAYERS_PER_PAGE = 15;
const MAX_PAGES_PER_CHUNK = 2; const MAX_PAGES_PER_CHUNK = 2;
/* /*
@ -157,8 +156,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$totalPlayersCount = count($players); $totalPlayersCount = count($players);
$chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount); $chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount);
$playerBeginIndex = $this->getChunkStatsBeginIndex($chunkIndex); $playerBeginIndex = $this->getChunkStatsBeginIndex($chunkIndex);
$pageMaxCount = $this->getPlayersPerPage();
$pagesCount = ceil($totalPlayersCount / self::MAX_PLAYERS_PER_PAGE); $pagesCount = ceil($totalPlayersCount / $pageMaxCount);
//create manialink //create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -207,11 +206,11 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$playerIndex = 1 + $playerBeginIndex; $playerIndex = 1 + $playerBeginIndex;
//Slice Array to chunk length //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; $pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK;
foreach ($players as $listPlayer) { foreach ($players as $listPlayer) {
if ($index % self::MAX_PLAYERS_PER_PAGE === 1) { if ($index % $pageMaxCount === 1) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->addChild($pageFrame); $frame->addChild($pageFrame);
@ -628,7 +627,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
* @return int * @return int
*/ */
private function getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount) { private function getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount) {
$pagesCount = ceil($totalPlayersCount / self::MAX_PLAYERS_PER_PAGE); $pagesCount = ceil($totalPlayersCount / $this->getPlayersPerPage());
if ($pageIndex > $pagesCount - 1) { if ($pageIndex > $pagesCount - 1) {
$pageIndex = $pagesCount - 1; $pageIndex = $pagesCount - 1;
} }
@ -642,7 +641,18 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
* @return int * @return int
*/ */
private function getChunkStatsBeginIndex($chunkIndex) { 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 // Config
$pagerSize = 9.; $pagerSize = 9.;
$entryHeight = 5.; $entryHeight = 5.;
$pageMaxCount = floor(($height * 0.85) / $entryHeight);
$posY = 0.; $posY = 0.;
$pageFrame = null; $pageFrame = null;
@ -135,7 +136,7 @@ class InstallMenu implements ConfiguratorMenu, ManialinkPageAnswerListener {
continue; continue;
} }
if ($index % 10 === 0) { if ($index % $pageMaxCount === 0) {
// New page // New page
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->addChild($pageFrame); $frame->addChild($pageFrame);

View File

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

View File

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