diff options
Diffstat (limited to 'go/ui/hand.go')
| -rw-r--r-- | go/ui/hand.go | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/go/ui/hand.go b/go/ui/hand.go index b07d177b..5421f6fb 100644 --- a/go/ui/hand.go +++ b/go/ui/hand.go @@ -6,6 +6,8 @@ import ( "github.com/hajimehoshi/ebiten/v2" "muhq.space/muhqs-game/go/assets" "muhq.space/muhqs-game/go/game" + + "golang.org/x/exp/slices" ) type HandCard struct { @@ -14,13 +16,24 @@ type HandCard struct { type HandView struct { WidgetBase - hand *game.Hand - cardWidth float64 - scale float64 + hand *game.Hand + cardWidth float64 + cardHeight float64 + scale float64 + bottomAligned bool + highlights []*game.Card } -func NewHandView(x, y, width, height int, h *game.Hand) *HandView { - hv := &HandView{NewWidgetBase(x, y, width, height), h, 0, 0} +func NewHandView(x, y, width, height int, h *game.Hand, bottomAligned bool) *HandView { + hv := &HandView{ + WidgetBase: NewWidgetBase(x, y, width, height), + hand: h, + cardWidth: 0, + cardHeight: 0, + scale: 0, + bottomAligned: bottomAligned, + highlights: []*game.Card{}, + } hv.renderImpl = func() *ebiten.Image { return hv.render() } return hv } @@ -44,11 +57,22 @@ func (hv *HandView) render() *ebiten.Image { hv.scale = y_scale } hv.cardWidth = float64(b.Dx()) * hv.scale + hv.cardHeight = float64(b.Dy()) * hv.scale + } + + yOffset := 0.0 + if hv.bottomAligned { + yOffset = float64(hv.Height) - hv.cardHeight } op := &ebiten.DrawImageOptions{} op.GeoM.Scale(hv.scale, hv.scale) - op.GeoM.Translate(float64(i)*hv.cardWidth, 0) + op.GeoM.Translate(float64(i)*hv.cardWidth, yOffset) + + if slices.Contains(hv.highlights, card) { + op.ColorM.Scale(1, 0, 0, 0.5) + } + img.DrawImage(cardImg, op) } return img @@ -59,6 +83,10 @@ func (hv *HandView) FindObjectAt(x, y int) interface{} { return nil } + if hv.bottomAligned && float64(y-hv.Y) < float64(hv.Height)-hv.cardHeight { + return nil + } + i := int(float64(x) / hv.cardWidth) if i >= hv.hand.Size() { return nil @@ -66,3 +94,16 @@ func (hv *HandView) FindObjectAt(x, y int) interface{} { return HandCard{hv.hand.GetCards()[i]} } + +func (hv *HandView) setHighlights(cards []*game.Card) { + hv.highlights = cards + hv.ForceRedraw() +} + +func (hv *HandView) HighlightCard(card *game.Card) { + hv.setHighlights([]*game.Card{card}) +} + +func (hv *HandView) ClearHighlights() { + hv.setHighlights([]*game.Card{}) +} |
