mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-30 18:25:16 +01:00
Refactor widgets state (#23621)
* Refactor windows to not share widget state * First half of refactoring all the windows * Refactor the remaining windows, compiles but has issues * Fix drawing only every second widget * Remove the need of an terminating widget * Address WidgetIndex signedness issues; use kWidgetIndexNull more * Address constexpr issue with Widget content union * Fix tabs in scenery window * Fix tabs in object selection window * Adjust custom widget index for CustomTool events * Use STR_NONE for default tooltip initialisation * Adjustment for mingw compiler * Fix bottom toolbar using the widget declaration not instance * Remove pointless code in Guest window, handled by SetPage * Prevent out of bounds crash * Move scroll widgets initialization to SetPage in Cheats window * Remove special logic in Options window * Remove special logic in Park window * Remove special logic for Player window * Remove special logic for Research window * Remove special logic for Ride window * Remove special logic for Staff window * Remove special logic for Finances window * Remove special logic for MapGen window * Remove special logic for editor objective options window * Remove special logic for editor scenario options window * Fix widgets not being set since page is initialized to 0 * Remove more redundant code * Fix remaining access to widget declarations * Remove unused variable * Fix editor object selection tabs on successive windows --------- Co-authored-by: Aaron van Geffen <aaron@aaronweb.net>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <openrct2-ui/UiStringIds.h>
|
||||
#include <openrct2/Context.h>
|
||||
@@ -939,9 +940,11 @@ namespace OpenRCT2::Ui
|
||||
int32_t* output_scroll_area, int32_t* scroll_id)
|
||||
{
|
||||
*scroll_id = 0;
|
||||
for (Widget* iterator = w.widgets; iterator != widget; iterator++)
|
||||
auto itLast = std::find_if(
|
||||
w.widgets.begin(), w.widgets.end(), [&](auto& otherWidget) { return &otherWidget == widget; });
|
||||
for (auto it = w.widgets.begin(); it != itLast; it++)
|
||||
{
|
||||
if (iterator->type == WindowWidgetType::Scroll)
|
||||
if (it->type == WindowWidgetType::Scroll)
|
||||
{
|
||||
*scroll_id += 1;
|
||||
}
|
||||
@@ -1044,20 +1047,13 @@ namespace OpenRCT2::Ui
|
||||
|
||||
Widget* GetWidgetByIndex(const WindowBase& w, WidgetIndex widgetIndex)
|
||||
{
|
||||
// Make sure we don't go out of bounds if we are given a bad widget index
|
||||
WidgetIndex index = 0;
|
||||
for (auto* widget = w.widgets; widget->type != WindowWidgetType::Last; widget++)
|
||||
if (widgetIndex >= w.widgets.size())
|
||||
{
|
||||
if (index == widgetIndex)
|
||||
{
|
||||
return widget;
|
||||
}
|
||||
index++;
|
||||
LOG_ERROR("Widget index %i out of bounds for window class %u", widgetIndex, w.classification);
|
||||
}
|
||||
|
||||
LOG_ERROR("Widget index %i out of bounds for window class %u", widgetIndex, w.classification);
|
||||
|
||||
return nullptr;
|
||||
// FIXME: This const_cast is bad.
|
||||
return const_cast<Widget*>(w.widgets.data() + widgetIndex);
|
||||
}
|
||||
|
||||
static void SafeSetWidgetFlag(WindowBase& w, WidgetIndex widgetIndex, WidgetFlags mask, bool value)
|
||||
|
||||
Reference in New Issue
Block a user