ui

package
v0.1.125 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ui draws each player's interface from a tree of elements, as struct literals:

ui.Show(p, ui.Panel{
	Style: ui.Style{Flow: ui.Down},
	Children: ui.Nodes{
		ui.Label{Text: "Round 2"},
		ui.Button{OnPress: ready, Children: ui.Text("Ready")},
	},
})

Each Show lays the tree out as flat nodes whose ids stay with their place in the tree, and sends the player only the nodes that changed since the screen they hold. Importing the package registers its handlers for presses, input changes, the frame clock and the player list with package mod.

Index

Constants

View Source
const (
	// Down runs children or colors down.
	Down = "down"
	// Right runs children or colors right, or aligns right.
	Right = "right"
	// DownWrap places children in columns that wrap.
	DownWrap = "downWrap"
	// RightWrap places children in rows that wrap.
	RightWrap = "rightWrap"
	// Up runs a gradient's colors up.
	Up = "up"
	// Left runs a gradient's colors left, or aligns left.
	Left = "left"
	// Radial runs a gradient's colors out from the center.
	Radial = "radial"
	// Top aligns to the top.
	Top = "top"
	// Center aligns to the middle.
	Center = "center"
	// Bottom aligns to the bottom.
	Bottom = "bottom"
	// Squish shrinks children that do not fit.
	Squish = "squish"
	// Clip cuts off children or text that do not fit.
	Clip = "clip"
	// Scroll lets the player scroll to children that do not fit.
	Scroll = "scroll"
	// Visible draws children that do not fit outside the element.
	Visible = "show"
	// Body is the game's text face.
	Body = "body"
	// Block is the face of the game's clock and titles.
	Block = "block"
	// Serif is the face of the game's menus.
	Serif = "serif"
	// Thin is the thinnest weight.
	Thin = "thin"
	// Light is a light weight.
	Light = "light"
	// Normal is the regular weight.
	Normal = "normal"
	// Medium is a medium weight.
	Medium = "medium"
	// SemiBold is a semibold weight.
	SemiBold = "semiBold"
	// Bold is a bold weight.
	Bold = "bold"
	// Black is the heaviest weight.
	Black = "black"
	// Ellipsis ends text that does not fit with an ellipsis.
	Ellipsis = "ellipsis"
	// Shrink shrinks text until it fits.
	Shrink = "shrink"
	// Underline draws a line under the text.
	Underline = "underline"
	// Strike draws a line through the text.
	Strike = "strike"
	// EaseOut starts fast and slows to the end.
	EaseOut = "out"
	// EaseIn starts slow and speeds to the end.
	EaseIn = "in"
	// EaseInOut starts and ends slow.
	EaseInOut = "inOut"
	// Linear keeps one pace.
	Linear = "linear"
	// Fit shows a picture whole.
	Fit = "fit"
	// Cover fills the box and crops.
	Cover = "cover"
	// Stretch fills the box and stretches.
	Stretch = "stretch"
	// FitWidth fits a picture's width.
	FitWidth = "fitWidth"
	// FitHeight fits a picture's height.
	FitHeight = "fitHeight"
	// None draws a picture at its own size.
	None = "none"
	// Small is the kill feed's square portrait.
	Small = "small"
	// Card is the hero picker's tall card.
	Card = "card"
	// Icon is the round icon.
	Icon = "icon"
	// Vertical is the hero grid's narrow portrait.
	Vertical = "vertical"
	// TopBar is the top bar, or its portrait.
	TopBar = "topBar"
	// Minimap is the minimap, or its icon.
	Minimap = "minimap"
	// LevelUp is the notice for each boon and ability point.
	LevelUp = "levelUp"
	// OwnHealth is the player's health bar.
	OwnHealth = "ownHealth"
	// Ammo is the clip ring and count at the crosshair.
	Ammo = "ammo"
	// Souls is the souls and level readout.
	Souls = "souls"
	// Abilities is the ability and active item bar.
	Abilities = "abilities"
	// Status is the game's mark in the top-left corner.
	Status = "status"
	// Stats is the weapon, spirit and vitality stats.
	Stats = "stats"
	// HeroPicker is the screen a player without a hero picks one on.
	HeroPicker = "heroPicker"
	// BrokerCountdown is the countdown in the Broker's window.
	BrokerCountdown = "brokerCountdown"
	// MinimapPlayers is every player's icon on the minimap, the player's own
	// included.
	MinimapPlayers = "minimapPlayers"
	// Inventory is the purchased items beside the stats.
	Inventory = "inventory"
	// Crosshair is the crosshair with its clip ring, count and stamina pips.
	Crosshair = "crosshair"
	// CastFailed is the notice of an ability the player could not cast.
	CastFailed = "castFailed"
	// EventIndicators is the icons and numbers floated at each event that
	// affects the player, such as a status or an item used.
	EventIndicators = "eventIndicators"
	// StatusIndicators is the event indicators that name a crowd control
	// status applied to the player, such as a stun.
	StatusIndicators = "statusIndicators"
	// KillFeed is the feed of kills and other match events.
	KillFeed = "killFeed"
	// Objectives is the health of each team's objectives.
	Objectives = "objectives"
	// Hints is the game's tips beside the crosshair.
	Hints = "hints"
	// OffscreenAttackers is the markers at the screen's edge that point to an enemy out of view.
	OffscreenAttackers = "offscreenAttackers"
	// DamagedTarget is the badge and health bar of the enemy the player last hurt.
	DamagedTarget = "damagedTarget"
	// DamageReport is the report of damage taken and dealt after a death.
	DamageReport = "damageReport"
	// TestingTools is the sandbox's test tools panel.
	TestingTools = "testingTools"
	// PlaytestNotice is the notice over a playtest build's HUD.
	PlaytestNotice = "playtestNotice"
	// ShopPrompt is the shop's sign and prompt while the player stands at a shop.
	ShopPrompt = "shopPrompt"
	// UnitMarkers is the markers with a distance over players and other units.
	UnitMarkers = "unitMarkers"
	// FlexSlotNotice is the notice that a flex item slot unlocked.
	FlexSlotNotice = "flexSlotNotice"
	// AbilityReminders is the reminders under the abilities to hold a key to
	// unlock or upgrade an ability.
	AbilityReminders = "abilityReminders"
	// All is the whole HUD but the mods' own interfaces, tooltips and chat.
	All = "all"
)

The names of each option. They are untyped so one name serves every option that takes it, as Right does a flow, an alignment and a gradient.

Variables

View Source
var Fill = Length{/* contains filtered or unexported fields */}

Fill shares the space left in the parent's flow.

View Source
var FitChildren = Length{/* contains filtered or unexported fields */}

FitChildren sizes an element to its children.

Functions

func AbilityBarPresses

func AbilityBarPresses(p mod.Player, onPress func(p mod.Player, slot int)) bool

AbilityBarPresses calls onPress with the slot, 0 to 3, each time player clicks the icon or upgrade pips of an ability on the game's own ability bar, as the game does when it trains one with Tab held; a nil onPress stops the clicks reaching the mod. The game answers a click from the hero's own abilities, and sends nothing for an ability the mod replaced, so a mod that replaces abilities answers here. Clicks reach the mod only while its screen holds the player's HUD.

func AbilityDisplay

func AbilityDisplay(viewer mod.Player, rows ...AbilityRow) bool

AbilityDisplay shows viewer each row's abilities in place of the ones the game shows for that player's hero: on the player's row of the game's Tab screen, and for viewer's own row on viewer's ability bar too, in the game's frame, ring and pips, with the game's ability window over each. Without rows the game's own come back, as they do when viewer leaves or the session ends. Rows match the Tab screen's by the player's name and else by the hero's, so each row's player should have a hero.

func CancelTimeline

func CancelTimeline(p mod.Player, id string) bool

CancelTimeline stops timeline id in player's interface, taking back its looks and playing none of its sounds still to come.

func CursorFree

func CursorFree(p mod.Player) (free, ok bool)

CursorFree reports whether player's mouse cursor is up now, whether the mod freed it with FreeCursor or the player freed it with the game's own keys. ok is false while the player does not have a hero, because the game keeps the cursor's state on the hero.

func FollowAction

func FollowAction(p mod.Player, action mod.GameAction, onPhase func(p mod.Player, phase mod.ActionPhase)) bool

FollowAction calls onPhase with each phase of action, a game action such as mod.GameActionScoreboard, each time player uses it, on whichever key they bound it to: pressed once, then released or cancelled once. The game still does what the action does. A press made while a stock overlay, such as chat, the shop or the escape menu, has the player's input reports nothing, and one held as such an overlay opens is cancelled. A nil onPhase stops following. Actions reach the mod only while its screen holds the player's HUD.

func FollowOverlay

func FollowOverlay(p mod.Player, onChange func(p mod.Player, overlay mod.Overlay)) bool

FollowOverlay calls onChange with the stock overlay, such as mod.OverlayChat, mod.OverlayShop or mod.OverlayEscapeMenu, that holds player's input: first the current one, then each time a different one takes it, or mod.OverlayNone as the game gets it back. When several are open it names the first of chat, the shop, the build editor, the item draft, a popup and the escape menu. A nil onChange stops following.

func FollowPlacement

func FollowPlacement(p mod.Player, onPlace func(p mod.Player, placement Placement)) bool

FollowPlacement calls onPlace with where player's screen places the interface: the whole placement first, then again each time any part of it moves, such as when the player changes resolution or an element's layout settles. Elements that share a Measure report one box. A nil onPlace stops following.

func FreeCursor

func FreeCursor(p mod.Player, free bool) bool

FreeCursor shows player's mouse cursor while free is true, so they can click the mod's panels, such as a pick screen, without holding Tab. A false free puts the cursor away and gives the mouse back to aiming. While the cursor is up, a click on one of the mod's panels goes to that panel, and the hero does not shoot. A click anywhere else fires the weapon, and the camera and movement keep working. If the player should not shoot while the screen is up, block the fire buttons with p.BlockInput, and release them when the screen hides. Blocking cannot stop the camera turning or the hero walking, because the game reads those from the mouse and movement axes, not from the buttons. The player can also put the cursor away with the game's own keys. It then stays away when the mod draws a new screen, until the next call with true shows it again.

func Hide

func Hide(p mod.Player) bool

Hide removes the interface, the routes and the notices the mod shows player.

func HideHud

func HideHud(p mod.Player, parts ...HudPart) bool

HideHud hides parts of the game's own HUD from player until the next call; no parts shows them all again.

func InHudFrame

func InHudFrame(p mod.Player, on bool) bool

InHudFrame draws player's interface inside the HUD's frame instead of the whole screen. The frame is the screen itself, except on a screen wider than 16:9 where the player keeps the HUD in its middle 16:9, so an interface aligned to the frame's edges lines up with the game's HUD.

func PlayTimeline

func PlayTimeline(p mod.Player, id string, t Timeline) bool

PlayTimeline starts timeline id in player's interface, or starts it again from its start, taking back the looks its last run gave. A finished timeline keeps its last looks until it is played again or cancelled. A renderer that reloads mid-run shows the run's last looks and plays none of its sounds.

func Route

func Route(p mod.Player, name, value string) bool

Route sends player the JSON text value under name, for every layout of the mod to read with Modlock.route, until the next call; "" removes it. A name is letters, digits, '_', '-' and '.'. A route with another name, or a value that is not JSON, sends nothing and returns false.

func Sheet

func Sheet(path string) bool

Sheet adds the style sheet at path in the mod's content styles directory, such as "hud.css", to every interface the mod shows, after the sheets added before it. Adding a sheet again changes nothing. A path is letters, digits, '_', '-' and '.' in segments separated by '/', ending in ".css"; another adds nothing and returns false.

func Show

func Show(p mod.Player, root Node) bool

Show replaces the interface the mod shows player with root. A player who left and a mod that restarted show nothing until the next call.

func Sound

func Sound(p mod.Player, sound string, seconds float32) bool

Sound plays the game's sound event sound, such as "UI.ItemDraft.Start", in player's game alone, once; seconds above 0 cuts it after that long, keeping only its start. It plays with the next screen the player reads, and not at all if the player reads it only after the mod's next few sounds. PlayTimeline times a run of sounds, such as a wheel's ticks.

func Toast

func Toast(p mod.Player, text string) bool

Toast shows player text in a notice at the lower left for four seconds. Notices stack, newest last, slide in, and fade as they expire.

func ToastFor

func ToastFor(p mod.Player, text string, seconds float64) bool

ToastFor shows player text in a notice for seconds, as Toast does.

Types

type AbilityRow

type AbilityRow struct {
	// Player is whose abilities the row replaces.
	Player mod.Player
	// Abilities holds slots 0 to 3; a nil slot shows the game's own.
	Abilities []*ShownAbility
}

AbilityRow is the four abilities, in slot order, AbilityDisplay shows for one player.

type AbilityTip

type AbilityTip struct {
	// Name is the ability's class name.
	Name string
	// Player is whose hero the window reads its numbers from.
	Player mod.Player
}

AbilityTip is the game's own window for an ability, in the player's language: Name is the ability's class name, such as "ability_bebop_hook", and Player is whose hero the window reads its numbers from, a hero that stands on the map, such as a bot that plays it.

type Align

type Align string

Align places an element in its parent, or text in its element: Left, Center or Right across, and Top, Center or Bottom down.

type Avatar

type Avatar struct {
	// Key keeps the avatar's node in a list while the list changes.
	Key string
	// Class names the avatar's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the avatar.
	Style Style
	// Hover is drawn over Style while the pointer is over the avatar.
	Hover *Style
	// Enter is the style the avatar starts from when it first shows.
	Enter *Style
	// Exit is the style the avatar eases to as it leaves.
	Exit *Style
	// Cycle swings the avatar to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the avatar.
	Tooltip string
	// Item names an item by class name whose shop card shows over the avatar.
	Item string
	// Ability names an ability whose window shows over the avatar.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Measure names the avatar in the placement reports of FollowPlacement.
	Measure string
	// SteamID is whose picture the avatar shows.
	SteamID uint64
}

Avatar shows the Steam picture of the player with SteamID.

func (Avatar) Render

func (e Avatar) Render() Node

Render returns the avatar itself.

type Binding

type Binding struct {
	// Text replaces a label's words.
	Text *string
	// Token replaces a label's words with the game's text for it in the
	// player's language, each {s:name} place filled from Variables.
	Token string
	// Variables supplies the named values used by the layout.
	Variables map[string]string
	// Visible shows or hides the panel.
	Visible *bool
	// Class adds classes from the layout's sheets, separated by spaces.
	Class string
	// Style sets inline style; a property it drops returns to the author's.
	Style *Style
	// Src sets an image's picture from the game's content. The game cannot
	// read a picture back, so the last one set stays until the layout loads
	// again.
	Src string
	// OnPress runs when the player presses the panel.
	OnPress func(p mod.Player)
}

Binding sets parts of one panel of a layout and leaves the rest as the layout's author drew it. A nil or empty field keeps the author's value, and one the mod stops setting returns to it, except Src. A panel the layout lacks leaves the binding undrawn and the rest drawn.

type Button

type Button struct {
	// Key keeps the button's node in a list while the list changes.
	Key string
	// Class names the button's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the button.
	Style Style
	// Hover is drawn over Style while the pointer is over the button.
	Hover *Style
	// Enter is the style the button starts from when it first shows.
	Enter *Style
	// Exit is the style the button eases to as it leaves.
	Exit *Style
	// Cycle swings the button to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the button.
	Tooltip string
	// Item names an item by class name whose shop card shows over the button.
	Item string
	// Ability names an ability whose window shows over the button.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Measure names the button in the placement reports of FollowPlacement.
	Measure string
	// Sound is the game's sound event the press plays.
	Sound string
	// Disabled makes the button take no presses.
	Disabled bool
	// OnPress runs with the player who pressed the button.
	OnPress func(p mod.Player)
	// Children are the nodes the button holds.
	Children Node
}

Button holds its children and calls OnPress with the player who pressed it. Players press buttons while they have a cursor. Sound is the game's sound event the press plays, such as "UI.MainMenu.Activate", and a disabled button takes no presses.

func (Button) Render

func (e Button) Render() Node

Render returns the button itself.

type Clipping added in v0.1.93

type Clipping struct {
	Rect   []float32
	Center []float32
	Start  float32
	Sweep  float32
}

Clipping draws only part of an element and its children. Rect is a box, [top, right, bottom, left], each side a percent of the element's size from its top or left edge. Without Rect, the clip is a slice of a circle about Center, [x, y] percents of the element's size and its middle unless set, through Sweep degrees from Start, as the game draws a cooldown ring. A transition does not ease a clip; draw it again to fill a ring over time.

type Clock added in v0.1.93

type Clock struct {
	Seconds float64
	Up      bool
	Paused  bool
	Format  ClockFormat
	Run     uint32
}

Clock counts a label's time in the player's game, so the mod draws it once and not every second. It starts at Seconds as the player first sees it and counts down to zero, or up when Up is set, unless Paused. A change to any of its fields starts the count again from Seconds; change Run to restart the same clock, such as at each round.

type ClockFormat added in v0.1.93

type ClockFormat string

ClockFormat writes a clock's time: ClockMinutes as "4:05", ClockSeconds as "245" or ClockTenths as "9.4".

const (
	// ClockMinutes writes minutes and seconds, such as "4:05".
	ClockMinutes ClockFormat = "minutes"
	// ClockSeconds writes whole seconds, such as "245".
	ClockSeconds ClockFormat = "seconds"
	// ClockTenths writes seconds and tenths, such as "9.4".
	ClockTenths ClockFormat = "tenths"
)

type Cycle

type Cycle struct {
	// Style is the style the element swings to.
	Style Style
	// Seconds is how long each swing takes.
	Seconds float32
	// Count is how many times it swings, or 0 for as long as it shows.
	Count uint32
}

Cycle swings an element from its style to Style and back, each way taking Seconds, Count times or, with a zero Count, while it shows.

type Decoration

type Decoration string

Decoration draws a line Underline or through (Strike) the text.

type Dropdown struct {
	// Key keeps the dropdown's node in a list while the list changes.
	Key string
	// Class names the dropdown's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the dropdown.
	Style Style
	// Hover is drawn over Style while the pointer is over the dropdown.
	Hover *Style
	// Enter is the style the dropdown starts from when it first shows.
	Enter *Style
	// Exit is the style the dropdown eases to as it leaves.
	Exit *Style
	// Cycle swings the dropdown to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the dropdown.
	Tooltip string
	// Item names an item by class name whose shop card shows over the dropdown.
	Item string
	// Ability names an ability whose window shows over the dropdown.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Measure names the dropdown in the placement reports of FollowPlacement.
	Measure string
	// Disabled makes the dropdown take no changes.
	Disabled bool
	// Options are the choices, in order.
	Options []string
	// Selected is the index of the chosen option.
	Selected int
	// OnChange runs with the index of the option the player picked.
	OnChange func(p mod.Player, index int)
}

Dropdown lets the player pick one of Options; Selected is its index. A disabled dropdown takes no changes.

func (e Dropdown) Render() Node

Render returns the dropdown itself.

type Easing

type Easing string

Easing is a transition's pace: EaseOut, EaseIn, EaseInOut or Linear.

type Edges

type Edges []float32

Edges are distances in pixels: one for every side, [vertical, horizontal], or [top, right, bottom, left]. Nil is unset.

type Entry

type Entry struct {
	// Key keeps the entry's node in a list while the list changes.
	Key string
	// Class names the entry's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the entry.
	Style Style
	// Hover is drawn over Style while the pointer is over the entry.
	Hover *Style
	// Enter is the style the entry starts from when it first shows.
	Enter *Style
	// Exit is the style the entry eases to as it leaves.
	Exit *Style
	// Cycle swings the entry to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the entry.
	Tooltip string
	// Item names an item by class name whose shop card shows over the entry.
	Item string
	// Ability names an ability whose window shows over the entry.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Measure names the entry in the placement reports of FollowPlacement.
	Measure string
	// Disabled makes the entry take no changes.
	Disabled bool
	// Value is the entry's text.
	Value string
	// Placeholder is the faint text the entry shows empty.
	Placeholder string
	// MaxLength is the entry's limit in characters.
	MaxLength uint32
	// OnChange runs with the text the player typed.
	OnChange func(p mod.Player, text string)
}

Entry is a box the player types a line into: Value is its text, Placeholder the faint text it shows empty, and MaxLength its limit in characters, 100 unless set, and at most 240 bytes of text. A disabled entry takes no changes.

func (Entry) Render

func (e Entry) Render() Node

Render returns the entry itself.

type Face

type Face string

Face is one of the game's typefaces: Body its text, Block the capitals of its clock and titles, Serif its menus.

type Flow

type Flow string

Flow places an element's children: Down in a column, Right in a row, and DownWrap or RightWrap in columns or rows that wrap where one is full; unset stacks them.

type Fragment

type Fragment struct {
	// Key keeps the fragment's nodes in a list while the list changes.
	Key string
	// Children are the nodes the fragment holds.
	Children Node
}

Fragment groups children without a panel of its own, and keys a component in a list: ui.Fragment{Key: id, Children: Row{...}}.

func (Fragment) Render

func (f Fragment) Render() Node

Render returns the fragment's children.

type Gradient

type Gradient struct {
	// Shape is the direction the colors run: Down, Right, Up, Left or Radial.
	Shape Shape
	// Colors are the colors in order, as "#rrggbb" or "#rrggbbaa".
	Colors []string
	// At places each color from 0 to 1; a color past its end is spaced evenly.
	At []float32
}

Gradient blends colors across an element in place of its background. The colors run down unless Shape is set; At places each color from 0 to 1, spaced evenly where unset.

type Hero

type Hero struct {
	// Key keeps the hero's node in a list while the list changes.
	Key string
	// Class names the hero's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the hero.
	Style Style
	// Hover is drawn over Style while the pointer is over the hero.
	Hover *Style
	// Enter is the style the hero starts from when it first shows.
	Enter *Style
	// Exit is the style the hero eases to as it leaves.
	Exit *Style
	// Cycle swings the hero to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the hero.
	Tooltip string
	// Item names an item by class name whose shop card shows over the hero.
	Item string
	// Ability names an ability whose window shows over the hero.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Measure names the hero in the placement reports of FollowPlacement.
	Measure string
	// Hero is the hero's id, as Pawn.Hero and mod.Heroes give it.
	Hero uint32
	// Look is which of the game's pictures of the hero to show.
	Look HeroLook
	// Scaling fits the picture into the element's box.
	Scaling Scaling
}

Hero shows a picture of a hero, by the game's hero id.

func (Hero) Render

func (e Hero) Render() Node

Render returns the hero itself.

type HeroLook

type HeroLook string

HeroLook is one of the game's pictures of a hero: Small the square portrait of the kill feed, Card the hero picker's tall card, Icon the round icon, Vertical the hero grid's narrow portrait, TopBar the top bar's portrait and Minimap the minimap icon.

type HudPart

type HudPart string

HudPart is a part of the game's own HUD: LevelUp the notice for each boon, ability point and power increase, OwnHealth the player's health bar, TopBar the bar of team scores, portraits and clock, Ammo the clip ring and count, Souls the souls and level readout, Minimap the minimap, Abilities the ability and active item bar, Status the game's mark in the top-left corner, Stats the weapon, spirit and vitality stats, HeroPicker the screen a player without a hero picks one on, BrokerCountdown the Broker's countdown, MinimapPlayers every player's icon on the minimap, Inventory the purchased items, Crosshair the crosshair with its clip ring, count and stamina pips, CastFailed the notice of an ability the player could not cast, EventIndicators the icons and numbers floated at each event that affects the player, StatusIndicators the event indicators of a crowd control status, KillFeed the feed of kills and other match events, Objectives the health of each team's objectives, Hints the game's tips beside the crosshair, OffscreenAttackers the markers at the screen's edge that point to an enemy out of view, DamagedTarget the badge and health bar of the enemy the player last hurt, DamageReport the report of damage taken and dealt after a death, TestingTools the sandbox's test tools panel, PlaytestNotice the notice over a playtest build's HUD, ShopPrompt the shop's sign and prompt while the player stands at a shop, UnitMarkers the markers with a distance over players and other units, FlexSlotNotice the notice that a flex item slot unlocked, AbilityReminders the reminders under the abilities to hold a key to unlock or upgrade one, and All the whole HUD but the mods' own interfaces, the game's tooltips and its chat.

type Image

type Image struct {
	// Key keeps the image's node in a list while the list changes.
	Key string
	// Class names the image's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the image.
	Style Style
	// Hover is drawn over Style while the pointer is over the image.
	Hover *Style
	// Enter is the style the image starts from when it first shows.
	Enter *Style
	// Exit is the style the image eases to as it leaves.
	Exit *Style
	// Cycle swings the image to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the image.
	Tooltip string
	// Item names an item by class name whose shop card shows over the image.
	Item string
	// Ability names an ability whose window shows over the image.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Measure names the image in the placement reports of FollowPlacement.
	Measure string
	// Src is the image's path in the game's content.
	Src string
	// Scaling fits the picture into the image's box.
	Scaling Scaling
}

Image shows an image from the game's content, such as "file://{images}/hud/icon.png".

func (Image) Render

func (e Image) Render() Node

Render returns the image itself.

type Label

type Label struct {
	// Key keeps the label's node in a list while the list changes.
	Key string
	// Class names the label's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the label.
	Style Style
	// Hover is drawn over Style while the pointer is over the label.
	Hover *Style
	// Enter is the style the label starts from when it first shows.
	Enter *Style
	// Exit is the style the label eases to as it leaves.
	Exit *Style
	// Cycle swings the label to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the label.
	Tooltip string
	// Item names an item by class name whose shop card shows over the label.
	Item string
	// Ability names an ability whose window shows over the label.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Measure names the label in the placement reports of FollowPlacement.
	Measure string
	// Text is the label's text.
	Text string
	// Token names the game's localized text to show in place of Text.
	Token string
	// Variables fill each {s:name} place in Token's text.
	Variables map[string]string
	// Clock counts a time in the player's game.
	Clock *Clock
}

Label shows text: Text, or the game's text for Token in the player's language, with each {s:name} place in it filled from Variables. A Clock's time stands in for Text, or fills Token's {s:clock} place.

func (Label) Render

func (e Label) Render() Node

Render returns the label itself.

type Layout

type Layout struct {
	// Key keeps the layout's node in a list while the list changes.
	Key string
	// Class names the layout's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the layout.
	Style Style
	// Src is the layout's path in the mod's content addon.
	Src string
	// Data is the JSON text the layout's script reads, or "" for none.
	Data string
	// Measure names the layout in the placement reports of FollowPlacement.
	Measure string
	// Bindings set parts of the layout's panels, by each panel's id: at most
	// 64. A layout with bindings takes presses only from the bindings with
	// an OnPress.
	Bindings map[string]Binding
}

Layout loads a layout from the mod's content addon: Src is its path there, such as "shop.xml". The layout keeps the fonts, art and localized strings its author drew, and Bindings set parts of its panels by their ids, so a layout needs no script. Data is the JSON text a layout's own script reads with Modlock.data.

func (Layout) Render

func (e Layout) Render() Node

Render returns the layout itself.

type Length

type Length struct {
	// contains filtered or unexported fields
}

Length is a size: pixels, a percentage of the parent, FitChildren to size to the children, or Fill to share the space left in the parent's flow. The zero Length is unset.

func Percent

func Percent(v float32) Length

Percent returns a length of v percent of the parent.

func Px

func Px(v float32) Length

Px returns a length of v pixels.

type List

type List struct {
	// Key keeps the list's node in a list of elements while that list changes.
	Key string
	// Class names the list's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the list; its height is how much it shows.
	Style Style
	// Measure names the list in the placement reports of FollowPlacement.
	Measure string
	// RowHeight is each row's height in pixels, from 1 to 1000.
	RowHeight float32

	// Row is the template each row is drawn from: a panel, label or image
	// holding at most fifteen more, with no buttons or inputs.
	Row Node
	// Rows are the list's rows, from NewRows. Drawing the same Rows again
	// costs the window, not the rows.
	Rows *Rows
	// Selected is the key of the row the mod draws as chosen, or "" for none.
	Selected string
	// FocusStyle is drawn over a row's style while the player focuses it.
	FocusStyle *Style
	// SelectedStyle is drawn over a row's style while it is Selected.
	SelectedStyle *Style
	// OnChange runs with the key of the row the player chose.
	OnChange func(p mod.Player, key string)
}

List scrolls rows far more numerous than an interface's nodes may be, such as a leaderboard of every player. The mod holds the rows, and the list's node carries only the window of them the player's screen shows, which the screen asks for as the player scrolls. So a list of ten thousand rows costs a draw and the screen what a list of a hundred does. Each row is drawn from the Row template, whose text, images and variables name a row's fields as "{field}".

The player focuses a row with the arrow keys or the controller, and chooses it with Enter, the controller's confirm or a click, which runs OnChange with the row's key. The focus stays on its row as rows come and go. The mod keeps the chosen row and draws it back as Selected, which shows while its row is in the list.

func (List) Render

func (e List) Render() Node

Render returns the list itself.

type Node

type Node interface {
	// Render returns the nodes that stand for this one.
	Render() Node
}

Node is anything an element may hold: an element, Text, Nodes, a Fragment or a component. A component is any other type whose Render returns the nodes that stand for it; an element's Render returns the element itself. A nil Node holds nothing.

type Nodes

type Nodes []Node

Nodes is a list of children. A child with a Key keeps its node while the list around it changes; the rest keep theirs by index.

func (Nodes) Render

func (n Nodes) Render() Node

Render returns the list itself.

type Overflow

type Overflow string

Overflow decides what happens to children that do not fit: Squish shrinks them, Clip cuts them off, Scroll lets the player scroll to them, and Visible draws them outside the element.

type Panel

type Panel struct {
	// Key keeps the panel's node in a list while the list changes.
	Key string
	// Class names the panel's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the panel.
	Style Style
	// Hover is drawn over Style while the pointer is over the panel.
	Hover *Style
	// Enter is the style the panel starts from when it first shows.
	Enter *Style
	// Exit is the style the panel eases to as it leaves.
	Exit *Style
	// Cycle swings the panel to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the panel.
	Tooltip string
	// Item names an item by class name whose shop card shows over the panel.
	Item string
	// Ability names an ability whose window shows over the panel.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Measure names the panel in the placement reports of FollowPlacement.
	Measure string
	// Children are the nodes the panel holds.
	Children Node
}

Panel groups its children.

func (Panel) Render

func (e Panel) Render() Node

Render returns the panel itself.

type Placement

type Placement struct {
	// Screen is the whole screen, at 0, 0.
	Screen *mod.Bounds
	// Hud is the HUD's frame: the screen, or the middle 16:9 of a wider
	// screen whose player keeps the HUD there.
	Hud *mod.Bounds
	// Measured holds the box of each element whose Measure names it, once
	// the screen has laid it out.
	Measured map[string]*mod.Bounds
}

Placement is where a player's screen places the interface, in layout units from the screen's top left, where the screen is 1080 units tall.

type Range

type Range struct {
	// Key keeps the range's node in a list while the list changes.
	Key string
	// Class names the range's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the range.
	Style Style
	// Hover is drawn over Style while the pointer is over the range.
	Hover *Style
	// Enter is the style the range starts from when it first shows.
	Enter *Style
	// Exit is the style the range eases to as it leaves.
	Exit *Style
	// Cycle swings the range to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the range.
	Tooltip string
	// Item names an item by class name whose shop card shows over the range.
	Item string
	// Ability names an ability whose window shows over the range.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Measure names the range in the placement reports of FollowPlacement.
	Measure string
	// Disabled makes the range take no changes.
	Disabled bool
	// Handles are the handles in track order, their values non-decreasing.
	Handles []RangeHandle
	// Min is the least number; with Max also 0 the range is 0 to 1.
	Min float32
	// Max is the greatest number.
	Max float32
	// Step is the distance between the stops, or 0 for none.
	Step float32
	// OnChange runs with every handle's value, in order, when the player lets
	// go of a handle.
	OnChange func(p mod.Player, values []float32)
	// OnHold runs as the player grabs a handle, lets it go, or loses it to a
	// stock overlay, with the handle's name.
	OnHold func(p mod.Player, handle string, phase mod.ActionPhase)
	// OnMove runs with every handle's value, in order, while the player drags
	// a handle, at most ten times a second, so the mod can preview where the
	// hold would land. A mod that previews shows its own values again when
	// OnHold hears the hold cancelled.
	OnMove func(p mod.Player, values []float32)
}

Range is a track with one to eight named handles the player drags, such as a minimum, a favored value and a maximum, each a number from Min to Max, 0 to 1 unless set, stopping at each Step when Step is set. The handles keep their order: a handle stops at its neighbors. While the player holds a handle a redraw leaves the handles where the player has them, and letting go reports every value. Left and right step the active handle from the keyboard or a controller, confirm makes the next handle active, and each step reports every value at once, as a release. A disabled range takes no changes. Changing the handles' names draws a new range.

func (Range) Render

func (e Range) Render() Node

Render returns the range itself.

type RangeHandle

type RangeHandle struct {
	// Name names the handle in the range's reports.
	Name string
	// Value is where the handle sits on the track.
	Value float32
}

RangeHandle is one handle of a range: its name, 1 to 64 letters, digits, '_', '-' or '.', distinct within the range, and its value.

type Row

type Row struct {
	// Key names the row, 1 to 64 bytes.
	Key string
	// Rank orders the rows, least first.
	Rank float64
	// Sort orders the rows of one rank, as text.
	Sort string
	// Fields are what the template's "{field}" names show, at most sixteen,
	// each named by letters, digits and '_'.
	Fields map[string]string
}

Row is one row of a List.

type Rows

type Rows struct {
	// contains filtered or unexported fields
}

Rows are a list's rows in order, which a List draws. A Rows does not change; to change a list's rows, draw it with new Rows.

func NewRows

func NewRows(rows ...Row) *Rows

NewRows orders rows by Rank, then Sort, then Key, keeping the last row of each key. The host takes at most 20,000 rows in a list. Rows already in that order with no key twice are kept as they are, so ordering them costs one pass.

func (*Rows) Len

func (r *Rows) Len() int

Len returns how many rows there are.

type Scaling

type Scaling string

Scaling fits a picture into its element's box: Fit shows it whole, Cover fills the box and crops, Stretch fills the box and stretches, FitWidth and FitHeight fit one side, and None draws it at its own size.

type Shadow

type Shadow struct {
	// X offsets the shadow across, in pixels.
	X float32
	// Y offsets the shadow down, in pixels.
	Y float32
	// Blur softens the shadow, in pixels.
	Blur float32
	// Spread grows a box's shadow or strengthens a text shadow.
	Spread float32
	// Color is the shadow's color, as "#rrggbb" or "#rrggbbaa".
	Color string
	// Inset draws a box's shadow inside its edge.
	Inset bool
}

Shadow is a soft shadow, offset by X and Y and softened by Blur, in pixels. Spread grows a box's shadow in pixels, or strengthens a text shadow, where 0 draws it at full strength; Inset draws a box's shadow inside its edge.

type Shape

type Shape string

Shape is the direction a gradient's colors run: Down, Right, Up, Left or Radial.

type ShownAbility

type ShownAbility struct {
	// Name is the ability's class name, whose window the game shows over it.
	Name string
	// Image is its picture, a path in the game's content as an image's src.
	Image string
	// Upgrades holds its bought tiers as Ability.Upgrades: bit 0 unlocks it.
	Upgrades uint32
}

ShownAbility is the ability AbilityDisplay shows in one slot.

type Slider

type Slider struct {
	// Key keeps the slider's node in a list while the list changes.
	Key string
	// Class names the slider's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the slider.
	Style Style
	// Hover is drawn over Style while the pointer is over the slider.
	Hover *Style
	// Enter is the style the slider starts from when it first shows.
	Enter *Style
	// Exit is the style the slider eases to as it leaves.
	Exit *Style
	// Cycle swings the slider to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the slider.
	Tooltip string
	// Item names an item by class name whose shop card shows over the slider.
	Item string
	// Ability names an ability whose window shows over the slider.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Measure names the slider in the placement reports of FollowPlacement.
	Measure string
	// Disabled makes the slider take no changes.
	Disabled bool
	// Value is the slider's number.
	Value float32
	// Min is the least number; with Max also 0 the range is 0 to 1.
	Min float32
	// Max is the greatest number.
	Max float32
	// Step is the distance between the stops, or 0 for none.
	Step float32
	// OnChange runs with the number the player dragged to.
	OnChange func(p mod.Player, value float32)
	// OnWheel receives one wheel step and its pointer anchor while enabled.
	OnWheel func(p mod.Player, wheel *mod.Wheel)
}

Slider is a bar the player drags to a number from Min to Max, 0 to 1 unless set, stopping at each Step when Step is set. A disabled slider takes no changes.

func (Slider) Render

func (e Slider) Render() Node

Render returns the slider itself.

type Style

type Style struct {
	// Width sizes the element across.
	Width Length
	// Height sizes the element down.
	Height Length
	// MinWidth is the least the element's width may shrink to.
	MinWidth Length
	// MaxWidth is the most the element's width may grow to.
	MaxWidth Length
	// MinHeight is the least the element's height may shrink to.
	MinHeight Length
	// MaxHeight is the most the element's height may grow to.
	MaxHeight Length
	// Flow places the children in a column or a row, or in columns or rows
	// that wrap where one is full; unset stacks them.
	Flow Flow
	// X places the element across from its parent's left edge, in pixels or a
	// percent of the parent, outside the parent's flow.
	X Length
	// Y places the element down from its parent's top edge, as X does across.
	Y Length
	// ZIndex draws the element above its siblings with a lower index.
	ZIndex int32
	// Overflow decides what children that do not fit do, across and down.
	Overflow Overflow
	// OverflowX sets Overflow across.
	OverflowX Overflow
	// OverflowY sets Overflow down.
	OverflowY Overflow
	// HorizontalAlign places the element across: Left, Center or Right.
	HorizontalAlign Align
	// VerticalAlign places the element down: Top, Center or Bottom.
	VerticalAlign Align
	// Margin is the space outside the element's edge, as Edges takes it.
	Margin Edges
	// Padding is the space inside the element's edge, as Edges takes it.
	Padding Edges
	// Background fills the element.
	Background string
	// Color colors the text.
	Color string
	// FontSize is the text's size in pixels.
	FontSize float32
	// Bold sets the text bold.
	Bold bool
	// TextAlign aligns the text: Left, Center or Right.
	TextAlign Align
	// BorderRadius rounds the corners, in pixels.
	BorderRadius float32
	// Opacity fades the element and its children, from 0 to 1.
	Opacity *float32
	// Face is one of the game's typefaces: Body, Block or Serif.
	Face Face
	// Uppercase sets the text in capitals.
	Uppercase bool
	// LetterSpacing widens the space between letters, in pixels.
	LetterSpacing float32
	// Shadow draws a soft drop shadow under the text, to read over the world.
	Shadow bool
	// TextShadow draws this shadow under the text in place of Shadow's.
	TextShadow *Shadow
	// BorderWidth and BorderColor draw a line around the element's edge; it
	// shows only when both are set.
	BorderWidth float32
	// BorderColor is the color of the border.
	BorderColor string
	// Gradient fills the element in place of its background.
	Gradient *Gradient
	// BoxShadow draws a shadow around or inside the element's box.
	BoxShadow *Shadow
	// Tint washes the element and its children with a color.
	Tint string
	// Saturation scales the colors' saturation; 1 leaves them.
	Saturation *float32
	// Brightness scales the colors' brightness; 1 leaves them.
	Brightness *float32
	// Contrast scales the colors' contrast; 1 leaves them.
	Contrast *float32
	// Blur blurs the element and its children by a radius in pixels.
	Blur float32
	// Italic sets the text in italics.
	Italic bool
	// Weight sets the text's weight in place of Bold.
	Weight Weight
	// LineHeight is the height of each line of text, in pixels.
	LineHeight float32
	// NoWrap keeps the text on one line.
	NoWrap bool
	// TextOverflow ends text that does not fit.
	TextOverflow TextOverflow
	// Decoration draws a line under or through the text.
	Decoration Decoration
	// Translate moves the element as drawn by [x, y] pixels.
	Translate []float32
	// Scale scales the element as drawn: one factor, or [x, y].
	Scale []float32
	// Rotate turns the element clockwise, in degrees.
	Rotate float32
	// Turn turns the element clockwise, in degrees, before its other
	// transforms. A transition eases the angle itself, so a turn from 0 to
	// 720 spins twice, where Rotate eases the shortest way round.
	Turn float32
	// Clip draws only part of the element and its children.
	Clip *Clipping
	// Origin is the point the element scales and turns about, as [x, y]
	// percents of its size; unset is its center.
	Origin []float32
	// Transition animates each change of the style.
	Transition *Transition
}

Style lays out and paints an element. Colors are "#rrggbb" or "#rrggbbaa". A zero field is unset, except where zero means something on the wire: the pointer fields, and the slices and Lengths, which are unset only when nil or zero.

func (Style) Merge

func (s Style) Merge(over Style) Style

Merge returns s with each field over sets in its place, as a later style overrides an earlier one.

type Text

type Text string

Text is a label of plain text.

func (Text) Render

func (t Text) Render() Node

Render returns the text itself.

type TextOverflow

type TextOverflow string

TextOverflow ends text that does not fit with an Ellipsis, Shrinks it until it fits, or Clips it at the edge.

type Timeline

type Timeline struct {
	// Game makes the timeline follow the game clock.
	Game bool
	// Steps lists the timed presentation changes.
	Steps []TimelineStep
}

Timeline is a timed presentation. Its steps run on the player's own time, or, with Game set, hold while the game is paused.

type TimelineStep

type TimelineStep struct {
	// At is the offset in seconds from the start.
	At float32
	// Measure selects the elements this step changes.
	Measure string
	// Class adds classes from the mod style sheets.
	Class string
	// Style overlays the selected elements.
	Style *Style
	// Sound plays the named game sound event.
	Sound string
	// Seconds bounds the sound duration when nonzero.
	Seconds float32
}

TimelineStep is one moment of a timeline, At seconds from its start, 0 to 60. From then on the elements whose Measure the step names take its look: Class adds classes from the mod's sheets, separated by spaces, and Style is laid over each element's own, setting, as a hover does, only what the element's style sets or what has a resting value. A step's look replaces the look an earlier step gave the same measure. Sound plays the game's sound event, cut after Seconds unless Seconds is zero.

type Toggle

type Toggle struct {
	// Key keeps the toggle's node in a list while the list changes.
	Key string
	// Class names the toggle's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the toggle.
	Style Style
	// Hover is drawn over Style while the pointer is over the toggle.
	Hover *Style
	// Enter is the style the toggle starts from when it first shows.
	Enter *Style
	// Exit is the style the toggle eases to as it leaves.
	Exit *Style
	// Cycle swings the toggle to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the toggle.
	Tooltip string
	// Item names an item by class name whose shop card shows over the toggle.
	Item string
	// Ability names an ability whose window shows over the toggle.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Measure names the toggle in the placement reports of FollowPlacement.
	Measure string
	// Disabled makes the toggle take no changes.
	Disabled bool
	// Text labels the toggle.
	Text string
	// On checks the box.
	On bool
	// OnChange runs with whether the player checked the box.
	OnChange func(p mod.Player, on bool)
}

Toggle is a box the player checks, labeled by Text. A disabled toggle takes no changes.

func (Toggle) Render

func (e Toggle) Render() Node

Render returns the toggle itself.

type Transition

type Transition struct {
	// Seconds is how long each change takes.
	Seconds float32
	// Delay is how long each change waits before it starts, in seconds.
	Delay float32
	// Easing is EaseOut, EaseIn, EaseInOut or Linear.
	Easing Easing
	// Curve shapes the change in place of Easing as a cubic Bezier curve's
	// two control points, [x1, y1, x2, y2], as CSS's cubic-bezier: each x is a
	// share of the time from 0 to 1, and a y outside 0 to 1 overshoots.
	Curve []float32
}

Transition animates each change of an element's style, and the move to its hover style and back, over Seconds after Delay. Easing is EaseOut unless set.

type Weight

type Weight string

Weight sets text's weight in place of Bold: Thin, Light, Normal, Medium, SemiBold, Bold or Black.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL