Skip to content

Commit 832069c

Browse files
authored
Merge pull request #4956 from frogi16/develop
Add distance and value info to buildingplan item selection list #4312
2 parents ac5da59 + 48a9738 commit 832069c

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Template for new versions:
6666
- Quickfort blueprint library: ``aquifer_tap`` blueprint walkthough rewritten for clarity
6767
- Quickfort blueprint library: ``aquifer_tap`` blueprint now designated at priority 3 and marks the stairway tile below the tap in "blueprint" mode to prevent drips while the drainage pipe is being prepared
6868
- `preserve-rooms`: automatically release room reservations for captured squad members. we were kidding ourselves with our optimistic kept reservations. they're unlikely to come back : ((
69+
- `buildingplan`: add value info to item selection dialog (effectively ungrouping items with different values) and add sorting by value
6970

7071
## Documentation
7172
- Dreamfort: add link to Dreamfort tutorial youtube series: https://www.youtube.com/playlist?list=PLzXx9JcB9oXxmrtkO1y8ZXzBCFEZrKxve

plugins/lua/buildingplan/itemselection.lua

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local gui = require('gui')
44
local pens = require('plugins.buildingplan.pens')
55
local utils = require('utils')
66
local widgets = require('gui.widgets')
7+
local caravan = reqscript('internal/caravan/common')
78

89
local uibs = df.global.buildreq
910
local to_pen = dfhack.pen.parse
@@ -60,6 +61,12 @@ local function sort_by_quantity(a, b)
6061
(ad.quantity == bd.quantity and sort_by_type(a, b))
6162
end
6263

64+
local function sort_by_value(a, b)
65+
local ad, bd = a.data, b.data
66+
return ad.value > bd.value or
67+
(ad.value == bd.value and sort_by_type(a, b))
68+
end
69+
6370
ItemSelection = defclass(ItemSelection, widgets.Window)
6471
ItemSelection.ATTRS{
6572
frame_title='Choose items',
@@ -151,8 +158,9 @@ function ItemSelection:init()
151158
label='Sort by:',
152159
options={
153160
{label='Recently used', value=sort_by_recency},
154-
{label='Name', value=sort_by_name},
155161
{label='Amount', value=sort_by_quantity},
162+
{label='Value', value=sort_by_value},
163+
{label='Name', value=sort_by_name},
156164
},
157165
on_change=self:callback('on_sort'),
158166
},
@@ -256,33 +264,39 @@ function ItemSelection:get_choices(sort_fn)
256264
local item = df.item.find(item_id)
257265
if not item then goto continue end
258266
local desc = get_item_description(item_id, item)
259-
if buckets[desc] then
260-
local bucket = buckets[desc]
267+
local value = dfhack.items.getValue(item)
268+
local key = desc .. "_" .. tostring(value)
269+
if buckets[key] then
270+
local bucket = buckets[key]
261271
table.insert(bucket.data.item_ids, item_id)
262272
bucket.data.quantity = bucket.data.quantity + 1
263273
else
264274
local entry = {
265275
search_key=make_search_key(desc),
266276
icon=self:callback('get_entry_icon', item_id),
267277
data={
278+
desc=desc,
268279
item_ids={item_id},
269280
item_type=item:getType(),
270281
item_subtype=item:getSubtype(),
271282
quantity=1,
272283
quality=item:getQuality(),
284+
value=value,
273285
selected=0,
274286
},
275287
}
276-
buckets[desc] = entry
288+
buckets[key] = entry
277289
end
278290
::continue::
279291
end
280292
local choices = {}
281-
for desc,choice in pairs(buckets) do
293+
for key,choice in pairs(buckets) do
282294
local data = choice.data
295+
local obfuscated_value = caravan.obfuscate_value(data.value)
283296
choice.text = {
284-
{width=10, text=function() return ('%d/%d'):format(data.selected, data.quantity) end},
285-
{gap=2, text=desc},
297+
{width=8, text=function() return ('%d/%d'):format(data.selected, data.quantity) end},
298+
{width=9, gap=2, text=function() return ('%s%s'):format(obfuscated_value, caravan.CH_MONEY) end},
299+
{gap=2, text=data.desc},
286300
}
287301
table.insert(choices, choice)
288302
end

0 commit comments

Comments
 (0)