Files
8bitMyGoUI/data/bestiary.go
T
ZacharyZhang-NY 03680980da Add data components 151-175; clear MyGo row highlights
Lists, tables, trees, grids, inventories and records in data/.
Outline and GridView build on ui.List: ui.Outline strokes its arrows
and ui.GridView spaces and tints items. The pixel theme keeps MyGo's
row highlights clear so scrolled rows stay on whole dots; off lists
take a veil against the wheel. Adds Canvas.Silhouette, SwitchOptions
Label and exports Rarity.Slot.
2026-10-11 22:29:07 -04:00

62 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package data
import (
"fmt"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/display"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/layout"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/text"
)
// Monster is a bestiary entry; unseen ones keep their secrets.
type Monster struct {
Sprite *pixel.Sprite
Name string
Stats [][2]string
Notes string
Seen bool
}
type BestiaryOptions struct {
// Scale enlarges the sprite, 1–4; zero means 2.
Scale int
}
// Bestiary is a monster card; unseen ones are silhouettes.
func Bestiary(c *ui.Context, m Monster, o BestiaryOptions) *ui.Element {
k := pixel.K(c)
sc := pixel.Or("Bestiary Scale", o.Scale, 2)
if m.Sprite == nil || sc > 4 {
panic(fmt.Sprintf("data: Bestiary %q needs a Sprite and Scale 1–4", m.Name))
}
hide := func(s string) string {
if m.Seen {
return s
}
return k.Msg("unknown")
}
return layout.Card(c, layout.CardOptions{Title: hide(m.Name)}, func() {
ui.Row(c).Gap(k.D(8)).Children(func() {
ui.Box(c).Size(k.D(m.Sprite.W*sc+8), k.D(m.Sprite.H*sc+8)).Shrink(0).Role(ui.RoleImage).Label(hide(m.Name)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
g.Frame(0, 0, g.W, g.H, pixel.Sunken, pixel.Well)
if m.Seen {
g.Sprite(4, 4, m.Sprite, 0, pixel.Ink, sc)
} else {
g.Silhouette(4, 4, m.Sprite, 0, pixel.Shade, sc)
}
})
ui.Column(c).Grow(1).Gap(k.D(2)).Children(func() {
for _, s := range m.Stats {
display.KeyValue(c, s[0], hide(s[1]), display.KeyValueOptions{})
}
})
})
ui.Box(c).Height(k.D(6))
text.Paragraph(c, hide(m.Notes), text.ParagraphOptions{})
})
}