Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gui/control-panel] confirmation prompts for reset to defaults #939

Merged
merged 3 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 46 additions & 34 deletions docs/gui/control-panel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,61 +18,73 @@ The tabs can also be navigated with the keyboard, with the :kbd:`Ctrl`:kbd:`T`
and :kbd:`Ctrl`:kbd:`Y` hotkeys. These are the default hotkeys for navigating
DFHack tab bars.

The "Enabled" tab
-----------------
The "Automation", "Bug Fixes", and "Gameplay" tabs
--------------------------------------------------

The "Enabled" tab shows tools that you can enable right now. You can select the
tool name to see a short description at the bottom of the list. Hit
These three tabs provide access to the three main subcategories of DFHack tools.
In general, you'll probably want to start with only the "Bugfix" tools enabled.
As you become more comfortable with vanilla systems, and some of them start to
become less fun and more toilsome, you can enable more of the "Automation"
tools to manage them for you. Finally, you can examine the tools on the
"Gameplay" tab and enable whatever you think sounds like fun :).

Under each of these tabs, there are two subtabs: "Enabled" and "Autostart". The
subtabs can be navigated with the keyboard, using the :kbd:`Ctrl`:kbd:`N` and
:kbd:`Ctrl`:kbd:`M` hotkeys.

The "Enabled" subtab
~~~~~~~~~~~~~~~~~~~~

The "Enabled" tab allows you to toggle which tools are enabled right now. You
can select the tool in the list to see a short description at the bottom. Hit
:kbd:`Enter`, double click on the tool name, or click on the toggle on the far
left to enable or disable that tool.

Note that before a fort is loaded, there will be very few tools listed here.
Come back when a fort is loaded to see much more.

Tools are split into three subcategories: ``automation``, ``bugfix``, and
``gameplay``. In general, you'll probably want to start with only the
``bugfix`` tools enabled. As you become more comfortable with vanilla systems,
and some of them start to become less fun and more toilsome, you can enable
more of the ``automation`` tools to manage them for you. Finally, you can
examine the tools on the ``gameplay`` tab and enable whatever you think sounds
like fun :).
Once tools are enabled, they will save their state with your fort and
automatically re-enable themselves when you load that same fort again.

The category subtabs can also be navigated with the keyboard, with the
:kbd:`Ctrl`:kbd:`N` and :kbd:`Ctrl`:kbd:`M` hotkeys.

Once tools are enabled (possible after you've loaded a fort), they will save
their state with your fort and automatically re-enable themselves when you load
that same fort again.

You can hit :kbd:`Ctrl`:kbd:`H` or click on the help icon to show the help page for the selected tool in `gui/launcher`. You can also use this as shortcut to
You can hit :kbd:`Ctrl`:kbd:`H` or click on the help icon to show the help page
for the selected tool in `gui/launcher`. You can also use this as shortcut to
run custom commandline commands to configure that tool manually. If the tool has
an associated GUI config screen, a gear icon will also appear next to the help
icon. Hit :kbd:`Ctrl`:kbd:`G`, click on the gear icon, or Shift-double click the tool name to launch the relevant configuration interface.
icon. Hit :kbd:`Ctrl`:kbd:`G`, click on the gear icon, or Shift-double click
the tool name to launch the relevant configuration interface.

.. _dfhack-examples-guide:

The "Autostart" tab
-------------------
The "Autostart" subtab
~~~~~~~~~~~~~~~~~~~~~~

This tab is organized similarly to the "Enabled" tab, but instead of tools you
can enable now, it shows the tools that you can configure DFHack to auto-enable
or auto-run when you start the game or a new fort. You'll recognize many tools
from the "Enabled" tab here, but there are also useful one-time commands that
you might want to run at the start of a fort, like
`ban-cooking all <ban-cooking>`.
This subtab is organized similarly to the "Enabled" subtab, but instead of
tools you can enable now, it shows the tools that you can configure DFHack to
auto-enable or auto-run when you start the game or a new fort. You'll recognize
many tools from the "Enabled" subtab here, but there are also useful one-time
commands that you might want to run at the start of a fort, like
`ban-cooking all <ban-cooking>` or (if you have "mortal mode" disabled in the
"Preferences" tab) god-mode tools like `light-aquifers-only`.

The "UI Overlays" tab
---------------------

The overlays tab allows you to easily see which overlays are enabled, lets you
toggle them on and off, and gives you links for the related help text (which is
normally added at the bottom of the help page for the tool that provides the
overlay). If you want to reposition any of the overlay widgets, hit
:kbd:`Ctrl`:kbd:`G` or click on the the hotkey hint to launch `gui/overlay`.
DFHack overlays add information and additional functionality to the vanilla DF
screens. For example, the popular DFHack `Building Planner <buildingplan>` is
an overlay named ``buildingplan.planner`` that appears when you are building
something.

The "Overlays" tab allows you to easily see which overlays are enabled, gives
you a short description of what each one does, lets you toggle them on and off,
and gives you links for the related help text (which is normally added at the
bottom of the help page for the tool that provides the overlay). If you want to
reposition any of the overlay widgets, hit :kbd:`Ctrl`:kbd:`G` or click on the
the hotkey hint to launch `gui/overlay`.

The "Preferences" tab
---------------------

The preferences tab allows you to change DFHack's internal settings and
The "Preferences" tab allows you to change DFHack's internal settings and
defaults, like whether DFHack's "mortal mode" is enabled -- hiding the god-mode
tools from the UI, whether DFHack tools pause the game when they come up, or how
long you can take between clicks and still have it count as a double-click.
Expand Down
67 changes: 45 additions & 22 deletions gui/control-panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ local helpdb = require('helpdb')
local textures = require('gui.textures')
local overlay = require('plugins.overlay')
local registry = reqscript('internal/control-panel/registry')
local utils = require('utils')
local widgets = require('gui.widgets')

local function get_icon_pens()
Expand Down Expand Up @@ -365,6 +364,17 @@ function CommandTab:init_main_panel(panel)
on_double_click=self:callback('on_submit'),
on_double_click2=self:callback('launch_config'),
row_height=2,
visible=function() return #self.subviews.list:getChoices() > 0 end,
},
widgets.Label{
frame={t=9, l=0},
text={
'Please load a fort to see the fort-mode tools. Alternately,', NEWLINE,
'please switch to the "Autostart" tab to configure which', NEWLINE,
'tools should be run or enabled on embark.',
},
text_pen=COLOR_LIGHTRED,
visible=function() return #self.subviews.list:getChoices() == 0 end,
},
}
end
Expand Down Expand Up @@ -460,15 +470,20 @@ function CommandTab:onInput(keys)
end

function CommandTab:restore_defaults()
if subtab == Subtabs.enabled then
enabled_restore_defaults(self)
else
autostart_restore_defaults(self)
end
self:refresh()
dialogs.showMessage('Success',
('%s defaults restored for %s tools.'):format(
self.subviews.subtabbar.labels[subtab], self.group))
dialogs.showYesNoPrompt('Are you sure?',
('Are you sure you want to restore %s\ndefaults for %s tools?'):format(
self.subviews.subtabbar.labels[subtab], self.group),
nil, function()
if subtab == Subtabs.enabled then
enabled_restore_defaults(self)
else
autostart_restore_defaults(self)
end
self:refresh()
dialogs.showMessage('Success',
('%s defaults restored for %s tools.'):format(
self.subviews.subtabbar.labels[subtab], self.group))
end)
end


Expand Down Expand Up @@ -631,12 +646,16 @@ function OverlaysTab:on_submit()
end

function OverlaysTab:restore_defaults()
local state = overlay.get_state()
for name, db_entry in pairs(state.db) do
enable_overlay(name, db_entry.widget.default_enabled)
end
self:refresh()
dialogs.showMessage('Success', 'Overlay defaults restored.')
dialogs.showYesNoPrompt('Are you sure?',
'Are you sure you want to restore overlay defaults?',
nil, function()
local state = overlay.get_state()
for name, db_entry in pairs(state.db) do
enable_overlay(name, db_entry.widget.default_enabled)
end
self:refresh()
dialogs.showMessage('Success', 'Overlay defaults restored.')
end)
end

function OverlaysTab:show_help()
Expand Down Expand Up @@ -842,12 +861,16 @@ function PreferencesTab:set_val(val)
end

function PreferencesTab:restore_defaults()
for _,data in ipairs(registry.PREFERENCES_BY_IDX) do
common.set_preference(data, data.default)
end
common.config:write()
self:refresh()
dialogs.showMessage('Success', 'Default preferences restored.')
dialogs.showYesNoPrompt('Are you sure?',
'Are you sure you want to restore default preferences?',
nil, function()
for _,data in ipairs(registry.PREFERENCES_BY_IDX) do
common.set_preference(data, data.default)
end
common.config:write()
self:refresh()
dialogs.showMessage('Success', 'Default preferences restored.')
end)
end


Expand Down