Skip to content

Commit

Permalink
Merge pull request #3958 from myk002/myk_work_animal
Browse files Browse the repository at this point in the history
[sort] support search and filter for work animal assignment
  • Loading branch information
myk002 authored Nov 5, 2023
2 parents f986029 + e196ceb commit cfec7ce
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Template for new versions:
## Misc Improvements
- `buildingplan`: display how many items are available on the planner panel
- `sort`: allow searching by profession on the squad assignment page
- `sort`: add search for work animal assignment screen; allow filtering by miltary/civilian
- `dreamfort`: Inside+ and Clearcutting burrows now automatically created and managed

## Documentation
Expand Down
47 changes: 40 additions & 7 deletions plugins/lua/sort/info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ local function get_race_name(raw_id)
return raw.name[1]
end

local function get_trainer_search_key(unit)
if not unit then return end
return ('%s %s'):format(dfhack.TranslateName(unit.name), dfhack.units.getProfessionName(unit))
end

-- get name in both dwarvish and English
local function get_artifact_search_key(artifact)
return ('%s %s'):format(dfhack.TranslateName(artifact.name), dfhack.TranslateName(artifact.name, true))
Expand Down Expand Up @@ -166,7 +161,7 @@ InfoOverlay = defclass(InfoOverlay, sortoverlay.SortOverlay)
InfoOverlay.ATTRS{
default_pos={x=64, y=8},
viewscreens='dwarfmode/Info',
frame={w=40, h=4},
frame={w=40, h=5},
}

function InfoOverlay:init()
Expand All @@ -185,6 +180,25 @@ function InfoOverlay:init()
},
},
},
widgets.BannerPanel{
view_id='filter_panel',
frame={l=0, t=1, r=0, h=1},
visible=function() return self:get_key() == 'PET_WA' end,
subviews={
widgets.CycleHotkeyLabel{
view_id='subset',
frame={l=1, t=0},
key='CUSTOM_SHIFT_F',
label='Show:',
options={
{label='All', value='all', pen=COLOR_GREEN},
{label='Military', value='military', pen=COLOR_YELLOW},
{label='Civilians', value='civilian', pen=COLOR_CYAN},
},
on_change=function() self:do_search(self.subviews.search.text, true) end,
},
},
},
}

local CRI_UNIT_VECS = {
Expand All @@ -209,7 +223,12 @@ function InfoOverlay:init()
self:register_handler('PET_OT', creatures.atk_index,
curry(sortoverlay.single_vector_search, {get_search_key_fn=get_race_name}))
self:register_handler('PET_AT', creatures.trainer,
curry(sortoverlay.single_vector_search, {get_search_key_fn=get_trainer_search_key}))
curry(sortoverlay.single_vector_search, {get_search_key_fn=sortoverlay.get_unit_search_key}))
self:register_handler('PET_WA', creatures.work_animal_recipient,
curry(sortoverlay.single_vector_search, {
get_search_key_fn=sortoverlay.get_unit_search_key,
matches_filters_fn=self:callback('matches_filters'),
}))
self:register_handler('WORK_DETAILS', work_details.assignable_unit, work_details_search)

for idx,name in ipairs(df.artifacts_mode_type) do
Expand All @@ -227,6 +246,8 @@ function InfoOverlay:get_key()
return 'PET_OT'
elseif creatures.adding_trainer then
return 'PET_AT'
elseif creatures.assign_work_animal then
return 'PET_WA'
end
end
return df.unit_list_mode_type[creatures.current_mode]
Expand Down Expand Up @@ -275,6 +296,8 @@ function InfoOverlay:updateFrames()
local frame = self.subviews.panel.frame
if frame.l == l and frame.t == t then return ret end
frame.l, frame.t = l, t
local frame2 = self.subviews.filter_panel.frame
frame2.l, frame2.t = l, t + 1
return true
end

Expand All @@ -296,6 +319,16 @@ function InfoOverlay:onInput(keys)
return InfoOverlay.super.onInput(self, keys)
end

function InfoOverlay:matches_filters(unit)
local subset = self.subviews.subset:getOptionValue()
if subset == 'all' then
return true
elseif unit.military.squad_id == -1 then
return subset == 'civilian'
end
return subset == 'military'
end

-- ----------------------
-- CandidatesOverlay
--
Expand Down

0 comments on commit cfec7ce

Please sign in to comment.