2014-11-02 09:39:01 +01:00
|
|
|
/*****************************************************************************
|
2024-01-01 12:52:28 +01:00
|
|
|
* Copyright (c) 2014-2024 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-11-02 09:39:01 +01:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
|
|
|
#include <openrct2-ui/windows/Window.h>
|
2018-03-29 11:17:54 +02:00
|
|
|
#include <openrct2/Context.h>
|
2017-11-30 18:17:06 +01:00
|
|
|
#include <openrct2/Game.h>
|
2024-01-22 16:03:39 +01:00
|
|
|
#include <openrct2/GameState.h>
|
2022-08-11 00:00:58 +02:00
|
|
|
#include <openrct2/actions/RideDemolishAction.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/drawing/Drawing.h>
|
2021-12-12 00:06:06 +01:00
|
|
|
#include <openrct2/localisation/Formatter.h>
|
2018-01-06 18:32:25 +01:00
|
|
|
#include <openrct2/localisation/Localisation.h>
|
2017-10-08 22:15:41 +02:00
|
|
|
#include <openrct2/windows/Intent.h>
|
2018-03-29 11:17:54 +02:00
|
|
|
#include <openrct2/world/Park.h>
|
2014-11-02 09:39:01 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
namespace OpenRCT2::Ui::Windows
|
|
|
|
{
|
|
|
|
static constexpr int32_t WW = 200;
|
|
|
|
static constexpr int32_t WH = 100;
|
2014-11-02 09:39:01 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// clang-format off
|
2021-12-14 19:26:27 +01:00
|
|
|
enum WindowRideDemolishWidgetIdx
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
2021-12-14 19:26:27 +01:00
|
|
|
WIDX_DEMOLISH,
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_CANCEL
|
2014-11-02 09:39:01 +01:00
|
|
|
};
|
|
|
|
|
2022-12-24 16:50:29 +01:00
|
|
|
static Widget window_ride_demolish_widgets[] =
|
2021-12-14 19:26:27 +01:00
|
|
|
{
|
2020-07-21 17:38:57 +02:00
|
|
|
WINDOW_SHIM_WHITE(STR_DEMOLISH_RIDE, WW, WH),
|
2020-11-27 04:14:20 +01:00
|
|
|
MakeWidget({ 10, WH - 22}, {85, 14}, WindowWidgetType::Button, WindowColour::Primary, STR_DEMOLISH ),
|
|
|
|
MakeWidget({WW - 95, WH - 22}, {85, 14}, WindowWidgetType::Button, WindowColour::Primary, STR_SAVE_PROMPT_CANCEL),
|
2024-03-09 15:15:45 +01:00
|
|
|
kWidgetsEnd,
|
2014-11-02 09:39:01 +01:00
|
|
|
};
|
2024-03-10 14:52:35 +01:00
|
|
|
// clang-format on
|
2018-03-29 11:17:54 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
class DemolishRidePromptWindow final : public Window
|
2021-12-13 01:20:12 +01:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
money64 _demolishRideCost;
|
2021-12-13 01:20:12 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
public:
|
|
|
|
void SetRide(const Ride& currentRide)
|
|
|
|
{
|
|
|
|
rideId = currentRide.id;
|
|
|
|
_demolishRideCost = -RideGetRefundPrice(currentRide);
|
|
|
|
}
|
2014-11-02 09:39:01 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnOpen() override
|
|
|
|
{
|
|
|
|
widgets = window_ride_demolish_widgets;
|
|
|
|
WindowInitScrollWidgets(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnMouseUp(WidgetIndex widgetIndex) override
|
2021-12-13 01:20:12 +01:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
switch (widgetIndex)
|
2021-12-13 01:20:12 +01:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
case WIDX_DEMOLISH:
|
|
|
|
{
|
|
|
|
auto gameAction = RideDemolishAction(rideId, RIDE_MODIFY_DEMOLISH);
|
|
|
|
GameActions::Execute(&gameAction);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WIDX_CANCEL:
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
Close();
|
|
|
|
break;
|
2021-12-13 01:20:12 +01:00
|
|
|
}
|
|
|
|
}
|
2017-09-06 16:09:35 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnDraw(DrawPixelInfo& dpi) override
|
|
|
|
{
|
|
|
|
WindowDrawWidgets(*this, dpi);
|
|
|
|
|
|
|
|
auto currentRide = GetRide(rideId);
|
|
|
|
if (currentRide != nullptr)
|
|
|
|
{
|
2024-03-26 21:35:55 +01:00
|
|
|
auto stringId = (GetGameState().Park.Flags & PARK_FLAGS_NO_MONEY) ? STR_DEMOLISH_RIDE_ID
|
|
|
|
: STR_DEMOLISH_RIDE_ID_MONEY;
|
2024-03-10 14:52:35 +01:00
|
|
|
auto ft = Formatter();
|
|
|
|
currentRide->FormatNameTo(ft);
|
|
|
|
ft.Add<money64>(_demolishRideCost);
|
|
|
|
|
|
|
|
ScreenCoordsXY stringCoords(windowPos.x + WW / 2, windowPos.y + (WH / 2) - 3);
|
|
|
|
DrawTextWrapped(dpi, stringCoords, WW - 4, stringId, ft, { TextAlignment::CENTRE });
|
|
|
|
}
|
|
|
|
}
|
2021-12-13 01:20:12 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnResize() override
|
2021-12-13 01:20:12 +01:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
ResizeFrame();
|
2021-12-13 01:20:12 +01:00
|
|
|
}
|
2024-03-10 14:52:35 +01:00
|
|
|
};
|
2023-05-19 10:17:38 +02:00
|
|
|
|
2024-03-17 07:37:46 +01:00
|
|
|
WindowBase* RideDemolishPromptOpen(const Ride& ride)
|
2023-05-19 10:17:38 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
WindowBase* w;
|
|
|
|
DemolishRidePromptWindow* newWindow;
|
2018-03-29 11:17:54 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
w = WindowFindByClass(WindowClass::DemolishRidePrompt);
|
|
|
|
if (w != nullptr)
|
|
|
|
{
|
|
|
|
auto windowPos = w->windowPos;
|
|
|
|
WindowClose(*w);
|
|
|
|
newWindow = WindowCreate<DemolishRidePromptWindow>(
|
|
|
|
WindowClass::DemolishRidePrompt, windowPos, WW, WH, WF_TRANSPARENT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newWindow = WindowCreate<DemolishRidePromptWindow>(
|
|
|
|
WindowClass::DemolishRidePrompt, WW, WH, WF_CENTRE_SCREEN | WF_TRANSPARENT);
|
|
|
|
}
|
2018-03-29 11:17:54 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
newWindow->SetRide(ride);
|
2019-07-21 14:50:01 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
return newWindow;
|
|
|
|
}
|
|
|
|
} // namespace OpenRCT2::Ui::Windows
|