A cross-cutting pass, each fix with a test that failed first. Veils: MyGo still hands a key to a base that turned off this frame, so every element key now goes through pixel.Shortcut, which an archtest enforces. Input handlers record and the build applies them only while enabled; the editor turns away a veil-frame letter or copy; value bases get a copy and keep only enabled turns. Popups give a held focus back to their opener when the veil lifts. Motion: S5 is enforced at the clock. Every Tick, Since, Step, Toward and Shot runs at 4-15 fps; blinks keep 1 Hz on 4 fps steps, fast animations step at 15, and drawn time is quantized to frames. Clocks stepping back: Since holds at zero without overflow, and k.Elapsed moves a stored start to now, so nothing goes negative, runs backward or indexes out of range. Also: logs count typed text instead of holding it, gallery names use glyphs the font has, removable rows are keyed, components take their own Options (archtest), and sweeps over all 508 demos check veiled keys, clicks, wheels, the clock stepping back and names.
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package game
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/display"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type InteractPromptOptions struct {
|
|
// Key is the pad button's letter; zero means A.
|
|
Key string
|
|
}
|
|
|
|
// InteractPrompt bobs a Ⓐ TALK bubble above target.
|
|
func InteractPrompt(c *ui.Context, target *ui.Element, action string, o InteractPromptOptions) *ui.Element {
|
|
k := pixel.K(c)
|
|
key := o.Key
|
|
if key == "" {
|
|
key = "A"
|
|
}
|
|
if len([]rune(key)) != 1 || !pixel.MicroOK(key) {
|
|
panic(fmt.Sprintf("game: InteractPrompt key %q is not one micro letter", key))
|
|
}
|
|
b := target.Bounds()
|
|
ww, wh := c.Size()
|
|
// The bubble's tail points at the target's middle.
|
|
x := max(0, min(b.X+b.W/2-k.D(10), ww-k.D(pixel.Measure(action)+30)))
|
|
at := max(3, int((b.X+b.W/2-x)/k.Dot()))
|
|
bob := 0
|
|
if !k.Reduce() {
|
|
bob = k.Tick(c, 4) / 2 % 2
|
|
}
|
|
var e *ui.Element
|
|
ui.Overlay(c, func() {
|
|
e = ui.Box(c).Absolute().Left(x).Bottom(wh - b.Y + k.D(1+bob)).PassThrough().Role(ui.RoleText).Label(key + " " + action)
|
|
// Bounds lag a layout; if the target moved, build again.
|
|
e.Draw(func(p *ui.Painter, r ui.Rect) {
|
|
if target.Bounds() != b {
|
|
c.Invalidate()
|
|
}
|
|
})
|
|
e.Children(func() {
|
|
display.Bubble(c, display.BubbleOptions{Tail: display.Bottom, At: at}, func() {
|
|
ui.Row(c).Gap(k.D(3)).AlignItems(ui.Center).Children(func() {
|
|
ui.Box(c).Size(k.D(11), k.D(11)).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
g.Disc(5, 5, 5, pixel.Ink)
|
|
g.Micro((11-pixel.MicroWidth(key))/2, 3, key, pixel.Back, 1)
|
|
})
|
|
pixel.Text(c, action, pixel.TextOptions{})
|
|
})
|
|
})
|
|
})
|
|
})
|
|
return e
|
|
}
|