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>
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package game
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"github.com/egoist/mygo/ui"
|
||
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/icon"
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||
)
|
||
|
||
type BossBarOptions struct {
|
||
// Width is in dots; zero means 200.
|
||
Width int
|
||
// Phases are where the boss changes, as fractions: 0.5.
|
||
Phases []float64
|
||
}
|
||
|
||
// BossBar is a wide bar under the name, phases marked.
|
||
func BossBar(c *ui.Context, name string, hp, full int, o BossBarOptions) ui.Element {
|
||
k := pixel.K(c)
|
||
amount("BossBar hp", hp, full)
|
||
for _, f := range o.Phases {
|
||
if !(f > 0 && f < 1) {
|
||
panic(fmt.Sprintf("game: BossBar phase %v outside 0–1", f))
|
||
}
|
||
}
|
||
w := pixel.Or("BossBar Width", o.Width, 200)
|
||
if need := icon.Skull.W + 3 + pixel.Measure(name); w < need {
|
||
panic(fmt.Sprintf("game: BossBar Width %d is under the %d its name needs", w, need))
|
||
}
|
||
return ui.Box(c).Role(ui.RoleMeter).Label(name).Description(ratio(hp, full)).Size(k.D(w), k.D(pixel.LineHeight+12)).Draw(func(p *ui.Painter, r ui.Rect) {
|
||
g := k.Canvas(p, r)
|
||
g.Sprite(0, 2, icon.Skull, 0, pixel.Bad, 1)
|
||
g.Text(icon.Skull.W+3, 0, name, pixel.Ink, 1)
|
||
meter(g, 0, pixel.LineHeight, w, 12, float64(hp)/float64(full), pixel.Bad)
|
||
for _, f := range o.Phases {
|
||
x := 2 + int(f*float64(w-4))
|
||
g.VLine(x, pixel.LineHeight-2, 14, pixel.Ink)
|
||
g.Rect(x-1, pixel.LineHeight-2, 3, 1, pixel.Ink)
|
||
}
|
||
})
|
||
}
|