Skip to content

Refactor access to widgets #23257

Closed
@ZehMatt

Description

@ZehMatt

In order to stop widgets sharing state from multiple windows of the same type we have to copy the widget definition and not assign a pointer. However before we change the pointer into a vector, so that each window will have a copy of the widget we have to first ensure the access to the data is correct.

There is some code the needs corrections, any code that directly accesses the definition rather than what is assigned to the windows has to be changed.

Example:
The variable widgets is assigned here:

widgets = window_custom_currency_widgets;

Access to the static can be seen here:

screenCoords = windowPos
+ ScreenCoordsXY{ window_custom_currency_widgets[WIDX_SYMBOL_TEXT].left + 1,
window_custom_currency_widgets[WIDX_SYMBOL_TEXT].top };
DrawText(dpi, screenCoords, { colours[1] }, CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode);
auto drawPos = windowPos
+ ScreenCoordsXY{ window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1,
window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top };
StringId stringId = (CurrencyDescriptors[EnumValue(CurrencyType::Custom)].affix_unicode == CurrencyAffix::Prefix)
? STR_PREFIX
: STR_SUFFIX;
DrawTextBasic(dpi, drawPos, stringId, {}, { colours[1] });

Instead of accessing window_custom_currency_widgets it should access the data from widgets stored in WindowBase.

After this we can turn the widgets member into std::vector and copy the widget definition instead of sharing the memory. This will also eliminate the need of having a special widget type that annotates the end of the array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good-first-issueLow hanging fruits good for people new to open source or OpenRCT2.refactorA task that will improve code readability, without changing outcome.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions