11local _ENV = mkmodule (' plugins.sort.places' )
22
33local sortoverlay = require (' plugins.sort.sortoverlay' )
4+ local locationselector = require (' plugins.sort.locationselector' )
45local widgets = require (' gui.widgets' )
56local utils = require (' utils' )
67
@@ -33,9 +34,15 @@ local language_name_types = {
3334 [df .language_name_type .SymbolFood ] = ' Inn Tavern' ,
3435 [df .language_name_type .Temple ] = ' Temple' ,
3536 [df .language_name_type .Hospital ] = ' Hospital' ,
36- [df .language_name_type .Guildhall ] = ' Guildhall'
37+ [df .language_name_type .Guildhall ] = ' Guildhall' ,
38+ [df .language_name_type .Library ] = ' Library' ,
3739}
3840
41+ local function get_location_religion (religion_id , religion_type )
42+ if religion_type == df .temple_deity_type .None then return ' Temple'
43+ else return locationselector .get_religion_string (religion_id , religion_type ) or ' ' end
44+ end
45+
3946local function get_default_zone_name (zone_type )
4047 return zone_names [zone_type ] or ' '
4148end
@@ -60,7 +67,8 @@ local function get_zone_search_key(zone)
6067 if zone .location_id == - 1 then -- zone is NOT a special location and we don't need to do anything special for type searching
6168 table.insert (result , df .civzone_type [zone .type ]);
6269 else -- zone is a special location and we need to get its type from world data
63- local building , success , _ = utils .binsearch (site .buildings , zone .location_id , ' id' )
70+ local building , success = utils .binsearch (site .buildings , zone .location_id , ' id' )
71+
6472 if success and building .name then
6573 table.insert (result , language_name_types [building .name .type ] or ' ' )
6674 if building .name .has_name then
@@ -77,6 +85,31 @@ local function get_zone_search_key(zone)
7785 return table.concat (result , ' ' )
7886end
7987
88+ local function get_location_search_key (zone )
89+ local site = df .global .world .world_data .active_site [0 ]
90+ local result = {}
91+
92+ -- get language_name and type (we dont need user-given zone name because it does not appear on this page)
93+ local building , success = utils .binsearch (site .buildings , zone .location_id , ' id' )
94+ if success and building .name then
95+ table.insert (result , language_name_types [building .name .type ] or ' ' )
96+ if building .name .has_name then
97+ table.insert (result , dfhack .TranslateName (building .name , true ))
98+ end
99+
100+ -- for temples and guildhalls, get assigned organization
101+ if df .abstract_building_templest :is_instance (building ) then
102+ table.insert (result , get_location_religion (building .deity_data .Deity or building .deity_data .Religion , building .deity_type ))
103+ elseif df .abstract_building_guildhallst :is_instance (building ) then
104+ local dwarfified_profession = locationselector .get_profession_string (building .contents .profession )
105+ table.insert (result , dwarfified_profession )
106+ end
107+
108+ end
109+
110+ return table.concat (result , ' ' )
111+ end
112+
80113-- ----------------------
81114-- PlacesOverlay
82115--
@@ -106,6 +139,7 @@ function PlacesOverlay:init()
106139 }
107140
108141 self :register_handler (' ZONES' , buildings .list [df .buildings_mode_type .ZONES ], curry (sortoverlay .single_vector_search , {get_search_key_fn = get_zone_search_key }))
142+ self :register_handler (' LOCATIONS' , buildings .list [df .buildings_mode_type .LOCATIONS ], curry (sortoverlay .single_vector_search , {get_search_key_fn = get_location_search_key }))
109143end
110144
111145function PlacesOverlay :get_key ()
@@ -114,6 +148,8 @@ function PlacesOverlay:get_key()
114148 -- Not there right now so it doesn't render a search bar on unsupported Places subpages
115149 if buildings .mode == df .buildings_mode_type .ZONES then
116150 return ' ZONES'
151+ elseif buildings .mode == df .buildings_mode_type .LOCATIONS then
152+ return ' LOCATIONS'
117153 end
118154 end
119155end
0 commit comments