diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-02-14 09:52:22 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:50:09 +0200 |
| commit | 1ac413e1d0ddc39a41374ff9b3375e6de3e1af1c (patch) | |
| tree | 23f6a6475340ea52026d2dea117e33c28b3a9df1 | |
| parent | 97d5079e68624f842938e4c87386752f1cfda649 (diff) | |
| download | muhqs-game-1ac413e1d0ddc39a41374ff9b3375e6de3e1af1c.tar.gz muhqs-game-1ac413e1d0ddc39a41374ff9b3375e6de3e1af1c.zip | |
improve state bar
| -rw-r--r-- | go/client/startMenu.go | 5 | ||||
| -rw-r--r-- | go/game/player.go | 15 | ||||
| -rw-r--r-- | go/ui/colors.go | 5 | ||||
| -rw-r--r-- | go/ui/prompt.go | 2 | ||||
| -rw-r--r-- | go/ui/stateBar.go | 10 | ||||
| -rw-r--r-- | go/ui/textBox.go | 58 |
6 files changed, 58 insertions, 37 deletions
diff --git a/go/client/startMenu.go b/go/client/startMenu.go index 234a1570..8f149f8b 100644 --- a/go/client/startMenu.go +++ b/go/client/startMenu.go @@ -33,14 +33,13 @@ func NewStartMenu(app *app) *StartMenu { } func (m *StartMenu) build() { - playerLabel := ui.NewCenteringFixedTextBox( + playerLabel := ui.NewFixedTextBox( (m.width-START_BUTTON_WIDTH)/2-START_BUTTON_WIDTH, (m.height-START_BUTTON_HEIGHT)/2-START_BUTTON_HEIGHT, START_BUTTON_WIDTH, START_BUTTON_HEIGHT, "name:", - ) - playerLabel.Bg = color.Black + ).Centering(true).Bg(color.Black) m.widgets = append(m.widgets, playerLabel) playerInput := ui.NewTextInput( diff --git a/go/game/player.go b/go/game/player.go index cb89e1ae..78b4637e 100644 --- a/go/game/player.go +++ b/go/game/player.go @@ -52,6 +52,21 @@ func (p *Player) resourceGain() int { } } +func (p *Player) UpkeepGain() int { + return p.resourceGain() - p.UpkeepCost() +} + +func (p *Player) UpkeepCost() int { + cost := 0 + for _, u := range p.gameState.Units { + if u.Controller() != p { + continue + } + cost += u.Upkeep + } + return cost +} + func (p *Player) gainResource(gain int) { p.Resource += gain } diff --git a/go/ui/colors.go b/go/ui/colors.go index a45aa16b..3998e640 100644 --- a/go/ui/colors.go +++ b/go/ui/colors.go @@ -4,4 +4,7 @@ import ( "image/color" ) -var gray = color.RGBA{0x80, 0x80, 0x80, 0xff} +var ( + gray = color.RGBA{0x80, 0x80, 0x80, 0xff} + resourceBg = color.RGBA{230, 180, 128, 0xff} +) diff --git a/go/ui/prompt.go b/go/ui/prompt.go index bfcd5d14..1d552564 100644 --- a/go/ui/prompt.go +++ b/go/ui/prompt.go @@ -28,7 +28,7 @@ func NewHandCardPrompt(y, width int, promptText string) *Prompt { y: y, width: width, promptType: handCard, - components: []Widget{NewCenteringFixedTextBox(0, y, width, PROMPT_HEIGHT, promptText)}, + components: []Widget{NewFixedTextBox(0, y, width, PROMPT_HEIGHT, promptText).Centering(true)}, } return p } diff --git a/go/ui/stateBar.go b/go/ui/stateBar.go index 3b9407b5..b698100a 100644 --- a/go/ui/stateBar.go +++ b/go/ui/stateBar.go @@ -22,7 +22,7 @@ func NewStateBar(x, y int, width, height int, s *game.State, p *game.Player) *St } func (sb *StateBar) resourceLabel() string { - return fmt.Sprintf("%d", sb.activePlayer.Resource) + return fmt.Sprintf("%d/%+d", sb.activePlayer.Resource, sb.activePlayer.UpkeepGain()) } func (sb *StateBar) phaseLabel() string { @@ -32,14 +32,14 @@ func (sb *StateBar) phaseLabel() string { func (sb *StateBar) Draw(screen *ebiten.Image) { if sb.resourceView == nil { - sb.resourceView = NewCenteringFixedTextBox(sb.X, sb.Y, sb.Height, sb.Height, - sb.resourceLabel()) + sb.resourceView = NewFixedTextBox(sb.X, sb.Y, + sb.Height*2, sb.Height, sb.resourceLabel()).Centering(true).Bg(resourceBg) } sb.resourceView.Draw(screen) if sb.phaseView == nil { - sb.phaseView = NewFixedTextBox(sb.X+sb.resourceView.Width, sb.Y, - sb.Width-sb.resourceView.Width, sb.Height, sb.phaseLabel(), false) + sb.phaseView = NewFixedTextBox(sb.X+sb.Height*2, sb.Y, + sb.Width-sb.resourceView.Width, sb.Height, sb.phaseLabel()) } sb.phaseView.Draw(screen) } diff --git a/go/ui/textBox.go b/go/ui/textBox.go index 58a3e679..1c82a307 100644 --- a/go/ui/textBox.go +++ b/go/ui/textBox.go @@ -12,46 +12,54 @@ import ( ) var ( - TEXTBOX_DEFAULT_BACKGROUND = gray + TEXTBOX_DEFAULT_BACKGROUND = color.Black TEXTBOX_DEFAULT_FOREGROUND = color.White TEXTBOX_DEFAULT_MARGIN = 3 + + TEXTBOX_AUTO_DIMENSION = -1 ) type TextBox struct { WidgetBase text string - Fg color.Color - Bg color.Color + fg color.Color + bg color.Color XMargin int YMargin int - Center bool + center bool } -func NewFixedTextBox(x, y int, width, height int, t string, center bool) *TextBox { +func NewFixedTextBox(x, y int, width, height int, t string) *TextBox { tb := &TextBox{ WidgetBase: NewWidgetBase(x, y, width, height), text: t, - Fg: TEXTBOX_DEFAULT_FOREGROUND, - Bg: TEXTBOX_DEFAULT_BACKGROUND, + fg: TEXTBOX_DEFAULT_FOREGROUND, + bg: TEXTBOX_DEFAULT_BACKGROUND, XMargin: TEXTBOX_DEFAULT_MARGIN, YMargin: TEXTBOX_DEFAULT_MARGIN, - Center: center, } tb.renderImpl = func() *ebiten.Image { return tb.render() } return tb } -func NewCenteringFixedTextBox(x, y int, width, height int, t string) *TextBox { - return NewFixedTextBox(x, y, width, height, t, true) +func NewAutoTextBox(x, y int, text string) *TextBox { + return NewFixedTextBox(x, y, TEXTBOX_AUTO_DIMENSION, TEXTBOX_AUTO_DIMENSION, text) } -func NewAutoTextBox(x, y int, t string) *TextBox { - return NewFixedTextBox(x, y, -1, -1, t, false) +func (tb *TextBox) Bg(bg color.Color) *TextBox { + tb.bg = bg + return tb } -func NewCenteringAutoTextBox(x, y int, t string) *TextBox { - return NewFixedTextBox(x, y, -1, -1, t, true) +func (tb *TextBox) Fg(fg color.Color) *TextBox { + tb.fg = fg + return tb +} + +func (tb *TextBox) Centering(centering bool) *TextBox { + tb.center = centering + return tb } func NewUnitInfo(x, y int, u *game.Unit) *TextBox { @@ -90,7 +98,7 @@ func (tb *TextBox) render() *ebiten.Image { x = tb.XMargin + b.Min.X y = tb.YMargin - b.Min.Y } else { - if !tb.Center { + if !tb.center { x = tb.XMargin + b.Min.X } else { x = tb.Width/2 - centerTextXOffset(b) @@ -100,8 +108,8 @@ func (tb *TextBox) render() *ebiten.Image { } img := ebiten.NewImage(tb.Width, tb.Height) - img.Fill(tb.Bg) - text.Draw(img, tb.text, font.Font24, x, y, tb.Fg) + img.Fill(tb.bg) + text.Draw(img, tb.text, font.Font24, x, y, tb.fg) return img } @@ -114,15 +122,7 @@ type PocList struct { func NewPocList(centerX, bottomY int, poc game.PileOfCards) *PocList { w := &PocList{ - TextBox: TextBox{ - WidgetBase: NewWidgetBase(-1, -1, -1, -1), - text: "", - Fg: TEXTBOX_DEFAULT_FOREGROUND, - Bg: TEXTBOX_DEFAULT_BACKGROUND, - XMargin: TEXTBOX_DEFAULT_MARGIN, - YMargin: TEXTBOX_DEFAULT_MARGIN, - Center: true, - }, + TextBox: *(NewAutoTextBox(-1, -1, "").Centering(true)), centerX: centerX, bottomY: bottomY, poc: poc, @@ -169,7 +169,11 @@ type TextInput struct { } func NewTextInput(x, y int, width, height int, label string) *TextInput { - w := &TextInput{*NewCenteringFixedTextBox(x, y, width, height, ""), "", label} + w := &TextInput{ + TextBox: *(NewFixedTextBox(x, y, width, height, "").Centering(true)), + input: "", + label: label, + } w.renderImpl = func() *ebiten.Image { if w.input == "" { |
