From 805cbf397589e5cb861f866713c2eb4bec9ce40b Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 8 Feb 2023 17:50:10 +0100 Subject: intermediate commit --- go/ui/prompt.go | 36 +++++------------------------------- go/ui/textBox.go | 2 +- 2 files changed, 6 insertions(+), 32 deletions(-) (limited to 'go/ui') diff --git a/go/ui/prompt.go b/go/ui/prompt.go index 1d552564..af5fca1d 100644 --- a/go/ui/prompt.go +++ b/go/ui/prompt.go @@ -1,63 +1,37 @@ package ui import ( - "log" - "github.com/hajimehoshi/ebiten/v2" "muhq.space/muhqs-game/go/game" ) -type promptType int - const ( - handCard promptType = iota - PROMPT_HEIGHT int = 50 ) type Prompt struct { - promptType promptType y, width int - sel []interface{} + action game.Action components []Widget } -func NewHandCardPrompt(y, width int, promptText string) *Prompt { +func NewPrompt(y, width int, action game.Action, promptText string) *Prompt { p := &Prompt{ y: y, width: width, - promptType: handCard, + action: action, components: []Widget{NewFixedTextBox(0, y, width, PROMPT_HEIGHT, promptText).Centering(true)}, } return p } func (p *Prompt) Add(obj interface{}) { - var ok bool - switch p.promptType { - case handCard: - _, ok = obj.(HandCard) - } - - if !ok { - log.Fatalf("Invalid type %T for prompt %d", obj, p.promptType) - } - - p.sel = append(p.sel, obj) + p.action.Targets().AddSelection(obj) } func (p *Prompt) Confirm() game.Action { - switch p.promptType { - case handCard: - cards := make([]*game.Card, 0, len(p.sel)) - for _, c := range p.sel { - cards = append(cards, c.(HandCard).C) - } - return game.NewHandCardSelection(cards) - } - - return nil + return p.action } func (p *Prompt) Height() int { diff --git a/go/ui/textBox.go b/go/ui/textBox.go index cc813a4e..7f1ab98c 100644 --- a/go/ui/textBox.go +++ b/go/ui/textBox.go @@ -64,7 +64,7 @@ func (tb *TextBox) Centering(centering bool) *TextBox { func NewUnitInfo(x, y int, u *game.Unit) *TextBox { info := fmt.Sprintf("%s\nDamage: %d\nHealth: %d\nUpkeep: %d", - u.String(), u.Damage(), u.Health, u.Upkeep) + u.String(), u.Damage(), u.Health, u.UpkeepCost()) if u.Movement != game.INVALID_MOVEMENT() { info = fmt.Sprintf("%s\nMovement: %s", info, u.Movement.String()) -- cgit v1.2.3