mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-06 06:32:56 +01:00
Refactor defines in LandTool.h
This commit is contained in:
@@ -47,7 +47,7 @@ money64 gWaterToolLowerCost;
|
||||
|
||||
uint32_t LandTool::SizeToSpriteIndex(uint16_t size)
|
||||
{
|
||||
if (size <= MAX_TOOL_SIZE_WITH_SPRITE)
|
||||
if (size <= kLandToolMaximumSizeWithSprite)
|
||||
{
|
||||
return toolSizeSpriteIndices[size];
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
#include <openrct2/common.h>
|
||||
#include <openrct2/sprites.h>
|
||||
|
||||
#define MINIMUM_TOOL_SIZE 1
|
||||
#define MAXIMUM_TOOL_SIZE 64
|
||||
constexpr uint16_t kLandToolMinimumSize = 1;
|
||||
constexpr uint16_t kLandToolMaximumSize = 64;
|
||||
// The highest tool size to have a sprite. Bigger tool sizes simply display a number.
|
||||
#define MAX_TOOL_SIZE_WITH_SPRITE 7
|
||||
constexpr uint16_t kLandToolMaximumSizeWithSprite = 7;
|
||||
|
||||
extern uint16_t gLandToolSize;
|
||||
extern money64 gLandToolRaiseCost;
|
||||
|
||||
@@ -97,8 +97,8 @@ public:
|
||||
case WIDX_PREVIEW:
|
||||
{
|
||||
Formatter ft;
|
||||
ft.Add<int16_t>(MINIMUM_TOOL_SIZE);
|
||||
ft.Add<int16_t>(MAXIMUM_TOOL_SIZE);
|
||||
ft.Add<uint16_t>(kLandToolMinimumSize);
|
||||
ft.Add<uint16_t>(kLandToolMaximumSize);
|
||||
TextInputOpen(WIDX_PREVIEW, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, ft, STR_NONE, STR_NONE, 3);
|
||||
break;
|
||||
}
|
||||
@@ -123,14 +123,14 @@ public:
|
||||
{
|
||||
case WIDX_DECREMENT:
|
||||
// Decrement land tool size, if it stays within the limit
|
||||
gLandToolSize = std::max(MINIMUM_TOOL_SIZE, gLandToolSize - 1);
|
||||
gLandToolSize = std::max<uint16_t>(kLandToolMinimumSize, gLandToolSize - 1);
|
||||
|
||||
// Invalidate the window
|
||||
Invalidate();
|
||||
break;
|
||||
case WIDX_INCREMENT:
|
||||
// Increment land tool size, if it stays within the limit
|
||||
gLandToolSize = std::min(MAXIMUM_TOOL_SIZE, gLandToolSize + 1);
|
||||
gLandToolSize = std::min<uint16_t>(kLandToolMaximumSize, gLandToolSize + 1);
|
||||
|
||||
// Invalidate the window
|
||||
Invalidate();
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
try
|
||||
{
|
||||
int32_t size = std::stol(std::string(text));
|
||||
size = std::clamp(size, MINIMUM_TOOL_SIZE, MAXIMUM_TOOL_SIZE);
|
||||
size = std::clamp<uint16_t>(size, kLandToolMinimumSize, kLandToolMaximumSize);
|
||||
gLandToolSize = size;
|
||||
Invalidate();
|
||||
}
|
||||
@@ -181,7 +181,7 @@ public:
|
||||
// Draw number for tool sizes bigger than 7
|
||||
ScreenCoordsXY screenCoords = { windowPos.x + window_clear_scenery_widgets[WIDX_PREVIEW].midX(),
|
||||
windowPos.y + window_clear_scenery_widgets[WIDX_PREVIEW].midY() };
|
||||
if (gLandToolSize > MAX_TOOL_SIZE_WITH_SPRITE)
|
||||
if (gLandToolSize > kLandToolMaximumSizeWithSprite)
|
||||
{
|
||||
auto ft = Formatter();
|
||||
ft.Add<uint16_t>(gLandToolSize);
|
||||
|
||||
@@ -62,8 +62,8 @@ private:
|
||||
void InputSize()
|
||||
{
|
||||
Formatter ft;
|
||||
ft.Add<int16_t>(MINIMUM_TOOL_SIZE);
|
||||
ft.Add<int16_t>(MAXIMUM_TOOL_SIZE);
|
||||
ft.Add<uint16_t>(kLandToolMinimumSize);
|
||||
ft.Add<uint16_t>(kLandToolMaximumSize);
|
||||
WindowTextInputOpen(this, WIDX_PREVIEW, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, ft, STR_NONE, STR_NONE, 3);
|
||||
}
|
||||
|
||||
@@ -132,14 +132,14 @@ public:
|
||||
break;
|
||||
case WIDX_DECREMENT:
|
||||
// Decrement land tool size
|
||||
gLandToolSize = std::max(MINIMUM_TOOL_SIZE, gLandToolSize - 1);
|
||||
gLandToolSize = std::max<uint16_t>(kLandToolMinimumSize, gLandToolSize - 1);
|
||||
|
||||
// Invalidate the window
|
||||
Invalidate();
|
||||
break;
|
||||
case WIDX_INCREMENT:
|
||||
// Increment land tool size
|
||||
gLandToolSize = std::min(MAXIMUM_TOOL_SIZE, gLandToolSize + 1);
|
||||
gLandToolSize = std::min<uint16_t>(kLandToolMaximumSize, gLandToolSize + 1);
|
||||
|
||||
// Invalidate the window
|
||||
Invalidate();
|
||||
@@ -202,8 +202,8 @@ public:
|
||||
int32_t size = strtol(textStr.c_str(), &end, 10);
|
||||
if (*end == '\0')
|
||||
{
|
||||
size = std::max(MINIMUM_TOOL_SIZE, size);
|
||||
size = std::min(MAXIMUM_TOOL_SIZE, size);
|
||||
size = std::max<uint16_t>(kLandToolMinimumSize, size);
|
||||
size = std::min<uint16_t>(kLandToolMaximumSize, size);
|
||||
gLandToolSize = size;
|
||||
|
||||
Invalidate();
|
||||
@@ -244,7 +244,7 @@ public:
|
||||
DrawDropdownButtons(dpi);
|
||||
|
||||
// Draw number for tool sizes bigger than 7
|
||||
if (gLandToolSize > MAX_TOOL_SIZE_WITH_SPRITE)
|
||||
if (gLandToolSize > kLandToolMaximumSizeWithSprite)
|
||||
{
|
||||
auto ft = Formatter();
|
||||
ft.Add<uint16_t>(gLandToolSize);
|
||||
|
||||
@@ -131,14 +131,14 @@ public:
|
||||
{
|
||||
case WIDX_DECREMENT:
|
||||
// Decrement land rights tool size
|
||||
gLandToolSize = std::max(MINIMUM_TOOL_SIZE, gLandToolSize - 1);
|
||||
gLandToolSize = std::max<uint16_t>(kLandToolMinimumSize, gLandToolSize - 1);
|
||||
|
||||
// Invalidate the window
|
||||
Invalidate();
|
||||
break;
|
||||
case WIDX_INCREMENT:
|
||||
// Decrement land rights tool size
|
||||
gLandToolSize = std::min(MAXIMUM_TOOL_SIZE, gLandToolSize + 1);
|
||||
gLandToolSize = std::min<uint16_t>(kLandToolMaximumSize, gLandToolSize + 1);
|
||||
|
||||
// Invalidate the window
|
||||
Invalidate();
|
||||
@@ -157,10 +157,10 @@ public:
|
||||
const auto res = String::Parse<int32_t>(text);
|
||||
if (res.has_value())
|
||||
{
|
||||
int32_t size;
|
||||
uint16_t size;
|
||||
size = res.value();
|
||||
size = std::max(MINIMUM_TOOL_SIZE, size);
|
||||
size = std::min(MAXIMUM_TOOL_SIZE, size);
|
||||
size = std::max(kLandToolMinimumSize, size);
|
||||
size = std::min(kLandToolMaximumSize, size);
|
||||
gLandToolSize = size;
|
||||
Invalidate();
|
||||
}
|
||||
@@ -220,7 +220,7 @@ public:
|
||||
|
||||
DrawWidgets(dpi);
|
||||
// Draw number for tool sizes bigger than 7
|
||||
if (gLandToolSize > MAX_TOOL_SIZE_WITH_SPRITE)
|
||||
if (gLandToolSize > kLandToolMaximumSizeWithSprite)
|
||||
{
|
||||
auto ft = Formatter();
|
||||
ft.Add<uint16_t>(gLandToolSize);
|
||||
@@ -393,8 +393,8 @@ private:
|
||||
void InputSize()
|
||||
{
|
||||
Formatter ft;
|
||||
ft.Add<int16_t>(MINIMUM_TOOL_SIZE);
|
||||
ft.Add<int16_t>(MAXIMUM_TOOL_SIZE);
|
||||
ft.Add<uint16_t>(kLandToolMinimumSize);
|
||||
ft.Add<uint16_t>(kLandToolMaximumSize);
|
||||
WindowTextInputOpen(this, WIDX_PREVIEW, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, ft, STR_NONE, STR_NONE, 3);
|
||||
}
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ public:
|
||||
break;
|
||||
_activeTool = 2;
|
||||
// Prevent mountain tool size.
|
||||
_landRightsToolSize = std::max<uint16_t>(MINIMUM_TOOL_SIZE, _landRightsToolSize);
|
||||
_landRightsToolSize = std::max<uint16_t>(kLandToolMinimumSize, _landRightsToolSize);
|
||||
ShowGridlines();
|
||||
ShowLandRights();
|
||||
ShowConstructionRights();
|
||||
@@ -313,13 +313,13 @@ public:
|
||||
break;
|
||||
case WIDX_LAND_TOOL_SMALLER:
|
||||
// Decrement land rights tool size
|
||||
_landRightsToolSize = std::max(MINIMUM_TOOL_SIZE, _landRightsToolSize - 1);
|
||||
_landRightsToolSize = std::max<uint16_t>(kLandToolMinimumSize, _landRightsToolSize - 1);
|
||||
|
||||
Invalidate();
|
||||
break;
|
||||
case WIDX_LAND_TOOL_LARGER:
|
||||
// Increment land rights tool size
|
||||
_landRightsToolSize = std::min(MAXIMUM_TOOL_SIZE, _landRightsToolSize + 1);
|
||||
_landRightsToolSize = std::min<uint16_t>(kLandToolMaximumSize, _landRightsToolSize + 1);
|
||||
|
||||
Invalidate();
|
||||
break;
|
||||
@@ -616,7 +616,7 @@ public:
|
||||
int32_t size = strtol(textStr.c_str(), &end, 10);
|
||||
if (*end == '\0')
|
||||
{
|
||||
size = std::clamp(size, MINIMUM_TOOL_SIZE, MAXIMUM_TOOL_SIZE);
|
||||
size = std::clamp<uint16_t>(size, kLandToolMinimumSize, kLandToolMaximumSize);
|
||||
_landRightsToolSize = size;
|
||||
Invalidate();
|
||||
}
|
||||
@@ -865,7 +865,7 @@ public:
|
||||
+ ScreenCoordsXY{ window_map_widgets[WIDX_LAND_TOOL].midX(), window_map_widgets[WIDX_LAND_TOOL].midY() };
|
||||
|
||||
// Draw land tool size
|
||||
if (WidgetIsActiveTool(*this, WIDX_SET_LAND_RIGHTS) && _landRightsToolSize > MAX_TOOL_SIZE_WITH_SPRITE)
|
||||
if (WidgetIsActiveTool(*this, WIDX_SET_LAND_RIGHTS) && _landRightsToolSize > kLandToolMaximumSizeWithSprite)
|
||||
{
|
||||
auto ft = Formatter();
|
||||
ft.Add<uint16_t>(_landRightsToolSize);
|
||||
@@ -1326,8 +1326,8 @@ private:
|
||||
void InputLandSize()
|
||||
{
|
||||
Formatter ft;
|
||||
ft.Add<int16_t>(MINIMUM_TOOL_SIZE);
|
||||
ft.Add<int16_t>(MAXIMUM_TOOL_SIZE);
|
||||
ft.Add<uint16_t>(kLandToolMinimumSize);
|
||||
ft.Add<uint16_t>(kLandToolMaximumSize);
|
||||
TextInputOpen(WIDX_LAND_TOOL, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, ft, STR_NONE, STR_NONE, 3);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,11 +86,11 @@ public:
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_DECREMENT:
|
||||
gLandToolSize = std::max(MINIMUM_TOOL_SIZE, gLandToolSize - 1);
|
||||
gLandToolSize = std::max<uint16_t>(kLandToolMinimumSize, gLandToolSize - 1);
|
||||
Invalidate();
|
||||
break;
|
||||
case WIDX_INCREMENT:
|
||||
gLandToolSize = std::min(MAXIMUM_TOOL_SIZE, gLandToolSize + 1);
|
||||
gLandToolSize = std::min<uint16_t>(kLandToolMaximumSize, gLandToolSize + 1);
|
||||
Invalidate();
|
||||
break;
|
||||
}
|
||||
@@ -109,8 +109,8 @@ public:
|
||||
{
|
||||
int32_t size;
|
||||
size = res.value();
|
||||
size = std::max(MINIMUM_TOOL_SIZE, size);
|
||||
size = std::min(MAXIMUM_TOOL_SIZE, size);
|
||||
size = std::max<uint16_t>(kLandToolMinimumSize, size);
|
||||
size = std::min<uint16_t>(kLandToolMaximumSize, size);
|
||||
gLandToolSize = size;
|
||||
Invalidate();
|
||||
}
|
||||
@@ -136,7 +136,7 @@ public:
|
||||
DrawWidgets(dpi);
|
||||
|
||||
// Draw number for tool sizes bigger than 7
|
||||
if (gLandToolSize > MAX_TOOL_SIZE_WITH_SPRITE)
|
||||
if (gLandToolSize > kLandToolMaximumSizeWithSprite)
|
||||
{
|
||||
auto screenCoords = ScreenCoordsXY{ windowPos.x + PatrolAreaWidgets[WIDX_PREVIEW].midX(),
|
||||
windowPos.y + PatrolAreaWidgets[WIDX_PREVIEW].midY() };
|
||||
@@ -257,8 +257,8 @@ private:
|
||||
void InputSize()
|
||||
{
|
||||
Formatter ft;
|
||||
ft.Add<int16_t>(MINIMUM_TOOL_SIZE);
|
||||
ft.Add<int16_t>(MAXIMUM_TOOL_SIZE);
|
||||
ft.Add<uint16_t>(kLandToolMinimumSize);
|
||||
ft.Add<uint16_t>(kLandToolMaximumSize);
|
||||
WindowTextInputOpen(this, WIDX_PREVIEW, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, ft, STR_NONE, STR_NONE, 3);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,8 +80,8 @@ public:
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_PREVIEW:
|
||||
ft.Add<int16_t>(MINIMUM_TOOL_SIZE);
|
||||
ft.Add<int16_t>(MAXIMUM_TOOL_SIZE);
|
||||
ft.Add<uint16_t>(kLandToolMinimumSize);
|
||||
ft.Add<uint16_t>(kLandToolMaximumSize);
|
||||
maxLength = 3;
|
||||
break;
|
||||
}
|
||||
@@ -120,13 +120,13 @@ public:
|
||||
{
|
||||
case WIDX_DECREMENT:
|
||||
// Decrement land tool size, if it stays within the limit
|
||||
gWindowSceneryScatterSize = std::max(MINIMUM_TOOL_SIZE, gWindowSceneryScatterSize - 1);
|
||||
gWindowSceneryScatterSize = std::max<uint16_t>(kLandToolMinimumSize, gWindowSceneryScatterSize - 1);
|
||||
Invalidate();
|
||||
break;
|
||||
|
||||
case WIDX_INCREMENT:
|
||||
// Increment land tool size, if it stays within the limit
|
||||
gWindowSceneryScatterSize = std::min(MAXIMUM_TOOL_SIZE, gWindowSceneryScatterSize + 1);
|
||||
gWindowSceneryScatterSize = std::min<uint16_t>(kLandToolMaximumSize, gWindowSceneryScatterSize + 1);
|
||||
Invalidate();
|
||||
break;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public:
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_PREVIEW:
|
||||
gWindowSceneryScatterSize = std::clamp<int32_t>(res.value(), MINIMUM_TOOL_SIZE, MAXIMUM_TOOL_SIZE);
|
||||
gWindowSceneryScatterSize = std::clamp<int32_t>(res.value(), kLandToolMinimumSize, kLandToolMaximumSize);
|
||||
break;
|
||||
}
|
||||
Invalidate();
|
||||
@@ -181,7 +181,7 @@ public:
|
||||
WindowDrawWidgets(*this, dpi);
|
||||
|
||||
// Draw area as a number for tool sizes bigger than 7
|
||||
if (gWindowSceneryScatterSize > MAX_TOOL_SIZE_WITH_SPRITE)
|
||||
if (gWindowSceneryScatterSize > kLandToolMaximumSizeWithSprite)
|
||||
{
|
||||
const auto& preview = widgets[WIDX_PREVIEW];
|
||||
const auto screenCoords = ScreenCoordsXY{ windowPos.x + preview.midX(), windowPos.y + preview.midY() };
|
||||
|
||||
@@ -86,14 +86,14 @@ public:
|
||||
{
|
||||
case WIDX_DECREMENT:
|
||||
// Decrement land tool size
|
||||
gLandToolSize = std::max(MINIMUM_TOOL_SIZE, gLandToolSize - 1);
|
||||
gLandToolSize = std::max<uint16_t>(kLandToolMinimumSize, gLandToolSize - 1);
|
||||
|
||||
// Invalidate the window
|
||||
Invalidate();
|
||||
break;
|
||||
case WIDX_INCREMENT:
|
||||
// Increment land tool size
|
||||
gLandToolSize = std::min(MAXIMUM_TOOL_SIZE, gLandToolSize + 1);
|
||||
gLandToolSize = std::min<uint16_t>(kLandToolMaximumSize, gLandToolSize + 1);
|
||||
|
||||
// Invalidate the window
|
||||
Invalidate();
|
||||
@@ -124,8 +124,8 @@ public:
|
||||
size = strtol(textStr.c_str(), &end, 10);
|
||||
if (*end == '\0')
|
||||
{
|
||||
size = std::max(MINIMUM_TOOL_SIZE, size);
|
||||
size = std::min(MAXIMUM_TOOL_SIZE, size);
|
||||
size = std::max<uint16_t>(kLandToolMinimumSize, size);
|
||||
size = std::min<uint16_t>(kLandToolMaximumSize, size);
|
||||
gLandToolSize = size;
|
||||
|
||||
Invalidate();
|
||||
@@ -148,7 +148,7 @@ public:
|
||||
|
||||
DrawWidgets(dpi);
|
||||
// Draw number for tool sizes bigger than 7
|
||||
if (gLandToolSize > MAX_TOOL_SIZE_WITH_SPRITE)
|
||||
if (gLandToolSize > kLandToolMaximumSizeWithSprite)
|
||||
{
|
||||
auto ft = Formatter();
|
||||
ft.Add<uint16_t>(gLandToolSize);
|
||||
@@ -186,8 +186,8 @@ private:
|
||||
void InputSize()
|
||||
{
|
||||
Formatter ft;
|
||||
ft.Add<int16_t>(MINIMUM_TOOL_SIZE);
|
||||
ft.Add<int16_t>(MAXIMUM_TOOL_SIZE);
|
||||
ft.Add<uint16_t>(kLandToolMinimumSize);
|
||||
ft.Add<uint16_t>(kLandToolMaximumSize);
|
||||
WindowTextInputOpen(this, WIDX_PREVIEW, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, ft, STR_NONE, STR_NONE, 3);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user