Templates
Based on game build 714014 | Last updated: 2026-03-08
Overview
The TEMPLATES module in dst-scripts/widgets/redux/templates.lua is a comprehensive collection of widget factory functions used to construct consistent, themable UI elements for the game's frontend (e.g., main menus, mod managers, character select, server browser, and profile UI). It leverages core widget types like Widget, ImageButton, Text, Spinner, NineSlice, and UIAnim, and supports keyboard/controller navigation, tooltips, localization, and theme-specific visuals (e.g., Quagmire, Boarrior, Clay Warg). Functions are grouped by purpose—backgrounds, buttons, menu systems, list items, counters, badges, and input fields—and often extend or wrap lower-level templates for specialized UI roles.
Usage example
local root = TEMPLATES.ScreenRoot("main_menu")
root:AddChild(TEMPLATES.BrightMenuBackground())
local title = TEMPLATES.ScreenTitle(STRINGS.UI.MAINMENU.TITLE, STRINGS.UI.MAINMENU.SUBTITLE)
root:AddChild(title)
local menuitems = {
{ text = STRINGS.UI.MAINMENU.NEW_GAME, onclick = function() ... end },
{ text = STRINGS.UI.MAINMENU.SERVER_LIST, onclick = function() ... end },
}
local menu = TEMPLATES.StandardMenu(menuitems)
root:AddChild(menu)
local back_btn = TEMPLATES.BackButton(function() TheFrontEnd:PopScreen() end)
root:AddChild(back_btn)
return root
Dependencies & tags
Components used:
AccountItemFrame,Button,Grid,Image,ImageButton,Menu,NineSlice,NumericSpinner,Spinner,Text,TextEdit,TrueScrollList,UIAnim,WidgetTEMPLATES.old.BackgroundTint,TEMPLATES.old.ForegroundLetterbox,TEMPLATES.old.ItemImageTextGetLoaderAtlasAndTex,GetSkinName,GetInventoryItemAtlas,math.clamp,wputils.*- Localized strings via
STRINGS.UI.*,STRINGS.CHARACTER_DETAILS.* - Constants:
FRONTEND_PORTAL_COLOUR,BRANCH,APP_VERSION,APP_ARCHITECTURE,RESOLUTION_X,RESOLUTION_Y,PI,FRAMES,UICOLOURS.*,TUNING.*
Tags: None found.
Properties
| Property | Type | Default Value | Description |
|---|
Main functions
TEMPLATES.ScreenRoot(name)
- Description: Creates and returns a root widget centered on screen with middle anchors and proportional scale mode.
- Parameters:
name— optional string name for the widget. - Returns: Widget instance.
TEMPLATES.LoaderBackground(item_key)
- Description: Creates a full-screen, stretched background image for loader screens with tinting using
FRONTEND_PORTAL_COLOUR. - Parameters:
item_key— string key used byGetLoaderAtlasAndTex. - Returns: Image widget with stretched fullscreen scale mode and tint applied.
TEMPLATES.PlainBackground()
- Description: Returns a background variant identical to
BrightMenuBackground. - Parameters: None.
- Returns: Widget background instance.
TEMPLATES.BoarriorBackground()
- Description: Returns a background variant for the "Boarrior" theme using
ReduxBackgroundwith"labg". - Parameters: None.
- Returns: Widget background instance.
TEMPLATES.BrightMenuBackground()
- Description: Returns a background variant using
ReduxBackgroundwith"dark_right". - Parameters: None.
- Returns: Widget background instance.
TEMPLATES.LeftSideBarBackground()
- Description: Creates a background with a vertical sidebar element on the left side.
- Parameters: None.
- Returns: Widget background instance with nested
sidebar_rootandsidebarImage child.
TEMPLATES._CreateBackgroundPlate(image)
- Description: Internal helper that wraps an image in a
Widgetwith scale adjusted to screen width (x-scale = RESOLUTION_X / plate_width). - Parameters:
image— Image widget instance. - Returns: Widget root containing the scaled image; stores
root.image = image.
TEMPLATES.BackgroundTint(a, rgb)
- Description: Delegates to
TEMPLATES.old.BackgroundTint(a, rgb). - Parameters:
a— alpha value;rgb— color triplet. - Returns: Return value of
TEMPLATES.old.BackgroundTint(a, rgb).
TEMPLATES.QuagmireAnim()
- Description: Creates a three-layer animated background using
UIAnimwidgets for the Quagmire menu theme. - Parameters: None.
- Returns: Widget root containing three
UIAnimchildren ("quagmire_menu_bg", "quagmire_menu_mid", "quagmire_menu").
TEMPLATES.BoarriorAnim()
- Description: Creates a single
UIAnimwidget for the Boarrior menu animation ("main_menu1") with idle animation playing. - Parameters: None.
- Returns: UIAnim instance.
TEMPLATES.ClayWargBackground()
- Description: Creates an animated background that fades using per-frame
OnUpdatelogic with a cosine wave. - Parameters: None.
- Returns: UIAnim instance with
"ground"animation and customOnUpdatemethod;fadetandOnUpdateattached to instance.
TEMPLATES.ClayWargAnim()
- Description: Creates a looping
UIAnimwidget for Clay Warg ("dst_menu_yotv") with"loop"animation. - Parameters: None.
- Returns: UIAnim instance.
TEMPLATES.GetBuildString()
- Description: Returns a formatted build version string (e.g.,
"Internal v1.2.3.4 (64-bit)","Preview v..."). - Parameters: None.
- Returns: String.
TEMPLATES.AddBuildString(parent_widget, config)
- Description: Adds a
Textwidget displaying the build string toparent_widget. - Parameters:
parent_widget— parent widget to which theTextis added.config— optional table with keys:font,size,colour,r,g,b,a,align,w,h,x,y.
- Returns: Text widget instance that displays the build string.
TEMPLATES.ScreenTitle(title_text, subtitle_text)
- Description: Creates a screen title widget with optional subtitle in top-left (predefined position
titleX,titleY). - Parameters:
title_text— main title string.subtitle_text— optional subtitle string.
- Returns: Root widget containing
big(main title Text) andsmall(subtitle Text) as properties.
TEMPLATES.ScreenTitle_BesideLeftSideBar(title_text, subtitle_text)
- Description: Wrapper for
ScreenTitle, positioning it to the right of the left sidebar. - Parameters: Same as
ScreenTitle. - Returns: Widget returned by
ScreenTitle, with position overridden.
TEMPLATES.StandardMenu(menuitems, offset, horizontal, style, wrap)
- Description: Creates a standard menu at predefined position (
menuX,menuY), withreverse = true. - Parameters: All passed to
Menu(...); optional params may be omitted. - Returns: Menu instance.
TEMPLATES.ScreenTooltip()
- Description: Creates a word-wrapped
Textwidget for tooltips at a fixed position below menu. - Parameters: None.
- Returns: Text widget instance.
TEMPLATES.MenuButton(text, onclick, tooltip_text, tooltip_widget, style, text_size)
- Description: Creates a menu button with focus/selected/hover states, background area, and customizable style ("wide").
- Parameters:
text— button label string.onclick— click callback.tooltip_text— text to display in tooltip.tooltip_widget—Textwidget to update on focus changes.style— optional"wide"to adjust dimensions.text_size— font size override.
- Returns: ImageButton instance with
bg,text,text_shadow, and event handlersongainfocus,onlosefocus.
TEMPLATES.TwoLineMenuButton(text, onclick, tooltip_text, tooltip_widget)
- Description: Extends
MenuButtonto support secondary (sub) text beneath primary text. - Parameters: Same as
MenuButton. - Returns: Modified ImageButton with
secondary_text,SetSecondaryText,onselect,onunselecthandlers.
TEMPLATES.WardrobeButton(text, onclick, tooltip_text, tooltip_widget)
- Description: Extends
TwoLineMenuButtonwith anAccountItemFrameicon and dynamic secondary text fromGetSkinName/GetColorForItem. - Parameters: Same as
TwoLineMenuButton. - Returns: ImageButton with
icon,SetItem(item_id)method.
TEMPLATES.WardrobeButtonMinimal(onclick)
- Description: Minimal wardrobe button (no text) using
AccountItemFrame, with focus/select visibility toggles. - Parameters:
onclick— click callback. - Returns: ImageButton with
iconandSetItem(item_id).
TEMPLATES.PortraitIconMenuButton(text, onclick, tooltip_text, tooltip_widget)
- Description: Extends
TwoLineMenuButtonwith a character portrait in top-left. - Parameters: Same as
TwoLineMenuButton. - Returns: ImageButton with
title_portrait,SetCharacter(character_atlas, character)method.
TEMPLATES.BackButton(onclick, txt, shadow_offset, scale)
- Description: Back/Cancel button with arrow icon and text, positioned at fixed screen location.
- Parameters:
onclick— callback.txt— optional label (defaults toSTRINGS.UI.SERVERLISTINGSCREEN.BACK).shadow_offset— text shadow offset table.scale— scale override.
- Returns: ImageButton with
bg, customSetText, and focus/onclick handlers.
TEMPLATES.BackButton_BesideLeftSidebar(onclick, txt, shadow_offset, scale)
- Description: Adjusts
BackButtonposition to align beside left sidebar. - Parameters: Same as
BackButton, butscaledefaults to0.8. - Returns: Adjusted ImageButton.
TEMPLATES.StandardButton(onclick, txt, size, icon_data)
- Description: Creates a standard clickable button with scalable textures (
"carny_long","carny_xlong","carny_square") and optional icon. - Parameters:
onclick— callback.txt— label text.size— optional{width,height}to select texture and font size.icon_data— optional{atlas, texture}to add icon.
- Returns: ImageButton with optional
iconand adjusted text/icon layout.
TEMPLATES.IconButton(iconAtlas, iconTexture, labelText, sideLabel, alwaysShowLabel, onclick, textinfo, defaultTexture)
- Description: Creates a square button with an icon and optional label beside or below it (or hover-only).
- Parameters:
iconAtlas,iconTexture— icon image path.labelText— optional label.sideLabel— boolean:trueplaces label to left;falsechecksalwaysShowLabel.alwaysShowLabel— boolean:trueplaces label below button.onclick— callback.textinfo— optional table with font, size, colour, etc.defaultTexture— unused (present in signature but not used).
- Returns: ImageButton instance with label logic.
TEMPLATES.StandardCheckbox(onclick, size, init_checked, helptext, hovertext_info)
- Description: Creates a checkbox with toggle visuals and optional hover/helptext.
- Parameters:
onclick— callback returning boolean.size— size of checkbox square.init_checked— initial state.helptext— optional help text.hovertext_info— optional hover tooltip config table.
- Returns: ImageButton with custom
SetCheckedlogic and onclick handler.
TEMPLATES.ServerDetailIcon(iconAtlas, iconTexture, bgColor, hoverText, textinfo, imgOffset, scaleX, scaleY)
- Description: Creates an icon widget with optional background and hover text.
- Parameters:
iconAtlas,iconTexture— icon image.bgColor— optional background suffix (used with"bg_..."texture).hoverText— optional tooltip string.textinfo— optional hover tooltip style config.imgOffset,scaleX,scaleY— image positioning/scale overrides.
- Returns: Widget instance with
bgandimgchildren.
TEMPLATES.ListItemBackground(row_width, row_height, onclick_fn)
- Description: Creates a highlightable list row background for click or focus interactions.
- Parameters:
row_width,row_height— dimensions.onclick_fn— optional click callback.
- Returns: ImageButton with scaled texture based on aspect ratio (uses prefix
listitem_thickorserverlist_listitem).
TEMPLATES.ListItemBackground_Static(row_width, row_height)
- Description: Static (non-interactive) list row background using tinted
Image. - Parameters:
row_width,row_height. - Returns: Image with fixed tint.
TEMPLATES.ModListItem(onclick_btn, onclick_checkbox, onclick_setfavorite)
- Description: Creates a mod list item widget with icon, checkbox, favorite star, status label, and out-of-date/configurable indicators.
- Parameters:
onclick_btn,onclick_checkbox,onclick_setfavorite— callbacks.
- Returns: Widget instance with extensive helper methods:
SetMod,SetModStatus,SetModEnabled,SetModFavorited,SetModConfigurable,SetModReadOnly,Select,Unselect.
TEMPLATES.ModListItem_Downloading()
- Description: Creates a mod list item for a mod that is currently downloading.
- Parameters: None.
- Returns: Widget instance with
nameandSetMod(mod)method showing download status string.
TEMPLATES.DoodadCounter(number_of_doodads)
- Description: Creates an animated counter widget for "doodads" (e.g., materials).
- Parameters:
number_of_doodads— initial count. - Returns: Widget with
image(UIAnim),doodad_count(Text),_CountFn,SetCount(new_count, animateDoodad).
TEMPLATES.KleiPointsCounter(number_of_points)
- Description: Creates a Klei Points counter widget that opens the rewards page on click.
- Parameters:
number_of_points. - Returns: Button with
image(UIAnim),points_count,SetCount, and onclick handler.
TEMPLATES.BoltCounter(number_of_bolts)
- Description: Creates an animated counter widget for bolts of cloth.
- Parameters:
number_of_bolts. - Returns: Widget with
image,bolt_count,_CountFn,SetCount.
TEMPLATES.StandardSingleLineTextEntry(fieldtext, width_field, height, font, font_size, prompt_text)
- Description: Creates a text entry field with background and input handling.
- Parameters:
fieldtext— initial text.width_field,height,font,font_size,prompt_text— optional.
- Returns: Widget with
textbox_bg,textbox, event handlers, andGetHelpText.
TEMPLATES.LabelTextbox(labeltext, fieldtext, width_label, width_field, height, spacing, font, font_size, horiz_offset)
- Description: Adds a label to
StandardSingleLineTextEntry, placing label to left of text input. - Parameters: All optional except
labeltext,fieldtext. - Returns: Widget with
labelandtextboxpositioned relative to label.
TEMPLATES.LabelSpinner(labeltext, spinnerdata, width_label, width_spinner, height, spacing, font, font_size, horiz_offset, onchanged_fn, colour, tooltip_text)
- Description: Creates a spinner with a label beside it.
- Parameters:
labeltext,spinnerdata— label text and spinner data list.- Other layout/size/behavior parameters.
- Returns: Widget with
labelandspinnerchild;focus_forwardset.
TEMPLATES.LabelNumericSpinner(labeltext, min, max, width_label, width_spinner, height, spacing, font, font_size, horiz_offset, tooltip_text)
- Description: Similar to
LabelSpinnerbut usesStandardNumericSpinner. - Parameters: Same structure as
LabelSpinner, but takesmin/maxinstead ofspinnerdata. - Returns: Widget with label and numeric spinner.
TEMPLATES.LabelButton(onclick, labeltext, buttontext, width_label, width_button, height, spacing, font, font_size, horiz_offset)
- Description: Creates a label +
StandardButtonlayout. - Parameters: All layout and callback args.
- Returns: Widget with
labelandbuttonchildren.
TEMPLATES.OptionsLabelCheckbox(onclick, labeltext, checked, width_label, width_button, height, checkbox_size, spacing, font, font_size, horiz_offset, tooltip_text)
- Description: Creates a label + checkbox layout.
- Parameters: All layout and callback args.
- Returns: Widget with
labelandbutton(a checkbox) children;tooltip_textstored.
TEMPLATES.LabelCheckbox(onclick, checked, text)
- Description: Creates a standalone checkbox with text label to right.
- Parameters:
onclick— callback receiving checkbox instance.checked— initial boolean.text— label string.
- Returns: ImageButton with
checked,Refresh, and text offset logic.
TEMPLATES.StandardSpinner(spinnerdata, width_spinner, height, font, font_size, onchanged_fn, colour)
- Description: Creates a
Spinnerwith custom font, width, height, and onchanged handler. - Parameters:
spinnerdata— list of{text, colour, image, data}entries.- Other layout/behavior args.
- Returns: Spinner instance.
TEMPLATES.StandardNumericSpinner(min, max, width_spinner, height, font, font_size)
- Description: Creates a
NumericSpinnerwith min/max range. - Parameters:
min,max, layout args. - Returns: NumericSpinner instance.
TEMPLATES.CharacterSpinner(onchanged_fn, puppet, user_profile)
- Description: Creates a character selection spinner populated by
GetFEVisibleCharacterList, updates skins viapuppetanduser_profile. - Parameters:
onchanged_fn— callback(selected_name, old).puppet,user_profile— for skin updates.
- Returns: Spinner with
LoadLastSelectedFromProfilemethod.
TEMPLATES.ChatFlairBadge()
- Description: Creates a chat flair badge widget with optional festival background and flair icon.
- Parameters: None.
- Returns: Widget with
bg,flair_img, methodsSetFestivalBackground,SetFlair,GetFlair,SetAlpha,GetSize.
TEMPLATES.ChatterMessageBadge()
- Description: Creates a chatter/message flair badge widget with bg icon, flair icon, and alpha toggle.
- Parameters: None.
- Returns: Widget with
bg,flair_img, methodsSetFlair,GetFlair,SetBGIcon,GetBGIcon,SetAlpha,GetSize.
TEMPLATES.AnnouncementBadge()
- Description: Creates an announcement badge with circle background and announcement icon.
- Parameters: None.
- Returns: Widget with
bg,announcement_img, methodsSetAnnouncement,GetAnnouncement,SetAlpha,GetSize.
TEMPLATES.SystemMessageBadge()
- Description: Creates a system message badge (dedicated server icon).
- Parameters: None.
- Returns: Widget with
bg,systemmessage_img, andSetAlpha,GetSize.
TEMPLATES.RankBadge()
- Description: Creates a rank badge showing profile flair and numeric rank under a festival background.
- Parameters: None.
- Returns: Widget with
bg,flair,num, methodsSetFestivalBackground,SetRank.
TEMPLATES.FestivalNumberBadge(festival_key)
- Description: Creates a static image badge with a numeric rank overlay for festivals.
- Parameters:
festival_key— optional (defaults toWORLD_FESTIVAL_EVENT). - Returns: Image instance with
numchild andSetRank(rank_value).
TEMPLATES.UserProgress(onclick)
- Description: Creates a user profile progress display with username, progress bar, rank badge, and clickable area.
- Parameters:
onclick— callback for click on progress area. - Returns: Widget with
name,bar,rank,btn, andUpdateProgressmethod.
TEMPLATES.LargeScissorProgressBar(name)
- Description: Creates a large progress bar that uses scissor rect on a fill image.
- Parameters:
name— optional widget name. - Returns: Widget with
frame,fillandSetPercent(percent)method.
TEMPLATES.WxpBar()
- Description: Creates a widget displaying experience progress, including rank badge, next-rank badge, progress bar, and XP value text fields. Handles both direct XP updates and local user profile updates.
- Parameters: None.
- Returns:
wxpbarwidget (Widget("Experience")instance).
TEMPLATES.ItemImageText(item_type, item_key, max_width)
- Description: Constructs a widget combining an item icon with descriptive text. Delegates to
TEMPLATES.old.ItemImageText, then enhances the text label with word wrapping and region sizing. - Parameters:
item_type: String, item type identifieritem_key: String, item key used to fetch localized name viaGetSkinNamemax_width: Optional number, max text width (default:300)
- Returns: Enhanced widget
wwithSetItemmethod added.
TEMPLATES.ItemImageVerticalText(item_type, item_key, max_width)
- Description: Reuses
TEMPLATES.ItemImageTextbut adjusts text alignment and position for vertical layout. - Parameters: Same as
ItemImageText. - Returns: Modified widget
wwith vertically centered text at position(0, -80).
TEMPLATES.CurlyWindow(sizeX, sizeY, title_text, bottom_buttons, button_spacing, body_text)
- Description: Creates a dialog window with ornate curly borders (
NineSlice), optional title, buttons, and body text. Handles layout adjustments for Japanese language PS4 builds. - Parameters:
sizeX,sizeY: Optional dimensions; clamped to[190–1000],[90–500]title_text: Optional string for titlebottom_buttons: Optional list of button widgets/objects forMenubutton_spacing: Optional spacing; auto-calculated ifnilbody_text: Optional string for body content
- Returns:
w(NineSlice-based dialog widget).
TEMPLATES.RectangleWindow(sizeX, sizeY, title_text, bottom_buttons, button_spacing, body_text)
- Description: Similar to
CurlyWindowbut uses rectangular borders. AddsSetBackgroundTint,HideBackground, andInsertWidgetmethods. - Parameters: Same as
CurlyWindow. - Returns:
w(NineSlice-based dialog widget with extra methods).
TEMPLATES.ControllerFunctionsFromButtons(buttons)
- Description: Generates
OnControlandGetHelpTextfunctions for controller input handling based on a button list. Auto-assignsCONTROL_CANCELto last button if none specified. - Parameters:
buttons: List of tables, each with{text, cb, controller_control}
- Returns: Two functions:
OnControl(control, down)→trueif handled, elsefalseGetHelpText()→ concatenated localized input + text string.
TEMPLATES.ScrollingGrid(items, opts)
- Description: Builds a scrollable grid of widgets using
TrueScrollList. Handles peek height calculation, scissor region setup, and widget layout. - Parameters:
items: List of data items to populate gridopts: Table with keys:peek_height,peek_percent,force_peek,num_visible_rows,num_columns,widget_width,widget_heightitem_ctor_fn,scroll_context,apply_fn,end_offset,allow_bottom_empty_rowscissor_pad,scrollbar_offset,scrollbar_height_offset,scroll_per_click
- Returns:
scroller(TrueScrollListinstance).
TEMPLATES.LeftColumn()
- Description: Creates a widget positioned on the left side of the screen via
lcol. - Parameters: None.
- Returns:
Widget("left column")instance atSetPosition(lcol, 0).
TEMPLATES.RightColumn()
- Description: Creates a widget positioned on the right side of the screen via
rcol. - Parameters: None.
- Returns:
Widget("right column")instance atSetPosition(rcol, 0).
TEMPLATES.ReduxForeground()
- Description: Creates a foreground widget containing a letterbox overlay. Disables alpha fading.
- Parameters: None.
- Returns:
fgwidget withletterboxchild.
TEMPLATES.MakeUIStatusBadge(_status_name, c)
- Description: Builds a static UI badge for a status (e.g., health, hunger, sanity) with icon, value image, and numeric text. Supports dynamic character updates.
- Parameters:
_status_name: String, status type (e.g.,"health")c: Optional character string; if provided, initializes badge with that character’s values
- Returns:
statuswidget withChangeCharactermethod.
TEMPLATES.MakeStartingInventoryWidget(c, left_align)
- Description: Builds a widget displaying a character’s starting inventory items as slots/images. Handles empty inventory case and character switching.
- Parameters:
c: Optional character string; if provided, initializes inventoryleft_align: Boolean, aligns title and layout left iftrue
- Returns:
rootwidget withChangeCharactermethod.
Events & listeners
None found. No inst:ListenForEvent or inst:PushEvent calls are present across the source file.