diff options
Diffstat (limited to 'go/ui/prompt.go')
| -rw-r--r-- | go/ui/prompt.go | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/go/ui/prompt.go b/go/ui/prompt.go new file mode 100644 index 00000000..bfcd5d14 --- /dev/null +++ b/go/ui/prompt.go @@ -0,0 +1,78 @@ +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{} + components []Widget +} + +func NewHandCardPrompt(y, width int, promptText string) *Prompt { + p := &Prompt{ + y: y, + width: width, + promptType: handCard, + components: []Widget{NewCenteringFixedTextBox(0, y, width, PROMPT_HEIGHT, promptText)}, + } + 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) +} + +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 +} + +func (p *Prompt) Height() int { + return PROMPT_HEIGHT +} + +func (p *Prompt) Draw(screen *ebiten.Image) { + for _, comp := range p.components { + comp.Draw(screen) + } +} + +func (p *Prompt) Contains(x, y int) bool { + return x >= 0 && y >= 0 && x <= p.width && y >= p.y && y <= p.y+PROMPT_HEIGHT +} + +func (p *Prompt) FindObjectAt(screenX, screenY int) interface{} { return nil } +func (*Prompt) Render(Widget) *ebiten.Image { return nil } |
