Make animations work in the options screen

This commit is contained in:
2020-03-23 00:33:29 +00:00
parent c67ee206cd
commit bcee07e8f7
11 changed files with 172 additions and 86 deletions

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"image"
"log"
"reflect" // For DeepEqual
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
@@ -23,7 +22,7 @@ import (
type Interface struct {
Name string
menu *assetstore.Menu
static []*staticElement
static []*noninteractive
ticks int
widgets []*Widget
}
@@ -44,14 +43,14 @@ func NewInterface(menu *assetstore.Menu) (*Interface, error) {
}
// Find a widget by its hierarchical ID path
func (i *Interface) Widget(path ...int) (*Widget, error) {
func (i *Interface) Widget(path string) (*Widget, error) {
for _, widget := range i.widgets {
if reflect.DeepEqual(path, widget.path) {
if path == widget.path {
return widget, nil
}
}
return nil, fmt.Errorf("Couldn't find widget %#+v", path)
return nil, fmt.Errorf("Couldn't find widget %v", path)
}
func (i *Interface) Update(screenX, screenY int) error {
@@ -82,9 +81,9 @@ func (i *Interface) Draw(screen *ebiten.Image) error {
do := &ebiten.DrawImageOptions{GeoM: geo}
for _, s := range i.static {
if s.image != nil {
do.GeoM.Translate(geo.Apply(float64(s.bounds.Min.X), float64(s.bounds.Min.X)))
if err := screen.DrawImage(s.image, do); err != nil {
if image := s.image(i.ticks); image != nil {
do.GeoM.Translate(geo.Apply(float64(s.bounds.Min.X), float64(s.bounds.Min.Y)))
if err := screen.DrawImage(image, do); err != nil {
return err
}
do.GeoM = geo