Files
8bitMyGoUI/game/loadingtips.go
T
ZacharyZhang-NY 86a6901333 Add game components 269-290; CommandMenu AutoFocus
Press start, title screen, save slots, options menu, game over with
CONTINUE, credits roll, ending card, loading tips, letterbox, mission
brief, achievements, result screen, crafting grid, loot popup,
treasure chest, gacha reel, interact prompt, turn order, battle log,
target selector, ATB gauge and stamina bar. Cued effects count runs,
so each cue change plays once and reports once. CommandMenu takes
AutoFocus when enabled. HealthBar, ManaBar and CountUp keep exact
colors, ticks and counts for the largest ints.
2026-10-12 02:48:20 -04:00

45 lines
1.4 KiB
Go

package game
import (
"time"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/feedback"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type LoadingTipsOptions struct {
// Width is in dots; zero means 200.
Width int
}
// tipTurn is how long a tip shows.
const tipTurn = 4 * time.Second
// LoadingTips turns tips every 4 s under a progress bar.
func LoadingTips(c *ui.Context, tips []string, value float64, o LoadingTipsOptions) *ui.Element {
k := pixel.K(c)
w := pixel.Or("LoadingTips Width", o.Width, 200)
if len(tips) == 0 {
panic("game: LoadingTips has no tips")
}
// Tips turn on the wall clock, like a loader's dots.
now := k.Now()
turn := now.Truncate(tipTurn)
k.At(c, turn.Add(tipTurn))
tip := tips[int(turn.Unix()/int64(tipTurn/time.Second))%len(tips)]
name := k.Msg("tip")
return ui.Column(c).Gap(k.D(6)).Width(k.D(w)).Children(func() {
feedback.Progress(c, k.Msg("loading"), value, feedback.ProgressOptions{Width: w - 4 - pixel.MicroWidth("100%"), Percent: true})
lines := pixel.Wrap(tip, w-tagW(name)-4, 3)
ui.Box(c).Role(ui.RoleStatus).Label(name+": "+tip).Size(k.D(w), k.D(len(lines)*pixel.LineHeight)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
tag(g, 0, 3, name, pixel.Accent)
for i, l := range lines {
g.Text(tagW(name)+4, i*pixel.LineHeight, l, pixel.Faint, 1)
}
})
})
}