Skip to content

Commit

Permalink
Merge pull request #805 from myk002/myk_tutorials
Browse files Browse the repository at this point in the history
new tool: hide-tutorials
  • Loading branch information
myk002 authored Aug 28, 2023
2 parents b1b331b + c3715aa commit 8300342
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Template for new versions:
## New Tools
- `devel/scan-vtables`: Scan and dump likely vtable addresses (for memory research)
- `hide-interface`: hide the vanilla UI elements for clean screenshots or laid-back fortress observing
- `hide-tutorials`: hide the DF tutorial popups; enable in the System tab of `gui/control-panel`

## New Features
- `exportlegends`: new overlay that integrates with the vanilla "Export XML" button. Now you can generate both the vanilla export and the extended data export with a single click!
Expand Down
32 changes: 32 additions & 0 deletions docs/hide-tutorials.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
hide-tutorials
==============

.. dfhack-tool::
:summary: Hide new fort tutorial popups.
:tags: fort interface

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

Specifically, this tool hides:

- The popup displayed when creating a new world
- The "Do you want to start a tutorial embark" popup
- Popups displayed the first time you open the labor, burrows, justice, and
other similar screens in a new fort

Note that only unsolicited tutorial popups are hidden. If you directly request
a tutorial page from the help, then it will still function normally.

Usage
-----

::

enable hide-tutorials
hide-tutorials

If you haven't enabled the tool, but you run the command while a fort is
loaded, all future popups for the loaded fort will be hidden.
1 change: 1 addition & 0 deletions gui/control-panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ local SYSTEM_SERVICES = {
-- these are fully controlled by the user
local SYSTEM_USER_SERVICES = {
'faststart',
'hide-tutorials',
'work-now',
}
for _,v in ipairs(SYSTEM_USER_SERVICES) do
Expand Down
80 changes: 80 additions & 0 deletions hide-tutorials.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
--@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 help.open and help.context == df.help_context_type.EMBARK_TUTORIAL_CHOICE then
help.context = df.help_context_type.EMBARK_MESSAGE
df.global.gps.mouse_x = df.global.gps.dimx // 2
df.global.gps.mouse_y = 18
df.global.enabler.mouse_lbut = 1
df.global.enabler.mouse_lbut_down = 1
gui.simulateInput(scr, '_MOUSE_L_DOWN')
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

0 comments on commit 8300342

Please sign in to comment.