/** * There are two kinds of menu. * A GridMenu, where the live thumbnails and buttons are generated in a grid. * A PrePlacedMenu, where the ThumbButtons have already been placed in the scene editor, * and the live thumbnails are added in the same place. * * This is the base class for both of these. */ class Menu : AbstractDirector { var horizontalClan = Clan.MO var verticalClan = Clan.MO var seconds = 0 // Only here, so that HighScore won't mind being on a Menu scene, rather than Play. var highScore = 0 var play : Play var resetMedals : Input override fun begin() { super.begin() resetMedals = Game.instance.resources.inputs.find( "resetMedals" ) DodgeEm.instance.menuName = Game.instance.sceneName } override fun onResize( event : ResizeEvent ) { // Don't try to rescale the view, just start the menu again! Game.instance.startScene( "menu" ) } override fun onKey ( event : KeyEvent ) { if (resetMedals.matches( event )) { DodgeEm.instance.resetMedals() } } fun play() = play fun createLiveThumb( thumbButton : ThumbButton ) : WrappedStageView { if (! thumbButton.isUnlocked() ) { return null } val sceneName = thumbButton.scene val game = Game.instance val mainStage = game.scene.findStage( "main" ) val glassStage = game.scene.findStage( "glass" ) play = Play() var sr : SceneResource try { sr = game.mergeScene( sceneName ) } catch ( e : Exception ) { return null } sr.directorAttributes.applyToObject(play) thumbButton.actor.color = sr.background.copy() val thumbStage = GameStage() val thumbView = WrappedStageView().apply { zOrder = 100 // Above all other views joinRight = game.resources.gameInfo.width joinTop = game.resources.gameInfo.height } thumbStage.addView(thumbView) game.scene.addView( "thumb-" + sceneName, thumbView ) game.scene.addStage( "thumb-" + sceneName, thumbStage ) // Move the actor from the main stage that were put there during game.mergeScene() moveActors( mainStage, thumbStage ) moveActors( glassStage, thumbStage ) val gameInfo = Game.instance.resources.gameInfo val mainView = Game.instance.scene.findStageView("main") val mainScale = mainView.scaleXY val window = Game.instance.window val thumbA = thumbButton.actor val left = thumbA.x * mainScale + mainView.rect.left val bottom = thumbA.y * mainScale + mainView.rect.bottom val width = 120 * mainView.scaleXY val height = width * gameInfo.height / gameInfo.width val scale = width / gameInfo.width thumbView.scaleXY = scale thumbView.rect = RectInt( left, bottom, (left + width), (bottom + height) ) return thumbView } fun moveActors( fromStage : Stage, thumbStage : GameStage ) { for (it in fromStage.actors.toList() ) { if ( it.role is Rock ) { it.stage = thumbStage (it.role as Rock).play = play } else if ( it.role is Edge ) { it.stage = thumbStage (it.role as Edge).updateClan() } else if ( it.role is ThumbButton ) { // Do nothing } else if ( it.role == null || it.role is NoRole ) { // Do nothing } else if ( it.role is Player ) { it.stage = thumbStage (it.role as Player).replaceAction( (it.role as Player).animationAction().forever() ) } else { it.die() } } } }