Files
inkwell/ui.chat_log.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.3 KiB
Go

package inkwell
import (
"image/color"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/vector"
)
// ChatLog renders the in-game message log (player commands + in-world
// replies) as a scrolling box. The newest message is at the bottom; older
// messages scroll up out of view as the buffer fills.
type ChatLog struct {
Name string
When Condition
Bounds Rectangle
LineHeight int
Padding int
// ShowBorder draws a thin border around the box.
ShowBorder bool
}
func (c *ChatLog) GetName() string { return c.Name }
func (c *ChatLog) VisibleWhen() Condition { return c.When }
func (c *ChatLog) Layer() Layer { return LayerHUD }
func (c *ChatLog) Tick(ctx *UICtx) {}
func (c *ChatLog) Draw(dst *ebiten.Image, ctx *UICtx) {
g := ctx.Game
th := g.Theme()
b := c.Bounds
if b.W <= 0 || b.H <= 0 {
return
}
lh := c.LineHeight
if lh <= 0 {
lh = 10
}
pad := c.Padding
if pad <= 0 {
pad = 3
}
vector.DrawFilledRect(dst, float32(b.X), float32(b.Y), float32(b.W), float32(b.H), th.ChatLogBG, false)
if c.ShowBorder {
vector.StrokeRect(dst, float32(b.X), float32(b.Y), float32(b.W), float32(b.H), 1, th.CharacterPanelBorder, false)
}
msgs := g.Messages()
maxLines := int((b.H - float64(2*pad)) / float64(lh))
if maxLines <= 0 {
return
}
// Wrap each message; collect rendered lines (color + text).
type line struct {
text string
col color.Color
}
wrapW := int(b.W) - pad*2
var rendered []line
for _, m := range msgs {
var col color.Color
switch m.Kind {
case LogAction:
col = th.ChatLogPrompt
case LogResponse:
col = th.ChatLogResponse
default:
col = th.ChatLogSystem
}
txt := m.Text
if m.Kind == LogResponse && m.Speaker != "" {
txt = m.Speaker + ": " + m.Text
}
for _, w := range WrapText(txt, wrapW) {
rendered = append(rendered, line{text: w, col: col})
}
}
// Show the LAST maxLines wrapped lines.
start := len(rendered) - maxLines
if start < 0 {
start = 0
}
for i, ln := range rendered[start:] {
y := int(b.Y) + pad + i*lh
g.DrawText(dst, ln.text, int(b.X)+pad, y-1, ln.col)
}
}
// BlocksClickAt — the log is non-interactive, but it sits over the bottom
// of the scene; treat it as opaque so RadialVerbs doesn't pop up over it.
func (c *ChatLog) BlocksClickAt(p Point) bool { return c.Bounds.Contains(p) }