Files
OpenRCT2-Web/src/openrct2-ui/interface/ViewportInteraction.cpp
T

803 lines
27 KiB
C++
Raw Normal View History

2014-11-05 19:42:19 +00:00
/*****************************************************************************
2023-01-01 04:58:01 -06:00
* Copyright (c) 2014-2023 OpenRCT2 developers
*
2018-06-15 14:07:34 +02:00
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
2014-11-05 19:42:19 +00:00
*****************************************************************************/
#include "../windows/Window.h"
2018-06-22 23:20:47 +02:00
#include "Viewport.h"
#include "Window.h"
2018-08-12 12:50:40 +01:00
#include <algorithm>
2018-06-22 23:20:47 +02:00
#include <openrct2/Context.h>
2018-06-02 14:34:01 +01:00
#include <openrct2/Editor.h>
#include <openrct2/Game.h>
2019-07-21 10:33:15 +01:00
#include <openrct2/GameState.h>
2018-06-02 14:34:01 +01:00
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/actions/BalloonPressAction.h>
#include <openrct2/actions/FootpathAdditionRemoveAction.h>
2022-08-11 00:00:58 +02:00
#include <openrct2/actions/FootpathRemoveAction.h>
#include <openrct2/actions/LargeSceneryRemoveAction.h>
#include <openrct2/actions/ParkEntranceRemoveAction.h>
#include <openrct2/actions/SmallSceneryRemoveAction.h>
#include <openrct2/actions/WallRemoveAction.h>
2021-11-24 16:48:33 +02:00
#include <openrct2/entity/Balloon.h>
#include <openrct2/entity/Duck.h>
2021-11-24 16:58:01 +02:00
#include <openrct2/entity/EntityRegistry.h>
2021-11-25 23:47:24 +02:00
#include <openrct2/entity/Staff.h>
2021-12-11 18:06:06 -05:00
#include <openrct2/localisation/Formatter.h>
2018-06-22 23:20:47 +02:00
#include <openrct2/localisation/Localisation.h>
2018-06-02 14:34:01 +01:00
#include <openrct2/ride/Ride.h>
2021-12-18 19:50:29 +01:00
#include <openrct2/ride/RideConstruction.h>
2018-06-02 14:34:01 +01:00
#include <openrct2/ride/RideData.h>
#include <openrct2/ride/Track.h>
2021-05-29 06:01:32 +01:00
#include <openrct2/ride/Vehicle.h>
2018-06-02 14:34:01 +01:00
#include <openrct2/scenario/Scenario.h>
#include <openrct2/windows/Intent.h>
#include <openrct2/world/Banner.h>
#include <openrct2/world/Footpath.h>
#include <openrct2/world/LargeScenery.h>
2018-06-22 23:20:47 +02:00
#include <openrct2/world/Map.h>
2018-06-02 14:34:01 +01:00
#include <openrct2/world/Park.h>
2018-06-22 23:20:47 +02:00
#include <openrct2/world/Scenery.h>
2018-06-02 14:34:01 +01:00
#include <openrct2/world/Surface.h>
#include <openrct2/world/Wall.h>
2014-11-05 19:42:19 +00:00
static void ViewportInteractionRemoveScenery(TileElement* tileElement, const CoordsXY& mapCoords);
static void ViewportInteractionRemoveFootpath(TileElement* tileElement, const CoordsXY& mapCoords);
static void ViewportInteractionRemoveFootpathItem(TileElement* tileElement, const CoordsXY& mapCoords);
static void ViewportInteractionRemoveParkWall(TileElement* tileElement, const CoordsXY& mapCoords);
static void ViewportInteractionRemoveLargeScenery(TileElement* tileElement, const CoordsXY& mapCoords);
static void ViewportInteractionRemoveParkEntrance(TileElement* tileElement, CoordsXY mapCoords);
static Peep* ViewportInteractionGetClosestPeep(ScreenCoordsXY screenCoords, int32_t maxDistance);
2014-11-05 19:42:19 +00:00
/**
*
* rct2: 0x006ED9D0
*/
InteractionInfo ViewportInteractionGetItemLeft(const ScreenCoordsXY& screenCoords)
{
2020-08-02 08:32:59 +01:00
InteractionInfo info{};
// No click input for scenario editor or track manager
if (gScreenFlags & (SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_MANAGER))
2020-08-02 08:32:59 +01:00
return info;
2017-06-06 23:24:18 +02:00
//
2021-04-05 18:01:43 +01:00
if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && gEditorStep != EditorStep::RollercoasterDesigner)
2020-08-02 08:32:59 +01:00
return info;
2023-01-16 21:14:50 +01:00
info = GetMapCoordinatesFromPos(
screenCoords,
EnumsToFlags(ViewportInteractionItem::Entity, ViewportInteractionItem::Ride, ViewportInteractionItem::ParkEntrance));
auto tileElement = info.SpriteType != ViewportInteractionItem::Entity ? info.Element : nullptr;
// Only valid when info.SpriteType == ViewportInteractionItem::Entity, but can't assign nullptr without compiler
2020-08-09 08:27:26 +02:00
// complaining
auto sprite = info.Entity;
// Allows only balloons to be popped and ducks to be quacked in title screen
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
{
if (info.SpriteType == ViewportInteractionItem::Entity && (sprite->Is<Balloon>() || sprite->Is<Duck>()))
2020-08-02 08:32:59 +01:00
return info;
2021-09-15 22:22:15 +02:00
info.SpriteType = ViewportInteractionItem::None;
return info;
}
2020-08-02 08:32:59 +01:00
switch (info.SpriteType)
2018-06-22 23:20:47 +02:00
{
case ViewportInteractionItem::Entity:
switch (sprite->Type)
2018-06-22 23:20:47 +02:00
{
case EntityType::Vehicle:
2020-08-01 11:29:54 +01:00
{
auto vehicle = sprite->As<Vehicle>();
2022-12-22 06:26:35 -05:00
if (vehicle != nullptr && !vehicle->IsCableLift())
vehicle->SetMapToolbar();
2018-06-22 23:20:47 +02:00
else
info.SpriteType = ViewportInteractionItem::None;
2020-08-01 11:29:54 +01:00
}
break;
case EntityType::Guest:
case EntityType::Staff:
2020-08-01 11:29:54 +01:00
{
auto peep = sprite->As<Peep>();
if (peep != nullptr)
{
PeepSetMapTooltip(peep);
2020-08-01 11:29:54 +01:00
}
else
{
info.SpriteType = ViewportInteractionItem::None;
2020-08-01 11:29:54 +01:00
}
}
break;
default:
break;
2018-06-22 23:20:47 +02:00
}
2017-06-06 23:24:18 +02:00
break;
case ViewportInteractionItem::Ride:
RideSetMapTooltip(tileElement);
2018-06-22 23:20:47 +02:00
break;
case ViewportInteractionItem::ParkEntrance:
2019-07-21 10:33:15 +01:00
{
auto& park = OpenRCT2::GetContext()->GetGameState()->GetPark();
auto parkName = park.Name.c_str();
auto ft = Formatter();
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_STRING);
ft.Add<const char*>(parkName);
SetMapTooltip(ft);
2018-06-22 23:20:47 +02:00
break;
2019-07-21 10:33:15 +01:00
}
2018-06-22 23:20:47 +02:00
default:
info.SpriteType = ViewportInteractionItem::None;
2017-06-06 23:24:18 +02:00
break;
}
2017-06-06 23:24:18 +02:00
// If nothing is under cursor, find a close by peep
if (info.SpriteType == ViewportInteractionItem::None)
2018-06-22 23:20:47 +02:00
{
auto peep = ViewportInteractionGetClosestPeep(screenCoords, 32);
2020-08-02 08:32:59 +01:00
if (peep != nullptr)
{
info.Entity = peep;
info.SpriteType = ViewportInteractionItem::Entity;
2020-08-02 08:32:59 +01:00
info.Loc.x = peep->x;
info.Loc.y = peep->y;
PeepSetMapTooltip(peep);
2020-08-02 08:32:59 +01:00
}
2017-06-06 23:24:18 +02:00
}
2020-08-02 08:32:59 +01:00
return info;
}
bool ViewportInteractionLeftOver(const ScreenCoordsXY& screenCoords)
{
auto info = ViewportInteractionGetItemLeft(screenCoords);
2020-08-02 08:32:59 +01:00
switch (info.SpriteType)
2018-06-22 23:20:47 +02:00
{
case ViewportInteractionItem::Entity:
case ViewportInteractionItem::Ride:
case ViewportInteractionItem::ParkEntrance:
2020-08-02 08:32:59 +01:00
return true;
2018-06-22 23:20:47 +02:00
default:
2020-08-02 08:32:59 +01:00
return false;
2017-06-06 23:24:18 +02:00
}
}
bool ViewportInteractionLeftClick(const ScreenCoordsXY& screenCoords)
{
auto info = ViewportInteractionGetItemLeft(screenCoords);
2020-08-02 08:32:59 +01:00
switch (info.SpriteType)
2018-06-22 23:20:47 +02:00
{
case ViewportInteractionItem::Entity:
2020-08-02 08:32:59 +01:00
{
auto entity = info.Entity;
switch (entity->Type)
2018-06-22 23:20:47 +02:00
{
case EntityType::Vehicle:
2018-06-22 23:20:47 +02:00
{
auto intent = Intent(WD_VEHICLE);
2023-01-17 20:46:55 +01:00
intent.PutExtra(INTENT_EXTRA_VEHICLE, entity);
2022-11-06 20:49:07 +00:00
ContextOpenIntent(&intent);
2017-06-06 23:24:18 +02:00
break;
}
case EntityType::Guest:
case EntityType::Staff:
2018-06-22 23:20:47 +02:00
{
auto intent = Intent(WindowClass::Peep);
2023-01-17 20:46:55 +01:00
intent.PutExtra(INTENT_EXTRA_PEEP, entity);
2022-11-06 20:49:07 +00:00
ContextOpenIntent(&intent);
2018-06-22 23:20:47 +02:00
break;
}
case EntityType::Balloon:
{
if (GameIsNotPaused())
2018-06-22 23:20:47 +02:00
{
auto balloonPress = BalloonPressAction(entity->sprite_index);
GameActions::Execute(&balloonPress);
}
}
break;
case EntityType::Duck:
{
if (GameIsNotPaused())
{
auto duck = entity->As<Duck>();
if (duck != nullptr)
{
2021-05-12 07:56:32 +01:00
duck->Press();
2018-06-22 23:20:47 +02:00
}
}
}
break;
default:
break;
2017-06-06 23:24:18 +02:00
}
2020-08-02 08:32:59 +01:00
return true;
}
case ViewportInteractionItem::Ride:
2018-06-22 23:20:47 +02:00
{
auto intent = Intent(WD_TRACK);
2023-01-17 20:46:55 +01:00
intent.PutExtra(INTENT_EXTRA_TILE_ELEMENT, info.Element);
2022-11-06 20:49:07 +00:00
ContextOpenIntent(&intent);
2018-06-22 23:20:47 +02:00
return true;
2017-06-06 23:24:18 +02:00
}
case ViewportInteractionItem::ParkEntrance:
2022-11-06 20:49:07 +00:00
ContextOpenWindow(WindowClass::ParkInformation);
2020-08-02 08:32:59 +01:00
return true;
2018-06-22 23:20:47 +02:00
default:
2020-08-02 08:32:59 +01:00
return false;
2017-06-06 23:24:18 +02:00
}
}
2014-11-05 19:42:19 +00:00
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006EDE88
*/
InteractionInfo ViewportInteractionGetItemRight(const ScreenCoordsXY& screenCoords)
2014-11-05 19:42:19 +00:00
{
2018-06-22 23:20:47 +02:00
Ride* ride;
int32_t i;
2020-08-02 08:32:59 +01:00
InteractionInfo info{};
2017-06-06 23:24:18 +02:00
// No click input for title screen or track manager
if (gScreenFlags & (SCREEN_FLAGS_TITLE_DEMO | SCREEN_FLAGS_TRACK_MANAGER))
2020-08-02 08:32:59 +01:00
return info;
2014-11-05 19:42:19 +00:00
2017-06-06 23:24:18 +02:00
//
2021-04-05 18:01:43 +01:00
if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && gEditorStep != EditorStep::RollercoasterDesigner)
2020-08-02 08:32:59 +01:00
return info;
2014-11-05 19:42:19 +00:00
2021-06-26 07:43:05 +03:00
constexpr auto flags = static_cast<int32_t>(
~EnumsToFlags(ViewportInteractionItem::Terrain, ViewportInteractionItem::Water));
2023-01-16 21:14:50 +01:00
info = GetMapCoordinatesFromPos(screenCoords, flags);
2020-08-02 08:32:59 +01:00
auto tileElement = info.Element;
2014-11-05 19:42:19 +00:00
2020-08-02 08:32:59 +01:00
switch (info.SpriteType)
2018-06-22 23:20:47 +02:00
{
case ViewportInteractionItem::Entity:
2020-08-01 11:29:54 +01:00
{
2020-08-02 08:32:59 +01:00
auto sprite = info.Entity;
if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || sprite->Type != EntityType::Vehicle)
2020-08-02 08:32:59 +01:00
{
info.SpriteType = ViewportInteractionItem::None;
2020-08-02 08:32:59 +01:00
return info;
}
2018-06-22 23:20:47 +02:00
2020-08-01 11:29:54 +01:00
auto vehicle = sprite->As<Vehicle>();
if (vehicle == nullptr)
{
info.SpriteType = ViewportInteractionItem::None;
2020-08-02 08:32:59 +01:00
return info;
2020-08-01 11:29:54 +01:00
}
ride = GetRide(vehicle->ride);
if (ride != nullptr && ride->status == RideStatus::Closed)
2018-06-22 23:20:47 +02:00
{
auto ft = Formatter();
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
ride->FormatNameTo(ft);
SetMapTooltip(ft);
2018-06-22 23:20:47 +02:00
}
2020-08-02 08:32:59 +01:00
return info;
2020-08-01 11:29:54 +01:00
}
case ViewportInteractionItem::Ride:
{
2018-06-22 23:20:47 +02:00
if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
2020-08-02 08:32:59 +01:00
{
info.SpriteType = ViewportInteractionItem::None;
2020-08-02 08:32:59 +01:00
return info;
}
2021-12-11 00:39:39 +01:00
if (tileElement->GetType() == TileElementType::Path)
2020-08-02 08:32:59 +01:00
{
info.SpriteType = ViewportInteractionItem::None;
2020-08-02 08:32:59 +01:00
return info;
}
2018-06-22 23:20:47 +02:00
ride = GetRide(tileElement->GetRideIndex());
if (ride == nullptr)
2020-08-02 08:32:59 +01:00
{
info.SpriteType = ViewportInteractionItem::None;
2020-08-02 08:32:59 +01:00
return info;
}
if (ride->status != RideStatus::Closed)
2020-08-02 08:32:59 +01:00
return info;
2018-06-22 23:20:47 +02:00
auto ft = Formatter();
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
2018-06-22 23:20:47 +02:00
2021-12-11 00:39:39 +01:00
if (tileElement->GetType() == TileElementType::Entrance)
2018-06-22 23:20:47 +02:00
{
2022-07-31 14:22:58 +02:00
StringId stringId;
2018-09-26 12:13:44 +02:00
if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE)
2018-06-22 23:20:47 +02:00
{
if (ride->num_stations > 1)
{
stringId = STR_RIDE_STATION_X_ENTRANCE;
}
else
{
stringId = STR_RIDE_ENTRANCE;
}
}
else
{
if (ride->num_stations > 1)
{
stringId = STR_RIDE_STATION_X_EXIT;
}
else
{
stringId = STR_RIDE_EXIT;
}
}
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(stringId);
2018-06-22 23:20:47 +02:00
}
2020-06-05 22:55:15 +02:00
else if (tileElement->AsTrack()->IsStation())
2018-06-22 23:20:47 +02:00
{
2022-07-31 14:22:58 +02:00
StringId stringId;
2018-06-22 23:20:47 +02:00
if (ride->num_stations > 1)
{
stringId = STR_RIDE_STATION_X;
}
else
{
stringId = STR_RIDE_STATION;
}
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(stringId);
2018-06-22 23:20:47 +02:00
}
else
{
// FIXME: Why does it *2 the value?
2022-10-12 06:35:20 +01:00
if (!gCheatsSandboxMode && !MapIsLocationOwned({ info.Loc, tileElement->GetBaseZ() * 2 }))
2018-06-22 23:20:47 +02:00
{
info.SpriteType = ViewportInteractionItem::None;
2020-08-02 08:32:59 +01:00
return info;
2018-06-22 23:20:47 +02:00
}
ride->FormatNameTo(ft);
2020-08-02 08:32:59 +01:00
return info;
2017-06-06 23:24:18 +02:00
}
2014-11-05 19:42:19 +00:00
ride->FormatNameTo(ft);
const auto& rtd = ride->GetRideTypeDescriptor();
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(GetRideComponentName(rtd.NameConvention.station).capitalised);
2018-09-23 11:55:37 +02:00
StationIndex::UnderlyingType stationIndex;
2021-12-11 00:39:39 +01:00
if (tileElement->GetType() == TileElementType::Entrance)
stationIndex = tileElement->AsEntrance()->GetStationIndex().ToUnderlying();
else
stationIndex = tileElement->AsTrack()->GetStationIndex().ToUnderlying();
2018-09-23 11:55:37 +02:00
2018-06-22 23:20:47 +02:00
for (i = stationIndex; i >= 0; i--)
if (ride->GetStations()[i].Start.IsNull())
2018-06-22 23:20:47 +02:00
stationIndex--;
stationIndex++;
ft.Add<uint16_t>(stationIndex);
SetMapTooltip(ft);
2020-08-02 08:32:59 +01:00
return info;
}
case ViewportInteractionItem::Wall:
{
auto* wallEntry = tileElement->AsWall()->GetEntry();
if (wallEntry->scrolling_mode != SCROLLING_MODE_NONE)
2018-06-22 23:20:47 +02:00
{
2019-07-25 17:51:22 +01:00
auto banner = tileElement->AsWall()->GetBanner();
2020-03-27 13:04:45 +01:00
if (banner != nullptr)
{
auto ft = Formatter();
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_BANNER_STRINGID_STRINGID);
banner->FormatTextTo(ft);
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
ft.Add<StringId>(wallEntry->name);
SetMapTooltip(ft);
2020-08-02 08:32:59 +01:00
return info;
2020-03-27 13:04:45 +01:00
}
2018-06-22 23:20:47 +02:00
}
break;
}
case ViewportInteractionItem::LargeScenery:
2021-06-04 02:14:41 +01:00
{
auto* sceneryEntry = tileElement->AsLargeScenery()->GetEntry();
if (sceneryEntry->scrolling_mode != SCROLLING_MODE_NONE)
2018-06-22 23:20:47 +02:00
{
2019-07-25 17:51:22 +01:00
auto banner = tileElement->AsLargeScenery()->GetBanner();
2020-03-27 13:04:45 +01:00
if (banner != nullptr)
{
auto ft = Formatter();
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_BANNER_STRINGID_STRINGID);
banner->FormatTextTo(ft);
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
ft.Add<StringId>(sceneryEntry->name);
SetMapTooltip(ft);
2020-08-02 08:32:59 +01:00
return info;
2020-03-27 13:04:45 +01:00
}
2018-06-22 23:20:47 +02:00
}
break;
2021-06-04 02:14:41 +01:00
}
case ViewportInteractionItem::Banner:
2019-07-21 15:16:44 +01:00
{
2019-07-25 17:51:22 +01:00
auto banner = tileElement->AsBanner()->GetBanner();
2021-07-27 10:25:58 +01:00
if (banner != nullptr)
{
auto* bannerEntry = GetBannerEntry(banner->type);
2014-11-05 19:42:19 +00:00
2021-07-27 10:25:58 +01:00
auto ft = Formatter();
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_BANNER_STRINGID_STRINGID);
2021-07-27 10:25:58 +01:00
banner->FormatTextTo(ft, /*addColour*/ true);
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
ft.Add<StringId>(bannerEntry->name);
2021-07-27 10:25:58 +01:00
SetMapTooltip(ft);
return info;
}
break;
2019-07-21 15:16:44 +01:00
}
2020-08-02 08:32:59 +01:00
default:
break;
2017-06-06 23:24:18 +02:00
}
2014-11-05 19:42:19 +00:00
if (!(InputTestFlag(INPUT_FLAG_6)) || !(InputTestFlag(INPUT_FLAG_TOOL_ACTIVE)))
2018-06-22 23:20:47 +02:00
{
if (WindowFindByClass(WindowClass::RideConstruction) == nullptr && WindowFindByClass(WindowClass::Footpath) == nullptr)
2018-06-22 23:20:47 +02:00
{
info.SpriteType = ViewportInteractionItem::None;
2020-08-02 08:32:59 +01:00
return info;
2017-06-06 23:24:18 +02:00
}
}
2014-11-05 19:42:19 +00:00
auto ft = Formatter();
2020-08-02 08:32:59 +01:00
switch (info.SpriteType)
2018-06-22 23:20:47 +02:00
{
case ViewportInteractionItem::Scenery:
2021-06-04 02:14:41 +01:00
{
auto* sceneryEntry = tileElement->AsSmallScenery()->GetEntry();
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
ft.Add<StringId>(sceneryEntry->name);
SetMapTooltip(ft);
2020-08-02 08:32:59 +01:00
return info;
2021-06-04 02:14:41 +01:00
}
case ViewportInteractionItem::Footpath:
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
2018-10-03 10:57:29 +02:00
if (tileElement->AsPath()->IsQueue())
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_QUEUE_LINE_MAP_TIP);
else
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_FOOTPATH_MAP_TIP);
SetMapTooltip(ft);
2020-08-02 08:32:59 +01:00
return info;
2014-11-05 19:42:19 +00:00
case ViewportInteractionItem::FootpathItem:
2021-06-03 21:23:00 +01:00
{
auto* pathAddEntry = tileElement->AsPath()->GetAdditionEntry();
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
2019-02-26 09:29:25 +00:00
if (tileElement->AsPath()->IsBroken())
2018-06-22 23:20:47 +02:00
{
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_BROKEN);
2018-06-22 23:20:47 +02:00
}
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(pathAddEntry != nullptr ? pathAddEntry->name : STR_NONE);
SetMapTooltip(ft);
2020-08-02 08:32:59 +01:00
return info;
2021-06-03 21:23:00 +01:00
}
case ViewportInteractionItem::ParkEntrance:
2018-06-22 23:20:47 +02:00
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode)
break;
2014-11-05 19:42:19 +00:00
2021-12-11 00:39:39 +01:00
if (tileElement->GetType() != TileElementType::Entrance)
2018-06-22 23:20:47 +02:00
break;
2014-11-05 19:42:19 +00:00
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
ft.Add<StringId>(STR_OBJECT_SELECTION_PARK_ENTRANCE);
SetMapTooltip(ft);
2020-08-02 08:32:59 +01:00
return info;
2018-06-22 23:20:47 +02:00
case ViewportInteractionItem::Wall:
{
auto* wallEntry = tileElement->AsWall()->GetEntry();
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
ft.Add<StringId>(wallEntry->name);
SetMapTooltip(ft);
2020-08-02 08:32:59 +01:00
return info;
}
case ViewportInteractionItem::LargeScenery:
2021-06-04 02:14:41 +01:00
{
auto* sceneryEntry = tileElement->AsLargeScenery()->GetEntry();
2022-07-31 14:22:58 +02:00
ft.Add<StringId>(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
ft.Add<StringId>(sceneryEntry->name);
SetMapTooltip(ft);
2020-08-02 08:32:59 +01:00
return info;
2021-06-04 02:14:41 +01:00
}
2020-08-02 08:32:59 +01:00
default:
break;
2017-06-06 23:24:18 +02:00
}
2014-11-05 19:42:19 +00:00
info.SpriteType = ViewportInteractionItem::None;
2020-08-02 08:32:59 +01:00
return info;
2014-11-05 19:42:19 +00:00
}
bool ViewportInteractionRightOver(const ScreenCoordsXY& screenCoords)
2014-11-05 19:42:19 +00:00
{
auto info = ViewportInteractionGetItemRight(screenCoords);
2014-11-05 19:42:19 +00:00
return info.SpriteType != ViewportInteractionItem::None;
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006E8A62
*/
bool ViewportInteractionRightClick(const ScreenCoordsXY& screenCoords)
2014-11-05 19:42:19 +00:00
{
2018-02-15 17:42:53 +01:00
CoordsXYE tileElement;
auto info = ViewportInteractionGetItemRight(screenCoords);
2014-11-05 19:42:19 +00:00
2020-08-02 08:32:59 +01:00
switch (info.SpriteType)
2018-06-22 23:20:47 +02:00
{
case ViewportInteractionItem::None:
case ViewportInteractionItem::Terrain:
case ViewportInteractionItem::Water:
case ViewportInteractionItem::Label:
2020-08-02 08:32:59 +01:00
return false;
case ViewportInteractionItem::Entity:
2020-08-02 08:32:59 +01:00
{
auto entity = info.Entity;
if (entity->Type == EntityType::Vehicle)
2019-08-09 18:29:34 +01:00
{
2020-08-02 08:32:59 +01:00
auto vehicle = entity->As<Vehicle>();
2020-08-01 11:29:54 +01:00
if (vehicle == nullptr)
{
break;
}
auto ride = GetRide(vehicle->ride);
2019-08-09 18:29:34 +01:00
if (ride != nullptr)
{
RideConstructionStart(*ride);
2019-08-09 18:29:34 +01:00
}
}
2020-08-02 08:32:59 +01:00
}
break;
case ViewportInteractionItem::Ride:
2020-08-02 08:32:59 +01:00
tileElement = { info.Loc, info.Element };
RideModify(tileElement);
2018-06-22 23:20:47 +02:00
break;
case ViewportInteractionItem::Scenery:
ViewportInteractionRemoveScenery(info.Element, info.Loc);
2018-06-22 23:20:47 +02:00
break;
case ViewportInteractionItem::Footpath:
ViewportInteractionRemoveFootpath(info.Element, info.Loc);
2018-06-22 23:20:47 +02:00
break;
case ViewportInteractionItem::FootpathItem:
ViewportInteractionRemoveFootpathItem(info.Element, info.Loc);
2018-06-22 23:20:47 +02:00
break;
case ViewportInteractionItem::ParkEntrance:
ViewportInteractionRemoveParkEntrance(info.Element, info.Loc);
2018-06-22 23:20:47 +02:00
break;
case ViewportInteractionItem::Wall:
ViewportInteractionRemoveParkWall(info.Element, info.Loc);
2018-06-22 23:20:47 +02:00
break;
case ViewportInteractionItem::LargeScenery:
ViewportInteractionRemoveLargeScenery(info.Element, info.Loc);
2018-06-22 23:20:47 +02:00
break;
case ViewportInteractionItem::Banner:
2022-11-06 20:49:07 +00:00
ContextOpenDetailWindow(WD_BANNER, info.Element->AsBanner()->GetIndex().ToUnderlying());
2018-06-22 23:20:47 +02:00
break;
2017-06-06 23:24:18 +02:00
}
2020-08-02 08:32:59 +01:00
return true;
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006E08D2
*/
static void ViewportInteractionRemoveScenery(TileElement* tileElement, const CoordsXY& mapCoords)
2014-11-05 19:42:19 +00:00
{
2019-01-03 02:20:35 +01:00
auto removeSceneryAction = SmallSceneryRemoveAction(
2019-12-22 22:14:02 +01:00
{ mapCoords.x, mapCoords.y, tileElement->GetBaseZ() }, tileElement->AsSmallScenery()->GetSceneryQuadrant(),
2018-12-22 18:11:08 +01:00
tileElement->AsSmallScenery()->GetEntryIndex());
GameActions::Execute(&removeSceneryAction);
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006A614A
*/
static void ViewportInteractionRemoveFootpath(TileElement* tileElement, const CoordsXY& mapCoords)
2014-11-05 19:42:19 +00:00
{
WindowBase* w;
2018-11-01 13:53:50 +01:00
TileElement* tileElement2;
2014-11-05 19:42:19 +00:00
2019-12-22 22:14:02 +01:00
auto z = tileElement->GetBaseZ();
2015-10-20 20:16:30 +02:00
w = WindowFindByClass(WindowClass::Footpath);
2018-01-07 21:43:07 +01:00
if (w != nullptr)
2022-10-04 07:51:27 +01:00
FootpathProvisionalUpdate();
2014-11-05 19:42:19 +00:00
tileElement2 = MapGetFirstElementAt(mapCoords);
if (tileElement2 == nullptr)
return;
2018-06-22 23:20:47 +02:00
do
{
2021-12-11 00:39:39 +01:00
if (tileElement2->GetType() == TileElementType::Path && tileElement2->GetBaseZ() == z)
2018-06-22 23:20:47 +02:00
{
2022-08-11 00:00:58 +02:00
auto action = FootpathRemoveAction({ mapCoords, z });
GameActions::Execute(&action);
2017-06-06 23:24:18 +02:00
break;
}
} while (!(tileElement2++)->IsLastForTile());
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006A61AB
*/
static void ViewportInteractionRemoveFootpathItem(TileElement* tileElement, const CoordsXY& mapCoords)
2014-11-05 19:42:19 +00:00
{
auto footpathAdditionRemoveAction = FootpathAdditionRemoveAction({ mapCoords.x, mapCoords.y, tileElement->GetBaseZ() });
GameActions::Execute(&footpathAdditionRemoveAction);
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x00666C0E
*/
void ViewportInteractionRemoveParkEntrance(TileElement* tileElement, CoordsXY mapCoords)
2014-11-05 19:42:19 +00:00
{
2018-09-14 11:14:19 +02:00
int32_t rotation = tileElement->GetDirectionWithOffset(1);
switch (tileElement->AsEntrance()->GetSequenceIndex())
2018-06-22 23:20:47 +02:00
{
case 1:
2019-11-25 23:08:31 -03:00
mapCoords += CoordsDirectionDelta[rotation];
2018-06-22 23:20:47 +02:00
break;
case 2:
2019-11-25 23:08:31 -03:00
mapCoords -= CoordsDirectionDelta[rotation];
2018-06-22 23:20:47 +02:00
break;
2017-06-06 23:24:18 +02:00
}
2019-12-22 22:14:02 +01:00
auto parkEntranceRemoveAction = ParkEntranceRemoveAction({ mapCoords.x, mapCoords.y, tileElement->GetBaseZ() });
2019-03-24 20:41:14 +00:00
GameActions::Execute(&parkEntranceRemoveAction);
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006E57A9
*/
static void ViewportInteractionRemoveParkWall(TileElement* tileElement, const CoordsXY& mapCoords)
2014-11-05 19:42:19 +00:00
{
auto* wallEntry = tileElement->AsWall()->GetEntry();
if (wallEntry->scrolling_mode != SCROLLING_MODE_NONE)
{
2022-11-06 20:49:07 +00:00
ContextOpenDetailWindow(WD_SIGN_SMALL, tileElement->AsWall()->GetBannerIndex().ToUnderlying());
}
else
{
2019-12-22 22:14:02 +01:00
CoordsXYZD wallLocation = { mapCoords.x, mapCoords.y, tileElement->GetBaseZ(), tileElement->GetDirection() };
2018-05-14 12:36:45 +02:00
auto wallRemoveAction = WallRemoveAction(wallLocation);
GameActions::Execute(&wallRemoveAction);
2017-06-06 23:24:18 +02:00
}
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006B88DC
*/
static void ViewportInteractionRemoveLargeScenery(TileElement* tileElement, const CoordsXY& mapCoords)
2014-11-05 19:42:19 +00:00
{
auto* sceneryEntry = tileElement->AsLargeScenery()->GetEntry();
2014-11-05 19:42:19 +00:00
if (sceneryEntry->scrolling_mode != SCROLLING_MODE_NONE)
{
2020-02-08 17:42:36 +01:00
auto bannerIndex = tileElement->AsLargeScenery()->GetBannerIndex();
2022-11-06 20:49:07 +00:00
ContextOpenDetailWindow(WD_SIGN, bannerIndex.ToUnderlying());
2018-06-22 23:20:47 +02:00
}
else
{
2019-01-03 02:20:35 +01:00
auto removeSceneryAction = LargeSceneryRemoveAction(
2019-12-22 22:14:02 +01:00
{ mapCoords.x, mapCoords.y, tileElement->GetBaseZ(), tileElement->GetDirection() },
2019-07-07 04:53:59 +03:00
tileElement->AsLargeScenery()->GetSequenceIndex());
2018-12-22 19:46:59 +01:00
GameActions::Execute(&removeSceneryAction);
2017-06-06 23:24:18 +02:00
}
}
struct PeepDistance
{
Peep* peep = nullptr;
int32_t distance = std::numeric_limits<decltype(distance)>::max();
};
template<typename T>
PeepDistance GetClosestPeep(const ScreenCoordsXY& viewportCoords, const int32_t maxDistance, PeepDistance goal)
{
2021-03-16 11:18:06 +00:00
for (auto peep : EntityList<T>())
{
if (peep->x == LOCATION_NULL)
continue;
auto distance = abs(((peep->SpriteRect.GetLeft() + peep->SpriteRect.GetRight()) / 2) - viewportCoords.x)
+ abs(((peep->SpriteRect.GetTop() + peep->SpriteRect.GetBottom()) / 2) - viewportCoords.y);
if (distance > maxDistance)
continue;
if (distance < goal.distance)
{
goal.peep = peep;
goal.distance = distance;
}
}
return goal;
}
static Peep* ViewportInteractionGetClosestPeep(ScreenCoordsXY screenCoords, int32_t maxDistance)
{
auto* w = WindowFindFromPoint(screenCoords);
2018-01-07 21:43:07 +01:00
if (w == nullptr)
return nullptr;
2015-10-20 20:16:30 +02:00
2022-03-04 02:46:37 +00:00
auto* viewport = w->viewport;
2021-09-29 20:04:56 +02:00
if (viewport == nullptr || viewport->zoom >= ZoomLevel{ 2 })
2018-01-07 21:43:07 +01:00
return nullptr;
auto viewportCoords = viewport->ScreenToViewportCoord(screenCoords);
2022-03-04 02:46:37 +00:00
PeepDistance goal;
2022-03-06 14:26:36 +00:00
if (!(viewport->flags & VIEWPORT_FLAG_HIDE_GUESTS))
2022-03-04 02:46:37 +00:00
goal = GetClosestPeep<Guest>(viewportCoords, maxDistance, goal);
2022-03-06 14:26:36 +00:00
if (!(viewport->flags & VIEWPORT_FLAG_HIDE_STAFF))
2022-03-04 02:46:37 +00:00
goal = GetClosestPeep<Staff>(viewportCoords, maxDistance, goal);
return goal.peep;
2015-04-21 18:19:11 +01:00
}
/**
*
* rct2: 0x0068A15E
*/
CoordsXY ViewportInteractionGetTileStartAtCursor(const ScreenCoordsXY& screenCoords)
2015-04-21 18:19:11 +01:00
{
WindowBase* window = WindowFindFromPoint(screenCoords);
if (window == nullptr || window->viewport == nullptr)
{
CoordsXY ret{};
ret.SetNull();
return ret;
}
2020-08-02 08:32:59 +01:00
auto viewport = window->viewport;
2023-01-16 21:14:50 +01:00
auto info = GetMapCoordinatesFromPosWindow(
window, screenCoords, EnumsToFlags(ViewportInteractionItem::Terrain, ViewportInteractionItem::Water));
2020-08-02 08:32:59 +01:00
auto initialPos = info.Loc;
2015-04-21 18:19:11 +01:00
if (info.SpriteType == ViewportInteractionItem::None)
2018-06-22 23:20:47 +02:00
{
initialPos.SetNull();
2019-11-14 19:09:27 -03:00
return initialPos;
2017-06-06 23:24:18 +02:00
}
2015-04-21 18:19:11 +01:00
2019-10-07 18:56:31 +01:00
int16_t waterHeight = 0;
if (info.SpriteType == ViewportInteractionItem::Water)
2018-06-22 23:20:47 +02:00
{
2020-08-02 08:32:59 +01:00
waterHeight = info.Element->AsSurface()->GetWaterHeight();
2017-06-06 23:24:18 +02:00
}
2015-04-21 18:19:11 +01:00
auto initialVPPos = viewport->ScreenToViewportCoord(screenCoords);
CoordsXY mapPos = initialPos + CoordsXY{ 16, 16 };
2015-04-21 18:19:11 +01:00
2018-06-22 23:20:47 +02:00
for (int32_t i = 0; i < 5; i++)
{
2019-10-07 18:56:31 +01:00
int16_t z = waterHeight;
if (info.SpriteType != ViewportInteractionItem::Water)
2018-06-22 23:20:47 +02:00
{
2022-10-12 06:35:20 +01:00
z = TileElementHeight(mapPos);
2017-06-06 23:24:18 +02:00
}
2023-01-16 21:14:50 +01:00
mapPos = ViewportPosToMapPos(initialVPPos, z);
mapPos.x = std::clamp(mapPos.x, initialPos.x, initialPos.x + 31);
mapPos.y = std::clamp(mapPos.y, initialPos.y, initialPos.y + 31);
2017-06-06 23:24:18 +02:00
}
2015-04-21 18:19:11 +01:00
return mapPos.ToTileStart();
}