Get the bridge door animations running
This commit is contained in:
@@ -15,6 +15,7 @@ func init() {
|
||||
registerBuilder(menus.TypeHypertext, registerHypertext)
|
||||
registerBuilder(menus.TypeOverlay, registerOverlay)
|
||||
registerBuilder(menus.TypeAnimationSample, registerAnimation)
|
||||
registerBuilder(menus.TypeAnimationHover, registerDebug("WIP AnimationHover", registerAnimationHover))
|
||||
}
|
||||
|
||||
// A non-interactive element is not a widget; it merely displays some pixels and
|
||||
@@ -31,6 +32,17 @@ type noninteractive struct {
|
||||
hoverImpl
|
||||
}
|
||||
|
||||
// This particular animation has entry and exit sequences, which are invoked
|
||||
// when entering and leaving hover, respectively. Example: bridge doors
|
||||
type animationHover struct {
|
||||
noninteractive // Use the frames in here for the "enter hover" animation
|
||||
exitFrames animation // and here the "exit hover" animation
|
||||
|
||||
atTick int // Tracks progress through the frames
|
||||
opening bool
|
||||
closing bool
|
||||
}
|
||||
|
||||
func registerStatic(d *Driver, r *menus.Record) error {
|
||||
// FIXME: SpriteID takes precedence over SHARE if present, but is that right?
|
||||
spriteId := r.Share
|
||||
@@ -125,6 +137,38 @@ func registerAnimation(d *Driver, r *menus.Record) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func registerAnimationHover(d *Driver, r *menus.Record) error {
|
||||
sprite, err := d.menu.Sprite(r.SpriteId[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
enterFrames, err := d.menu.Images(r.SpriteId[0], r.DrawType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
exitFrames, err := d.menu.Images(r.SpriteId[0]+r.DrawType, r.DrawType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ani := &animationHover{
|
||||
noninteractive: noninteractive{
|
||||
frames: animation(enterFrames),
|
||||
hoverImpl: hoverImpl{text: r.Text},
|
||||
rect: sprite.Rect,
|
||||
},
|
||||
|
||||
exitFrames: animation(exitFrames),
|
||||
}
|
||||
|
||||
d.hoverables = append(d.hoverables, ani)
|
||||
d.paintables = append(d.paintables, ani)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *noninteractive) bounds() image.Rectangle {
|
||||
return n.rect
|
||||
}
|
||||
@@ -138,3 +182,35 @@ func (n *noninteractive) regions(tick int) []region {
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func (a *animationHover) regions(tick int) []region {
|
||||
if a.opening || a.closing {
|
||||
var anim animation
|
||||
if a.opening {
|
||||
anim = a.frames
|
||||
} else {
|
||||
anim = a.exitFrames
|
||||
}
|
||||
|
||||
out := oneRegion(a.bounds().Min, anim[a.atTick])
|
||||
|
||||
if a.atTick < len(anim)-1 {
|
||||
a.atTick += 1
|
||||
} else if !a.hoverState() {
|
||||
a.closing = false
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// Nothing doing, show a closed door
|
||||
return oneRegion(a.bounds().Min, a.frames.image(0))
|
||||
}
|
||||
|
||||
func (a *animationHover) setHoverState(value bool) {
|
||||
a.atTick = 0
|
||||
a.opening = value
|
||||
a.closing = !value
|
||||
|
||||
a.hoverImpl.setHoverState(value)
|
||||
}
|
||||
|
Reference in New Issue
Block a user