Filter wearable items by body part in the armor layers window #45600
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 "Filter wearable items by body part in the armor layers window"
Purpose of change
The armor layers window has two buttons for equipping items, "e" and "E" where "E" equips an item at the current position marked by the cursor. It seems logical to me that if you are looking at a specific body part, you should only see clothing that covers that body part. I have modified "E" to do just that. The "e" keybind has been left untouched and shows all available wearables.
Describe the solution
wear() is called when the "E" key is pressed, and the current body part tab is passed so that it can be used to filter clothing to only that which covers that specific body part (a default null body part is used for cases where wear() is called without body parts, which is checked later in order to skip filtering).
This is done through the presets sent to inv_internal() which filter items through their is_shown(). I've modified the wear preset with a body part field which is constant and unique each time wear() is called.
Due to the default null body part and the conditional in is_shown(), this modification should have no side effects when wear() is called without specifying body parts (as it is in 2 other calls), and it is only called with body parts in the "E" key handler.
Describe alternatives you've considered
A function object approach was also possible, which would have allowed somewhat custom filtering, but I deemed it too convoluted for this purpose.
Potentially modifying the "e" key so that it filters by body part as well.
A more robust generic filtering together with sorting would have been better, but is much more complicated and left for the future.
Testing
Spawned a bunch of clothing of each body part coverage and a few with shared coverage. Works as intended and only shows the appropriate ones when in that specific body part's tab, though I did spot a few segfaults when unequipping some items, none of which is related to this.