Elements are now pass-scoped value handles: tests that read bounds after a frame bind a ui.Handle. pixel tells frames apart by the build pass's root, since the Tester clock no longer moves on its own. Fix the regressions the upgrade brought: - Clipboard reads in input handlers go through c.Services(). - MyGo notes an overlay's opener after building it, so AutoFocus inside lost it; pixel.AutoFocus focuses through a Handle, and archtest bans the raw call. Dialogs hand the focus back again. - Elements around a press stay hovered: Tooltip tells a press-given focus by focus arriving under the pointer. - The web host moves the Tester clock with real time, at most 500 ms a call, and gives components the real clock. The gallery's source index also accepts CRLF checkouts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package game
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
// Member is a party member: portrait, HP and MP.
|
|
type Member struct {
|
|
Name string
|
|
Portrait *pixel.Sprite
|
|
HP, MaxHP, MP, MaxMP int
|
|
}
|
|
|
|
type PartyFramesOptions struct{}
|
|
|
|
// PartyFrames stacks member cards; a fallen member greys out.
|
|
func PartyFrames(c *ui.Context, text string, members []Member, o PartyFramesOptions) ui.Element {
|
|
k := pixel.K(c)
|
|
return ui.Column(c).Gap(k.D(3)).AlignItems(ui.Start).Role(ui.RoleGroup).Label(text).Children(func() {
|
|
for _, m := range members {
|
|
if m.Portrait == nil {
|
|
panic(fmt.Sprintf("game: member %q has no portrait", m.Name))
|
|
}
|
|
down := m.HP == 0
|
|
ui.Row(c).Gap(k.D(4)).Padding(k.D(3)).AlignItems(ui.Center).Role(ui.RoleGroup).Label(m.Name).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
g.Frame(0, 0, g.W, g.H, pixel.Raised, pixel.Face)
|
|
}).Children(func() {
|
|
ui.Box(c).Size(k.D(28), k.D(28)).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
g.Frame(0, 0, 28, 28, pixel.Sunken, pixel.Well)
|
|
if down {
|
|
g.Silhouette(2, 2, m.Portrait, 0, pixel.Shade, 2)
|
|
return
|
|
}
|
|
g.Sprite(2, 2, m.Portrait, 0, pixel.Ink, 2)
|
|
})
|
|
ui.Column(c).Gap(k.D(1)).Children(func() {
|
|
slot := pixel.Ink
|
|
if down {
|
|
slot = pixel.Faint
|
|
}
|
|
pixel.Text(c, m.Name, pixel.TextOptions{Slot: slot})
|
|
HealthBar(c, "HP", m.HP, m.MaxHP, HealthBarOptions{Width: 72})
|
|
ManaBar(c, "MP", m.MP, m.MaxMP, ManaBarOptions{Width: 72})
|
|
})
|
|
})
|
|
}
|
|
})
|
|
}
|