package topbar
import "git.teletypegames.org/engines/inkwell/inkbase/topbar"
Package topbar is an inkbase widget: TopBar, a strip across the top of the screen in three sections.
- Left: LeftText, or the scene title, followed after an em dash by the value of the NoteVar State var when it holds anything ("ALLEY — paused"). Notes maps each value to what the player reads, so the var's value stays the same in every language.
- Centre: the ScoreVar var, as "Score: X/MAX" when ScoreMax is set and "Score: X" otherwise; ScoreLabel overrides the word, which defaults to the package's ScoreLabel.
- Right: the TimeVar var.
An empty section is skipped. VarText is how a var is printed. The strip blocks clicks above its bottom edge (widget.ClickBlocker).
The widget reaches its game through Host: the screen, SceneTitle, StateVar and the Colors. inkwell's *Game is a Host, with the theme's top bar tokens, and the root package re-exports TopBar; there a game changes the default label through inkwell.ScoreLabel, which the engine copies here every frame.
Index
Variables
var ScoreLabel = inkbase.Text{ {Lang: "en", Text: "Score"}, {Lang: "hu", Text: "Pont"}, }
ScoreLabel is the default label for the score.
Functions
func VarText
func VarText(v any) string
VarText renders a state variable for the bar: a Text resolved into the player's language, a string as it is, nil as "", and anything else with fmt.Sprint.
Types
type Colors
type Colors struct { BG color.Color Text color.Color Accent color.Color }
Colors is the palette a TopBar draws with: BG fills the strip, Text is the left and right sections, Accent the score.
type Host
type Host interface { widget.Screen // SceneTitle is the left section when LeftText is empty; an empty Text // leaves it blank. SceneTitle() inkbase.Text // StateVar reads a state variable, nil when it was never set. StateVar(name string) any // TopBarColors is the palette the bar draws with. TopBarColors() Colors }
Host is what a TopBar needs from the game it is drawn for, the UICtx's Game. On a Game that does not implement it the bar draws nothing.
type TopBar
type TopBar struct { // Name is the key the widget is registered under. Name string // When gates the widget; nil shows it always. When inkbase.Condition // Height is the strip's height in pixels; 0 means 12. Height int // LeftText overrides the auto-discovered scene Title/Name. LeftText inkbase.Text // ScoreVar is a State Var key whose value is fmt-printed as the // center score; empty = no score shown. ScoreVar string // ScoreMax, when above 0, prints the score as "Score: X/MAX". ScoreMax int // ScoreLabel overrides the engine's own word for it. ScoreLabel inkbase.Text // TimeVar is a State Var key whose value is printed at the right // edge (e.g. "Day 2 - 14:32"); empty = nothing on the right. TimeVar string // NoteVar is a State Var key whose value is appended to the left // text after an em dash — "ALLEY — paused". Empty or unset = no // note, and the title stands alone. NoteVar string // Notes is what to print for each value NoteVar takes. The value // itself is game state a Condition compares against, so it has to // stay the same in every language; what the player reads does not. // A value with no entry prints as it stands. Notes map[string]inkbase.Text }
TopBar is a thin strip across the top of the screen with three sections: scene title on the left, a score number in the center, and a day/time string on the right. Empty fields are skipped.
func (*TopBar) BlocksClickAt
func (t *TopBar) BlocksClickAt(ctx *widget.UICtx, p inkbase.Point) bool
BlocksClickAt reports whether p lies above the bar's bottom edge.
func (*TopBar) Draw
func (t *TopBar) Draw(dst *ebiten.Image, ctx *widget.UICtx)
Draw paints the strip, Height pixels tall (12 when zero), with the left text and its note, the score in the centre and the time at the right edge, each read from State as the frame is drawn.
func (*TopBar) GetName
func (t *TopBar) GetName() string
GetName returns the name the bar is registered under.
func (*TopBar) Layer
func (t *TopBar) Layer() widget.Layer
Layer puts the bar on widget.LayerHUD.
func (*TopBar) Tick
func (t *TopBar) Tick(ctx *widget.UICtx)
Tick does nothing; the bar reads the game when it draws.
func (*TopBar) VisibleWhen
func (t *TopBar) VisibleWhen() inkbase.Condition
VisibleWhen returns the condition that switches the bar on; nil means always.