Custom UI API
The Custom UI API provides functions for creating interactive UI elements in Schedule 1. This includes windows, controls, and styling options to create custom interfaces for your mods and scripts.
Implementation Status: Partially implemented. Basic custom UI functions are available.
Overview
The Custom UI system allows you to create your own user interface elements from Lua scripts. You can build windows with various controls like buttons, labels, and text fields, and customize their appearance using styling functions.
Available Functions
Window Management
CreateWindow(id, title, x, y, width, height)
- Creates a UI windowSetWindowPosition(windowId, x, y)
- Sets a window's positionSetWindowSize(windowId, width, height)
- Sets a window's sizeShowWindow(windowId, visible)
- Shows or hides a windowDestroyWindow(windowId)
- Destroys a window
UI Controls
AddButton(windowId, id, text, callback)
- Adds a button to a windowAddLabel(windowId, id, text)
- Adds a label to a windowAddTextField(windowId, id, text)
- Adds a text field to a windowGetControlText(controlId)
- Gets the text of a UI controlSetControlText(controlId, text)
- Sets the text of a UI controlSetControlPosition(controlId, x, y)
- Sets a control's positionSetControlSize(controlId, width, height)
- Sets a control's sizeShowControl(controlId, visible)
- Shows or hides a controlDestroyControl(controlId)
- Destroys a control
UI Styling
SetWindowStyle(colorName, r, g, b, a)
- Sets window style colorsSetButtonStyle(colorName, r, g, b, a)
- Sets button style colorsSetLabelStyle(colorName, r, g, b, a)
- Sets label style colorsSetTextFieldStyle(colorName, r, g, b, a)
- Sets text field style colorsSetBoxStyle(colorName, r, g, b, a)
- Sets box style colorsSetFontSize(styleName, size)
- Sets font size for UI elementsSetFontStyle(styleName, fontStyle)
- Sets font style (bold, italic, etc.)SetTextAlignment(styleName, alignment)
- Sets text alignmentSetBorder(styleName, left, right, top, bottom)
- Sets border dimensionsSetPadding(styleName, left, right, top, bottom)
- Sets padding dimensions
Example Usage
Basic Window with Controls
lua
local windowId = "myWindow"
local submitButtonId = "submitBtn"
local nameFieldId = "nameField"
function CreatePlayerInfoWindow()
-- Create a window
CreateWindow(windowId, "Player Information", 100, 100, 300, 200)
-- Add label
AddLabel(windowId, "nameLabel", "Enter your character name:")
-- Add text field
AddTextField(windowId, nameFieldId, "")
SetControlPosition(nameFieldId, 20, 50)
SetControlSize(nameFieldId, 260, 30)
-- Add button
AddButton(windowId, submitButtonId, "Save Name", OnSaveNameClick)
SetControlPosition(submitButtonId, 100, 150)
-- Show the window
ShowWindow(windowId, true)
}
function OnSaveNameClick()
local playerName = GetControlText(nameFieldId)
if playerName and playerName ~= "" then
ShowNotification("Name saved: " .. playerName)
-- Here you might store the name in the Registry
DestroyWindow(windowId)
else
ShowNotification("Please enter a valid name")
end
end
function CommandNameChange(args)
CreatePlayerInfoWindow()
end
function OnConsoleReady()
-- Register commands
RegisterCommand("namechange", "Opens name change window", "namechange", CommandNameChange)
end
Styled Window Example
lua
function CreateStyledWindow()
-- Create the base window
CreateWindow("styledWindow", "Custom Styled UI", 100, 100, 500, 400)
-- Style the window with a dark theme
SetWindowStyle("background", 0.12, 0.12, 0.15, 0.95)
SetFontSize("window", 18)
SetFontStyle("window", "bold")
SetBorder("window", 8, 8, 8, 8)
SetPadding("window", 12, 12, 25, 12)
-- Add a title label
AddLabel("styledWindow", "titleLabel", "Welcome to the Custom UI Demo")
SetControlPosition("titleLabel", 20, 40)
SetControlSize("titleLabel", 460, 30)
SetLabelStyle("text", 0.9, 0.9, 1.0, 1.0)
SetFontSize("label", 16)
SetFontStyle("label", "bold")
SetTextAlignment("label", "middlecenter")
-- Add a description
AddLabel("styledWindow", "descLabel", "This window demonstrates the styling capabilities of the UI system.")
SetControlPosition("descLabel", 20, 80)
SetLabelStyle("text", 0.8, 0.8, 0.9, 1.0)
-- Add buttons with different styles
AddButton("styledWindow", "acceptButton", "OK", OnAcceptButtonClick)
SetControlPosition("acceptButton", 200, 350)
SetButtonStyle("background", 0.3, 0.6, 0.3, 1.0)
SetButtonStyle("text", 1.0, 1.0, 1.0, 1.0)
-- Show the window
ShowWindow("styledWindow", true)
}
function OnAcceptButtonClick()
DestroyWindow("styledWindow")
end
function CommandShowStyledUI(args)
CreateStyledWindow()
end
function OnConsoleReady()
-- Register UI commands
RegisterCommand("namechange", "Opens name change window", "namechange", CommandNameChange)
RegisterCommand("styledui", "Shows a styled UI example", "styledui", CommandShowStyledUI)
end
Current Limitations
- UI elements may not persist across scene changes
- The UI system may have performance impacts with many elements
- Windows cannot be resized by the user (only programmatically)
- Limited support for complex UI layouts
- UI elements operate in screen space, not world space
Best Practices
- Clear UI when done: Always destroy UI elements when they're no longer needed
- Limit active UI: Avoid having too many UI elements active at once
- Be responsive: Consider different screen resolutions in your UI design
- Error checking: Validate all IDs before using them with control functions
- Limited Update calls: Avoid updating UI elements every frame
- Consistent styling: Use the styling functions to maintain a consistent look across your UI elements
Future Enhancements
Future updates to the Custom UI API will include:
- Additional control types (checkboxes, radio buttons, sliders)
- World-space UI elements
- UI animations and transitions
- UI event system
- Drag-and-drop support
- Advanced layout containers
Explore the sections in the sidebar for detailed documentation of each function.