1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Fix #21289: Map window does not layout properly

This commit is contained in:
Michael Bernardi
2024-02-25 23:18:38 +01:00
parent 7797db10c8
commit 1cb0650cba
6 changed files with 62 additions and 16 deletions

View File

@@ -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.

View File

@@ -28,6 +28,7 @@
#include <openrct2/entity/EntityRegistry.h>
#include <openrct2/entity/Staff.h>
#include <openrct2/localisation/Formatter.h>
#include <openrct2/localisation/Language.h>
#include <openrct2/object/TerrainSurfaceObject.h>
#include <openrct2/ride/RideData.h>
#include <openrct2/ride/Track.h>
@@ -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<int16_t>(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<uint8_t> _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

View File

@@ -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

View File

@@ -501,6 +501,7 @@ void WindowVisitEach(std::function<void(WindowBase*)> func);
void WindowDispatchUpdateAll();
void WindowUpdateAllViewports();
void WindowUpdateAll();
void WindowNotifyLanguageChange();
void WindowSetWindowLimit(int32_t value);

View File

@@ -167,6 +167,9 @@ struct WindowBase
{
}
virtual CursorID OnCursor(WidgetIndex, const ScreenCoordsXY&, CursorID);
virtual void OnLanguageChange()
{
}
void ResizeFrame();
void ResizeFrameWithPage();

View File

@@ -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&)