Fifteen pieces of a games night: Dice, DiceTray, PlayingCard, CardHand, Deck, Chessboard, GoBoard, MahjongTile, Domino, Roulette, CoinFlip, BingoCard, TicTacToe, ScoreTrack and Meeple. Component number 500 is a meeple, which seems right. Dice tumble, coins turn and wheels spin on a cue, a frame at a time, and land at once under Reduce Motion. Hands lift the card you point at and play the one drawn on top; pieces and stones pick the lighter of Lit and Ink for White, so they read in every palette; the computer plays a fair O; FREE is a star in every language. New 12x12 icons: Spade, Club, Diamond, Meeple, King, Queen, Rook, Bishop, Knight and Pawn.
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package tabletop
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type DiceTrayOptions struct {
|
|
// Cue rolls them all, as Dice's Cue does.
|
|
Cue int
|
|
}
|
|
|
|
// DiceTray holds several dice on felt, and their total.
|
|
func DiceTray(c *ui.Context, text string, values []int, o DiceTrayOptions) *ui.Element {
|
|
k := pixel.K(c)
|
|
if len(values) == 0 {
|
|
panic("tabletop: DiceTray has no dice")
|
|
}
|
|
total := 0
|
|
for _, v := range values {
|
|
total += v
|
|
}
|
|
sum := fmt.Sprintf("%s %d", k.Msg("total"), total)
|
|
return ui.Column(c).Gap(k.D(4)).AlignItems(ui.Center).AlignSelf(ui.Start).Role(ui.RoleGroup).Label(text).Description(sum).Children(func() {
|
|
ui.Row(c).Gap(k.D(2)).Padding(k.D(6)).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
g.Frame(0, 0, g.W, g.H, pixel.Sunken, pixel.Good)
|
|
g.Veil(2, 2, g.W-4, g.H-4, pixel.Shade, 4)
|
|
}).Children(func() {
|
|
for i, v := range values {
|
|
Dice(c, fmt.Sprintf("%s %d", text, i+1), v, DiceOptions{Cue: o.Cue})
|
|
}
|
|
})
|
|
pixel.Text(c, sum, pixel.TextOptions{})
|
|
})
|
|
}
|