package ui import ( "fmt" "github.com/hajimehoshi/ebiten/v2" "muhq.space/muhqs-game/go/game" "muhq.space/muhqs-game/go/utils" ) type Choice struct { TextBox choices []interface{} onClick func(*Choice, int, int) } func NewChoice(x, y int, choices []interface{}, onClick func(*Choice, int, int)) *Choice { c := &Choice{ TextBox: *(NewAutoTextBox(x, y, "")), choices: choices, onClick: onClick, } c.renderImpl = func() *ebiten.Image { c.setText() return c.render() } return c } func (c *Choice) setText() { c.Width, c.Height = -1, -1 t := "" for _, choice := range c.choices { t = fmt.Sprintf("%s%v\n", t, choice) } c.text = t[:len(t)-1] } func (c *Choice) GetChoosen(x, y int) int { i := (y - c.Y) / (c.Height / len(c.choices)) return i } func (c *Choice) Click(x, y int) { c.onClick(c, x, y) } func NewActionChoice(x, y int, actions []game.Action, onClick func(*Choice, int, int)) *Choice { return NewChoice(x, y, utils.TypedSliceToInterfaceSlice(actions), onClick) } func NewPermChoice(x, y int, perms []game.Permanent, onClick func(*Choice, int, int)) *Choice { return NewChoice(x, y, utils.TypedSliceToInterfaceSlice(perms), onClick) }