Skip to content

Commit 5b12b1e

Browse files
committed
Ungroup items with same names but different values
- save item name (desc) in dictionary items instead of using keys for this purpose - encode item value in dictionary key, this way ungrouping items with different values
1 parent 38b6ac2 commit 5b12b1e

2 files changed

Lines changed: 13 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: 12 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
@@ -263,35 +264,39 @@ function ItemSelection:get_choices(sort_fn)
263264
local item = df.item.find(item_id)
264265
if not item then goto continue end
265266
local desc = get_item_description(item_id, item)
266-
if buckets[desc] then
267-
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]
268271
table.insert(bucket.data.item_ids, item_id)
269272
bucket.data.quantity = bucket.data.quantity + 1
270273
else
271274
local entry = {
272275
search_key=make_search_key(desc),
273276
icon=self:callback('get_entry_icon', item_id),
274277
data={
278+
desc=desc,
275279
item_ids={item_id},
276280
item_type=item:getType(),
277281
item_subtype=item:getSubtype(),
278282
quantity=1,
279283
quality=item:getQuality(),
280-
value=dfhack.items.getValue(item),
284+
value=value,
281285
selected=0,
282286
},
283287
}
284-
buckets[desc] = entry
288+
buckets[key] = entry
285289
end
286290
::continue::
287291
end
288292
local choices = {}
289-
for desc,choice in pairs(buckets) do
293+
for key,choice in pairs(buckets) do
290294
local data = choice.data
295+
local obfuscated_value = caravan.obfuscate_value(data.value)
291296
choice.text = {
292297
{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},
294-
{gap=2, text=desc},
298+
{width=9, gap=2, text=function() return ('%d%s'):format(obfuscated_value, caravan.CH_MONEY) end},
299+
{gap=2, text=data.desc},
295300
}
296301
table.insert(choices, choice)
297302
end

0 commit comments

Comments
 (0)