Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add distance and value info to buildingplan item selection list #4312 #4956

Merged
merged 3 commits into from
Oct 4, 2024
Merged
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 @@ -66,6 +66,7 @@ Template for new versions:
- Quickfort blueprint library: ``aquifer_tap`` blueprint walkthough rewritten for clarity
- 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
- `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 : ((
- `buildingplan`: add value info to item selection dialog (effectively ungrouping items with different values) and add sorting by value

## Documentation
- Dreamfort: add link to Dreamfort tutorial youtube series: https://www.youtube.com/playlist?list=PLzXx9JcB9oXxmrtkO1y8ZXzBCFEZrKxve
Expand Down
28 changes: 21 additions & 7 deletions plugins/lua/buildingplan/itemselection.lua
frogi16 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local gui = require('gui')
local pens = require('plugins.buildingplan.pens')
local utils = require('utils')
local widgets = require('gui.widgets')
local caravan = reqscript('internal/caravan/common')

local uibs = df.global.buildreq
local to_pen = dfhack.pen.parse
Expand Down Expand Up @@ -60,6 +61,12 @@ local function sort_by_quantity(a, b)
(ad.quantity == bd.quantity and sort_by_type(a, b))
end

local function sort_by_value(a, b)
local ad, bd = a.data, b.data
return ad.value > bd.value or
(ad.value == bd.value and sort_by_type(a, b))
end

ItemSelection = defclass(ItemSelection, widgets.Window)
ItemSelection.ATTRS{
frame_title='Choose items',
Expand Down Expand Up @@ -151,8 +158,9 @@ function ItemSelection:init()
label='Sort by:',
options={
{label='Recently used', value=sort_by_recency},
{label='Name', value=sort_by_name},
{label='Amount', value=sort_by_quantity},
{label='Value', value=sort_by_value},
{label='Name', value=sort_by_name},
},
on_change=self:callback('on_sort'),
},
Expand Down Expand Up @@ -256,33 +264,39 @@ function ItemSelection:get_choices(sort_fn)
local item = df.item.find(item_id)
if not item then goto continue end
local desc = get_item_description(item_id, item)
if buckets[desc] then
local bucket = buckets[desc]
local value = dfhack.items.getValue(item)
local key = desc .. "_" .. tostring(value)
if buckets[key] then
local bucket = buckets[key]
table.insert(bucket.data.item_ids, item_id)
bucket.data.quantity = bucket.data.quantity + 1
else
local entry = {
search_key=make_search_key(desc),
icon=self:callback('get_entry_icon', item_id),
data={
desc=desc,
item_ids={item_id},
item_type=item:getType(),
item_subtype=item:getSubtype(),
quantity=1,
quality=item:getQuality(),
value=value,
selected=0,
},
}
buckets[desc] = entry
buckets[key] = entry
end
::continue::
end
local choices = {}
for desc,choice in pairs(buckets) do
for key,choice in pairs(buckets) do
local data = choice.data
local obfuscated_value = caravan.obfuscate_value(data.value)
choice.text = {
{width=10, text=function() return ('%d/%d'):format(data.selected, data.quantity) end},
{gap=2, text=desc},
{width=8, text=function() return ('%d/%d'):format(data.selected, data.quantity) end},
frogi16 marked this conversation as resolved.
Show resolved Hide resolved
{width=9, gap=2, text=function() return ('%d%s'):format(obfuscated_value, caravan.CH_MONEY) end},
myk002 marked this conversation as resolved.
Show resolved Hide resolved
{gap=2, text=data.desc},
frogi16 marked this conversation as resolved.
Show resolved Hide resolved
}
table.insert(choices, choice)
end
Expand Down
Loading