From 8665a1a743ba635211a5c3d70bd7a182b0c14a1c Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 20 Feb 2025 15:47:12 -0800 Subject: [PATCH] implement shift click to follow --- changelog.txt | 1 + docs/gui/sitemap.rst | 8 ++++--- gui/sitemap.lua | 55 ++++++++++++++++++++++++++++++++++++++------ 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/changelog.txt b/changelog.txt index 1afdc48926..97d2ed0c7a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 diff --git a/docs/gui/sitemap.rst b/docs/gui/sitemap.rst index 74e1fde942..ed1d89521d 100644 --- a/docs/gui/sitemap.rst +++ b/docs/gui/sitemap.rst @@ -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 diff --git a/gui/sitemap.lua b/gui/sitemap.lua index 1f779bfc9c..671212f919 100644 --- a/gui/sitemap.lua +++ b/gui/sitemap.lua @@ -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) @@ -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() @@ -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() @@ -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={ @@ -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, }, @@ -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, }, @@ -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, }, @@ -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