From bb6e26570079c291ed3ba696156c714a96af1709 Mon Sep 17 00:00:00 2001 From: Brian Kolstad Date: Sun, 12 Dec 2021 19:20:12 -0500 Subject: [PATCH 1/2] Refactor window to class: DemolishRidePrompt --- .../windows/DemolishRidePrompt.cpp | 243 ++++++++++-------- 1 file changed, 133 insertions(+), 110 deletions(-) mode change 100644 => 100755 src/openrct2-ui/windows/DemolishRidePrompt.cpp diff --git a/src/openrct2-ui/windows/DemolishRidePrompt.cpp b/src/openrct2-ui/windows/DemolishRidePrompt.cpp old mode 100644 new mode 100755 index a48a278e4c..1bef9d3c0e --- a/src/openrct2-ui/windows/DemolishRidePrompt.cpp +++ b/src/openrct2-ui/windows/DemolishRidePrompt.cpp @@ -19,9 +19,12 @@ static constexpr const int32_t WW = 200; static constexpr const int32_t WH = 100; -static money32 _demolishRideCost; - // clang-format off +enum WindowRideDemolishPage { + WINDOW_RIDE_DEMOLISH, + WINDOW_RIDE_REFURBISH, +}; + enum WindowRideDemolishWidgetIdx { WIDX_BACKGROUND, WIDX_TITLE, @@ -46,147 +49,167 @@ static rct_widget window_ride_refurbish_widgets[] = { WIDGETS_END, }; -static void WindowRideDemolishMouseup(rct_window *w, rct_widgetindex widgetIndex); -static void WindowRideDemolishPaint(rct_window *w, rct_drawpixelinfo *dpi); -static void WindowRideRefurbishMouseup(rct_window *w, rct_widgetindex widgetIndex); -static void WindowRideRefurbishPaint(rct_window *w, rct_drawpixelinfo *dpi); - -//0x0098E2E4 -static rct_window_event_list window_ride_demolish_events([](auto& events) +class DemolishRidePromptWindow final : public Window { - events.mouse_up = &WindowRideDemolishMouseup; - events.paint = &WindowRideDemolishPaint; -}); -// clang-format on + money32 _demolishRideCost; -static rct_window_event_list window_ride_refurbish_events([](auto& events) { - events.mouse_up = &WindowRideRefurbishMouseup; - events.paint = &WindowRideRefurbishPaint; -}); +public: + void SetPageAndCurrentRide(int32_t p, Ride* currentRide) + { + page = p; + rideId = currentRide->id; + _demolishRideCost = -ride_get_refund_price(currentRide); + + switch (page) + { + case WINDOW_RIDE_DEMOLISH: + widgets = window_ride_demolish_widgets; + enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_CANCEL) | (1ULL << WIDX_DEMOLISH); + break; + case WINDOW_RIDE_REFURBISH: + widgets = window_ride_refurbish_widgets; + enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_CANCEL) | (1ULL << WIDX_REFURBISH); + break; + } + WindowInitScrollWidgets(this); + } + + void OnMouseUp(rct_widgetindex widgetIndex) override + { + switch (page) + { + case WINDOW_RIDE_DEMOLISH: + OnMouseUpDemolish(widgetIndex); + break; + case WINDOW_RIDE_REFURBISH: + OnMouseUpRefurbish(widgetIndex); + break; + } + } + + void OnDraw(rct_drawpixelinfo& dpi) override + { + switch (page) + { + case WINDOW_RIDE_DEMOLISH: + OnDrawDemolish(&dpi); + break; + case WINDOW_RIDE_REFURBISH: + OnDrawRefurbish(&dpi); + break; + } + } + +private: + void OnMouseUpDemolish(rct_widgetindex widgetIndex) + { + switch (widgetIndex) + { + case WIDX_DEMOLISH: + { + auto* currentRide = get_ride(rideId); + ride_action_modify(currentRide, RIDE_MODIFY_DEMOLISH, GAME_COMMAND_FLAG_APPLY); + break; + } + case WIDX_CANCEL: + case WIDX_CLOSE: + Close(); + break; + } + } + + void OnMouseUpRefurbish(rct_widgetindex widgetIndex) + { + switch (widgetIndex) + { + case WIDX_REFURBISH: + { + auto* currentRide = get_ride(rideId); + ride_action_modify(currentRide, RIDE_MODIFY_RENEW, GAME_COMMAND_FLAG_APPLY); + break; + } + case WIDX_CANCEL: + case WIDX_CLOSE: + Close(); + break; + } + } + + void OnDrawDemolish(rct_drawpixelinfo* dpi) + { + WindowDrawWidgets(this, dpi); + + auto currentRide = get_ride(rideId); + if (currentRide != nullptr) + { + auto stringId = (gParkFlags & PARK_FLAGS_NO_MONEY) ? STR_DEMOLISH_RIDE_ID : STR_DEMOLISH_RIDE_ID_MONEY; + auto ft = Formatter(); + currentRide->FormatNameTo(ft); + ft.Add(_demolishRideCost); + + ScreenCoordsXY stringCoords(windowPos.x + WW / 2, windowPos.y + (WH / 2) - 3); + DrawTextWrapped(dpi, stringCoords, WW - 4, stringId, ft, { TextAlignment::CENTRE }); + } + } + + void OnDrawRefurbish(rct_drawpixelinfo* dpi) + { + WindowDrawWidgets(this, dpi); + + auto currentRide = get_ride(rideId); + if (currentRide != nullptr) + { + auto stringId = (gParkFlags & PARK_FLAGS_NO_MONEY) ? STR_REFURBISH_RIDE_ID_NO_MONEY : STR_REFURBISH_RIDE_ID_MONEY; + auto ft = Formatter(); + currentRide->FormatNameTo(ft); + ft.Add(_demolishRideCost / 2); + + ScreenCoordsXY stringCoords(windowPos.x + WW / 2, windowPos.y + (WH / 2) - 3); + DrawTextWrapped(dpi, stringCoords, WW - 4, stringId, ft, { TextAlignment::CENTRE }); + } + } +}; -/** Based off of rct2: 0x006B486A */ rct_window* WindowRideDemolishPromptOpen(Ride* ride) { rct_window* w; + DemolishRidePromptWindow* newWindow; w = window_find_by_class(WC_DEMOLISH_RIDE_PROMPT); if (w != nullptr) { auto windowPos = w->windowPos; window_close(w); - w = WindowCreate(windowPos, WW, WH, &window_ride_demolish_events, WC_DEMOLISH_RIDE_PROMPT, WF_TRANSPARENT); + newWindow = WindowCreate(WC_DEMOLISH_RIDE_PROMPT, windowPos, WW, WH, WF_TRANSPARENT); } else { - w = WindowCreateCentred(WW, WH, &window_ride_demolish_events, WC_DEMOLISH_RIDE_PROMPT, WF_TRANSPARENT); + newWindow = WindowCreate(WC_DEMOLISH_RIDE_PROMPT, WW, WH, WF_CENTRE_SCREEN | WF_TRANSPARENT); } - w->widgets = window_ride_demolish_widgets; - w->enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_CANCEL) | (1ULL << WIDX_DEMOLISH); - WindowInitScrollWidgets(w); - w->rideId = ride->id; - _demolishRideCost = -ride_get_refund_price(ride); + newWindow->SetPageAndCurrentRide(WINDOW_RIDE_DEMOLISH, ride); - return w; + return newWindow; } rct_window* WindowRideRefurbishPromptOpen(Ride* ride) { rct_window* w; + DemolishRidePromptWindow* newWindow; w = window_find_by_class(WC_DEMOLISH_RIDE_PROMPT); if (w != nullptr) { auto windowPos = w->windowPos; window_close(w); - w = WindowCreate(windowPos, WW, WH, &window_ride_refurbish_events, WC_DEMOLISH_RIDE_PROMPT, WF_TRANSPARENT); + newWindow = WindowCreate(WC_DEMOLISH_RIDE_PROMPT, windowPos, WW, WH, WF_TRANSPARENT); } else { - w = WindowCreateCentred(WW, WH, &window_ride_refurbish_events, WC_DEMOLISH_RIDE_PROMPT, WF_TRANSPARENT); + newWindow = WindowCreate(WC_DEMOLISH_RIDE_PROMPT, WW, WH, WF_CENTRE_SCREEN | WF_TRANSPARENT); } - w->widgets = window_ride_refurbish_widgets; - w->enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_CANCEL) | (1ULL << WIDX_REFURBISH); - WindowInitScrollWidgets(w); - w->rideId = ride->id; - _demolishRideCost = -ride_get_refund_price(ride); + newWindow->SetPageAndCurrentRide(WINDOW_RIDE_REFURBISH, ride); - return w; -} - -/** - * - * rct2: 0x006B4933 - */ -static void WindowRideDemolishMouseup(rct_window* w, rct_widgetindex widgetIndex) -{ - switch (widgetIndex) - { - case WIDX_DEMOLISH: - { - auto ride = get_ride(w->rideId); - ride_action_modify(ride, RIDE_MODIFY_DEMOLISH, GAME_COMMAND_FLAG_APPLY); - break; - } - case WIDX_CANCEL: - case WIDX_CLOSE: - window_close(w); - break; - } -} - -static void WindowRideRefurbishMouseup(rct_window* w, rct_widgetindex widgetIndex) -{ - switch (widgetIndex) - { - case WIDX_REFURBISH: - { - auto ride = get_ride(w->rideId); - ride_action_modify(ride, RIDE_MODIFY_RENEW, GAME_COMMAND_FLAG_APPLY); - break; - } - case WIDX_CANCEL: - case WIDX_CLOSE: - window_close(w); - break; - } -} - -/** - * - * rct2: 0x006B48E5 - */ -static void WindowRideDemolishPaint(rct_window* w, rct_drawpixelinfo* dpi) -{ - WindowDrawWidgets(w, dpi); - - auto ride = get_ride(w->rideId); - if (ride != nullptr) - { - auto stringId = (gParkFlags & PARK_FLAGS_NO_MONEY) ? STR_DEMOLISH_RIDE_ID : STR_DEMOLISH_RIDE_ID_MONEY; - auto ft = Formatter(); - ride->FormatNameTo(ft); - ft.Add(_demolishRideCost); - - ScreenCoordsXY stringCoords(w->windowPos.x + WW / 2, w->windowPos.y + (WH / 2) - 3); - DrawTextWrapped(dpi, stringCoords, WW - 4, stringId, ft, { TextAlignment::CENTRE }); - } -} - -static void WindowRideRefurbishPaint(rct_window* w, rct_drawpixelinfo* dpi) -{ - WindowDrawWidgets(w, dpi); - - auto ride = get_ride(w->rideId); - if (ride != nullptr) - { - auto stringId = (gParkFlags & PARK_FLAGS_NO_MONEY) ? STR_REFURBISH_RIDE_ID_NO_MONEY : STR_REFURBISH_RIDE_ID_MONEY; - auto ft = Formatter(); - ride->FormatNameTo(ft); - ft.Add(_demolishRideCost / 2); - - ScreenCoordsXY stringCoords(w->windowPos.x + WW / 2, w->windowPos.y + (WH / 2) - 3); - DrawTextWrapped(dpi, stringCoords, WW - 4, stringId, ft, { TextAlignment::CENTRE }); - } + return newWindow; } From 35a56c0810779ddc92567847816027a15d170f35 Mon Sep 17 00:00:00 2001 From: Brian Kolstad Date: Tue, 14 Dec 2021 13:26:27 -0500 Subject: [PATCH 2/2] Split demolish and refurbish into seperate windows --- src/openrct2-ui/libopenrct2ui.vcxproj | 3 +- .../windows/DemolishRidePrompt.cpp | 133 +++--------------- .../windows/RefurbishRidePrompt.cpp | 114 +++++++++++++++ 3 files changed, 132 insertions(+), 118 deletions(-) mode change 100644 => 100755 src/openrct2-ui/libopenrct2ui.vcxproj create mode 100755 src/openrct2-ui/windows/RefurbishRidePrompt.cpp diff --git a/src/openrct2-ui/libopenrct2ui.vcxproj b/src/openrct2-ui/libopenrct2ui.vcxproj old mode 100644 new mode 100755 index 909897d98b..b8a3649b3c --- a/src/openrct2-ui/libopenrct2ui.vcxproj +++ b/src/openrct2-ui/libopenrct2ui.vcxproj @@ -157,6 +157,7 @@ + @@ -215,4 +216,4 @@ - + \ No newline at end of file diff --git a/src/openrct2-ui/windows/DemolishRidePrompt.cpp b/src/openrct2-ui/windows/DemolishRidePrompt.cpp index 1bef9d3c0e..cecab7e369 100755 --- a/src/openrct2-ui/windows/DemolishRidePrompt.cpp +++ b/src/openrct2-ui/windows/DemolishRidePrompt.cpp @@ -20,88 +20,43 @@ static constexpr const int32_t WW = 200; static constexpr const int32_t WH = 100; // clang-format off -enum WindowRideDemolishPage { - WINDOW_RIDE_DEMOLISH, - WINDOW_RIDE_REFURBISH, -}; - -enum WindowRideDemolishWidgetIdx { +enum WindowRideDemolishWidgetIdx +{ WIDX_BACKGROUND, WIDX_TITLE, WIDX_CLOSE, - WIDX_DEMOLISH = 3, - WIDX_REFURBISH = 3, + WIDX_DEMOLISH, WIDX_CANCEL }; -// 0x009AEBA0 -static rct_widget window_ride_demolish_widgets[] = { +static rct_widget window_ride_demolish_widgets[] = +{ WINDOW_SHIM_WHITE(STR_DEMOLISH_RIDE, WW, WH), 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), WIDGETS_END, }; - -static rct_widget window_ride_refurbish_widgets[] = { - WINDOW_SHIM_WHITE(STR_REFURBISH_RIDE, WW, WH), - MakeWidget({ 10, WH - 22}, {85, 14}, WindowWidgetType::Button, WindowColour::Primary, STR_REFURBISH ), - MakeWidget({WW - 95, WH - 22}, {85, 14}, WindowWidgetType::Button, WindowColour::Primary, STR_SAVE_PROMPT_CANCEL), - WIDGETS_END, -}; +// clang-format on class DemolishRidePromptWindow final : public Window { money32 _demolishRideCost; public: - void SetPageAndCurrentRide(int32_t p, Ride* currentRide) + void SetRide(Ride* currentRide) { - page = p; rideId = currentRide->id; _demolishRideCost = -ride_get_refund_price(currentRide); + } - switch (page) - { - case WINDOW_RIDE_DEMOLISH: - widgets = window_ride_demolish_widgets; - enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_CANCEL) | (1ULL << WIDX_DEMOLISH); - break; - case WINDOW_RIDE_REFURBISH: - widgets = window_ride_refurbish_widgets; - enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_CANCEL) | (1ULL << WIDX_REFURBISH); - break; - } + void OnOpen() override + { + widgets = window_ride_demolish_widgets; + enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_CANCEL) | (1ULL << WIDX_DEMOLISH); WindowInitScrollWidgets(this); } void OnMouseUp(rct_widgetindex widgetIndex) override - { - switch (page) - { - case WINDOW_RIDE_DEMOLISH: - OnMouseUpDemolish(widgetIndex); - break; - case WINDOW_RIDE_REFURBISH: - OnMouseUpRefurbish(widgetIndex); - break; - } - } - - void OnDraw(rct_drawpixelinfo& dpi) override - { - switch (page) - { - case WINDOW_RIDE_DEMOLISH: - OnDrawDemolish(&dpi); - break; - case WINDOW_RIDE_REFURBISH: - OnDrawRefurbish(&dpi); - break; - } - } - -private: - void OnMouseUpDemolish(rct_widgetindex widgetIndex) { switch (widgetIndex) { @@ -118,26 +73,9 @@ private: } } - void OnMouseUpRefurbish(rct_widgetindex widgetIndex) + void OnDraw(rct_drawpixelinfo& dpi) override { - switch (widgetIndex) - { - case WIDX_REFURBISH: - { - auto* currentRide = get_ride(rideId); - ride_action_modify(currentRide, RIDE_MODIFY_RENEW, GAME_COMMAND_FLAG_APPLY); - break; - } - case WIDX_CANCEL: - case WIDX_CLOSE: - Close(); - break; - } - } - - void OnDrawDemolish(rct_drawpixelinfo* dpi) - { - WindowDrawWidgets(this, dpi); + WindowDrawWidgets(this, &dpi); auto currentRide = get_ride(rideId); if (currentRide != nullptr) @@ -148,24 +86,7 @@ private: ft.Add(_demolishRideCost); ScreenCoordsXY stringCoords(windowPos.x + WW / 2, windowPos.y + (WH / 2) - 3); - DrawTextWrapped(dpi, stringCoords, WW - 4, stringId, ft, { TextAlignment::CENTRE }); - } - } - - void OnDrawRefurbish(rct_drawpixelinfo* dpi) - { - WindowDrawWidgets(this, dpi); - - auto currentRide = get_ride(rideId); - if (currentRide != nullptr) - { - auto stringId = (gParkFlags & PARK_FLAGS_NO_MONEY) ? STR_REFURBISH_RIDE_ID_NO_MONEY : STR_REFURBISH_RIDE_ID_MONEY; - auto ft = Formatter(); - currentRide->FormatNameTo(ft); - ft.Add(_demolishRideCost / 2); - - ScreenCoordsXY stringCoords(windowPos.x + WW / 2, windowPos.y + (WH / 2) - 3); - DrawTextWrapped(dpi, stringCoords, WW - 4, stringId, ft, { TextAlignment::CENTRE }); + DrawTextWrapped(&dpi, stringCoords, WW - 4, stringId, ft, { TextAlignment::CENTRE }); } } }; @@ -187,29 +108,7 @@ rct_window* WindowRideDemolishPromptOpen(Ride* ride) newWindow = WindowCreate(WC_DEMOLISH_RIDE_PROMPT, WW, WH, WF_CENTRE_SCREEN | WF_TRANSPARENT); } - newWindow->SetPageAndCurrentRide(WINDOW_RIDE_DEMOLISH, ride); - - return newWindow; -} - -rct_window* WindowRideRefurbishPromptOpen(Ride* ride) -{ - rct_window* w; - DemolishRidePromptWindow* newWindow; - - w = window_find_by_class(WC_DEMOLISH_RIDE_PROMPT); - if (w != nullptr) - { - auto windowPos = w->windowPos; - window_close(w); - newWindow = WindowCreate(WC_DEMOLISH_RIDE_PROMPT, windowPos, WW, WH, WF_TRANSPARENT); - } - else - { - newWindow = WindowCreate(WC_DEMOLISH_RIDE_PROMPT, WW, WH, WF_CENTRE_SCREEN | WF_TRANSPARENT); - } - - newWindow->SetPageAndCurrentRide(WINDOW_RIDE_REFURBISH, ride); + newWindow->SetRide(ride); return newWindow; } diff --git a/src/openrct2-ui/windows/RefurbishRidePrompt.cpp b/src/openrct2-ui/windows/RefurbishRidePrompt.cpp new file mode 100755 index 0000000000..f7dea958c7 --- /dev/null +++ b/src/openrct2-ui/windows/RefurbishRidePrompt.cpp @@ -0,0 +1,114 @@ +/***************************************************************************** + * Copyright (c) 2014-2020 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +static constexpr const int32_t WW = 200; +static constexpr const int32_t WH = 100; + +// clang-format off +enum WindowRideRefurbishWidgetIdx +{ + WIDX_BACKGROUND, + WIDX_TITLE, + WIDX_CLOSE, + WIDX_REFURBISH, + WIDX_CANCEL +}; + +static rct_widget window_ride_refurbish_widgets[] = +{ + WINDOW_SHIM_WHITE(STR_REFURBISH_RIDE, WW, WH), + MakeWidget({ 10, WH - 22 }, { 85, 14 }, WindowWidgetType::Button, WindowColour::Primary, STR_REFURBISH), + MakeWidget({ WW - 95, WH - 22 }, { 85, 14 }, WindowWidgetType::Button, WindowColour::Primary, STR_SAVE_PROMPT_CANCEL), + WIDGETS_END, +}; +// clang-format on + +class RefurbishRidePromptWindow final : public Window +{ + money32 _demolishRideCost; + +public: + void SetRide(Ride* currentRide) + { + rideId = currentRide->id; + _demolishRideCost = -ride_get_refund_price(currentRide); + } + + void OnOpen() override + { + widgets = window_ride_refurbish_widgets; + enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_CANCEL) | (1ULL << WIDX_REFURBISH); + WindowInitScrollWidgets(this); + } + + void OnMouseUp(rct_widgetindex widgetIndex) override + { + switch (widgetIndex) + { + case WIDX_REFURBISH: + { + auto* currentRide = get_ride(rideId); + ride_action_modify(currentRide, RIDE_MODIFY_RENEW, GAME_COMMAND_FLAG_APPLY); + break; + } + case WIDX_CANCEL: + case WIDX_CLOSE: + Close(); + break; + } + } + + void OnDraw(rct_drawpixelinfo& dpi) override + { + WindowDrawWidgets(this, &dpi); + + auto currentRide = get_ride(rideId); + if (currentRide != nullptr) + { + auto stringId = (gParkFlags & PARK_FLAGS_NO_MONEY) ? STR_REFURBISH_RIDE_ID_NO_MONEY : STR_REFURBISH_RIDE_ID_MONEY; + auto ft = Formatter(); + currentRide->FormatNameTo(ft); + ft.Add(_demolishRideCost / 2); + + ScreenCoordsXY stringCoords(windowPos.x + WW / 2, windowPos.y + (WH / 2) - 3); + DrawTextWrapped(&dpi, stringCoords, WW - 4, stringId, ft, { TextAlignment::CENTRE }); + } + } +}; + +rct_window* WindowRideRefurbishPromptOpen(Ride* ride) +{ + rct_window* w; + RefurbishRidePromptWindow* newWindow; + + w = window_find_by_class(WC_DEMOLISH_RIDE_PROMPT); + if (w != nullptr) + { + auto windowPos = w->windowPos; + window_close(w); + newWindow = WindowCreate(WC_DEMOLISH_RIDE_PROMPT, windowPos, WW, WH, WF_TRANSPARENT); + } + else + { + newWindow = WindowCreate(WC_DEMOLISH_RIDE_PROMPT, WW, WH, WF_CENTRE_SCREEN | WF_TRANSPARENT); + } + + newWindow->SetRide(ride); + + return newWindow; +}