From f8ab48176a069e266a298b76ee28110c11cae596 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Tue, 28 Jul 2020 22:37:52 +0200 Subject: [PATCH] Tile Inspector: remove hardcoded surface/edge style names --- data/language/en-GB.txt | 31 ------------ src/openrct2-ui/windows/TileInspector.cpp | 57 ++++++----------------- src/openrct2/localisation/StringIds.h | 32 ------------- src/openrct2/world/Surface.cpp | 13 ++++++ src/openrct2/world/TileElement.h | 4 ++ 5 files changed, 31 insertions(+), 106 deletions(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index c3e6366c05..088a9d55e0 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -2658,26 +2658,6 @@ STR_5311 :{SMALLFONT}{BLACK}Debug tools STR_5312 :Show console STR_5313 :Show tile inspector STR_5314 :Tile inspector -STR_5315 :Grass -STR_5316 :Sand -STR_5317 :Dirt -STR_5318 :Rock -STR_5319 :Martian -STR_5320 :Checkerboard -STR_5321 :Grass clumps -STR_5322 :Ice -STR_5323 :Grid (red) -STR_5324 :Grid (yellow) -STR_5325 :Grid (blue) -STR_5326 :Grid (green) -STR_5327 :Sand (dark) -STR_5328 :Sand (light) -STR_5329 :Checkerboard (inverted) -STR_5330 :Underground view -STR_5331 :Rock -STR_5332 :Wood (red) -STR_5333 :Wood (black) -STR_5334 :Ice STR_5335 :Ride entrance STR_5336 :Ride exit STR_5337 :Park entrance @@ -3493,17 +3473,6 @@ STR_6200 :Reset date STR_6201 :{MONTH} STR_6202 :Virtual floor style: STR_6203 :{SMALLFONT}{BLACK}When enabled, a virtual floor will be rendered when holding Ctrl or Shift to ease vertical placement of elements. -STR_6204 :Brick -STR_6205 :Iron -STR_6206 :Grey stucco -STR_6207 :Yellow stucco -STR_6208 :Red stucco -STR_6209 :Purple stucco -STR_6210 :Green stucco -STR_6211 :Brown sandstone -STR_6212 :Grey sandstone -STR_6213 :Skyscraper A -STR_6214 :Skyscraper B STR_6215 :Construction STR_6216 :Operation STR_6217 :Ride / track availability diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index a36ec28585..c731e0c1c2 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -32,43 +34,6 @@ #include // clang-format off -static constexpr const rct_string_id TerrainTypeStringIds[] = { - STR_TILE_INSPECTOR_TERRAIN_GRASS, - STR_TILE_INSPECTOR_TERRAIN_SAND, - STR_TILE_INSPECTOR_TERRAIN_DIRT, - STR_TILE_INSPECTOR_TERRAIN_ROCK, - STR_TILE_INSPECTOR_TERRAIN_MARTIAN, - STR_TILE_INSPECTOR_TERRAIN_CHECKERBOARD, - STR_TILE_INSPECTOR_TERRAIN_GRASS_CLUMPS, - STR_TILE_INSPECTOR_TERRAIN_ICE, - STR_TILE_INSPECTOR_TERRAIN_GRID_RED, - STR_TILE_INSPECTOR_TERRAIN_GRID_YELLOW, - STR_TILE_INSPECTOR_TERRAIN_GRID_BLUE, - STR_TILE_INSPECTOR_TERRAIN_GRID_GREEN, - STR_TILE_INSPECTOR_TERRAIN_SAND_DARK, - STR_TILE_INSPECTOR_TERRAIN_SAND_LIGHT, - STR_TILE_INSPECTOR_TERRAIN_CHECKERBOARD_INVERTED, - STR_TILE_INSPECTOR_TERRAIN_UNDERGROUND_VIEW, -}; - -static constexpr const rct_string_id TerrainEdgeTypeStringIds[] = { - STR_TILE_INSPECTOR_TERRAIN_EDGE_ROCK, - STR_TILE_INSPECTOR_TERRAIN_EDGE_WOOD_RED, - STR_TILE_INSPECTOR_TERRAIN_EDGE_WOOD_BLACK, - STR_TILE_INSPECTOR_TERRAIN_EDGE_ICE, - STR_TILE_INSPECTOR_TERRAIN_EDGE_BRICK, - STR_TILE_INSPECTOR_TERRAIN_EDGE_IRON, - STR_TILE_INSPECTOR_TERRAIN_EDGE_GREY, - STR_TILE_INSPECTOR_TERRAIN_EDGE_YELLOW, - STR_TILE_INSPECTOR_TERRAIN_EDGE_RED, - STR_TILE_INSPECTOR_TERRAIN_EDGE_PURPLE, - STR_TILE_INSPECTOR_TERRAIN_EDGE_GREEN, - STR_TILE_INSPECTOR_TERRAIN_EDGE_STONE_BROWN, - STR_TILE_INSPECTOR_TERRAIN_EDGE_STONE_GREY, - STR_TILE_INSPECTOR_TERRAIN_EDGE_SKYSCRAPER_A, - STR_TILE_INSPECTOR_TERRAIN_EDGE_SKYSCRAPER_B, -}; - static constexpr const rct_string_id EntranceTypeStringIds[] = { STR_TILE_INSPECTOR_ENTRANCE_TYPE_RIDE_ENTRANCE, STR_TILE_INSPECTOR_ENTRANCE_TYPE_RIDE_EXIT, @@ -1814,15 +1779,21 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) { // Details // Terrain texture name - rct_string_id terrainNameId = TerrainTypeStringIds[tileElement->AsSurface()->GetSurfaceStyle()]; + rct_string_id terrainNameId = STR_EMPTY; + auto surfaceStyle = tileElement->AsSurface()->GetSurfaceStyleObject(); + if (surfaceStyle != nullptr) + { + terrainNameId = surfaceStyle->NameStringId; + } gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_SURFACE_TERAIN, &terrainNameId, COLOUR_WHITE, screenCoords); // Edge texture name - uint32_t idx = tileElement->AsSurface()->GetEdgeStyle(); - openrct2_assert( - idx < std::size(TerrainEdgeTypeStringIds), "Tried accessing invalid entry %d in terrainEdgeTypeStringIds", - idx); - rct_string_id terrainEdgeNameId = TerrainEdgeTypeStringIds[tileElement->AsSurface()->GetEdgeStyle()]; + rct_string_id terrainEdgeNameId = STR_EMPTY; + auto edgeStyle = tileElement->AsSurface()->GetEdgeStyleObject(); + if (edgeStyle != nullptr) + { + terrainEdgeNameId = edgeStyle->NameStringId; + } gfx_draw_string_left( dpi, STR_TILE_INSPECTOR_SURFACE_EDGE, &terrainEdgeNameId, COLOUR_WHITE, screenCoords + ScreenCoordsXY{ 0, 11 }); diff --git a/src/openrct2/localisation/StringIds.h b/src/openrct2/localisation/StringIds.h index bc79126dfd..f6a6c53692 100644 --- a/src/openrct2/localisation/StringIds.h +++ b/src/openrct2/localisation/StringIds.h @@ -2786,26 +2786,6 @@ enum STR_DEBUG_DROPDOWN_CONSOLE = 5312, STR_DEBUG_DROPDOWN_TILE_INSPECTOR = 5313, STR_TILE_INSPECTOR_TITLE = 5314, - STR_TILE_INSPECTOR_TERRAIN_GRASS = 5315, - STR_TILE_INSPECTOR_TERRAIN_SAND = 5316, - STR_TILE_INSPECTOR_TERRAIN_DIRT = 5317, - STR_TILE_INSPECTOR_TERRAIN_ROCK = 5318, - STR_TILE_INSPECTOR_TERRAIN_MARTIAN = 5319, - STR_TILE_INSPECTOR_TERRAIN_CHECKERBOARD = 5320, - STR_TILE_INSPECTOR_TERRAIN_GRASS_CLUMPS = 5321, - STR_TILE_INSPECTOR_TERRAIN_ICE = 5322, - STR_TILE_INSPECTOR_TERRAIN_GRID_RED = 5323, - STR_TILE_INSPECTOR_TERRAIN_GRID_YELLOW = 5324, - STR_TILE_INSPECTOR_TERRAIN_GRID_BLUE = 5325, - STR_TILE_INSPECTOR_TERRAIN_GRID_GREEN = 5326, - STR_TILE_INSPECTOR_TERRAIN_SAND_DARK = 5327, - STR_TILE_INSPECTOR_TERRAIN_SAND_LIGHT = 5328, - STR_TILE_INSPECTOR_TERRAIN_CHECKERBOARD_INVERTED = 5329, - STR_TILE_INSPECTOR_TERRAIN_UNDERGROUND_VIEW = 5330, - STR_TILE_INSPECTOR_TERRAIN_EDGE_ROCK = 5331, - STR_TILE_INSPECTOR_TERRAIN_EDGE_WOOD_RED = 5332, - STR_TILE_INSPECTOR_TERRAIN_EDGE_WOOD_BLACK = 5333, - STR_TILE_INSPECTOR_TERRAIN_EDGE_ICE = 5334, STR_TILE_INSPECTOR_ENTRANCE_TYPE_RIDE_ENTRANCE = 5335, STR_TILE_INSPECTOR_ENTRANCE_TYPE_RIDE_EXIT = 5336, STR_TILE_INSPECTOR_ENTRANCE_TYPE_PARK_ENTRANC = 5337, @@ -3671,18 +3651,6 @@ enum STR_VIRTUAL_FLOOR_STYLE = 6202, STR_VIRTUAL_FLOOR_STYLE_TIP = 6203, - STR_TILE_INSPECTOR_TERRAIN_EDGE_BRICK = 6204, - STR_TILE_INSPECTOR_TERRAIN_EDGE_IRON = 6205, - STR_TILE_INSPECTOR_TERRAIN_EDGE_GREY = 6206, - STR_TILE_INSPECTOR_TERRAIN_EDGE_YELLOW = 6207, - STR_TILE_INSPECTOR_TERRAIN_EDGE_RED = 6208, - STR_TILE_INSPECTOR_TERRAIN_EDGE_PURPLE = 6209, - STR_TILE_INSPECTOR_TERRAIN_EDGE_GREEN = 6210, - STR_TILE_INSPECTOR_TERRAIN_EDGE_STONE_BROWN = 6211, - STR_TILE_INSPECTOR_TERRAIN_EDGE_STONE_GREY = 6212, - STR_TILE_INSPECTOR_TERRAIN_EDGE_SKYSCRAPER_A = 6213, - STR_TILE_INSPECTOR_TERRAIN_EDGE_SKYSCRAPER_B = 6214, - STR_CHEAT_GROUP_CONSTRUCTION = 6215, STR_CHEAT_GROUP_OPERATION = 6216, STR_CHEAT_GROUP_AVAILABILITY = 6217, diff --git a/src/openrct2/world/Surface.cpp b/src/openrct2/world/Surface.cpp index 4aae8d64fb..dad84eaf00 100644 --- a/src/openrct2/world/Surface.cpp +++ b/src/openrct2/world/Surface.cpp @@ -11,6 +11,7 @@ #include "../Context.h" #include "../object/ObjectManager.h" +#include "../object/TerrainEdgeObject.h" #include "../object/TerrainSurfaceObject.h" #include "../scenario/Scenario.h" #include "Location.hpp" @@ -21,11 +22,23 @@ uint32_t SurfaceElement::GetSurfaceStyle() const return SurfaceStyle; } +TerrainSurfaceObject* SurfaceElement::GetSurfaceStyleObject() const +{ + auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); + return static_cast(objManager.GetLoadedObject(OBJECT_TYPE_TERRAIN_SURFACE, GetSurfaceStyle())); +} + uint32_t SurfaceElement::GetEdgeStyle() const { return EdgeStyle; } +TerrainEdgeObject* SurfaceElement::GetEdgeStyleObject() const +{ + auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); + return static_cast(objManager.GetLoadedObject(OBJECT_TYPE_TERRAIN_EDGE, GetEdgeStyle())); +} + void SurfaceElement::SetSurfaceStyle(uint32_t newStyle) { SurfaceStyle = newStyle; diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 193fe8c6f3..8c0766a16c 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -19,6 +19,8 @@ struct Banner; struct CoordsXY; struct rct_scenery_entry; struct rct_footpath_entry; +class TerrainSurfaceObject; +class TerrainEdgeObject; using track_type_t = uint16_t; constexpr const uint8_t MAX_ELEMENT_HEIGHT = 255; @@ -166,8 +168,10 @@ public: void SetSlope(uint8_t newSlope); uint32_t GetSurfaceStyle() const; + TerrainSurfaceObject* GetSurfaceStyleObject() const; void SetSurfaceStyle(uint32_t newStyle); uint32_t GetEdgeStyle() const; + TerrainEdgeObject* GetEdgeStyleObject() const; void SetEdgeStyle(uint32_t newStyle); bool CanGrassGrow() const;