Skip to content

Your own HUD ​

Start from the client's HUD and change as much as you need: its look, one part, several parts, or all of it. Each step below goes further than the one before; most games stop at the second or third.

tsx
// in src/view.ts
export const view: GameView = {
	hud: {
		theme: 'bone',
		console: 'corners',
		hide: ['layoutButton', 'legendButton'],
		widgets: [
			{ id: 'my.lives', place: 'top-bar-right', order: 5, component: (props) => <Lives client={props.client} /> },
			{ id: 'card', component: (props) => <MyFrame title='Orders'>{props.children}</MyFrame> }
		]
	}
}

The HUD is cast in bone, the minimap and card sit in the corners, two buttons are gone, your lives counter stands first among the resources, and the command card wears your frame.

1. Change the look, keep every part ​

ts
hud: {
	theme: 'iron', // a skin: 'gilded' (default), 'iron', 'bone', 'jade', or your own
	console: 'corners', // 'centered' (default): the minimap, the selection and the card as one console
	places: { consoleWidth: 1100, minimapWidth: 240 }, // sizes in HUD pixels of a 1600 × 900 layout
	scale: (screen) => (screen.width < 1400 ? 0.85 : 1),
	title: 'Chapter One: The Pass'
}

A race can name its skin (races: { undead: { theme: 'bone' } }), so the HUD wears the metal of the side its player plays. Your own skin: registerTheme('ember', { accent: '#e8743b' }, 'iron'). See Skins.

2. Hide parts, move parts ​

ts
hud: {
	hide: ['clock', 'idle', 'groups'],
	widgets: [{ id: 'minimap', place: 'over-map', style: { left: '12px', bottom: '12px' } }]
}

A widget with the id of one of the client's parts changes that part: its place, order, when or style. The parts' ids are in HUD_WIDGETS; the places are in HUD layout and places. In code, while the game runs: client.hud.hide('clock', true).

Show a part only sometimes ​

ts
{ id: 'groups', when: (client) => client.ui.selection().length > 1 }

when is read as a signal: the part comes and goes as the answer changes. For a client's part, both its own when and yours must hold.

3. Add parts of your own ​

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

/** A boss bar at the top of the screen while the boss lives */
const bossBar: HudWidgetDef = {
	id: 'my.bossBar',
	place: 'top',
	when: (client) => !!client.ui.slot('boss'),
	component: (props) => {
		const boss = () => props.client.ui.slot('boss')!
		return <Bar value={boss().health} max={boss().maxHealth} tone='health-auto' size='md' label={boss().name} />
	}
}

The data comes from a slot of the HUD model. A describer fills it from what the player's client knows (HudDescribeContext: the state, the selection, the words), and the HUD asks it again as that changes:

ts
declare module '@v12-engine/client' {
	interface HudModelSlots {
		boss: { name: string; health: number; maxHealth: number } | undefined
	}
}

hud: {
	widgets: [bossBar],
	describe: {
		boss: (context) => {
			const boss = [...context.state.entities.values()].find((entity) => entity.type === 'warlord')
			return boss && { name: 'Varga', health: boss.health, maxHealth: boss.maxHealth ?? boss.health }
		}
	}
}

Or plain HTML, with no Solid at all. Here the slot is filled from what the rules report to each player (Rules.report):

ts
// in the rules: plain data each player is sent
report: (world) => ({ wave: waveOf(world) })

// in the view
declare module '@v12-engine/client' {
	interface HudModelSlots {
		wave: number
	}
}
hud: {
	describe: { wave: (context) => Number(context.state.report.wave ?? 0) },
	widgets: [
		{
			id: 'my.waves',
			place: 'top-right',
			mount(element, client) {
				const draw = (wave: number | undefined) => (element.textContent = `Wave ${wave ?? 0}`)
				draw(client.ui.slot('wave'))
				return client.ui.watch(() => client.ui.slot('wave'), draw)
			}
		}
	]
}

mount returns what takes it away. In React, use useSyncExternalStore over client.ui.watch and client.ui.snapshot.

4. Replace a part, keep its behaviour ​

Draw a part your own way and keep what it does, by giving the client's part as children:

tsx
{ id: 'minimap', component: (props) => <OrnateFrame>{props.children}</OrnateFrame> } // wrap it
{ id: 'card', mount: (element, client) => drawMyCard(element, client) } // or draw it yourself

To draw the command card yourself, read its buttons from client.ui.commands() and press them with client.controller (a PlayerActions): what the player may do is still the game's to decide.

5. Replace the whole HUD ​

Hide the client's console and draw yours in its places. Keep the overlays (dialog, the end screen, the pause menu), which you rarely want to rewrite:

tsx
import { CommandCard, Minimap, Resources, useHud } from '@v12-engine/client/hud'

const CONSOLE = ['console', 'minimap', 'minimapButtons', 'selection', 'heroPanel', 'card', 'groups', 'idle', 'heroes', 'topBar']

function MyConsole(props: { client: HudClient }) {
	const hud = useHud(props.client)
	return (
		<div class='my-console'>
			<Minimap client={props.client} />
			<div class='my-middle'>
				<Show when={hud.focus() !== 'none'} fallback={<span>Nothing selected</span>}>
					<span>{props.client.ui.selection().length} selected</span>
				</Show>
				<Resources client={props.client} />
			</div>
			<CommandCard client={props.client} />
		</div>
	)
}

hud: {
	hide: CONSOLE,
	widgets: [{ id: 'my.console', place: 'bottom', component: (props) => <MyConsole client={props.client} /> }]
}

The pieces (Bar, Ring, Slot, StatGrid, BuffRow, UnitTile, Chips) and the client's widgets (CommandCard, Minimap, SelectionPanel, HeroPanel, Resources, Objectives…) only know their props, so you can mix yours with the client's.

No HUD at all ​

For a single game on a page, launch({ hud: false }) draws no HUD; build everything from client.ui (the model) and client.controller (the player's hands). Inside an app of scenes, hide every part instead:

ts
hud: { hide: HUD_WIDGETS.filter((id) => !['dialog', 'outcome', 'menu', 'cinematic', 'fade'].includes(id)) }

Common tasks ​

A HUD for one mission only ​

A campaign's missions share one view. Report which mission is playing, fill a slot with it, and let parts follow it:

ts
// in the rules
report: (world) => ({ mission: world.map.name })
// in the view (with `mission: string` added to `HudModelSlots`)
hud: {
	describe: { mission: (context) => String(context.state.report.mission ?? '') },
	widgets: [{ id: 'my.siegeWaves', place: 'top', when: (client) => client.ui.slot('mission') === 'fort', component: SiegeWaves }]
}

Change the quest log ​

The quest log is the objectives part. Reword it with messages (ui.objectives.title, ui.objectives.optional), move it with place, or draw your own over client.ui.objectives():

tsx
{
	id: 'objectives',
	component: (props) => (
		<ul class='my-quests'>
			<For each={props.client.ui.objectives()}>
				{(quest) => <li classList={{ done: quest.status === 'done', failed: quest.status === 'failed', optional: !quest.required }}>{quest.text}</li>}
			</For>
		</ul>
	)
}

React to what happens in the HUD ​

ts
client.hud.on('heroDied', ({ name }) => showBanner(`${name} has fallen`))
client.hud.on('supplyCapped', () => playSound('needMoreFarms'))

Try your HUD without playing ​

ts
client.hud.emit('heroLevel', { hero: 1, name: 'Aldric', level: 5 })

Reference ​

You want to…Use
restyle everythinghud.theme, registerTheme, races[race].theme
move the consolehud.console, hud.places, client.hud.setPlaces
hide or show a parthud.hide, client.hud.hide, a widget's when
add a parthud.widgets, client.hud.widgets.add
change a client's parta widget with its id: place, order, component, mount
read the game's stateclient.ui (signals), client.ui.snapshot(), client.ui.watch, useHud
bring data of your ownHudModelSlots, hud.describe, client.ui.slot
act as the playerclient.controller (PlayerActions)
listenclient.hud.on, onHudEvent

Every place, size, part and event: HUD layout and places. A hero-centred HUD built step by step: The HUD and a test.