Files
inkwell/ui.top_bar.go
T
mr.zeroandClaude Opus 5 92fc36bdf5
ci/woodpecker/push/woodpecker Pipeline was successful
Nine things a domain kept having to invent
Every change here started life as a workaround in a game and is really
the same finding: a fact about an entity had nowhere to live, so the
domain built machinery around the gap.

  Character.Label / Character.Voice — a tape is a character that speaks
  into the log, not a second spelling of Say. VoiceOf and CharacterLabel
  read them; Say obeys them.

  Game.Do — a real action queue, in order, so a widget can start an
  action. queueAction no longer drops what arrives while the runner is
  busy; it queues it.

  Widget.When + Gated + WidgetVisible — a widget declares when it is on
  screen. Nothing ticks, draws or blocks a click while its condition is
  false, so a HUD is hidden for a cutscene without a wrapper per widget.

  TopBar.NoteVar — the title was already discovered; the note beside it
  no longer needs a domain widget to push it in.

  Game.UseWithFail — the pair nobody authored is content, and belongs to
  the domain, exactly like ExitLook and ExitTake.

  Game.Player / Game.Walkboxes — a scene that names no cast and no floor
  means "the usual", instead of a defaults pass rewriting every scene.

  Game.WindowScale — Run's 4× is now a default, not a decision.

  SceneNav — the dev widget every game was writing.

  Colour text: DrawText paints in the colour it is handed, and GlyphW/H,
  TextWidth, WrapText and ClipText are the library's, not each game's.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-30 22:57:16 +02:00

95 lines
2.4 KiB
Go

package inkwell
import (
"fmt"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/vector"
)
// 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.
type TopBar struct {
Name string
When Condition
Height int
// LeftText overrides the auto-discovered scene Title/Name.
LeftText string
// ScoreVar is a State Var key whose value is fmt-printed as the
// center score; empty = no score shown.
ScoreVar string
ScoreMax int // when >0, rendered as "Score: X/MAX"
// 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
}
func (t *TopBar) GetName() string { return t.Name }
func (t *TopBar) VisibleWhen() Condition { return t.When }
func (t *TopBar) Layer() Layer { return LayerHUD }
func (t *TopBar) Tick(ctx *UICtx) {}
func (t *TopBar) Draw(dst *ebiten.Image, ctx *UICtx) {
g := ctx.Game
th := g.Theme()
h := t.Height
if h <= 0 {
h = 12
}
vector.DrawFilledRect(dst, 0, 0, float32(g.Width), float32(h), th.TopBarBG, false)
left := t.LeftText
if left == "" && g.currentScene != "" {
s := g.SceneManager.MustGet(g.currentScene)
if s.Title != "" {
left = s.Title
} else {
left = s.Name
}
}
if t.NoteVar != "" {
if note := fmt.Sprint(g.State.Var(t.NoteVar)); note != "" && note != "<nil>" {
left += " — " + note
}
}
if left != "" {
g.DrawText(dst, left, 4, -1, th.TopBarText)
}
if t.ScoreVar != "" {
var sc string
v := g.State.Var(t.ScoreVar)
if t.ScoreMax > 0 {
sc = fmt.Sprintf("Score: %v/%d", v, t.ScoreMax)
} else {
sc = fmt.Sprintf("Score: %v", v)
}
x := (g.Width - TextWidth(sc)) / 2
g.DrawText(dst, sc, x, -1, th.TopBarAccent)
}
if t.TimeVar != "" {
tm := fmt.Sprint(g.State.Var(t.TimeVar))
x := g.Width - TextWidth(tm) - 4
g.DrawText(dst, tm, x, -1, th.TopBarText)
}
}
// BlocksClickAt — the TopBar swallows clicks so the radial menu doesn't
// pop up under it.
func (t *TopBar) BlocksClickAt(p Point) bool {
h := t.Height
if h <= 0 {
h = 12
}
return p.Y < float64(h)
}