| 1 | class MainMenu extends BaseMenu |
| 2 | { |
| 3 | static Instance; |
| 4 | |
| 5 | buttons = []; |
| 6 | buttonPadding = 10; |
| 7 | buttonXOffset = -32; |
| 8 | |
| 9 | openTargetX = 60; |
| 10 | |
| 11 | closedTargetX = -15; |
| 12 | |
| 13 | constructor (sx, sy, ex, ey, sprite, layer, tOpen, tClose) |
| 14 | { |
| 15 | super(sx, sy, ex, ey, sprite, layer, tOpen, tClose); |
| 16 | MainMenu.Instance = this; |
| 17 | } |
| 18 | |
| 19 | addedToScene () |
| 20 | { |
| 21 | super.addedToScene(); |
| 22 | |
| 23 | this.initialiseChildren(); |
| 24 | |
| 25 | this.moveSelfOnOpen(); |
| 26 | this.moveSelfOnClose(); |
| 27 | |
| 28 | this.open(() => this.close(), this); |
| 29 | } |
| 30 | |
| 31 | initialiseChildren () |
| 32 | { |
| 33 | let vectorOrigin = this.getNextOriginPosition(); |
| 34 | this.addChildButton("btnFruit", this.scene.addObject(new BtnFruit(vectorOrigin.x, vectorOrigin.y, this.targetPosition.x + this.buttonXOffset, vectorOrigin.y, this.scene.game.images.btnFruit, 4))); |
| 35 | |
| 36 | vectorOrigin = this.getNextOriginPosition(); |
| 37 | this.addChildButton("btnToys", this.scene.addObject(new BtnToys(vectorOrigin.x, vectorOrigin.y, this.targetPosition.x + this.buttonXOffset, vectorOrigin.y, this.scene.game.images.btnToys, 4))); |
| 38 | |
| 39 | vectorOrigin = this.getNextOriginPosition(); |
| 40 | this.addChildButton("btnGames", this.scene.addObject(new BtnGames(vectorOrigin.x, vectorOrigin.y, this.targetPosition.x + this.buttonXOffset, vectorOrigin.y, this.scene.game.images.btnGames, 4))); |
| 41 | |
| 42 | vectorOrigin = this.getNextOriginPosition(); |
| 43 | this.addChildButton("btnPlants", this.scene.addObject(new BtnPlants(vectorOrigin.x, vectorOrigin.y, this.targetPosition.x + this.buttonXOffset, vectorOrigin.y, this.scene.game.images.btnPlants, 4)) |
| 44 | ); |
| 45 | |
| 46 | } |
| 47 | |
| 48 | getNextOriginPosition () |
| 49 | { |
| 50 | if (this.children.length == 0) |
| 51 | { |
| 52 | return new vector(this.transform.position.x + this.buttonXOffset, this.transform.position.y + this.transform.size.y + this.buttonPadding); |
| 53 | } |
| 54 | else |
| 55 | { |
| 56 | return new vector(this.transform.position.x + this.buttonXOffset, this.children[this.children.length - 1].button.transform.position.y + this.children[this.children.length - 1].button.transform.size.y + this.buttonPadding); |
| 57 | |
| 58 | } |
| 59 | } |
| 60 | } |