package ui import ( "image/color" "github.com/hajimehoshi/ebiten/v2" "muhq.space/muhqs-game/go/game" ) const ( PROMPT_HEIGHT int = 50 ) type Prompt struct { EventHandlersMap y, width int action game.Action components []Widget cancelable bool } func NewPrompt(y, width int, action game.Action, promptText string) *Prompt { p := &Prompt{ EventHandlersMap: NewEventHandlersMap(), y: y, width: width, action: action, components: []Widget{NewFixedTextBox(0, y, width, PROMPT_HEIGHT, promptText).Centering(true)}, } p.RegisterHandler("hover", p.Hover) return p } func NewCancelablePrompt(y, width int, action game.Action, promptText string) *Prompt { p := NewPrompt(y, width, action, promptText) p.cancelable = true return p } func (p *Prompt) Cancelable() bool { return p.cancelable } func (p *Prompt) Action() game.Action { return p.action } func (p *Prompt) Add(obj any) error { if handCard, ok := obj.(HandCard); ok { obj = handCard.C } return p.action.Targets().AddSelection(obj) } func (p *Prompt) Height() int { return PROMPT_HEIGHT } func (p *Prompt) ClearSelections() { p.action.Targets().ClearSelections() } 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) any { return nil } func (*Prompt) Render(Widget) *ebiten.Image { return nil } func (p *Prompt) setTextBgAlpha(alpha uint8) { for _, comp := range p.components { textBox, ok := comp.(*TextBox) if !ok { continue } bg := color.RGBAModel.Convert(textBox.bg).(color.RGBA) bg.A = alpha textBox.Bg(bg) textBox.ForceRedraw() } } func (p *Prompt) Hover(hover bool, x int, y int) { if hover { p.setTextBgAlpha(0x7f) } else { p.setTextBgAlpha(0xff) } } func (p *Prompt) Layout() (int, int) { return p.width, PROMPT_HEIGHT }