From ef730aa56c01af7050fbf28a266476cbcfb3103c Mon Sep 17 00:00:00 2001 From: Andrew <5436387+fidwell@users.noreply.github.com> Date: Tue, 14 Feb 2023 15:57:11 -0500 Subject: [PATCH] Fix #14635: Show more scenery tab groups in rows (#19373) --- contributors.md | 1 + distribution/changelog.txt | 1 + src/openrct2-ui/windows/Scenery.cpp | 74 +++++++++++++++++++++++++---- 3 files changed, 66 insertions(+), 10 deletions(-) diff --git a/contributors.md b/contributors.md index 0c981c0b15..d8b188be2f 100644 --- a/contributors.md +++ b/contributors.md @@ -102,6 +102,7 @@ The following people are not part of the development team, but have been contrib * Karst van Galen Last (AuraSpecs) - Ride paint (bounding boxes, extra track pieces), soundtrack, sound effects, misc. * (8street) - Misc. * Umar Ahmed (umar-ahmed) - MacOS file watcher +* Andrew Arnold (fidwell) - Added window support for more scenery groups. ## Bug fixes * (KirilAngelov) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index cdd7a7e13e..36265ef7ff 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -21,6 +21,7 @@ - Improved: [#19253] Queue junctions drawn properly when using regular paths as queue. - Improved: [#19067] New Ride window now allows filtering similarly to Object Selection. - Improved: [#19272] Scenery window now allows filtering similarly to Object Selection. +- Improved: [#14635] Scenery window now shows up to 255 scenery groups. - Change: [#19018] Renamed actions to fit the naming scheme. - Change: [#19091] [Plugin] Add game action information to callback arguments of custom actions. - Change: [#19233] Reduce lift speed minimum and maximum values for “Classic Wooden Coaster”. diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index e5dca308bd..6883e72723 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -44,7 +44,9 @@ constexpr int32_t WINDOW_SCENERY_MIN_HEIGHT = 195; constexpr int32_t SCENERY_BUTTON_WIDTH = 66; constexpr int32_t SCENERY_BUTTON_HEIGHT = 80; constexpr int32_t TabWidth = 31; -constexpr int32_t MaxTabs = 32; +constexpr int32_t TabHeight = 28; +constexpr int32_t MaxTabs = 257; // 255 selected tabs + misc + search +constexpr int32_t MaxTabsPerRow = 20; constexpr uint8_t SceneryContentScrollIndex = 0; @@ -151,6 +153,7 @@ private: std::vector _tabEntries; std::vector _widgets; int32_t _requiredWidth; + int32_t _actualMinHeight; ScenerySelection _selectedScenery; int16_t _hoverCounter; SceneryTabInfo _filteredSceneryTab; @@ -177,7 +180,7 @@ public: width = GetRequiredWidth(); min_width = width; max_width = width; - height = WINDOW_SCENERY_MIN_HEIGHT; + height = _actualMinHeight; min_height = height; max_height = height; if (_activeTabIndex > _tabSelections.size()) @@ -390,8 +393,8 @@ public: { if (InputGetState() != InputState::ScrollLeft) { - min_height = WINDOW_SCENERY_MIN_HEIGHT; - max_height = WINDOW_SCENERY_MIN_HEIGHT; + min_height = _actualMinHeight; + max_height = _actualMinHeight; } } else @@ -402,7 +405,7 @@ public: const auto numRows = static_cast(CountRows()); const auto maxContentHeight = numRows * SCENERY_BUTTON_HEIGHT; const auto maxWindowHeight = maxContentHeight + nonListHeight; - const auto windowHeight = std::clamp(maxWindowHeight, WINDOW_SCENERY_MIN_HEIGHT, 463); + const auto windowHeight = std::clamp(maxWindowHeight, _actualMinHeight, 463); min_height = windowHeight; max_height = windowHeight; @@ -415,8 +418,8 @@ public: _hoverCounter = 0; if (InputGetState() != InputState::ScrollLeft) { - min_height = WINDOW_SCENERY_MIN_HEIGHT; - max_height = WINDOW_SCENERY_MIN_HEIGHT; + min_height = _actualMinHeight; + max_height = _actualMinHeight; } } @@ -677,7 +680,7 @@ public: auto windowWidth = width; if (_tabEntries.size() > 0) { - const auto lastTabIndex = _tabEntries.size() - 1; + const auto lastTabIndex = GetMaxTabCountInARow() == MaxTabsPerRow ? MaxTabsPerRow - 1 : _tabEntries.size() - 1; const auto lastTabWidget = &widgets[WIDX_SCENERY_TAB_1 + lastTabIndex]; windowWidth = std::max(windowWidth, lastTabWidget->right + 3); } @@ -888,7 +891,7 @@ public: } // Set required width - _requiredWidth = static_cast(_tabEntries.size()) * TabWidth + 5; + _requiredWidth = std::min(static_cast(_tabEntries.size()), MaxTabsPerRow) * TabWidth + 5; SortTabs(); PrepareWidgets(); @@ -1146,6 +1149,18 @@ private: }); } + int32_t GetTabRowCount() + { + int32_t tabEntries = static_cast(_tabEntries.size()); + return std::max((tabEntries + MaxTabsPerRow - 1) / MaxTabsPerRow, 0); + } + + int32_t GetMaxTabCountInARow() + { + int32_t tabEntries = static_cast(_tabEntries.size()); + return std::min(tabEntries, MaxTabsPerRow); + } + void PrepareWidgets() { // Add the base widgets @@ -1160,7 +1175,11 @@ private: _widgets.pop_back(); // Add tabs - ScreenCoordsXY pos = { 3, 17 }; + _actualMinHeight = WINDOW_SCENERY_MIN_HEIGHT; + int32_t xInit = 3; + int32_t tabsInThisRow = 0; + + ScreenCoordsXY pos = { xInit, 17 }; for (const auto& tabInfo : _tabEntries) { auto widget = MakeTab(pos, STR_STRING_DEFINED_TOOLTIP); @@ -1172,10 +1191,45 @@ private: } _widgets.push_back(widget); + + tabsInThisRow++; + if (tabsInThisRow >= MaxTabsPerRow) + { + pos.x = xInit; + pos.y += TabHeight; + tabsInThisRow = 0; + _actualMinHeight += TabHeight; + } } _widgets.push_back(lastWidget); + // Shift base widgets based on number of tab rows + int32_t shiftAmount = (GetTabRowCount() - 1) * TabHeight; + if (shiftAmount > 0) + { + _widgets[WIDX_SCENERY_LIST].top += shiftAmount; + _widgets[WIDX_SCENERY_LIST].bottom += shiftAmount; + _widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].top += shiftAmount; + _widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].bottom += shiftAmount; + _widgets[WIDX_SCENERY_REPAINT_SCENERY_BUTTON].top += shiftAmount; + _widgets[WIDX_SCENERY_REPAINT_SCENERY_BUTTON].bottom += shiftAmount; + _widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].top += shiftAmount; + _widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].bottom += shiftAmount; + _widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].top += shiftAmount; + _widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].bottom += shiftAmount; + _widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].top += shiftAmount; + _widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].bottom += shiftAmount; + _widgets[WIDX_SCENERY_EYEDROPPER_BUTTON].top += shiftAmount; + _widgets[WIDX_SCENERY_EYEDROPPER_BUTTON].bottom += shiftAmount; + _widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].top += shiftAmount; + _widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].bottom += shiftAmount; + _widgets[WIDX_FILTER_TEXT_BOX].top += shiftAmount; + _widgets[WIDX_FILTER_TEXT_BOX].bottom += shiftAmount; + _widgets[WIDX_FILTER_CLEAR_BUTTON].top += shiftAmount; + _widgets[WIDX_FILTER_CLEAR_BUTTON].bottom += shiftAmount; + } + widgets = _widgets.data(); }