package chatlog

import "git.teletypegames.org/engines/inkwell/inkbase/chatlog"

Package chatlog is an inkbase widget: ChatLog, the message log — player commands, in-world replies and system lines — drawn as a box with the newest line at the bottom, older lines scrolling up out of view.

A SpeakerStyle says how a reply names who said it: inline in front of every reply, once as a header above a rule (which suits a panel given over to one voice at a time), or not at all. Deliveries keeps only the replies delivered one of the ways it lists, which is how a game with a radio, a tape or a narrator gives that voice a panel of its own without the widget knowing what the thing is; player commands and system lines are nobody's, so they are kept either way. Resting is the inkbase.Talker the header carries before anybody speaks.

The widget reaches its game through Host: the messages, the speaker lookups (DeliveryOf, SpeechColor, SpeakerLabel) and the Colors. inkwell's *Game is a Host, drawing with the theme's chat log tokens, and the root package re-exports ChatLog; a game built on inkbase alone implements Host itself. The log blocks clicks inside its Bounds (widget.ClickBlocker).

Index

Types

type ChatLog

type ChatLog struct {
	// Name is the key the widget is registered under.
	Name string
	// When gates the widget; nil shows it always.
	When inkbase.Condition
	// Bounds is the box; a zero width or height draws nothing.
	Bounds inkbase.Rectangle
	// LineHeight is a line's height in pixels; 0 means 10.
	LineHeight int
	// Padding is the inner margin in pixels; 0 means 3.
	Padding int
	// ShowBorder draws a thin border around the box.
	ShowBorder bool
	// Speaker says how a reply names who said it.
	Speaker SpeakerStyle
	// Deliveries, when set, keeps only the replies spoken in one of these
	// voices. Player commands and system lines are not a character's, so
	// they are kept either way. Nil keeps everything.
	Deliveries []inkbase.Delivery
	// Resting names the character the header carries before anybody this
	// log listens to has spoken. Only SpeakerHeader reads it.
	Resting inkbase.Talker
}

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.

A log can be given over to part of the conversation rather than all of it: Deliveries keeps only the replies spoken in one of the voices it lists, which is how a game with a radio, a tape or a narrator hands that voice a panel of its own without the widget having to know what the thing is.

func (*ChatLog) BlocksClickAt
func (c *ChatLog) BlocksClickAt(ctx *widget.UICtx, p inkbase.Point) bool

BlocksClickAt reports whether p falls inside Bounds. The log takes no clicks itself, but the screen under it is the log's, not the scene's.

func (*ChatLog) Draw
func (c *ChatLog) Draw(dst *ebiten.Image, ctx *widget.UICtx)

Draw paints the box in Bounds, the speaker header when Speaker is SpeakerHeader, and as many of the newest wrapped messages as fit, each in its kind's colour or its speaker's. A zero-sized Bounds draws nothing.

func (*ChatLog) GetName
func (c *ChatLog) GetName() string

GetName returns the name the log is registered under.

func (*ChatLog) Layer
func (c *ChatLog) Layer() widget.Layer

Layer puts the log on widget.LayerHUD.

func (*ChatLog) Tick
func (c *ChatLog) Tick(ctx *widget.UICtx)

Tick does nothing; the log reads the game's messages when it draws.

func (*ChatLog) VisibleWhen
func (c *ChatLog) VisibleWhen() inkbase.Condition

VisibleWhen returns the condition that switches the log on; nil means always.

type Colors

type Colors struct {
	BG       color.Color
	Border   color.Color
	Prompt   color.Color
	Response color.Color
	System   color.Color
}

Colors is the palette a ChatLog draws with: BG fills the box, Border outlines it and draws the header rule, Prompt colors the player's commands, Response a reply whose speaker has no color of their own, and System every other line.

type Host

type Host interface {
	widget.Screen
	// Messages is the log, oldest first.
	Messages() []inkbase.LogMessage
	// DeliveryOf is how the voice behind a speaker's name delivers its
	// lines, which is what Deliveries filters on.
	DeliveryOf(name string) inkbase.Delivery
	// SpeechColor is the colour of a speaker's lines, or fallback when the
	// speaker has none.
	SpeechColor(name string, fallback color.Color) color.Color
	// SpeakerLabel is what the log calls a speaker.
	SpeakerLabel(name string) inkbase.Text
	// ChatLogColors is the palette the log draws with.
	ChatLogColors() Colors
}

Host is what a ChatLog needs from the game it is drawn for, the UICtx's Game. On a Game that does not implement it the log draws nothing.

type SpeakerStyle

type SpeakerStyle int

SpeakerStyle says how a ChatLog names who is talking.

const (
	// SpeakerInline puts "DEX: " in front of every reply, which is what a
	// log of a conversation between several people needs.
	SpeakerInline SpeakerStyle = iota
	// SpeakerHeader names only the latest speaker, once, above a rule at the
	// top of the box.
	SpeakerHeader
	// SpeakerNone names nobody.
	SpeakerNone
)