From 1cb0650cbaf198f31d0be208e9c8a8b8a4968ee4 Mon Sep 17 00:00:00 2001 From: Michael Bernardi Date: Sun, 25 Feb 2024 23:18:38 +0100 Subject: [PATCH] Fix #21289: Map window does not layout properly --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/Map.cpp | 66 ++++++++++++++++++------ src/openrct2/interface/Window.cpp | 5 ++ src/openrct2/interface/Window.h | 1 + src/openrct2/interface/Window_internal.h | 3 ++ src/openrct2/localisation/Language.cpp | 2 + 6 files changed, 62 insertions(+), 16 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 7c23184988..5929cc1981 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -12,6 +12,7 @@ - Fix: [#21220] When creating a new park from a SC4 file, the localised park name is not applied. - Fix: [#21286] Cannot build unbanking turns with RCT1 vehicles. - Fix: [#21288] Text overlaps in the “About ‘OpenRCT2’” window for Arabic, Chinese, Japanese, Korean and Vietnamese. +- Fix: [#21289] Text overlaps and overflows in the map window for some languages. - Fix: [#21310] Some half loop elements require more clearance than their upward/downward counterparts. - Fix: [#21318] Virtual Floor for building scenery is not properly invalidated. - Fix: [#21330] Tooltips from dropdown widgets have the wrong position. diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index ea19e56c17..1398b6acca 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -155,8 +156,15 @@ public: | (1uLL << WIDX_MAP_SIZE_SPINNER_X_UP) | (1uLL << WIDX_MAP_SIZE_SPINNER_X_DOWN) | (1uLL << WIDX_LAND_TOOL_LARGER) | (1uLL << WIDX_LAND_TOOL_SMALLER); + flags |= WF_RESIZABLE; + min_width = WW; + max_width = 800; + min_height = WH; + max_height = 560; + ResizeMap(); InitScrollWidgets(); + CalculateTextLayout(); _rotation = GetCurrentRotation(); @@ -183,15 +191,6 @@ public: } } - void OnResize() override - { - flags |= WF_RESIZABLE; - min_width = 245; - max_width = 800; - min_height = 259; - max_height = 560; - } - void OnMouseUp(WidgetIndex widgetIndex) override { switch (widgetIndex) @@ -287,6 +286,7 @@ public: selected_tab = widgetIndex; list_information_type = 0; + _recalculateScrollbars = true; } } } @@ -854,6 +854,11 @@ public: ShowDefaultScenarioEditorButtons(); } } + if (_recalculateScrollbars) + { + WidgetScrollUpdateThumbs(*this, WIDX_MAP); + _recalculateScrollbars = false; + } } void OnDraw(DrawPixelInfo& dpi) override @@ -889,22 +894,18 @@ public: { screenCoords = windowPos + ScreenCoordsXY{ 4, widgets[WIDX_MAP].bottom + 2 }; - static constexpr StringId _mapLabels[] = { - STR_MAP_RIDE, STR_MAP_FOOD_STALL, STR_MAP_DRINK_STALL, STR_MAP_SOUVENIR_STALL, - STR_MAP_INFO_KIOSK, STR_MAP_FIRST_AID, STR_MAP_CASH_MACHINE, STR_MAP_TOILET, - }; - static_assert(std::size(RideKeyColours) == std::size(_mapLabels)); + static_assert(std::size(RideKeyColours) == std::size(MapLabels)); for (uint32_t i = 0; i < std::size(RideKeyColours); i++) { GfxFillRect( dpi, { screenCoords + ScreenCoordsXY{ 0, 2 }, screenCoords + ScreenCoordsXY{ 6, 8 } }, RideKeyColours[i]); - DrawTextBasic(dpi, screenCoords + ScreenCoordsXY{ LIST_ROW_HEIGHT, 0 }, _mapLabels[i], {}); + DrawTextBasic(dpi, screenCoords + ScreenCoordsXY{ LIST_ROW_HEIGHT, 0 }, MapLabels[i], {}); screenCoords.y += LIST_ROW_HEIGHT; if (i == 3) { - screenCoords += { 118, -(LIST_ROW_HEIGHT * 4) }; + screenCoords += { _firstColumnWidth, -(LIST_ROW_HEIGHT * 4) }; } } } @@ -917,6 +918,11 @@ public: } } + void OnLanguageChange() override + { + CalculateTextLayout(); + } + void ResetMap() { InitMap(); @@ -1404,11 +1410,34 @@ private: widgets[WIDX_MAP].bottom = height - 1 - 14; } + void CalculateTextLayout() + { + int32_t textOffset = 4 + LIST_ROW_HEIGHT; + _firstColumnWidth = 118; + for (uint32_t i = 0; i < 4; i++) + { + const auto* labelStr = LanguageGetString(MapLabels[i]); + _firstColumnWidth = std::max(textOffset + GfxGetStringWidth(labelStr, FontStyle::Medium), _firstColumnWidth); + } + + textOffset += _firstColumnWidth + 4; + min_width = WW; + for (uint32_t i = 4; i < std::size(MapLabels); i++) + { + const auto* labelStr = LanguageGetString(MapLabels[i]); + min_width = std::max(static_cast(textOffset + GfxGetStringWidth(labelStr, FontStyle::Medium)), min_width); + } + width = std::max(min_width, width); + _recalculateScrollbars = true; + } + uint8_t _activeTool; uint32_t _currentLine; uint16_t _landRightsToolSize; + int32_t _firstColumnWidth; std::vector _mapImageData; bool _mapWidthAndHeightLinked{ true }; + bool _recalculateScrollbars = false; enum class ResizeDirection { Both, @@ -1416,6 +1445,11 @@ private: Y, } _resizeDirection{ ResizeDirection::Both }; + static constexpr StringId MapLabels[] = { + STR_MAP_RIDE, STR_MAP_FOOD_STALL, STR_MAP_DRINK_STALL, STR_MAP_SOUVENIR_STALL, + STR_MAP_INFO_KIOSK, STR_MAP_FIRST_AID, STR_MAP_CASH_MACHINE, STR_MAP_TOILET, + }; + static constexpr uint16_t RideKeyColours[] = { MapColour(PALETTE_INDEX_61), // COLOUR_KEY_RIDE MapColour(PALETTE_INDEX_42), // COLOUR_KEY_FOOD diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 2a71c91224..cdf29495bf 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -156,6 +156,11 @@ void WindowUpdateAll() windowManager->UpdateMouseWheel(); } +void WindowNotifyLanguageChange() +{ + WindowVisitEach([&](WindowBase* w) { w->OnLanguageChange(); }); +} + static void WindowCloseSurplus(int32_t cap, WindowClass avoid_classification) { // find the amount of windows that are currently open diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index 66c4dc08e9..12e44616d8 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -501,6 +501,7 @@ void WindowVisitEach(std::function func); void WindowDispatchUpdateAll(); void WindowUpdateAllViewports(); void WindowUpdateAll(); +void WindowNotifyLanguageChange(); void WindowSetWindowLimit(int32_t value); diff --git a/src/openrct2/interface/Window_internal.h b/src/openrct2/interface/Window_internal.h index 994c587089..2a1e3ffd9a 100644 --- a/src/openrct2/interface/Window_internal.h +++ b/src/openrct2/interface/Window_internal.h @@ -167,6 +167,9 @@ struct WindowBase { } virtual CursorID OnCursor(WidgetIndex, const ScreenCoordsXY&, CursorID); + virtual void OnLanguageChange() + { + } void ResizeFrame(); void ResizeFrameWithPage(); diff --git a/src/openrct2/localisation/Language.cpp b/src/openrct2/localisation/Language.cpp index a47d68c901..4bf4e9ada2 100644 --- a/src/openrct2/localisation/Language.cpp +++ b/src/openrct2/localisation/Language.cpp @@ -12,6 +12,7 @@ #include "../core/String.hpp" #include "../interface/FontFamilies.h" #include "../interface/Fonts.h" +#include "../interface/Window.h" #include "../object/ObjectManager.h" #include "../platform/Platform.h" #include "LanguagePack.h" @@ -85,6 +86,7 @@ bool LanguageOpen(int32_t id) // Objects and their localised strings need to be refreshed objectManager.ResetObjects(); ScrollingTextInvalidate(); + WindowNotifyLanguageChange(); return true; } catch (const std::exception&)