From 9f343abddaa7a103d368bfb1be2291729ce7494e Mon Sep 17 00:00:00 2001 From: Michael Steenbeek <1478678+Gymnasiast@users.noreply.github.com> Date: Mon, 24 Feb 2025 17:59:23 +0100 Subject: [PATCH] Reduce hardcoded positions for various windows --- src/openrct2-ui/windows/AssetPacks.cpp | 4 +- src/openrct2-ui/windows/Banner.cpp | 3 + src/openrct2-ui/windows/Cheats.cpp | 3 +- src/openrct2-ui/windows/CustomCurrency.cpp | 2 +- .../windows/EditorObjectSelection.cpp | 7 +- src/openrct2-ui/windows/Finances.cpp | 64 ++++++++++--------- src/openrct2-ui/windows/Guest.cpp | 6 +- src/openrct2-ui/windows/NewCampaign.cpp | 2 +- src/openrct2-ui/windows/NewRide.cpp | 11 ++-- .../windows/RefurbishRidePrompt.cpp | 5 ++ src/openrct2-ui/windows/Research.cpp | 5 +- src/openrct2-ui/windows/Ride.cpp | 54 +++++++++------- src/openrct2-ui/windows/RideConstruction.cpp | 17 +++-- src/openrct2-ui/windows/RideList.cpp | 3 +- src/openrct2-ui/windows/ScenarioSelect.cpp | 2 +- src/openrct2-ui/windows/Scenery.cpp | 9 +-- src/openrct2-ui/windows/ServerList.cpp | 24 +++---- src/openrct2-ui/windows/Staff.cpp | 6 +- src/openrct2-ui/windows/StaffList.cpp | 3 +- src/openrct2-ui/windows/TextInput.cpp | 9 +-- 20 files changed, 132 insertions(+), 107 deletions(-) diff --git a/src/openrct2-ui/windows/AssetPacks.cpp b/src/openrct2-ui/windows/AssetPacks.cpp index cbbc1245b9..c78c48e8e3 100644 --- a/src/openrct2-ui/windows/AssetPacks.cpp +++ b/src/openrct2-ui/windows/AssetPacks.cpp @@ -155,7 +155,7 @@ namespace OpenRCT2::Ui::Windows auto& list = widgets[WIDX_LIST]; list.left = 6; - list.top = 20 + 11 + 3; + list.top = widgets[WIDX_TITLE].height() + 8 + 11 + 3; list.right = width - 2 - 24 - 1; list.bottom = height - 6 - 11 - 3; @@ -168,7 +168,7 @@ namespace OpenRCT2::Ui::Windows widgets[WIDX_LOW_LABEL].left = list.left; widgets[WIDX_LOW_LABEL].right = list.right; - auto toolstripY = 20; + auto toolstripY = widgets[WIDX_TITLE].height() + 8; auto toolstripRight = width - 2; auto toolstripLeft = toolstripRight - 24; for (WidgetIndex i = WIDX_MOVE_UP; i <= WIDX_APPLY; i++) diff --git a/src/openrct2-ui/windows/Banner.cpp b/src/openrct2-ui/windows/Banner.cpp index 59c30f057d..e4979adba7 100644 --- a/src/openrct2-ui/windows/Banner.cpp +++ b/src/openrct2-ui/windows/Banner.cpp @@ -279,6 +279,9 @@ namespace OpenRCT2::Ui::Windows { return; } + + ResizeFrame(); + Widget& colourBtn = widgets[WIDX_MAIN_COLOUR]; colourBtn.type = WindowWidgetType::Empty; diff --git a/src/openrct2-ui/windows/Cheats.cpp b/src/openrct2-ui/windows/Cheats.cpp index 3e7fdd6dd3..a09ed02b92 100644 --- a/src/openrct2-ui/windows/Cheats.cpp +++ b/src/openrct2-ui/windows/Cheats.cpp @@ -755,8 +755,7 @@ static StringId window_cheats_page_titles[] = { Invalidate(); WindowInitScrollWidgets(*this); height = maxY; - widgets[WIDX_BACKGROUND].bottom = maxY - 1; - widgets[WIDX_PAGE_BACKGROUND].bottom = maxY - 1; + ResizeFrameWithPage(); Invalidate(); } diff --git a/src/openrct2-ui/windows/CustomCurrency.cpp b/src/openrct2-ui/windows/CustomCurrency.cpp index 3cfb7b9bef..2a5fdd2035 100644 --- a/src/openrct2-ui/windows/CustomCurrency.cpp +++ b/src/openrct2-ui/windows/CustomCurrency.cpp @@ -198,7 +198,7 @@ namespace OpenRCT2::Ui::Windows DrawWidgets(dpi); - auto screenCoords = windowPos + ScreenCoordsXY{ 10, 30 }; + auto screenCoords = windowPos + ScreenCoordsXY{ 10, 18 + widgets[WIDX_TITLE].height() }; DrawTextBasic(dpi, screenCoords, STR_RATE, {}, { colours[1] }); diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 4cd23758c2..c698032743 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -930,14 +930,13 @@ namespace OpenRCT2::Ui::Windows widgets[WIDX_FILTER_RIDE_TAB_FRAME].right = widgets[WIDX_LIST].right; widgets[WIDX_FILTER_TEXT_BOX].right = widgets[WIDX_LIST].right - 77; - widgets[WIDX_FILTER_TEXT_BOX].top = (hasSubTabs ? 79 : 48); - widgets[WIDX_FILTER_TEXT_BOX].bottom = (hasSubTabs ? 92 : 61); + auto contentStart = widgets[WIDX_TAB_CONTENT_PANEL].top; + widgets[WIDX_FILTER_TEXT_BOX].moveToY(contentStart + (hasSubTabs ? 36 : 5)); widgets[WIDX_FILTER_TEXT_BOX].string = _filter.data(); widgets[WIDX_FILTER_CLEAR_BUTTON].left = widgets[WIDX_LIST].right - 73; widgets[WIDX_FILTER_CLEAR_BUTTON].right = widgets[WIDX_LIST].right; - widgets[WIDX_FILTER_CLEAR_BUTTON].top = (hasSubTabs ? 79 : 48); - widgets[WIDX_FILTER_CLEAR_BUTTON].bottom = (hasSubTabs ? 92 : 61); + widgets[WIDX_FILTER_CLEAR_BUTTON].moveToY(contentStart + (hasSubTabs ? 36 : 5)); // Toggle sub-tab visibility const auto numSubTabs = static_cast(currentPage.subTabs.size()); diff --git a/src/openrct2-ui/windows/Finances.cpp b/src/openrct2-ui/windows/Finances.cpp index 84cfee4e65..80cca31b76 100644 --- a/src/openrct2-ui/windows/Finances.cpp +++ b/src/openrct2-ui/windows/Finances.cpp @@ -82,9 +82,10 @@ namespace OpenRCT2::Ui::Windows #pragma region Measurements - static constexpr int32_t WH_SUMMARY = 309; - static constexpr int32_t WH_RESEARCH = 207; - static constexpr int32_t WH_OTHER_TABS = 257; + static constexpr int32_t kCostPerWeekOffset = 321; + static constexpr int32_t kHeightSummary = 309; + static constexpr int32_t kHeightResearch = 207; + static constexpr int32_t kHeightOtherTabs = 257; static constexpr int32_t WW_RESEARCH = 320; static constexpr int32_t WW_OTHER_TABS = 530; static constexpr int32_t RSH_SUMMARY = 266; @@ -110,29 +111,29 @@ namespace OpenRCT2::Ui::Windows static constexpr Widget _windowFinancesSummaryWidgets[] = { - MAIN_FINANCES_WIDGETS(STR_FINANCIAL_SUMMARY, RSW_OTHER_TABS, RSH_SUMMARY, WW_OTHER_TABS, WH_SUMMARY), + MAIN_FINANCES_WIDGETS(STR_FINANCIAL_SUMMARY, RSW_OTHER_TABS, RSH_SUMMARY, WW_OTHER_TABS, kHeightSummary), MakeWidget ({130, 50}, {391, 211}, WindowWidgetType::Scroll, WindowColour::Secondary, SCROLL_HORIZONTAL ), MakeSpinnerWidgets({ 64, 279}, { 97, 14}, WindowWidgetType::Spinner, WindowColour::Secondary, STR_FINANCES_SUMMARY_LOAN_VALUE), // NB: 3 widgets. }; static constexpr Widget _windowFinancesCashWidgets[] = { - MAIN_FINANCES_WIDGETS(STR_FINANCIAL_GRAPH, RSW_OTHER_TABS, RSH_OTHER_TABS, WW_OTHER_TABS, WH_OTHER_TABS), + MAIN_FINANCES_WIDGETS(STR_FINANCIAL_GRAPH, RSW_OTHER_TABS, RSH_OTHER_TABS, WW_OTHER_TABS, kHeightOtherTabs), }; static constexpr Widget _windowFinancesParkValueWidgets[] = { - MAIN_FINANCES_WIDGETS(STR_PARK_VALUE_GRAPH, RSW_OTHER_TABS, RSH_OTHER_TABS, WW_OTHER_TABS, WH_OTHER_TABS), + MAIN_FINANCES_WIDGETS(STR_PARK_VALUE_GRAPH, RSW_OTHER_TABS, RSH_OTHER_TABS, WW_OTHER_TABS, kHeightOtherTabs), }; static constexpr Widget _windowFinancesProfitWidgets[] = { - MAIN_FINANCES_WIDGETS(STR_PROFIT_GRAPH, RSW_OTHER_TABS, RSH_OTHER_TABS, WW_OTHER_TABS, WH_OTHER_TABS), + MAIN_FINANCES_WIDGETS(STR_PROFIT_GRAPH, RSW_OTHER_TABS, RSH_OTHER_TABS, WW_OTHER_TABS, kHeightOtherTabs), }; static constexpr Widget _windowFinancesMarketingWidgets[] = { - MAIN_FINANCES_WIDGETS(STR_MARKETING, RSW_OTHER_TABS, RSH_OTHER_TABS, WW_OTHER_TABS, WH_OTHER_TABS), + MAIN_FINANCES_WIDGETS(STR_MARKETING, RSW_OTHER_TABS, RSH_OTHER_TABS, WW_OTHER_TABS, kHeightOtherTabs), MakeWidget({3, 47}, { WW_OTHER_TABS - 6, 45}, WindowWidgetType::Groupbox, WindowColour::Tertiary , STR_MARKETING_CAMPAIGNS_IN_OPERATION ), MakeWidget({3, 47}, { WW_OTHER_TABS - 6, 206}, WindowWidgetType::Groupbox, WindowColour::Tertiary , STR_MARKETING_CAMPAIGNS_AVAILABLE ), MakeWidget({8, 0}, {WW_OTHER_TABS - 16, 14}, WindowWidgetType::ImgBtn, WindowColour::Secondary, 0xFFFFFFFF, STR_START_THIS_MARKETING_CAMPAIGN), @@ -145,7 +146,7 @@ namespace OpenRCT2::Ui::Windows static constexpr Widget _windowFinancesResearchWidgets[] = { - MAIN_FINANCES_WIDGETS(STR_RESEARCH_FUNDING, RSW_RESEARCH, RSH_RESEARCH, WW_RESEARCH, WH_RESEARCH), + MAIN_FINANCES_WIDGETS(STR_RESEARCH_FUNDING, RSW_RESEARCH, RSH_RESEARCH, WW_RESEARCH, kHeightResearch), MakeWidget({ 3, 47}, { WW_RESEARCH - 6, 45}, WindowWidgetType::Groupbox, WindowColour::Tertiary, STR_RESEARCH_FUNDING_ ), MakeWidget({ 8, 59}, { 160, 14}, WindowWidgetType::DropdownMenu, WindowColour::Tertiary, 0xFFFFFFFF, STR_SELECT_LEVEL_OF_RESEARCH_AND_DEVELOPMENT), MakeWidget({156, 60}, { 11, 12}, WindowWidgetType::Button, WindowColour::Tertiary, STR_DROPDOWN_GLYPH, STR_SELECT_LEVEL_OF_RESEARCH_AND_DEVELOPMENT), @@ -493,13 +494,13 @@ namespace OpenRCT2::Ui::Windows if (p == WINDOW_FINANCES_PAGE_RESEARCH) { width = WW_RESEARCH; - height = WH_RESEARCH; + height = kHeightResearch; flags &= ~WF_RESIZABLE; } else if (p == WINDOW_FINANCES_PAGE_SUMMARY) { width = WW_OTHER_TABS; - height = WH_SUMMARY; + height = kHeightSummary; flags &= ~WF_RESIZABLE; } else if ( @@ -508,13 +509,13 @@ namespace OpenRCT2::Ui::Windows { flags |= WF_RESIZABLE; WindowSetResize( - *this, WW_OTHER_TABS, WH_OTHER_TABS, std::numeric_limits::max(), + *this, WW_OTHER_TABS, kHeightOtherTabs, std::numeric_limits::max(), std::numeric_limits::max()); } else { width = WW_OTHER_TABS; - height = WH_OTHER_TABS; + height = kHeightOtherTabs; flags &= ~WF_RESIZABLE; } OnResize(); @@ -584,7 +585,8 @@ namespace OpenRCT2::Ui::Windows void OnDrawSummary(DrawPixelInfo& dpi) { - auto screenCoords = windowPos + ScreenCoordsXY{ 8, 51 }; + auto titleBarBottom = widgets[WIDX_TITLE].bottom; + auto screenCoords = windowPos + ScreenCoordsXY{ 8, titleBarBottom + 37 }; auto& gameState = GetGameState(); // Expenditure / Income heading @@ -609,23 +611,26 @@ namespace OpenRCT2::Ui::Windows // Horizontal rule below expenditure / income table GfxFillRectInset( - dpi, { windowPos + ScreenCoordsXY{ 8, 272 }, windowPos + ScreenCoordsXY{ 8 + 513, 272 + 1 } }, colours[1], - INSET_RECT_FLAG_BORDER_INSET); + dpi, + { windowPos + ScreenCoordsXY{ 8, titleBarBottom + 258 }, + windowPos + ScreenCoordsXY{ 8 + 513, titleBarBottom + 258 + 1 } }, + colours[1], INSET_RECT_FLAG_BORDER_INSET); // Loan and interest rate - DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ 8, 279 }, STR_FINANCES_SUMMARY_LOAN); + DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ 8, titleBarBottom + 265 }, STR_FINANCES_SUMMARY_LOAN); if (!(gameState.Park.Flags & PARK_FLAGS_RCT1_INTEREST)) { auto ft = Formatter(); ft.Add(gameState.BankLoanInterestRate); - DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ 167, 279 }, STR_FINANCES_SUMMARY_AT_X_PER_YEAR, ft); + DrawTextBasic( + dpi, windowPos + ScreenCoordsXY{ 167, titleBarBottom + 265 }, STR_FINANCES_SUMMARY_AT_X_PER_YEAR, ft); } // Current cash auto ft = Formatter(); ft.Add(gameState.Cash); StringId stringId = gameState.Cash >= 0 ? STR_CASH_LABEL : STR_CASH_NEGATIVE_LABEL; - DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ 8, 294 }, stringId, ft); + DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ 8, titleBarBottom + 280 }, stringId, ft); // Objective related financial information if (gameState.ScenarioObjective.Type == OBJECTIVE_MONTHLY_FOOD_INCOME) @@ -634,18 +639,18 @@ namespace OpenRCT2::Ui::Windows ft = Formatter(); ft.Add(lastMonthProfit); DrawTextBasic( - dpi, windowPos + ScreenCoordsXY{ 280, 279 }, STR_LAST_MONTH_PROFIT_FROM_FOOD_DRINK_MERCHANDISE_SALES_LABEL, - ft); + dpi, windowPos + ScreenCoordsXY{ 280, titleBarBottom + 265 }, + STR_LAST_MONTH_PROFIT_FROM_FOOD_DRINK_MERCHANDISE_SALES_LABEL, ft); } else { // Park value and company value ft = Formatter(); ft.Add(gameState.Park.Value); - DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ 280, 279 }, STR_PARK_VALUE_LABEL, ft); + DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ 280, titleBarBottom + 265 }, STR_PARK_VALUE_LABEL, ft); ft = Formatter(); ft.Add(gameState.CompanyValue); - DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ 280, 294 }, STR_COMPANY_VALUE_LABEL, ft); + DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ 280, titleBarBottom + 280 }, STR_COMPANY_VALUE_LABEL, ft); } } @@ -698,7 +703,7 @@ namespace OpenRCT2::Ui::Windows void OnDrawMarketing(DrawPixelInfo& dpi) { - auto screenCoords = windowPos + ScreenCoordsXY{ 8, 62 }; + auto screenCoords = windowPos + ScreenCoordsXY{ 8, widgets[WIDX_TAB_1].top + 45 }; int32_t noCampaignsActive = 1; for (int32_t i = 0; i < ADVERTISING_CAMPAIGN_COUNT; i++) { @@ -753,9 +758,7 @@ namespace OpenRCT2::Ui::Windows if (noCampaignsActive) { DrawTextBasic(dpi, screenCoords + ScreenCoordsXY{ 4, 0 }, STR_MARKETING_CAMPAIGNS_NONE); - screenCoords.y += kListRowHeight; } - screenCoords.y += 34; // Draw campaign button text for (int32_t i = 0; i < ADVERTISING_CAMPAIGN_COUNT; i++) @@ -764,12 +767,11 @@ namespace OpenRCT2::Ui::Windows if (campaignButton->type != WindowWidgetType::Empty) { // Draw button text + screenCoords = windowPos + ScreenCoordsXY{ campaignButton->left, campaignButton->textTop() }; DrawTextBasic(dpi, screenCoords + ScreenCoordsXY{ 4, 0 }, kMarketingCampaignNames[i][0]); auto ft = Formatter(); ft.Add(AdvertisingCampaignPricePerWeek[i]); - DrawTextBasic(dpi, screenCoords + ScreenCoordsXY{ WH_SUMMARY, 0 }, STR_MARKETING_PER_WEEK, ft); - - screenCoords.y += kButtonFaceHeight + 2; + DrawTextBasic(dpi, screenCoords + ScreenCoordsXY{ kCostPerWeekOffset, 0 }, STR_MARKETING_PER_WEEK, ft); } } } @@ -880,7 +882,7 @@ namespace OpenRCT2::Ui::Windows static FinancesWindow* FinancesWindowOpen(uint8_t page) { auto* windowMgr = Ui::GetWindowManager(); - auto* window = windowMgr->FocusOrCreate(WindowClass::Finances, WW_OTHER_TABS, WH_SUMMARY, WF_10); + auto* window = windowMgr->FocusOrCreate(WindowClass::Finances, WW_OTHER_TABS, kHeightSummary, WF_10); if (window != nullptr && page != WINDOW_FINANCES_PAGE_SUMMARY) window->SetPage(page); @@ -891,7 +893,7 @@ namespace OpenRCT2::Ui::Windows WindowBase* FinancesOpen() { auto* windowMgr = Ui::GetWindowManager(); - return windowMgr->FocusOrCreate(WindowClass::Finances, WW_OTHER_TABS, WH_SUMMARY, WF_10); + return windowMgr->FocusOrCreate(WindowClass::Finances, WW_OTHER_TABS, kHeightSummary, WF_10); } WindowBase* FinancesResearchOpen() diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index e15894d990..7241b9a540 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -601,8 +601,10 @@ namespace OpenRCT2::Ui::Windows if (viewport != nullptr) { - auto reqViewportWidth = width - 30; - auto reqViewportHeight = height - 72; + auto widget = widgets[WIDX_VIEWPORT]; + auto reqViewportWidth = widget.width() - 1; + auto reqViewportHeight = widget.height() - 1; + viewport->pos = windowPos + ScreenCoordsXY{ widget.left + 1, widget.top + 1 }; if (viewport->width != reqViewportWidth || viewport->height != reqViewportHeight) { viewport->width = reqViewportWidth; diff --git a/src/openrct2-ui/windows/NewCampaign.cpp b/src/openrct2-ui/windows/NewCampaign.cpp index 2b8a1d3d6f..6b7d51b243 100644 --- a/src/openrct2-ui/windows/NewCampaign.cpp +++ b/src/openrct2-ui/windows/NewCampaign.cpp @@ -376,7 +376,7 @@ namespace OpenRCT2::Ui::Windows dpi, windowPos + ScreenCoordsXY{ spinnerWidget->left + 1, spinnerWidget->top }, Campaign.no_weeks == 1 ? STR_MARKETING_1_WEEK : STR_X_WEEKS, ft, { colours[0] }); - screenCoords = windowPos + ScreenCoordsXY{ 14, 60 }; + screenCoords = windowPos + ScreenCoordsXY{ 14, spinnerWidget->bottom + 6 }; // Price per week ft = Formatter(); diff --git a/src/openrct2-ui/windows/NewRide.cpp b/src/openrct2-ui/windows/NewRide.cpp index 840cbd3677..05bf067ac0 100644 --- a/src/openrct2-ui/windows/NewRide.cpp +++ b/src/openrct2-ui/windows/NewRide.cpp @@ -43,7 +43,8 @@ using namespace OpenRCT2::TrackMetaData; namespace OpenRCT2::Ui::Windows { static constexpr StringId WindowTitle = kStringIdNone; - static constexpr int32_t WindowHeight = 382; + static constexpr int32_t kWindowHeight = 382; + static constexpr int32_t kWindowHeightResearch = 194; static constexpr int32_t WindowWidth = 601; static constexpr int32_t RideListItemsMax = 384; static constexpr int32_t RideTabCount = 6; @@ -209,7 +210,7 @@ namespace OpenRCT2::Ui::Windows // clang-format off static constexpr Widget window_new_ride_widgets[] = { - WINDOW_SHIM(WindowTitle, WindowWidth, WindowHeight), + WINDOW_SHIM(WindowTitle, WindowWidth, kWindowHeight), MakeWidget({ 0, 43}, {601, 339}, WindowWidgetType::Resize, WindowColour::Secondary ), MakeTab ({ 3, 17}, STR_TRANSPORT_RIDES_TIP ), MakeTab ({ 34, 17}, STR_GENTLE_RIDES_TIP ), @@ -837,7 +838,7 @@ namespace OpenRCT2::Ui::Windows widgets[WIDX_RESEARCH_FUNDING_BUTTON].type = WindowWidgetType::Empty; newWidth = WindowWidth; - newHeight = WindowHeight; + newHeight = kWindowHeight; } else { @@ -851,7 +852,7 @@ namespace OpenRCT2::Ui::Windows widgets[WIDX_RESEARCH_FUNDING_BUTTON].type = WindowWidgetType::FlatBtn; newWidth = 300; - newHeight = 196; + newHeight = kWindowHeightResearch; } // Handle new window size @@ -1083,7 +1084,7 @@ namespace OpenRCT2::Ui::Windows windowMgr->CloseByClass(WindowClass::TrackDesignPlace); window = windowMgr->Create( - WindowClass::ConstructRide, WindowWidth, WindowHeight, WF_10 | WF_AUTO_POSITION); + WindowClass::ConstructRide, WindowWidth, kWindowHeight, WF_10 | WF_AUTO_POSITION); return window; } diff --git a/src/openrct2-ui/windows/RefurbishRidePrompt.cpp b/src/openrct2-ui/windows/RefurbishRidePrompt.cpp index fd32058dfe..ce83526d7b 100644 --- a/src/openrct2-ui/windows/RefurbishRidePrompt.cpp +++ b/src/openrct2-ui/windows/RefurbishRidePrompt.cpp @@ -92,6 +92,11 @@ namespace OpenRCT2::Ui::Windows } } + void OnPrepareDraw() override + { + ResizeFrame(); + } + void OnResize() override { ResizeFrame(); diff --git a/src/openrct2-ui/windows/Research.cpp b/src/openrct2-ui/windows/Research.cpp index 1e4d6f2570..d2a7476591 100644 --- a/src/openrct2-ui/windows/Research.cpp +++ b/src/openrct2-ui/windows/Research.cpp @@ -52,7 +52,7 @@ namespace OpenRCT2::Ui::Windows WIDX_LAST_DEVELOPMENT_GROUP, WIDX_LAST_DEVELOPMENT_BUTTON, - WIDX_FUNDING_GROUP = 6, + WIDX_RESEARCH_FUNDING_GROUP = 6, WIDX_RESEARCH_FUNDING, WIDX_RESEARCH_FUNDING_DROPDOWN_BUTTON, WIDX_PRIORITIES_GROUP, @@ -591,7 +591,8 @@ namespace OpenRCT2::Ui::Windows int32_t currentResearchLevel = gameState.ResearchFundingLevel; auto ft = Formatter(); ft.Add(research_cost_table[currentResearchLevel]); - DrawTextBasic(dpi, w->windowPos + ScreenCoordsXY{ 10, 77 }, STR_RESEARCH_COST_PER_MONTH, ft); + DrawTextBasic( + dpi, w->windowPos + ScreenCoordsXY{ 10, w->widgets[WIDX_TAB_1].top + 60 }, STR_RESEARCH_COST_PER_MONTH, ft); } #pragma endregion diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 1bf97c2b07..fb26010eb6 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -79,9 +79,11 @@ using namespace OpenRCT2::TrackMetaData; namespace OpenRCT2::Ui::Windows { + static constexpr int32_t kMinimumWindowWidth = 316; + static constexpr StringId WINDOW_TITLE = STR_RIDE_WINDOW_TITLE; static constexpr int32_t WH = 207; - static constexpr int32_t WW = 316; + static constexpr int32_t WW = kMinimumWindowWidth; enum { @@ -242,7 +244,7 @@ namespace OpenRCT2::Ui::Windows #define MAIN_RIDE_WIDGETS \ WINDOW_SHIM(WINDOW_TITLE, WW, WH), \ - MakeWidget({ 0, 43 }, { 316, 137 }, WindowWidgetType::Resize, WindowColour::Secondary), \ + MakeWidget({ 0, 43}, {kMinimumWindowWidth, 137}, WindowWidgetType::Resize, WindowColour::Secondary), \ MakeTab({ 3, 17 }, STR_VIEW_OF_RIDE_ATTRACTION_TIP), \ MakeTab({ 34, 17 }, STR_VEHICLE_DETAILS_AND_OPTIONS_TIP), \ MakeTab({ 65, 17 }, STR_OPERATING_OPTIONS_TIP), \ @@ -752,7 +754,7 @@ namespace OpenRCT2::Ui::Windows list_information_type = 0; picked_peep_frame = 0; DisableTabs(); - min_width = 316; + min_width = kMinimumWindowWidth; min_height = 180; max_width = 500; max_height = 450; @@ -1708,7 +1710,7 @@ namespace OpenRCT2::Ui::Windows } flags |= WF_RESIZABLE; - WindowSetResize(*this, 316, minHeight, 500, 450); + WindowSetResize(*this, kMinimumWindowWidth, minHeight, 500, 450); // Unlike with other windows, the focus needs to be recentred so it’s best to just reset it. focus = std::nullopt; InitViewport(); @@ -2410,7 +2412,7 @@ namespace OpenRCT2::Ui::Windows : WindowWidgetType::Empty; widgets[WIDX_OPEN_LIGHT].type = WindowWidgetType::ImgBtn; - widgetHeight = 62; + widgetHeight = widgets[WIDX_PAGE_BACKGROUND].top + 19; if (widgets[WIDX_SIMULATE_LIGHT].type != WindowWidgetType::Empty) { widgets[WIDX_SIMULATE_LIGHT].top = widgetHeight; @@ -2656,7 +2658,7 @@ namespace OpenRCT2::Ui::Windows void VehicleResize() { auto bottom = widgets[WIDX_VEHICLE_TRAINS].bottom + 6; - WindowSetResize(*this, 316, bottom, 316, bottom); + WindowSetResize(*this, kMinimumWindowWidth, bottom, kMinimumWindowWidth, bottom); } void VehicleOnMouseDown(WidgetIndex widgetIndex) @@ -2879,8 +2881,7 @@ namespace OpenRCT2::Ui::Windows if (rideEntry == nullptr) return; - auto screenCoords = windowPos + ScreenCoordsXY{ 8, 64 }; - + auto screenCoords = windowPos + ScreenCoordsXY{ 8, widgets[WIDX_VEHICLE_TYPE_DROPDOWN].bottom + 5 }; // Description auto ft = Formatter(); ft.Add(rideEntry->naming.Description); @@ -3201,7 +3202,8 @@ namespace OpenRCT2::Ui::Windows void OperatingResize() { - WindowSetResize(*this, 316, 186, 316, 186); + auto bottom = widgets[WIDX_SYNCHRONISE_WITH_ADJACENT_STATIONS_CHECKBOX].bottom + 6; + WindowSetResize(*this, kMinimumWindowWidth, bottom, kMinimumWindowWidth, bottom); } void OperatingOnMouseDown(WidgetIndex widgetIndex) @@ -3695,10 +3697,11 @@ namespace OpenRCT2::Ui::Windows return; // Horizontal rule between mode settings and depart settings + auto ruleStart = widgets[WIDX_LOAD_DROPDOWN].top - 8; GfxFillRectInset( dpi, - { windowPos + ScreenCoordsXY{ widgets[WIDX_PAGE_BACKGROUND].left + 4, 103 }, - windowPos + ScreenCoordsXY{ widgets[WIDX_PAGE_BACKGROUND].right - 5, 104 } }, + { windowPos + ScreenCoordsXY{ widgets[WIDX_PAGE_BACKGROUND].left + 4, ruleStart }, + windowPos + ScreenCoordsXY{ widgets[WIDX_PAGE_BACKGROUND].right - 5, ruleStart + 1 } }, colours[1], INSET_RECT_FLAG_BORDER_INSET); // Number of block sections @@ -3706,9 +3709,10 @@ namespace OpenRCT2::Ui::Windows { auto ft = Formatter(); ft.Add(ride->num_block_brakes + ride->num_stations); + auto underWidget = ride->mode == RideMode::PoweredLaunchBlockSectioned ? WIDX_MODE_TWEAK : WIDX_MODE; DrawTextBasic( - dpi, windowPos + ScreenCoordsXY{ 21, ride->mode == RideMode::PoweredLaunchBlockSectioned ? 89 : 61 }, - STR_BLOCK_SECTIONS, ft, { COLOUR_BLACK }); + dpi, windowPos + ScreenCoordsXY{ 21, widgets[underWidget].bottom + 3 }, STR_BLOCK_SECTIONS, ft, + { COLOUR_BLACK }); } } @@ -3769,7 +3773,8 @@ namespace OpenRCT2::Ui::Windows void MaintenanceResize() { - WindowSetResize(*this, 316, 135, 316, 135); + auto bottom = widgets[WIDX_LOCATE_MECHANIC].bottom + 6; + WindowSetResize(*this, kMinimumWindowWidth, bottom, kMinimumWindowWidth, bottom); } void MaintenanceOnMouseDown(WidgetIndex widgetIndex) @@ -4293,7 +4298,8 @@ namespace OpenRCT2::Ui::Windows void ColourResize() { - WindowSetResize(*this, 316, 207, 316, 207); + auto bottom = widgets[WIDX_VEHICLE_PREVIEW].bottom + 6; + WindowSetResize(*this, kMinimumWindowWidth, bottom, kMinimumWindowWidth, bottom); } void ColourOnMouseDown(WidgetIndex widgetIndex) @@ -5013,9 +5019,10 @@ namespace OpenRCT2::Ui::Windows // Expand the window when music is playing auto isMusicActivated = (ride->lifecycle_flags & RIDE_LIFECYCLE_MUSIC) != 0; - auto minHeight = isMusicActivated ? 214 : 81; - auto maxHeight = isMusicActivated ? 450 : 81; - WindowSetResize(*this, 316, minHeight, 500, maxHeight); + auto standardHeight = widgets[WIDX_MUSIC_DROPDOWN].bottom + 6; + auto minHeight = isMusicActivated ? standardHeight + 133 : standardHeight; + auto maxHeight = isMusicActivated ? standardHeight + 369 : standardHeight; + WindowSetResize(*this, kMinimumWindowWidth, minHeight, 500, maxHeight); } static std::string GetMusicString(ObjectEntryIndex musicObjectIndex) @@ -5456,7 +5463,7 @@ namespace OpenRCT2::Ui::Windows void MeasurementsResize() { - WindowSetResize(*this, 316, 234, 316, 234); + WindowSetResize(*this, kMinimumWindowWidth, 234, kMinimumWindowWidth, 234); } void MeasurementsOnMouseDown(WidgetIndex widgetIndex) @@ -5892,7 +5899,7 @@ namespace OpenRCT2::Ui::Windows void GraphsResize() { - WindowSetResize(*this, 316, 182, std::numeric_limits::max(), 450); + WindowSetResize(*this, kMinimumWindowWidth, 182, std::numeric_limits::max(), 450); } void GraphsOnMouseDown(WidgetIndex widgetIndex) @@ -6444,7 +6451,8 @@ namespace OpenRCT2::Ui::Windows void IncomeResize() { - WindowSetResize(*this, 316, 194, 316, 194); + auto newHeight = 194; + WindowSetResize(*this, kMinimumWindowWidth, newHeight, kMinimumWindowWidth, newHeight); } void IncomeOnMouseDown(WidgetIndex widgetIndex) @@ -6760,7 +6768,7 @@ namespace OpenRCT2::Ui::Windows void CustomerResize() { flags |= WF_RESIZABLE; - WindowSetResize(*this, 316, 163, 316, 163); + WindowSetResize(*this, kMinimumWindowWidth, 163, kMinimumWindowWidth, 163); } void CustomerUpdate() @@ -6940,7 +6948,7 @@ namespace OpenRCT2::Ui::Windows static RideWindow* WindowRideOpen(const Ride& ride) { auto* windowMgr = GetWindowManager(); - return windowMgr->Create(WindowClass::Ride, 316, 207, WF_10 | WF_RESIZABLE, ride); + return windowMgr->Create(WindowClass::Ride, kMinimumWindowWidth, 207, WF_10 | WF_RESIZABLE, ride); } /** diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 5397dc4c25..772e70ac37 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -1887,25 +1887,27 @@ namespace OpenRCT2::Ui::Windows } } + auto top = 118 + widgets[WIDX_TITLE].bottom; + auto bottom = top + 23; widgets[WIDX_BANKING_GROUPBOX].image = ImageId(STR_RIDE_CONSTRUCTION_ROLL_BANKING); widgets[WIDX_BANK_LEFT].image = ImageId(SPR_RIDE_CONSTRUCTION_LEFT_BANK); widgets[WIDX_BANK_LEFT].tooltip = STR_RIDE_CONSTRUCTION_ROLL_FOR_LEFT_CURVE_TIP; widgets[WIDX_BANK_LEFT].left = 69; widgets[WIDX_BANK_LEFT].right = 92; - widgets[WIDX_BANK_LEFT].top = 132; - widgets[WIDX_BANK_LEFT].bottom = 155; + widgets[WIDX_BANK_LEFT].top = top; + widgets[WIDX_BANK_LEFT].bottom = bottom; widgets[WIDX_BANK_STRAIGHT].image = ImageId(SPR_RIDE_CONSTRUCTION_NO_BANK); widgets[WIDX_BANK_STRAIGHT].tooltip = STR_RIDE_CONSTRUCTION_NO_ROLL_TIP; widgets[WIDX_BANK_STRAIGHT].left = 93; widgets[WIDX_BANK_STRAIGHT].right = 116; - widgets[WIDX_BANK_STRAIGHT].top = 132; - widgets[WIDX_BANK_STRAIGHT].bottom = 155; + widgets[WIDX_BANK_STRAIGHT].top = top; + widgets[WIDX_BANK_STRAIGHT].bottom = bottom; widgets[WIDX_BANK_RIGHT].image = ImageId(SPR_RIDE_CONSTRUCTION_RIGHT_BANK); widgets[WIDX_BANK_RIGHT].tooltip = STR_RIDE_CONSTRUCTION_ROLL_FOR_RIGHT_CURVE_TIP; widgets[WIDX_BANK_RIGHT].left = 117; widgets[WIDX_BANK_RIGHT].right = 140; - widgets[WIDX_BANK_RIGHT].top = 132; - widgets[WIDX_BANK_RIGHT].bottom = 155; + widgets[WIDX_BANK_RIGHT].top = top; + widgets[WIDX_BANK_RIGHT].bottom = bottom; widgets[WIDX_BANK_LEFT].type = WindowWidgetType::Empty; widgets[WIDX_BANK_STRAIGHT].type = WindowWidgetType::Empty; widgets[WIDX_BANK_RIGHT].type = WindowWidgetType::Empty; @@ -1960,7 +1962,8 @@ namespace OpenRCT2::Ui::Windows widgets[WIDX_SPEED_SETTING_SPINNER_DOWN].type = WindowWidgetType::Button; widgets[WIDX_SPEED_SETTING_SPINNER_DOWN].text = STR_NUMERIC_DOWN; - ResizeSpinner(WIDX_SPEED_SETTING_SPINNER, { 12, 138 }, { 85, kSpinnerHeight }); + auto spinnerStart = 124 + widgets[WIDX_TITLE].bottom; + ResizeSpinner(WIDX_SPEED_SETTING_SPINNER, { 12, spinnerStart }, { 85, kSpinnerHeight }); hold_down_widgets |= (1uLL << WIDX_SPEED_SETTING_SPINNER_UP) | (1uLL << WIDX_SPEED_SETTING_SPINNER_DOWN); } diff --git a/src/openrct2-ui/windows/RideList.cpp b/src/openrct2-ui/windows/RideList.cpp index 6ba40441cc..6f6def4eb5 100644 --- a/src/openrct2-ui/windows/RideList.cpp +++ b/src/openrct2-ui/windows/RideList.cpp @@ -211,7 +211,8 @@ namespace OpenRCT2::Ui::Windows widgets[WIDX_SORT].left = width - 60; widgets[WIDX_SORT].right = width - 60 + 54; - ResizeDropdown(WIDX_CURRENT_INFORMATION_TYPE, { 150, 46 }, { width - 216, kDropdownHeight }); + auto dropdownStart = widgets[WIDX_CURRENT_INFORMATION_TYPE].top; + ResizeDropdown(WIDX_CURRENT_INFORMATION_TYPE, { 150, dropdownStart }, { width - 216, kDropdownHeight }); // Refreshing the list can be a very intensive operation // owing to its use of ride_has_any_track_elements(). diff --git a/src/openrct2-ui/windows/ScenarioSelect.cpp b/src/openrct2-ui/windows/ScenarioSelect.cpp index 501b89f722..acce5da39f 100644 --- a/src/openrct2-ui/windows/ScenarioSelect.cpp +++ b/src/openrct2-ui/windows/ScenarioSelect.cpp @@ -723,7 +723,7 @@ namespace OpenRCT2::Ui::Windows } } - int32_t y = kTabsStart; + int32_t y = widgets[WIDX_TAB1].top; for (int32_t i = 0; i < kNumTabs; i++) { auto& widget = widgets[i + WIDX_TAB1]; diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 03b43f8e3d..de45daef51 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -782,13 +782,14 @@ namespace OpenRCT2::Ui::Windows const auto lastTabWidget = &widgets[WIDX_SCENERY_TAB_1 + lastTabIndex]; windowWidth = std::max(windowWidth, lastTabWidget->right + 3); + auto tabTop = widgets[WIDX_SCENERY_TITLE].bottom + 3; if (GetSceneryTabInfoForMisc() != nullptr) { auto miscTabWidget = &widgets[WIDX_SCENERY_TAB_1 + _tabEntries.size() - 2]; miscTabWidget->left = windowWidth - 2 * TabWidth - 6; miscTabWidget->right = windowWidth - TabWidth - 7; - miscTabWidget->top = InitTabPosY; - miscTabWidget->bottom = InitTabPosY + TabHeight; + miscTabWidget->top = tabTop; + miscTabWidget->bottom = tabTop + TabHeight; } if (_tabEntries.back().IsAll()) @@ -796,8 +797,8 @@ namespace OpenRCT2::Ui::Windows auto allTabWidget = &widgets[WIDX_SCENERY_TAB_1 + _tabEntries.size() - 1]; allTabWidget->left = windowWidth - TabWidth - 6; allTabWidget->right = windowWidth - 7; - allTabWidget->top = InitTabPosY; - allTabWidget->bottom = InitTabPosY + TabHeight; + allTabWidget->top = tabTop; + allTabWidget->bottom = tabTop + TabHeight; } } diff --git a/src/openrct2-ui/windows/ServerList.cpp b/src/openrct2-ui/windows/ServerList.cpp index 8fbe786e40..9a69b1c490 100644 --- a/src/openrct2-ui/windows/ServerList.cpp +++ b/src/openrct2-ui/windows/ServerList.cpp @@ -30,11 +30,11 @@ namespace OpenRCT2::Ui::Windows { - #define WWIDTH_MIN 500 - #define WHEIGHT_MIN 300 - #define WWIDTH_MAX 1200 - #define WHEIGHT_MAX 800 - #define ITEM_HEIGHT (3 + 9 + 3) + static constexpr int32_t kWindowWidthMin = 500; + static constexpr int32_t kWindowHeightMin = 288; + static constexpr int32_t kWindowWidthMax = 1200; + static constexpr int32_t kWindowHeightMax = 788; + static constexpr int32_t kItemHeight = (3 + 9 + 3); constexpr size_t MaxPlayerNameLength = 32; @@ -109,7 +109,7 @@ namespace OpenRCT2::Ui::Windows page = 0; list_information_type = 0; - WindowSetResize(*this, WWIDTH_MIN, WHEIGHT_MIN, WWIDTH_MAX, WHEIGHT_MAX); + WindowSetResize(*this, kWindowWidthMin, kWindowHeightMin, kWindowWidthMax, kWindowHeightMax); no_list_items = static_cast(_serverList.GetCount()); @@ -166,7 +166,7 @@ namespace OpenRCT2::Ui::Windows void OnResize() override { - WindowSetResize(*this, WWIDTH_MIN, WHEIGHT_MIN, WWIDTH_MAX, WHEIGHT_MAX); + WindowSetResize(*this, kWindowWidthMin, kWindowHeightMin, kWindowWidthMax, kWindowHeightMax); } void OnDropdown(WidgetIndex widgetIndex, int32_t selectedIndex) override @@ -215,7 +215,7 @@ namespace OpenRCT2::Ui::Windows ScreenSize OnScrollGetSize(int32_t scrollIndex) override { - return { 0, no_list_items * ITEM_HEIGHT }; + return { 0, no_list_items * kItemHeight }; } void OnScrollMouseDown(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override @@ -248,7 +248,7 @@ namespace OpenRCT2::Ui::Windows { auto& listWidget = widgets[WIDX_LIST]; - int32_t itemIndex = screenCoords.y / ITEM_HEIGHT; + int32_t itemIndex = screenCoords.y / kItemHeight; bool showNetworkVersionTooltip = false; if (itemIndex < 0 || itemIndex >= no_list_items) { @@ -356,7 +356,7 @@ namespace OpenRCT2::Ui::Windows if (highlighted) { GfxFilterRect( - dpi, { 0, screenCoords.y, listWidgetWidth, screenCoords.y + ITEM_HEIGHT }, + dpi, { 0, screenCoords.y, listWidgetWidth, screenCoords.y + kItemHeight }, FilterPaletteID::PaletteDarken1); _version = serverDetails.Version; } @@ -428,7 +428,7 @@ namespace OpenRCT2::Ui::Windows screenCoords.x = right - numPlayersStringWidth; DrawText(dpi, screenCoords + ScreenCoordsXY{ 0, 3 }, { colours[1] }, players); - screenCoords.y += ITEM_HEIGHT; + screenCoords.y += kItemHeight; } } @@ -553,7 +553,7 @@ namespace OpenRCT2::Ui::Windows return window; window = windowMgr->Create( - WindowClass::ServerList, WWIDTH_MIN, WHEIGHT_MIN, WF_10 | WF_RESIZABLE | WF_CENTRE_SCREEN); + WindowClass::ServerList, kWindowWidthMin, kWindowHeightMin, WF_10 | WF_RESIZABLE | WF_CENTRE_SCREEN); return window; } diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index 5e4220b3b4..8928c9f27c 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -633,8 +633,10 @@ namespace OpenRCT2::Ui::Windows if (viewport != nullptr) { - int32_t newWidth = width - 30; - int32_t newHeight = height - 62; + auto widget = widgets[WIDX_VIEWPORT]; + auto newWidth = widget.width() - 1; + auto newHeight = widget.height() - 1; + viewport->pos = windowPos + ScreenCoordsXY{ widget.left + 1, widget.top + 1 }; // Update the viewport size if (viewport->width != newWidth || viewport->height != newHeight) diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index d412cc9d02..0178974e32 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -300,7 +300,8 @@ namespace OpenRCT2::Ui::Windows { auto ft = Formatter(); ft.Add(GetStaffWage(GetSelectedStaffType())); - DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ width - 155, 32 }, STR_COST_PER_MONTH, ft); + auto y = widgets[WIDX_STAFF_LIST_TITLE].bottom + 17; + DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ width - 155, y }, STR_COST_PER_MONTH, ft); } if (GetSelectedStaffType() != StaffType::Entertainer) diff --git a/src/openrct2-ui/windows/TextInput.cpp b/src/openrct2-ui/windows/TextInput.cpp index dbca27e43a..1c35868e06 100644 --- a/src/openrct2-ui/windows/TextInput.cpp +++ b/src/openrct2-ui/windows/TextInput.cpp @@ -198,8 +198,7 @@ namespace OpenRCT2::Ui::Windows { DrawWidgets(dpi); - ScreenCoordsXY screenCoords; - screenCoords.y = windowPos.y + 25; + auto screenCoords = windowPos + ScreenCoordsXY{ WW / 2, widgets[WIDX_TITLE].bottom + 13 }; int32_t no_lines = 0; @@ -207,14 +206,12 @@ namespace OpenRCT2::Ui::Windows { auto ft = Formatter(); ft.Add(_description.c_str()); - DrawTextWrapped( - dpi, { windowPos.x + WW / 2, screenCoords.y }, WW, STR_STRING, ft, { colours[1], TextAlignment::CENTRE }); + DrawTextWrapped(dpi, screenCoords, WW, STR_STRING, ft, { colours[1], TextAlignment::CENTRE }); } else { DrawTextWrapped( - dpi, { windowPos.x + WW / 2, screenCoords.y }, WW, _descriptionStringId, _descriptionArgs, - { colours[1], TextAlignment::CENTRE }); + dpi, screenCoords, WW, _descriptionStringId, _descriptionArgs, { colours[1], TextAlignment::CENTRE }); } screenCoords.y += 25;