Skip to content

Commit c6cbd00

Browse files
committed
combine.lua try harder to find the currently-selected stockpile
If a stockpile is not selected, try finding it using these: * If an item is selected, find the stockpile (if any) that it is in. * If a dwarfmode/ViewSheets/ITEM_LIST is active in the UI, find the stockpile (if any) of the tile being viewed.
1 parent 72f90ad commit c6cbd00

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Template for new versions:
3333
## Fixes
3434

3535
## Misc Improvements
36+
- `combine`: try harder to find the currently-selected stockpile
3637

3738
## Removed
3839

combine.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,26 @@ local function get_stockpile_here()
736736
-- return the stockpile as a table
737737
local stockpiles = {}
738738
local building = dfhack.gui.getSelectedStockpile(true)
739+
740+
-- try finding the stockpile by viewed item or first item in itemlist viewsheet.
741+
if building == nil then
742+
local item = nil
743+
if dfhack.gui.getSelectedItem(--[[silent]]true) ~= nil then
744+
item = dfhack.gui.getSelectedItem(--[[silent]]true)
745+
elseif tonumber(dfhack.DF_VERSION:match("^0*%.*(%d+%.%d+)")) >= 50.07 -- matchFocusString() in Commit a770a4c
746+
and dfhack.gui.matchFocusString("dwarfmode/ViewSheets/ITEM_LIST", dfhack.gui.getDFViewscreen())
747+
and df.global.game.main_interface.view_sheets.open == true
748+
and df.global.game.main_interface.view_sheets.active_sheet == df.view_sheet_type.ITEM_LIST
749+
and #df.global.game.main_interface.view_sheets.viewing_itid > 0
750+
then
751+
local itemid = df.global.game.main_interface.view_sheets.viewing_itid[0]
752+
item = df.item.find(itemid)
753+
end
754+
local pos = (item) and xyz2pos(dfhack.items.getPosition(item)) or nil
755+
building = (pos) and dfhack.buildings.findAtTile(pos) or nil
756+
building = (df.building_stockpilest:is_instance(building)) and building or nil
757+
end
758+
739759
if not building then qerror('Please select a stockpile.') end
740760
table.insert(stockpiles, building)
741761
if opts.verbose > 0 then

0 commit comments

Comments
 (0)