Skip to content

Commit

Permalink
Merge pull request #1353 from myk002/myk_pedestal
Browse files Browse the repository at this point in the history
[caravan] add filter for written works
  • Loading branch information
myk002 authored Dec 25, 2024
2 parents 0324a19 + 77e91ea commit afcd9c1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Template for new versions:

## Misc Improvements
- `immortal-cravings`: goblins and other naturally non-eating/non-drinking races will now also satisfy their needs for eating and drinking
- `caravan`: add filter for written works in display furniture assignment dialog

## Removed

Expand Down
8 changes: 6 additions & 2 deletions docs/caravan.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,9 @@ assignment GUI.
The dialog allows you to sort by name, value, or where the item is currently
assigned for display.

You can search by name, and you can filter by item quality and by whether the
item is forbidden.
You can search by name, and you can filter by:

- item quality
- whether the item is forbidden
- whether the item is reachable from the display furniture
- whether the item is a written work (book or scroll)
26 changes: 25 additions & 1 deletion internal/caravan/pedestal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ local filters = {
max_quality=6,
hide_unreachable=true,
hide_forbidden=false,
hide_written=false,
inside_containers=true,
}

Expand Down Expand Up @@ -288,7 +289,7 @@ function AssignItems:init()
},
widgets.ToggleHotkeyLabel{
view_id='hide_forbidden',
frame={t=2, l=40, w=30},
frame={t=1, l=40, w=30},
label='Hide forbidden items:',
key='CUSTOM_SHIFT_F',
options={
Expand All @@ -302,6 +303,22 @@ function AssignItems:init()
self:refresh_list()
end,
},
widgets.ToggleHotkeyLabel{
view_id='hide_written',
frame={t=3, l=40, w=30},
label='Hide written items:',
key='CUSTOM_SHIFT_W',
options={
{label='Yes', value=true, pen=COLOR_GREEN},
{label='No', value=false}
},
option_gap=5,
initial_option=filters.hide_written,
on_change=function(val)
filters.hide_written = val
self:refresh_list()
end,
},
},
},
widgets.Panel{
Expand Down Expand Up @@ -553,17 +570,24 @@ function AssignItems:cache_choices(inside_containers, display_bld)
return choices
end

local function is_written_work(item)
if df.item_bookst:is_instance(item) then return true end
return df.item_toolst:is_instance(item) and item:hasToolUse(df.tool_uses.CONTAIN_WRITING)
end

function AssignItems:get_choices()
local raw_choices = self:cache_choices(self.subviews.inside_containers:getOptionValue(), self.bld)
local choices = {}
local include_unreachable = not self.subviews.hide_unreachable:getOptionValue()
local include_forbidden = not self.subviews.hide_forbidden:getOptionValue()
local include_written = not self.subviews.hide_written:getOptionValue()
local min_quality = self.subviews.min_quality:getOptionValue()
local max_quality = self.subviews.max_quality:getOptionValue()
for _,choice in ipairs(raw_choices) do
local data = choice.data
if not include_unreachable and not data.reachable then goto continue end
if not include_forbidden and data.item.flags.forbid then goto continue end
if not include_written and is_written_work(data.item) then goto continue end
if min_quality > data.quality then goto continue end
if max_quality < data.quality then goto continue end
table.insert(choices, choice)
Expand Down

0 comments on commit afcd9c1

Please sign in to comment.