2017-06-22 20:49:13 +02:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 OpenRCT2 developers
|
2017-06-22 20:49:13 +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
|
2017-06-22 20:49:13 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2017-06-22 20:49:13 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2017-12-07 22:33:11 +01:00
|
|
|
#include <openrct2-ui/interface/Dropdown.h>
|
2017-12-07 02:47:26 +01:00
|
|
|
#include <openrct2-ui/interface/LandTool.h>
|
2018-01-03 00:13:37 +01:00
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
|
|
|
|
#include <openrct2-ui/interface/Window.h>
|
2018-12-05 20:33:45 +00:00
|
|
|
#include <openrct2/Context.h>
|
2018-01-21 17:18:00 +01:00
|
|
|
#include <openrct2/Input.h>
|
2018-03-19 23:28:40 +01:00
|
|
|
#include <openrct2/drawing/Drawing.h>
|
2021-11-27 16:20:05 +00:00
|
|
|
#include <openrct2/object/ObjectLimits.h>
|
2018-12-05 20:33:45 +00:00
|
|
|
#include <openrct2/object/ObjectManager.h>
|
|
|
|
|
#include <openrct2/object/TerrainEdgeObject.h>
|
|
|
|
|
#include <openrct2/object/TerrainSurfaceObject.h>
|
2018-06-22 23:20:47 +02:00
|
|
|
#include <openrct2/world/Map.h>
|
|
|
|
|
#include <openrct2/world/Surface.h>
|
2017-06-22 20:49:13 +02:00
|
|
|
|
2018-12-05 20:33:45 +00:00
|
|
|
using namespace OpenRCT2;
|
|
|
|
|
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format off
|
2018-06-20 17:28:51 +02:00
|
|
|
static uint16_t toolSizeSpriteIndices[] =
|
2017-06-22 20:49:13 +02:00
|
|
|
{
|
|
|
|
|
SPR_LAND_TOOL_SIZE_0,
|
|
|
|
|
SPR_LAND_TOOL_SIZE_1,
|
|
|
|
|
SPR_LAND_TOOL_SIZE_2,
|
|
|
|
|
SPR_LAND_TOOL_SIZE_3,
|
|
|
|
|
SPR_LAND_TOOL_SIZE_4,
|
|
|
|
|
SPR_LAND_TOOL_SIZE_5,
|
2020-02-19 09:45:00 +01:00
|
|
|
SPR_G2_LAND_TOOL_SIZE_6,
|
2017-06-22 20:49:13 +02:00
|
|
|
SPR_LAND_TOOL_SIZE_7,
|
|
|
|
|
};
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format on
|
2018-01-21 17:18:00 +01:00
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
uint16_t gLandToolSize;
|
2021-07-28 10:25:36 +02:00
|
|
|
money64 gLandToolRaiseCost;
|
|
|
|
|
money64 gLandToolLowerCost;
|
2020-07-23 12:17:33 +02:00
|
|
|
ObjectEntryIndex gLandToolTerrainSurface;
|
|
|
|
|
ObjectEntryIndex gLandToolTerrainEdge;
|
2021-07-28 10:25:36 +02:00
|
|
|
money64 gWaterToolRaiseCost;
|
|
|
|
|
money64 gWaterToolLowerCost;
|
2017-06-22 20:49:13 +02:00
|
|
|
|
2020-11-03 03:59:00 -07:00
|
|
|
uint32_t LandTool::SizeToSpriteIndex(uint16_t size)
|
2017-06-22 20:49:13 +02:00
|
|
|
{
|
|
|
|
|
if (size <= MAX_TOOL_SIZE_WITH_SPRITE)
|
|
|
|
|
{
|
|
|
|
|
return toolSizeSpriteIndices[size];
|
|
|
|
|
}
|
2021-09-15 22:22:15 +02:00
|
|
|
|
|
|
|
|
return 0xFFFFFFFF;
|
2017-06-22 20:49:13 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-15 23:08:00 +01:00
|
|
|
void LandTool::ShowSurfaceStyleDropdown(rct_window* w, rct_widget* widget, ObjectEntryIndex currentSurfaceType)
|
2017-06-22 20:49:13 +02:00
|
|
|
{
|
2018-12-05 20:33:45 +00:00
|
|
|
auto& objManager = GetContext()->GetObjectManager();
|
2017-06-22 20:49:13 +02:00
|
|
|
|
2018-12-05 20:33:45 +00:00
|
|
|
auto defaultIndex = 0;
|
|
|
|
|
auto itemIndex = 0;
|
|
|
|
|
for (size_t i = 0; i < MAX_TERRAIN_SURFACE_OBJECTS; i++)
|
2017-06-22 20:49:13 +02:00
|
|
|
{
|
2020-11-09 10:36:37 +01:00
|
|
|
const auto surfaceObj = static_cast<TerrainSurfaceObject*>(objManager.GetLoadedObject(ObjectType::TerrainSurface, i));
|
2020-12-21 14:53:54 +01:00
|
|
|
// NumImagesLoaded can be 1 for RCT1 surfaces if the user does not have RCT1 linked.
|
2020-12-20 21:38:34 +01:00
|
|
|
if (surfaceObj != nullptr && surfaceObj->NumImagesLoaded > 1)
|
2017-06-22 20:49:13 +02:00
|
|
|
{
|
2020-11-03 01:16:06 -07:00
|
|
|
gDropdownItemsFormat[itemIndex] = Dropdown::FormatLandPicker;
|
2018-12-05 20:33:45 +00:00
|
|
|
gDropdownItemsArgs[itemIndex] = surfaceObj->IconImageId;
|
|
|
|
|
if (surfaceObj->Colour != 255)
|
|
|
|
|
{
|
2020-03-05 18:15:03 +01:00
|
|
|
gDropdownItemsArgs[itemIndex] |= SPRITE_ID_PALETTE_COLOUR_1(surfaceObj->Colour);
|
2018-12-05 20:33:45 +00:00
|
|
|
}
|
|
|
|
|
if (i == currentSurfaceType)
|
|
|
|
|
{
|
|
|
|
|
defaultIndex = itemIndex;
|
|
|
|
|
}
|
|
|
|
|
itemIndex++;
|
2017-06-22 20:49:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-03-06 15:06:28 +01:00
|
|
|
uint32_t surfaceCount = itemIndex;
|
2017-06-22 20:49:13 +02:00
|
|
|
|
2020-11-03 01:16:06 -07:00
|
|
|
WindowDropdownShowImage(
|
2020-06-25 03:44:00 +02:00
|
|
|
w->windowPos.x + widget->left, w->windowPos.y + widget->top, widget->height(), w->colours[2], 0, surfaceCount, 47, 36,
|
2020-11-03 01:16:06 -07:00
|
|
|
DropdownGetAppropriateImageDropdownItemsPerRow(surfaceCount));
|
2017-06-22 20:49:13 +02:00
|
|
|
|
|
|
|
|
gDropdownDefaultIndex = defaultIndex;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-15 23:08:00 +01:00
|
|
|
void LandTool::ShowEdgeStyleDropdown(rct_window* w, rct_widget* widget, ObjectEntryIndex currentEdgeType)
|
2017-06-22 20:49:13 +02:00
|
|
|
{
|
2018-12-05 20:33:45 +00:00
|
|
|
auto& objManager = GetContext()->GetObjectManager();
|
2017-06-22 20:49:13 +02:00
|
|
|
|
2018-12-05 20:33:45 +00:00
|
|
|
auto defaultIndex = 0;
|
|
|
|
|
auto itemIndex = 0;
|
|
|
|
|
for (size_t i = 0; i < MAX_TERRAIN_EDGE_OBJECTS; i++)
|
2018-06-22 23:20:47 +02:00
|
|
|
{
|
2020-11-09 10:36:37 +01:00
|
|
|
const auto edgeObj = static_cast<TerrainEdgeObject*>(objManager.GetLoadedObject(ObjectType::TerrainEdge, i));
|
2019-03-12 09:23:17 +01:00
|
|
|
if (edgeObj != nullptr && edgeObj->NumImagesLoaded > 1)
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
2020-11-03 01:16:06 -07:00
|
|
|
gDropdownItemsFormat[itemIndex] = Dropdown::FormatLandPicker;
|
2018-12-05 20:33:45 +00:00
|
|
|
gDropdownItemsArgs[itemIndex] = edgeObj->IconImageId;
|
|
|
|
|
if (i == currentEdgeType)
|
|
|
|
|
{
|
|
|
|
|
defaultIndex = itemIndex;
|
|
|
|
|
}
|
|
|
|
|
itemIndex++;
|
|
|
|
|
}
|
2017-06-22 20:49:13 +02:00
|
|
|
}
|
2020-03-06 15:06:28 +01:00
|
|
|
uint32_t edgeCount = itemIndex;
|
2020-11-03 01:16:06 -07:00
|
|
|
auto itemsPerRow = DropdownGetAppropriateImageDropdownItemsPerRow(edgeCount);
|
2017-06-22 20:49:13 +02:00
|
|
|
|
2020-11-03 01:16:06 -07:00
|
|
|
WindowDropdownShowImage(
|
2020-06-25 03:44:00 +02:00
|
|
|
w->windowPos.x + widget->left, w->windowPos.y + widget->top, widget->height(), w->colours[2], 0, edgeCount, 47, 36,
|
|
|
|
|
itemsPerRow);
|
2017-06-22 20:49:13 +02:00
|
|
|
|
|
|
|
|
gDropdownDefaultIndex = defaultIndex;
|
|
|
|
|
}
|