Files
ZacharyZhang-NYandClaude Opus 5.5 03e1f91706 Upgrade MyGo to v0.5.5
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>
2026-10-17 01:31:08 -04:00

52 lines
1.5 KiB
Go

package game
import (
"fmt"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/data"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/overlay"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type LootPopupOptions struct {
Disabled bool
}
type LootPopupResult struct {
Element ui.Element
// Closed is OK, Escape or a click outside.
Closed bool
}
// LootPopup announces YOU GOT: an item, rising, until OK.
func LootPopup(c *ui.Context, it data.Item, open *bool, o LootPopupOptions) LootPopupResult {
k := pixel.K(c)
if it.Sprite == nil {
panic(fmt.Sprintf("game: LootPopup item %q has no sprite", it.Name))
}
title := fmt.Sprintf(k.Msg("you_got"), it.String())
w := max(140, pixel.Measure(title)+24)
r := overlay.Dialog(c, title, open, overlay.DialogOptions{Actions: []string{k.Msg("ok")}, Width: w, Disabled: o.Disabled}, func() {
sp := it.Sprite
e := ui.Box(c).Size(k.D(w-24), k.D(3*sp.H+12)).Role(ui.RoleImage).Label(it.String())
// The item rises 8 dots; reduced, it starts up.
rise := 8
if !k.Reduce() {
rise = k.Since(c, start(k, e, 0).at, 15, 8)
}
e.Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
x := (g.W - 3*sp.W) / 2
g.Sprite(x, g.H-3*sp.H-rise-2, sp, 0, pixel.Ink, 3)
if rise == 8 {
for _, d := range [][2]int{{-4, 2}, {3 * sp.W, 4}, {-2, 3 * sp.H / 2}, {3*sp.W + 2, 3 * sp.H / 2}} {
g.Rect(x+d[0], d[1], 2, 2, pixel.Warn)
}
}
})
})
return LootPopupResult{Element: r.Element, Closed: r.Action == 0 || r.Closed}
}