Add shop components 436-450; Odometer exact at 15 fps
Fifteen shop components: PriceTag, Wallet, ShopItem, Cart, Receipt, Checkout, CurrencyConvert, SaleBadge, Quantity, PricingTiers, Coupon, DailyReward, BidTicker, TradeWindow and VendingMachine. Receipt prints dot by dot with feed holes and a torn edge; Coupon cuts real notches; SaleBadge is a sixteen-point starburst; VendingMachine sells A1 to D4 by code and drops the snack into its tray. Sums are checked against overflow, TradeWindow withdraws both confirms on any change to an offer, and a disabled Checkout veils its inert content. text.Odometer now counts digits as text, steps at 15 fps as S5 asks, draws exact digits at rest and lands rolls that floats would stall.
This commit is contained in:
28 files changed
+2420
-9
No files matched your search
+15
-7
@@ -31,8 +31,9 @@ func Odometer(c *ui.Context, value int, o OdometerOptions) *ui.Element {
|
||||
panic(fmt.Sprintf("text: Odometer value %d is negative", value))
|
||||
}
|
||||
k := pixel.K(c)
|
||||
// Counted as text, so the largest int needs no float.
|
||||
digits := pixel.Or("Odometer Digits", o.Digits, len(strconv.Itoa(value)))
|
||||
if value >= int(math.Pow10(digits)) {
|
||||
if len(strconv.Itoa(value)) > digits {
|
||||
panic(fmt.Sprintf("text: Odometer value %d needs more than %d digits", value, digits))
|
||||
}
|
||||
h := pixel.LineHeight + 2
|
||||
@@ -43,20 +44,25 @@ func Odometer(c *ui.Context, value int, o OdometerOptions) *ui.Element {
|
||||
case k.Reduce() || st.shown == target:
|
||||
st.shown, st.last = target, -1
|
||||
default:
|
||||
tick := k.Tick(c, 30)
|
||||
// S5 caps steps at 15 fps; two rolls a step.
|
||||
tick := k.Tick(c, 15)
|
||||
if st.last >= 0 {
|
||||
for range tick - st.last {
|
||||
for range 2 * (tick - st.last) {
|
||||
st.shown = roll(st.shown, target)
|
||||
}
|
||||
}
|
||||
st.last = tick
|
||||
}
|
||||
shown := st.shown
|
||||
// At rest digits come from the int; floats would round.
|
||||
shown, settled, exact := st.shown, st.last < 0, fmt.Sprintf("%0*d", digits, value)
|
||||
return e.Draw(func(p *ui.Painter, r ui.Rect) {
|
||||
g := k.Canvas(p, r)
|
||||
for i := range digits {
|
||||
x := (digits - 1 - i) * odoCell
|
||||
d, frac := wheel(shown, i)
|
||||
d, frac := int(exact[digits-1-i]-'0'), 0.0
|
||||
if !settled {
|
||||
d, frac = wheel(shown, i)
|
||||
}
|
||||
g.Frame(x, 0, odoCell-1, h, pixel.Sunken, pixel.Well)
|
||||
g.Clip(x+2, 2, odoCell-5, h-4, func() {
|
||||
y := 1 - int(frac*float64(h))
|
||||
@@ -71,10 +77,12 @@ func Odometer(c *ui.Context, value int, o OdometerOptions) *ui.Element {
|
||||
func roll(shown, target float64) float64 {
|
||||
diff := target - shown
|
||||
stride := max(0.25, math.Abs(diff)/6)
|
||||
if math.Abs(diff) <= stride {
|
||||
// Near 2^53 a step may not move; then land.
|
||||
next := shown + math.Copysign(stride, diff)
|
||||
if math.Abs(diff) <= stride || next == shown {
|
||||
return target
|
||||
}
|
||||
return shown + math.Copysign(stride, diff)
|
||||
return next
|
||||
}
|
||||
|
||||
// wheel is digit i of shown and its roll.
|
||||
|
||||
Reference in new issue
Block a user