1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

Remove custom_info pointer (#20480)

* Remove custom_info pointer

* Formatting
This commit is contained in:
Duncan
2023-07-18 06:24:42 +01:00
committed by GitHub
parent 8c0a931403
commit ce86aa029f
2 changed files with 110 additions and 130 deletions

View File

@@ -375,7 +375,8 @@ namespace OpenRCT2::Ui::Windows
} }
}; };
static CustomWindowInfo& GetInfo(WindowBase* w); class CustomWindow;
static CustomWindowInfo& GetInfo(CustomWindow* w);
static void InvokeEventHandler(const std::shared_ptr<Plugin>& owner, const DukValue& dukHandler); static void InvokeEventHandler(const std::shared_ptr<Plugin>& owner, const DukValue& dukHandler);
static void InvokeEventHandler( static void InvokeEventHandler(
const std::shared_ptr<Plugin>& owner, const DukValue& dukHandler, const std::vector<DukValue>& args); const std::shared_ptr<Plugin>& owner, const DukValue& dukHandler, const std::vector<DukValue>& args);
@@ -384,12 +385,13 @@ namespace OpenRCT2::Ui::Windows
{ {
private: private:
static rct_windownumber _nextWindowNumber; static rct_windownumber _nextWindowNumber;
CustomWindowInfo _info;
public: public:
void Initialise(std::shared_ptr<Plugin> owner, const CustomWindowDesc& desc) CustomWindow(std::shared_ptr<Plugin> owner, const CustomWindowDesc& desc)
: _info(owner, desc)
{ {
number = GetNewWindowNumber(); number = GetNewWindowNumber();
custom_info = new CustomWindowInfo(owner, desc);
// Set window tab // Set window tab
page = desc.TabIndex.value_or(0); page = desc.TabIndex.value_or(0);
@@ -416,13 +418,7 @@ namespace OpenRCT2::Ui::Windows
void OnClose() override void OnClose() override
{ {
auto info = static_cast<CustomWindowInfo*>(custom_info); InvokeEventHandler(_info.Owner, _info.Desc.OnClose);
if (info != nullptr)
{
InvokeEventHandler(info->Owner, info->Desc.OnClose);
delete info;
custom_info = nullptr;
}
} }
void OnResize() override void OnResize() override
@@ -442,10 +438,9 @@ namespace OpenRCT2::Ui::Windows
void OnUpdate() override void OnUpdate() override
{ {
const auto& info = GetInfo(this); if (_info.Desc.Tabs.size() > static_cast<size_t>(page))
if (info.Desc.Tabs.size() > static_cast<size_t>(page))
{ {
const auto& tab = info.Desc.Tabs[page]; const auto& tab = _info.Desc.Tabs[page];
if (tab.imageFrameCount != 0) if (tab.imageFrameCount != 0)
{ {
frame_no++; frame_no++;
@@ -457,7 +452,7 @@ namespace OpenRCT2::Ui::Windows
} }
} }
InvokeEventHandler(info.Owner, info.Desc.OnUpdate); InvokeEventHandler(_info.Owner, _info.Desc.OnUpdate);
// Since the plugin may alter widget positions and sizes during an update event, // Since the plugin may alter widget positions and sizes during an update event,
// we need to force an update for all list view scrollbars // we need to force an update for all list view scrollbars
@@ -481,9 +476,8 @@ namespace OpenRCT2::Ui::Windows
// Having the content panel visible for transparent windows makes the borders darker than they should be // Having the content panel visible for transparent windows makes the borders darker than they should be
// For now just hide it if there are no tabs and the window is not resizable // For now just hide it if there are no tabs and the window is not resizable
auto& info = GetInfo(this);
auto canResize = (flags & WF_RESIZABLE) != 0 && (min_width != max_width || min_height != max_height); auto canResize = (flags & WF_RESIZABLE) != 0 && (min_width != max_width || min_height != max_height);
auto numTabs = info.Desc.Tabs.size(); auto numTabs = _info.Desc.Tabs.size();
if (canResize || numTabs != 0) if (canResize || numTabs != 0)
{ {
widgets[WIDX_CONTENT_PANEL].flags &= ~WIDGET_FLAGS::IS_HIDDEN; widgets[WIDX_CONTENT_PANEL].flags &= ~WIDGET_FLAGS::IS_HIDDEN;
@@ -495,7 +489,7 @@ namespace OpenRCT2::Ui::Windows
SetPressedTab(); SetPressedTab();
const auto& desc = info.Desc; const auto& desc = _info.Desc;
auto ft = Formatter::Common(); auto ft = Formatter::Common();
ft.Add<const char*>(desc.Title.c_str()); ft.Add<const char*>(desc.Title.c_str());
@@ -504,7 +498,7 @@ namespace OpenRCT2::Ui::Windows
{ {
if (widget->type == WindowWidgetType::Scroll) if (widget->type == WindowWidgetType::Scroll)
{ {
auto& listView = info.ListViews[scrollIndex]; auto& listView = _info.ListViews[scrollIndex];
auto wwidth = widget->width() + 1 - 2; auto wwidth = widget->width() + 1 - 2;
auto wheight = widget->height() + 1 - 2; auto wheight = widget->height() + 1 - 2;
if (listView.GetScrollbars() == ScrollbarType::Horizontal if (listView.GetScrollbars() == ScrollbarType::Horizontal
@@ -539,8 +533,7 @@ namespace OpenRCT2::Ui::Windows
void OnDrawWidget(WidgetIndex widgetIndex, DrawPixelInfo& dpi) override void OnDrawWidget(WidgetIndex widgetIndex, DrawPixelInfo& dpi) override
{ {
const auto& widget = widgets[widgetIndex]; const auto& widget = widgets[widgetIndex];
const auto& info = GetInfo(this); const auto widgetDesc = _info.GetCustomWidgetDesc(this, widgetIndex);
const auto widgetDesc = info.GetCustomWidgetDesc(this, widgetIndex);
if (widgetDesc != nullptr && widgetDesc->Type == "custom") if (widgetDesc != nullptr && widgetDesc->Type == "custom")
{ {
auto& onDraw = widgetDesc->OnDraw; auto& onDraw = widgetDesc->OnDraw;
@@ -555,7 +548,7 @@ namespace OpenRCT2::Ui::Windows
auto dukWidget = ScWidget::ToDukValue(ctx, this, widgetIndex); auto dukWidget = ScWidget::ToDukValue(ctx, this, widgetIndex);
auto dukG = GetObjectAsDukValue(ctx, std::make_shared<ScGraphicsContext>(ctx, widgetDpi)); auto dukG = GetObjectAsDukValue(ctx, std::make_shared<ScGraphicsContext>(ctx, widgetDpi));
auto& scriptEngine = GetContext()->GetScriptEngine(); auto& scriptEngine = GetContext()->GetScriptEngine();
scriptEngine.ExecutePluginCall(info.Owner, widgetDesc->OnDraw, dukWidget, { dukG }, false); scriptEngine.ExecutePluginCall(_info.Owner, widgetDesc->OnDraw, dukWidget, { dukG }, false);
} }
} }
} }
@@ -574,19 +567,19 @@ namespace OpenRCT2::Ui::Windows
break; break;
default: default:
{ {
const auto& info = GetInfo(this); if (widgetIndex >= WIDX_TAB_0
if (widgetIndex >= WIDX_TAB_0 && widgetIndex < static_cast<WidgetIndex>(WIDX_TAB_0 + info.Desc.Tabs.size())) && widgetIndex < static_cast<WidgetIndex>(WIDX_TAB_0 + _info.Desc.Tabs.size()))
{ {
ChangeTab(widgetIndex - WIDX_TAB_0); ChangeTab(widgetIndex - WIDX_TAB_0);
break; break;
} }
const auto widgetDesc = info.GetCustomWidgetDesc(this, widgetIndex); const auto widgetDesc = _info.GetCustomWidgetDesc(this, widgetIndex);
if (widgetDesc != nullptr) if (widgetDesc != nullptr)
{ {
if (widgetDesc->Type == "button") if (widgetDesc->Type == "button")
{ {
InvokeEventHandler(info.Owner, widgetDesc->OnClick); InvokeEventHandler(_info.Owner, widgetDesc->OnClick);
} }
else if (widgetDesc->Type == "checkbox") else if (widgetDesc->Type == "checkbox")
{ {
@@ -600,14 +593,14 @@ namespace OpenRCT2::Ui::Windows
auto ctx = widgetDesc->OnChange.context(); auto ctx = widgetDesc->OnChange.context();
duk_push_boolean(ctx, isChecked); duk_push_boolean(ctx, isChecked);
args.push_back(DukValue::take_from_stack(ctx)); args.push_back(DukValue::take_from_stack(ctx));
InvokeEventHandler(info.Owner, widgetDesc->OnChange, args); InvokeEventHandler(_info.Owner, widgetDesc->OnChange, args);
} }
else if (widgetDesc->Type == "spinner") else if (widgetDesc->Type == "spinner")
{ {
auto& widget = widgets[widgetIndex]; auto& widget = widgets[widgetIndex];
if (widget.text != STR_NUMERIC_DOWN && widget.text != STR_NUMERIC_UP) if (widget.text != STR_NUMERIC_DOWN && widget.text != STR_NUMERIC_UP)
{ {
InvokeEventHandler(info.Owner, widgetDesc->OnClick); InvokeEventHandler(_info.Owner, widgetDesc->OnClick);
} }
} }
} }
@@ -619,8 +612,7 @@ namespace OpenRCT2::Ui::Windows
void OnMouseDown(WidgetIndex widgetIndex) override void OnMouseDown(WidgetIndex widgetIndex) override
{ {
auto* widget = &widgets[widgetIndex]; auto* widget = &widgets[widgetIndex];
const auto& info = GetInfo(this); const auto widgetDesc = _info.GetCustomWidgetDesc(this, widgetIndex);
const auto widgetDesc = info.GetCustomWidgetDesc(this, widgetIndex);
if (widgetDesc != nullptr) if (widgetDesc != nullptr)
{ {
if (widgetDesc->Type == "colourpicker") if (widgetDesc->Type == "colourpicker")
@@ -648,11 +640,11 @@ namespace OpenRCT2::Ui::Windows
{ {
if (widget->text == STR_NUMERIC_DOWN) if (widget->text == STR_NUMERIC_DOWN)
{ {
InvokeEventHandler(info.Owner, widgetDesc->OnDecrement); InvokeEventHandler(_info.Owner, widgetDesc->OnDecrement);
} }
else if (widget->text == STR_NUMERIC_UP) else if (widget->text == STR_NUMERIC_UP)
{ {
InvokeEventHandler(info.Owner, widgetDesc->OnIncrement); InvokeEventHandler(_info.Owner, widgetDesc->OnIncrement);
} }
} }
else if (widgetDesc->Type == "textbox") else if (widgetDesc->Type == "textbox")
@@ -668,8 +660,7 @@ namespace OpenRCT2::Ui::Windows
if (dropdownIndex == -1) if (dropdownIndex == -1)
return; return;
auto& info = GetInfo(this); auto widgetDesc = _info.GetCustomWidgetDesc(this, widgetIndex);
auto widgetDesc = info.GetCustomWidgetDesc(this, widgetIndex);
if (widgetDesc != nullptr) if (widgetDesc != nullptr)
{ {
if (widgetDesc->Type == "colourpicker") if (widgetDesc->Type == "colourpicker")
@@ -685,8 +676,7 @@ namespace OpenRCT2::Ui::Windows
void OnTextInput(WidgetIndex widgetIndex, std::string_view text) override void OnTextInput(WidgetIndex widgetIndex, std::string_view text) override
{ {
auto& info = GetInfo(this); auto widgetDesc = _info.GetCustomWidgetDesc(this, widgetIndex);
auto widgetDesc = info.GetCustomWidgetDesc(this, widgetIndex);
if (widgetDesc != nullptr) if (widgetDesc != nullptr)
{ {
if (widgetDesc->Type == "textbox") if (widgetDesc->Type == "textbox")
@@ -697,17 +687,16 @@ namespace OpenRCT2::Ui::Windows
auto ctx = widgetDesc->OnChange.context(); auto ctx = widgetDesc->OnChange.context();
duk_push_lstring(ctx, text.data(), text.size()); duk_push_lstring(ctx, text.data(), text.size());
args.push_back(DukValue::take_from_stack(ctx)); args.push_back(DukValue::take_from_stack(ctx));
InvokeEventHandler(info.Owner, widgetDesc->OnChange, args); InvokeEventHandler(_info.Owner, widgetDesc->OnChange, args);
} }
} }
} }
ScreenSize OnScrollGetSize(int32_t scrollIndex) override ScreenSize OnScrollGetSize(int32_t scrollIndex) override
{ {
auto& info = GetInfo(this); if (scrollIndex < static_cast<int32_t>(_info.ListViews.size()))
if (scrollIndex < static_cast<int32_t>(info.ListViews.size()))
{ {
auto size = info.ListViews[scrollIndex].GetSize(); auto size = _info.ListViews[scrollIndex].GetSize();
return { size.width, size.height }; return { size.width, size.height };
} }
return {}; return {};
@@ -715,44 +704,38 @@ namespace OpenRCT2::Ui::Windows
void OnScrollMouseDown(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override void OnScrollMouseDown(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override
{ {
auto& info = GetInfo(this); if (scrollIndex < static_cast<int32_t>(_info.ListViews.size()))
if (scrollIndex < static_cast<int32_t>(info.ListViews.size()))
{ {
info.ListViews[scrollIndex].MouseDown(screenCoords); _info.ListViews[scrollIndex].MouseDown(screenCoords);
} }
} }
void OnScrollMouseDrag(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override void OnScrollMouseDrag(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override
{ {
auto& info = GetInfo(this); if (scrollIndex < static_cast<int32_t>(_info.ListViews.size()))
if (scrollIndex < static_cast<int32_t>(info.ListViews.size()))
{ {
info.ListViews[scrollIndex].MouseOver(screenCoords, true); _info.ListViews[scrollIndex].MouseOver(screenCoords, true);
} }
} }
void OnScrollMouseOver(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override void OnScrollMouseOver(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override
{ {
auto& info = GetInfo(this); if (scrollIndex < static_cast<int32_t>(_info.ListViews.size()))
if (scrollIndex < static_cast<int32_t>(info.ListViews.size()))
{ {
info.ListViews[scrollIndex].MouseOver(screenCoords, false); _info.ListViews[scrollIndex].MouseOver(screenCoords, false);
} }
} }
void OnScrollDraw(int32_t scrollIndex, DrawPixelInfo& dpi) override void OnScrollDraw(int32_t scrollIndex, DrawPixelInfo& dpi) override
{ {
const auto& info = GetInfo(this); if (scrollIndex < static_cast<int32_t>(_info.ListViews.size()))
if (scrollIndex < static_cast<int32_t>(info.ListViews.size()))
{ {
info.ListViews[scrollIndex].Paint(this, dpi, &scrolls[scrollIndex]); _info.ListViews[scrollIndex].Paint(this, dpi, &scrolls[scrollIndex]);
} }
} }
void ChangeTab(size_t tabIndex) void ChangeTab(size_t tabIndex)
{ {
const auto& info = GetInfo(this);
page = static_cast<int16_t>(tabIndex); page = static_cast<int16_t>(tabIndex);
frame_no = 0; frame_no = 0;
RefreshWidgets(); RefreshWidgets();
@@ -763,7 +746,16 @@ namespace OpenRCT2::Ui::Windows
WindowInitScrollWidgets(*this); WindowInitScrollWidgets(*this);
Invalidate(); Invalidate();
InvokeEventHandler(info.Owner, info.Desc.OnTabChange); InvokeEventHandler(_info.Owner, _info.Desc.OnTabChange);
}
const CustomWindowInfo& GetInfo() const
{
return _info;
}
CustomWindowInfo& GetInfo()
{
return _info;
} }
private: private:
@@ -787,8 +779,7 @@ namespace OpenRCT2::Ui::Windows
if (viewportWidgetIndex) if (viewportWidgetIndex)
{ {
auto viewportWidget = &widgets[*viewportWidgetIndex]; auto viewportWidget = &widgets[*viewportWidgetIndex];
auto& customInfo = GetInfo(this); auto widgetInfo = _info.GetCustomWidgetDesc(this, *viewportWidgetIndex);
auto widgetInfo = customInfo.GetCustomWidgetDesc(this, *viewportWidgetIndex);
if (widgetInfo != nullptr) if (widgetInfo != nullptr)
{ {
auto left = windowPos.x + viewportWidget->left + 1; auto left = windowPos.x + viewportWidget->left + 1;
@@ -829,8 +820,7 @@ namespace OpenRCT2::Ui::Windows
void SetPressedTab() void SetPressedTab()
{ {
const auto& info = GetInfo(this); auto numTabs = _info.Desc.Tabs.size();
auto numTabs = info.Desc.Tabs.size();
if (numTabs != 0) if (numTabs != 0)
{ {
for (size_t i = 0; i < numTabs; i++) for (size_t i = 0; i < numTabs; i++)
@@ -843,8 +833,7 @@ namespace OpenRCT2::Ui::Windows
void DrawTabImages(DrawPixelInfo& dpi) void DrawTabImages(DrawPixelInfo& dpi)
{ {
const auto& customInfo = GetInfo(this); const auto& tabs = _info.Desc.Tabs;
const auto& tabs = customInfo.Desc.Tabs;
size_t tabIndex = 0; size_t tabIndex = 0;
for (const auto& tab : tabs) for (const auto& tab : tabs)
{ {
@@ -868,26 +857,25 @@ namespace OpenRCT2::Ui::Windows
void RefreshWidgets() void RefreshWidgets()
{ {
auto& info = GetInfo(this); auto& widgetList = _info.Widgets;
auto& widgetList = info.Widgets;
widgetList.clear(); widgetList.clear();
info.WidgetIndexMap.clear(); _info.WidgetIndexMap.clear();
info.ListViews.clear(); _info.ListViews.clear();
// Add default widgets (window shim) // Add default widgets (window shim)
widgetList.insert(widgetList.begin(), std::begin(CustomDefaultWidgets), std::end(CustomDefaultWidgets)); widgetList.insert(widgetList.begin(), std::begin(CustomDefaultWidgets), std::end(CustomDefaultWidgets));
for (size_t i = 0; i < widgetList.size(); i++) for (size_t i = 0; i < widgetList.size(); i++)
{ {
info.WidgetIndexMap.push_back(std::numeric_limits<size_t>::max()); _info.WidgetIndexMap.push_back(std::numeric_limits<size_t>::max());
} }
// Add window tabs // Add window tabs
if (info.Desc.Tabs.size() != 0) if (_info.Desc.Tabs.size() != 0)
{ {
widgetList[WIDX_CONTENT_PANEL].top = 43; widgetList[WIDX_CONTENT_PANEL].top = 43;
} }
for (size_t tabDescIndex = 0; tabDescIndex < info.Desc.Tabs.size(); tabDescIndex++) for (size_t tabDescIndex = 0; tabDescIndex < _info.Desc.Tabs.size(); tabDescIndex++)
{ {
Widget widget{}; Widget widget{};
widget.type = WindowWidgetType::Tab; widget.type = WindowWidgetType::Tab;
@@ -899,33 +887,33 @@ namespace OpenRCT2::Ui::Windows
widget.image = ImageId(SPR_TAB, FilterPaletteID::PaletteNull); widget.image = ImageId(SPR_TAB, FilterPaletteID::PaletteNull);
widget.tooltip = STR_NONE; widget.tooltip = STR_NONE;
widgetList.push_back(widget); widgetList.push_back(widget);
info.WidgetIndexMap.push_back(std::numeric_limits<size_t>::max()); _info.WidgetIndexMap.push_back(std::numeric_limits<size_t>::max());
} }
// Add custom widgets // Add custom widgets
auto totalWidgets = info.Desc.Widgets.size(); auto totalWidgets = _info.Desc.Widgets.size();
auto tabWidgetsOffset = totalWidgets; auto tabWidgetsOffset = totalWidgets;
if (info.Desc.Tabs.size() != 0) if (_info.Desc.Tabs.size() != 0)
{ {
totalWidgets += info.Desc.Tabs[page].Widgets.size(); totalWidgets += _info.Desc.Tabs[page].Widgets.size();
} }
for (size_t widgetDescIndex = 0; widgetDescIndex < totalWidgets; widgetDescIndex++) for (size_t widgetDescIndex = 0; widgetDescIndex < totalWidgets; widgetDescIndex++)
{ {
const auto& widgetDesc = widgetDescIndex < info.Desc.Widgets.size() const auto& widgetDesc = widgetDescIndex < _info.Desc.Widgets.size()
? info.Desc.Widgets[widgetDescIndex] ? _info.Desc.Widgets[widgetDescIndex]
: info.Desc.Tabs[page].Widgets[widgetDescIndex - tabWidgetsOffset]; : _info.Desc.Tabs[page].Widgets[widgetDescIndex - tabWidgetsOffset];
auto preWidgetSize = widgetList.size(); auto preWidgetSize = widgetList.size();
CreateWidget(widgetList, widgetDesc); CreateWidget(widgetList, widgetDesc);
auto numWidetsAdded = widgetList.size() - preWidgetSize; auto numWidetsAdded = widgetList.size() - preWidgetSize;
for (size_t i = 0; i < numWidetsAdded; i++) for (size_t i = 0; i < numWidetsAdded; i++)
{ {
info.WidgetIndexMap.push_back(widgetDescIndex); _info.WidgetIndexMap.push_back(widgetDescIndex);
} }
if (widgetDesc.Type == "listview") if (widgetDesc.Type == "listview")
{ {
CustomListView listView(this, info.ListViews.size()); CustomListView listView(this, _info.ListViews.size());
listView.Owner = info.Owner; listView.Owner = _info.Owner;
listView.SetScrollbars(widgetDesc.Scrollbars, true); listView.SetScrollbars(widgetDesc.Scrollbars, true);
listView.SetColumns(widgetDesc.ListViewColumns, true); listView.SetColumns(widgetDesc.ListViewColumns, true);
listView.SetItems(widgetDesc.ListViewItems, true); listView.SetItems(widgetDesc.ListViewItems, true);
@@ -935,7 +923,7 @@ namespace OpenRCT2::Ui::Windows
listView.OnClick = widgetDesc.OnClick; listView.OnClick = widgetDesc.OnClick;
listView.OnHighlight = widgetDesc.OnHighlight; listView.OnHighlight = widgetDesc.OnHighlight;
listView.CanSelect = widgetDesc.CanSelect; listView.CanSelect = widgetDesc.CanSelect;
info.ListViews.push_back(std::move(listView)); _info.ListViews.push_back(std::move(listView));
} }
} }
@@ -1126,22 +1114,18 @@ namespace OpenRCT2::Ui::Windows
if (desc.X && desc.Y) if (desc.X && desc.Y)
{ {
window = WindowCreate<CustomWindow>( window = WindowCreate<CustomWindow>(
WindowClass::Custom, { *desc.X, *desc.Y }, desc.Width, desc.Height, windowFlags); WindowClass::Custom, { *desc.X, *desc.Y }, desc.Width, desc.Height, windowFlags, owner, desc);
} }
else else
{ {
window = WindowCreate<CustomWindow>(WindowClass::Custom, desc.Width, desc.Height, windowFlags); window = WindowCreate<CustomWindow>(WindowClass::Custom, desc.Width, desc.Height, windowFlags, owner, desc);
}
if (window != nullptr)
{
window->Initialise(owner, desc);
} }
return window; return window;
} }
static CustomWindowInfo& GetInfo(WindowBase* w) static CustomWindowInfo& GetInfo(CustomWindow* w)
{ {
return *(static_cast<CustomWindowInfo*>(w->custom_info)); return w->GetInfo();
} }
static void InvokeEventHandler(const std::shared_ptr<Plugin>& owner, const DukValue& dukHandler) static void InvokeEventHandler(const std::shared_ptr<Plugin>& owner, const DukValue& dukHandler)
@@ -1159,9 +1143,9 @@ namespace OpenRCT2::Ui::Windows
std::string GetWindowTitle(WindowBase* w) std::string GetWindowTitle(WindowBase* w)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
return customInfo.Desc.Title; return customInfo.Desc.Title;
} }
return {}; return {};
@@ -1169,18 +1153,18 @@ namespace OpenRCT2::Ui::Windows
void UpdateWindowTitle(WindowBase* w, std::string_view value) void UpdateWindowTitle(WindowBase* w, std::string_view value)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
customInfo.Desc.Title = value; customInfo.Desc.Title = value;
} }
} }
void UpdateWindowTab(WindowBase* w, int32_t tabIndex) void UpdateWindowTab(WindowBase* w, int32_t tabIndex)
{ {
if (w->classification == WindowClass::Custom && w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
if (tabIndex >= 0 && tabIndex < static_cast<int32_t>(customInfo.Desc.Tabs.size())) if (tabIndex >= 0 && tabIndex < static_cast<int32_t>(customInfo.Desc.Tabs.size()))
{ {
static_cast<CustomWindow*>(w)->ChangeTab(tabIndex); static_cast<CustomWindow*>(w)->ChangeTab(tabIndex);
@@ -1190,9 +1174,9 @@ namespace OpenRCT2::Ui::Windows
void UpdateWidgetText(WindowBase* w, WidgetIndex widgetIndex, std::string_view value) void UpdateWidgetText(WindowBase* w, WidgetIndex widgetIndex, std::string_view value)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr) if (customWidgetInfo != nullptr)
{ {
@@ -1205,9 +1189,9 @@ namespace OpenRCT2::Ui::Windows
void UpdateWidgetItems(WindowBase* w, WidgetIndex widgetIndex, const std::vector<std::string>& items) void UpdateWidgetItems(WindowBase* w, WidgetIndex widgetIndex, const std::vector<std::string>& items)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr) if (customWidgetInfo != nullptr)
{ {
@@ -1219,9 +1203,9 @@ namespace OpenRCT2::Ui::Windows
void UpdateWidgetColour(WindowBase* w, WidgetIndex widgetIndex, colour_t colour) void UpdateWidgetColour(WindowBase* w, WidgetIndex widgetIndex, colour_t colour)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr) if (customWidgetInfo != nullptr)
{ {
@@ -1246,9 +1230,9 @@ namespace OpenRCT2::Ui::Windows
void UpdateWidgetSelectedIndex(WindowBase* w, WidgetIndex widgetIndex, int32_t selectedIndex) void UpdateWidgetSelectedIndex(WindowBase* w, WidgetIndex widgetIndex, int32_t selectedIndex)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr) if (customWidgetInfo != nullptr)
{ {
@@ -1293,9 +1277,9 @@ namespace OpenRCT2::Ui::Windows
std::vector<std::string> GetWidgetItems(WindowBase* w, WidgetIndex widgetIndex) std::vector<std::string> GetWidgetItems(WindowBase* w, WidgetIndex widgetIndex)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr) if (customWidgetInfo != nullptr)
{ {
@@ -1307,9 +1291,9 @@ namespace OpenRCT2::Ui::Windows
colour_t GetWidgetColour(WindowBase* w, WidgetIndex widgetIndex) colour_t GetWidgetColour(WindowBase* w, WidgetIndex widgetIndex)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr) if (customWidgetInfo != nullptr)
{ {
@@ -1321,9 +1305,9 @@ namespace OpenRCT2::Ui::Windows
int32_t GetWidgetSelectedIndex(WindowBase* w, WidgetIndex widgetIndex) int32_t GetWidgetSelectedIndex(WindowBase* w, WidgetIndex widgetIndex)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr) if (customWidgetInfo != nullptr)
{ {
@@ -1339,7 +1323,7 @@ namespace OpenRCT2::Ui::Windows
{ {
if (w->classification == WindowClass::Custom) if (w->classification == WindowClass::Custom)
{ {
const auto& customInfo = GetInfo(w.get()); const auto& customInfo = GetInfo(static_cast<CustomWindow*>(w.get()));
if (customInfo.Desc.Classification == classification) if (customInfo.Desc.Classification == classification)
{ {
return w.get(); return w.get();
@@ -1351,9 +1335,9 @@ namespace OpenRCT2::Ui::Windows
std::optional<WidgetIndex> FindWidgetIndexByName(WindowBase* w, std::string_view name) std::optional<WidgetIndex> FindWidgetIndexByName(WindowBase* w, std::string_view name)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
for (size_t i = 0; i < customInfo.Widgets.size(); i++) for (size_t i = 0; i < customInfo.Widgets.size(); i++)
{ {
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, i); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, i);
@@ -1371,9 +1355,9 @@ namespace OpenRCT2::Ui::Windows
std::string GetWidgetName(WindowBase* w, WidgetIndex widgetIndex) std::string GetWidgetName(WindowBase* w, WidgetIndex widgetIndex)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
const auto& customInfo = GetInfo(w); const auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr) if (customWidgetInfo != nullptr)
{ {
@@ -1385,9 +1369,9 @@ namespace OpenRCT2::Ui::Windows
void SetWidgetName(WindowBase* w, WidgetIndex widgetIndex, std::string_view name) void SetWidgetName(WindowBase* w, WidgetIndex widgetIndex, std::string_view name)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr) if (customWidgetInfo != nullptr)
{ {
@@ -1398,9 +1382,9 @@ namespace OpenRCT2::Ui::Windows
std::string GetWidgetTooltip(WindowBase* w, WidgetIndex widgetIndex) std::string GetWidgetTooltip(WindowBase* w, WidgetIndex widgetIndex)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
const auto& customInfo = GetInfo(w); const auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr) if (customWidgetInfo != nullptr)
{ {
@@ -1412,9 +1396,9 @@ namespace OpenRCT2::Ui::Windows
void SetWidgetTooltip(WindowBase* w, WidgetIndex widgetIndex, std::string_view tooltip) void SetWidgetTooltip(WindowBase* w, WidgetIndex widgetIndex, std::string_view tooltip)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr) if (customWidgetInfo != nullptr)
{ {
@@ -1425,9 +1409,9 @@ namespace OpenRCT2::Ui::Windows
CustomListView* GetCustomListView(WindowBase* w, WidgetIndex widgetIndex) CustomListView* GetCustomListView(WindowBase* w, WidgetIndex widgetIndex)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& info = GetInfo(w); auto& info = GetInfo(static_cast<CustomWindow*>(w));
auto scrollIndex = WindowGetScrollDataIndex(*w, widgetIndex); auto scrollIndex = WindowGetScrollDataIndex(*w, widgetIndex);
if (scrollIndex < static_cast<int32_t>(info.ListViews.size())) if (scrollIndex < static_cast<int32_t>(info.ListViews.size()))
{ {
@@ -1439,9 +1423,9 @@ namespace OpenRCT2::Ui::Windows
int32_t GetWidgetMaxLength(WindowBase* w, WidgetIndex widgetIndex) int32_t GetWidgetMaxLength(WindowBase* w, WidgetIndex widgetIndex)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr) if (customWidgetInfo != nullptr)
{ {
@@ -1453,9 +1437,9 @@ namespace OpenRCT2::Ui::Windows
void SetWidgetMaxLength(WindowBase* w, WidgetIndex widgetIndex, int32_t value) void SetWidgetMaxLength(WindowBase* w, WidgetIndex widgetIndex, int32_t value)
{ {
if (w->custom_info != nullptr) if (w->classification == WindowClass::Custom)
{ {
auto& customInfo = GetInfo(w); auto& customInfo = GetInfo(static_cast<CustomWindow*>(w));
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr) if (customWidgetInfo != nullptr)
{ {
@@ -1473,8 +1457,8 @@ namespace OpenRCT2::Ui::Windows
if (window->classification == WindowClass::Custom) if (window->classification == WindowClass::Custom)
{ {
auto customWindow = reinterpret_cast<CustomWindow*>(window.get()); auto customWindow = reinterpret_cast<CustomWindow*>(window.get());
auto customInfo = reinterpret_cast<CustomWindowInfo*>(customWindow->custom_info); auto& customInfo = GetInfo(customWindow);
if (customInfo != nullptr && customInfo->Owner == plugin) if (customInfo.Owner == plugin)
{ {
customWindows.push_back(window); customWindows.push_back(window);
} }

View File

@@ -53,11 +53,7 @@ struct WindowBase
uint16_t no_list_items{}; // 0 for no items uint16_t no_list_items{}; // 0 for no items
int16_t selected_list_item{}; // -1 for none selected int16_t selected_list_item{}; // -1 for none selected
std::optional<Focus> focus; std::optional<Focus> focus;
union TrackListVariables track_list;
{
TrackListVariables track_list;
void* custom_info;
};
union union
{ {
int16_t page; int16_t page;