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

@@ -17,7 +17,7 @@ var setupHandlers = map[menus.MenuType]func(i *Interface, r *menus.Record) error
menus.TypeOverlay: nil, // FIXME: What's it for?
menus.TypeHypertext: handleHypertext,
menus.TypeCheckbox: handleCheckbox,
menus.TypeAnimationSample: nil, // FIXME: handle this
menus.TypeAnimationSample: handleAnimation,
menus.TypeMainButton: handleMainButton,
menus.TypeSlider: nil, // FIXME: handle this
}
@@ -35,9 +35,9 @@ func handleStatic(i *Interface, record *menus.Record) error {
return err
}
static := &staticElement{
static := &noninteractive{
bounds: sprite.Rect,
image: sprite.Image,
frames: animation{sprite.Image},
tooltip: record.Desc,
}
@@ -54,9 +54,9 @@ func handleHypertext(i *Interface, record *menus.Record) error {
return err
}
static := &staticElement{
static := &noninteractive{
bounds: sprite.Rect,
image: nil,
frames: nil,
tooltip: record.Desc,
}
@@ -106,6 +106,29 @@ func handleCheckbox(i *Interface, record *menus.Record) error {
return nil
}
// An animation is a non-interactive element that displays something in a loop
func handleAnimation(i *Interface, record *menus.Record) error {
sprite, err := i.menu.Sprite(record.SpriteId[0])
if err != nil {
return err
}
frames, err := i.menu.Images(record.SpriteId[0], record.DrawType)
if err != nil {
return err
}
ani := &noninteractive{
bounds: sprite.Rect,
frames: animation(frames),
tooltip: record.Desc,
}
i.static = append(i.static, ani)
return nil
}
func handleButton(i *Interface, record *menus.Record) error {
spriteId := record.SpriteId[0]
widget, err := i.widgetFromRecord(record, spriteId)
@@ -179,7 +202,7 @@ func handleMainButton(i *Interface, record *menus.Record) error {
widget.mouseButtonDownImage = pressed.Image
widget.disabledImage = disabled.Image
widget.hoverAnimation = hovers
widget.hoverAnimation = animation(hovers)
i.widgets = append(i.widgets, widget)
@@ -194,15 +217,10 @@ func (i *Interface) widgetFromRecord(record *menus.Record, spriteId int) (*Widge
return nil, err
}
var path []int
for r := record; r != nil; r = r.Parent {
path = append([]int{r.Id}, path...)
}
widget := &Widget{
Bounds: sprite.Rect,
Tooltip: record.Desc,
path: path,
path: record.Path(),
record: record,
sprite: sprite,
}