Merge pull request #3958 from myk002/myk_work_animal

[sort] support search and filter for work animal assignment
develop
Myk 2023-11-04 19:37:48 -07:00 committed by GitHub
commit cfec7cef12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 7 deletions

@ -67,6 +67,7 @@ Template for new versions:
## Misc Improvements ## Misc Improvements
- `buildingplan`: display how many items are available on the planner panel - `buildingplan`: display how many items are available on the planner panel
- `sort`: allow searching by profession on the squad assignment page - `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 - `dreamfort`: Inside+ and Clearcutting burrows now automatically created and managed
## Documentation ## Documentation

@ -109,11 +109,6 @@ local function get_race_name(raw_id)
return raw.name[1] return raw.name[1]
end 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 -- get name in both dwarvish and English
local function get_artifact_search_key(artifact) local function get_artifact_search_key(artifact)
return ('%s %s'):format(dfhack.TranslateName(artifact.name), dfhack.TranslateName(artifact.name, true)) return ('%s %s'):format(dfhack.TranslateName(artifact.name), dfhack.TranslateName(artifact.name, true))
@ -166,7 +161,7 @@ InfoOverlay = defclass(InfoOverlay, sortoverlay.SortOverlay)
InfoOverlay.ATTRS{ InfoOverlay.ATTRS{
default_pos={x=64, y=8}, default_pos={x=64, y=8},
viewscreens='dwarfmode/Info', viewscreens='dwarfmode/Info',
frame={w=40, h=4}, frame={w=40, h=5},
} }
function InfoOverlay:init() function InfoOverlay:init()
@ -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 = { local CRI_UNIT_VECS = {
@ -209,7 +223,12 @@ function InfoOverlay:init()
self:register_handler('PET_OT', creatures.atk_index, self:register_handler('PET_OT', creatures.atk_index,
curry(sortoverlay.single_vector_search, {get_search_key_fn=get_race_name})) curry(sortoverlay.single_vector_search, {get_search_key_fn=get_race_name}))
self:register_handler('PET_AT', creatures.trainer, 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) self:register_handler('WORK_DETAILS', work_details.assignable_unit, work_details_search)
for idx,name in ipairs(df.artifacts_mode_type) do for idx,name in ipairs(df.artifacts_mode_type) do
@ -227,6 +246,8 @@ function InfoOverlay:get_key()
return 'PET_OT' return 'PET_OT'
elseif creatures.adding_trainer then elseif creatures.adding_trainer then
return 'PET_AT' return 'PET_AT'
elseif creatures.assign_work_animal then
return 'PET_WA'
end end
end end
return df.unit_list_mode_type[creatures.current_mode] return df.unit_list_mode_type[creatures.current_mode]
@ -275,6 +296,8 @@ function InfoOverlay:updateFrames()
local frame = self.subviews.panel.frame local frame = self.subviews.panel.frame
if frame.l == l and frame.t == t then return ret end if frame.l == l and frame.t == t then return ret end
frame.l, frame.t = l, t frame.l, frame.t = l, t
local frame2 = self.subviews.filter_panel.frame
frame2.l, frame2.t = l, t + 1
return true return true
end end
@ -296,6 +319,16 @@ function InfoOverlay:onInput(keys)
return InfoOverlay.super.onInput(self, keys) return InfoOverlay.super.onInput(self, keys)
end 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 -- CandidatesOverlay
-- --