package game import ( "image/color" "openquell/assets" "github.com/ebitenui/ebitenui" "github.com/ebitenui/ebitenui/image" "github.com/ebitenui/ebitenui/widget" "github.com/hajimehoshi/ebiten/v2" ) type SelectScene struct { Game *Game Next SceneName Whoami SceneName UseCache bool Ui *ebitenui.UI } func NewSelectScene(game *Game) Scene { scene := &SelectScene{Whoami: Select, Game: game, Next: Select} scene.SetupUI() return scene } func (scene *SelectScene) GetNext() SceneName { return scene.Next } func (scene *SelectScene) SetNext(next SceneName) { scene.Next = next } func (scene *SelectScene) Update() error { scene.Ui.Update() return nil } func (scene *SelectScene) Draw(screen *ebiten.Image) { scene.Ui.Draw(screen) } func (scene *SelectScene) SetupUI() { buttonImage, _ := loadButtonImage() btnContainer := widget.NewContainer( widget.ContainerOpts.Layout(widget.NewAnchorLayout()), ) button := widget.NewButton( widget.ButtonOpts.WidgetOpts( widget.WidgetOpts.LayoutData(widget.AnchorLayoutData{ HorizontalPosition: widget.AnchorLayoutPositionCenter, VerticalPosition: widget.AnchorLayoutPositionCenter, }), ), widget.ButtonOpts.Image(buttonImage), widget.ButtonOpts.Text("Start new Game", *assets.FontRenderer.FontNormal, &widget.ButtonTextColor{ Idle: color.NRGBA{0xdf, 0xf4, 0xff, 0xff}, }), widget.ButtonOpts.TextPadding(widget.Insets{ Left: 30, Right: 30, Top: 5, Bottom: 5, }), widget.ButtonOpts.ClickedHandler(func(args *widget.ButtonClickedEventArgs) { scene.SetNext(Play) }), ) btnContainer.AddChild(button) rootContainer := widget.NewContainer( widget.ContainerOpts.BackgroundImage( image.NewNineSlice(assets.Assets["background-transparent"], [3]int{0, 1, 639}, [3]int{0, 1, 479})), //widget.ContainerOpts.BackgroundImage(image.NewNineSliceColor(color.NRGBA{0x13, 0x1a, 0x22, 0xff})), //widget.ContainerOpts.BackgroundImage(image.NewNineSliceColor(color.NRGBA{0xff, 0x80, 0x00, 0x00})), widget.ContainerOpts.Layout( widget.NewStackedLayout( widget.StackedLayoutOpts.Padding( widget.NewInsetsSimple(25)))), ) rootContainer.AddChild(btnContainer) scene.Ui = &ebitenui.UI{ Container: rootContainer, } } func loadButtonImage() (*widget.ButtonImage, error) { idle := image.NewNineSliceColor(color.NRGBA{R: 170, G: 170, B: 180, A: 255}) hover := image.NewNineSliceColor(color.NRGBA{R: 130, G: 130, B: 150, A: 255}) pressed := image.NewNineSliceColor(color.NRGBA{R: 100, G: 100, B: 120, A: 255}) return &widget.ButtonImage{ Idle: idle, Hover: hover, Pressed: pressed, }, nil }