aboutsummaryrefslogtreecommitdiff
path: root/go/ui
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-01-25 21:10:44 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:44 +0100
commit8720ebf9c74d9e11001772b5c00c293fa3a8b9e5 (patch)
tree70013771c425746318d290b5cadad0bbc1a48abb /go/ui
parent73d40903aecad3efcf7c6055c133f0db86558203 (diff)
downloadmuhqs-game-8720ebf9c74d9e11001772b5c00c293fa3a8b9e5.tar.gz
muhqs-game-8720ebf9c74d9e11001772b5c00c293fa3a8b9e5.zip
intermediate commit
Diffstat (limited to 'go/ui')
-rw-r--r--go/ui/hand.go24
-rw-r--r--go/ui/stateBar.go23
-rw-r--r--go/ui/textBox.go4
3 files changed, 35 insertions, 16 deletions
diff --git a/go/ui/hand.go b/go/ui/hand.go
index 0fdde253..b07d177b 100644
--- a/go/ui/hand.go
+++ b/go/ui/hand.go
@@ -8,47 +8,47 @@ import (
"muhq.space/muhqs-game/go/game"
)
-const (
- HAND_CARD_WIDTH = 200
-)
-
type HandCard struct {
C *game.Card
}
type HandView struct {
WidgetBase
- hand *game.Hand
- scale float64
+ hand *game.Hand
+ cardWidth float64
+ scale float64
}
func NewHandView(x, y, width, height int, h *game.Hand) *HandView {
- hv := &HandView{NewWidgetBase(x, y, width, height), h, -1}
+ hv := &HandView{NewWidgetBase(x, y, width, height), h, 0, 0}
hv.renderImpl = func() *ebiten.Image { return hv.render() }
return hv
}
func (hv *HandView) render() *ebiten.Image {
img := ebiten.NewImage(hv.Width, hv.Height)
- for i, card := range hv.hand.GetCards() {
+ handCards := hv.hand.GetCards()
+ nHandCards := len(handCards)
+ for i, card := range handCards {
cardImg := assets.GetCard(card.Path(), "en")
if cardImg == nil {
log.Fatalf("No image found for %s", card.Path())
}
- if hv.scale == -1 {
+ if hv.scale == 0 {
b := cardImg.Bounds()
- x_scale := float64(HAND_CARD_WIDTH) / float64(b.Dx())
+ x_scale := (float64(hv.Width) / float64(nHandCards)) / float64(b.Dx())
y_scale := float64(hv.Height) / float64(b.Dy())
hv.scale = x_scale
if y_scale < x_scale {
hv.scale = y_scale
}
+ hv.cardWidth = float64(b.Dx()) * hv.scale
}
op := &ebiten.DrawImageOptions{}
op.GeoM.Scale(hv.scale, hv.scale)
- op.GeoM.Translate(float64(i*HAND_CARD_WIDTH), 0)
+ op.GeoM.Translate(float64(i)*hv.cardWidth, 0)
img.DrawImage(cardImg, op)
}
return img
@@ -59,7 +59,7 @@ func (hv *HandView) FindObjectAt(x, y int) interface{} {
return nil
}
- i := x / HAND_CARD_WIDTH
+ i := int(float64(x) / hv.cardWidth)
if i >= hv.hand.Size() {
return nil
}
diff --git a/go/ui/stateBar.go b/go/ui/stateBar.go
index e175c0c5..d7d86ea9 100644
--- a/go/ui/stateBar.go
+++ b/go/ui/stateBar.go
@@ -7,16 +7,21 @@ import (
"muhq.space/muhqs-game/go/game"
)
+const (
+ PHASE_VIEW_WIDTH = 250
+)
+
type StateBar struct {
X, Y int
Width, Height int
gameState *game.State
activePlayer *game.Player
ressourceView *TextBox
+ phaseView *TextBox
}
func NewStateBar(x, y int, width, height int, s *game.State, p *game.Player) *StateBar {
- sb := &StateBar{x, y, width, height, s, p, nil}
+ sb := &StateBar{x, y, width, height, s, p, nil, nil}
return sb
}
@@ -24,12 +29,23 @@ func (sb *StateBar) ressourceLabel() string {
return fmt.Sprintf("%d", sb.activePlayer.Ressource)
}
+func (sb *StateBar) phaseLabel() string {
+ return fmt.Sprintf("%s: %s", sb.gameState.Players[sb.gameState.ActivePlayerId].Name,
+ sb.gameState.ActivePhase.String())
+}
+
func (sb *StateBar) Draw(screen *ebiten.Image) {
if sb.ressourceView == nil {
- sb.ressourceView = NewFixedTextBox(sb.X, sb.Y+sb.Height-sb.Width, sb.Width, sb.Width,
+ sb.ressourceView = NewFixedTextBox(sb.X, sb.Y, sb.Height, sb.Height,
sb.ressourceLabel())
}
sb.ressourceView.Draw(screen)
+
+ if sb.phaseView == nil {
+ sb.phaseView = NewFixedTextBox(sb.X+sb.ressourceView.Width, sb.Y,
+ PHASE_VIEW_WIDTH, sb.Height, sb.phaseLabel())
+ }
+ sb.phaseView.Draw(screen)
}
func (sb *StateBar) FindObjectAt(x, y int) interface{} {
@@ -39,4 +55,7 @@ func (sb *StateBar) FindObjectAt(x, y int) interface{} {
func (sb *StateBar) ForceRedraw() {
sb.ressourceView.Text = sb.ressourceLabel()
sb.ressourceView = nil
+
+ sb.phaseView.Text = sb.phaseLabel()
+ sb.phaseView = nil
}
diff --git a/go/ui/textBox.go b/go/ui/textBox.go
index 5e2d140b..0cd09294 100644
--- a/go/ui/textBox.go
+++ b/go/ui/textBox.go
@@ -33,8 +33,8 @@ func NewAutoTextBox(x, y int, t string) *TextBox {
}
func NewUnitInfo(x, y int, u *game.Unit) *TextBox {
- info := fmt.Sprintf("%s\nDamage: %d\nHealth: %d\nMovement: %d\nAttack %s\nUpkeep: %d",
- u.String(), u.GetDamage(), u.Health, u.Movement, u.Attack.String(), u.Upkeep)
+ info := fmt.Sprintf("%s\nDamage: %d\nHealth: %d\nMovement: %s\nAttack %s\nUpkeep: %d",
+ u.String(), u.GetDamage(), u.Health, u.Movement.String(), u.Attack.String(), u.Upkeep)
return NewAutoTextBox(x, y, info)
}