Skip to content

Commit cc421f0

Browse files
authored
Merge pull request #1405 from myk002/myk_sitemap
[gui/sitemap] implement shift click to follow
2 parents 8639a8f + 8665a1a commit cc421f0

3 files changed

Lines changed: 54 additions & 10 deletions

File tree

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Template for new versions:
4444
- `gui/notify`: moody dwarf notification turns red when they can't reach workshop or items
4545
- `gui/confirm`: in the delete manager order confirmation dialog, show a description of which order you have selected to delete
4646
- `position`: display both adventurer and site pos simultaneously. Display map block pos+offset of selected tile.
47+
- `gui/sitemap`: shift click to start following the selected unit or artifact
4748

4849
## Removed
4950

docs/gui/sitemap.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ gui/sitemap
77

88
This simple UI gives you searchable lists of people, locations (temples,
99
guildhalls, hospitals, taverns, and libraries), and artifacts in the local area.
10-
Clicking on a list item will zoom the map to the target. If you are zooming to
11-
a location and the location has multiple zones attached to it, clicking again
12-
will zoom to each component zone in turn.
10+
Clicking on a list item will zoom the map to the target. In fort mode,
11+
shift-clicking will zoom to the unit or artifact and lock the camera to the
12+
target with follow mode. If you are zooming to a location and the location has
13+
multiple zones attached to it, clicking again will zoom to each component zone
14+
in turn.
1315

1416
Locations are attached to a site, so if you're in adventure mode, you must
1517
enter a site before searching for locations. For worldgen sites, many locations

gui/sitemap.lua

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Sitemap.ATTRS {
1313
frame_title='Sitemap',
1414
frame={w=57, r=2, t=18, h=25},
1515
resizable=true,
16-
resize_min={w=43, h=20},
16+
resize_min={w=44, h=20},
17+
frame_inset={l=1, t=1, r=0, b=0},
1718
}
1819

1920
local function to_title_case(str)
@@ -169,6 +170,19 @@ local function zoom_to_unit(_, choice)
169170
if not unit then return end
170171
dfhack.gui.revealInDwarfmodeMap(
171172
xyz2pos(dfhack.units.getPosition(unit)), true, true)
173+
return unit.id
174+
end
175+
176+
local function follow_unit(idx, choice)
177+
local unit_id = zoom_to_unit(idx, choice)
178+
if not unit_id or not dfhack.world.isFortressMode() then return end
179+
df.global.plotinfo.follow_item = -1
180+
df.global.plotinfo.follow_unit = unit_id
181+
pcall(function()
182+
-- if spectate is available, add the unit to the follow history
183+
local spectate = require('plugins.spectate')
184+
spectate.spectate_addToHistory(unit_id)
185+
end)
172186
end
173187

174188
local function get_artifact_choices()
@@ -192,6 +206,33 @@ local function zoom_to_item(_, choice)
192206
if not item then return end
193207
dfhack.gui.revealInDwarfmodeMap(
194208
xyz2pos(dfhack.items.getPosition(item)), true, true)
209+
return item.id
210+
end
211+
212+
local function follow_item(idx, choice)
213+
local item_id = zoom_to_item(idx, choice)
214+
if not item_id or not dfhack.world.isFortressMode() then return end
215+
df.global.plotinfo.follow_item = item_id
216+
df.global.plotinfo.follow_unit = -1
217+
end
218+
219+
local function get_bottom_text()
220+
local text = {
221+
'Click on a name or hit ', {text='Enter', pen=COLOR_LIGHTGREEN}, ' to zoom to', NEWLINE,
222+
'the selected target.',
223+
}
224+
225+
if not dfhack.world.isFortressMode() then
226+
table.insert(text, NEWLINE)
227+
table.insert(text, NEWLINE)
228+
return text
229+
end
230+
231+
table.insert(text, ' Shift-click or')
232+
table.insert(text, NEWLINE)
233+
table.insert(text, {text='Shift-Enter', pen=COLOR_LIGHTGREEN})
234+
table.insert(text, ' to zoom and follow unit/item.')
235+
return text
195236
end
196237

197238
function Sitemap:init()
@@ -217,7 +258,7 @@ function Sitemap:init()
217258
},
218259
widgets.Pages{
219260
view_id='pages',
220-
frame={t=3, l=0, b=5, r=0},
261+
frame={t=3, l=0, b=6, r=0},
221262
subviews={
222263
widgets.Panel{
223264
subviews={
@@ -230,6 +271,7 @@ function Sitemap:init()
230271
widgets.FilteredList{
231272
view_id='list',
232273
on_submit=zoom_to_unit,
274+
on_submit2=follow_unit,
233275
choices=unit_choices,
234276
visible=#unit_choices > 0,
235277
},
@@ -255,6 +297,7 @@ function Sitemap:init()
255297
widgets.FilteredList{
256298
view_id='list',
257299
on_submit=zoom_to_next_zone,
300+
on_submit2=zoom_to_next_zone,
258301
choices=location_choices,
259302
visible=#location_choices > 0,
260303
},
@@ -271,6 +314,7 @@ function Sitemap:init()
271314
widgets.FilteredList{
272315
view_id='list',
273316
on_submit=zoom_to_item,
317+
on_submit2=follow_item,
274318
choices=artifact_choices,
275319
visible=#artifact_choices > 0,
276320
},
@@ -279,17 +323,14 @@ function Sitemap:init()
279323
},
280324
},
281325
widgets.Divider{
282-
frame={b=3, h=1},
326+
frame={b=4, h=1, l=0, r=1},
283327
frame_style=gui.FRAME_THIN,
284328
frame_style_l=false,
285329
frame_style_r=false,
286330
},
287331
widgets.Label{
288332
frame={b=0, l=0},
289-
text={
290-
'Click on a name or hit ', {text='Enter', pen=COLOR_LIGHTGREEN}, NEWLINE,
291-
'to zoom to the selected target.'
292-
},
333+
text=get_bottom_text(),
293334
},
294335
}
295336
end

0 commit comments

Comments
 (0)