Skip to content

Commit 03030cd

Browse files
committed
implement zooming to unit and buildings
1 parent 7232ba8 commit 03030cd

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

gui/manipulator.lua

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ function ColumnMenu:init()
9595
text='Hide group',
9696
fn=self.col:callback('hide_group'),
9797
})
98+
if self.col.zoom_fn then
99+
table.insert(choices, {
100+
text='Zoom to',
101+
fn=self.col.zoom_fn,
102+
})
103+
end
98104

99105
self:addviews{
100106
widgets.List{
@@ -148,6 +154,7 @@ Column.ATTRS{
148154
count_fn=DEFAULT_NIL,
149155
cmp_fn=DEFAULT_NIL,
150156
choice_fn=DEFAULT_NIL,
157+
zoom_fn=DEFAULT_NIL,
151158
}
152159

153160
local CH_DOT = string.char(15)
@@ -233,7 +240,7 @@ function Column:init()
233240
},
234241
ColumnMenu{
235242
view_id='col_menu',
236-
frame={l=0, t=1, h=5},
243+
frame={l=0, t=1, h=self.zoom_fn and 6 or 5},
237244
col=self,
238245
},
239246
},
@@ -647,19 +654,23 @@ function Spreadsheet:init()
647654
end
648655

649656
local function add_workshops(vec, type_enum, type_defs)
650-
for _, workshop in ipairs(vec) do
657+
for _, bld in ipairs(vec) do
651658
cols:addviews{
652659
ToggleColumn{
653660
group='workshops',
654-
label=get_workshop_label(workshop, type_enum, type_defs),
661+
label=get_workshop_label(bld, type_enum, type_defs),
655662
shared=self.shared,
656-
data_fn=curry(toggle_sorted_vec_data, workshop.profile.permitted_workers),
663+
data_fn=curry(toggle_sorted_vec_data, bld.profile.permitted_workers),
657664
toggle_fn=function(unit_id, prev_val)
658665
if not prev_val then
659666
-- there can be only one
660-
workshop.profile.permitted_workers:resize(0)
667+
bld.profile.permitted_workers:resize(0)
661668
end
662-
toggle_sorted_vec(workshop.profile.permitted_workers, unit_id, prev_val)
669+
toggle_sorted_vec(bld.profile.permitted_workers, unit_id, prev_val)
670+
end,
671+
zoom_fn=function()
672+
dfhack.gui.revealInDwarfmodeMap(
673+
xyz2pos(bld.centerx, bld.centery, bld.z), true, true)
663674
end,
664675
}
665676
}
@@ -717,6 +728,19 @@ function Spreadsheet:init()
717728
self.namelist:setFocus(true)
718729
end
719730

731+
function Spreadsheet:zoom_to_unit()
732+
local idx = self.namelist:getSelected()
733+
if not idx then return end
734+
local unit = df.unit.find(self.subviews.name:get_sorted_unit_id(idx))
735+
if not unit then return end
736+
dfhack.gui.revealInDwarfmodeMap(
737+
xyz2pos(dfhack.units.getPosition(unit)), true, true)
738+
end
739+
740+
function Spreadsheet:zoom_to_col_source()
741+
-- TODO
742+
end
743+
720744
function Spreadsheet:sort_by_current_col()
721745
-- TODO
722746
end
@@ -1091,6 +1115,20 @@ function Manipulator:init()
10911115
widgets.HotkeyLabel{
10921116
frame={b=0, l=0},
10931117
auto_width=true,
1118+
label='Zoom to unit',
1119+
key='CUSTOM_SHIFT_Z',
1120+
on_activate=function() self.subviews.sheet:zoom_to_unit() end,
1121+
},
1122+
widgets.HotkeyLabel{
1123+
frame={b=0, l=22},
1124+
auto_width=true,
1125+
label='Zoom to col source',
1126+
key='CUSTOM_CTRL_Z',
1127+
on_activate=function() self.subviews.sheet:zoom_to_col_source() end,
1128+
},
1129+
widgets.HotkeyLabel{
1130+
frame={b=0, l=46},
1131+
auto_width=true,
10941132
label=function()
10951133
return self.needs_refresh and 'Refresh units (new units have arrived)' or 'Refresh units'
10961134
end,

0 commit comments

Comments
 (0)