class InfoAnimation( val actor : Actor, val showInSeconds : double, val hideAfterSeconds : double, val duration : double ) { var initialScale = actor.scaleXY init { // Hide it. Move it below the bottom of the screen. actor.y -= actor.stage.firstView().worldHeight actor.scaleXY = 0.1 } fun createAction() : Action { return if (showInSeconds < 0 ) { null } else { val show = Delay( showInSeconds ) then showAction() if (hideAfterSeconds > 0) { show then Delay( hideAfterSeconds ) then hideAction() } else { show } } } /** Some Info are not displayed when the scene is loaded. For example, the tutorial can display message(s) when the exit gate is open. See Play.showInfo() and Play.checkCargo(). */ fun show() { actor.scaleXY = 0.1 (actor.role as ActionRole).replaceAction( showAction() ) } /** The action to animate the appeaance of this Info. Scales the Actor to [initialScale] at the same time moving the Info into place. */ fun showAction() : Action { return MoveBy( actor.position, duration, Vector2(0, actor.stage.firstView().worldHeight), Eases.easeOutBack ) and ScaleTo( actor, duration, initialScale ) } fun hideAction() : Action { return MoveBy( actor.position, duration, Vector2(0, -actor.stage.firstView().worldHeight), Eases.easeIn ) and ScaleTo( actor, duration, 0.1 ) } } /** Text which is initially hidden. If [showInSeconds] >= 0, then the message will automatically appear soon after the scene is loaded. If [showInSeconds] < 0 then this Info will only appear when show() is called. These should be placed on the glass stage. */ class Info : ActionRole() { @Attribute var event = "" @Attribute var showInSeconds = -1.0 @Attribute var hideAfterSeconds = 5.0 @Attribute var duration = 1.0 var animation : InfoAnimation override fun createAction() : Action { animation = InfoAnimation( actor, showInSeconds, hideAfterSeconds, duration ) return animation.createAction() } fun show() { animation.show() } } class AnnimatedOptionButton : Button, OptionButtonRole { @Attribute var showInSeconds = -1.0 @Attribute var duration = 1.0 val handler = OptionButtonHandler( this ) override fun getHandler() = handler override fun onClicked(event:MouseEvent) { handler.onClicked() } override fun createAction() : Action { return InfoAnimation( actor, showInSeconds, 0, duration ).createAction() } }