package ui
Package ui is a map's own interface on the players' screens: a few plain elements (text, a button, a panel that holds others) placed from a corner or the centre of the screen, in the same 1080-pixel units as the rest of the interface, drawn in its style.
A call per thing: ui.Text(player.Everyone, "score", "Kills: 3", ui.TopRight, 20, 20) puts a line of text 20 pixels in from the top right corner and replaces it when called again with the same id; ui.Button(player.Red, "buy", "Buy", ui.Bottom, 0, 120, func(p player.ID) {...}) is a button whose click calls the function; ui.Hide(player.Red, "buy") hides it.
The elements are not the simulation's state: the game shows them to the players they are for (player.Everyone or one player, like player.Red) and sends the clicks back to the script, which runs inside the simulation, so a map's interface works the same over a network.
import "w4/ui"Functions
Button
func Button(who player.ID, id, label string, at Anchor, x, y float64, onClick func(p player.ID), opts ...Option)Button shows a button with a label; a click calls onClick with the player who clicked. Calling it again with the same id replaces it.
FloatText
func FloatText(who player.ID, text string, x, y float64, opts ...Option)FloatText shows a line of text over the place (x, y) of the map, in world units from the middle of the map like a unit's position, for a player (or player.Everyone). It rises and fades away by itself. Size, Color and Seconds apply. It is only a picture: use it for damage numbers, "+10 gold" and the like.
FloatTextOver
func FloatTextOver(who player.ID, u game.Unit, text string, opts ...Option)FloatTextOver is FloatText over a unit, a little above where it stands now. The text stays where it was shown when the unit moves on.
Hide
func Hide(who player.ID, id string)Hide takes the element off the screen, keeping it for Show.
Panel
func Panel(who player.ID, id string, at Anchor, x, y, w, h float64, opts ...Option)Panel shows a box of the interface's style, w by h pixels, that other elements can be placed in with In(id).
Quest
func Quest(who player.ID, id, title, objective string)Quest adds an entry to the quest panel on the right of the screen, for a player (or player.Everyone): a title and a line saying what to do. Calling it again with the same id changes the text and makes it active again.
QuestDone
func QuestDone(id string)QuestDone marks a quest completed; it stays in the panel, in green.
QuestFailed
func QuestFailed(id string)QuestFailed marks a quest failed; it stays in the panel, in red.
Remove
func Remove(who player.ID, id string)Remove takes the element away for good (a panel takes what is in it along).
Show
func Show(who player.ID, id string)Show shows a hidden element again.
Text
func Text(who player.ID, id, text string, at Anchor, x, y float64, opts ...Option)Text shows a line of text for a player (or player.Everyone) at the anchor, offset by x and y. Calling it again with the same id changes the text or moves it.
Types
Anchor
type Anchor intAnchor is the corner, edge or centre of the screen an element is placed from. The offsets of an element go inwards from it: x to the right from a left anchor, to the left from a right one; y down from a top anchor, up from a bottom one.
const (
TopLeft Anchor = iota
Top
TopRight
Left
Center
Right
BottomLeft
Bottom
BottomRight
)Option
type Option func(*element)An Option changes the look or the place of an element.
Color
func Color(hex string) OptionColor is the text colour as "rrggbb" (hex).
In
func In(panel string) OptionIn puts the element inside a panel: its anchor and offsets are then the panel's, not the screen's.
Seconds
func Seconds(s float64) OptionSeconds is how long a floating text stays before it has faded away (2.5 is the usual).
Size
func Size(px float64) OptionSize is the text size in pixels (18 is the usual).