Files
inkwell/ui.speech.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

84 lines
1.7 KiB
Go

package inkwell
import (
"image/color"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/vector"
)
// SpeechBubble renders the line set by the Say action above the speaking
// character (or at FallbackY if the speaker has no on-screen position).
type SpeechBubble struct {
Name string
When Condition
MaxWidth int
Padding int
OffsetY int
FallbackY int
}
func (s *SpeechBubble) GetName() string { return s.Name }
func (s *SpeechBubble) VisibleWhen() Condition { return s.When }
func (s *SpeechBubble) Layer() Layer { return LayerSpeech }
func (s *SpeechBubble) Tick(ctx *UICtx) {}
func (s *SpeechBubble) Draw(dst *ebiten.Image, ctx *UICtx) {
g := ctx.Game
sp := g.speech
if !sp.Active {
return
}
maxW := s.MaxWidth
if maxW <= 0 {
maxW = 200
}
pad := s.Padding
if pad <= 0 {
pad = 3
}
lines := WrapText(sp.Text, maxW)
w := 0
for _, ln := range lines {
if t := TextWidth(ln); t > w {
w = t
}
}
w += pad * 2
h := len(lines)*16 + pad*2
// position above speaker if known
cx, cy := g.Width/2, s.FallbackY
if cy == 0 {
cy = 14
}
if c, ok := g.runtimeChar(sp.Speaker); ok {
cx = int(c.pos.X)
cy = int(c.pos.Y-c.def.H) - s.OffsetY
}
x := cx - w/2
y := cy - h
if x < 2 {
x = 2
}
if x+w > g.Width-2 {
x = g.Width - 2 - w
}
if y < 2 {
y = 2
}
th := g.Theme()
vector.DrawFilledRect(dst, float32(x), float32(y), float32(w), float32(h), th.SpeechBubbleBG, false)
textCol := th.SpeechDefaultText
if c, ok := g.CharacterManager.Get(sp.Speaker); ok {
if rgba, ok := c.SpeechColor.(color.RGBA); ok && rgba.A > 0 {
textCol = rgba
}
}
for i, ln := range lines {
g.DrawText(dst, ln, x+pad, y+pad+i*16-2, textCol)
}
}