diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 387f922a1c..af5ff2a9c2 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -2,6 +2,7 @@ ------------------------------------------------------------------------ - Feature: [#15084] [Plugin] Add "vehicle.crash" hook. - Feature: [#15143] Added a shortcut key for Giant Screenshot. +- Feature: [#15164] Highlight elements selected by the Tile Inspector, tracks are currently not supported. - Feature: [#15165] [Plugin] Add the ability to create entities using "map.createEntity". - Fix: [#13465] Creating a scenario based on a won save game results in a scenario that’s instantly won. - Fix: [#14316] Closing the Track Designs Manager window causes broken state. diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 5e50110dfb..54103820a2 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -32,6 +32,7 @@ #include #include #include +#include // clang-format off static constexpr const rct_string_id EntranceTypeStringIds[] = { @@ -438,6 +439,7 @@ static void window_tile_inspector_invalidate(rct_window* w); static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi); static void window_tile_inspector_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex); static void window_tile_inspector_set_page(rct_window* w, const TileInspectorPage page); +static void window_tile_inspector_close(rct_window* w); // clang-format off static rct_window_event_list TileInspectorWindowEvents([](auto& events) @@ -456,6 +458,7 @@ static rct_window_event_list TileInspectorWindowEvents([](auto& events) events.invalidate = &window_tile_inspector_invalidate; events.paint = &window_tile_inspector_paint; events.scroll_paint = &window_tile_inspector_scrollpaint; + events.close = &window_tile_inspector_close; }); static uint64_t PageEnabledWidgets[] = { @@ -542,10 +545,14 @@ static void window_tile_inspector_select_element_from_list(rct_window* w, int32_ if (index < 0 || index >= windowTileInspectorElementCount) { windowTileInspectorSelectedIndex = -1; + OpenRCT2::TileInspector::SetSelectedElement(nullptr); } else { windowTileInspectorSelectedIndex = index; + + const TileElement* const tileElement = window_tile_inspector_get_selected_element(w); + OpenRCT2::TileInspector::SetSelectedElement(tileElement); } w->Invalidate(); @@ -761,6 +768,11 @@ static void window_tile_inspector_clamp_corrupt(int32_t elementIndex) GameActions::Execute(&modifyTile); } +static void window_tile_inspector_close(rct_window* w) +{ + OpenRCT2::TileInspector::SetSelectedElement(nullptr); +} + static void window_tile_inspector_mouseup(rct_window* w, rct_widgetindex widgetIndex) { switch (widgetIndex) @@ -1287,6 +1299,8 @@ static void window_tile_inspector_update_selected_tile(rct_window* w, const Scre windowTileInspectorToolMap = mapCoords; windowTileInspectorTile = TileCoordsXY(mapCoords); + OpenRCT2::TileInspector::SetSelectedElement(clickedElement); + window_tile_inspector_load_tile(w, clickedElement); } diff --git a/src/openrct2/paint/tile_element/Paint.Banner.cpp b/src/openrct2/paint/tile_element/Paint.Banner.cpp index 0b3f492ba6..a6bd774e65 100644 --- a/src/openrct2/paint/tile_element/Paint.Banner.cpp +++ b/src/openrct2/paint/tile_element/Paint.Banner.cpp @@ -15,6 +15,7 @@ #include "../../sprites.h" #include "../../world/Banner.h" #include "../../world/Scenery.h" +#include "../../world/TileInspector.h" #include "../Paint.h" #include "Paint.TileElement.h" @@ -74,6 +75,10 @@ void banner_paint(paint_session* session, uint8_t direction, int32_t height, con session->InteractionType = ViewportInteractionItem::None; image_id |= CONSTRUCTION_MARKER; } + else if (OpenRCT2::TileInspector::IsElementSelected(tile_element)) + { + image_id |= CONSTRUCTION_MARKER; + } else { image_id |= (banner->colour << 19) | IMAGE_TYPE_REMAP; diff --git a/src/openrct2/paint/tile_element/Paint.Entrance.cpp b/src/openrct2/paint/tile_element/Paint.Entrance.cpp index 8a7b106617..4f268bce17 100644 --- a/src/openrct2/paint/tile_element/Paint.Entrance.cpp +++ b/src/openrct2/paint/tile_element/Paint.Entrance.cpp @@ -21,6 +21,7 @@ #include "../../world/Entrance.h" #include "../../world/Footpath.h" #include "../../world/Park.h" +#include "../../world/TileInspector.h" #include "../Paint.h" #include "../Supports.h" #include "Paint.TileElement.h" @@ -100,6 +101,13 @@ static void ride_entrance_exit_paint(paint_session* session, uint8_t direction, if (transparant_image_id) transparant_image_id = image_id; } + else if (OpenRCT2::TileInspector::IsElementSelected(tile_element)) + { + image_id = CONSTRUCTION_MARKER; + entranceImageId = image_id; + if (transparant_image_id) + transparant_image_id = image_id; + } if (is_exit) { @@ -227,6 +235,10 @@ static void park_entrance_paint(paint_session* session, uint8_t direction, int32 session->InteractionType = ViewportInteractionItem::None; ghost_id = CONSTRUCTION_MARKER; } + else if (OpenRCT2::TileInspector::IsElementSelected(tile_element)) + { + ghost_id = CONSTRUCTION_MARKER; + } // Index to which part of the entrance // Middle, left, right diff --git a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp index 155a442efb..273bb2bf74 100644 --- a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp +++ b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp @@ -19,6 +19,7 @@ #include "../../world/LargeScenery.h" #include "../../world/Map.h" #include "../../world/Scenery.h" +#include "../../world/TileInspector.h" #include "../Paint.h" #include "../Supports.h" #include "Paint.TileElement.h" @@ -227,7 +228,7 @@ void large_scenery_paint(paint_session* session, uint8_t direction, uint16_t hei return; } session->InteractionType = ViewportInteractionItem::LargeScenery; - uint32_t sequenceNum = tileElement->AsLargeScenery()->GetSequenceIndex(); + const uint32_t sequenceNum = tileElement->AsLargeScenery()->GetSequenceIndex(); const LargeSceneryObject* object = tileElement->AsLargeScenery()->GetObject(); if (object == nullptr) return; @@ -250,20 +251,25 @@ void large_scenery_paint(paint_session* session, uint8_t direction, uint16_t hei { if (!track_design_save_contains_tile_element(tileElement)) { - sequenceNum = SPRITE_ID_PALETTE_COLOUR_1(EnumValue(FilterPaletteID::Palette46)); image_id &= 0x7FFFF; - dword_F4387C = sequenceNum; + dword_F4387C = SPRITE_ID_PALETTE_COLOUR_1(EnumValue(FilterPaletteID::Palette46)); image_id |= dword_F4387C; } } if (tileElement->IsGhost()) { session->InteractionType = ViewportInteractionItem::None; - sequenceNum = CONSTRUCTION_MARKER; image_id &= 0x7FFFF; - dword_F4387C = sequenceNum; + dword_F4387C = CONSTRUCTION_MARKER; image_id |= dword_F4387C; } + else if (OpenRCT2::TileInspector::IsElementSelected(tileElement)) + { + image_id &= 0x7FFFF; + dword_F4387C = CONSTRUCTION_MARKER; + image_id |= dword_F4387C; + } + int32_t boxlengthZ = tile->z_clearance; if (boxlengthZ > 0x80) { diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 1b6e59dfa2..5437e4ccfc 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -23,11 +23,14 @@ #include "../../world/Map.h" #include "../../world/Scenery.h" #include "../../world/Surface.h" +#include "../../world/TileInspector.h" #include "../Paint.h" #include "../Supports.h" #include "Paint.Surface.h" #include "Paint.TileElement.h" +using namespace OpenRCT2; + bool gPaintWidePathsAsGhost = false; // clang-format off @@ -844,6 +847,11 @@ void path_paint(paint_session* session, uint16_t height, const TileElement* tile session->InteractionType = ViewportInteractionItem::None; imageFlags = CONSTRUCTION_MARKER; } + else if (TileInspector::IsElementSelected(tile_element)) + { + imageFlags |= CONSTRUCTION_MARKER; + sceneryImageFlags = CONSTRUCTION_MARKER; + } // For debugging purpose, show blocked tiles with a colour if (gPaintBlockedTiles && tile_element->AsPath()->IsBlockedByVehicle()) diff --git a/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp b/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp index e07c6bd115..31a3755871 100644 --- a/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp +++ b/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp @@ -16,6 +16,7 @@ #include "../../world/Map.h" #include "../../world/Scenery.h" #include "../../world/SmallScenery.h" +#include "../../world/TileInspector.h" #include "../Paint.h" #include "../Supports.h" #include "Paint.TileElement.h" @@ -58,6 +59,10 @@ void scenery_paint(paint_session* session, uint8_t direction, int32_t height, co session->InteractionType = ViewportInteractionItem::None; marker = CONSTRUCTION_MARKER; } + else if (OpenRCT2::TileInspector::IsElementSelected(tileElement)) + { + marker = CONSTRUCTION_MARKER; + } auto* sceneryEntry = tileElement->AsSmallScenery()->GetEntry(); diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index d25d25f660..771215b680 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -27,6 +27,7 @@ #include "../../sprites.h" #include "../../world/Entity.h" #include "../../world/Surface.h" +#include "../../world/TileInspector.h" #include "Paint.TileElement.h" #include @@ -1075,6 +1076,11 @@ void surface_paint(paint_session* session, uint8_t direction, uint16_t height, c imageId |= 0x41880000; } + if (OpenRCT2::TileInspector::IsElementSelected(tileElement)) + { + imageId |= CONSTRUCTION_MARKER; + } + PaintAddImageAsParent(session, imageId, { 0, 0, height }, { 32, 32, -1 }); has_surface = true; } diff --git a/src/openrct2/paint/tile_element/Paint.Wall.cpp b/src/openrct2/paint/tile_element/Paint.Wall.cpp index ffe208e5df..1792186556 100644 --- a/src/openrct2/paint/tile_element/Paint.Wall.cpp +++ b/src/openrct2/paint/tile_element/Paint.Wall.cpp @@ -19,6 +19,7 @@ #include "../../world/Banner.h" #include "../../world/Map.h" #include "../../world/Scenery.h" +#include "../../world/TileInspector.h" #include "../../world/Wall.h" #include "../Paint.h" #include "Paint.TileElement.h" @@ -203,6 +204,10 @@ void fence_paint(paint_session* session, uint8_t direction, int32_t height, cons session->InteractionType = ViewportInteractionItem::None; dword_141F710 = CONSTRUCTION_MARKER; } + else if (OpenRCT2::TileInspector::IsElementSelected(tile_element)) + { + dword_141F710 = CONSTRUCTION_MARKER; + } // Save tile_element diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index ac95bbfe60..e4599bbbd5 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -1131,4 +1131,18 @@ namespace OpenRCT2::TileInspector return std::make_unique(); } + // NOTE: The pointer is exclusively used to determine the current selection, + // do not access the data, points to potentially invalid memory. + static const TileElement* _highlightedElement = nullptr; + + void SetSelectedElement(const TileElement* elem) + { + _highlightedElement = elem; + } + + bool IsElementSelected(const TileElement* elem) + { + return _highlightedElement == elem; + } + } // namespace OpenRCT2::TileInspector diff --git a/src/openrct2/world/TileInspector.h b/src/openrct2/world/TileInspector.h index 1c1d9d180e..212320fa4c 100644 --- a/src/openrct2/world/TileInspector.h +++ b/src/openrct2/world/TileInspector.h @@ -21,6 +21,9 @@ namespace OpenRCT2::TileInspector { using GameActionResultPtr = std::unique_ptr; + void SetSelectedElement(const TileElement* elem); + bool IsElementSelected(const TileElement* elem); + GameActionResultPtr InsertCorruptElementAt(const CoordsXY& loc, int16_t elementIndex, bool isExecuting); GameActionResultPtr RemoveElementAt(const CoordsXY& loc, int16_t elementIndex, bool isExecuting); GameActionResultPtr SwapElementsAt(const CoordsXY& loc, int16_t first, int16_t second, bool isExecuting);