diff --git a/docs/changelog.txt b/docs/changelog.txt index be3371941..0dbb73c90 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -71,6 +71,7 @@ Template for new versions: - `buildingplan`: display how many items are available on the planner panel - `buildingplan`: make it easier to build single-tile staircases of any shape (up, down, or up/down) - `sort`: allow searching by profession on the squad assignment page +- `sort`: add search for places screens - `sort`: add search for work animal assignment screen; allow filtering by miltary/squad/civilian/burrow - `sort`: on the squad assignment screen, make effectiveness and potential ratings use the same scale so effectiveness is always less than or equal to potential for a given unit. this way you can also tell when units are approaching their maximum potential - `sort`: new overlay on the animal assignment screen that shows how many work animals each visible unit already has assigned to them diff --git a/plugins/lua/sort/places.lua b/plugins/lua/sort/places.lua index 326089b29..5dd95b423 100644 --- a/plugins/lua/sort/places.lua +++ b/plugins/lua/sort/places.lua @@ -111,6 +111,36 @@ local function get_location_search_key(zone) return table.concat(result, ' ') end +local function get_stockpile_search_key(stockpile) + if #stockpile.name ~= 0 then return stockpile.name + else return ('Stockpile #%s'):format(stockpile.stockpile_number) end +end + +local function get_workshop_search_key(workshop) + local result = {} + for _, unit_id in ipairs(workshop.profile.permitted_workers) do + local unit = df.unit.find(unit_id) + if unit then table.insert(result, sortoverlay.get_unit_search_key(unit)) end + end + + table.insert(result, workshop.name) + table.insert(result, df.workshop_type.attrs[workshop.type].name or '') + table.insert(result, df.workshop_type[workshop.type]) + + return table.concat(result, ' ') +end + +local function get_farmplot_search_key(farmplot) + local result = {} + + if #farmplot.name ~= 0 then table.insert(result, farmplot.name) else table.insert(result, 'Farm Plot') end + + local plant = df.plant_raw.find(farmplot.plant_id[farmplot.last_season]) + if plant then table.insert(result, plant.name_plural) end + + return table.concat(result, ' ') +end + -- ---------------------- -- PlacesOverlay -- @@ -142,17 +172,14 @@ function PlacesOverlay:init() self:register_handler('ZONES', buildings.list[df.buildings_mode_type.ZONES], curry(sortoverlay.single_vector_search, {get_search_key_fn=get_zone_search_key})) self:register_handler('LOCATIONS', buildings.list[df.buildings_mode_type.LOCATIONS], curry(sortoverlay.single_vector_search, {get_search_key_fn=get_location_search_key})) + self:register_handler('STOCKPILES', buildings.list[df.buildings_mode_type.STOCKPILES], curry(sortoverlay.single_vector_search, {get_search_key_fn=get_stockpile_search_key})) + self:register_handler('WORKSHOPS', buildings.list[df.buildings_mode_type.WORKSHOPS], curry(sortoverlay.single_vector_search, {get_search_key_fn=get_workshop_search_key})) + self:register_handler('FARMPLOTS', buildings.list[df.buildings_mode_type.FARMPLOTS], curry(sortoverlay.single_vector_search, {get_search_key_fn=get_farmplot_search_key})) end function PlacesOverlay:get_key() if info.current_mode == df.info_interface_mode_type.BUILDINGS then - -- TODO: Replace nested if with 'return df.buildings_mode_type[buildings.mode]' once other handlers are written - -- Not there right now so it doesn't render a search bar on unsupported Places subpages - if buildings.mode == df.buildings_mode_type.ZONES then - return 'ZONES' - elseif buildings.mode == df.buildings_mode_type.LOCATIONS then - return 'LOCATIONS' - end + return df.buildings_mode_type[buildings.mode] end end