Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Template for new versions:
- `gui/notify`: moody dwarf notification turns red when they can't reach workshop or items
- `gui/confirm`: in the delete manager order confirmation dialog, show a description of which order you have selected to delete
- `position`: display both adventurer and site pos simultaneously. Display map block pos+offset of selected tile.
- `gui/sitemap`: shift click to start following the selected unit or artifact

## Removed

Expand Down
8 changes: 5 additions & 3 deletions docs/gui/sitemap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ gui/sitemap

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

Locations are attached to a site, so if you're in adventure mode, you must
enter a site before searching for locations. For worldgen sites, many locations
Expand Down
55 changes: 48 additions & 7 deletions gui/sitemap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Sitemap.ATTRS {
frame_title='Sitemap',
frame={w=57, r=2, t=18, h=25},
resizable=true,
resize_min={w=43, h=20},
resize_min={w=44, h=20},
frame_inset={l=1, t=1, r=0, b=0},
}

local function to_title_case(str)
Expand Down Expand Up @@ -169,6 +170,19 @@ local function zoom_to_unit(_, choice)
if not unit then return end
dfhack.gui.revealInDwarfmodeMap(
xyz2pos(dfhack.units.getPosition(unit)), true, true)
return unit.id
end

local function follow_unit(idx, choice)
local unit_id = zoom_to_unit(idx, choice)
if not unit_id or not dfhack.world.isFortressMode() then return end
df.global.plotinfo.follow_item = -1
df.global.plotinfo.follow_unit = unit_id
pcall(function()
-- if spectate is available, add the unit to the follow history
local spectate = require('plugins.spectate')
spectate.spectate_addToHistory(unit_id)
end)
end

local function get_artifact_choices()
Expand All @@ -192,6 +206,33 @@ local function zoom_to_item(_, choice)
if not item then return end
dfhack.gui.revealInDwarfmodeMap(
xyz2pos(dfhack.items.getPosition(item)), true, true)
return item.id
end

local function follow_item(idx, choice)
local item_id = zoom_to_item(idx, choice)
if not item_id or not dfhack.world.isFortressMode() then return end
df.global.plotinfo.follow_item = item_id
df.global.plotinfo.follow_unit = -1
end

local function get_bottom_text()
local text = {
'Click on a name or hit ', {text='Enter', pen=COLOR_LIGHTGREEN}, ' to zoom to', NEWLINE,
'the selected target.',
}

if not dfhack.world.isFortressMode() then
table.insert(text, NEWLINE)
table.insert(text, NEWLINE)
return text
end

table.insert(text, ' Shift-click or')
table.insert(text, NEWLINE)
table.insert(text, {text='Shift-Enter', pen=COLOR_LIGHTGREEN})
table.insert(text, ' to zoom and follow unit/item.')
return text
end

function Sitemap:init()
Expand All @@ -217,7 +258,7 @@ function Sitemap:init()
},
widgets.Pages{
view_id='pages',
frame={t=3, l=0, b=5, r=0},
frame={t=3, l=0, b=6, r=0},
subviews={
widgets.Panel{
subviews={
Expand All @@ -230,6 +271,7 @@ function Sitemap:init()
widgets.FilteredList{
view_id='list',
on_submit=zoom_to_unit,
on_submit2=follow_unit,
choices=unit_choices,
visible=#unit_choices > 0,
},
Expand All @@ -255,6 +297,7 @@ function Sitemap:init()
widgets.FilteredList{
view_id='list',
on_submit=zoom_to_next_zone,
on_submit2=zoom_to_next_zone,
choices=location_choices,
visible=#location_choices > 0,
},
Expand All @@ -271,6 +314,7 @@ function Sitemap:init()
widgets.FilteredList{
view_id='list',
on_submit=zoom_to_item,
on_submit2=follow_item,
choices=artifact_choices,
visible=#artifact_choices > 0,
},
Expand All @@ -279,17 +323,14 @@ function Sitemap:init()
},
},
widgets.Divider{
frame={b=3, h=1},
frame={b=4, h=1, l=0, r=1},
frame_style=gui.FRAME_THIN,
frame_style_l=false,
frame_style_r=false,
},
widgets.Label{
frame={b=0, l=0},
text={
'Click on a name or hit ', {text='Enter', pen=COLOR_LIGHTGREEN}, NEWLINE,
'to zoom to the selected target.'
},
text=get_bottom_text(),
},
}
end
Expand Down