Skip to content

Commit

Permalink
Allow manipulator to be invoked from main dwarf mode screen
Browse files Browse the repository at this point in the history
  • Loading branch information
lethosor committed May 21, 2015
1 parent 91033b2 commit 54d5ed9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions manipulator/gui/manipulator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function manipulator:init(args)
for i, u in pairs(args.units) do
self.units[i + 1] = unit_wrapper(u)
end
self.dismiss_parent = args.dismiss_parent
self.unit_max = #self.units
self.bounds = {}
self.gframe = 0
Expand Down Expand Up @@ -516,6 +517,9 @@ function manipulator:onDismiss(...)
storage.default_columns = get_column_ids(self.columns)
storage.diff_enabled = self.diff_enabled
self.super.onDismiss(...)
if self.dismiss_parent then
dfhack.screen.dismiss(self._native.parent)
end
end

function manipulator:onGetSelectedUnit()
Expand Down
15 changes: 13 additions & 2 deletions manipulator/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,22 @@ manipulator_columns.ATTRS = {
frame_title = 'Dwarf Manipulator - Columns',
}

function mkscreen(parent, opts)
opts = opts or {}
opts.units = parent.units[parent.page]
opts.selected = parent.units[parent.page][parent.cursor_pos[parent.page]]
local scr = mgui.manipulator(opts)
scr:show()
return scr
end

function main()
local scr = dfhack.gui.getCurViewscreen()
if df.viewscreen_unitlistst:is_instance(scr) then
cur = mgui.manipulator{units = scr.units[scr.page], selected = scr.units[scr.page][scr.cursor_pos[scr.page]]}
cur:show()
cur = mkscreen(scr)
elseif dfhack.gui.getCurFocus() == 'dwarfmode/Default' then
gui.simulateInput(scr, 'D_UNITLIST')
cur = mkscreen(dfhack.gui.getCurViewscreen(), {dismiss_parent = true})
else
dfhack.printerr('Invalid context')
end
Expand Down

0 comments on commit 54d5ed9

Please sign in to comment.