-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathhide-tutorials.lua
More file actions
140 lines (123 loc) · 4.28 KB
/
Copy pathhide-tutorials.lua
File metadata and controls
140 lines (123 loc) · 4.28 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
--@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 help = df.global.game.main_interface.help
local function close_help()
help.open = false
end
function skip_tutorial_prompt()
if not help.open then return end
local scr = dfhack.gui.getDFViewscreen(true)
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
if help.open then
-- retry later
help.context = df.help_context_type.EMBARK_TUTORIAL_CHOICE
end
end
local ADVENTURE_TUTORIAL_CONTEXTS = utils.invert{
'ADVENTURE_START_MESSAGE',
'ADVENTURE_START_TUTORIAL_CAMERA_CONTROLS',
'ADVENTURE_START_TUTORIAL_MOVEMENT',
'ADVENTURE_START_TUTORIAL_MENU_OVERVIEW',
'ADVENTURE_DONE_WITH_FIRST_STEPS_MESSAGE',
}
function skip_adventure_tutorial()
if not dfhack.world.isAdventureMode() then return end
df.global.plotinfo.flags.need_to_do_tutorial = false
if help.open and ADVENTURE_TUTORIAL_CONTEXTS[df.help_context_type[help.context]] then
close_help()
end
end
local function get_prefix()
if dfhack.world.isFortressMode() then
return 'POPUP_'
elseif dfhack.world.isAdventureMode() then
return 'ADVENTURE_POPUP_'
end
end
local function hide_all_popups()
local prefix = get_prefix()
if not prefix then return end
for i,name in ipairs(df.help_context_type) do
if not name:startswith(prefix) 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
local function show_all_popups()
local prefix = get_prefix()
if not prefix then return end
for i,name in ipairs(df.help_context_type) do
if not name:startswith(prefix) then goto continue end
utils.erase_sorted(df.global.plotinfo.tutorial_seen, i)
utils.erase_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()
dfhack.timeout(10, 'frames', skip_tutorial_prompt)
dfhack.timeout(100, 'frames', skip_tutorial_prompt)
dfhack.timeout(1000, 'frames', skip_tutorial_prompt)
elseif df.viewscreen_setupadventurest:is_instance(scr) then
-- default the "tutorial" checkbox to off; the player can still
-- check it if they want the tutorial
scr.want_tutorial = false
elseif df.viewscreen_dungeonmodest:is_instance(scr) then
-- the start tutorial can pop up shortly after the screen appears
skip_adventure_tutorial()
dfhack.timeout(10, 'frames', skip_adventure_tutorial)
dfhack.timeout(100, 'frames', skip_adventure_tutorial)
end
elseif sc == SC_MAP_LOADED then
hide_all_popups()
skip_adventure_tutorial()
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 dfhack.isMapLoaded() then
hide_all_popups()
skip_adventure_tutorial()
end
elseif args[1] == "disable" then
enabled = false
elseif args[1] == "reset" then
show_all_popups()
elseif dfhack.isMapLoaded() then
hide_all_popups()
skip_adventure_tutorial()
else
qerror('hide-tutorials needs a loaded fortress or adventure map to work')
end