2014-08-21 21:53:17 +02:00
|
|
|
|
/*****************************************************************************
|
2024-12-31 20:30:04 +01:00
|
|
|
|
* Copyright (c) 2014-2025 OpenRCT2 developers
|
2016-05-04 19:24:41 +02:00
|
|
|
|
*
|
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
|
2016-05-04 19:24:41 +02:00
|
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-05-04 19:24:41 +02:00
|
|
|
|
*****************************************************************************/
|
2014-08-21 21:53:17 +02:00
|
|
|
|
|
2023-02-08 16:54:58 -06:00
|
|
|
|
#include <deque>
|
2024-08-14 16:36:05 +02:00
|
|
|
|
#include <openrct2-ui/UiContext.h>
|
|
|
|
|
|
#include <openrct2-ui/input/InputManager.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
|
#include <openrct2-ui/interface/Dropdown.h>
|
2018-01-03 00:13:37 +01:00
|
|
|
|
#include <openrct2-ui/interface/Viewport.h>
|
2024-08-14 16:36:05 +02:00
|
|
|
|
#include <openrct2-ui/interface/ViewportInteraction.h>
|
2018-01-03 00:13:37 +01:00
|
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
2025-01-19 15:50:54 +01:00
|
|
|
|
#include <openrct2-ui/windows/Windows.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
|
#include <openrct2/Context.h>
|
2024-01-22 16:03:39 +01:00
|
|
|
|
#include <openrct2/GameState.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
|
#include <openrct2/Input.h>
|
2024-02-28 20:38:43 +01:00
|
|
|
|
#include <openrct2/OpenRCT2.h>
|
2025-02-13 10:51:46 -05:00
|
|
|
|
#include <openrct2/SpriteIds.h>
|
2024-07-29 13:37:09 +02:00
|
|
|
|
#include <openrct2/actions/BannerPlaceAction.h>
|
|
|
|
|
|
#include <openrct2/actions/BannerSetColourAction.h>
|
|
|
|
|
|
#include <openrct2/actions/FootpathAdditionPlaceAction.h>
|
|
|
|
|
|
#include <openrct2/actions/LargeSceneryPlaceAction.h>
|
|
|
|
|
|
#include <openrct2/actions/LargeScenerySetColourAction.h>
|
2024-02-28 20:38:43 +01:00
|
|
|
|
#include <openrct2/actions/ScenerySetRestrictedAction.h>
|
2024-07-29 13:37:09 +02:00
|
|
|
|
#include <openrct2/actions/SmallSceneryPlaceAction.h>
|
|
|
|
|
|
#include <openrct2/actions/SmallScenerySetColourAction.h>
|
|
|
|
|
|
#include <openrct2/actions/WallPlaceAction.h>
|
2025-11-16 17:14:20 +01:00
|
|
|
|
#include <openrct2/actions/WallRemoveAction.h>
|
2024-07-29 13:37:09 +02:00
|
|
|
|
#include <openrct2/actions/WallSetColourAction.h>
|
2025-02-17 07:24:03 -05:00
|
|
|
|
#include <openrct2/audio/Audio.h>
|
2024-07-08 22:21:38 +02:00
|
|
|
|
#include <openrct2/config/Config.h>
|
2018-10-29 14:52:07 -07:00
|
|
|
|
#include <openrct2/core/Guard.hpp>
|
2024-09-10 23:55:53 +02:00
|
|
|
|
#include <openrct2/core/String.hpp>
|
2025-10-23 18:44:45 +02:00
|
|
|
|
#include <openrct2/drawing/Rectangle.h>
|
2021-12-11 18:06:06 -05:00
|
|
|
|
#include <openrct2/localisation/Formatter.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
|
#include <openrct2/management/Research.h>
|
2025-02-24 04:43:06 -05:00
|
|
|
|
#include <openrct2/network/Network.h>
|
2023-01-25 19:56:29 +00:00
|
|
|
|
#include <openrct2/object/BannerSceneryEntry.h>
|
2023-01-26 18:44:42 +00:00
|
|
|
|
#include <openrct2/object/LargeSceneryEntry.h>
|
2023-02-12 20:43:11 +00:00
|
|
|
|
#include <openrct2/object/ObjectEntryManager.h>
|
2024-11-25 23:32:16 +09:00
|
|
|
|
#include <openrct2/object/ObjectLimits.h>
|
2018-01-02 20:36:42 +01:00
|
|
|
|
#include <openrct2/object/ObjectList.h>
|
2023-01-26 15:40:02 -06:00
|
|
|
|
#include <openrct2/object/ObjectManager.h>
|
|
|
|
|
|
#include <openrct2/object/ObjectRepository.h>
|
2023-05-09 21:08:25 +02:00
|
|
|
|
#include <openrct2/object/PathAdditionEntry.h>
|
2023-01-27 19:44:58 +00:00
|
|
|
|
#include <openrct2/object/SceneryGroupEntry.h>
|
2023-01-25 19:25:33 +00:00
|
|
|
|
#include <openrct2/object/SmallSceneryEntry.h>
|
2023-01-25 19:56:29 +00:00
|
|
|
|
#include <openrct2/object/WallSceneryEntry.h>
|
2024-07-29 13:37:09 +02:00
|
|
|
|
#include <openrct2/paint/VirtualFloor.h>
|
2025-01-08 21:12:11 +01:00
|
|
|
|
#include <openrct2/ui/WindowManager.h>
|
2024-12-15 17:39:52 +01:00
|
|
|
|
#include <openrct2/util/Util.h>
|
2024-10-15 22:02:31 +02:00
|
|
|
|
#include <openrct2/world/ConstructionClearance.h>
|
|
|
|
|
|
#include <openrct2/world/Footpath.h>
|
2025-09-04 21:57:41 +02:00
|
|
|
|
#include <openrct2/world/Map.h>
|
2025-09-04 21:18:12 +02:00
|
|
|
|
#include <openrct2/world/MapSelection.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
|
#include <openrct2/world/Park.h>
|
2018-01-11 10:59:26 +01:00
|
|
|
|
#include <openrct2/world/Scenery.h>
|
2024-10-14 14:26:10 +02:00
|
|
|
|
#include <openrct2/world/tile_element/BannerElement.h>
|
2024-10-15 22:02:31 +02:00
|
|
|
|
#include <openrct2/world/tile_element/LargeSceneryElement.h>
|
|
|
|
|
|
#include <openrct2/world/tile_element/PathElement.h>
|
|
|
|
|
|
#include <openrct2/world/tile_element/SmallSceneryElement.h>
|
|
|
|
|
|
#include <openrct2/world/tile_element/SurfaceElement.h>
|
2024-10-03 21:09:30 +01:00
|
|
|
|
#include <openrct2/world/tile_element/WallElement.h>
|
2015-03-29 02:29:07 +01:00
|
|
|
|
|
2025-10-21 12:20:00 +02:00
|
|
|
|
using namespace OpenRCT2::Drawing;
|
2025-12-11 00:12:21 +01:00
|
|
|
|
using OpenRCT2::GameActions::CommandFlag;
|
2025-10-21 12:20:00 +02:00
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
namespace OpenRCT2::Ui::Windows
|
2020-09-28 20:36:15 +02:00
|
|
|
|
{
|
2025-06-16 23:10:47 +02:00
|
|
|
|
static constexpr StringId kWindowTitle = kStringIdNone;
|
|
|
|
|
|
static constexpr ScreenSize kMinimumWindowSize = { 634, 195 - kTitleHeightNormal };
|
|
|
|
|
|
constexpr int32_t kSceneryButtonWidth = 66;
|
|
|
|
|
|
constexpr int32_t kSceneryButtonHeight = 80;
|
2025-05-02 22:56:56 +02:00
|
|
|
|
constexpr int32_t kDescriptionHeight = 24;
|
|
|
|
|
|
constexpr int32_t kInputMargin = 2;
|
|
|
|
|
|
constexpr int32_t kMaxWindowHeight = 473;
|
2025-04-11 23:26:34 +02:00
|
|
|
|
constexpr int32_t kTabMargin = 3;
|
2025-06-16 23:10:47 +02:00
|
|
|
|
constexpr int32_t kTabWidth = 31;
|
|
|
|
|
|
constexpr int32_t kTabHeight = 28;
|
|
|
|
|
|
constexpr int32_t kReservedTabCount = 2;
|
|
|
|
|
|
constexpr int32_t kMaxTabs = 257; // 255 selected tabs + misc + all
|
|
|
|
|
|
constexpr int32_t kMaxTabsPerRow = 20;
|
2014-08-21 21:53:17 +02:00
|
|
|
|
|
2025-06-16 23:10:47 +02:00
|
|
|
|
constexpr uint8_t kSceneryContentScrollIndex = 0;
|
2017-05-02 02:01:29 +02:00
|
|
|
|
|
2024-08-05 10:47:36 +02:00
|
|
|
|
enum WindowSceneryListWidgetIdx : WidgetIndex
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
WIDX_SCENERY_BACKGROUND,
|
|
|
|
|
|
WIDX_SCENERY_TITLE,
|
|
|
|
|
|
WIDX_SCENERY_CLOSE,
|
|
|
|
|
|
WIDX_SCENERY_TAB_CONTENT_PANEL,
|
|
|
|
|
|
WIDX_SCENERY_LIST,
|
|
|
|
|
|
WIDX_SCENERY_ROTATE_OBJECTS_BUTTON,
|
|
|
|
|
|
WIDX_SCENERY_REPAINT_SCENERY_BUTTON,
|
|
|
|
|
|
WIDX_SCENERY_PRIMARY_COLOUR_BUTTON,
|
|
|
|
|
|
WIDX_SCENERY_SECONDARY_COLOUR_BUTTON,
|
|
|
|
|
|
WIDX_SCENERY_TERTIARY_COLOUR_BUTTON,
|
|
|
|
|
|
WIDX_SCENERY_EYEDROPPER_BUTTON,
|
|
|
|
|
|
WIDX_SCENERY_BUILD_CLUSTER_BUTTON,
|
|
|
|
|
|
WIDX_FILTER_TEXT_BOX,
|
|
|
|
|
|
WIDX_FILTER_CLEAR_BUTTON,
|
|
|
|
|
|
WIDX_RESTRICT_SCENERY,
|
|
|
|
|
|
WIDX_SCENERY_TAB_1,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-17 23:50:28 +02:00
|
|
|
|
VALIDATE_GLOBAL_WIDX(WC_SCENERY, WIDX_SCENERY_BACKGROUND);
|
|
|
|
|
|
VALIDATE_GLOBAL_WIDX(WC_SCENERY, WIDX_SCENERY_TAB_1);
|
|
|
|
|
|
VALIDATE_GLOBAL_WIDX(WC_SCENERY, WIDX_SCENERY_ROTATE_OBJECTS_BUTTON);
|
|
|
|
|
|
VALIDATE_GLOBAL_WIDX(WC_SCENERY, WIDX_SCENERY_EYEDROPPER_BUTTON);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
// clang-format off
|
2025-06-07 23:02:14 +02:00
|
|
|
|
static constexpr auto WindowSceneryBaseWidgets = makeWidgets(
|
2025-06-16 23:10:47 +02:00
|
|
|
|
makeWindowShim(kWindowTitle, kMinimumWindowSize),
|
|
|
|
|
|
makeWidget({ 0, 43}, {634, 99}, WidgetType::resize, WindowColour::secondary ), // 8 0x009DE2C8
|
|
|
|
|
|
makeWidget({ 2, 62}, {607, 80}, WidgetType::scroll, WindowColour::secondary, SCROLL_VERTICAL ), // 1000000 0x009DE418
|
|
|
|
|
|
makeWidget({609, 59}, { 24, 24}, WidgetType::flatBtn, WindowColour::secondary, ImageId(SPR_ROTATE_ARROW), STR_ROTATE_OBJECTS_90 ), // 2000000 0x009DE428
|
|
|
|
|
|
makeWidget({609, 83}, { 24, 24}, WidgetType::flatBtn, WindowColour::secondary, ImageId(SPR_PAINTBRUSH), STR_SCENERY_PAINTBRUSH_TIP ), // 4000000 0x009DE438
|
|
|
|
|
|
makeWidget({615, 108}, { 12, 12}, WidgetType::colourBtn, WindowColour::secondary, 0xFFFFFFFF, STR_SELECT_COLOUR ), // 8000000 0x009DE448
|
|
|
|
|
|
makeWidget({615, 120}, { 12, 12}, WidgetType::colourBtn, WindowColour::secondary, 0xFFFFFFFF, STR_SELECT_SECONDARY_COLOUR), // 10000000 0x009DE458
|
|
|
|
|
|
makeWidget({615, 132}, { 12, 12}, WidgetType::colourBtn, WindowColour::secondary, 0xFFFFFFFF, STR_SELECT_TERTIARY_COLOUR ), // 20000000 0x009DE468
|
|
|
|
|
|
makeWidget({609, 145}, { 24, 24}, WidgetType::flatBtn, WindowColour::secondary, ImageId(SPR_G2_EYEDROPPER), STR_SCENERY_EYEDROPPER_TIP ), // 40000000 0x009DE478
|
|
|
|
|
|
makeWidget({609, 169}, { 24, 24}, WidgetType::flatBtn, WindowColour::secondary, ImageId(SPR_SCENERY_CLUSTER), STR_SCENERY_CLUSTER_TIP ), // 40000000 0x009DE478
|
|
|
|
|
|
makeWidget({ 4, 46}, {211, 14}, WidgetType::textBox, WindowColour::secondary ),
|
|
|
|
|
|
makeWidget({218, 46}, { 70, 14}, WidgetType::button, WindowColour::secondary, STR_OBJECT_SEARCH_CLEAR ),
|
|
|
|
|
|
makeWidget({539, 46}, { 70, 14}, WidgetType::button, WindowColour::secondary, STR_RESTRICT_SCENERY, STR_RESTRICT_SCENERY_TIP )
|
2025-06-07 23:02:14 +02:00
|
|
|
|
);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
// clang-format on
|
2014-08-21 21:53:17 +02:00
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
// Persistent between window instances
|
|
|
|
|
|
static size_t _activeTabIndex;
|
|
|
|
|
|
static std::vector<ScenerySelection> _tabSelections;
|
2022-04-14 20:36:04 +01:00
|
|
|
|
|
2024-07-29 14:33:43 +02:00
|
|
|
|
static bool _sceneryPaintEnabled;
|
|
|
|
|
|
static colour_t _sceneryPrimaryColour;
|
|
|
|
|
|
static colour_t _scenerySecondaryColour;
|
|
|
|
|
|
static colour_t _sceneryTertiaryColour;
|
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
uint8_t gWindowSceneryRotation;
|
|
|
|
|
|
bool gWindowSceneryEyedropperEnabled;
|
2021-09-30 17:47:49 +01:00
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
class SceneryWindow final : public Window
|
2023-02-22 17:31:21 -06:00
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
private:
|
|
|
|
|
|
enum SceneryTabType
|
2021-09-30 17:47:49 +01:00
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
SCENERY_TAB_TYPE_GROUP,
|
|
|
|
|
|
SCENERY_TAB_TYPE_MISC,
|
|
|
|
|
|
SCENERY_TAB_TYPE_ALL,
|
|
|
|
|
|
};
|
2023-02-22 17:31:21 -06:00
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
struct SceneryItem
|
2023-02-22 17:31:21 -06:00
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
int32_t allRows;
|
|
|
|
|
|
int32_t selected_item;
|
|
|
|
|
|
ScenerySelection scenerySelection;
|
|
|
|
|
|
};
|
2023-02-22 17:31:21 -06:00
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
struct SceneryTabInfo
|
2023-02-22 17:31:21 -06:00
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
SceneryTabType Type = SCENERY_TAB_TYPE_GROUP;
|
2025-01-22 17:16:55 +01:00
|
|
|
|
ObjectEntryIndex SceneryGroupIndex = kObjectEntryIndexNull;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
std::deque<ScenerySelection> Entries{};
|
|
|
|
|
|
u8string Filter = "";
|
2021-09-30 17:47:49 +01:00
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
bool IsMisc() const
|
2021-09-30 17:47:49 +01:00
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
return Type == SCENERY_TAB_TYPE_MISC;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IsAll() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return Type == SCENERY_TAB_TYPE_ALL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IsSceneryGroup() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return Type == SCENERY_TAB_TYPE_GROUP;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Contains(const ScenerySelection& entry) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return std::find(std::begin(Entries), std::end(Entries), entry) != std::end(Entries);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AddEntryToBack(const ScenerySelection& entry)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Contains(entry))
|
|
|
|
|
|
{
|
|
|
|
|
|
Entries.push_back(entry);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AddEntryToFront(const ScenerySelection& entry)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Contains(entry))
|
|
|
|
|
|
{
|
|
|
|
|
|
Entries.push_front(entry);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const SceneryGroupEntry* GetSceneryGroupEntry() const
|
|
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
return ObjectManager::GetObjectEntry<SceneryGroupEntry>(SceneryGroupIndex);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-16 17:14:20 +01:00
|
|
|
|
struct ProvisionalWallTile
|
|
|
|
|
|
{
|
|
|
|
|
|
CoordsXYZD location;
|
|
|
|
|
|
int32_t calculatedZ;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
std::vector<SceneryTabInfo> _tabEntries;
|
|
|
|
|
|
int32_t _requiredWidth;
|
|
|
|
|
|
int32_t _actualMinHeight;
|
|
|
|
|
|
ScenerySelection _selectedScenery;
|
|
|
|
|
|
int16_t _hoverCounter;
|
|
|
|
|
|
SceneryTabInfo _filteredSceneryTab;
|
|
|
|
|
|
|
2024-07-29 13:37:09 +02:00
|
|
|
|
uint8_t _unkF64F0E{ 0 };
|
|
|
|
|
|
int16_t _unkF64F0A{ 0 };
|
|
|
|
|
|
|
2025-11-16 17:14:20 +01:00
|
|
|
|
CoordsXY _dragStartPos{};
|
|
|
|
|
|
/**
|
|
|
|
|
|
* When placing fences in the air using Shift, the user may shift their mouse to the left or right.
|
|
|
|
|
|
* We save this position to avoid detecting a wall drag where there isn’t one.
|
|
|
|
|
|
*/
|
|
|
|
|
|
CoordsXY _dragStartHoverPos{};
|
|
|
|
|
|
CoordsXY _dragEndPos{};
|
|
|
|
|
|
uint8_t _startEdge{};
|
|
|
|
|
|
GameActions::Result _lastProvisionalError{};
|
|
|
|
|
|
bool _inDragMode = false;
|
|
|
|
|
|
std::vector<ProvisionalWallTile> _provisionalTiles{};
|
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
public:
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void onOpen() override
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
init();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
initScrollWidgets();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
ContentUpdateScroll();
|
|
|
|
|
|
ShowGridlines();
|
|
|
|
|
|
gWindowSceneryRotation = 3;
|
|
|
|
|
|
gSceneryCtrlPressed = false;
|
|
|
|
|
|
gSceneryShiftPressed = false;
|
|
|
|
|
|
_selectedScenery = {};
|
|
|
|
|
|
_hoverCounter = 0;
|
|
|
|
|
|
gSceneryGhostType = 0;
|
|
|
|
|
|
gSceneryPlaceCost = kMoney64Undefined;
|
|
|
|
|
|
gSceneryPlaceRotation = 0;
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_sceneryPaintEnabled = false; // repaint coloured scenery tool state
|
2024-03-10 13:52:35 +00:00
|
|
|
|
gWindowSceneryEyedropperEnabled = false;
|
|
|
|
|
|
|
2025-05-16 22:41:40 +01:00
|
|
|
|
_actualMinHeight = GetMinimumHeight();
|
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
width = GetRequiredWidth();
|
2025-09-17 19:03:29 +02:00
|
|
|
|
minWidth = width;
|
|
|
|
|
|
maxWidth = width;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
height = _actualMinHeight;
|
2025-09-17 19:03:29 +02:00
|
|
|
|
minHeight = height;
|
|
|
|
|
|
maxHeight = height;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (_activeTabIndex > _tabSelections.size())
|
|
|
|
|
|
{
|
|
|
|
|
|
_activeTabIndex = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WindowMovePosition(*this, { ContextGetWidth() - GetRequiredWidth(), 0x1D });
|
|
|
|
|
|
WindowPushOthersBelow(*this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void onClose() override
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
2025-11-16 17:14:20 +01:00
|
|
|
|
removeProvisionalTilesFromMap();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
HideGridlines();
|
2025-09-15 23:34:29 +02:00
|
|
|
|
ViewportSetVisibility(ViewportVisibility::standard);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
if (gWindowSceneryScatterEnabled)
|
2025-01-19 18:49:18 +01:00
|
|
|
|
{
|
|
|
|
|
|
auto* windowMgr = Ui::GetWindowManager();
|
2025-09-17 23:18:52 +02:00
|
|
|
|
windowMgr->CloseByClass(WindowClass::sceneryScatter);
|
2025-01-19 18:49:18 +01:00
|
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2025-09-17 23:18:52 +02:00
|
|
|
|
if (isToolActive(WindowClass::scenery))
|
2024-03-10 13:52:35 +00:00
|
|
|
|
ToolCancel();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void onMouseUp(WidgetIndex widgetIndex) override
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-01-19 18:49:18 +01:00
|
|
|
|
auto* windowMgr = Ui::GetWindowManager();
|
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
switch (widgetIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
case WIDX_SCENERY_CLOSE:
|
2025-09-17 20:10:06 +02:00
|
|
|
|
close();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case WIDX_SCENERY_ROTATE_OBJECTS_BUTTON:
|
|
|
|
|
|
gWindowSceneryRotation++;
|
|
|
|
|
|
gWindowSceneryRotation = gWindowSceneryRotation % 4;
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case WIDX_SCENERY_REPAINT_SCENERY_BUTTON:
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_sceneryPaintEnabled ^= true;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
gWindowSceneryEyedropperEnabled = false;
|
|
|
|
|
|
if (gWindowSceneryScatterEnabled)
|
2025-09-17 23:18:52 +02:00
|
|
|
|
windowMgr->CloseByClass(WindowClass::sceneryScatter);
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case WIDX_SCENERY_EYEDROPPER_BUTTON:
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_sceneryPaintEnabled = false;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
gWindowSceneryEyedropperEnabled = !gWindowSceneryEyedropperEnabled;
|
|
|
|
|
|
if (gWindowSceneryScatterEnabled)
|
2025-09-17 23:18:52 +02:00
|
|
|
|
windowMgr->CloseByClass(WindowClass::sceneryScatter);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case WIDX_SCENERY_BUILD_CLUSTER_BUTTON:
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_sceneryPaintEnabled = false;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
gWindowSceneryEyedropperEnabled = false;
|
|
|
|
|
|
if (gWindowSceneryScatterEnabled)
|
2025-09-17 23:18:52 +02:00
|
|
|
|
windowMgr->CloseByClass(WindowClass::sceneryScatter);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
else if (
|
2025-08-31 16:02:43 +02:00
|
|
|
|
Network::GetMode() != Network::Mode::client
|
|
|
|
|
|
|| Network::CanPerformCommand(Network::GetCurrentPlayerGroupIndex(), -2))
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2024-03-17 02:37:46 -04:00
|
|
|
|
SceneryScatterOpen();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ContextShowError(STR_CANT_DO_THIS, STR_PERMISSION_DENIED, {});
|
|
|
|
|
|
}
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case WIDX_FILTER_TEXT_BOX:
|
2024-03-22 08:53:22 +00:00
|
|
|
|
WindowStartTextbox(*this, widgetIndex, _filteredSceneryTab.Filter, kTextInputSize);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case WIDX_FILTER_CLEAR_BUTTON:
|
|
|
|
|
|
_tabEntries[_activeTabIndex].Filter.clear();
|
|
|
|
|
|
ContentUpdateScroll();
|
2024-08-11 16:21:53 +02:00
|
|
|
|
scrolls->contentOffsetY = 0;
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case WIDX_RESTRICT_SCENERY:
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto tabIndex = _activeTabIndex;
|
|
|
|
|
|
const auto tabSelectedScenery = GetSelectedScenery(tabIndex);
|
|
|
|
|
|
if (!tabSelectedScenery.IsUndefined())
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto newStatus = !IsSceneryItemRestricted(tabSelectedScenery);
|
|
|
|
|
|
const auto objectType = GetObjectTypeFromSceneryType(tabSelectedScenery.SceneryType);
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto action = GameActions::ScenerySetRestrictedAction(
|
|
|
|
|
|
objectType, tabSelectedScenery.EntryIndex, newStatus);
|
2025-09-08 16:21:29 +02:00
|
|
|
|
GameActions::Execute(&action, getGameState());
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-08-31 21:21:30 +02:00
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void onResize() override
|
2023-02-08 16:54:58 -06:00
|
|
|
|
{
|
2025-09-17 19:03:29 +02:00
|
|
|
|
if (width < minWidth)
|
2023-02-08 16:54:58 -06:00
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2025-09-17 19:03:29 +02:00
|
|
|
|
width = minWidth;
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2023-02-08 16:54:58 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 19:03:29 +02:00
|
|
|
|
if (width > maxWidth)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2025-09-17 19:03:29 +02:00
|
|
|
|
width = maxWidth;
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 19:03:29 +02:00
|
|
|
|
if (height < minHeight)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2025-09-17 19:03:29 +02:00
|
|
|
|
height = minHeight;
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
// HACK: For some reason invalidate has not been called
|
2025-09-17 20:10:06 +02:00
|
|
|
|
onPrepareDraw();
|
2023-01-26 15:40:02 -06:00
|
|
|
|
ContentUpdateScroll();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 19:03:29 +02:00
|
|
|
|
if (height > maxHeight)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2025-09-17 19:03:29 +02:00
|
|
|
|
height = maxHeight;
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
// HACK: For some reason invalidate has not been called
|
2025-09-17 20:10:06 +02:00
|
|
|
|
onPrepareDraw();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
ContentUpdateScroll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
resizeFrame();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void onMouseDown(WidgetIndex widgetIndex) override
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
switch (widgetIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
case WIDX_SCENERY_PRIMARY_COLOUR_BUTTON:
|
2024-07-29 14:33:43 +02:00
|
|
|
|
WindowDropdownShowColour(this, &widgets[widgetIndex], colours[1], _sceneryPrimaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case WIDX_SCENERY_SECONDARY_COLOUR_BUTTON:
|
2024-07-29 14:33:43 +02:00
|
|
|
|
WindowDropdownShowColour(this, &widgets[widgetIndex], colours[1], _scenerySecondaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case WIDX_SCENERY_TERTIARY_COLOUR_BUTTON:
|
2024-07-29 14:33:43 +02:00
|
|
|
|
WindowDropdownShowColour(this, &widgets[widgetIndex], colours[1], _sceneryTertiaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (widgetIndex >= WIDX_SCENERY_TAB_1)
|
|
|
|
|
|
{
|
|
|
|
|
|
_activeTabIndex = widgetIndex - WIDX_SCENERY_TAB_1;
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
gSceneryPlaceCost = kMoney64Undefined;
|
|
|
|
|
|
|
|
|
|
|
|
ContentUpdateScroll();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void onDropdown(WidgetIndex widgetIndex, int32_t dropdownIndex) override
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (dropdownIndex == -1)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (widgetIndex == WIDX_SCENERY_PRIMARY_COLOUR_BUTTON)
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_sceneryPrimaryColour = ColourDropDownIndexToColour(dropdownIndex);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (widgetIndex == WIDX_SCENERY_SECONDARY_COLOUR_BUTTON)
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_scenerySecondaryColour = ColourDropDownIndexToColour(dropdownIndex);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (widgetIndex == WIDX_SCENERY_TERTIARY_COLOUR_BUTTON)
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_sceneryTertiaryColour = ColourDropDownIndexToColour(dropdownIndex);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void onPeriodicUpdate() override
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (!_selectedScenery.IsUndefined())
|
|
|
|
|
|
{
|
|
|
|
|
|
// Find out what scenery the cursor is over
|
|
|
|
|
|
const CursorState* state = ContextGetCursorState();
|
2025-01-08 21:12:11 +01:00
|
|
|
|
|
2025-01-19 10:58:28 +01:00
|
|
|
|
auto* windowMgr = GetWindowManager();
|
2025-01-08 21:12:11 +01:00
|
|
|
|
WidgetIndex widgetIndex = windowMgr->FindWidgetFromPoint(*this, state->position);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (widgetIndex == WIDX_SCENERY_LIST)
|
|
|
|
|
|
{
|
|
|
|
|
|
ScreenCoordsXY scrollPos = {};
|
|
|
|
|
|
int32_t scrollArea = 0;
|
|
|
|
|
|
int32_t scrollId = 0;
|
2025-06-10 21:57:53 +02:00
|
|
|
|
widgetScrollGetPart(*this, &widgets[WIDX_SCENERY_LIST], state->position, scrollPos, &scrollArea, &scrollId);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (scrollArea == SCROLL_PART_VIEW)
|
|
|
|
|
|
{
|
|
|
|
|
|
const ScenerySelection scenery = GetSceneryIdByCursorPos(scrollPos);
|
|
|
|
|
|
if (scenery == _selectedScenery)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Cursor was not over the currently hover selected scenery so reset hover selection.
|
|
|
|
|
|
// This will happen when the mouse leaves the scroll window and is required so that the cost and description
|
|
|
|
|
|
// switch to the tool scenery selection.
|
|
|
|
|
|
_selectedScenery = {};
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void onUpdate() override
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
const CursorState* state = ContextGetCursorState();
|
2025-01-08 21:12:11 +01:00
|
|
|
|
|
2025-01-19 10:58:28 +01:00
|
|
|
|
auto* windowMgr = GetWindowManager();
|
2025-01-08 21:12:11 +01:00
|
|
|
|
WindowBase* other = windowMgr->FindFromPoint(state->position);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (other == this)
|
|
|
|
|
|
{
|
|
|
|
|
|
ScreenCoordsXY window = state->position - ScreenCoordsXY{ windowPos.x - 26, windowPos.y };
|
|
|
|
|
|
|
|
|
|
|
|
if (window.y < 44 || window.x <= width)
|
|
|
|
|
|
{
|
2025-01-08 21:12:11 +01:00
|
|
|
|
WidgetIndex widgetIndex = windowMgr->FindWidgetFromPoint(*this, state->position);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (widgetIndex >= WIDX_SCENERY_TAB_CONTENT_PANEL)
|
|
|
|
|
|
{
|
|
|
|
|
|
_hoverCounter++;
|
|
|
|
|
|
if (_hoverCounter < 8)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (InputGetState() != InputState::ScrollLeft)
|
|
|
|
|
|
{
|
2025-09-17 19:03:29 +02:00
|
|
|
|
minHeight = _actualMinHeight;
|
|
|
|
|
|
maxHeight = _actualMinHeight;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto& listWidget = widgets[WIDX_SCENERY_LIST];
|
2025-05-02 22:56:56 +02:00
|
|
|
|
const auto nonListHeight = height - listWidget.height() + 2;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
const auto numRows = static_cast<int32_t>(CountRows());
|
2025-06-16 23:10:47 +02:00
|
|
|
|
const auto maxContentHeight = numRows * kSceneryButtonHeight;
|
2025-05-02 22:56:56 +02:00
|
|
|
|
const auto expandedWindowHeight = maxContentHeight + nonListHeight;
|
|
|
|
|
|
const auto windowHeight = std::clamp(expandedWindowHeight, _actualMinHeight, kMaxWindowHeight);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2025-09-17 19:03:29 +02:00
|
|
|
|
minHeight = windowHeight;
|
|
|
|
|
|
maxHeight = windowHeight;
|
2025-05-16 22:41:40 +01:00
|
|
|
|
|
2025-09-17 19:03:29 +02:00
|
|
|
|
if (height < minHeight)
|
2025-05-16 22:41:40 +01:00
|
|
|
|
{
|
2025-09-17 19:03:29 +02:00
|
|
|
|
height = minHeight;
|
2025-09-17 20:10:06 +02:00
|
|
|
|
onPrepareDraw();
|
2025-05-16 22:41:40 +01:00
|
|
|
|
ContentUpdateScroll();
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2025-05-16 22:41:40 +01:00
|
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_hoverCounter = 0;
|
|
|
|
|
|
if (InputGetState() != InputState::ScrollLeft)
|
|
|
|
|
|
{
|
2025-09-17 19:03:29 +02:00
|
|
|
|
minHeight = _actualMinHeight;
|
|
|
|
|
|
maxHeight = _actualMinHeight;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 19:03:29 +02:00
|
|
|
|
if (height > maxHeight)
|
2025-05-16 22:41:40 +01:00
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2025-09-17 19:03:29 +02:00
|
|
|
|
height = maxHeight;
|
2025-09-17 20:10:06 +02:00
|
|
|
|
onPrepareDraw();
|
2025-05-16 22:41:40 +01:00
|
|
|
|
ContentUpdateScroll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-22 08:43:42 +00:00
|
|
|
|
if (GetCurrentTextBox().window.classification == classification && GetCurrentTextBox().window.number == number)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
WindowUpdateTextboxCaret();
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidateWidget(WIDX_FILTER_TEXT_BOX);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 23:18:52 +02:00
|
|
|
|
if (!isToolActive(WindowClass::scenery))
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-11-25 21:52:39 +01:00
|
|
|
|
if (_inDragMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
removeProvisionalTilesFromMap();
|
|
|
|
|
|
_provisionalTiles.clear();
|
|
|
|
|
|
_inDragMode = false;
|
|
|
|
|
|
|
|
|
|
|
|
ToolSet(*this, WIDX_SCENERY_BACKGROUND, Tool::arrow);
|
|
|
|
|
|
gInputFlags.set(InputFlag::unk6);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (gWindowSceneryEyedropperEnabled)
|
|
|
|
|
|
{
|
2025-03-01 15:56:36 +01:00
|
|
|
|
gCurrentToolId = Tool::crosshair;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
2024-07-29 14:33:43 +02:00
|
|
|
|
else if (_sceneryPaintEnabled)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-03-01 15:56:36 +01:00
|
|
|
|
gCurrentToolId = Tool::paintDown;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2024-02-28 20:38:43 +01:00
|
|
|
|
{
|
|
|
|
|
|
const auto tabIndex = _activeTabIndex;
|
|
|
|
|
|
const auto tabSelectedScenery = GetSelectedScenery(tabIndex);
|
|
|
|
|
|
if (!tabSelectedScenery.IsUndefined())
|
|
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (tabSelectedScenery.SceneryType == SCENERY_TYPE_BANNER)
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2025-03-01 15:56:36 +01:00
|
|
|
|
gCurrentToolId = Tool::entranceDown;
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
|
else if (tabSelectedScenery.SceneryType == SCENERY_TYPE_LARGE)
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
gCurrentToolId = static_cast<Tool>(
|
2025-08-26 15:55:26 +02:00
|
|
|
|
ObjectManager::GetObjectEntry<LargeSceneryEntry>(tabSelectedScenery.EntryIndex)->tool_id);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (tabSelectedScenery.SceneryType == SCENERY_TYPE_WALL)
|
|
|
|
|
|
{
|
|
|
|
|
|
gCurrentToolId = static_cast<Tool>(
|
2025-08-26 15:55:26 +02:00
|
|
|
|
ObjectManager::GetObjectEntry<WallSceneryEntry>(tabSelectedScenery.EntryIndex)->tool_id);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (tabSelectedScenery.SceneryType == SCENERY_TYPE_PATH_ITEM)
|
|
|
|
|
|
{
|
|
|
|
|
|
gCurrentToolId = static_cast<Tool>(
|
2025-08-26 15:55:26 +02:00
|
|
|
|
ObjectManager::GetObjectEntry<PathAdditionEntry>(tabSelectedScenery.EntryIndex)->tool_id);
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{ // small scenery
|
|
|
|
|
|
gCurrentToolId = static_cast<Tool>(
|
2025-08-26 15:55:26 +02:00
|
|
|
|
ObjectManager::GetObjectEntry<SmallSceneryEntry>(tabSelectedScenery.EntryIndex)->tool_id);
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-03-01 15:56:36 +01:00
|
|
|
|
gCurrentToolId = Tool::arrow;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void onTextInput(WidgetIndex widgetIndex, std::string_view text) override
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (widgetIndex != WIDX_FILTER_TEXT_BOX)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (text == _tabEntries[_activeTabIndex].Filter)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
_tabEntries[_activeTabIndex].Filter.assign(text);
|
|
|
|
|
|
ContentUpdateScroll();
|
|
|
|
|
|
|
2024-08-11 16:21:53 +02:00
|
|
|
|
scrolls->contentOffsetY = 0;
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
OpenRCT2String onTooltip(const WidgetIndex widgetIndex, const StringId fallback) override
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (widgetIndex >= WIDX_SCENERY_TAB_1)
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto tabIndex = static_cast<size_t>(widgetIndex - WIDX_SCENERY_TAB_1);
|
|
|
|
|
|
if (_tabEntries.size() > tabIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto& tabInfo = _tabEntries[tabIndex];
|
|
|
|
|
|
if (tabInfo.IsMisc())
|
|
|
|
|
|
{
|
|
|
|
|
|
auto ft = Formatter();
|
|
|
|
|
|
ft.Add<StringId>(STR_MISCELLANEOUS);
|
|
|
|
|
|
return { fallback, ft };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tabInfo.IsAll())
|
|
|
|
|
|
{
|
|
|
|
|
|
auto ft = Formatter();
|
|
|
|
|
|
ft.Add<StringId>(STR_ALL_SCENERY);
|
|
|
|
|
|
return { fallback, ft };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const auto* sceneryEntry = tabInfo.GetSceneryGroupEntry();
|
|
|
|
|
|
if (sceneryEntry != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto ft = Formatter();
|
|
|
|
|
|
ft.Add<StringId>(sceneryEntry->name);
|
|
|
|
|
|
return { fallback, ft };
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-01-19 16:59:45 +01:00
|
|
|
|
return { kStringIdNone, Formatter() };
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void onPrepareDraw() override
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2025-05-16 22:41:40 +01:00
|
|
|
|
_actualMinHeight = GetMinimumHeight();
|
2025-04-11 20:37:54 +02:00
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
// Set the window title
|
|
|
|
|
|
StringId titleStringId = STR_MISCELLANEOUS;
|
2022-04-14 20:36:04 +01:00
|
|
|
|
const auto tabIndex = _activeTabIndex;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (tabIndex < _tabEntries.size())
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto& tabInfo = _tabEntries[tabIndex];
|
|
|
|
|
|
if (tabInfo.IsAll())
|
|
|
|
|
|
{
|
|
|
|
|
|
titleStringId = STR_ALL_SCENERY;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto* sgEntry = tabInfo.GetSceneryGroupEntry();
|
|
|
|
|
|
if (sgEntry != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
titleStringId = sgEntry->name;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
widgets[WIDX_SCENERY_TITLE].text = titleStringId;
|
|
|
|
|
|
widgets[WIDX_FILTER_TEXT_BOX].string = _filteredSceneryTab.Filter.data();
|
|
|
|
|
|
|
2025-09-17 19:03:29 +02:00
|
|
|
|
pressedWidgets = 0;
|
|
|
|
|
|
pressedWidgets |= 1uLL << (tabIndex + WIDX_SCENERY_TAB_1);
|
2024-07-29 14:33:43 +02:00
|
|
|
|
if (_sceneryPaintEnabled)
|
2025-09-17 19:03:29 +02:00
|
|
|
|
pressedWidgets |= (1uLL << WIDX_SCENERY_REPAINT_SCENERY_BUTTON);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (gWindowSceneryEyedropperEnabled)
|
2025-09-17 19:03:29 +02:00
|
|
|
|
pressedWidgets |= (1uLL << WIDX_SCENERY_EYEDROPPER_BUTTON);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (gWindowSceneryScatterEnabled)
|
2025-09-17 19:03:29 +02:00
|
|
|
|
pressedWidgets |= (1uLL << WIDX_SCENERY_BUILD_CLUSTER_BUTTON);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].type = WidgetType::empty;
|
|
|
|
|
|
widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].type = WidgetType::empty;
|
|
|
|
|
|
widgets[WIDX_RESTRICT_SCENERY].type = WidgetType::empty;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2022-03-04 07:17:20 +00:00
|
|
|
|
const auto tabSelectedScenery = GetSelectedScenery(tabIndex);
|
|
|
|
|
|
if (!tabSelectedScenery.IsUndefined())
|
|
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (tabSelectedScenery.SceneryType == SCENERY_TYPE_SMALL)
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].type = WidgetType::flatBtn;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto* sceneryEntry = ObjectManager::GetObjectEntry<SmallSceneryEntry>(tabSelectedScenery.EntryIndex);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_ROTATABLE))
|
|
|
|
|
|
{
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].type = WidgetType::flatBtn;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
|
else if (tabSelectedScenery.SceneryType >= SCENERY_TYPE_LARGE)
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].type = WidgetType::flatBtn;
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
2024-02-28 20:38:43 +01:00
|
|
|
|
|
2025-03-20 19:47:53 +01:00
|
|
|
|
if (gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode)
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_RESTRICT_SCENERY].type = WidgetType::button;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (IsSceneryItemRestricted(tabSelectedScenery))
|
2025-09-17 19:03:29 +02:00
|
|
|
|
pressedWidgets |= (1uLL << WIDX_RESTRICT_SCENERY);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
else
|
2025-09-17 19:03:29 +02:00
|
|
|
|
pressedWidgets &= ~(1uLL << WIDX_RESTRICT_SCENERY);
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-10 21:57:53 +02:00
|
|
|
|
widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].image = getColourButtonImage(_sceneryPrimaryColour);
|
|
|
|
|
|
widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].image = getColourButtonImage(_scenerySecondaryColour);
|
|
|
|
|
|
widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].image = getColourButtonImage(_sceneryTertiaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WidgetType::empty;
|
|
|
|
|
|
widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].type = WidgetType::empty;
|
|
|
|
|
|
widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].type = WidgetType::empty;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2024-07-29 14:33:43 +02:00
|
|
|
|
if (_sceneryPaintEnabled)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{ // repaint coloured scenery tool is on
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WidgetType::colourBtn;
|
|
|
|
|
|
widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].type = WidgetType::colourBtn;
|
|
|
|
|
|
widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].type = WidgetType::colourBtn;
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
|
else if (!tabSelectedScenery.IsUndefined())
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (tabSelectedScenery.SceneryType == SCENERY_TYPE_BANNER)
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto* bannerEntry = ObjectManager::GetObjectEntry<BannerSceneryEntry>(tabSelectedScenery.EntryIndex);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (bannerEntry->flags & BANNER_ENTRY_FLAG_HAS_PRIMARY_COLOUR)
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WidgetType::colourBtn;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (tabSelectedScenery.SceneryType == SCENERY_TYPE_LARGE)
|
|
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto* sceneryEntry = ObjectManager::GetObjectEntry<LargeSceneryEntry>(tabSelectedScenery.EntryIndex);
|
2022-03-04 07:17:20 +00:00
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryEntry->flags & LARGE_SCENERY_FLAG_HAS_PRIMARY_COLOUR
|
|
|
|
|
|
&& !(sceneryEntry->flags & LARGE_SCENERY_FLAG_HIDE_PRIMARY_REMAP_BUTTON))
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WidgetType::colourBtn;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryEntry->flags & LARGE_SCENERY_FLAG_HAS_SECONDARY_COLOUR
|
|
|
|
|
|
&& !(sceneryEntry->flags & LARGE_SCENERY_FLAG_HIDE_SECONDARY_REMAP_BUTTON))
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].type = WidgetType::colourBtn;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryEntry->flags & LARGE_SCENERY_FLAG_HAS_TERTIARY_COLOUR)
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].type = WidgetType::colourBtn;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (tabSelectedScenery.SceneryType == SCENERY_TYPE_WALL)
|
|
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto* wallEntry = ObjectManager::GetObjectEntry<WallSceneryEntry>(tabSelectedScenery.EntryIndex);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (wallEntry->flags & (WALL_SCENERY_HAS_PRIMARY_COLOUR | WALL_SCENERY_HAS_GLASS))
|
|
|
|
|
|
{
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WidgetType::colourBtn;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
if (wallEntry->flags & WALL_SCENERY_HAS_SECONDARY_COLOUR)
|
|
|
|
|
|
{
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].type = WidgetType::colourBtn;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
if (wallEntry->flags2 & WALL_SCENERY_2_NO_SELECT_PRIMARY_COLOUR)
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WidgetType::empty;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (wallEntry->flags & WALL_SCENERY_HAS_TERTIARY_COLOUR)
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].type = WidgetType::colourBtn;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (tabSelectedScenery.SceneryType == SCENERY_TYPE_SMALL)
|
|
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto* sceneryEntry = ObjectManager::GetObjectEntry<SmallSceneryEntry>(tabSelectedScenery.EntryIndex);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR | SMALL_SCENERY_FLAG_HAS_GLASS))
|
|
|
|
|
|
{
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WidgetType::colourBtn;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HAS_SECONDARY_COLOUR))
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].type = WidgetType::colourBtn;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HAS_TERTIARY_COLOUR))
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].type = WidgetType::colourBtn;
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
auto windowWidth = width;
|
|
|
|
|
|
if (_tabEntries.size() > 0)
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2025-06-16 23:10:47 +02:00
|
|
|
|
const auto lastTabIndex = GetMaxTabCountInARow() == kMaxTabsPerRow ? kMaxTabsPerRow - 1
|
|
|
|
|
|
: _tabEntries.size() - 1;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
const auto lastTabWidget = &widgets[WIDX_SCENERY_TAB_1 + lastTabIndex];
|
|
|
|
|
|
windowWidth = std::max<int32_t>(windowWidth, lastTabWidget->right + 3);
|
2022-03-04 07:17:20 +00:00
|
|
|
|
|
2025-04-11 23:26:34 +02:00
|
|
|
|
auto tabTop = widgets[WIDX_SCENERY_TITLE].bottom + kTabMargin;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (GetSceneryTabInfoForMisc() != nullptr)
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
auto miscTabWidget = &widgets[WIDX_SCENERY_TAB_1 + _tabEntries.size() - 2];
|
2025-06-16 23:10:47 +02:00
|
|
|
|
miscTabWidget->left = windowWidth - 2 * kTabWidth - 6;
|
|
|
|
|
|
miscTabWidget->right = windowWidth - kTabWidth - 7;
|
2025-02-24 17:59:23 +01:00
|
|
|
|
miscTabWidget->top = tabTop;
|
2025-06-16 23:10:47 +02:00
|
|
|
|
miscTabWidget->bottom = tabTop + kTabHeight;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
2022-03-04 07:17:20 +00:00
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (_tabEntries.back().IsAll())
|
|
|
|
|
|
{
|
|
|
|
|
|
auto allTabWidget = &widgets[WIDX_SCENERY_TAB_1 + _tabEntries.size() - 1];
|
2025-06-16 23:10:47 +02:00
|
|
|
|
allTabWidget->left = windowWidth - kTabWidth - 6;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
allTabWidget->right = windowWidth - 7;
|
2025-02-24 17:59:23 +01:00
|
|
|
|
allTabWidget->top = tabTop;
|
2025-06-16 23:10:47 +02:00
|
|
|
|
allTabWidget->bottom = tabTop + kTabHeight;
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
resizeFrame();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
widgets[WIDX_SCENERY_LIST].right = windowWidth - 26;
|
2025-05-02 22:56:56 +02:00
|
|
|
|
widgets[WIDX_SCENERY_LIST].bottom = height - kDescriptionHeight;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].left = windowWidth - 25;
|
|
|
|
|
|
widgets[WIDX_SCENERY_REPAINT_SCENERY_BUTTON].left = windowWidth - 25;
|
|
|
|
|
|
widgets[WIDX_SCENERY_EYEDROPPER_BUTTON].left = windowWidth - 25;
|
|
|
|
|
|
widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].left = windowWidth - 25;
|
|
|
|
|
|
widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].right = windowWidth - 2;
|
|
|
|
|
|
widgets[WIDX_SCENERY_REPAINT_SCENERY_BUTTON].right = windowWidth - 2;
|
|
|
|
|
|
widgets[WIDX_SCENERY_EYEDROPPER_BUTTON].right = windowWidth - 2;
|
|
|
|
|
|
widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].right = windowWidth - 2;
|
|
|
|
|
|
|
|
|
|
|
|
widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].left = windowWidth - 19;
|
|
|
|
|
|
widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].left = windowWidth - 19;
|
|
|
|
|
|
widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].left = windowWidth - 19;
|
|
|
|
|
|
widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].right = windowWidth - 8;
|
|
|
|
|
|
widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].right = windowWidth - 8;
|
|
|
|
|
|
widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].right = windowWidth - 8;
|
2025-05-02 22:56:56 +02:00
|
|
|
|
|
|
|
|
|
|
const bool canFit = widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].top < height;
|
2025-06-10 19:55:12 +02:00
|
|
|
|
widgets[WIDX_SCENERY_EYEDROPPER_BUTTON].type = canFit ? WidgetType::flatBtn : WidgetType::empty;
|
|
|
|
|
|
widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].type = canFit ? WidgetType::flatBtn : WidgetType::empty;
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void onDraw(RenderTarget& rt) override
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
drawWidgets(rt);
|
2025-05-05 01:06:46 +03:00
|
|
|
|
DrawTabs(rt, windowPos);
|
2023-02-22 17:31:21 -06:00
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
auto selectedSceneryEntry = _selectedScenery;
|
2022-03-04 07:17:20 +00:00
|
|
|
|
if (selectedSceneryEntry.IsUndefined())
|
2023-12-20 01:15:04 +01:00
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
if (_sceneryPaintEnabled) // repaint coloured scenery tool is on
|
2024-03-10 13:52:35 +00:00
|
|
|
|
return;
|
|
|
|
|
|
if (gWindowSceneryEyedropperEnabled)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
selectedSceneryEntry = GetSelectedScenery(_activeTabIndex);
|
|
|
|
|
|
if (selectedSceneryEntry.IsUndefined())
|
|
|
|
|
|
return;
|
2023-12-20 01:15:04 +01:00
|
|
|
|
}
|
2022-03-04 07:17:20 +00:00
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
auto [name, price] = GetNameAndPrice(selectedSceneryEntry);
|
2025-08-21 20:50:23 +02:00
|
|
|
|
if (price != kMoney64Undefined && !(getGameState().park.flags & PARK_FLAGS_NO_MONEY))
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
auto ft = Formatter();
|
|
|
|
|
|
ft.Add<money64>(price);
|
|
|
|
|
|
|
|
|
|
|
|
// -14
|
|
|
|
|
|
DrawTextBasic(
|
2025-10-16 20:06:18 +02:00
|
|
|
|
rt, windowPos + ScreenCoordsXY{ width - 0x1A, height - 13 }, STR_COST_LABEL, ft, { TextAlignment::right });
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto ft = Formatter();
|
|
|
|
|
|
ft.Add<StringId>(name);
|
2025-05-05 01:06:46 +03:00
|
|
|
|
DrawTextEllipsised(rt, { windowPos.x + 3, windowPos.y + height - 23 }, width - 19, STR_BLACK_STRING, ft);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2024-07-08 22:21:38 +02:00
|
|
|
|
// Draw object author(s) if debugging tools are active
|
2025-10-07 20:14:37 +02:00
|
|
|
|
if (Config::Get().general.debuggingTools)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2024-07-08 22:21:38 +02:00
|
|
|
|
auto sceneryObjectType = GetObjectTypeFromSceneryType(selectedSceneryEntry.SceneryType);
|
|
|
|
|
|
auto& objManager = GetContext()->GetObjectManager();
|
|
|
|
|
|
auto sceneryObject = objManager.GetLoadedObject(sceneryObjectType, selectedSceneryEntry.EntryIndex);
|
|
|
|
|
|
if (sceneryObject != nullptr && sceneryObject->GetAuthors().size() > 0)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2024-07-08 22:21:38 +02:00
|
|
|
|
std::string authorsString;
|
|
|
|
|
|
const auto& authors = sceneryObject->GetAuthors();
|
|
|
|
|
|
for (size_t i = 0; i < authors.size(); ++i)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2024-07-08 22:21:38 +02:00
|
|
|
|
if (i > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
authorsString.append(", ");
|
|
|
|
|
|
}
|
|
|
|
|
|
authorsString.append(authors[i]);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
2024-07-08 22:21:38 +02:00
|
|
|
|
ft = Formatter();
|
|
|
|
|
|
ft.Add<const char*>(authorsString.c_str());
|
|
|
|
|
|
DrawTextEllipsised(
|
2025-05-05 01:06:46 +03:00
|
|
|
|
rt, windowPos + ScreenCoordsXY{ 3, height - 13 }, width - 19,
|
2024-07-08 22:21:38 +02:00
|
|
|
|
(sceneryObject->GetAuthors().size() == 1 ? STR_SCENERY_AUTHOR : STR_SCENERY_AUTHOR_PLURAL), ft);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void setSelectedItem(
|
2024-03-10 13:52:35 +00:00
|
|
|
|
const ScenerySelection& scenery, const std::optional<colour_t> primary, const std::optional<colour_t> secondary,
|
|
|
|
|
|
const std::optional<colour_t> tertiary, const std::optional<colour_t> rotation)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto tabIndex = FindTabWithScenery(scenery);
|
|
|
|
|
|
if (!tabIndex.has_value())
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_activeTabIndex = tabIndex.value();
|
|
|
|
|
|
SetSelectedScenery(tabIndex.value(), scenery);
|
|
|
|
|
|
if (primary.has_value())
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_sceneryPrimaryColour = primary.value();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
if (secondary.has_value())
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_scenerySecondaryColour = secondary.value();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
if (tertiary.has_value())
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_sceneryTertiaryColour = tertiary.value();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
if (rotation.has_value())
|
|
|
|
|
|
{
|
|
|
|
|
|
gWindowSceneryRotation = rotation.value();
|
|
|
|
|
|
}
|
|
|
|
|
|
gWindowSceneryEyedropperEnabled = false;
|
2025-09-30 22:13:25 +02:00
|
|
|
|
Audio::Play(Audio::SoundId::click1, 0, ContextGetWidth() / 2);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
_hoverCounter = -16;
|
|
|
|
|
|
gSceneryPlaceCost = kMoney64Undefined;
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void setSelectedTab(const ObjectEntryIndex sceneryGroupIndex)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
const auto* tabInfo = GetSceneryTabInfoForGroup(sceneryGroupIndex);
|
|
|
|
|
|
if (tabInfo == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
tabInfo = &_tabEntries.back();
|
|
|
|
|
|
}
|
|
|
|
|
|
const auto tabId = std::distance(&*_tabEntries.cbegin(), tabInfo);
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
onMouseDown(WIDX_SCENERY_TAB_1 + tabId);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
const ScenerySelection getTabSelection()
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
return GetSelectedScenery(_activeTabIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void init()
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
_tabEntries.clear();
|
|
|
|
|
|
|
2025-06-16 23:10:47 +02:00
|
|
|
|
for (ObjectEntryIndex scenerySetIndex = 0; scenerySetIndex < kMaxTabs - kReservedTabCount; scenerySetIndex++)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
const auto* sceneryGroupEntry = ObjectManager::GetObjectEntry<SceneryGroupEntry>(scenerySetIndex);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryGroupEntry != nullptr && SceneryGroupIsInvented(scenerySetIndex))
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryTabInfo tabInfo;
|
|
|
|
|
|
tabInfo.SceneryGroupIndex = scenerySetIndex;
|
|
|
|
|
|
for (const auto& sceneryEntry : sceneryGroupEntry->SceneryEntries)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsSceneryAvailableToBuild(sceneryEntry))
|
|
|
|
|
|
{
|
|
|
|
|
|
tabInfo.AddEntryToBack(sceneryEntry);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (tabInfo.Entries.size() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
_tabEntries.push_back(std::move(tabInfo));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Sort scenery group tabs before adding other tabs
|
|
|
|
|
|
SortTabs();
|
|
|
|
|
|
|
|
|
|
|
|
// Add misc and all tab
|
|
|
|
|
|
_tabEntries.emplace_back(SceneryWindow::SceneryTabInfo{ SCENERY_TAB_TYPE_MISC });
|
|
|
|
|
|
_tabEntries.emplace_back(SceneryWindow::SceneryTabInfo{ SCENERY_TAB_TYPE_ALL });
|
|
|
|
|
|
|
|
|
|
|
|
// small scenery
|
2024-08-11 21:21:24 +01:00
|
|
|
|
for (ObjectEntryIndex sceneryId = 0; sceneryId < kMaxSmallSceneryObjects; sceneryId++)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
const auto* sceneryEntry = ObjectManager::GetObjectEntry<SmallSceneryEntry>(sceneryId);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryEntry != nullptr)
|
|
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
initSceneryEntry({ SCENERY_TYPE_SMALL, sceneryId }, sceneryEntry->scenery_tab_id);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// large scenery
|
2024-08-11 21:21:24 +01:00
|
|
|
|
for (ObjectEntryIndex sceneryId = 0; sceneryId < kMaxLargeSceneryObjects; sceneryId++)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
const auto* sceneryEntry = ObjectManager::GetObjectEntry<LargeSceneryEntry>(sceneryId);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryEntry != nullptr)
|
|
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
initSceneryEntry({ SCENERY_TYPE_LARGE, sceneryId }, sceneryEntry->scenery_tab_id);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// walls
|
2024-08-11 21:21:24 +01:00
|
|
|
|
for (ObjectEntryIndex sceneryId = 0; sceneryId < kMaxWallSceneryObjects; sceneryId++)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
const auto* sceneryEntry = ObjectManager::GetObjectEntry<WallSceneryEntry>(sceneryId);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryEntry != nullptr)
|
|
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
initSceneryEntry({ SCENERY_TYPE_WALL, sceneryId }, sceneryEntry->scenery_tab_id);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// banners
|
2024-08-11 21:21:24 +01:00
|
|
|
|
for (ObjectEntryIndex sceneryId = 0; sceneryId < kMaxBannerObjects; sceneryId++)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
const auto* sceneryEntry = ObjectManager::GetObjectEntry<BannerSceneryEntry>(sceneryId);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryEntry != nullptr)
|
|
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
initSceneryEntry({ SCENERY_TYPE_BANNER, sceneryId }, sceneryEntry->scenery_tab_id);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-11 21:21:24 +01:00
|
|
|
|
for (ObjectEntryIndex sceneryId = 0; sceneryId < kMaxPathAdditionObjects; sceneryId++)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
const auto* sceneryEntry = ObjectManager::GetObjectEntry<PathAdditionEntry>(sceneryId);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryEntry != nullptr)
|
|
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
initSceneryEntry({ SCENERY_TYPE_PATH_ITEM, sceneryId }, sceneryEntry->scenery_tab_id);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Remove empty tabs
|
|
|
|
|
|
_tabEntries.erase(
|
|
|
|
|
|
std::remove_if(
|
|
|
|
|
|
_tabEntries.begin(), _tabEntries.end(),
|
|
|
|
|
|
[](const SceneryTabInfo& tabInfo) { return tabInfo.Entries.empty(); }),
|
|
|
|
|
|
_tabEntries.end());
|
|
|
|
|
|
|
|
|
|
|
|
// Set required width
|
2025-06-16 23:10:47 +02:00
|
|
|
|
_requiredWidth = std::min(static_cast<int32_t>(_tabEntries.size()), kMaxTabsPerRow) * kTabWidth + 5;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
PrepareWidgets();
|
2025-01-25 13:46:08 +01:00
|
|
|
|
|
|
|
|
|
|
auto* windowMgr = Ui::GetWindowManager();
|
2025-09-17 23:18:52 +02:00
|
|
|
|
windowMgr->InvalidateByClass(WindowClass::scenery);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t GetRequiredWidth() const
|
|
|
|
|
|
{
|
2025-06-16 23:10:47 +02:00
|
|
|
|
return std::max(_requiredWidth, kMinimumWindowSize.width);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2025-05-16 22:41:40 +01:00
|
|
|
|
int32_t GetMinimumHeight() const
|
|
|
|
|
|
{
|
2025-09-17 23:51:12 +02:00
|
|
|
|
// Minimum window height: title, status bar, padding
|
|
|
|
|
|
int32_t newMinHeight = getTitleBarTargetHeight() + kDescriptionHeight + 2 * kTabMargin;
|
|
|
|
|
|
|
|
|
|
|
|
// Room for the search/filter widget
|
2025-09-17 19:03:29 +02:00
|
|
|
|
newMinHeight += widgets[WIDX_FILTER_TEXT_BOX].height() + 2 * kInputMargin;
|
2025-09-17 23:51:12 +02:00
|
|
|
|
|
|
|
|
|
|
// Fit *all* rows of tabs
|
|
|
|
|
|
newMinHeight += static_cast<int32_t>(1 + (_tabEntries.size() / GetMaxTabCountInARow())) * kTabHeight;
|
|
|
|
|
|
|
|
|
|
|
|
// And at least 1.5 rows of scenery items
|
|
|
|
|
|
newMinHeight += 1.5 * kSceneryButtonHeight;
|
|
|
|
|
|
|
2025-09-17 19:03:29 +02:00
|
|
|
|
return newMinHeight;
|
2025-05-16 22:41:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
int32_t GetNumColumns() const
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto& listWidget = widgets[WIDX_SCENERY_LIST];
|
2025-11-08 10:27:58 +01:00
|
|
|
|
const auto contentWidth = listWidget.width() - 1 - kScrollBarWidth;
|
2025-06-16 23:10:47 +02:00
|
|
|
|
return contentWidth / kSceneryButtonWidth;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-29 16:54:01 +01:00
|
|
|
|
template<typename T>
|
|
|
|
|
|
T CountRows(T items) const
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
const auto rows = items / GetNumColumns();
|
|
|
|
|
|
return rows;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t CountRows() const
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto tabIndex = _activeTabIndex;
|
|
|
|
|
|
if (tabIndex >= _tabEntries.size())
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const auto totalItems = _filteredSceneryTab.Entries.size();
|
|
|
|
|
|
const auto numColumns = GetNumColumns();
|
|
|
|
|
|
const auto rows = CountRows(totalItems + numColumns - 1);
|
|
|
|
|
|
return rows;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t constexpr ContentRowsHeight(const size_t rows) const
|
|
|
|
|
|
{
|
2025-06-16 23:10:47 +02:00
|
|
|
|
return static_cast<int32_t>(rows * kSceneryButtonHeight);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ContentUpdateScroll()
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto tabIndex = _activeTabIndex;
|
|
|
|
|
|
if (tabIndex >= _tabEntries.size())
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SetFilteredScenery(tabIndex);
|
|
|
|
|
|
|
|
|
|
|
|
const int32_t listHeight = height - 14 - widgets[WIDX_SCENERY_LIST].top - 1;
|
|
|
|
|
|
|
|
|
|
|
|
const auto sceneryItem = ContentCountRowsWithSelectedItem(tabIndex);
|
2025-06-16 23:10:47 +02:00
|
|
|
|
scrolls[kSceneryContentScrollIndex].contentHeight = ContentRowsHeight(sceneryItem.allRows) + 1;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2025-06-16 23:10:47 +02:00
|
|
|
|
const int32_t maxTop = std::max(0, scrolls[kSceneryContentScrollIndex].contentHeight - listHeight);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
auto rowSelected = CountRows(sceneryItem.selected_item);
|
|
|
|
|
|
if (sceneryItem.scenerySelection.IsUndefined())
|
|
|
|
|
|
{
|
|
|
|
|
|
auto& oldScenery = GetSelectedScenery(tabIndex);
|
|
|
|
|
|
if (!oldScenery.IsUndefined())
|
|
|
|
|
|
{
|
|
|
|
|
|
// Make sure last selected scenery for tab is always present
|
|
|
|
|
|
_filteredSceneryTab.AddEntryToFront(oldScenery);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// No last selection was made, use blank ScenerySelection
|
|
|
|
|
|
SetSelectedScenery(tabIndex, ScenerySelection());
|
|
|
|
|
|
rowSelected = 0;
|
|
|
|
|
|
if (!_filteredSceneryTab.Entries.empty())
|
|
|
|
|
|
{
|
|
|
|
|
|
// Select first item in current filtered tab if available
|
|
|
|
|
|
const auto& scenery = _filteredSceneryTab.Entries.front();
|
|
|
|
|
|
if (!scenery.IsUndefined())
|
|
|
|
|
|
{
|
|
|
|
|
|
SetSelectedScenery(tabIndex, scenery);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-16 23:10:47 +02:00
|
|
|
|
scrolls[kSceneryContentScrollIndex].contentOffsetY = ContentRowsHeight(rowSelected);
|
|
|
|
|
|
scrolls[kSceneryContentScrollIndex].contentOffsetY = std::min<int32_t>(
|
|
|
|
|
|
maxTop, scrolls[kSceneryContentScrollIndex].contentOffsetY);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2025-06-10 21:57:53 +02:00
|
|
|
|
widgetScrollUpdateThumbs(*this, WIDX_SCENERY_LIST);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SceneryItem ContentCountRowsWithSelectedItem(const size_t tabIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryItem sceneryItem = { 0, 0, ScenerySelection() };
|
|
|
|
|
|
const auto scenerySelection = GetSelectedScenery(tabIndex);
|
|
|
|
|
|
for (size_t i = 0; i < _filteredSceneryTab.Entries.size(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto& currentEntry = _filteredSceneryTab.Entries[i];
|
|
|
|
|
|
if (currentEntry == scenerySelection)
|
|
|
|
|
|
{
|
|
|
|
|
|
sceneryItem.selected_item = static_cast<int32_t>(i);
|
|
|
|
|
|
sceneryItem.scenerySelection = scenerySelection;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
sceneryItem.allRows = static_cast<int32_t>(CountRows(_filteredSceneryTab.Entries.size() + 8));
|
|
|
|
|
|
return sceneryItem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const ScenerySelection GetSelectedScenery(const size_t tabIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_tabSelections.size() > tabIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _tabSelections[tabIndex];
|
|
|
|
|
|
}
|
|
|
|
|
|
return {};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SetSelectedScenery(const size_t tabIndex, const ScenerySelection& value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_tabSelections.size() <= tabIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_tabSelections.resize(tabIndex + 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
_tabSelections[tabIndex] = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SceneryTabInfo* GetSceneryTabInfoForMisc()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_tabEntries.size() >= 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_tabEntries[_tabEntries.size() - 2].IsMisc())
|
|
|
|
|
|
return &_tabEntries[_tabEntries.size() - 2];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SceneryTabInfo* GetSceneryTabInfoForAll()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_tabEntries.empty())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_tabEntries.back().IsAll())
|
|
|
|
|
|
return &_tabEntries.back();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SceneryTabInfo* GetSceneryTabInfoForGroup(const ObjectEntryIndex sceneryGroupIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (auto& tabEntry : _tabEntries)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (tabEntry.SceneryGroupIndex == sceneryGroupIndex)
|
|
|
|
|
|
return &tabEntry;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::optional<size_t> FindTabWithScenery(const ScenerySelection& scenery)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (size_t i = 0; i < _tabEntries.size(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto& tabInfo = _tabEntries[i];
|
|
|
|
|
|
if (tabInfo.IsAll())
|
|
|
|
|
|
{
|
|
|
|
|
|
// The scenery will be always added here so exclude this one.
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (tabInfo.Contains(scenery))
|
|
|
|
|
|
{
|
|
|
|
|
|
return i;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 20:10:06 +02:00
|
|
|
|
void initSceneryEntry(const ScenerySelection& selection, const ObjectEntryIndex sceneryGroupIndex)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-01-22 17:16:55 +01:00
|
|
|
|
Guard::ArgumentInRange<int32_t>(selection.EntryIndex, 0, kObjectEntryIndexNull);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
if (IsSceneryAvailableToBuild(selection))
|
|
|
|
|
|
{
|
|
|
|
|
|
// Add scenery to all tab
|
|
|
|
|
|
auto* allTabInfo = GetSceneryTabInfoForAll();
|
|
|
|
|
|
if (allTabInfo != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
allTabInfo->AddEntryToBack(selection);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Add scenery to primary group (usually trees or path additions)
|
2025-01-22 17:16:55 +01:00
|
|
|
|
if (sceneryGroupIndex != kObjectEntryIndexNull)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
auto* tabInfo = GetSceneryTabInfoForGroup(sceneryGroupIndex);
|
|
|
|
|
|
if (tabInfo != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
tabInfo->AddEntryToBack(selection);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If scenery has no tab, add it to misc
|
|
|
|
|
|
const auto tabIndex = FindTabWithScenery(selection);
|
|
|
|
|
|
if (!tabIndex.has_value())
|
|
|
|
|
|
{
|
|
|
|
|
|
auto* tabInfo = GetSceneryTabInfoForMisc();
|
|
|
|
|
|
if (tabInfo != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
tabInfo->AddEntryToBack(selection);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SetFilteredScenery(const size_t tabIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto currentTab = _tabEntries[tabIndex];
|
|
|
|
|
|
|
|
|
|
|
|
_filteredSceneryTab.Entries.clear();
|
|
|
|
|
|
_filteredSceneryTab.Filter = currentTab.Filter;
|
|
|
|
|
|
|
|
|
|
|
|
for (auto selection : currentTab.Entries)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (MatchFilter(selection))
|
|
|
|
|
|
_filteredSceneryTab.AddEntryToBack(selection);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MatchFilter(const ScenerySelection& selection)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_filteredSceneryTab.Filter.empty())
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
auto& objManager = GetContext()->GetObjectManager();
|
|
|
|
|
|
auto sceneryObjectType = GetObjectTypeFromSceneryType(selection.SceneryType);
|
|
|
|
|
|
auto sceneryObject = objManager.GetLoadedObject(sceneryObjectType, selection.EntryIndex);
|
|
|
|
|
|
|
|
|
|
|
|
return IsFilterInName(*sceneryObject) || IsFilterInAuthors(*sceneryObject) || IsFilterInIdentifier(*sceneryObject)
|
|
|
|
|
|
|| IsFilterInFilename(*sceneryObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IsFilterInName(const Object& object)
|
|
|
|
|
|
{
|
2024-12-11 22:28:31 +01:00
|
|
|
|
return String::contains(object.GetName(), _filteredSceneryTab.Filter, true);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IsFilterInAuthors(const Object& object)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (auto author : object.GetAuthors())
|
2024-12-11 22:28:31 +01:00
|
|
|
|
if (String::contains(author, _filteredSceneryTab.Filter, true))
|
2024-03-10 13:52:35 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IsFilterInIdentifier(const Object& object)
|
|
|
|
|
|
{
|
2024-12-11 22:28:31 +01:00
|
|
|
|
return String::contains(object.GetIdentifier(), _filteredSceneryTab.Filter, true);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IsFilterInFilename(const Object& object)
|
|
|
|
|
|
{
|
2025-07-23 11:03:09 +01:00
|
|
|
|
return String::contains(object.GetFileName(), _filteredSceneryTab.Filter, true);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SortTabs()
|
|
|
|
|
|
{
|
|
|
|
|
|
std::sort(_tabEntries.begin(), _tabEntries.end(), [](const SceneryTabInfo& a, const SceneryTabInfo& b) {
|
|
|
|
|
|
if (a.SceneryGroupIndex == b.SceneryGroupIndex)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
2025-01-22 17:16:55 +01:00
|
|
|
|
if (a.SceneryGroupIndex == kObjectEntryIndexNull)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
return false;
|
2025-01-22 17:16:55 +01:00
|
|
|
|
if (b.SceneryGroupIndex == kObjectEntryIndexNull)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
const auto* entryA = a.GetSceneryGroupEntry();
|
|
|
|
|
|
const auto* entryB = b.GetSceneryGroupEntry();
|
|
|
|
|
|
return entryA->priority < entryB->priority;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t GetTabRowCount()
|
|
|
|
|
|
{
|
2025-06-16 23:10:47 +02:00
|
|
|
|
return std::max<int32_t>((static_cast<int32_t>(_tabEntries.size()) + kMaxTabsPerRow - 1) / kMaxTabsPerRow, 0);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-16 22:41:40 +01:00
|
|
|
|
int32_t GetMaxTabCountInARow() const
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
int32_t tabEntries = static_cast<int32_t>(_tabEntries.size());
|
2025-06-16 23:10:47 +02:00
|
|
|
|
return std::clamp(tabEntries, 1, kMaxTabsPerRow);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrepareWidgets()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Add the base widgets
|
2025-09-17 20:10:06 +02:00
|
|
|
|
setWidgets(WindowSceneryBaseWidgets);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
auto hasMisc = GetSceneryTabInfoForMisc() != nullptr;
|
2025-06-16 23:10:47 +02:00
|
|
|
|
auto kMaxTabsInThisRow = kMaxTabsPerRow - 1 - (hasMisc ? 1 : 0);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2025-04-11 20:37:54 +02:00
|
|
|
|
// Add tabs
|
|
|
|
|
|
int32_t tabsInThisRow = 0;
|
2025-04-11 23:26:34 +02:00
|
|
|
|
ScreenCoordsXY pos = { kTabMargin, widgets[WIDX_SCENERY_TITLE].bottom + kTabMargin };
|
2024-03-10 13:52:35 +00:00
|
|
|
|
for (const auto& tabInfo : _tabEntries)
|
|
|
|
|
|
{
|
2025-06-10 19:51:21 +02:00
|
|
|
|
auto widget = makeTab(pos, STR_STRING_DEFINED_TOOLTIP);
|
2025-06-16 23:10:47 +02:00
|
|
|
|
pos.x += kTabWidth;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
if (tabInfo.IsMisc())
|
|
|
|
|
|
{
|
2025-09-23 21:09:54 +02:00
|
|
|
|
widget.image = ImageId(SPR_TAB_QUESTION, FilterPaletteID::paletteNull);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (tabInfo.IsAll())
|
|
|
|
|
|
{
|
2025-09-23 21:09:54 +02:00
|
|
|
|
widget.image = ImageId(SPR_TAB, FilterPaletteID::paletteNull);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (tabInfo.IsSceneryGroup())
|
|
|
|
|
|
{
|
|
|
|
|
|
// Default tab image
|
2025-09-23 21:09:54 +02:00
|
|
|
|
widget.image = ImageId(SPR_TAB_QUESTION, FilterPaletteID::paletteNull);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
// Scenery Group image
|
|
|
|
|
|
auto scgEntry = tabInfo.GetSceneryGroupEntry();
|
|
|
|
|
|
if (scgEntry != nullptr)
|
|
|
|
|
|
{
|
2024-05-09 02:45:07 +02:00
|
|
|
|
widget.image = ImageId(scgEntry->image, colours[1].colour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-18 14:45:17 +02:00
|
|
|
|
widgets.push_back(widget);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
tabsInThisRow++;
|
2025-06-16 23:10:47 +02:00
|
|
|
|
if (tabsInThisRow >= kMaxTabsInThisRow)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-04-11 23:26:34 +02:00
|
|
|
|
pos.x = kTabMargin;
|
2025-06-16 23:10:47 +02:00
|
|
|
|
pos.y += kTabHeight;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
tabsInThisRow = 0;
|
2025-06-16 23:10:47 +02:00
|
|
|
|
_actualMinHeight += kTabHeight;
|
|
|
|
|
|
kMaxTabsInThisRow = kMaxTabsPerRow;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Shift base widgets based on number of tab rows
|
2025-06-16 23:10:47 +02:00
|
|
|
|
int32_t shiftAmount = (GetTabRowCount() - 1) * kTabHeight;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (shiftAmount > 0)
|
|
|
|
|
|
{
|
2025-01-18 14:45:17 +02:00
|
|
|
|
widgets[WIDX_SCENERY_LIST].top += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_LIST].bottom += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].top += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].bottom += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_REPAINT_SCENERY_BUTTON].top += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_REPAINT_SCENERY_BUTTON].bottom += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].top += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].bottom += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].top += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].bottom += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].top += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].bottom += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_EYEDROPPER_BUTTON].top += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_EYEDROPPER_BUTTON].bottom += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].top += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].bottom += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_FILTER_TEXT_BOX].top += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_FILTER_TEXT_BOX].bottom += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_FILTER_CLEAR_BUTTON].top += shiftAmount;
|
|
|
|
|
|
widgets[WIDX_FILTER_CLEAR_BUTTON].bottom += shiftAmount;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ScenerySelection GetSceneryIdByCursorPos(const ScreenCoordsXY& screenCoords) const
|
|
|
|
|
|
{
|
|
|
|
|
|
ScenerySelection scenery{};
|
|
|
|
|
|
|
|
|
|
|
|
const auto numColumns = GetNumColumns();
|
2025-06-16 23:10:47 +02:00
|
|
|
|
const auto colIndex = screenCoords.x / kSceneryButtonWidth;
|
|
|
|
|
|
const auto rowIndex = screenCoords.y / kSceneryButtonHeight;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (colIndex >= 0 && colIndex < numColumns && rowIndex >= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto tabSceneryIndex = static_cast<size_t>((rowIndex * numColumns) + colIndex);
|
|
|
|
|
|
if (tabSceneryIndex < _filteredSceneryTab.Entries.size())
|
|
|
|
|
|
{
|
|
|
|
|
|
return _filteredSceneryTab.Entries[tabSceneryIndex];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return scenery;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-18 16:41:20 +02:00
|
|
|
|
ScreenSize onScrollGetSize(int32_t scrollIndex) override
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
auto rows = CountRows();
|
|
|
|
|
|
return { 0, ContentRowsHeight(rows) };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-18 16:41:20 +02:00
|
|
|
|
void onScrollMouseDown(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
const auto scenery = GetSceneryIdByCursorPos(screenCoords);
|
|
|
|
|
|
if (scenery.IsUndefined())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
auto lastScenery = GetSelectedScenery(_activeTabIndex);
|
|
|
|
|
|
if (lastScenery != scenery && !MatchFilter(lastScenery))
|
|
|
|
|
|
{
|
|
|
|
|
|
_filteredSceneryTab.Entries.pop_front();
|
|
|
|
|
|
}
|
|
|
|
|
|
SetSelectedScenery(_activeTabIndex, scenery);
|
|
|
|
|
|
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_sceneryPaintEnabled = false;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
gWindowSceneryEyedropperEnabled = false;
|
2024-07-29 14:33:43 +02:00
|
|
|
|
|
2025-09-30 22:13:25 +02:00
|
|
|
|
Audio::Play(Audio::SoundId::click1, 0, windowPos.x + (width / 2));
|
2024-03-10 13:52:35 +00:00
|
|
|
|
_hoverCounter = -16;
|
|
|
|
|
|
gSceneryPlaceCost = kMoney64Undefined;
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-18 16:41:20 +02:00
|
|
|
|
void onScrollMouseOver(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
ScenerySelection scenery = GetSceneryIdByCursorPos(screenCoords);
|
2025-05-17 03:23:44 +01:00
|
|
|
|
if (!scenery.IsUndefined() && _selectedScenery != scenery)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
_selectedScenery = scenery;
|
2025-09-17 20:10:06 +02:00
|
|
|
|
invalidate();
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-18 17:23:15 +02:00
|
|
|
|
template<typename TObjectType>
|
|
|
|
|
|
std::pair<StringId, money64> GetNameAndPriceByType(const ScenerySelection& selectedScenery)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-10-18 17:23:15 +02:00
|
|
|
|
auto* sceneryEntry = ObjectManager::GetObjectEntry<TObjectType>(selectedScenery.EntryIndex);
|
|
|
|
|
|
if (sceneryEntry != nullptr)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-10-18 17:23:15 +02:00
|
|
|
|
return { sceneryEntry->name, sceneryEntry->price };
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2025-10-18 17:23:15 +02:00
|
|
|
|
{
|
|
|
|
|
|
return { STR_UNKNOWN_OBJECT_TYPE, kMoney64Undefined };
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::pair<StringId, money64> GetNameAndPrice(const ScenerySelection& selectedScenery)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!selectedScenery.IsUndefined())
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
switch (selectedScenery.SceneryType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SCENERY_TYPE_SMALL:
|
|
|
|
|
|
{
|
2025-10-18 17:23:15 +02:00
|
|
|
|
return GetNameAndPriceByType<SmallSceneryEntry>(selectedScenery);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
case SCENERY_TYPE_PATH_ITEM:
|
|
|
|
|
|
{
|
2025-10-18 17:23:15 +02:00
|
|
|
|
return GetNameAndPriceByType<PathAdditionEntry>(selectedScenery);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
case SCENERY_TYPE_WALL:
|
|
|
|
|
|
{
|
2025-10-18 17:23:15 +02:00
|
|
|
|
return GetNameAndPriceByType<WallSceneryEntry>(selectedScenery);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
case SCENERY_TYPE_LARGE:
|
|
|
|
|
|
{
|
2025-10-18 17:23:15 +02:00
|
|
|
|
return GetNameAndPriceByType<LargeSceneryEntry>(selectedScenery);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
case SCENERY_TYPE_BANNER:
|
|
|
|
|
|
{
|
2025-10-18 17:23:15 +02:00
|
|
|
|
return GetNameAndPriceByType<BannerSceneryEntry>(selectedScenery);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-18 17:23:15 +02:00
|
|
|
|
|
|
|
|
|
|
StringId name = STR_UNKNOWN_OBJECT_TYPE;
|
|
|
|
|
|
money64 price = gSceneryPlaceCost != kMoney64Undefined ? gSceneryPlaceCost : kMoney64Undefined;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
return { name, price };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-05 01:06:46 +03:00
|
|
|
|
void DrawTabs(RenderTarget& rt, const ScreenCoordsXY& offset)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
for (size_t tabIndex = 0; tabIndex < _tabEntries.size(); tabIndex++)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto widgetIndex = static_cast<WidgetIndex>(WIDX_SCENERY_TAB_1 + tabIndex);
|
|
|
|
|
|
auto widgetCoordsXY = ScreenCoordsXY(widgets[widgetIndex].left, widgets[widgetIndex].top);
|
|
|
|
|
|
|
|
|
|
|
|
if (_tabEntries[tabIndex].IsAll())
|
|
|
|
|
|
{
|
2025-09-23 21:09:54 +02:00
|
|
|
|
auto imageId = ImageId(SPR_G2_INFINITY, FilterPaletteID::paletteNull);
|
2025-05-05 01:06:46 +03:00
|
|
|
|
GfxDrawSprite(rt, imageId, offset + widgetCoordsXY);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-05 01:06:46 +03:00
|
|
|
|
void DrawSceneryItem(RenderTarget& rt, ScenerySelection scenerySelection)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (scenerySelection.SceneryType == SCENERY_TYPE_BANNER)
|
|
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto bannerEntry = ObjectManager::GetObjectEntry<BannerSceneryEntry>(scenerySelection.EntryIndex);
|
2024-07-29 14:33:43 +02:00
|
|
|
|
auto imageId = ImageId(bannerEntry->image + gWindowSceneryRotation * 2, _sceneryPrimaryColour);
|
2025-05-05 01:06:46 +03:00
|
|
|
|
GfxDrawSprite(rt, imageId, { 33, 40 });
|
|
|
|
|
|
GfxDrawSprite(rt, imageId.WithIndexOffset(1), { 33, 40 });
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (scenerySelection.SceneryType == SCENERY_TYPE_LARGE)
|
|
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto sceneryEntry = ObjectManager::GetObjectEntry<LargeSceneryEntry>(scenerySelection.EntryIndex);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
auto imageId = ImageId(sceneryEntry->image + gWindowSceneryRotation);
|
|
|
|
|
|
if (sceneryEntry->flags & LARGE_SCENERY_FLAG_HAS_PRIMARY_COLOUR)
|
2024-07-29 14:33:43 +02:00
|
|
|
|
imageId = imageId.WithPrimary(_sceneryPrimaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryEntry->flags & LARGE_SCENERY_FLAG_HAS_SECONDARY_COLOUR)
|
2024-07-29 14:33:43 +02:00
|
|
|
|
imageId = imageId.WithSecondary(_scenerySecondaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryEntry->flags & LARGE_SCENERY_FLAG_HAS_TERTIARY_COLOUR)
|
2024-07-29 14:33:43 +02:00
|
|
|
|
imageId = imageId.WithTertiary(_sceneryTertiaryColour);
|
2025-05-05 01:06:46 +03:00
|
|
|
|
GfxDrawSprite(rt, imageId, { 33, 0 });
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (scenerySelection.SceneryType == SCENERY_TYPE_WALL)
|
|
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto wallEntry = ObjectManager::GetObjectEntry<WallSceneryEntry>(scenerySelection.EntryIndex);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
auto imageId = ImageId(wallEntry->image);
|
|
|
|
|
|
auto spriteTop = (wallEntry->height * 2) + 0x32;
|
|
|
|
|
|
if (wallEntry->flags & WALL_SCENERY_HAS_GLASS)
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
imageId = imageId.WithPrimary(_sceneryPrimaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (wallEntry->flags & WALL_SCENERY_HAS_SECONDARY_COLOUR)
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
imageId = imageId.WithSecondary(_scenerySecondaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
2025-05-05 01:06:46 +03:00
|
|
|
|
GfxDrawSprite(rt, imageId, { 47, spriteTop });
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
2024-07-29 14:33:43 +02:00
|
|
|
|
auto glassImageId = ImageId(wallEntry->image + 6).WithTransparency(_sceneryPrimaryColour);
|
2025-05-05 01:06:46 +03:00
|
|
|
|
GfxDrawSprite(rt, glassImageId, { 47, spriteTop });
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
imageId = imageId.WithPrimary(_sceneryPrimaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (wallEntry->flags & WALL_SCENERY_HAS_SECONDARY_COLOUR)
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
imageId = imageId.WithSecondary(_scenerySecondaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (wallEntry->flags & WALL_SCENERY_HAS_TERTIARY_COLOUR)
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
imageId = imageId.WithTertiary(_sceneryTertiaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-05-05 01:06:46 +03:00
|
|
|
|
GfxDrawSprite(rt, imageId, { 47, spriteTop });
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
if (wallEntry->flags & WALL_SCENERY_IS_DOOR)
|
|
|
|
|
|
{
|
2025-05-05 01:06:46 +03:00
|
|
|
|
GfxDrawSprite(rt, imageId.WithIndexOffset(1), { 47, spriteTop });
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (scenerySelection.SceneryType == SCENERY_TYPE_PATH_ITEM)
|
|
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto* pathAdditionEntry = ObjectManager::GetObjectEntry<PathAdditionEntry>(scenerySelection.EntryIndex);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
auto imageId = ImageId(pathAdditionEntry->image);
|
2025-05-05 01:06:46 +03:00
|
|
|
|
GfxDrawSprite(rt, imageId, { 11, 16 });
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto sceneryEntry = ObjectManager::GetObjectEntry<SmallSceneryEntry>(scenerySelection.EntryIndex);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
auto imageId = ImageId(sceneryEntry->image + gWindowSceneryRotation);
|
|
|
|
|
|
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR))
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
imageId = imageId.WithPrimary(_sceneryPrimaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HAS_SECONDARY_COLOUR))
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
imageId = imageId.WithSecondary(_scenerySecondaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (sceneryEntry->flags & SMALL_SCENERY_FLAG_HAS_TERTIARY_COLOUR)
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
imageId = imageId.WithTertiary(_sceneryTertiaryColour);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto spriteTop = (sceneryEntry->height / 4) + 43;
|
|
|
|
|
|
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE)
|
|
|
|
|
|
&& sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_VOFFSET_CENTRE))
|
|
|
|
|
|
{
|
|
|
|
|
|
spriteTop -= 12;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-05 01:06:46 +03:00
|
|
|
|
GfxDrawSprite(rt, imageId, { 32, spriteTop });
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HAS_GLASS))
|
|
|
|
|
|
{
|
2024-07-29 14:33:43 +02:00
|
|
|
|
imageId = ImageId(sceneryEntry->image + 4 + gWindowSceneryRotation).WithTransparency(_sceneryPrimaryColour);
|
2025-05-05 01:06:46 +03:00
|
|
|
|
GfxDrawSprite(rt, imageId, { 32, spriteTop });
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_ANIMATED_FG))
|
|
|
|
|
|
{
|
|
|
|
|
|
imageId = ImageId(sceneryEntry->image + 4 + gWindowSceneryRotation);
|
2025-05-05 01:06:46 +03:00
|
|
|
|
GfxDrawSprite(rt, imageId, { 32, spriteTop });
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-18 16:41:20 +02:00
|
|
|
|
void onScrollDraw(int32_t scrollIndex, RenderTarget& rt) override
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-05-05 01:06:46 +03:00
|
|
|
|
GfxClear(rt, ColourMapA[colours[1].colour].mid_light);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
auto numColumns = GetNumColumns();
|
|
|
|
|
|
auto tabIndex = _activeTabIndex;
|
|
|
|
|
|
if (tabIndex >= _tabEntries.size())
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ScreenCoordsXY topLeft{ 0, 0 };
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t sceneryTabItemIndex = 0; sceneryTabItemIndex < _filteredSceneryTab.Entries.size();
|
|
|
|
|
|
sceneryTabItemIndex++)
|
|
|
|
|
|
{
|
|
|
|
|
|
const auto& currentSceneryGlobal = _filteredSceneryTab.Entries[sceneryTabItemIndex];
|
|
|
|
|
|
const auto tabSelectedScenery = GetSelectedScenery(tabIndex);
|
2024-07-29 14:33:43 +02:00
|
|
|
|
if (_sceneryPaintEnabled == 1 || gWindowSceneryEyedropperEnabled)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (_selectedScenery == currentSceneryGlobal)
|
|
|
|
|
|
{
|
2025-10-23 18:44:45 +02:00
|
|
|
|
Rectangle::fillInset(
|
2025-06-16 23:10:47 +02:00
|
|
|
|
rt, { topLeft, topLeft + ScreenCoordsXY{ kSceneryButtonWidth - 1, kSceneryButtonHeight - 1 } },
|
2025-10-23 18:44:45 +02:00
|
|
|
|
colours[1], Rectangle::BorderStyle::outset, Rectangle::FillBrightness::dark);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (tabSelectedScenery == currentSceneryGlobal)
|
|
|
|
|
|
{
|
2025-10-23 18:44:45 +02:00
|
|
|
|
Rectangle::fillInset(
|
2025-06-16 23:10:47 +02:00
|
|
|
|
rt, { topLeft, topLeft + ScreenCoordsXY{ kSceneryButtonWidth - 1, kSceneryButtonHeight - 1 } },
|
2025-10-23 18:44:45 +02:00
|
|
|
|
colours[1], Rectangle::BorderStyle::inset, Rectangle::FillBrightness::dark);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (_selectedScenery == currentSceneryGlobal)
|
|
|
|
|
|
{
|
2025-10-23 18:44:45 +02:00
|
|
|
|
Rectangle::fillInset(
|
2025-06-16 23:10:47 +02:00
|
|
|
|
rt, { topLeft, topLeft + ScreenCoordsXY{ kSceneryButtonWidth - 1, kSceneryButtonHeight - 1 } },
|
2025-10-23 18:44:45 +02:00
|
|
|
|
colours[1], Rectangle::BorderStyle::outset, Rectangle::FillBrightness::dark);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-05 01:06:46 +03:00
|
|
|
|
RenderTarget clippedRT;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (ClipDrawPixelInfo(
|
2025-06-16 23:10:47 +02:00
|
|
|
|
clippedRT, rt, topLeft + ScreenCoordsXY{ 1, 1 }, kSceneryButtonWidth - 2, kSceneryButtonHeight - 2))
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-05-05 01:06:46 +03:00
|
|
|
|
DrawSceneryItem(clippedRT, currentSceneryGlobal);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-16 23:10:47 +02:00
|
|
|
|
topLeft.x += kSceneryButtonWidth;
|
|
|
|
|
|
if (topLeft.x >= numColumns * kSceneryButtonWidth)
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-06-16 23:10:47 +02:00
|
|
|
|
topLeft.y += kSceneryButtonHeight;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
topLeft.x = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
2025-10-18 17:13:10 +02:00
|
|
|
|
void onToolUpdateSmallScenery(WidgetIndex widgetIndex, const ScreenCoordsXY& screenPos, ScenerySelection selection)
|
|
|
|
|
|
{
|
|
|
|
|
|
CoordsXY mapTile = {};
|
|
|
|
|
|
uint8_t quadrant;
|
|
|
|
|
|
Direction rotation;
|
|
|
|
|
|
|
|
|
|
|
|
Sub6E1F34SmallScenery(screenPos, selection.EntryIndex, mapTile, &quadrant, &rotation);
|
|
|
|
|
|
|
|
|
|
|
|
if (mapTile.IsNull())
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gMapSelectFlags.set(MapSelectFlag::enable);
|
|
|
|
|
|
if (gWindowSceneryScatterEnabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint16_t cluster_size = (gWindowSceneryScatterSize - 1) * kCoordsXYStep;
|
|
|
|
|
|
gMapSelectPositionA.x = mapTile.x - cluster_size / 2;
|
|
|
|
|
|
gMapSelectPositionA.y = mapTile.y - cluster_size / 2;
|
|
|
|
|
|
gMapSelectPositionB.x = mapTile.x + cluster_size / 2;
|
|
|
|
|
|
gMapSelectPositionB.y = mapTile.y + cluster_size / 2;
|
|
|
|
|
|
if (gWindowSceneryScatterSize % 2 == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
gMapSelectPositionB.x += kCoordsXYStep;
|
|
|
|
|
|
gMapSelectPositionB.y += kCoordsXYStep;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
gMapSelectPositionA.x = mapTile.x;
|
|
|
|
|
|
gMapSelectPositionA.y = mapTile.y;
|
|
|
|
|
|
gMapSelectPositionB.x = mapTile.x;
|
|
|
|
|
|
gMapSelectPositionB.y = mapTile.y;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto* sceneryEntry = ObjectManager::GetObjectEntry<SmallSceneryEntry>(selection.EntryIndex);
|
|
|
|
|
|
|
|
|
|
|
|
gMapSelectType = MapSelectType::full;
|
|
|
|
|
|
if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE) && !gWindowSceneryScatterEnabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
gMapSelectType = getMapSelectQuarter((quadrant ^ 2));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If no change in ghost placement
|
|
|
|
|
|
if ((gSceneryGhostType & SCENERY_GHOST_FLAG_0) && mapTile == gSceneryGhostPosition && quadrant == _unkF64F0E
|
|
|
|
|
|
&& gSceneryPlaceZ == _unkF64F0A && gSceneryPlaceObject.SceneryType == SCENERY_TYPE_SMALL
|
|
|
|
|
|
&& gSceneryPlaceObject.EntryIndex == selection.EntryIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
|
|
|
|
|
|
_unkF64F0E = quadrant;
|
|
|
|
|
|
_unkF64F0A = gSceneryPlaceZ;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t attemptsLeft = 1;
|
|
|
|
|
|
if (gSceneryPlaceZ != 0 && gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
attemptsLeft = 20;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
money64 cost = 0;
|
|
|
|
|
|
for (; attemptsLeft != 0; attemptsLeft--)
|
|
|
|
|
|
{
|
|
|
|
|
|
cost = TryPlaceGhostSmallScenery(
|
|
|
|
|
|
{ mapTile, gSceneryPlaceZ, rotation }, quadrant, selection.EntryIndex, _sceneryPrimaryColour,
|
|
|
|
|
|
_scenerySecondaryColour, _sceneryTertiaryColour);
|
|
|
|
|
|
|
|
|
|
|
|
if (cost != kMoney64Undefined)
|
|
|
|
|
|
break;
|
|
|
|
|
|
gSceneryPlaceZ += 8;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceCost = cost;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onToolUpdatePathItem(WidgetIndex widgetIndex, const ScreenCoordsXY& screenPos, ScenerySelection selection)
|
|
|
|
|
|
{
|
|
|
|
|
|
CoordsXY mapTile = {};
|
|
|
|
|
|
int32_t z;
|
|
|
|
|
|
|
|
|
|
|
|
Sub6E1F34PathItem(screenPos, selection.EntryIndex, mapTile, &z);
|
|
|
|
|
|
|
|
|
|
|
|
if (mapTile.IsNull())
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gMapSelectFlags.set(MapSelectFlag::enable);
|
|
|
|
|
|
gMapSelectPositionA.x = mapTile.x;
|
|
|
|
|
|
gMapSelectPositionA.y = mapTile.y;
|
|
|
|
|
|
gMapSelectPositionB.x = mapTile.x;
|
|
|
|
|
|
gMapSelectPositionB.y = mapTile.y;
|
|
|
|
|
|
gMapSelectType = MapSelectType::full;
|
|
|
|
|
|
|
|
|
|
|
|
// If no change in ghost placement
|
|
|
|
|
|
if ((gSceneryGhostType & SCENERY_GHOST_FLAG_1) && mapTile == gSceneryGhostPosition && z == gSceneryGhostPosition.z)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
|
|
|
|
|
|
money64 cost = TryPlaceGhostPathAddition({ mapTile, z }, selection.EntryIndex);
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceCost = cost;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onToolUpdateWall(WidgetIndex widgetIndex, const ScreenCoordsXY& screenPos, ScenerySelection selection)
|
|
|
|
|
|
{
|
2025-11-16 17:14:20 +01:00
|
|
|
|
bool isLeftMousePressed = gInputFlags.has(InputFlag::leftMousePressed);
|
|
|
|
|
|
if (isLeftMousePressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
gMapSelectFlags.set(MapSelectFlag::enable);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-18 17:13:10 +02:00
|
|
|
|
CoordsXY mapTile = {};
|
|
|
|
|
|
uint8_t edge;
|
|
|
|
|
|
|
|
|
|
|
|
Sub6E1F34Wall(screenPos, selection.EntryIndex, mapTile, &edge);
|
|
|
|
|
|
|
|
|
|
|
|
if (mapTile.IsNull())
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gMapSelectFlags.set(MapSelectFlag::enable);
|
2025-11-16 17:14:20 +01:00
|
|
|
|
setMapSelectRange(mapTile);
|
2025-10-18 17:13:10 +02:00
|
|
|
|
gMapSelectType = getMapSelectEdge(edge);
|
|
|
|
|
|
|
|
|
|
|
|
// If no change in ghost placement
|
|
|
|
|
|
if ((gSceneryGhostType & SCENERY_GHOST_FLAG_2) && mapTile == gSceneryGhostPosition
|
|
|
|
|
|
&& edge == gSceneryGhostWallRotation && gSceneryPlaceZ == _unkF64F0A)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryGhostWallRotation = edge;
|
|
|
|
|
|
_unkF64F0A = gSceneryPlaceZ;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t attemptsLeft = 1;
|
|
|
|
|
|
if (gSceneryPlaceZ != 0 && gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
attemptsLeft = 20;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
money64 cost = 0;
|
|
|
|
|
|
for (; attemptsLeft != 0; attemptsLeft--)
|
|
|
|
|
|
{
|
|
|
|
|
|
cost = TryPlaceGhostWall(
|
|
|
|
|
|
{ mapTile, gSceneryPlaceZ }, edge, selection.EntryIndex, _sceneryPrimaryColour, _scenerySecondaryColour,
|
|
|
|
|
|
_sceneryTertiaryColour);
|
|
|
|
|
|
|
|
|
|
|
|
if (cost != kMoney64Undefined)
|
|
|
|
|
|
break;
|
|
|
|
|
|
gSceneryPlaceZ += 8;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceCost = cost;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onToolUpdateLargeScenery(WidgetIndex widgetIndex, const ScreenCoordsXY& screenPos, ScenerySelection selection)
|
|
|
|
|
|
{
|
|
|
|
|
|
CoordsXY mapTile = {};
|
|
|
|
|
|
Direction direction;
|
|
|
|
|
|
|
|
|
|
|
|
Sub6E1F34LargeScenery(screenPos, selection.EntryIndex, mapTile, &direction);
|
|
|
|
|
|
|
|
|
|
|
|
if (mapTile.IsNull())
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto* sceneryEntry = ObjectManager::GetObjectEntry<LargeSceneryEntry>(selection.EntryIndex);
|
|
|
|
|
|
|
|
|
|
|
|
gMapSelectFlags.set(MapSelectFlag::enableConstruct);
|
|
|
|
|
|
|
|
|
|
|
|
// If no change in ghost placement
|
|
|
|
|
|
if ((gSceneryGhostType & SCENERY_GHOST_FLAG_3) && mapTile == gSceneryGhostPosition && gSceneryPlaceZ == _unkF64F0A
|
|
|
|
|
|
&& gSceneryPlaceObject.SceneryType == SCENERY_TYPE_LARGE
|
|
|
|
|
|
&& gSceneryPlaceObject.EntryIndex == selection.EntryIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-16 16:54:01 +00:00
|
|
|
|
MapSelection::clearSelectedTiles();
|
2025-11-16 15:28:10 +00:00
|
|
|
|
for (auto& tile : sceneryEntry->tiles)
|
|
|
|
|
|
{
|
2025-11-16 16:54:01 +00:00
|
|
|
|
MapSelection::addSelectedTile(mapTile + tile.offset.Rotate(direction));
|
2025-11-16 15:28:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-18 17:13:10 +02:00
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceObject.SceneryType = SCENERY_TYPE_LARGE;
|
|
|
|
|
|
gSceneryPlaceObject.EntryIndex = selection.EntryIndex;
|
|
|
|
|
|
_unkF64F0A = gSceneryPlaceZ;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t attemptsLeft = 1;
|
|
|
|
|
|
if (gSceneryPlaceZ != 0 && gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
attemptsLeft = 20;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
money64 cost = 0;
|
|
|
|
|
|
for (; attemptsLeft != 0; attemptsLeft--)
|
|
|
|
|
|
{
|
|
|
|
|
|
cost = TryPlaceGhostLargeScenery(
|
|
|
|
|
|
{ mapTile, gSceneryPlaceZ, direction }, selection.EntryIndex, _sceneryPrimaryColour,
|
|
|
|
|
|
_scenerySecondaryColour, _sceneryTertiaryColour);
|
|
|
|
|
|
|
|
|
|
|
|
if (cost != kMoney64Undefined)
|
|
|
|
|
|
break;
|
|
|
|
|
|
gSceneryPlaceZ += kCoordsZStep;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceCost = cost;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onToolUpdateBanner(WidgetIndex widgetIndex, const ScreenCoordsXY& screenPos, ScenerySelection selection)
|
|
|
|
|
|
{
|
|
|
|
|
|
CoordsXY mapTile = {};
|
|
|
|
|
|
Direction direction;
|
|
|
|
|
|
int32_t z;
|
|
|
|
|
|
|
|
|
|
|
|
Sub6E1F34Banner(screenPos, selection.EntryIndex, mapTile, &z, &direction);
|
|
|
|
|
|
|
|
|
|
|
|
if (mapTile.IsNull())
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gMapSelectFlags.set(MapSelectFlag::enable);
|
|
|
|
|
|
gMapSelectPositionA.x = mapTile.x;
|
|
|
|
|
|
gMapSelectPositionA.y = mapTile.y;
|
|
|
|
|
|
gMapSelectPositionB.x = mapTile.x;
|
|
|
|
|
|
gMapSelectPositionB.y = mapTile.y;
|
|
|
|
|
|
gMapSelectType = MapSelectType::full;
|
|
|
|
|
|
|
|
|
|
|
|
// If no change in ghost placement
|
|
|
|
|
|
if ((gSceneryGhostType & SCENERY_GHOST_FLAG_4) && mapTile == gSceneryGhostPosition && z == gSceneryGhostPosition.z
|
|
|
|
|
|
&& direction == gSceneryPlaceRotation)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
|
|
|
|
|
|
money64 cost = TryPlaceGhostBanner({ mapTile, z, direction }, selection.EntryIndex);
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceCost = cost;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-29 13:37:09 +02:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* rct2: 0x006E287B
|
|
|
|
|
|
*/
|
2025-10-18 16:41:20 +02:00
|
|
|
|
void onToolUpdate(WidgetIndex widgetIndex, const ScreenCoordsXY& screenPos) override
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
2025-09-10 23:23:51 +02:00
|
|
|
|
gMapSelectFlags.unset(MapSelectFlag::enable);
|
|
|
|
|
|
gMapSelectFlags.unset(MapSelectFlag::enableConstruct);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
2024-07-29 14:33:43 +02:00
|
|
|
|
if (_sceneryPaintEnabled)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
return;
|
|
|
|
|
|
if (gWindowSceneryEyedropperEnabled)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
const auto selection = WindowSceneryGetTabSelection();
|
|
|
|
|
|
if (selection.IsUndefined())
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (selection.SceneryType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SCENERY_TYPE_SMALL:
|
|
|
|
|
|
{
|
2025-10-18 17:13:10 +02:00
|
|
|
|
return onToolUpdateSmallScenery(widgetIndex, screenPos, selection);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
case SCENERY_TYPE_PATH_ITEM:
|
|
|
|
|
|
{
|
2025-10-18 17:13:10 +02:00
|
|
|
|
return onToolUpdatePathItem(widgetIndex, screenPos, selection);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
case SCENERY_TYPE_WALL:
|
|
|
|
|
|
{
|
2025-10-18 17:13:10 +02:00
|
|
|
|
return onToolUpdateWall(widgetIndex, screenPos, selection);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
case SCENERY_TYPE_LARGE:
|
|
|
|
|
|
{
|
2025-10-18 17:13:10 +02:00
|
|
|
|
return onToolUpdateLargeScenery(widgetIndex, screenPos, selection);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
case SCENERY_TYPE_BANNER:
|
|
|
|
|
|
{
|
2025-10-18 17:13:10 +02:00
|
|
|
|
return onToolUpdateBanner(widgetIndex, screenPos, selection);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* rct2: 0x006E24F6
|
2025-09-17 20:10:06 +02:00
|
|
|
|
* on failure returns kMoney64Undefined
|
|
|
|
|
|
* on success places ghost scenery and returns cost to place proper
|
2024-07-29 13:37:09 +02:00
|
|
|
|
*/
|
|
|
|
|
|
money64 TryPlaceGhostSmallScenery(
|
|
|
|
|
|
CoordsXYZD loc, uint8_t quadrant, ObjectEntryIndex entryIndex, colour_t primaryColour, colour_t secondaryColour,
|
|
|
|
|
|
colour_t tertiaryColour)
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
|
|
|
|
|
|
// 6e252b
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto smallSceneryPlaceAction = GameActions::SmallSceneryPlaceAction(
|
2024-07-29 13:37:09 +02:00
|
|
|
|
loc, quadrant, entryIndex, primaryColour, secondaryColour, tertiaryColour);
|
2025-12-11 00:12:21 +01:00
|
|
|
|
smallSceneryPlaceAction.SetFlags({ CommandFlag::ghost, CommandFlag::allowDuringPaused });
|
2025-09-08 16:21:29 +02:00
|
|
|
|
auto res = GameActions::Execute(&smallSceneryPlaceAction, getGameState());
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (res.Error != GameActions::Status::ok)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
return kMoney64Undefined;
|
|
|
|
|
|
|
2025-08-26 15:55:26 +02:00
|
|
|
|
const auto placementData = res.GetData<GameActions::SmallSceneryPlaceActionResult>();
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceRotation = loc.direction;
|
|
|
|
|
|
gSceneryPlaceObject.SceneryType = SCENERY_TYPE_SMALL;
|
|
|
|
|
|
gSceneryPlaceObject.EntryIndex = entryIndex;
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryGhostPosition = { loc, placementData.BaseHeight };
|
|
|
|
|
|
gSceneryQuadrant = placementData.SceneryQuadrant;
|
|
|
|
|
|
if (placementData.GroundFlags & ELEMENT_IS_UNDERGROUND)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Set underground on
|
2025-09-15 23:34:29 +02:00
|
|
|
|
ViewportSetVisibility(ViewportVisibility::undergroundViewGhostOn);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// Set underground off
|
2025-09-15 23:34:29 +02:00
|
|
|
|
ViewportSetVisibility(ViewportVisibility::undergroundViewGhostOff);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryGhostType |= SCENERY_GHOST_FLAG_0;
|
|
|
|
|
|
return res.Cost;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
money64 TryPlaceGhostPathAddition(CoordsXYZ loc, ObjectEntryIndex entryIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
|
|
|
|
|
|
// 6e265b
|
2025-08-26 14:48:16 +02:00
|
|
|
|
auto footpathAdditionPlaceAction = GameActions::FootpathAdditionPlaceAction(loc, entryIndex);
|
2025-12-11 00:12:21 +01:00
|
|
|
|
footpathAdditionPlaceAction.SetFlags({ CommandFlag::ghost, CommandFlag::allowDuringPaused });
|
2025-08-29 11:32:05 +02:00
|
|
|
|
footpathAdditionPlaceAction.SetCallback([=](const GameActions::GameAction* ga, const GameActions::Result* result) {
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (result->Error != GameActions::Status::ok)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
gSceneryGhostPosition = loc;
|
|
|
|
|
|
gSceneryGhostType |= SCENERY_GHOST_FLAG_1;
|
|
|
|
|
|
});
|
2025-09-08 16:21:29 +02:00
|
|
|
|
auto res = GameActions::Execute(&footpathAdditionPlaceAction, getGameState());
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (res.Error != GameActions::Status::ok)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
return kMoney64Undefined;
|
|
|
|
|
|
|
|
|
|
|
|
return res.Cost;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
money64 TryPlaceGhostWall(
|
|
|
|
|
|
CoordsXYZ loc, uint8_t edge, ObjectEntryIndex entryIndex, colour_t primaryColour, colour_t secondaryColour,
|
|
|
|
|
|
colour_t tertiaryColour)
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
|
|
|
|
|
|
// 6e26b0
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto wallPlaceAction = GameActions::WallPlaceAction(
|
|
|
|
|
|
entryIndex, loc, edge, primaryColour, secondaryColour, tertiaryColour);
|
2025-12-11 00:12:21 +01:00
|
|
|
|
wallPlaceAction.SetFlags({ CommandFlag::ghost, CommandFlag::allowDuringPaused, CommandFlag::noSpend });
|
2025-08-29 11:32:05 +02:00
|
|
|
|
wallPlaceAction.SetCallback([=](const GameActions::GameAction* ga, const GameActions::Result* result) {
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (result->Error != GameActions::Status::ok)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
2025-08-26 15:55:26 +02:00
|
|
|
|
const auto placementData = result->GetData<GameActions::WallPlaceActionResult>();
|
2024-07-29 13:37:09 +02:00
|
|
|
|
gSceneryGhostPosition = { loc, placementData.BaseHeight };
|
|
|
|
|
|
gSceneryGhostWallRotation = edge;
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryGhostType |= SCENERY_GHOST_FLAG_2;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-09-08 16:21:29 +02:00
|
|
|
|
auto res = GameActions::Execute(&wallPlaceAction, getGameState());
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (res.Error != GameActions::Status::ok)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
return kMoney64Undefined;
|
|
|
|
|
|
|
|
|
|
|
|
return res.Cost;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
money64 TryPlaceGhostLargeScenery(
|
|
|
|
|
|
CoordsXYZD loc, ObjectEntryIndex entryIndex, colour_t primaryColour, colour_t secondaryColour,
|
|
|
|
|
|
colour_t tertiaryColour)
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
|
|
|
|
|
|
// 6e25a7
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto sceneryPlaceAction = GameActions::LargeSceneryPlaceAction(
|
|
|
|
|
|
loc, entryIndex, primaryColour, secondaryColour, tertiaryColour);
|
2025-12-11 00:12:21 +01:00
|
|
|
|
sceneryPlaceAction.SetFlags({ CommandFlag::ghost, CommandFlag::allowDuringPaused, CommandFlag::noSpend });
|
2025-09-08 16:21:29 +02:00
|
|
|
|
auto res = GameActions::Execute(&sceneryPlaceAction, getGameState());
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (res.Error != GameActions::Status::ok)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
return kMoney64Undefined;
|
|
|
|
|
|
|
2025-08-26 15:55:26 +02:00
|
|
|
|
const auto placementData = res.GetData<GameActions::LargeSceneryPlaceActionResult>();
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceRotation = loc.direction;
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryGhostPosition = { loc, placementData.firstTileHeight };
|
|
|
|
|
|
if (placementData.GroundFlags & ELEMENT_IS_UNDERGROUND)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Set underground on
|
2025-09-15 23:34:29 +02:00
|
|
|
|
ViewportSetVisibility(ViewportVisibility::undergroundViewGhostOn);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// Set underground off
|
2025-09-15 23:34:29 +02:00
|
|
|
|
ViewportSetVisibility(ViewportVisibility::undergroundViewGhostOff);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryGhostType |= SCENERY_GHOST_FLAG_3;
|
|
|
|
|
|
return res.Cost;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
money64 TryPlaceGhostBanner(CoordsXYZD loc, ObjectEntryIndex entryIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
|
|
|
|
|
|
|
|
|
|
|
// 6e2612
|
2024-07-29 14:33:43 +02:00
|
|
|
|
auto primaryColour = _sceneryPrimaryColour;
|
2025-08-25 22:16:55 +02:00
|
|
|
|
auto bannerPlaceAction = GameActions::BannerPlaceAction(loc, entryIndex, primaryColour);
|
2025-12-11 00:12:21 +01:00
|
|
|
|
bannerPlaceAction.SetFlags({ CommandFlag::ghost, CommandFlag::allowDuringPaused, CommandFlag::noSpend });
|
2025-09-08 16:21:29 +02:00
|
|
|
|
auto res = GameActions::Execute(&bannerPlaceAction, getGameState());
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (res.Error != GameActions::Status::ok)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
return kMoney64Undefined;
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryGhostPosition = loc;
|
2024-08-16 23:18:33 +02:00
|
|
|
|
gSceneryGhostPosition.z += kPathHeightStep;
|
2024-07-29 13:37:09 +02:00
|
|
|
|
gSceneryPlaceRotation = loc.direction;
|
|
|
|
|
|
gSceneryGhostType |= SCENERY_GHOST_FLAG_4;
|
|
|
|
|
|
return res.Cost;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* rct2: 0x006E3158
|
|
|
|
|
|
*/
|
|
|
|
|
|
void RepaintSceneryToolDown(const ScreenCoordsXY& screenCoords, WidgetIndex widgetIndex)
|
|
|
|
|
|
{
|
2025-05-23 18:28:23 +03:00
|
|
|
|
constexpr auto flag = EnumsToFlags(
|
2025-09-15 23:34:29 +02:00
|
|
|
|
ViewportInteractionItem::scenery, ViewportInteractionItem::wall, ViewportInteractionItem::largeScenery,
|
|
|
|
|
|
ViewportInteractionItem::banner);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
auto info = GetMapCoordinatesFromPos(screenCoords, flag);
|
2025-09-08 16:21:29 +02:00
|
|
|
|
auto& gameState = getGameState();
|
2024-09-22 16:53:43 +02:00
|
|
|
|
switch (info.interactionType)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
2025-09-15 23:34:29 +02:00
|
|
|
|
case ViewportInteractionItem::scenery:
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
auto* sceneryEntry = info.Element->AsSmallScenery()->GetEntry();
|
|
|
|
|
|
|
|
|
|
|
|
// If can't repaint
|
|
|
|
|
|
if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR | SMALL_SCENERY_FLAG_HAS_GLASS))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t quadrant = info.Element->AsSmallScenery()->GetSceneryQuadrant();
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto repaintScenery = GameActions::SmallScenerySetColourAction(
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{ info.Loc, info.Element->GetBaseZ() }, quadrant, info.Element->AsSmallScenery()->GetEntryIndex(),
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
2025-09-08 16:21:29 +02:00
|
|
|
|
GameActions::Execute(&repaintScenery, gameState);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-09-15 23:34:29 +02:00
|
|
|
|
case ViewportInteractionItem::wall:
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
auto* scenery_entry = info.Element->AsWall()->GetEntry();
|
|
|
|
|
|
|
|
|
|
|
|
// If can't repaint
|
|
|
|
|
|
if (!(scenery_entry->flags & (WALL_SCENERY_HAS_PRIMARY_COLOUR | WALL_SCENERY_HAS_GLASS)))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto repaintScenery = GameActions::WallSetColourAction(
|
2024-07-29 14:33:43 +02:00
|
|
|
|
{ info.Loc, info.Element->GetBaseZ(), info.Element->GetDirection() }, _sceneryPrimaryColour,
|
|
|
|
|
|
_scenerySecondaryColour, _sceneryTertiaryColour);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
2025-09-08 16:21:29 +02:00
|
|
|
|
GameActions::Execute(&repaintScenery, gameState);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-09-15 23:34:29 +02:00
|
|
|
|
case ViewportInteractionItem::largeScenery:
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
auto* sceneryEntry = info.Element->AsLargeScenery()->GetEntry();
|
|
|
|
|
|
|
|
|
|
|
|
// If can't repaint
|
|
|
|
|
|
if (!(sceneryEntry->flags & LARGE_SCENERY_FLAG_HAS_PRIMARY_COLOUR))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto repaintScenery = GameActions::LargeScenerySetColourAction(
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{ info.Loc, info.Element->GetBaseZ(), info.Element->GetDirection() },
|
2024-07-29 14:33:43 +02:00
|
|
|
|
info.Element->AsLargeScenery()->GetSequenceIndex(), _sceneryPrimaryColour, _scenerySecondaryColour,
|
|
|
|
|
|
_sceneryTertiaryColour);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
2025-09-08 16:21:29 +02:00
|
|
|
|
GameActions::Execute(&repaintScenery, gameState);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-09-15 23:34:29 +02:00
|
|
|
|
case ViewportInteractionItem::banner:
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
auto banner = info.Element->AsBanner()->GetBanner();
|
|
|
|
|
|
if (banner != nullptr)
|
|
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto* bannerEntry = ObjectManager::GetObjectEntry<BannerSceneryEntry>(banner->type);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
if (bannerEntry->flags & BANNER_ENTRY_FLAG_HAS_PRIMARY_COLOUR)
|
|
|
|
|
|
{
|
2025-08-26 14:22:58 +02:00
|
|
|
|
auto repaintScenery = GameActions::BannerSetColourAction(
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{ info.Loc, info.Element->GetBaseZ(), info.Element->AsBanner()->GetPosition() },
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_sceneryPrimaryColour);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
2025-09-08 16:21:29 +02:00
|
|
|
|
GameActions::Execute(&repaintScenery, gameState);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default:
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SceneryEyedropperToolDown(const ScreenCoordsXY& screenCoords, WidgetIndex widgetIndex)
|
|
|
|
|
|
{
|
2025-05-23 18:28:23 +03:00
|
|
|
|
constexpr auto flag = EnumsToFlags(
|
2025-09-15 23:34:29 +02:00
|
|
|
|
ViewportInteractionItem::scenery, ViewportInteractionItem::wall, ViewportInteractionItem::largeScenery,
|
|
|
|
|
|
ViewportInteractionItem::banner, ViewportInteractionItem::pathAddition);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
auto info = GetMapCoordinatesFromPos(screenCoords, flag);
|
2024-09-22 16:53:43 +02:00
|
|
|
|
switch (info.interactionType)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
2025-09-15 23:34:29 +02:00
|
|
|
|
case ViewportInteractionItem::scenery:
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
SmallSceneryElement* sceneryElement = info.Element->AsSmallScenery();
|
|
|
|
|
|
auto entryIndex = sceneryElement->GetEntryIndex();
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto* sceneryEntry = ObjectManager::GetObjectEntry<SmallSceneryEntry>(entryIndex);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
if (sceneryEntry != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
WindowScenerySetSelectedItem(
|
|
|
|
|
|
{ SCENERY_TYPE_SMALL, entryIndex }, sceneryElement->GetPrimaryColour(),
|
|
|
|
|
|
sceneryElement->GetSecondaryColour(), sceneryElement->GetTertiaryColour(),
|
|
|
|
|
|
sceneryElement->GetDirectionWithOffset(GetCurrentRotation()));
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-09-15 23:34:29 +02:00
|
|
|
|
case ViewportInteractionItem::wall:
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
auto entryIndex = info.Element->AsWall()->GetEntryIndex();
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto* sceneryEntry = ObjectManager::GetObjectEntry<WallSceneryEntry>(entryIndex);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
if (sceneryEntry != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
WindowScenerySetSelectedItem(
|
|
|
|
|
|
{ SCENERY_TYPE_WALL, entryIndex }, info.Element->AsWall()->GetPrimaryColour(),
|
|
|
|
|
|
info.Element->AsWall()->GetSecondaryColour(), info.Element->AsWall()->GetTertiaryColour(),
|
|
|
|
|
|
std::nullopt);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-09-15 23:34:29 +02:00
|
|
|
|
case ViewportInteractionItem::largeScenery:
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
auto entryIndex = info.Element->AsLargeScenery()->GetEntryIndex();
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto* sceneryEntry = ObjectManager::GetObjectEntry<LargeSceneryEntry>(entryIndex);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
if (sceneryEntry != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
WindowScenerySetSelectedItem(
|
|
|
|
|
|
{ SCENERY_TYPE_LARGE, entryIndex }, info.Element->AsLargeScenery()->GetPrimaryColour(),
|
|
|
|
|
|
info.Element->AsLargeScenery()->GetSecondaryColour(), std::nullopt,
|
|
|
|
|
|
(GetCurrentRotation() + info.Element->GetDirection()) & 3);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-09-15 23:34:29 +02:00
|
|
|
|
case ViewportInteractionItem::banner:
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
auto banner = info.Element->AsBanner()->GetBanner();
|
|
|
|
|
|
if (banner != nullptr)
|
|
|
|
|
|
{
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto sceneryEntry = ObjectManager::GetObjectEntry<BannerSceneryEntry>(banner->type);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
if (sceneryEntry != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
WindowScenerySetSelectedItem(
|
|
|
|
|
|
{ SCENERY_TYPE_BANNER, banner->type }, std::nullopt, std::nullopt, std::nullopt, std::nullopt);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-09-15 23:34:29 +02:00
|
|
|
|
case ViewportInteractionItem::pathAddition:
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
auto entryIndex = info.Element->AsPath()->GetAdditionEntryIndex();
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto* pathAdditionEntry = ObjectManager::GetObjectEntry<PathAdditionEntry>(entryIndex);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
if (pathAdditionEntry != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
WindowScenerySetSelectedItem(
|
|
|
|
|
|
{ SCENERY_TYPE_PATH_ITEM, entryIndex }, std::nullopt, std::nullopt, std::nullopt, std::nullopt);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Sub6E1F34UpdateScreenCoordsAndButtonsPressed(bool canRaiseItem, ScreenCoordsXY& screenPos)
|
|
|
|
|
|
{
|
2025-03-20 19:47:53 +01:00
|
|
|
|
if (!canRaiseItem && !getGameState().cheats.disableSupportLimits)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
gSceneryCtrlPressed = false;
|
|
|
|
|
|
gSceneryShiftPressed = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-08-14 16:36:05 +02:00
|
|
|
|
auto& im = GetInputManager();
|
2024-07-29 13:37:09 +02:00
|
|
|
|
if (!gSceneryCtrlPressed)
|
|
|
|
|
|
{
|
2025-09-30 22:35:02 +02:00
|
|
|
|
if (im.isModifierKeyPressed(ModifierKey::ctrl))
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
// CTRL pressed
|
|
|
|
|
|
constexpr auto flag = EnumsToFlags(
|
2025-09-15 23:34:29 +02:00
|
|
|
|
ViewportInteractionItem::terrain, ViewportInteractionItem::ride, ViewportInteractionItem::scenery,
|
|
|
|
|
|
ViewportInteractionItem::footpath, ViewportInteractionItem::wall,
|
|
|
|
|
|
ViewportInteractionItem::largeScenery);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
auto info = GetMapCoordinatesFromPos(screenPos, flag);
|
|
|
|
|
|
|
2025-09-15 23:34:29 +02:00
|
|
|
|
if (info.interactionType != ViewportInteractionItem::none)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
gSceneryCtrlPressed = true;
|
|
|
|
|
|
gSceneryCtrlPressZ = info.Element->GetBaseZ();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-09-30 22:35:02 +02:00
|
|
|
|
if (!(im.isModifierKeyPressed(ModifierKey::ctrl)))
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
// CTRL not pressed
|
|
|
|
|
|
gSceneryCtrlPressed = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!gSceneryShiftPressed)
|
|
|
|
|
|
{
|
2025-09-30 22:35:02 +02:00
|
|
|
|
if (im.isModifierKeyPressed(ModifierKey::shift))
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
// SHIFT pressed
|
|
|
|
|
|
gSceneryShiftPressed = true;
|
|
|
|
|
|
gSceneryShiftPressX = screenPos.x;
|
|
|
|
|
|
gSceneryShiftPressY = screenPos.y;
|
|
|
|
|
|
gSceneryShiftPressZOffset = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-09-30 22:35:02 +02:00
|
|
|
|
if (im.isModifierKeyPressed(ModifierKey::shift))
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
// SHIFT pressed
|
|
|
|
|
|
gSceneryShiftPressZOffset = (gSceneryShiftPressY - screenPos.y + 4);
|
|
|
|
|
|
// Scale delta by zoom to match mouse position.
|
|
|
|
|
|
auto* mainWnd = WindowGetMain();
|
|
|
|
|
|
if (mainWnd != nullptr && mainWnd->viewport != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
gSceneryShiftPressZOffset = mainWnd->viewport->zoom.ApplyTo(gSceneryShiftPressZOffset);
|
|
|
|
|
|
}
|
2025-10-18 17:32:44 +02:00
|
|
|
|
gSceneryShiftPressZOffset = Numerics::floor2(gSceneryShiftPressZOffset, 8);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
|
|
|
|
|
screenPos.x = gSceneryShiftPressX;
|
|
|
|
|
|
screenPos.y = gSceneryShiftPressY;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// SHIFT not pressed
|
|
|
|
|
|
gSceneryShiftPressed = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Sub6E1F34SmallScenery(
|
|
|
|
|
|
const ScreenCoordsXY& sourceScreenPos, ObjectEntryIndex sceneryIndex, CoordsXY& gridPos, uint8_t* outQuadrant,
|
|
|
|
|
|
Direction* outRotation)
|
|
|
|
|
|
{
|
2025-01-19 10:58:28 +01:00
|
|
|
|
auto* windowMgr = GetWindowManager();
|
2025-09-17 23:18:52 +02:00
|
|
|
|
auto* w = windowMgr->FindByClass(WindowClass::scenery);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
|
|
|
|
|
if (w == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto screenPos = sourceScreenPos;
|
|
|
|
|
|
uint16_t maxPossibleHeight = ZoomLevel::max().ApplyTo(
|
|
|
|
|
|
std::numeric_limits<decltype(TileElement::BaseHeight)>::max() - 32);
|
|
|
|
|
|
bool can_raise_item = false;
|
|
|
|
|
|
|
2025-08-26 15:55:26 +02:00
|
|
|
|
const auto* sceneryEntry = ObjectManager::GetObjectEntry<SmallSceneryEntry>(sceneryIndex);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
if (sceneryEntry == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
maxPossibleHeight -= sceneryEntry->height;
|
|
|
|
|
|
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_STACKABLE))
|
|
|
|
|
|
{
|
|
|
|
|
|
can_raise_item = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Sub6E1F34UpdateScreenCoordsAndButtonsPressed(can_raise_item, screenPos);
|
|
|
|
|
|
|
|
|
|
|
|
// Small scenery
|
|
|
|
|
|
if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE))
|
|
|
|
|
|
{
|
|
|
|
|
|
uint8_t quadrant = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// If CTRL not pressed
|
|
|
|
|
|
if (!gSceneryCtrlPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto gridCoords = ScreenGetMapXYQuadrant(screenPos, &quadrant);
|
|
|
|
|
|
if (!gridCoords.has_value())
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
gridPos = gridCoords.value();
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceZ = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// If SHIFT pressed
|
|
|
|
|
|
if (gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto* surfaceElement = MapGetSurfaceElementAt(gridPos);
|
|
|
|
|
|
|
|
|
|
|
|
if (surfaceElement == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int16_t z = (surfaceElement->GetBaseZ()) & 0xFFF0;
|
|
|
|
|
|
z += gSceneryShiftPressZOffset;
|
|
|
|
|
|
|
|
|
|
|
|
z = std::clamp<int16_t>(z, 16, maxPossibleHeight);
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceZ = z;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
int16_t z = gSceneryCtrlPressZ;
|
|
|
|
|
|
|
|
|
|
|
|
auto mapCoords = ScreenGetMapXYQuadrantWithZ(screenPos, z, &quadrant);
|
|
|
|
|
|
if (!mapCoords.has_value())
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
gridPos = mapCoords.value();
|
|
|
|
|
|
|
|
|
|
|
|
// If SHIFT pressed
|
|
|
|
|
|
if (gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
z += gSceneryShiftPressZOffset;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
z = std::clamp<int16_t>(z, 16, maxPossibleHeight);
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceZ = z;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (gridPos.IsNull())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t rotation = gWindowSceneryRotation;
|
|
|
|
|
|
|
|
|
|
|
|
if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_ROTATABLE))
|
|
|
|
|
|
{
|
|
|
|
|
|
rotation = UtilRand() & 0xFF;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rotation -= GetCurrentRotation();
|
|
|
|
|
|
rotation &= 0x3;
|
|
|
|
|
|
|
2025-10-07 20:14:37 +02:00
|
|
|
|
if (Config::Get().general.virtualFloorStyle != VirtualFloorStyles::Off)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
VirtualFloorSetHeight(gSceneryPlaceZ);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*outQuadrant = quadrant ^ 2;
|
|
|
|
|
|
*outRotation = rotation;
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If CTRL not pressed
|
|
|
|
|
|
if (!gSceneryCtrlPressed)
|
|
|
|
|
|
{
|
2025-09-15 23:34:29 +02:00
|
|
|
|
constexpr auto flag = EnumsToFlags(ViewportInteractionItem::terrain, ViewportInteractionItem::water);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
|
|
|
|
|
auto info = GetMapCoordinatesFromPos(screenPos, flag);
|
|
|
|
|
|
gridPos = info.Loc;
|
|
|
|
|
|
|
2025-09-15 23:34:29 +02:00
|
|
|
|
if (info.interactionType == ViewportInteractionItem::none)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If CTRL and SHIFT not pressed
|
|
|
|
|
|
gSceneryPlaceZ = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// If SHIFT pressed
|
|
|
|
|
|
if (gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto surfaceElement = MapGetSurfaceElementAt(gridPos);
|
|
|
|
|
|
|
|
|
|
|
|
if (surfaceElement == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int16_t z = (surfaceElement->GetBaseZ()) & 0xFFF0;
|
|
|
|
|
|
z += gSceneryShiftPressZOffset;
|
|
|
|
|
|
|
|
|
|
|
|
z = std::clamp<int16_t>(z, 16, maxPossibleHeight);
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceZ = z;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
int16_t z = gSceneryCtrlPressZ;
|
|
|
|
|
|
auto coords = ScreenGetMapXYWithZ(screenPos, z);
|
|
|
|
|
|
if (coords.has_value())
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos = *coords;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
}
|
|
|
|
|
|
// If SHIFT pressed
|
|
|
|
|
|
if (gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
z += gSceneryShiftPressZOffset;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
z = std::clamp<int16_t>(z, 16, maxPossibleHeight);
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceZ = z;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (gridPos.IsNull())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
gridPos = gridPos.ToTileStart();
|
|
|
|
|
|
uint8_t rotation = gWindowSceneryRotation;
|
|
|
|
|
|
|
|
|
|
|
|
if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_ROTATABLE))
|
|
|
|
|
|
{
|
|
|
|
|
|
rotation = UtilRand() & 0xFF;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rotation -= GetCurrentRotation();
|
|
|
|
|
|
rotation &= 0x3;
|
|
|
|
|
|
|
2025-10-07 20:14:37 +02:00
|
|
|
|
if (Config::Get().general.virtualFloorStyle != VirtualFloorStyles::Off)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
VirtualFloorSetHeight(gSceneryPlaceZ);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*outQuadrant = 0;
|
|
|
|
|
|
*outRotation = rotation;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Sub6E1F34PathItem(
|
|
|
|
|
|
const ScreenCoordsXY& sourceScreenPos, ObjectEntryIndex sceneryIndex, CoordsXY& gridPos, int32_t* outZ)
|
|
|
|
|
|
{
|
2025-01-19 10:58:28 +01:00
|
|
|
|
auto* windowMgr = GetWindowManager();
|
2025-09-17 23:18:52 +02:00
|
|
|
|
auto* w = windowMgr->FindByClass(WindowClass::scenery);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
|
|
|
|
|
if (w == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto screenPos = sourceScreenPos;
|
|
|
|
|
|
Sub6E1F34UpdateScreenCoordsAndButtonsPressed(false, screenPos);
|
|
|
|
|
|
|
|
|
|
|
|
// Path bits
|
2025-09-15 23:34:29 +02:00
|
|
|
|
constexpr auto flag = EnumsToFlags(ViewportInteractionItem::footpath, ViewportInteractionItem::pathAddition);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
auto info = GetMapCoordinatesFromPos(screenPos, flag);
|
|
|
|
|
|
gridPos = info.Loc;
|
|
|
|
|
|
|
2025-09-15 23:34:29 +02:00
|
|
|
|
if (info.interactionType == ViewportInteractionItem::none)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-07 20:14:37 +02:00
|
|
|
|
if (Config::Get().general.virtualFloorStyle != VirtualFloorStyles::Off)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
VirtualFloorSetHeight(gSceneryPlaceZ);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*outZ = info.Element->GetBaseZ();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Sub6E1F34Wall(
|
|
|
|
|
|
const ScreenCoordsXY& sourceScreenPos, ObjectEntryIndex sceneryIndex, CoordsXY& gridPos, uint8_t* outEdges)
|
|
|
|
|
|
{
|
2025-01-19 10:58:28 +01:00
|
|
|
|
auto* windowMgr = GetWindowManager();
|
2025-09-17 23:18:52 +02:00
|
|
|
|
auto* w = windowMgr->FindByClass(WindowClass::scenery);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
|
|
|
|
|
if (w == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto screenPos = sourceScreenPos;
|
|
|
|
|
|
uint16_t maxPossibleHeight = ZoomLevel::max().ApplyTo(
|
|
|
|
|
|
std::numeric_limits<decltype(TileElement::BaseHeight)>::max() - 32);
|
|
|
|
|
|
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto* wallEntry = ObjectManager::GetObjectEntry<WallSceneryEntry>(sceneryIndex);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
if (wallEntry != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
maxPossibleHeight -= wallEntry->height;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Sub6E1F34UpdateScreenCoordsAndButtonsPressed(true, screenPos);
|
|
|
|
|
|
|
|
|
|
|
|
// Walls
|
|
|
|
|
|
uint8_t edge;
|
|
|
|
|
|
// If CTRL not pressed
|
|
|
|
|
|
if (!gSceneryCtrlPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto gridCoords = ScreenGetMapXYSide(screenPos, &edge);
|
|
|
|
|
|
if (!gridCoords.has_value())
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
gridPos = gridCoords.value();
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceZ = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// If SHIFT pressed
|
|
|
|
|
|
if (gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto* surfaceElement = MapGetSurfaceElementAt(gridPos);
|
|
|
|
|
|
|
|
|
|
|
|
if (surfaceElement == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int16_t z = (surfaceElement->GetBaseZ()) & 0xFFF0;
|
|
|
|
|
|
z += gSceneryShiftPressZOffset;
|
|
|
|
|
|
|
|
|
|
|
|
z = std::clamp<int16_t>(z, 16, maxPossibleHeight);
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceZ = z;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
int16_t z = gSceneryCtrlPressZ;
|
|
|
|
|
|
auto mapCoords = ScreenGetMapXYSideWithZ(screenPos, z, &edge);
|
|
|
|
|
|
if (!mapCoords.has_value())
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
gridPos = mapCoords.value();
|
|
|
|
|
|
|
|
|
|
|
|
// If SHIFT pressed
|
|
|
|
|
|
if (gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
z += gSceneryShiftPressZOffset;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
z = std::clamp<int16_t>(z, 16, maxPossibleHeight);
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceZ = z;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (gridPos.IsNull())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2025-11-16 17:14:20 +01:00
|
|
|
|
gridPos = gridPos.ToTileStart();
|
|
|
|
|
|
|
2025-10-07 20:14:37 +02:00
|
|
|
|
if (Config::Get().general.virtualFloorStyle != VirtualFloorStyles::Off)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
VirtualFloorSetHeight(gSceneryPlaceZ);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*outEdges = edge;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Sub6E1F34LargeScenery(
|
|
|
|
|
|
const ScreenCoordsXY& sourceScreenPos, ObjectEntryIndex sceneryIndex, CoordsXY& gridPos, Direction* outDirection)
|
|
|
|
|
|
{
|
2025-01-19 10:58:28 +01:00
|
|
|
|
auto* windowMgr = GetWindowManager();
|
2025-09-17 23:18:52 +02:00
|
|
|
|
auto* w = windowMgr->FindByClass(WindowClass::scenery);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
|
|
|
|
|
if (w == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto screenPos = sourceScreenPos;
|
|
|
|
|
|
uint16_t maxPossibleHeight = ZoomLevel::max().ApplyTo(
|
|
|
|
|
|
std::numeric_limits<decltype(TileElement::BaseHeight)>::max() - 32);
|
|
|
|
|
|
|
2025-08-26 15:55:26 +02:00
|
|
|
|
auto* sceneryEntry = ObjectManager::GetObjectEntry<LargeSceneryEntry>(sceneryIndex);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
if (sceneryEntry)
|
|
|
|
|
|
{
|
|
|
|
|
|
int16_t maxClearZ = 0;
|
2024-10-16 22:35:29 +01:00
|
|
|
|
for (auto& tile : sceneryEntry->tiles)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
2024-10-16 22:35:29 +01:00
|
|
|
|
maxClearZ = std::max<int16_t>(maxClearZ, tile.zClearance);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
maxPossibleHeight = std::max(0, maxPossibleHeight - maxClearZ);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Sub6E1F34UpdateScreenCoordsAndButtonsPressed(true, screenPos);
|
|
|
|
|
|
|
|
|
|
|
|
// Large scenery
|
|
|
|
|
|
// If CTRL not pressed
|
|
|
|
|
|
if (!gSceneryCtrlPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
const CoordsXY mapCoords = ViewportInteractionGetTileStartAtCursor(screenPos);
|
|
|
|
|
|
gridPos = mapCoords;
|
|
|
|
|
|
|
|
|
|
|
|
if (gridPos.IsNull())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceZ = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// If SHIFT pressed
|
|
|
|
|
|
if (gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto* surfaceElement = MapGetSurfaceElementAt(gridPos);
|
|
|
|
|
|
|
|
|
|
|
|
if (surfaceElement == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int16_t z = (surfaceElement->GetBaseZ()) & 0xFFF0;
|
|
|
|
|
|
z += gSceneryShiftPressZOffset;
|
|
|
|
|
|
|
|
|
|
|
|
z = std::clamp<int16_t>(z, 16, maxPossibleHeight);
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceZ = z;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
int16_t z = gSceneryCtrlPressZ;
|
|
|
|
|
|
auto coords = ScreenGetMapXYWithZ(screenPos, z);
|
|
|
|
|
|
if (coords.has_value())
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos = *coords;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If SHIFT pressed
|
|
|
|
|
|
if (gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
z += gSceneryShiftPressZOffset;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
z = std::clamp<int16_t>(z, 16, maxPossibleHeight);
|
|
|
|
|
|
|
|
|
|
|
|
gSceneryPlaceZ = z;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (gridPos.IsNull())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
gridPos = gridPos.ToTileStart();
|
|
|
|
|
|
|
|
|
|
|
|
Direction rotation = gWindowSceneryRotation;
|
|
|
|
|
|
rotation -= GetCurrentRotation();
|
|
|
|
|
|
rotation &= 0x3;
|
|
|
|
|
|
|
2025-10-07 20:14:37 +02:00
|
|
|
|
if (Config::Get().general.virtualFloorStyle != VirtualFloorStyles::Off)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
VirtualFloorSetHeight(gSceneryPlaceZ);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*outDirection = rotation;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Sub6E1F34Banner(
|
|
|
|
|
|
const ScreenCoordsXY& sourceScreenPos, ObjectEntryIndex sceneryIndex, CoordsXY& gridPos, int32_t* outZ,
|
|
|
|
|
|
Direction* outDirection)
|
|
|
|
|
|
{
|
2025-01-19 10:58:28 +01:00
|
|
|
|
auto* windowMgr = GetWindowManager();
|
2025-09-17 23:18:52 +02:00
|
|
|
|
auto* w = windowMgr->FindByClass(WindowClass::scenery);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
|
|
|
|
|
if (w == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto screenPos = sourceScreenPos;
|
|
|
|
|
|
Sub6E1F34UpdateScreenCoordsAndButtonsPressed(false, screenPos);
|
|
|
|
|
|
|
|
|
|
|
|
// Banner
|
2025-09-15 23:34:29 +02:00
|
|
|
|
constexpr auto flag = EnumsToFlags(ViewportInteractionItem::footpath, ViewportInteractionItem::pathAddition);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
auto info = GetMapCoordinatesFromPos(screenPos, flag);
|
|
|
|
|
|
gridPos = info.Loc;
|
|
|
|
|
|
|
2025-09-15 23:34:29 +02:00
|
|
|
|
if (info.interactionType == ViewportInteractionItem::none)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
gridPos.SetNull();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t rotation = gWindowSceneryRotation;
|
|
|
|
|
|
rotation -= GetCurrentRotation();
|
|
|
|
|
|
rotation &= 0x3;
|
|
|
|
|
|
|
|
|
|
|
|
auto z = info.Element->GetBaseZ();
|
|
|
|
|
|
|
|
|
|
|
|
if (info.Element->AsPath()->IsSloped())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (rotation != DirectionReverse(info.Element->AsPath()->GetSlopeDirection()))
|
|
|
|
|
|
{
|
|
|
|
|
|
z += (2 * kCoordsZStep);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-07 20:14:37 +02:00
|
|
|
|
if (Config::Get().general.virtualFloorStyle != VirtualFloorStyles::Off)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
VirtualFloorSetHeight(gSceneryPlaceZ);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*outDirection = rotation;
|
|
|
|
|
|
*outZ = z;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-18 16:56:32 +02:00
|
|
|
|
void onToolDownSmallScenery(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords, uint16_t selectedScenery)
|
|
|
|
|
|
{
|
|
|
|
|
|
CoordsXY gridPos;
|
|
|
|
|
|
uint8_t quadrant;
|
|
|
|
|
|
Direction rotation;
|
|
|
|
|
|
|
|
|
|
|
|
Sub6E1F34SmallScenery(screenCoords, selectedScenery, gridPos, &quadrant, &rotation);
|
|
|
|
|
|
if (gridPos.IsNull())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
int32_t quantity = 1;
|
|
|
|
|
|
bool isCluster = gWindowSceneryScatterEnabled
|
|
|
|
|
|
&& (Network::GetMode() != Network::Mode::client
|
|
|
|
|
|
|| Network::CanPerformCommand(Network::GetCurrentPlayerGroupIndex(), -2));
|
|
|
|
|
|
|
|
|
|
|
|
if (isCluster)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (gWindowSceneryScatterDensity)
|
|
|
|
|
|
{
|
|
|
|
|
|
case ScatterToolDensity::LowDensity:
|
|
|
|
|
|
quantity = gWindowSceneryScatterSize;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ScatterToolDensity::MediumDensity:
|
|
|
|
|
|
quantity = gWindowSceneryScatterSize * 2;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ScatterToolDensity::HighDensity:
|
|
|
|
|
|
quantity = gWindowSceneryScatterSize * 3;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool forceError = true;
|
|
|
|
|
|
for (int32_t q = 0; q < quantity; q++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int32_t zCoordinate = gSceneryPlaceZ;
|
|
|
|
|
|
auto* sceneryEntry = ObjectManager::GetObjectEntry<SmallSceneryEntry>(selectedScenery);
|
|
|
|
|
|
|
|
|
|
|
|
int16_t cur_grid_x = gridPos.x;
|
|
|
|
|
|
int16_t cur_grid_y = gridPos.y;
|
|
|
|
|
|
|
|
|
|
|
|
if (isCluster)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE))
|
|
|
|
|
|
{
|
|
|
|
|
|
quadrant = UtilRand() & 3;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int16_t grid_x_offset = (UtilRand() % gWindowSceneryScatterSize) - (gWindowSceneryScatterSize / 2);
|
|
|
|
|
|
int16_t grid_y_offset = (UtilRand() % gWindowSceneryScatterSize) - (gWindowSceneryScatterSize / 2);
|
|
|
|
|
|
if (gWindowSceneryScatterSize % 2 == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
grid_x_offset += 1;
|
|
|
|
|
|
grid_y_offset += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
cur_grid_x += grid_x_offset * kCoordsXYStep;
|
|
|
|
|
|
cur_grid_y += grid_y_offset * kCoordsXYStep;
|
|
|
|
|
|
|
|
|
|
|
|
if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_ROTATABLE))
|
|
|
|
|
|
{
|
|
|
|
|
|
gSceneryPlaceRotation = (gSceneryPlaceRotation + 1) & 3;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t zAttemptRange = 1;
|
|
|
|
|
|
if (gSceneryPlaceZ != 0 && gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
zAttemptRange = 20;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 11:41:49 +01:00
|
|
|
|
auto success = GameActions::Status::unknown;
|
2025-10-18 16:56:32 +02:00
|
|
|
|
// Try find a valid z coordinate
|
|
|
|
|
|
for (; zAttemptRange != 0; zAttemptRange--)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto smallSceneryPlaceAction = GameActions::SmallSceneryPlaceAction(
|
|
|
|
|
|
{ cur_grid_x, cur_grid_y, gSceneryPlaceZ, gSceneryPlaceRotation }, quadrant, selectedScenery,
|
|
|
|
|
|
_sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour);
|
|
|
|
|
|
|
|
|
|
|
|
auto& gameState = getGameState();
|
|
|
|
|
|
auto res = GameActions::Query(&smallSceneryPlaceAction, gameState);
|
|
|
|
|
|
success = res.Error;
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (res.Error == GameActions::Status::ok)
|
2025-10-18 16:56:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (res.Error == GameActions::Status::insufficientFunds)
|
2025-10-18 16:56:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (zAttemptRange != 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
gSceneryPlaceZ += 8;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Actually place
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (success == GameActions::Status::ok || ((q + 1 == quantity) && forceError))
|
2025-10-18 16:56:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
auto smallSceneryPlaceAction = GameActions::SmallSceneryPlaceAction(
|
|
|
|
|
|
{ cur_grid_x, cur_grid_y, gSceneryPlaceZ, gSceneryPlaceRotation }, quadrant, selectedScenery,
|
|
|
|
|
|
_sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour);
|
|
|
|
|
|
|
|
|
|
|
|
smallSceneryPlaceAction.SetCallback(
|
|
|
|
|
|
[=](const GameActions::GameAction* ga, const GameActions::Result* result) {
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (result->Error == GameActions::Status::ok)
|
2025-10-18 16:56:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
Audio::Play3D(Audio::SoundId::placeItem, result->Position);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
auto& gameState = getGameState();
|
|
|
|
|
|
auto res = GameActions::Execute(&smallSceneryPlaceAction, gameState);
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (res.Error == GameActions::Status::ok)
|
2025-10-18 16:56:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
forceError = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (res.Error == GameActions::Status::insufficientFunds)
|
2025-10-18 16:56:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
gSceneryPlaceZ = zCoordinate;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onToolDownPathItem(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords, uint16_t selectedScenery)
|
|
|
|
|
|
{
|
|
|
|
|
|
CoordsXY gridPos;
|
|
|
|
|
|
int32_t z;
|
|
|
|
|
|
|
|
|
|
|
|
Sub6E1F34PathItem(screenCoords, selectedScenery, gridPos, &z);
|
|
|
|
|
|
if (gridPos.IsNull())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
auto footpathAdditionPlaceAction = GameActions::FootpathAdditionPlaceAction({ gridPos, z }, selectedScenery);
|
|
|
|
|
|
|
|
|
|
|
|
footpathAdditionPlaceAction.SetCallback([](const GameActions::GameAction* ga, const GameActions::Result* result) {
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (result->Error != GameActions::Status::ok)
|
2025-10-18 16:56:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
Audio::Play3D(Audio::SoundId::placeItem, result->Position);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
auto& gameState = getGameState();
|
|
|
|
|
|
auto res = GameActions::Execute(&footpathAdditionPlaceAction, gameState);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-16 17:14:20 +01:00
|
|
|
|
std::optional<CoordsXY> getMapPosFromScreenPos(const ScreenCoordsXY& screenCoords)
|
|
|
|
|
|
{
|
|
|
|
|
|
CoordsXY coords;
|
|
|
|
|
|
if (gSceneryPlaceZ > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto candidate = ScreenGetMapXYWithZ(screenCoords, gSceneryPlaceZ);
|
|
|
|
|
|
if (!candidate.has_value())
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
|
|
|
|
coords = *candidate;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
auto info = GetMapCoordinatesFromPos(screenCoords, EnumsToFlags(ViewportInteractionItem::terrain));
|
|
|
|
|
|
|
|
|
|
|
|
if (info.interactionType == ViewportInteractionItem::none)
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
|
|
|
|
coords = info.Loc;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
coords = coords.ToTileStart();
|
|
|
|
|
|
return coords;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-18 16:56:32 +02:00
|
|
|
|
void onToolDownWall(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords, uint16_t selectedScenery)
|
|
|
|
|
|
{
|
|
|
|
|
|
CoordsXY gridPos;
|
|
|
|
|
|
uint8_t edges;
|
|
|
|
|
|
Sub6E1F34Wall(screenCoords, selectedScenery, gridPos, &edges);
|
|
|
|
|
|
if (gridPos.IsNull())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t zAttemptRange = 1;
|
|
|
|
|
|
if (gSceneryPlaceZ != 0 && gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
zAttemptRange = 20;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (; zAttemptRange != 0; zAttemptRange--)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto wallPlaceAction = GameActions::WallPlaceAction(
|
|
|
|
|
|
selectedScenery, { gridPos, gSceneryPlaceZ }, edges, _sceneryPrimaryColour, _scenerySecondaryColour,
|
|
|
|
|
|
_sceneryTertiaryColour);
|
|
|
|
|
|
|
|
|
|
|
|
auto& gameState = getGameState();
|
|
|
|
|
|
auto res = GameActions::Query(&wallPlaceAction, gameState);
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (res.Error == GameActions::Status::ok)
|
2025-10-18 16:56:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (const auto* message = std::get_if<StringId>(&res.ErrorMessage))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (*message == STR_NOT_ENOUGH_CASH_REQUIRES || *message == STR_CAN_ONLY_BUILD_THIS_ON_WATER)
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (zAttemptRange != 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
gSceneryPlaceZ += 8;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-16 17:14:20 +01:00
|
|
|
|
_inDragMode = true;
|
|
|
|
|
|
_dragStartPos = gridPos;
|
|
|
|
|
|
auto hoverPos = getMapPosFromScreenPos(screenCoords);
|
|
|
|
|
|
_dragStartHoverPos = hoverPos.has_value() ? *hoverPos : gridPos;
|
|
|
|
|
|
_dragEndPos = {};
|
|
|
|
|
|
_startEdge = edges;
|
|
|
|
|
|
gMapSelectFlags.set(MapSelectFlag::enable);
|
|
|
|
|
|
gMapSelectType = getMapSelectEdge(_startEdge);
|
|
|
|
|
|
setMapSelectRange(gridPos);
|
|
|
|
|
|
}
|
2025-10-18 16:56:32 +02:00
|
|
|
|
|
2025-11-16 17:14:20 +01:00
|
|
|
|
void dragWallSetEndPos(const ScreenCoordsXY& screenCoords)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto endCoords = getMapPosFromScreenPos(screenCoords);
|
|
|
|
|
|
if (!endCoords.has_value())
|
|
|
|
|
|
return;
|
2025-10-18 16:56:32 +02:00
|
|
|
|
|
2025-11-16 17:14:20 +01:00
|
|
|
|
if (endCoords == _dragStartHoverPos)
|
|
|
|
|
|
{
|
|
|
|
|
|
endCoords = _dragStartPos;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const bool onXAxis = (_startEdge == 1 || _startEdge == 3);
|
|
|
|
|
|
if (onXAxis)
|
|
|
|
|
|
{
|
|
|
|
|
|
endCoords->y = _dragStartPos.y;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
endCoords->x = _dragStartPos.x;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (*endCoords != _dragEndPos)
|
|
|
|
|
|
{
|
|
|
|
|
|
setMapSelectRange({ _dragStartPos, *endCoords });
|
|
|
|
|
|
updateProvisionalTiles();
|
|
|
|
|
|
}
|
|
|
|
|
|
_dragEndPos = *endCoords;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void removeProvisionalTilesFromMap()
|
|
|
|
|
|
{
|
2025-10-18 16:56:32 +02:00
|
|
|
|
auto& gameState = getGameState();
|
2025-11-16 17:14:20 +01:00
|
|
|
|
for (const auto& tile : _provisionalTiles)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto location = tile.location;
|
|
|
|
|
|
location.z = tile.calculatedZ;
|
|
|
|
|
|
auto wallRemoveAction = GameActions::WallRemoveAction(location);
|
2025-12-11 00:12:21 +01:00
|
|
|
|
wallRemoveAction.SetFlags({ CommandFlag::allowDuringPaused, CommandFlag::noSpend, CommandFlag::ghost });
|
2025-11-16 17:14:20 +01:00
|
|
|
|
wallRemoveAction.Execute(gameState);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void updateProvisionalTiles()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto& gameState = getGameState();
|
|
|
|
|
|
auto tabSelection = WindowSceneryGetTabSelection();
|
|
|
|
|
|
removeProvisionalTilesFromMap();
|
|
|
|
|
|
|
|
|
|
|
|
_provisionalTiles.clear();
|
|
|
|
|
|
_lastProvisionalError = {};
|
|
|
|
|
|
|
|
|
|
|
|
auto mapRange = getMapSelectRange();
|
|
|
|
|
|
for (auto y = mapRange.GetY1(); y <= mapRange.GetY2(); y += kCoordsXYStep)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (auto x = mapRange.GetX1(); x <= mapRange.GetX2(); x += kCoordsXYStep)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto wallPlaceAction = GameActions::WallPlaceAction(
|
|
|
|
|
|
tabSelection.EntryIndex, { x, y, gSceneryPlaceZ }, _startEdge, _sceneryPrimaryColour,
|
|
|
|
|
|
_scenerySecondaryColour, _sceneryTertiaryColour);
|
2025-12-11 00:12:21 +01:00
|
|
|
|
wallPlaceAction.SetFlags({ CommandFlag::ghost, CommandFlag::allowDuringPaused });
|
2025-11-16 17:14:20 +01:00
|
|
|
|
|
|
|
|
|
|
auto result = GameActions::Execute(&wallPlaceAction, gameState);
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (result.Error == GameActions::Status::ok)
|
2025-11-16 17:14:20 +01:00
|
|
|
|
{
|
|
|
|
|
|
const auto placementData = result.GetData<GameActions::WallPlaceActionResult>();
|
|
|
|
|
|
_provisionalTiles.push_back({ CoordsXYZD(x, y, gSceneryPlaceZ, _startEdge), placementData.BaseHeight });
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_lastProvisionalError = result;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onToolDragWall(const ScreenCoordsXY& screenCoords)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_inDragMode)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
dragWallSetEndPos(screenCoords);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onToolUp(WidgetIndex, const ScreenCoordsXY&) override
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_sceneryPaintEnabled || gWindowSceneryEyedropperEnabled)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
auto tabSelection = WindowSceneryGetTabSelection();
|
|
|
|
|
|
auto sceneryType = tabSelection.SceneryType;
|
|
|
|
|
|
if (sceneryType == SCENERY_TYPE_WALL)
|
|
|
|
|
|
{
|
|
|
|
|
|
onToolUpWall(tabSelection.EntryIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onToolUpWall(uint16_t selectedScenery)
|
|
|
|
|
|
{
|
|
|
|
|
|
removeProvisionalTilesFromMap();
|
|
|
|
|
|
|
|
|
|
|
|
if (!_inDragMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
_provisionalTiles.clear();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_provisionalTiles.empty())
|
|
|
|
|
|
{
|
|
|
|
|
|
auto z = gSceneryPlaceZ > 0 ? gSceneryPlaceZ : TileElementHeight(_dragStartPos);
|
|
|
|
|
|
Audio::Play3D(Audio::SoundId::error, { _dragStartPos, z });
|
|
|
|
|
|
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (_lastProvisionalError.Error != GameActions::Status::ok)
|
2025-11-16 17:14:20 +01:00
|
|
|
|
{
|
|
|
|
|
|
auto windowManager = Ui::GetWindowManager();
|
|
|
|
|
|
windowManager->ShowError(
|
|
|
|
|
|
_lastProvisionalError.GetErrorTitle(), _lastProvisionalError.GetErrorMessage(), true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_inDragMode = false;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto mapRange = getMapSelectRange();
|
|
|
|
|
|
bool anySuccessful = false;
|
|
|
|
|
|
CoordsXYZ lastLocation = { mapRange.Point2, gSceneryPlaceZ };
|
|
|
|
|
|
for (const auto& tile : _provisionalTiles)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto wallPlaceAction = GameActions::WallPlaceAction(
|
|
|
|
|
|
selectedScenery, tile.location, tile.location.direction, _sceneryPrimaryColour, _scenerySecondaryColour,
|
|
|
|
|
|
_sceneryTertiaryColour);
|
|
|
|
|
|
|
|
|
|
|
|
auto& gameState = getGameState();
|
|
|
|
|
|
auto result = GameActions::Execute(&wallPlaceAction, gameState);
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (result.Error == GameActions::Status::ok)
|
2025-11-16 17:14:20 +01:00
|
|
|
|
{
|
|
|
|
|
|
anySuccessful = true;
|
|
|
|
|
|
lastLocation = result.Position;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_provisionalTiles.clear();
|
|
|
|
|
|
_inDragMode = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (anySuccessful)
|
|
|
|
|
|
{
|
|
|
|
|
|
Audio::Play3D(Audio::SoundId::placeItem, lastLocation);
|
|
|
|
|
|
}
|
2025-10-18 16:56:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onToolDownLargeScenery(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords, uint16_t selectedScenery)
|
|
|
|
|
|
{
|
|
|
|
|
|
CoordsXY gridPos;
|
|
|
|
|
|
Direction direction;
|
|
|
|
|
|
Sub6E1F34LargeScenery(screenCoords, selectedScenery, gridPos, &direction);
|
|
|
|
|
|
if (gridPos.IsNull())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t zAttemptRange = 1;
|
|
|
|
|
|
if (gSceneryPlaceZ != 0 && gSceneryShiftPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
zAttemptRange = 20;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (; zAttemptRange != 0; zAttemptRange--)
|
|
|
|
|
|
{
|
|
|
|
|
|
CoordsXYZD loc = { gridPos, gSceneryPlaceZ, direction };
|
|
|
|
|
|
|
|
|
|
|
|
auto sceneryPlaceAction = GameActions::LargeSceneryPlaceAction(
|
|
|
|
|
|
loc, selectedScenery, _sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour);
|
|
|
|
|
|
|
|
|
|
|
|
auto& gameState = getGameState();
|
|
|
|
|
|
auto res = GameActions::Query(&sceneryPlaceAction, gameState);
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (res.Error == GameActions::Status::ok)
|
2025-10-18 16:56:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (const auto* message = std::get_if<StringId>(&res.ErrorMessage))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (*message == STR_NOT_ENOUGH_CASH_REQUIRES || *message == STR_CAN_ONLY_BUILD_THIS_ON_WATER)
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (zAttemptRange != 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
gSceneryPlaceZ += 8;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CoordsXYZD loc = { gridPos, gSceneryPlaceZ, direction };
|
|
|
|
|
|
|
|
|
|
|
|
auto sceneryPlaceAction = GameActions::LargeSceneryPlaceAction(
|
|
|
|
|
|
loc, selectedScenery, _sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour);
|
|
|
|
|
|
sceneryPlaceAction.SetCallback([=](const GameActions::GameAction* ga, const GameActions::Result* result) {
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (result->Error == GameActions::Status::ok)
|
2025-10-18 16:56:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
Audio::Play3D(Audio::SoundId::placeItem, result->Position);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Audio::Play3D(Audio::SoundId::error, { loc.x, loc.y, gSceneryPlaceZ });
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
auto& gameState = getGameState();
|
|
|
|
|
|
auto res = GameActions::Execute(&sceneryPlaceAction, gameState);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onToolDownBanner(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords, uint16_t selectedScenery)
|
|
|
|
|
|
{
|
|
|
|
|
|
CoordsXY gridPos;
|
|
|
|
|
|
int32_t z;
|
|
|
|
|
|
Direction direction;
|
|
|
|
|
|
Sub6E1F34Banner(screenCoords, selectedScenery, gridPos, &z, &direction);
|
|
|
|
|
|
if (gridPos.IsNull())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
CoordsXYZD loc{ gridPos, z, direction };
|
|
|
|
|
|
auto primaryColour = _sceneryPrimaryColour;
|
|
|
|
|
|
auto bannerPlaceAction = GameActions::BannerPlaceAction(loc, selectedScenery, primaryColour);
|
|
|
|
|
|
bannerPlaceAction.SetCallback([=](const GameActions::GameAction* ga, const GameActions::Result* result) {
|
2025-12-12 11:41:49 +01:00
|
|
|
|
if (result->Error == GameActions::Status::ok)
|
2025-10-18 16:56:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
auto data = result->GetData<GameActions::BannerPlaceActionResult>();
|
|
|
|
|
|
Audio::Play3D(Audio::SoundId::placeItem, result->Position);
|
|
|
|
|
|
ContextOpenDetailWindow(WindowDetail::banner, data.bannerId.ToUnderlying());
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
auto& gameState = getGameState();
|
|
|
|
|
|
GameActions::Execute(&bannerPlaceAction, gameState);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-29 13:37:09 +02:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* rct2: 0x006E2CC6
|
|
|
|
|
|
*/
|
2025-10-18 16:41:20 +02:00
|
|
|
|
void onToolDown(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
SceneryRemoveGhostToolPlacement();
|
2024-07-29 14:33:43 +02:00
|
|
|
|
|
|
|
|
|
|
if (_sceneryPaintEnabled)
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
RepaintSceneryToolDown(screenCoords, widgetIndex);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (gWindowSceneryEyedropperEnabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneryEyedropperToolDown(screenCoords, widgetIndex);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 19:03:29 +02:00
|
|
|
|
auto tabSelection = WindowSceneryGetTabSelection();
|
|
|
|
|
|
uint8_t sceneryType = tabSelection.SceneryType;
|
|
|
|
|
|
uint16_t selectedScenery = tabSelection.EntryIndex;
|
2025-09-08 16:21:29 +02:00
|
|
|
|
|
2024-07-29 13:37:09 +02:00
|
|
|
|
switch (sceneryType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SCENERY_TYPE_SMALL:
|
|
|
|
|
|
{
|
2025-10-18 16:56:32 +02:00
|
|
|
|
return onToolDownSmallScenery(widgetIndex, screenCoords, selectedScenery);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
2025-10-18 16:56:32 +02:00
|
|
|
|
|
2024-07-29 13:37:09 +02:00
|
|
|
|
case SCENERY_TYPE_PATH_ITEM:
|
|
|
|
|
|
{
|
2025-10-18 16:56:32 +02:00
|
|
|
|
return onToolDownPathItem(widgetIndex, screenCoords, selectedScenery);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
case SCENERY_TYPE_WALL:
|
|
|
|
|
|
{
|
2025-10-18 16:56:32 +02:00
|
|
|
|
return onToolDownWall(widgetIndex, screenCoords, selectedScenery);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
case SCENERY_TYPE_LARGE:
|
|
|
|
|
|
{
|
2025-10-18 16:56:32 +02:00
|
|
|
|
return onToolDownLargeScenery(widgetIndex, screenCoords, selectedScenery);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
case SCENERY_TYPE_BANNER:
|
|
|
|
|
|
{
|
2025-10-18 16:56:32 +02:00
|
|
|
|
return onToolDownBanner(widgetIndex, screenCoords, selectedScenery);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-18 16:41:20 +02:00
|
|
|
|
|
|
|
|
|
|
void onToolDrag(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_sceneryPaintEnabled || gWindowSceneryEyedropperEnabled)
|
|
|
|
|
|
onToolDown(widgetIndex, screenCoords);
|
2025-11-16 17:14:20 +01:00
|
|
|
|
|
|
|
|
|
|
auto tabSelection = WindowSceneryGetTabSelection();
|
|
|
|
|
|
auto sceneryType = tabSelection.SceneryType;
|
|
|
|
|
|
if (sceneryType == SCENERY_TYPE_WALL)
|
|
|
|
|
|
{
|
|
|
|
|
|
onToolDragWall(screenCoords);
|
|
|
|
|
|
}
|
2025-10-18 16:41:20 +02:00
|
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-03-17 02:37:46 -04:00
|
|
|
|
WindowBase* SceneryOpen()
|
2024-03-10 13:52:35 +00:00
|
|
|
|
{
|
2025-01-19 10:58:28 +01:00
|
|
|
|
auto* windowMgr = GetWindowManager();
|
2025-09-17 23:18:52 +02:00
|
|
|
|
auto* w = static_cast<SceneryWindow*>(windowMgr->BringToFrontByClass(WindowClass::scenery));
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (w == nullptr)
|
|
|
|
|
|
{
|
2025-09-17 23:18:52 +02:00
|
|
|
|
w = windowMgr->Create<SceneryWindow>(WindowClass::scenery);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
return w;
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
void WindowScenerySetSelectedItem(
|
2022-03-04 07:17:20 +00:00
|
|
|
|
const ScenerySelection& scenery, const std::optional<colour_t> primary, const std::optional<colour_t> secondary,
|
|
|
|
|
|
const std::optional<colour_t> tertiary, const std::optional<colour_t> rotation)
|
|
|
|
|
|
{
|
2025-01-19 10:58:28 +01:00
|
|
|
|
auto* windowMgr = GetWindowManager();
|
2025-09-17 23:18:52 +02:00
|
|
|
|
auto* w = static_cast<SceneryWindow*>(windowMgr->BringToFrontByClass(WindowClass::scenery));
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (w != nullptr)
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
w->setSelectedItem(scenery, primary, secondary, tertiary, rotation);
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
void WindowScenerySetSelectedTab(const ObjectEntryIndex sceneryGroupIndex)
|
2023-01-26 15:40:02 -06:00
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
// Should this bring to front?
|
2025-01-19 10:58:28 +01:00
|
|
|
|
auto* windowMgr = GetWindowManager();
|
2025-09-17 23:18:52 +02:00
|
|
|
|
auto* w = static_cast<SceneryWindow*>(windowMgr->FindByClass(WindowClass::scenery));
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (w != nullptr)
|
2023-01-26 15:40:02 -06:00
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
return w->setSelectedTab(sceneryGroupIndex);
|
2023-01-26 15:40:02 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
// Used after removing objects, in order to avoid crashes.
|
|
|
|
|
|
void WindowSceneryResetSelectedSceneryItems()
|
2023-01-26 15:40:02 -06:00
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
_tabSelections.clear();
|
|
|
|
|
|
_activeTabIndex = 0;
|
2023-01-26 15:40:02 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
void WindowScenerySetDefaultPlacementConfiguration()
|
2023-01-26 15:40:02 -06:00
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
gWindowSceneryRotation = 3;
|
2024-07-29 14:33:43 +02:00
|
|
|
|
_sceneryPrimaryColour = COLOUR_BORDEAUX_RED;
|
|
|
|
|
|
_scenerySecondaryColour = COLOUR_YELLOW;
|
|
|
|
|
|
_sceneryTertiaryColour = COLOUR_DARK_BROWN;
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
WindowSceneryResetSelectedSceneryItems();
|
2023-01-26 15:40:02 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
const ScenerySelection WindowSceneryGetTabSelection()
|
2023-01-26 15:40:02 -06:00
|
|
|
|
{
|
2025-01-19 10:58:28 +01:00
|
|
|
|
auto* windowMgr = GetWindowManager();
|
2025-09-17 23:18:52 +02:00
|
|
|
|
auto* w = static_cast<SceneryWindow*>(windowMgr->FindByClass(WindowClass::scenery));
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (w != nullptr)
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
return w->getTabSelection();
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
|
return {};
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
|
void WindowSceneryInit()
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2025-01-19 10:58:28 +01:00
|
|
|
|
auto* windowMgr = GetWindowManager();
|
2025-09-17 23:18:52 +02:00
|
|
|
|
auto* w = static_cast<SceneryWindow*>(windowMgr->FindByClass(WindowClass::scenery));
|
2024-03-10 13:52:35 +00:00
|
|
|
|
if (w != nullptr)
|
2022-03-04 07:17:20 +00:00
|
|
|
|
{
|
2025-09-17 20:10:06 +02:00
|
|
|
|
w->init();
|
2022-03-04 07:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-29 13:37:09 +02:00
|
|
|
|
|
|
|
|
|
|
void ToggleSceneryWindow()
|
|
|
|
|
|
{
|
2025-09-17 23:18:52 +02:00
|
|
|
|
if (isToolActive(WindowClass::scenery, WIDX_SCENERY_BACKGROUND))
|
2024-07-29 13:37:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
ToolCancel();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-09-17 23:18:52 +02:00
|
|
|
|
auto* toolWindow = ContextOpenWindow(WindowClass::scenery);
|
2025-03-01 15:56:36 +01:00
|
|
|
|
ToolSet(*toolWindow, WIDX_SCENERY_BACKGROUND, Tool::arrow);
|
2025-03-26 13:00:54 +01:00
|
|
|
|
gInputFlags.set(InputFlag::unk6);
|
2024-07-29 13:37:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
|
} // namespace OpenRCT2::Ui::Windows
|