Skip to content

HUD layout and places ​

The HUD is a list of parts (widgets), each at a named place. You add your own, move or hide the client's, or draw one in the client's place.

By default the console is centred at the bottom: three frames standing apart, the minimap with its buttons in its frame, what is selected (or the hero's panel), and the command card, about 1,330 of the HUD's 1,600 pixels wide, with the world showing on both sides. Across the top hang three plaques: the menu, the quests, the log and the title on the left, the clock in a crest in the middle, what the player has and the buttons on the right. Every frame is cast in the skin's metal (see Skins). hud: { console: 'corners' } puts the minimap and the card in the bottom corners, on a band across the screen.

Quick start ​

tsx
hud: {
	hide: ['clock', 'layoutButton'],
	widgets: [
		// your own, in the top bar: after the resources, before the frames a second
		{ id: 'td.mana', place: 'top-bar-right', order: 15, component: (props) => <Mana client={props.client} /> },
		// a column over the map, shown while there is a wave
		{ id: 'td.waves', place: 'top', when: (client) => !!client.ui.status().length, mount: (element, client) => drawWaves(element, client) },
		// any HTML in the place of the client's minimap
		{ id: 'minimap', mount: (element, client) => drawMyMinimap(element, client) },
		// wrap the client's command card
		{ id: 'card', component: (props) => <MyFrame title='Orders'>{props.children}</MyFrame> },
		// move the clock to the top left, beside the title
		{ id: 'clock', place: 'top-bar-left', order: 5 }
	]
}

A widget with a new id is added. One with the id of a client's part changes that part. See also How do I add a HUD part.

Common tasks ​

Add a part while the game runs ​

client.hud.widgets.add(widget) returns what takes it away. client.hud.hide(widget, hidden) hides or shows one.

ts
const remove = client.hud.widgets.add({ id: 'td.boss', place: 'top', component: BossBar })

Show a part only sometimes ​

when is read as a signal. For a client's part, both its own when and yours must hold.

ts
{ id: 'td.sell', place: 'bottom-right', when: (client) => client.ui.selection().length > 0, component: SellButton }

Give heroes the command card ​

The hero panel replaces the selection sheet for a hero. To give heroes the card like any unit:

ts
hud: {
	widgets: [{ id: 'heroPanel', when: () => false }]
}

Show lines and buttons of your game ​

The rules report plain data to each player; the view turns it into status lines and buttons:

ts
// in the Rules: what each player is told, every tick
report: (world, player) => ({ wave: waveOf(world), lives: world.player(player).resources.lives })

// in the GameView
status: (report) => [{ text: `Wave ${report.wave}` }],
actions: [{ id: 'next', label: 'Next wave', command: nextWave.make({}), enabled: (report) => report.waiting === true }]

enabled is only the look: the simulation decides, as with any command. visible leaves a button off where it means nothing.

Lay the console out centred or in the corners ​

ts
hud: {
	console: 'corners'
} // 'centered' when left out
client.hud.setConsole('centered') // while the game runs; client.hud.console() reads it

The parts placed by the console follow it: the minimap's buttons, the control groups, the chat, the objectives, the lock, the dialog box. The HUD's element says which (data-hud-console="centered"), for your styles.

Move the HUD's places ​

The places are named sizes in HUD pixels (a 1600 by 900 layout):

ts
hud: {
	places: {
		consoleWidth: 1100
	}
}
client.hud.setPlaces({ minimapWidth: 260 })
hud: {
	places: {
		cardFrame: 46
	}
} // a card in a frame of yours 20 pixels thicker across and down than the client's

Each is a CSS variable on the HUD (--vg-hud-console-width, --vg-hud-bottom-bar) for your own parts to line up with. The console's geometry is there too, worked out from them: --vg-hud-console-start and --vg-hud-console-end (its edges, 0 in the corners), --vg-hud-console-height, --vg-hud-above-console (where what floats over it starts), --vg-hud-minimap-start, --vg-hud-minimap-buttons-start, --vg-hud-middle-start and --vg-hud-middle-end (the room between the minimap and the card), --vg-hud-card-width, --vg-hud-card-height.

Set the title ​

GameView.hud.title is words, a name with a line under it, or a function of the client asked each frame. In code: client.hud.setTitle(). With nothing said, it is the scene's name.

Change the minimap ​

ts
hud: { minimap: { resolution: 8, smooth: false, size: 260, dotsEvery: 0 } }
client.hud.setMinimap({ size: 260 })

Draw layers of your own on it (zones, lanes, capture points):

ts
const remove = client.hud.addMinimapLayer({
	id: 'td.zones',
	at: 'ground', // 'ground' under the dots and fog, 'units' with the dots, 'over' above the fog
	draw: (context, frame) => {
		const at = frame.toMap(40, 60) // { x, y } in the minimap's pixels
		context.fillRect(at.x, at.y, 8 * frame.scale.x, 8 * frame.scale.y)
	}
})

Listen to what happens ​

client.hud.on(name, listener) returns what stops it. Events are worked out only while someone listens.

ts
const stop = client.hud.on('heroLevel', ({ name, level }) => toast(`${name} reached level ${level}`))
client.hud.emit('supplyCapped', { used: 10, cap: 10 }) // fake one, to try your HUD

Follow the HUD's state from React, Vue or plain JS ​

ts
const now = client.ui.snapshot() // everything the HUD shows, as plain data
const stop = client.ui.watch(
	() => client.ui.selection(),
	(selection) => draw(selection)
)

A React component subscribes with watch and keeps what it is told (useSyncExternalStore(subscribe, snapshot)). Controllers work the same: watch(saves.list, redraw).

Build your own HUD from the pieces ​

Turn the HUD off (launch({ hud: false })) and compose your own from @v12-engine/client/hud:

tsx
import { Bar, Slot, useHud } from '@v12-engine/client/hud'

function MyHeroBar(props: { client: HudClient }) {
	const hud = useHud(props.client)
	return (
		<Show when={hud.hero()}>
			{(hero) => (
				<>
					<Bar value={hero().health} max={hero().maxHealth} tone='health-auto' size='md' label={`${hero().health}`} />
					<For each={hero().abilities}>{(slot) => <Slot name={slot.name} icon={slot.icon} hotkey={slot.key} cooldown={slot.cooldown} />}</For>
				</>
			)}
		</Show>
	)
}

Let the player move parts ​

Every part is a section the player moves, scales, folds and locks in the layout mode (Alt+Shift+L, or Alt and a drag). The layout is kept for the next game of the same kind.

ts
hud: { layout: { minimap: { locked: true, dx: 20 } } } // or (id) => ({ movable: id !== 'card' })
client.layout.get('minimap'); client.layout.lock('minimap'); client.layout.reset()

Scale the HUD ​

The HUD is laid out for 1600 by 900 and scaled to the screen (0.7 to 1.4). GameView.hud.scale is a number or a function of the screen size; client.hud.scale() reads it, client.hud.setScale(size) sets the player's size.

Add data to the HUD model ​

Add a slot by declaration merging, fill it with a describer, draw it with a part that reads client.ui.slot('waves'):

ts
declare module '@v12-engine/client' {
	interface HudModelSlots {
		waves: { next: number }
	}
}
hud: {
	describe: {
		waves: (context) => ({ next: nextWave(context.state) })
	}
}

Reference ​

Places ​

Widgets in a place stand in a row or column by order (the client's at 10, 20, 30…; yours without an order after them).

PlaceWhereThe client's parts there
top-bar-leftthe left plaquemenu, quests, log, title
top-bar-center, top-bar-rightthe crest in the middle, the right plaqueclock; resources, fps, allies, chat, sound, settings
traybuttons under the right plaquefull screen, stats, quick cast, shortcuts, layout, debug panel, saves, leave
sidedown the leftheroes, idle workers
bottom-bar-center, bottom-bar-rightthe console's middle and rightthe selection; the card
top, top-left, top-right, left, right, center, bottom, bottom-left, bottom-rightcolumns over the map, clear of the HUD(yours: capture points at top)
over-mapanywhere over the map (the part's style)minimap, messages, chat, objectives, lock, hero panel, shop
backdropunder the HUD, over the viewthe screen fade
overlayover everything, also while the HUD is hiddendialog, choice, menu, score, ping wheel

Sizes (HudPlaces) ​

NameDefaultWhat
consoleWidth1330the centred console's width
cardFrame25the card's padding and border, added to its keys (52, gaps of 5) across and down
minimapWidth218the minimap with its line; its frame and its buttons are around it
bottomBar170the bottom band's height (corners)
bottomBarEdge118its edge (corners)
aboveBottomBar262where messages and objectives float (corners)
aboveCard240the lock over the card (over the centred console's top at least)
cornerWidth230where the top bar ends; the top-right column stands left of it

A widget (HudWidgetDef) ​

FieldWhat
idnew, or the id of a client's part to change it
placea HudPlace
orderposition among the others in the place
componenta Solid component, given { client, widget } (and the client's part as children)
mount(element, client) => dispose: any HTML
when(client) => boolean, read as a signal
sectionwhether the player can move it
styleCSS for its element (where an over-map part goes)

The client's parts (HudWidget, all in HUD_WIDGETS): clock, status, resources, allies, saves, layoutButton, layout, debugButton, leave, fullscreen, sound, quickCast, legend, stats, heroes, debug, messages, chat, lock, minimap, idle, groups, outcome, objectives, timers, selection, card, heroPanel, shop, console, dialog, choice, cinematic, fade, menu, menuButton, connection, paused, pingWheel, topBar (with objectivesButton, title, perf, chatButton, settingsButton, legendButton), log, logButton, minimapButtons, photo, score.

  • objectives: an objective with more to say opens under itself (ObjectiveDef.detail).
  • timers: the rules' timers shown to a player, counted down at the top (world.timers.show(player, id, { label })).
  • log: what was said on screen and in chat (client.ui.log(), pushLog, setLogOpen).
  • minimapButtons: ping where the view looks, ground on or off, dots by side, formation (MinimapLook.terrain, allyColors). A column at the map's right, in the minimap's frame; hidden, the frame is only as wide as the map.
  • console: what the HUD stands on: nothing in the centred console (its frames stand on the map), a band across the bottom in the corners.
  • selection, heroPanel: in the room between the minimap and the card, up to 800 wide. The hero's panel: its stats in a well, its face in a ring of the metal with its experience and level, standing out of the frame's top, what it can do over its health and mana, what it carries in a well; its buffs over the frame's left. One unit alone: its face in a square of the metal with its health under it, its name, bars and stats, and a well with what it carries or trains and its effects. A group: a tile each, eight to a row, the subgroups' chips over them.

Skins ​

The HUD's frames are cast in a metal: the minimap's, the card's, the panels', the plaques', the keys' edges, the portrait's ring, with an ornament on each corner and a gem under the clock. A skin is a theme (see Theme tokens) that says the metal (metal-light, metal, metal-dark), the face behind the frames and its grain (frame-face, texture), the keys' letters (key-letter), the gem (gem) and the corners' ornament (ornament, a CSS clip-path). The client has four (skins):

SkinMetalGemOrnament
gildedgold (the default)bluediamond
irondark ironredclaw
boneold bonegreenstar
jadegreen bronzevioletleaf

A race names one as its look, so the HUD is in the metal of the side its player plays:

ts
races: { undead: { theme: 'bone' }, orcs: { theme: 'iron' } }

A theme of your own takes one as its base: registerTheme('restless', { accent: '#9ccf6a' }, 'bone'). The classes are there for your own parts too: vg-frame (a frame, with Corners inside it for the ornaments), vg-well, vg-tile (its colour --vg-tint), vg-plate (a button), vg-trough (a bar), vg-level (a level's coin), vg-key-letter, vg-metal-fill.

HUD events (client.hud.on) ​

EventPayloadWhen
selection{ ids }who is selected changed
subgroup{ type }the type the card is about changed (Tab, a chip)
heroLevel{ hero, name, level }a hero reached a level
heroDied{ hero, name }a hero fell
heroRevived{ hero, name }a hero came back
points{ hero, name, points }a hero has points to spend
abilityReady{ hero, ability, name }an ability of the shown hero came off cooldown
resources{ amounts }what the player has changed
supplyCapped{ used, cap }supply ran out (once, until free again)
idleWorkers{ count }the idle worker count changed
dayPhase{ night }night fell or day broke

In a Solid component, onHudEvent(client, name, listener) listens for as long as the component lives.

What a part is given: HudClient ​

Every part gets a HudClient (client.forHud()), not the whole client: the HUD's state (ui), the player's hands (controller, a PlayerActions: select, press a card button, control groups, items, the shop, chat, give), registry, playerId, tickRate, checkpoint, debug (HudSession), state, keys, settings, menus, saves, and where the game is played (menu.scene()). It has no renderer and no world. A line of the pause menu, which is your game's code, gets a GameClientApi.

useHud(client) ​

Gives the model's signals and what is worked out of them: focus() ('hero', 'unit', 'group' or 'none'), subgroups(), activeSubgroup(), title(), clock(), and the moves pickSubgroup(type) and select(ids).

The pieces (@v12-engine/client/hud) ​

The client's HUD is made of pieces that only know their props: Frame, Bar and Ring (health, mana, experience, a shield, marks, words), Slot (an ability or item key: picture, key, cost, charges, cooldown, learn level), StatGrid, BuffRow, UnitTile, Chips, KeyButton, SquareButton, Badge, and their classes (frame, faceButton, badge). Pictures are glyphs by name: registerGlyph(name, component) adds or replaces one, and your IconSet pictures (units, commands, abilities, items, buffs) always come first.

The widgets are given out too, each taking { client }: Hud, CommandCard, SelectionPanel, Minimap, Resources, Status, Clock, Allies, Chat, Groups, Heroes, HeroPanel, ShopWindow, Legend, Objectives, OutcomeWidget, Saves, PauseMenuScreen, DialogWidget, ConnectionBanner, PausedBanner, Fullscreen, Mute, QuickCast, FrameStats, TopBar; WidgetFrame wraps one of yours as the client wraps its own; clientWidgets, HudWidgets, WidgetsAt draw the client's list at a place.

The HUD model ​

The model has a core (selection, card, resources, objectives, mode, control groups) and slots features fill (HudModelSlots, read with client.ui.slot(name)). The heroes' slots (hero, heroes, shop) come from heroesViewPack() (GameView.packs). A describer gets HudDescribeContext (the state, session, selection, words, keys); client.hud.describe(slot, describer) adds one in code. A pack (ViewPack: id, describe, words) brings its own.

Words for what a unit is doing (Training {item}, Idle) are HudWords: the client's (HUD_WORDS), the packs', then yours (GameView.hud.words: { idle: 'Resting', orders: { move: 'Marching' } }). GameView.hud.activity(entity) decides them in code.

The top bar ​

topBar holds the menu and quests buttons, the title, the clock (time, day or night, and what comes next, ClockInfo.next), resources (with supply and upkeep), perf (fps and ping), and buttons for allies, chat, sound and settings. Its places are top-bar-left, top-bar-center, top-bar-right.

It is three plaques hanging from the top, centred console or not: top-bar-left on a plaque at the left whose end is cut on a slant, top-bar-center (the clock) in a crest hanging from the middle with the skin's gem under it, top-bar-right on a plaque at the right. A plaque with nothing on it is not drawn. The objectives open under the tray at the top right.

The minimap (MinimapLook) ​

FieldWhat
resolutionpixels a cell (enough for about 512 a side by default)
smoothsmoothing
sizeits size; parts beside it move with it unless places.minimapWidth says
entityhow an entity's dot looks
drawone picture of yours over everything
dotsEveryseconds between dot updates (0.1; 0 every frame)
layersMinimapLayers: id, at, draw(context, frame)

It draws the ground once, then only what changed: fog when a cell changed, dots ten times a second, the camera corners as the view moves. The capture points are a layer (captureMinimapLayer()).

The score screen ​

The part score shows the game's score by category and a graph over time. It opens from the end screen, the pause menu's Score line, or client.score.show(tab). Declared: GameView.hud.score = { atEnd: 'open', menu: false, labels, format, graph, hide: ['combat'] }. Build your own from Score, ScoreBoard, ScoreTable, ScoreGraph.

The debug panel ​

The part debug (and debugButton) shows where debug tools are allowed (launch({ debug: true }), a server that allows it: client.debugTools.allowed). Alt+Shift+D opens it. It holds the game speed, switches, numbers and lists (client.debugTools.toggles, numbers, choices), windows (Entities, Inspect, Events, Console, Score), the spawn tool, the effects tool (Effects), your buttons (debugTools.actions) and the tick.

ts
hud: { debug: { open: true, hide: ['spawn'], hideItems: ['ink'] } } // sections: DEBUG_PANEL_SECTIONS
client.hud.showDebug(); client.hud.showDebug(false); client.hud.debugShown()

Its code (@v12-engine/client/debug: DebugPanel, Entities, Inspector, EventLog, ConsoleWindow, AiTab, LogConsole, PerfList, StatsWindow) loads the first time it is drawn.

Debug views (client.debugView(kind), one at a time, null for none; client.debugTools.view): wireframe, cascades (what each shadow part covers), navmesh (only where the simulation runs in the page), overdraw, detail (level of detail, DETAIL_COLORS), pick (what a click takes), fog. They change only this screen.

When a frame fails ​

What the view runs each frame (renderers, framePhases, hud.status, plates, floats, bars, lighting, input.cursor, hud.cardButtons, hud.editCard, its on listeners) runs guarded: one that throws is logged once (category view) and skipped from then on (client.guard.failed). Anything else that throws stops the client and shows the error screen: see Loading and error screens.

Abilities in tooltips ​

An ability's tooltip shows its numbers for the caster now (AbilityDef.values, describe; see Abilities). GameView.hud.abilityTip(tip, caster, client) changes it or draws your own.