unify unit search key logic

so all pages have the same search capabilities
develop
Myk Taylor 2023-10-26 19:24:01 -07:00
parent ea28f599ed
commit 966762c198
No known key found for this signature in database
6 changed files with 19 additions and 23 deletions

@ -60,6 +60,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
## Documentation

@ -3,7 +3,7 @@ local _ENV = mkmodule('plugins.sort')
local gui = require('gui')
local overlay = require('plugins.overlay')
local setbelief = reqscript('modtools/set-belief')
local textures = require('gui.textures')
local sortoverlay = require('plugins.sort.sortoverlay')
local utils = require('utils')
local widgets = require('gui.widgets')
@ -1031,7 +1031,7 @@ local function filter_matches(unit_id, filter)
if filter.maimed == 'only' and not is_maimed(unit) then return false end
if filter.maimed == 'exclude' and is_maimed(unit) then return false end
if #filter.search == 0 then return true end
local search_key = dfhack.TranslateName(dfhack.units.getVisibleName(unit))
local search_key = sortoverlay.get_unit_search_key(unit)
return normalize_search_key(search_key):find(dfhack.toSearchNormalized(filter.search))
end
@ -1233,6 +1233,7 @@ local function init_face_tiles()
FACE_TILES[idx-1] = face
end
end
init_face_tiles()
function get_stress_face_tile(idx, x, y)
local elem = rating_annotations[idx]
@ -1240,7 +1241,7 @@ function get_stress_face_tile(idx, x, y)
return x == 0 and y == 1 and DASH_PEN or gui.CLEAR_PEN
end
local val = math.min(6, elem.val)
return FACE_TILES[val][y][x]
return safe_index(FACE_TILES, val, y, x)
end
function SquadAnnotationOverlay:init()

@ -97,16 +97,9 @@ local function get_sort()
end
end
local function get_unit_search_key(unit)
return ('%s %s %s'):format(
dfhack.units.getReadableName(unit), -- last name is in english
dfhack.units.getProfessionName(unit),
dfhack.TranslateName(unit.name, false, true)) -- get untranslated last name
end
local function get_cri_unit_search_key(cri_unit)
return ('%s %s'):format(
cri_unit.un and get_unit_search_key(cri_unit.un) or '',
cri_unit.un and sortoverlay.get_unit_search_key(cri_unit.un) or '',
cri_unit.job_sort_name)
end
@ -132,7 +125,7 @@ local function work_details_search(vec, data, text, incremental)
data.selected = work_details.selected_work_detail_index
end
sortoverlay.single_vector_search(
{get_search_key_fn=get_unit_search_key},
{get_search_key_fn=sortoverlay.get_unit_search_key},
vec, data, text, incremental)
end
@ -161,7 +154,7 @@ end
local function get_candidate_search_key(cand)
if not cand.un then return end
return ('%s %s'):format(
get_unit_search_key(cand.un),
sortoverlay.get_unit_search_key(cand.un),
serialize_skills(cand.un))
end
@ -420,7 +413,7 @@ function InterrogationOverlay:init()
self:register_handler('INTERROGATING', justice.interrogation_list,
curry(sortoverlay.flags_vector_search,
{
get_search_key_fn=get_unit_search_key,
get_search_key_fn=sortoverlay.get_unit_search_key,
get_elem_id_fn=function(unit) return unit.id end,
matches_filters_fn=self:callback('matches_filters'),
},
@ -428,7 +421,7 @@ function InterrogationOverlay:init()
self:register_handler('CONVICTING', justice.conviction_list,
curry(sortoverlay.single_vector_search,
{
get_search_key_fn=get_unit_search_key,
get_search_key_fn=sortoverlay.get_unit_search_key,
matches_filters_fn=self:callback('matches_filters'),
}))
end

@ -5,7 +5,6 @@ local sortoverlay = require('plugins.sort.sortoverlay')
local widgets = require('gui.widgets')
local building = df.global.game.main_interface.building
local view_sheets = df.global.game.main_interface.view_sheets
-- ----------------------
-- SlabOverlay
@ -95,9 +94,7 @@ end
function SlabOverlay:get_search_key(if_button)
local unit = get_unit(if_button)
if not unit then return if_button.filter_str end
return ('%s %s'):format(
dfhack.units.getReadableName(unit), -- last name is in english
dfhack.TranslateName(unit.name, false, true)) -- get untranslated last name
return sortoverlay.get_unit_search_key(unit)
end
local function needs_slab(if_button)

@ -3,6 +3,13 @@ local _ENV = mkmodule('plugins.sort.sortoverlay')
local overlay = require('plugins.overlay')
local utils = require('utils')
function get_unit_search_key(unit)
return ('%s %s %s'):format(
dfhack.units.getReadableName(unit), -- last name is in english
dfhack.units.getProfessionName(unit),
dfhack.TranslateName(unit.name, false, true)) -- get untranslated last name
end
local function copy_to_lua_table(vec)
local tab = {}
for k,v in ipairs(vec) do

@ -20,10 +20,7 @@ UnitSelectorOverlay.ATTRS{
local function get_unit_id_search_key(unit_id)
local unit = df.unit.find(unit_id)
if not unit then return end
return ('%s %s %s'):format(
dfhack.units.getReadableName(unit), -- last name is in english
dfhack.units.getProfessionName(unit),
dfhack.TranslateName(unit.name, false, true)) -- get untranslated last name
return sortoverlay.get_unit_search_key(unit)
end
function UnitSelectorOverlay:init()