mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
Selected TileElement now stored in paint session
This commit is contained in:
@@ -558,10 +558,7 @@ public:
|
||||
if (tileInspectorPage == TileInspectorPage::Default || windowTileInspectorSelectedIndex == -1)
|
||||
return;
|
||||
|
||||
const TileElement* const tileElement = GetSelectedElement();
|
||||
|
||||
// Update selection, can be nullptr.
|
||||
OpenRCT2::TileInspector::SetSelectedElement(tileElement);
|
||||
const TileElement* const tileElement = OpenRCT2::TileInspector::GetSelectedElement();
|
||||
|
||||
if (tileElement == nullptr)
|
||||
return;
|
||||
@@ -713,12 +710,12 @@ public:
|
||||
void OnClose() override
|
||||
{
|
||||
ToolCancel();
|
||||
TileElement* const elem = GetSelectedElement();
|
||||
TileElement* const elem = OpenRCT2::TileInspector::GetSelectedElement();
|
||||
if (elem != nullptr)
|
||||
{
|
||||
MapInvalidateElement(_toolMap, elem);
|
||||
}
|
||||
OpenRCT2::TileInspector::SetSelectedElement(nullptr);
|
||||
windowTileInspectorSelectedIndex = -1;
|
||||
}
|
||||
|
||||
void OnResize() override
|
||||
@@ -769,7 +766,7 @@ public:
|
||||
if (tileInspectorPage == TileInspectorPage::Default || windowTileInspectorSelectedIndex == -1)
|
||||
return;
|
||||
|
||||
const TileElement* tileElement = GetSelectedElement();
|
||||
const TileElement* tileElement = OpenRCT2::TileInspector::GetSelectedElement();
|
||||
if (tileElement == nullptr)
|
||||
return;
|
||||
|
||||
@@ -928,7 +925,7 @@ public:
|
||||
if (dropdownIndex == -1)
|
||||
return;
|
||||
// Get selected element
|
||||
const TileElement* const tileElement = GetSelectedElement();
|
||||
const TileElement* const tileElement = OpenRCT2::TileInspector::GetSelectedElement();
|
||||
if (tileInspectorPage == TileInspectorPage::Wall)
|
||||
{
|
||||
Guard::Assert(tileElement->GetType() == TileElementType::Wall, "Element is not a wall");
|
||||
@@ -1049,7 +1046,7 @@ public:
|
||||
+ ScreenCoordsXY{ widgets[WIDX_GROUPBOX_DETAILS].left + 7, widgets[WIDX_GROUPBOX_DETAILS].top + 14 };
|
||||
|
||||
// Get map element
|
||||
const TileElement* const tileElement = GetSelectedElement();
|
||||
const TileElement* const tileElement = OpenRCT2::TileInspector::GetSelectedElement();
|
||||
if (tileElement == nullptr)
|
||||
return;
|
||||
|
||||
@@ -1764,7 +1761,6 @@ private:
|
||||
_tileSelected = true;
|
||||
_toolMap = mapCoords;
|
||||
windowTileInspectorTile = TileCoordsXY(mapCoords);
|
||||
OpenRCT2::TileInspector::SetSelectedElement(clickedElement);
|
||||
LoadTile(clickedElement);
|
||||
}
|
||||
|
||||
@@ -1773,13 +1769,10 @@ private:
|
||||
if (index < 0 || index >= windowTileInspectorElementCount)
|
||||
{
|
||||
windowTileInspectorSelectedIndex = -1;
|
||||
OpenRCT2::TileInspector::SetSelectedElement(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
windowTileInspectorSelectedIndex = index;
|
||||
const TileElement* const tileElement = GetSelectedElement();
|
||||
OpenRCT2::TileInspector::SetSelectedElement(tileElement);
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
@@ -1839,7 +1832,7 @@ private:
|
||||
|
||||
void CopyElement()
|
||||
{
|
||||
const TileElement* const tileElement = GetSelectedElement();
|
||||
const TileElement* const tileElement = OpenRCT2::TileInspector::GetSelectedElement();
|
||||
Guard::Assert(tileElement != nullptr, "Invalid tile element");
|
||||
// Copy value, in case the element gets moved
|
||||
_copiedElement = *tileElement;
|
||||
@@ -1992,21 +1985,9 @@ private:
|
||||
GameActions::Execute(&modifyTile);
|
||||
}
|
||||
|
||||
TileElement* GetSelectedElement()
|
||||
{
|
||||
if (windowTileInspectorSelectedIndex == -1)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
Guard::Assert(
|
||||
windowTileInspectorSelectedIndex >= 0 && windowTileInspectorSelectedIndex < windowTileInspectorElementCount,
|
||||
"Selected list item out of range");
|
||||
return MapGetNthElementAt(_toolMap, windowTileInspectorSelectedIndex);
|
||||
}
|
||||
|
||||
void OnPrepareDraw() override
|
||||
{
|
||||
const TileElement* const tileElement = GetSelectedElement();
|
||||
const TileElement* const tileElement = OpenRCT2::TileInspector::GetSelectedElement();
|
||||
|
||||
// Set the correct page automatically
|
||||
TileInspectorPage p = TileInspectorPage::Default;
|
||||
|
||||
@@ -190,6 +190,7 @@ struct PaintSessionCore
|
||||
TileElement* CurrentlyDrawnTileElement;
|
||||
const TileElement* PathElementOnSameHeight;
|
||||
const TileElement* TrackElementOnSameHeight;
|
||||
const TileElement* SelectedElement;
|
||||
PaintStruct* WoodenSupportsPrependTo;
|
||||
CoordsXY SpritePosition;
|
||||
CoordsXY MapPosition;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "../profiling/Profiling.h"
|
||||
#include "../title/TitleScreen.h"
|
||||
#include "../ui/UiContext.h"
|
||||
#include "../world/TileInspector.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Drawing;
|
||||
@@ -169,6 +170,7 @@ PaintSession* Painter::CreateSession(DrawPixelInfo& dpi, uint32_t viewFlags)
|
||||
session->CurrentlyDrawnEntity = nullptr;
|
||||
session->CurrentlyDrawnTileElement = nullptr;
|
||||
session->Surface = nullptr;
|
||||
session->SelectedElement = OpenRCT2::TileInspector::GetSelectedElement();
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ void PaintBanner(PaintSession& session, uint8_t direction, int32_t height, const
|
||||
session.InteractionType = ViewportInteractionItem::None;
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
}
|
||||
else if (OpenRCT2::TileInspector::IsElementSelected(reinterpret_cast<const TileElement*>(&bannerElement)))
|
||||
else if (session.SelectedElement == reinterpret_cast<const TileElement*>(&bannerElement))
|
||||
{
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ static void PaintRideEntranceExit(PaintSession& session, uint8_t direction, int3
|
||||
session.InteractionType = ViewportInteractionItem::None;
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
}
|
||||
else if (OpenRCT2::TileInspector::IsElementSelected(reinterpret_cast<const TileElement*>(&entranceEl)))
|
||||
else if (session.SelectedElement == reinterpret_cast<const TileElement*>(&entranceEl))
|
||||
{
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
}
|
||||
@@ -277,7 +277,7 @@ static void PaintParkEntrance(PaintSession& session, uint8_t direction, int32_t
|
||||
session.InteractionType = ViewportInteractionItem::None;
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
}
|
||||
else if (OpenRCT2::TileInspector::IsElementSelected(reinterpret_cast<const TileElement*>(&entranceEl)))
|
||||
else if (session.SelectedElement == reinterpret_cast<const TileElement*>(&entranceEl))
|
||||
{
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ void PaintLargeScenery(PaintSession& session, uint8_t direction, uint16_t height
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
isGhost = true;
|
||||
}
|
||||
else if (OpenRCT2::TileInspector::IsElementSelected(reinterpret_cast<const TileElement*>(&tileElement)))
|
||||
else if (session.SelectedElement == reinterpret_cast<const TileElement*>(&tileElement))
|
||||
{
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
isGhost = true;
|
||||
|
||||
@@ -789,7 +789,7 @@ void PaintPath(PaintSession& session, uint16_t height, const PathElement& tileEl
|
||||
session.InteractionType = ViewportInteractionItem::None;
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
}
|
||||
else if (TileInspector::IsElementSelected(reinterpret_cast<const TileElement*>(&tileElement)))
|
||||
else if (session.SelectedElement == reinterpret_cast<const TileElement*>(&tileElement))
|
||||
{
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
sceneryImageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
|
||||
@@ -346,7 +346,7 @@ void PaintSmallScenery(PaintSession& session, uint8_t direction, int32_t height,
|
||||
session.InteractionType = ViewportInteractionItem::None;
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
}
|
||||
else if (OpenRCT2::TileInspector::IsElementSelected(reinterpret_cast<const TileElement*>(&sceneryElement)))
|
||||
else if (session.SelectedElement == reinterpret_cast<const TileElement*>(&sceneryElement))
|
||||
{
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
}
|
||||
|
||||
@@ -1138,7 +1138,7 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con
|
||||
imageId = imageId.WithTransparency(FilterPaletteID::PaletteDarken1);
|
||||
}
|
||||
|
||||
if (OpenRCT2::TileInspector::IsElementSelected(elementPtr))
|
||||
if (session.SelectedElement == elementPtr)
|
||||
{
|
||||
imageId = imageId.WithRemap(FilterPaletteID::PaletteGhost);
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ void PaintWall(PaintSession& session, uint8_t direction, int32_t height, const W
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
isGhost = true;
|
||||
}
|
||||
else if (OpenRCT2::TileInspector::IsElementSelected(reinterpret_cast<const TileElement*>(&wallElement)))
|
||||
else if (session.SelectedElement == reinterpret_cast<const TileElement*>(&wallElement))
|
||||
{
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::PaletteGhost);
|
||||
isGhost = true;
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
TileCoordsXY windowTileInspectorTile;
|
||||
int32_t windowTileInspectorElementCount = 0;
|
||||
int32_t windowTileInspectorSelectedIndex;
|
||||
int32_t windowTileInspectorSelectedIndex = -1;
|
||||
|
||||
using namespace OpenRCT2::TrackMetaData;
|
||||
namespace OpenRCT2::TileInspector
|
||||
@@ -955,17 +955,15 @@ namespace OpenRCT2::TileInspector
|
||||
return GameActions::Result();
|
||||
}
|
||||
|
||||
// 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)
|
||||
TileElement* GetSelectedElement()
|
||||
{
|
||||
_highlightedElement = elem;
|
||||
}
|
||||
|
||||
bool IsElementSelected(const TileElement* elem)
|
||||
{
|
||||
return _highlightedElement == elem;
|
||||
if (windowTileInspectorSelectedIndex == -1)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
Guard::Assert(
|
||||
windowTileInspectorSelectedIndex >= 0 && windowTileInspectorSelectedIndex < windowTileInspectorElementCount,
|
||||
"Selected list item out of range");
|
||||
return MapGetNthElementAt(windowTileInspectorTile.ToCoordsXY(), windowTileInspectorSelectedIndex);
|
||||
}
|
||||
} // namespace OpenRCT2::TileInspector
|
||||
|
||||
@@ -19,8 +19,7 @@ namespace GameActions
|
||||
|
||||
namespace OpenRCT2::TileInspector
|
||||
{
|
||||
void SetSelectedElement(const TileElement* elem);
|
||||
bool IsElementSelected(const TileElement* elem);
|
||||
TileElement* GetSelectedElement();
|
||||
|
||||
GameActions::Result InsertCorruptElementAt(const CoordsXY& loc, int16_t elementIndex, bool isExecuting);
|
||||
GameActions::Result RemoveElementAt(const CoordsXY& loc, int16_t elementIndex, bool isExecuting);
|
||||
|
||||
Reference in New Issue
Block a user