1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-23 23:04:36 +01:00

Close plugin's windows gracefully when stopped

When a plugin is stopped, close all windows created by that plugin.
Ensure the close event on the window can not open a new window if the plugin is being stopped.
This commit is contained in:
Ted John
2022-02-15 20:26:37 +00:00
parent 105009f3f8
commit 007a33404e
7 changed files with 63 additions and 17 deletions

View File

@@ -9,16 +9,17 @@
#ifdef ENABLE_SCRIPTING
# include "../UiContext.h"
# include "../interface/Dropdown.h"
# include "../interface/Widget.h"
# include "../scripting/ScGraphicsContext.hpp"
# include "../scripting/ScWidget.hpp"
# include "../windows/Window.h"
# include "CustomListView.h"
# include "ScUi.hpp"
# include "ScWindow.hpp"
# include <limits>
# include <openrct2-ui/interface/Widget.h>
# include <openrct2-ui/windows/Window.h>
# include <openrct2/drawing/Drawing.h>
# include <openrct2/interface/Window.h>
# include <openrct2/localisation/Formatter.h>
@@ -1433,6 +1434,29 @@ namespace OpenRCT2::Ui::Windows
}
}
void CloseWindowsOwnedByPlugin(std::shared_ptr<Plugin> plugin)
{
// Get all the windows that need closing
std::vector<std::shared_ptr<rct_window>> customWindows;
for (const auto& window : g_window_list)
{
if (window->classification == WC_CUSTOM)
{
auto customWindow = reinterpret_cast<CustomWindow*>(window.get());
auto customInfo = reinterpret_cast<CustomWindowInfo*>(customWindow->custom_info);
if (customInfo != nullptr && customInfo->Owner == plugin)
{
customWindows.push_back(window);
}
}
}
for (auto& window : customWindows)
{
window_close(window.get());
}
}
} // namespace OpenRCT2::Ui::Windows
#endif