mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-02-02 19:56:13 +01:00
Move clear scenery tool functions from TopToolbar.cpp into ClearScenery
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
#include <openrct2-ui/windows/Window.h>
|
||||
#include <openrct2/Context.h>
|
||||
#include <openrct2/GameState.h>
|
||||
#include <openrct2/Input.h>
|
||||
#include <openrct2/actions/ClearAction.h>
|
||||
#include <openrct2/localisation/Formatter.h>
|
||||
#include <openrct2/world/Park.h>
|
||||
#include <openrct2/world/Scenery.h>
|
||||
@@ -30,7 +32,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
WIDX_LARGE_SCENERY,
|
||||
WIDX_FOOTPATH
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
static constexpr StringId WINDOW_TITLE = STR_CLEAR_SCENERY;
|
||||
static constexpr int32_t WW = 98;
|
||||
static constexpr int32_t WH = 94;
|
||||
@@ -204,6 +206,100 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
ResizeFrame();
|
||||
}
|
||||
|
||||
ClearAction GetClearAction()
|
||||
{
|
||||
auto range = MapRange(gMapSelectPositionA.x, gMapSelectPositionA.y, gMapSelectPositionB.x, gMapSelectPositionB.y);
|
||||
|
||||
ClearableItems itemsToClear = 0;
|
||||
|
||||
if (gClearSmallScenery)
|
||||
itemsToClear |= CLEARABLE_ITEMS::SCENERY_SMALL;
|
||||
if (gClearLargeScenery)
|
||||
itemsToClear |= CLEARABLE_ITEMS::SCENERY_LARGE;
|
||||
if (gClearFootpath)
|
||||
itemsToClear |= CLEARABLE_ITEMS::SCENERY_FOOTPATH;
|
||||
|
||||
return ClearAction(range, itemsToClear);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0068E213
|
||||
*/
|
||||
void ToolUpdateSceneryClear(const ScreenCoordsXY& screenPos)
|
||||
{
|
||||
auto action = GetClearAction();
|
||||
auto result = GameActions::Query(&action);
|
||||
auto cost = (result.Error == GameActions::Status::Ok ? result.Cost : kMoney64Undefined);
|
||||
if (gClearSceneryCost != cost)
|
||||
{
|
||||
gClearSceneryCost = cost;
|
||||
WindowInvalidateByClass(WindowClass::ClearScenery);
|
||||
}
|
||||
}
|
||||
|
||||
void OnToolUpdate(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override
|
||||
{
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_BACKGROUND:
|
||||
ToolUpdateSceneryClear(screenCoords);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OnToolDown(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override
|
||||
{
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_BACKGROUND:
|
||||
if (gMapSelectFlags & MAP_SELECT_FLAG_ENABLE)
|
||||
{
|
||||
auto action = GetClearAction();
|
||||
GameActions::Execute(&action);
|
||||
gCurrentToolId = Tool::Crosshair;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OnToolDrag(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override
|
||||
{
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_BACKGROUND:
|
||||
if (WindowFindByClass(WindowClass::Error) == nullptr && (gMapSelectFlags & MAP_SELECT_FLAG_ENABLE))
|
||||
{
|
||||
auto action = GetClearAction();
|
||||
GameActions::Execute(&action);
|
||||
gCurrentToolId = Tool::Crosshair;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OnToolUp(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override
|
||||
{
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_BACKGROUND:
|
||||
MapInvalidateSelectionRect();
|
||||
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
|
||||
gCurrentToolId = Tool::Crosshair;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OnToolAbort(WidgetIndex widgetIndex) override
|
||||
{
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_BACKGROUND:
|
||||
HideGridlines();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
WindowBase* ClearSceneryOpen()
|
||||
@@ -220,4 +316,24 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0066CD0C
|
||||
*/
|
||||
void ToggleClearSceneryWindow()
|
||||
{
|
||||
if ((InputTestFlag(INPUT_FLAG_TOOL_ACTIVE) && gCurrentToolWidget.window_classification == WindowClass::ClearScenery
|
||||
&& gCurrentToolWidget.widget_index == WIDX_BACKGROUND))
|
||||
{
|
||||
ToolCancel();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowGridlines();
|
||||
auto* toolWindow = ContextOpenWindow(WindowClass::ClearScenery);
|
||||
ToolSet(*toolWindow, WIDX_BACKGROUND, Tool::Crosshair);
|
||||
InputSetFlag(INPUT_FLAG_6, true);
|
||||
}
|
||||
}
|
||||
} // namespace OpenRCT2::Ui::Windows
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <openrct2/OpenRCT2.h>
|
||||
#include <openrct2/ParkImporter.h>
|
||||
#include <openrct2/Version.h>
|
||||
#include <openrct2/actions/ClearAction.h>
|
||||
#include <openrct2/actions/GameSetSpeedAction.h>
|
||||
#include <openrct2/actions/LoadOrQuitAction.h>
|
||||
#include <openrct2/actions/PauseToggleAction.h>
|
||||
@@ -278,7 +277,6 @@ namespace OpenRCT2::Ui::Windows
|
||||
class TopToolbar final : public Window
|
||||
{
|
||||
private:
|
||||
bool _landToolBlocked{ false };
|
||||
bool _waitingForPause{ false };
|
||||
|
||||
void InitViewMenu(Widget& widget);
|
||||
@@ -328,58 +326,6 @@ namespace OpenRCT2::Ui::Windows
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0066CD0C
|
||||
*/
|
||||
void ToggleClearSceneryWindow(WidgetIndex widgetIndex)
|
||||
{
|
||||
if ((InputTestFlag(INPUT_FLAG_TOOL_ACTIVE) && gCurrentToolWidget.window_classification == WindowClass::TopToolbar
|
||||
&& gCurrentToolWidget.widget_index == WIDX_CLEAR_SCENERY))
|
||||
{
|
||||
ToolCancel();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowGridlines();
|
||||
ToolSet(*this, widgetIndex, Tool::Crosshair);
|
||||
InputSetFlag(INPUT_FLAG_6, true);
|
||||
ContextOpenWindow(WindowClass::ClearScenery);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0068E213
|
||||
*/
|
||||
void ToolUpdateSceneryClear(const ScreenCoordsXY& screenPos)
|
||||
{
|
||||
auto action = GetClearAction();
|
||||
auto result = GameActions::Query(&action);
|
||||
auto cost = (result.Error == GameActions::Status::Ok ? result.Cost : kMoney64Undefined);
|
||||
if (gClearSceneryCost != cost)
|
||||
{
|
||||
gClearSceneryCost = cost;
|
||||
WindowInvalidateByClass(WindowClass::ClearScenery);
|
||||
}
|
||||
}
|
||||
|
||||
ClearAction GetClearAction()
|
||||
{
|
||||
auto range = MapRange(gMapSelectPositionA.x, gMapSelectPositionA.y, gMapSelectPositionB.x, gMapSelectPositionB.y);
|
||||
|
||||
ClearableItems itemsToClear = 0;
|
||||
|
||||
if (gClearSmallScenery)
|
||||
itemsToClear |= CLEARABLE_ITEMS::SCENERY_SMALL;
|
||||
if (gClearLargeScenery)
|
||||
itemsToClear |= CLEARABLE_ITEMS::SCENERY_LARGE;
|
||||
if (gClearFootpath)
|
||||
itemsToClear |= CLEARABLE_ITEMS::SCENERY_FOOTPATH;
|
||||
|
||||
return ClearAction(range, itemsToClear);
|
||||
}
|
||||
|
||||
public:
|
||||
void OnMouseUp(WidgetIndex widgetIndex) override
|
||||
{
|
||||
@@ -404,7 +350,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
WindowZoomIn(*mainWindow, false);
|
||||
break;
|
||||
case WIDX_CLEAR_SCENERY:
|
||||
ToggleClearSceneryWindow(WIDX_CLEAR_SCENERY);
|
||||
ToggleClearSceneryWindow();
|
||||
break;
|
||||
case WIDX_LAND:
|
||||
ToggleLandWindow();
|
||||
@@ -619,9 +565,6 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_CLEAR_SCENERY:
|
||||
ToolUpdateSceneryClear(screenCoords);
|
||||
break;
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
default:
|
||||
auto& customTool = OpenRCT2::Scripting::ActiveCustomTool;
|
||||
@@ -638,14 +581,6 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_CLEAR_SCENERY:
|
||||
if (gMapSelectFlags & MAP_SELECT_FLAG_ENABLE)
|
||||
{
|
||||
auto action = GetClearAction();
|
||||
GameActions::Execute(&action);
|
||||
gCurrentToolId = Tool::Crosshair;
|
||||
}
|
||||
break;
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
default:
|
||||
auto& customTool = OpenRCT2::Scripting::ActiveCustomTool;
|
||||
@@ -662,14 +597,6 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_CLEAR_SCENERY:
|
||||
if (WindowFindByClass(WindowClass::Error) == nullptr && (gMapSelectFlags & MAP_SELECT_FLAG_ENABLE))
|
||||
{
|
||||
auto action = GetClearAction();
|
||||
GameActions::Execute(&action);
|
||||
gCurrentToolId = Tool::Crosshair;
|
||||
}
|
||||
break;
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
default:
|
||||
auto& customTool = OpenRCT2::Scripting::ActiveCustomTool;
|
||||
@@ -684,14 +611,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
void OnToolUp(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override
|
||||
{
|
||||
_landToolBlocked = false;
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_CLEAR_SCENERY:
|
||||
MapInvalidateSelectionRect();
|
||||
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
|
||||
gCurrentToolId = Tool::Crosshair;
|
||||
break;
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
default:
|
||||
auto& customTool = OpenRCT2::Scripting::ActiveCustomTool;
|
||||
@@ -708,9 +629,6 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_CLEAR_SCENERY:
|
||||
HideGridlines();
|
||||
break;
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
default:
|
||||
auto& customTool = OpenRCT2::Scripting::ActiveCustomTool;
|
||||
|
||||
@@ -43,7 +43,10 @@ namespace OpenRCT2::Ui::Windows
|
||||
void WindowCampaignRefreshRides();
|
||||
WindowBase* ChangelogOpen(int personality);
|
||||
WindowBase* CheatsOpen();
|
||||
|
||||
WindowBase* ClearSceneryOpen();
|
||||
void ToggleClearSceneryWindow();
|
||||
|
||||
WindowBase* CustomCurrencyOpen();
|
||||
WindowBase* DebugPaintOpen();
|
||||
WindowBase* EditorInventionsListOpen();
|
||||
|
||||
Reference in New Issue
Block a user