Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Template for new versions:
## New Tools

## New Features
- `stocks`: add button/hotkey for expanding all categories on stocks interface

## Fixes

Expand Down
14 changes: 14 additions & 0 deletions plugins/lua/stocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ local function collapse_all()
stocks.i_height = num_sections * 3
end

local function expand_all()
local num_sections = #stocks.current_type_a_expanded
for idx=0,num_sections-1 do
stocks.current_type_a_expanded[idx] = true
end
stocks.i_height = num_sections * 3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm uncertain that this is the correct thing to do here, but I also don't understand why collapse_all does the same thing. So if someone could explain this to me, it would help me feel better about approving this change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you were right to be suspicious. stocks.i_height appears to be the total height of the right hand side (in interface lines, 3 per entry). When expanding all entries, the total height of the right inside could be computed as simply as:

Suggested change
stocks.i_height = num_sections * 3
num_items = #stocks.current_type_i_list
stocks.i_height = (num_items + num_sections) * 3

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the clarification, I've updated the branch to reflect your suggested way of computing it

end

local function remove_empty()
local empties = {}
for itype,v in ipairs(stocks.storeamount) do
Expand Down Expand Up @@ -52,6 +60,12 @@ function StocksOverlay:init()
key='CUSTOM_CTRL_X',
on_activate=collapse_all,
},
widgets.HotkeyLabel{
frame={t=1, l=0},
label='expand all',
key='CUSTOM_CTRL_Z',
on_activate=expand_all,
},
widgets.HotkeyLabel{
frame={t=2, l=0},
label='remove empties',
Expand Down