Skip to content

Commit 38b6ac2

Browse files
committed
Add distance and value info to buildingplan item selection list #4312
- adjust width of existing columns - reorder sorting options to match ordering of colums
1 parent ac5da59 commit 38b6ac2

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

plugins/lua/buildingplan/itemselection.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ local function sort_by_quantity(a, b)
6060
(ad.quantity == bd.quantity and sort_by_type(a, b))
6161
end
6262

63+
local function sort_by_value(a, b)
64+
local ad, bd = a.data, b.data
65+
return ad.value > bd.value or
66+
(ad.value == bd.value and sort_by_type(a, b))
67+
end
68+
6369
ItemSelection = defclass(ItemSelection, widgets.Window)
6470
ItemSelection.ATTRS{
6571
frame_title='Choose items',
@@ -151,8 +157,9 @@ function ItemSelection:init()
151157
label='Sort by:',
152158
options={
153159
{label='Recently used', value=sort_by_recency},
154-
{label='Name', value=sort_by_name},
155160
{label='Amount', value=sort_by_quantity},
161+
{label='Value', value=sort_by_value},
162+
{label='Name', value=sort_by_name},
156163
},
157164
on_change=self:callback('on_sort'),
158165
},
@@ -270,6 +277,7 @@ function ItemSelection:get_choices(sort_fn)
270277
item_subtype=item:getSubtype(),
271278
quantity=1,
272279
quality=item:getQuality(),
280+
value=dfhack.items.getValue(item),
273281
selected=0,
274282
},
275283
}
@@ -281,7 +289,8 @@ function ItemSelection:get_choices(sort_fn)
281289
for desc,choice in pairs(buckets) do
282290
local data = choice.data
283291
choice.text = {
284-
{width=10, text=function() return ('%d/%d'):format(data.selected, data.quantity) end},
292+
{width=8, text=function() return ('%d/%d'):format(data.selected, data.quantity) end},
293+
{width=8, gap=2, text=function() return ('%d\x0F'):format(data.value) end},
285294
{gap=2, text=desc},
286295
}
287296
table.insert(choices, choice)

0 commit comments

Comments
 (0)