The command card
The grid of buttons for what is selected: orders, abilities, what a building trains. You set its size, place buttons, add your own and change the client's.
Quick start
hud: {
cardSize: { columns: 5, rows: 3 }, // 4 by 3 when left out
card: { move: { slot: 0, hotkey: 'M' }, attackGround: { slot: 3, hotkey: 'G' } }, // where the client's commands go, and their keys
cardButtons: (context) => [
{ id: 'sell', label: 'Sell', slot: 11, onPress: () => sell(context) } // shown as game:sell
]
}That widens the card, moves two of the client's commands and adds a Sell button of your own.
Common tasks
Add a button that sends a command
cardButtons(context) adds buttons (their id on the card is game:<id>). A button has onPress, a command, a target to aim (onTarget gets what was clicked), or a menu it opens (with menu on the buttons inside). slot takes a place.
Hide, rename, disable or move a button
hud: {
editCard: (buttons, context) => buttons.map((button) => (button.label === 'Patrol' ? { ...button, label: 'Walk around' } : button))
}Step in on every press or key
input: {
onPress: (button, context) => false, // true: your game handled it
onKey: (event, client) => false, // sees keys before the client
beforeSend: (command, client) => command // change it, fan it out, or stop it with null
}onRightClick(click) takes a right click, or lets the smart order go with a mark of your own.
Change the words on the card
Every hint, refusal and label is a message key (moveHint, mustTargetUnit, card.move, card.repair.about). Reword them in GameView.hud.messages.
Show charged abilities
icons.charged and sounds.charged, by ability id, say how an ability looks and sounds when charged.
Check your card for clashes
apps/example/tests/card.test.ts builds the card of every unit type and fails on two buttons with the same key or place. Copy it for your game.
Reference
How the card is laid out
- A place (
GameView.hud.card, a card button'sslot) is counted along the rows from 0. - The client's defaults are for a 4 by 3 card. On a smaller card, what has no slot goes to a free one (Cancel to the last), and its key still works.
- A unit's abilities go on the last row; what a place hires goes on the first empty row.
- A builder with more to build than its menu has room for gets two pages, as in classic RTS games: More (
card.build-more) on the first, Back (card.build-back) on the second. - In code:
client.cardSize = { columns, rows }.
Which key a button takes
A button takes the keys of its action where it has one (card.<command>, a hero's hero.ability.N), else the key its definition's hotkey names, or the player's own for that button (client.keys.bind('card:train:footman', ['KeyZ'])). On a CommandButton, hotkey is the key as shown, keys its bindings, action the action they come from. See Keys and hotkeys.
Order of asking on a key press
- Your
input.onKey. - The card button on that key.
- The actions, yours first.
The card's state
client.ui.commands() is what the card shows, a signal. The card and the selection are controllers like the rest of the HUD: see The interface.