diff --git a/src/openrct2-ui/scripting/CustomWindow.cpp b/src/openrct2-ui/scripting/CustomWindow.cpp index 74039ea776..82e43334a3 100644 --- a/src/openrct2-ui/scripting/CustomWindow.cpp +++ b/src/openrct2-ui/scripting/CustomWindow.cpp @@ -192,6 +192,9 @@ namespace OpenRCT2::Ui::Windows std::vector Widgets; std::vector Colours; + // Event handlers + DukValue OnClose; + CustomWindowDesc() = default; bool IsResizable() const @@ -235,6 +238,8 @@ namespace OpenRCT2::Ui::Windows }); } + result.OnClose = desc["onClose"]; + return result; } @@ -338,8 +343,13 @@ namespace OpenRCT2::Ui::Windows static void window_custom_close(rct_window* w) { - delete static_cast(w->custom_info); - w->custom_info = nullptr; + auto info = static_cast(w->custom_info); + if (info != nullptr) + { + InvokeEventHandler(info->Owner, info->Desc.OnClose); + delete info; + w->custom_info = nullptr; + } } static void window_custom_mouseup(rct_window* w, rct_widgetindex widgetIndex)