forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hide-tutorials.lua
85 lines (71 loc) · 2.26 KB
/
hide-tutorials.lua
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
--@module = true
--@enable = true
local gui = require('gui')
local utils = require('utils')
local GLOBAL_KEY = 'hide-tutorials'
enabled = enabled or false
function isEnabled()
return enabled
end
local function is_fort_map_loaded()
return df.global.gamemode == df.game_mode.DWARF and dfhack.isMapLoaded()
end
local help = df.global.game.main_interface.help
local function close_help()
help.open = false
end
function skip_tutorial_prompt(scr)
if not help.open then return end
local mouse_y = 23
if help.context == df.help_context_type.EMBARK_TUTORIAL_CHOICE then
help.context = df.help_context_type.EMBARK_MESSAGE
-- dialog behavior changes for the button click, but the button is still
-- in the "tutorial choice" button position
mouse_y = 18
end
if help.context == df.help_context_type.EMBARK_MESSAGE then
df.global.gps.mouse_x = df.global.gps.dimx // 2
df.global.gps.mouse_y = mouse_y
gui.simulateInput(scr, '_MOUSE_L')
end
end
local function hide_all_popups()
for i,name in ipairs(df.help_context_type) do
if not name:startswith('POPUP_') then goto continue end
utils.insert_sorted(df.global.plotinfo.tutorial_seen, i)
utils.insert_sorted(df.global.plotinfo.tutorial_hide, i)
::continue::
end
end
dfhack.onStateChange[GLOBAL_KEY] = function(sc)
if not enabled then return end
if sc == SC_VIEWSCREEN_CHANGED then
local scr = dfhack.gui.getDFViewscreen(true)
if df.viewscreen_new_regionst:is_instance(scr) then
close_help()
elseif df.viewscreen_choose_start_sitest:is_instance(scr) then
skip_tutorial_prompt(scr)
end
elseif sc == SC_MAP_LOADED and df.global.gamemode == df.game_mode.DWARF then
hide_all_popups()
end
end
if dfhack_flags.module then
return
end
local args = {...}
if dfhack_flags and dfhack_flags.enable then
args = {dfhack_flags.enable_state and 'enable' or 'disable'}
end
if args[1] == "enable" then
enabled = true
if is_fort_map_loaded() then
hide_all_popups()
end
elseif args[1] == "disable" then
enabled = false
elseif is_fort_map_loaded() then
hide_all_popups()
else
qerror('hide-tutorials needs a loaded fortress map to work')
end