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>
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package account
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/icon"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type DifficultySelectOptions struct {
|
|
Disabled bool
|
|
}
|
|
|
|
type DifficultySelectResult struct {
|
|
Element ui.Element
|
|
Changed bool
|
|
}
|
|
|
|
var levels = []string{"easy", "normal", "hard", "nightmare"}
|
|
|
|
// DifficultySelect picks EASY to NIGHTMARE, a skull a step.
|
|
func DifficultySelect(c *ui.Context, text string, chosen *int, o DifficultySelectOptions) DifficultySelectResult {
|
|
k := pixel.K(c)
|
|
choice("DifficultySelect", chosen, len(levels))
|
|
old := *chosen
|
|
// Arrows choose at once; the cursor is the choice.
|
|
shell, base, st, _ := pixel.Pad(c, text, 1, len(levels), 140, 16, chosen, o.Disabled)
|
|
base.Description(fmt.Sprintf("%s, %d", k.Msg(levels[*chosen]), *chosen+1))
|
|
at := *chosen
|
|
shell.Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
for i, l := range levels {
|
|
y, ink := i*16, pixel.Ink
|
|
if i == len(levels)-1 {
|
|
ink = pixel.Bad
|
|
}
|
|
if i == at {
|
|
g.Text(2, y+2, "▶", pixel.Accent, 1)
|
|
}
|
|
g.Text(14, y+2, k.Msg(l), ink, 1)
|
|
for s := range i + 1 {
|
|
g.Sprite(140-14*(s+1), y+2, icon.Skull, 0, ink, 1)
|
|
}
|
|
}
|
|
g.Finish(st)
|
|
})
|
|
res := DifficultySelectResult{Element: shell, Changed: *chosen != old}
|
|
if res.Changed {
|
|
slog.Debug("8bit: difficulty", "label", text, "level", levels[*chosen])
|
|
}
|
|
return res
|
|
}
|