Implement onClose event for custom windows

This commit is contained in:
Ted John 2020-04-26 16:01:03 +01:00
parent c0aa5bdcc8
commit ca98ffc697
1 changed files with 12 additions and 2 deletions

View File

@ -192,6 +192,9 @@ namespace OpenRCT2::Ui::Windows
std::vector<CustomWidgetDesc> Widgets; std::vector<CustomWidgetDesc> Widgets;
std::vector<colour_t> Colours; std::vector<colour_t> Colours;
// Event handlers
DukValue OnClose;
CustomWindowDesc() = default; CustomWindowDesc() = default;
bool IsResizable() const bool IsResizable() const
@ -235,6 +238,8 @@ namespace OpenRCT2::Ui::Windows
}); });
} }
result.OnClose = desc["onClose"];
return result; return result;
} }
@ -338,8 +343,13 @@ namespace OpenRCT2::Ui::Windows
static void window_custom_close(rct_window* w) static void window_custom_close(rct_window* w)
{ {
delete static_cast<CustomWindowInfo*>(w->custom_info); auto info = static_cast<CustomWindowInfo*>(w->custom_info);
w->custom_info = nullptr; 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) static void window_custom_mouseup(rct_window* w, rct_widgetindex widgetIndex)