Migrate inventory_ui.cpp and game_inventory.cpp to ui_adaptor #40094
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SUMMARY: Interface "Migrate inventory_ui.cpp and game_inventory.cpp to ui_adaptor"
Purpose of change
Migrate more UIs to
ui_adaptor
.Describe the solution
Encapsulate inventory ui initialization and redrawing with
ui_adaptor
.Testing
Opened and closed sub-UIs (such as keybindings menu), and lower UIs were redrawn correctly. (If the inventory menu is opened from unmigrated UIs, then lower UIs are not redrawn because they are disabled, which is expected and will be fixed once the unmigrated UI is migrated).
Resized the game window with or without sub-UIs open. Resized the game window when entering the filter string. Resizing was working as intended apart from a small glitch (see additional context below).
inventory_pick_selector
: tested with inventory menu ('i')inventory_compare_selector
: tested with item compare menu ('I')inventory_iuse_selector
: tested by using washboard ('a'->select wash borad)inventory_drop_selector
: tested with drop menu ('d')Also tested eating menu to make sure filter and selection is preserved after eating once.
Additional context
Due to the way the UI initialization code was written, there are some inconsistency when you resize the window multiple times. For example, if multiple columns are present and window width is reduced, the columns can be merged into a single column, but then remains a single column even if the window is widened again. I've fixed a different case where truncated cell does not reset its width when the window is widened by resetting the column width before re-initializing the UI, but the former case seems to be trickier to tackle because the logic in
inventory_selector::rearrange_columns
destroys the column information, so I could not come up with a fix.There's also another bug with filtering that existed before this PR. In instances of
inventory_multiselector
(for example item compare menu 'I' or multidrop menu 'd'), if a filter is set after toggling some of the items, the toggled status of these items resets but the selection column is not cleared. This is becauseinventory_column::prepare_paging
filters out entries by removing them fromentries
, and removes the toggled status in the process. I do not entirely understand how filtering works ininventory_ui
so I could not come up with a fix.@codemime it seem that you are the original author of the inventory UI system, so perhaps you could provide some insights on how to handle these issues?