Files
8bitMyGoUI/account/difficultyselect.go
T
ZacharyZhang-NY c745b082a9 Add account components 386-405; Reduce setting, PinInput Cmd+V
Twenty account components: SettingsList, OptionCycler, KeyBindings,
ControllerMap, ProfileCard, CharacterCreator, LoginForm, PasswordGrid,
SessionList, LanguagePicker, PalettePicker, VolumeMixer,
DifficultySelect, AccessibilityOptions, AccountSwitcher, PlayerSelect,
TwoFactor, About, PatchNotes and FeedbackForm.

The components never check credentials, and no secret reaches the log:
LoginForm reports Submitted and the caller counts Failures; each new
failure clears the password, refocuses it, shakes the form and names no
field. TwoFactor builds on input.PinInput and drains an epoch-aligned
period bar. PalettePicker draws each tile in its own palette on a
pixel.Pad grid.

pixel.Settings.Reduce stills motion like the system preference, the
micro font gains '?', display.Face draws avatar faces anywhere, and
input.PinInput pastes on Cmd+V as native hosts send it.
2026-10-12 08:21:39 -04:00

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
}