forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen-legends.lua
More file actions
85 lines (71 loc) · 2.17 KB
/
open-legends.lua
File metadata and controls
85 lines (71 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
-- open legends screen when in fortress mode
--@ module = true
--[====[
open-legends
============
Open a legends screen when in fortress mode.
Compatible with `exportlegends`.
]====]
gui = require 'gui'
utils = require 'utils'
Wrapper = defclass(Wrapper, gui.Screen)
Wrapper.focus_path = 'legends'
region_details_backup = {}
function Wrapper:onRender()
self._native.parent:render()
end
function Wrapper:onIdle()
self._native.parent:logic()
end
function Wrapper:onHelp()
self._native.parent:help()
end
function Wrapper:onInput(keys)
if self._native.parent.cur_page == 0 and keys.LEAVESCREEN then
local v = df.global.world.world_data.region_details
while (#v > 0) do v:erase(0) end
for _,item in pairs(region_details_backup) do
v:insert(0, item)
end
self:dismiss()
dfhack.screen.dismiss(self._native.parent)
return
end
gui.simulateInput(self._native.parent, keys)
end
function show(force)
if not dfhack.isWorldLoaded() then
qerror('no world loaded')
end
local view = df.global.gview.view
while view do
if df.viewscreen_legendsst:is_instance(view) then
qerror('legends screen already displayed')
end
view = view.child
end
local old_view = dfhack.gui.getCurViewscreen()
if not dfhack.world.isFortressMode(df.global.gametype) and not dfhack.world.isAdventureMode(df.global.gametype) and not force then
qerror('mode not tested: ' .. df.game_type[df.global.gametype] .. ' (use "force" to force)')
end
local ok, err = pcall(function()
dfhack.screen.show(df.viewscreen_legendsst:new())
Wrapper():show()
end)
if ok then
local v = df.global.world.world_data.region_details
while (#v > 0) do
table.insert(region_details_backup, 1, v[0])
v:erase(0)
end
else
while dfhack.gui.getCurViewscreen(true) ~= old_view do
dfhack.screen.dismiss(dfhack.gui.getCurViewscreen(true))
end
qerror('Failed to set up legends screen: ' .. tostring(err))
end
end
if not moduleMode then
local iargs = utils.invert{...}
show(iargs.force)
end