Skip to content

Commit aba5ddb

Browse files
authored
Merge pull request #3984 from ToxicBananaParty/placesort
Add search overlay to Locations page
2 parents 8a336b1 + 8533f06 commit aba5ddb

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

plugins/lua/sort/locationselector.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ local function stringify_spheres(spheres)
3131
return table.concat(strs, ' ')
3232
end
3333

34-
local function get_religion_string(religion_id, religion_type)
34+
function get_religion_string(religion_id, religion_type)
3535
if religion_id == -1 then return end
3636
local entity
3737
local spheres = {}
38-
if religion_type == 0 then
38+
if religion_type == df.temple_deity_type.Deity then
3939
entity = df.historical_figure.find(religion_id)
4040
add_spheres(entity, spheres)
41-
elseif religion_type == 1 then
41+
elseif religion_type == df.temple_deity_type.Religion then
4242
entity = df.historical_entity.find(religion_id)
4343
if entity then
4444
for _, deity in ipairs(entity.relations.deities) do
@@ -50,8 +50,10 @@ local function get_religion_string(religion_id, religion_type)
5050
return ('%s %s'):format(dfhack.TranslateName(entity.name, true), stringify_spheres(spheres))
5151
end
5252

53-
local function get_profession_string(profession)
54-
return df.profession[profession]:gsub('_', ' ')
53+
function get_profession_string(profession)
54+
local profession_string = df.profession[profession]:gsub('_', ' ')
55+
local dwarfified_string = profession_string:gsub('[Mm][Aa][Nn]', 'dwarf')
56+
return profession_string .. ' ' .. dwarfified_string
5557
end
5658

5759
function LocationSelectorOverlay:init()

plugins/lua/sort/places.lua

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local _ENV = mkmodule('plugins.sort.places')
22

33
local sortoverlay = require('plugins.sort.sortoverlay')
4+
local locationselector = require('plugins.sort.locationselector')
45
local widgets = require('gui.widgets')
56
local 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+
3946
local function get_default_zone_name(zone_type)
4047
return zone_names[zone_type] or ''
4148
end
@@ -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, ' ')
7886
end
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}))
109143
end
110144

111145
function 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
119155
end

0 commit comments

Comments
 (0)