widget manager refact
This commit is contained in:
@@ -1,102 +0,0 @@
|
||||
package inc
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
|
||||
inkwell "git.teletypegames.org/engines/inkwell"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/vector"
|
||||
)
|
||||
|
||||
type tapeChannel struct {
|
||||
Name string
|
||||
Bounds inkwell.Rectangle
|
||||
}
|
||||
|
||||
func (t *tapeChannel) GetName() string { return t.Name }
|
||||
|
||||
func (t *tapeChannel) Tick(ctx *inkwell.UICtx) {}
|
||||
|
||||
func (t *tapeChannel) BlocksClickAt(p inkwell.Point) bool {
|
||||
return World.HUDVisible() && t.Bounds.Contains(p)
|
||||
}
|
||||
|
||||
func (t *tapeChannel) Draw(dst *ebiten.Image, ctx *inkwell.UICtx) {
|
||||
if !World.HUDVisible() {
|
||||
return
|
||||
}
|
||||
g := ctx.Game
|
||||
th := g.Theme()
|
||||
b := t.Bounds
|
||||
if b.W <= 0 || b.H <= 0 {
|
||||
return
|
||||
}
|
||||
const lh, pad = LineH, Pad
|
||||
|
||||
vector.DrawFilledRect(dst, float32(b.X), float32(b.Y), float32(b.W), float32(b.H), th.ChatLogBG, false)
|
||||
|
||||
speaker, speakerCol := t.lastSpeaker(g, th)
|
||||
drawTextC(dst, speaker, int(b.X)+pad, int(b.Y)+pad, speakerCol)
|
||||
hy := float32(b.Y+pad+lh) + 2
|
||||
vector.StrokeLine(dst, float32(b.X)+pad, hy,
|
||||
float32(b.X+b.W)-pad, hy, 1, th.CharacterPanelBorder, false)
|
||||
|
||||
type line struct {
|
||||
text string
|
||||
col color.Color
|
||||
}
|
||||
wrapW := int(b.W) - pad*2
|
||||
var rendered []line
|
||||
for _, m := range g.Messages() {
|
||||
var col color.Color
|
||||
var txt string
|
||||
switch m.Kind {
|
||||
case inkwell.LogAction:
|
||||
|
||||
col, txt = th.ChatLogPrompt, m.Text
|
||||
case inkwell.LogResponse:
|
||||
if !IsTape(m.Speaker) {
|
||||
continue
|
||||
}
|
||||
col, txt = speechColor(g, m.Speaker, th.ChatLogResponse), m.Text
|
||||
default:
|
||||
col, txt = th.ChatLogSystem, m.Text
|
||||
}
|
||||
for _, wl := range wrap(txt, wrapW) {
|
||||
rendered = append(rendered, line{
|
||||
text: wl,
|
||||
col: col,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
top := int(b.Y) + pad + lh + 6
|
||||
maxLines := (int(b.Y+b.H) - pad - top) / lh
|
||||
if maxLines <= 0 {
|
||||
return
|
||||
}
|
||||
if start := len(rendered) - maxLines; start > 0 {
|
||||
rendered = rendered[start:]
|
||||
}
|
||||
for i, ln := range rendered {
|
||||
drawTextC(dst, ln.text, int(b.X)+pad, top+i*lh, ln.col)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *tapeChannel) lastSpeaker(g *inkwell.Game, th inkwell.Theme) (string, color.Color) {
|
||||
msgs := g.Messages()
|
||||
for i := len(msgs) - 1; i >= 0; i-- {
|
||||
m := msgs[i]
|
||||
if m.Kind == inkwell.LogResponse && IsTape(m.Speaker) {
|
||||
return TapeDisplayName(m.Speaker), speechColor(g, m.Speaker, th.ChatLogResponse)
|
||||
}
|
||||
}
|
||||
return TapeDisplayName(Dex), speechColor(g, Dex, th.ChatLogResponse)
|
||||
}
|
||||
|
||||
func speechColor(g *inkwell.Game, name string, fallback color.Color) color.Color {
|
||||
if c, ok := g.CharacterManager.Get(name); ok && c.SpeechColor != nil {
|
||||
return c.SpeechColor
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
Reference in New Issue
Block a user