Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Use per-window filter state for station list windows. #11532

Merged
merged 2 commits into from Dec 4, 2023

Conversation

PeterN
Copy link
Member

@PeterN PeterN commented Dec 3, 2023

Motivation / Problem

Multiple Station List windows can be opened, one for each company.

They each have their own filter state buttons at the top, however these were global variables so shared between windows. Changing filter state in one window affected filter state in other windows, but did not refresh the windows or cause the list to be invalidated.

Description

Given the filter buttons are per-window, make the filter state be per-window as well. This is loaded/saved when the window is opened/closed so that it is still persistent.

This requires adding an state parameter to the SortFunction part of GUIList, which defaults to void * when unused.

Limitations

(It would probably be less work to just make the filter state update all windows, but then having all the buttons per window, duplicating the state, is a bit weird.)

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

GUIList sorter functions can currently only use global state, which makes per-window-instance sorting difficult.
… state.

Changing filters with multiple windows open would have unexpected effects leading to inconsistent state.

Now state is loaded and saved when the window is opened and closed, so state is still persistent.
@PeterN PeterN merged commit 07a8bd2 into OpenTTD:master Dec 4, 2023
20 checks passed
@PeterN PeterN deleted the non-static-sorter-data branch December 4, 2023 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants