Add overlay components 176-195; pixel Harbor and Kit.Cue
Dialogs on DialogBase with focusable panels that harbor parked focus, popovers on PopoverBase, bubbles, drawers, sheets, a lightbox, an RPG dialogue box, notifications, a pause menu and a dithered title card. Kit.Cue moves from feedback to pixel.
This commit is contained in:
37 files changed
+2835
-31
No files matched your search
@@ -67,6 +67,23 @@ func (k Kit) Since(c *ui.Context, t time.Time, fps, done int) int {
|
||||
return min(n, done)
|
||||
}
|
||||
|
||||
type cueKey struct{}
|
||||
|
||||
// cued is a cue's last value and when it changed.
|
||||
type cued struct {
|
||||
n int
|
||||
at time.Time
|
||||
}
|
||||
|
||||
// Cue is when n last changed on e, zero before.
|
||||
func (k Kit) Cue(e *ui.Element, n int) time.Time {
|
||||
s := ui.Local(e, cueKey{}, func() cued { return cued{n: n} })
|
||||
if s.n != n {
|
||||
s.n, s.at = n, k.now
|
||||
}
|
||||
return s.at
|
||||
}
|
||||
|
||||
// frameAt is the frame at t and the next wait.
|
||||
func frameAt(t time.Time, fps int) (int, time.Duration) {
|
||||
checkFPS(fps)
|
||||
|
||||
+15
-2
@@ -107,19 +107,32 @@ type parkKey struct{}
|
||||
// Park moves focus off e while off, back once on.
|
||||
func Park(c *ui.Context, e *ui.Element, off bool) {
|
||||
parked := ui.Local(e, parkKey{}, func() bool { return false })
|
||||
spot := c.Root()
|
||||
if h := current(c).harbor; h != nil {
|
||||
spot = h
|
||||
}
|
||||
switch {
|
||||
case off && e.Focused():
|
||||
c.Root().Focus()
|
||||
spot.Focus()
|
||||
*parked = true
|
||||
case !off && *parked:
|
||||
// Focus comes back unless something else took it.
|
||||
if root := c.Root(); root.Focused() || !root.FocusWithin() {
|
||||
if spot.Focused() || !c.Root().FocusWithin() {
|
||||
e.Focus()
|
||||
}
|
||||
*parked = false
|
||||
}
|
||||
}
|
||||
|
||||
// Harbor keeps focus in e while controls in fn rest.
|
||||
func Harbor(c *ui.Context, e *ui.Element, fn func()) {
|
||||
f := current(c)
|
||||
prev := f.harbor
|
||||
f.harbor = e
|
||||
fn()
|
||||
f.harbor = prev
|
||||
}
|
||||
|
||||
// Hand is the pointing cursor of focus and menus.
|
||||
var Hand = MustSprite(`
|
||||
.eee......
|
||||
|
||||
+4
-2
@@ -17,7 +17,8 @@ var messages = map[Locale]map[string]string{
|
||||
"combo": "COMBO!", "saving": "SAVING", "saved": "SAVED", "go": "GO!", "wait": "PLEASE WAIT",
|
||||
"prev": "PREVIOUS", "next": "NEXT", "back": "BACK", "forward": "FORWARD", "history": "HISTORY",
|
||||
"on": "ON", "off": "OFF", "clear": "CLEAR", "per_page": "PER PAGE", "range": "%d–%d OF %d", "found": "FOUND: %d",
|
||||
"unknown": "???",
|
||||
"unknown": "???", "sure": "ARE YOU SURE?", "paused": "PAUSED", "resume": "RESUME", "options": "OPTIONS", "quit": "QUIT",
|
||||
"next_step": "NEXT ▶",
|
||||
},
|
||||
Zh: {
|
||||
"ok": "确定", "cancel": "取消", "yes": "是", "no": "否", "close": "关闭",
|
||||
@@ -33,7 +34,8 @@ var messages = map[Locale]map[string]string{
|
||||
"combo": "连击!", "saving": "存档中", "saved": "已存档", "go": "开始!", "wait": "请稍候",
|
||||
"prev": "上一页", "next": "下一页", "back": "后退", "forward": "前进", "history": "历史",
|
||||
"on": "开", "off": "关", "clear": "清除", "per_page": "每页", "range": "%d–%d / 共 %d", "found": "找到:%d",
|
||||
"unknown": "???",
|
||||
"unknown": "???", "sure": "确定吗?", "paused": "暂停", "resume": "继续游戏", "options": "设置", "quit": "退出",
|
||||
"next_step": "下一步 ▶",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -48,6 +48,8 @@ type frame struct {
|
||||
cur Settings
|
||||
at time.Time
|
||||
typing bool
|
||||
// harbor holds the focus of controls turning off.
|
||||
harbor *ui.Element
|
||||
}
|
||||
|
||||
type frameKey struct{}
|
||||
@@ -59,7 +61,7 @@ func Use(c *ui.Context, s Settings) {
|
||||
if f.cur.Palette != s.Palette {
|
||||
slog.Debug("8bit: palette", "name", s.Palette.Name)
|
||||
}
|
||||
f.cur, f.at, f.typing = s, c.Now(), false
|
||||
f.cur, f.at, f.typing, f.harbor = s, c.Now(), false, nil
|
||||
c.SetTheme(theme(s.Palette))
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user