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>
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package feedback
|
|
|
|
import (
|
|
"log/slog"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/display"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/icon"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/text"
|
|
)
|
|
|
|
type ErrorStateOptions struct {
|
|
Disabled bool
|
|
}
|
|
|
|
type ErrorStateResult struct {
|
|
Element ui.Element
|
|
Continue bool
|
|
}
|
|
|
|
type startKey struct{}
|
|
|
|
// ErrorState is GAME OVER, a CONTINUE? countdown, and CONTINUE.
|
|
func ErrorState(c *ui.Context, message string, o ErrorStateOptions) ErrorStateResult {
|
|
k := pixel.K(c)
|
|
col := ui.Column(c).Gap(k.D(8)).Padding(k.D(16)).AlignItems(ui.Center).Role(ui.RoleGroup).Label(k.Msg("game_over"))
|
|
start := ui.Local(col, startKey{}, func() time.Time { return k.Now() })
|
|
left := max(0, 9-max(0, int(k.Now().Sub(*start)/time.Second)))
|
|
if left > 0 {
|
|
k.Tick(c, 10)
|
|
}
|
|
res := ErrorStateResult{Element: col}
|
|
col.Children(func() {
|
|
text.ShadowText(c, k.Msg("game_over"), text.ShadowTextOptions{Slot: pixel.Bad, Scale: 3})
|
|
pixel.Text(c, message, pixel.TextOptions{Slot: pixel.Faint, Wrap: true, MaxLines: 6}).Width(k.D(min(pixel.Measure(message), 280)))
|
|
display.Icon(c, icon.Skull, display.IconOptions{Scale: 3})
|
|
text.ShadowText(c, k.Msg("continue")+" "+strconv.Itoa(left), text.ShadowTextOptions{Slot: pixel.Accent, Scale: 2})
|
|
res.Continue = input.Button(c, k.Msg("continue_game"), input.ButtonOptions{Variant: input.Primary, Disabled: o.Disabled}).Clicked
|
|
})
|
|
if res.Continue {
|
|
slog.Debug("8bit: continue", "left", left)
|
|
}
|
|
return res
|
|
}
|