/** When a top-level scene has been completed, it unlocks more scenes of the same type. For example, when we complete scene "01", then the "plain/plain" GridMenu scene shows all of the numbered scenes in scene directory "plain". They are layed out as a grid. This menu is dynamically created (so just add a new Scene in the relevant directory, and it will appear in the grid. On the top-level Menu, we get to this GridMenu by clicking the "..." button. */ class GridMenu : Menu { var thumbX = 0.0 var thumbY = 0.0 @Attribute var prefix = "" @Attribute var count = 16 override fun activated() { super.activated() for (i in 1 until count ) { val foo = if (i < 10) "0$i" else "$i" createInGrid( prefix + foo ) } } fun createInGrid( sceneName : String ) { val gameInfo = Game.instance.resources.gameInfo val xMargin = 40 val width = (gameInfo.width - xMargin) / 4.0 - xMargin val height = gameInfo.height * width / gameInfo.width val yMargin = (gameInfo.height - height * 4) / 5 val left = xMargin + thumbX * (width + xMargin) val bottom = 20 + gameInfo.height - height - yMargin - thumbY * (height + yMargin) val button = createThumbButton( sceneName, left, bottom, width, height ) createLiveThumb( button ) thumbX ++ if (thumbX >= 4) { thumbX = 0 thumbY ++ } } fun createThumbButton( sceneName : String, left : double, bottom : double, width : double, height : double ) : ThumbButton { val button = ThumbButton() button.scene = sceneName val costume = Resources.instance.costumes.find( "thumbButton" ) val buttonA = Actor( costume, button ) buttonA.appearance = TiledAppearance( buttonA, costume.choosePose("default") ) buttonA.x = left buttonA.y = bottom //buttonA.appearance.size.x = width //buttonA.appearance.size.y = height buttonA.stage = Game.instance.scene.findStage( "menu" ) return button } }