hud elements - Darktide-Mod-Framework/Darktide-Mod-Framework GitHub Wiki
Custom HUD Elements
DMF provides support for injecting custom UI elements into Darktide's HUD.
Functions
DMFMod:register_hud_element
Register an element with DMF.
Parameters
element_settings
[table]class_name
[string] (required) Name of the class containing the element's logic.visibility_groups
[table] (required) Array of visibility group names for the element to be included in."alive"
is most common.use_hud_scale
[boolean] (optional) Set totrue
if the element should scale with the rest of the HUD.validation_function
[function] (optional) Function called byUIHud
to determine whether to create the element. Returntrue
from this function to conditionally enable the element. Exclude this parameter to always enable the element.params
[table] All parameters with which theUIHud
was created.
Returns
success
[boolean]true
if the element was successfully injected.
Examples
Element Class
local UIWorkspaceSettings = require("scripts/settings/ui/ui_workspace_settings")
local UIWidget = require("scripts/managers/ui/ui_widget")
local Definitions = {
scenegraph_definition = {
screen = UIWorkspaceSettings.screen,
example = {
parent = "screen",
size = { 150, 50 },
vertical_alignment = "center",
horizontal_alignment = "center",
position = { 0, 0, 1 }
}
},
widget_definitions = {
example = UIWidget.create_definition({
{
pass_type = "text",
value = "Hello, HUD!",
value_id = "text_value",
style_id = "text_style",
style = {
font_type = "proxima_nova_bold",
font_size = 28,
text_vertical_alignment = "center",
text_horizontal_alignment = "center",
text_color = Color.terminal_text_body(255, true),
offset = { 0, 0, 1 }
}
}
}, "example")
}
}
ExampleElement = class("ExampleElement", "HudElementBase")
function ExampleElement:init(parent, draw_layer, start_scale)
ExampleElement.super.init(self, parent, draw_layer, start_scale, Definitions)
end
return ExampleElement
Element Registration
local mod = get_mod("example_mod")
mod:register_hud_element({
class_name = "ExampleElement",
filename = "path/to/element",
use_hud_scale = true,
visibility_groups = {
"alive"
},
validation_function = function (params)
return params.enable_world_bloom
end
})