allow overlay widgets to specify a default enabled state

and make relevant library widgets enabled by default
and remove the default overlay.json config file
develop
Myk Taylor 2023-01-26 00:53:57 -08:00
parent 2a8520fb9e
commit 998a63a979
No known key found for this signature in database
5 changed files with 9 additions and 8 deletions

@ -1,8 +0,0 @@
{
"hotkeys.menu": {
"enabled": true
},
"unsuspend.overlay": {
"enabled": true
}
}

@ -96,6 +96,9 @@ The ``overlay.OverlayWidget`` superclass defines the following class attributes:
mean for the position. Players can change the widget position at any time mean for the position. Players can change the widget position at any time
via the `overlay position <overlay>` command, so don't assume that your via the `overlay position <overlay>` command, so don't assume that your
widget will always be at the default position. widget will always be at the default position.
- ``default_enabled`` (default: ``false``)
Override this attribute if the overlay should be enabled by default if it
does not already have a state stored in ``dfhack-config/overlay.json``.
- ``viewscreens`` (default: ``{}``) - ``viewscreens`` (default: ``{}``)
The list of viewscreens that this widget should be associated with. When The list of viewscreens that this widget should be associated with. When
one of these viewscreens is on top of the viewscreen stack, your widget's one of these viewscreens is on top of the viewscreen stack, your widget's

@ -12,6 +12,7 @@ local widgets = require('gui.widgets')
HotspotMenuWidget = defclass(HotspotMenuWidget, overlay.OverlayWidget) HotspotMenuWidget = defclass(HotspotMenuWidget, overlay.OverlayWidget)
HotspotMenuWidget.ATTRS{ HotspotMenuWidget.ATTRS{
default_pos={x=2,y=2}, default_pos={x=2,y=2},
default_enabled=true,
hotspot=true, hotspot=true,
viewscreens='all', viewscreens='all',
overlay_onupdate_max_freq_seconds=0, overlay_onupdate_max_freq_seconds=0,

@ -48,6 +48,7 @@ end
OrdersOverlay = defclass(OrdersOverlay, overlay.OverlayWidget) OrdersOverlay = defclass(OrdersOverlay, overlay.OverlayWidget)
OrdersOverlay.ATTRS{ OrdersOverlay.ATTRS{
default_pos={x=53,y=-6}, default_pos={x=53,y=-6},
default_enabled=true,
viewscreens='dwarfmode', viewscreens='dwarfmode',
frame={w=30, h=4}, frame={w=30, h=4},
frame_style=gui.MEDIUM_FRAME, frame_style=gui.MEDIUM_FRAME,

@ -249,6 +249,9 @@ local function load_widget(name, widget_class)
} }
if not overlay_config[name] then overlay_config[name] = {} end if not overlay_config[name] then overlay_config[name] = {} end
local config = overlay_config[name] local config = overlay_config[name]
if config.enabled == nil then
config.enabled = widget.default_enabled
end
config.pos = sanitize_pos(config.pos or widget.default_pos) config.pos = sanitize_pos(config.pos or widget.default_pos)
widget.frame = make_frame(config.pos, widget.frame) widget.frame = make_frame(config.pos, widget.frame)
if config.enabled then if config.enabled then
@ -487,6 +490,7 @@ OverlayWidget = defclass(OverlayWidget, widgets.Panel)
OverlayWidget.ATTRS{ OverlayWidget.ATTRS{
name=DEFAULT_NIL, -- this is set by the framework to the widget name name=DEFAULT_NIL, -- this is set by the framework to the widget name
default_pos={x=DEFAULT_X_POS, y=DEFAULT_Y_POS}, -- 1-based widget screen pos default_pos={x=DEFAULT_X_POS, y=DEFAULT_Y_POS}, -- 1-based widget screen pos
default_enabled=false, -- initial enabled state if not in config
overlay_only=false, -- true if there is no widget to reposition overlay_only=false, -- true if there is no widget to reposition
hotspot=false, -- whether to call overlay_onupdate on all screens hotspot=false, -- whether to call overlay_onupdate on all screens
viewscreens={}, -- override with associated viewscreen or list of viewscrens viewscreens={}, -- override with associated viewscreen or list of viewscrens