diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 7f56ba282b..13b7e982fe 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -21,6 +21,7 @@ - Fix: [#13130] Android always defaulting to UK locale for language, currency and temperature. - Fix: [#13397] Ride simulation causes strange station behaviour and makes the ride unusable in some cases. - Fix: [#16791] Rotodrop top piece replicates when walls are placed around it and clearance checks are disabled (original bug). +- Fix: [#18583] Land dropdown is incorrect if there are surface entry index holes. - Fix: [#18895] Responding mechanic blocked at level crossing. - Fix: [#19231] Crash due to null pointer to previously deleted banner in tile copy/paste functionality. - Fix: [#19296] Crash due to a race condition for parallel object loading. diff --git a/src/openrct2-ui/interface/LandTool.cpp b/src/openrct2-ui/interface/LandTool.cpp index d8d6106faa..ad0e8f67f2 100644 --- a/src/openrct2-ui/interface/LandTool.cpp +++ b/src/openrct2-ui/interface/LandTool.cpp @@ -89,6 +89,26 @@ void LandTool::ShowSurfaceStyleDropdown(WindowBase* w, Widget* widget, ObjectEnt gDropdownDefaultIndex = defaultIndex; } +ObjectEntryIndex LandTool::GetSurfaceStyleFromDropdownIndex(size_t index) +{ + auto& objManager = GetContext()->GetObjectManager(); + auto itemIndex = 0U; + for (size_t i = 0; i < MAX_TERRAIN_SURFACE_OBJECTS; i++) + { + const auto surfaceObj = static_cast(objManager.GetLoadedObject(ObjectType::TerrainSurface, i)); + // If fallback images are loaded, the RCT1 styles will just look like copies of already existing styles, so hide them. + if (surfaceObj != nullptr && !surfaceObj->UsesFallbackImages()) + { + if (itemIndex == index) + { + return static_cast(i); + } + itemIndex++; + } + } + return OBJECT_ENTRY_INDEX_NULL; +} + void LandTool::ShowEdgeStyleDropdown(WindowBase* w, Widget* widget, ObjectEntryIndex currentEdgeType) { auto& objManager = GetContext()->GetObjectManager(); @@ -119,3 +139,23 @@ void LandTool::ShowEdgeStyleDropdown(WindowBase* w, Widget* widget, ObjectEntryI gDropdownDefaultIndex = defaultIndex; } + +ObjectEntryIndex LandTool::GetEdgeStyleFromDropdownIndex(size_t index) +{ + auto& objManager = GetContext()->GetObjectManager(); + auto itemIndex = 0U; + for (size_t i = 0; i < MAX_TERRAIN_EDGE_OBJECTS; i++) + { + const auto edgeObj = static_cast(objManager.GetLoadedObject(ObjectType::TerrainEdge, i)); + // If fallback images are loaded, the RCT1 styles will just look like copies of already existing styles, so hide them. + if (edgeObj != nullptr && !edgeObj->UsesFallbackImages()) + { + if (itemIndex == index) + { + return static_cast(i); + } + itemIndex++; + } + } + return OBJECT_ENTRY_INDEX_NULL; +} diff --git a/src/openrct2-ui/interface/LandTool.h b/src/openrct2-ui/interface/LandTool.h index dab9395cad..542ed62680 100644 --- a/src/openrct2-ui/interface/LandTool.h +++ b/src/openrct2-ui/interface/LandTool.h @@ -30,5 +30,7 @@ namespace LandTool { uint32_t SizeToSpriteIndex(uint16_t size); void ShowSurfaceStyleDropdown(WindowBase* w, Widget* widget, ObjectEntryIndex currentSurfaceType); + ObjectEntryIndex GetSurfaceStyleFromDropdownIndex(size_t index); void ShowEdgeStyleDropdown(WindowBase* w, Widget* widget, ObjectEntryIndex currentEdgeType); + ObjectEntryIndex GetEdgeStyleFromDropdownIndex(size_t index); } // namespace LandTool diff --git a/src/openrct2-ui/windows/Land.cpp b/src/openrct2-ui/windows/Land.cpp index dc7e1ce871..ae9984e9ff 100644 --- a/src/openrct2-ui/windows/Land.cpp +++ b/src/openrct2-ui/windows/Land.cpp @@ -156,7 +156,8 @@ public: if (dropdownIndex == -1) dropdownIndex = gDropdownHighlightedIndex; - type = (dropdownIndex == -1) ? _selectedFloorTexture : dropdownIndex; + type = (dropdownIndex == -1) ? _selectedFloorTexture + : LandTool::GetSurfaceStyleFromDropdownIndex(static_cast(dropdownIndex)); if (gLandToolTerrainSurface == type) { @@ -173,7 +174,8 @@ public: if (dropdownIndex == -1) dropdownIndex = gDropdownHighlightedIndex; - type = (dropdownIndex == -1) ? _selectedWallTexture : dropdownIndex; + type = (dropdownIndex == -1) ? _selectedWallTexture + : LandTool::GetEdgeStyleFromDropdownIndex(static_cast(dropdownIndex)); if (gLandToolTerrainEdge == type) {