Skip to content

Commit 1a58e45

Browse files
authored
Merge pull request #1379 from myk002/myk_hide_tutorials
[hide-tutorials] hide popups for adventure mode; add reset command
2 parents a4b1630 + 7546d3c commit 1a58e45

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Template for new versions:
3535
## Misc Improvements
3636
- `assign-preferences`: new ``--show`` option to display the preferences of the selected unit
3737
- `pref-adjust`: new ``show`` command to display the preferences of the selected unit
38+
- `hide-tutorials`: if enabled, also hide tutorial popups for adventure mode
39+
- `hide-tutorials`: new ``reset`` command that will re-enable popups in the current game
3840

3941
## Removed
4042

docs/hide-tutorials.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ hide-tutorials
33

44
.. dfhack-tool::
55
:summary: Hide new fort tutorial popups.
6-
:tags: fort interface
6+
:tags: adventure fort interface
77

88
If you've played the game before and don't need to see the tutorial popups that
99
show up on every new fort, ``hide-tutorials`` can hide them for you. You can
1010
enable this tool as a system service in the "Services" tab of
11-
`gui/control-panel` so it takes effect for all new or loaded forts.
11+
`gui/control-panel` so it takes effect for all forts and adventures.
1212

1313
Specifically, this tool hides:
1414

1515
- The popup displayed when creating a new world
1616
- The "Do you want to start a tutorial embark" popup
1717
- Popups displayed the first time you open the labor, burrows, justice, and
1818
other similar screens in a new fort
19+
- Popups displayed when you perform certain actions for the first time in an
20+
adventure
1921

2022
Note that only unsolicited tutorial popups are hidden. If you directly request
2123
a tutorial page from the help, then it will still function normally.
@@ -27,6 +29,10 @@ Usage
2729

2830
enable hide-tutorials
2931
hide-tutorials
32+
hide-tutorials reset
3033

31-
If you haven't enabled the tool, but you run the command while a fort is
32-
loaded, all future popups for the loaded fort will be hidden.
34+
If you haven't enabled the tool, but you run the command while a fort or
35+
adventure is loaded, all future popups for the loaded game will be hidden.
36+
37+
If you run the command with the ``reset`` option, all popups will be re-enabled
38+
as if they had never been seen or dismissed.

hide-tutorials.lua

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ function isEnabled()
1212
return enabled
1313
end
1414

15-
local function is_fort_map_loaded()
16-
return df.global.gamemode == df.game_mode.DWARF and dfhack.isMapLoaded()
17-
end
18-
1915
local help = df.global.game.main_interface.help
2016

2117
local function close_help()
@@ -43,15 +39,36 @@ function skip_tutorial_prompt()
4339
end
4440
end
4541

42+
local function get_prefix()
43+
if dfhack.world.isFortressMode() then
44+
return 'POPUP_'
45+
elseif dfhack.world.isAdventureMode() then
46+
return 'ADVENTURE_POPUP_'
47+
end
48+
end
49+
4650
local function hide_all_popups()
51+
local prefix = get_prefix()
52+
if not prefix then return end
4753
for i,name in ipairs(df.help_context_type) do
48-
if not name:startswith('POPUP_') then goto continue end
54+
if not name:startswith(prefix) then goto continue end
4955
utils.insert_sorted(df.global.plotinfo.tutorial_seen, i)
5056
utils.insert_sorted(df.global.plotinfo.tutorial_hide, i)
5157
::continue::
5258
end
5359
end
5460

61+
local function show_all_popups()
62+
local prefix = get_prefix()
63+
if not prefix then return end
64+
for i,name in ipairs(df.help_context_type) do
65+
if not name:startswith(prefix) then goto continue end
66+
utils.erase_sorted(df.global.plotinfo.tutorial_seen, i)
67+
utils.erase_sorted(df.global.plotinfo.tutorial_hide, i)
68+
::continue::
69+
end
70+
end
71+
5572
dfhack.onStateChange[GLOBAL_KEY] = function(sc)
5673
if not enabled then return end
5774

@@ -65,7 +82,7 @@ dfhack.onStateChange[GLOBAL_KEY] = function(sc)
6582
dfhack.timeout(100, 'frames', skip_tutorial_prompt)
6683
dfhack.timeout(1000, 'frames', skip_tutorial_prompt)
6784
end
68-
elseif sc == SC_MAP_LOADED and df.global.gamemode == df.game_mode.DWARF then
85+
elseif sc == SC_MAP_LOADED then
6986
hide_all_popups()
7087
end
7188
end
@@ -81,13 +98,15 @@ end
8198

8299
if args[1] == "enable" then
83100
enabled = true
84-
if is_fort_map_loaded() then
101+
if dfhack.isMapLoaded() then
85102
hide_all_popups()
86103
end
87104
elseif args[1] == "disable" then
88105
enabled = false
89-
elseif is_fort_map_loaded() then
106+
elseif args[1] == "reset" then
107+
show_all_popups()
108+
elseif dfhack.isMapLoaded() then
90109
hide_all_popups()
91110
else
92-
qerror('hide-tutorials needs a loaded fortress map to work')
111+
qerror('hide-tutorials needs a loaded fortress or adventure map to work')
93112
end

0 commit comments

Comments
 (0)