BlueGit

blue-star speeltuin

Menu component

timfa Nick Hiert · pushed by timfa

Authored 2022-10-25 · 4 years ago

Hash
f555b1c2eed46b47d0711ad5c9e79e1ecc74fafb
Parent
9382a02c
10 files changed +62 −38
src/game.js +3 −1
@@ -129,7 +129,9 @@ createMainScene = function (game)
129 129 chao = new Chao(Math.randomRange(0, 704), Math.randomRange(0, 640), game.images.chao_default, 0);
130 130 scene.addObject(chao);
131 131
132 scene.addObject(new MainMenu(0, 50, 60, 50, game.images.menuButton, 5));
132 menu = new MainMenu(0, 50, 60, 50, game.images.menuButton, 5, true);
133
134 scene.addObject(menu);
133 135 scene.addObject(new SimpleImagesRenderTween(-100, -100, game.images.arrow, 1));
134 136
135 137 WorldObjectTracker.Load(scene);
@@ -129,7 +129,9 @@ createMainScene = function (game)
129 chao = new Chao(Math.randomRange(0, 704), Math.randomRange(0, 640), game.images.chao_default, 0);
129 chao = new Chao(Math.randomRange(0, 704), Math.randomRange(0, 640), game.images.chao_default, 0);
130 scene.addObject(chao);
130 scene.addObject(chao);
131
131
132 scene.addObject(new MainMenu(0, 50, 60, 50, game.images.menuButton, 5));
132 menu = new MainMenu(0, 50, 60, 50, game.images.menuButton, 5, true);
133
134 scene.addObject(menu);
133 scene.addObject(new SimpleImagesRenderTween(-100, -100, game.images.arrow, 1));
135 scene.addObject(new SimpleImagesRenderTween(-100, -100, game.images.arrow, 1));
134
136
135 WorldObjectTracker.Load(scene);
137 WorldObjectTracker.Load(scene);
src/objects/menus/1-baseMenu.js +9 −7
@@ -1,7 +1,9 @@
1 class BaseMenu extends BaseMenuButton
1 class BaseMenu
2 2 {
3 3 children = {};
4 4
5 owner = null;
6
5 7 state = 0;
6 8 prevState = null;
7 9
@@ -11,11 +13,12 @@ class BaseMenu extends BaseMenuButton
11 13 tOpen = 0;
12 14 tClose = 0;
13 15
14 constructor (sx, sy, ex, ey, sprite, layer, tOpen = 800, tClose = 1000)
16 constructor (owner, tOpen = 800, tClose = 1000)
15 17 {
16 super(sx, sy, ex, ey, sprite, layer);
18 this.owner = owner;
17 19 this.tOpen = tOpen;
18 20 this.tClose = tClose;
21 this.init();
19 22 }
20 23
21 24 openOnParentOpen ()
@@ -28,11 +31,10 @@ class BaseMenu extends BaseMenuButton
28 31 this.parent.isClosed.add(() => this.close(), this);
29 32 }
30 33
31 addedToScene ()
34 init ()
32 35 {
33 36 this.isOpened = new Signal();
34 37 this.isClosed = new Signal();
35 // reminder to implement this in subclasses to instantiate child buttons etc
36 38 }
37 39
38 40 addChildButton (label, childButton)
@@ -49,12 +51,12 @@ class BaseMenu extends BaseMenuButton
49 51
50 52 moveSelfOnOpen ()
51 53 {
52 this.isOpened.add((a, b) => this.moveToActiveState(a, b), this);
54 this.isOpened.add((a, b) => this.owner.moveToActiveState(a, b), this);
53 55 }
54 56
55 57 moveSelfOnClose ()
56 58 {
57 this.isClosed.add((a, b) => this.moveToInactiveState(a, b), this);
59 this.isClosed.add((a, b) => this.owner.moveToInactiveState(a, b), this);
58 60 }
59 61
60 62 onClick (btn)
@@ -1,7 +1,9 @@
1class BaseMenu extends BaseMenuButton
1class BaseMenu
2{
2{
3 children = {};
3 children = {};
4
4
5 owner = null;
6
5 state = 0;
7 state = 0;
6 prevState = null;
8 prevState = null;
7
9
@@ -11,11 +13,12 @@ class BaseMenu extends BaseMenuButton
11 tOpen = 0;
13 tOpen = 0;
12 tClose = 0;
14 tClose = 0;
13
15
14 constructor (sx, sy, ex, ey, sprite, layer, tOpen = 800, tClose = 1000)
16 constructor (owner, tOpen = 800, tClose = 1000)
15 {
17 {
16 super(sx, sy, ex, ey, sprite, layer);
18 this.owner = owner;
17 this.tOpen = tOpen;
19 this.tOpen = tOpen;
18 this.tClose = tClose;
20 this.tClose = tClose;
21 this.init();
19 }
22 }
20
23
21 openOnParentOpen ()
24 openOnParentOpen ()
@@ -28,11 +31,10 @@ class BaseMenu extends BaseMenuButton
28 this.parent.isClosed.add(() => this.close(), this);
31 this.parent.isClosed.add(() => this.close(), this);
29 }
32 }
30
33
31 addedToScene ()
34 init ()
32 {
35 {
33 this.isOpened = new Signal();
36 this.isOpened = new Signal();
34 this.isClosed = new Signal();
37 this.isClosed = new Signal();
35 // reminder to implement this in subclasses to instantiate child buttons etc
36 }
38 }
37
39
38 addChildButton (label, childButton)
40 addChildButton (label, childButton)
@@ -49,12 +51,12 @@ class BaseMenu extends BaseMenuButton
49
51
50 moveSelfOnOpen ()
52 moveSelfOnOpen ()
51 {
53 {
52 this.isOpened.add((a, b) => this.moveToActiveState(a, b), this);
54 this.isOpened.add((a, b) => this.owner.moveToActiveState(a, b), this);
53 }
55 }
54
56
55 moveSelfOnClose ()
57 moveSelfOnClose ()
56 {
58 {
57 this.isClosed.add((a, b) => this.moveToInactiveState(a, b), this);
59 this.isClosed.add((a, b) => this.owner.moveToInactiveState(a, b), this);
58 }
60 }
59
61
60 onClick (btn)
62 onClick (btn)
src/objects/menus/13-subBtn.js +1 −1
@@ -13,7 +13,7 @@ class SubBtn extends GameObject
13 13 this.isClicked.dispatch();
14 14 }
15 15
16 moveToActiveState (onDone)
16 moveToActiveState (onDone)
17 17 {
18 18 this.createOpenTween(onDone);
19 19 }
@@ -13,7 +13,7 @@ class SubBtn extends GameObject
13 this.isClicked.dispatch();
13 this.isClicked.dispatch();
14 }
14 }
15
15
16 moveToActiveState (onDone)
16 moveToActiveState (onDone)
17 {
17 {
18 this.createOpenTween(onDone);
18 this.createOpenTween(onDone);
19 }
19 }
src/objects/menus/12-baseMenuButton.js src/objects/menus/2-MoveableMenuItem.js renamed +14 −2
@@ -1,4 +1,4 @@
1 class BaseMenuButton extends GameObject
1 class MoveableMenuItem extends GameObject
2 2 {
3 3 targetPosition = null;
4 4 originPosition = null;
@@ -9,11 +9,23 @@ class BaseMenuButton extends GameObject
9 9
10 10 shouldPeekOnHover = true;
11 11
12 constructor (sx, sy, ex, ey, sprite, layer)
12 menu = null;
13
14 constructor (sx, sy, ex, ey, sprite, layer, isMenu, tOpen = 800, tClose = 1000)
13 15 {
14 16 super(sx, sy, sprite, layer);
15 17 this.originPosition = new vector(sx, sy);
16 18 this.targetPosition = new vector(ex, ey);
19
20 if (isMenu)
21 {
22 this.addMenu(tOpen, tClose);
23 }
24 }
25
26 addMenu (tOpen, tClose)
27 {
28 this.menu = new BaseMenu(this, tOpen, tClose);
17 29 }
18 30
19 31 peekOnHover ()
@@ -1,4 +1,4 @@
1class BaseMenuButton extends GameObject
1class MoveableMenuItem extends GameObject
2{
2{
3 targetPosition = null;
3 targetPosition = null;
4 originPosition = null;
4 originPosition = null;
@@ -9,11 +9,23 @@ class BaseMenuButton extends GameObject
9
9
10 shouldPeekOnHover = true;
10 shouldPeekOnHover = true;
11
11
12 constructor (sx, sy, ex, ey, sprite, layer)
12 menu = null;
13
14 constructor (sx, sy, ex, ey, sprite, layer, isMenu, tOpen = 800, tClose = 1000)
13 {
15 {
14 super(sx, sy, sprite, layer);
16 super(sx, sy, sprite, layer);
15 this.originPosition = new vector(sx, sy);
17 this.originPosition = new vector(sx, sy);
16 this.targetPosition = new vector(ex, ey);
18 this.targetPosition = new vector(ex, ey);
19
20 if (isMenu)
21 {
22 this.addMenu(tOpen, tClose);
23 }
24 }
25
26 addMenu (tOpen, tClose)
27 {
28 this.menu = new BaseMenu(this, tOpen, tClose);
17 }
29 }
18
30
19 peekOnHover ()
31 peekOnHover ()
src/objects/menus/btnFruit.js +1 −1
@@ -1,4 +1,4 @@
1 class BtnFruit extends BaseMenuButton
1 class BtnFruit extends MoveableMenuItem
2 2 {
3 3 fruitInventory = null;
4 4
@@ -1,4 +1,4 @@
1class BtnFruit extends BaseMenuButton
1class BtnFruit extends MoveableMenuItem
2{
2{
3 fruitInventory = null;
3 fruitInventory = null;
4
4
src/objects/menus/btnGames.js +13 −10
@@ -1,26 +1,29 @@
1 class BtnGames extends BaseMenu
1 class BtnGames extends MoveableMenuItem
2 2 {
3 3 buttons = [];
4 4 buttonPadding = 10;
5 5 state = 0;
6 6 prevState = 1;
7 7
8 constructor (sx, sy, ex, ey, sprite, layer, tOpen = 600, tClose = 800)
8 constructor (sx, sy, ex, ey, sprite, layer, isMenu, tOpen = 600, tClose = 800)
9 9 {
10 super(sx, sy, ex, ey, sprite, layer, tOpen, tClose);
10 super(sx, sy, ex, ey, sprite, layer, isMenu, tOpen, tClose);
11 11 }
12 12
13 13 addedToScene ()
14 14 {
15 super.addedToScene();
16
17 15 this.initialiseChildren();
18 16 }
19 17
18 onClick (btn)
19 {
20 this.menu.onClick(btn);
21 }
22
20 23 initialiseChildren ()
21 24 {
22 25 let target = this.getNextTargetPosition();
23 let buttonFrog = this.scene.addObject(new BaseMenuButton(this.originPosition.x, this.originPosition.y, target.x, target.y, this.scene.game.images.btnFrog, 3));
26 let buttonFrog = this.scene.addObject(new MoveableMenuItem(this.originPosition.x, this.originPosition.y, target.x, target.y, this.scene.game.images.btnFrog, 3));
24 27 buttonFrog.onClick = function ()
25 28 {
26 29 MinigameInitialiser.StartFrogGame(this.scene, new vector(this.targetPosition.x - this.transform.size.x / 2, this.targetPosition.y - this.transform.size.y / 2), this.transform.size);
@@ -29,24 +32,24 @@ class BtnGames extends BaseMenu
29 32
30 33 buttonFrog.createActiveStateTween = function (time, onDone)
31 34 {
32 return BaseMenuButton.prototype.createActiveStateTween(time, onDone, this)
35 return MoveableMenuItem.prototype.createActiveStateTween(time, onDone, this)
33 36 .to({ x: [this.targetPosition.x], y: [this.originPosition.y, this.originPosition.y, this.originPosition.y, this.targetPosition.y] }, time)
34 37 .easing(TWEEN.Easing.Back.Out);
35 38 };
36 39
37 40 buttonFrog.createInactiveStateTween = function (time, onDone)
38 41 {
39 return BaseMenuButton.prototype.createInactiveStateTween(time, onDone, this)
42 return MoveableMenuItem.prototype.createInactiveStateTween(time, onDone, this)
40 43 .to({ x: [this.targetPosition.x, this.targetPosition.x, this.targetPosition.x, this.targetPosition.x, this.originPosition.x], y: [this.originPosition.y] }, time)
41 44 .easing(TWEEN.Easing.Quintic.Out);
42 45 };
43 46
44 this.addChildButton("btnFrog", buttonFrog);
47 this.menu.addChildButton("btnFrog", buttonFrog);
45 48 }
46 49
47 50 getNextTargetPosition ()
48 51 {
49 let buttonArray = Object.values(this.children);
52 let buttonArray = Object.values(this.menu.children);
50 53 if (buttonArray == 0)
51 54 {
52 55 return new vector(this.transform.position.x + this.transform.size.x * 2 + this.buttonPadding, this.transform.position.y + this.buttonPadding);
@@ -1,26 +1,29 @@
1class BtnGames extends BaseMenu
1class BtnGames extends MoveableMenuItem
2{
2{
3 buttons = [];
3 buttons = [];
4 buttonPadding = 10;
4 buttonPadding = 10;
5 state = 0;
5 state = 0;
6 prevState = 1;
6 prevState = 1;
7
7
8 constructor (sx, sy, ex, ey, sprite, layer, tOpen = 600, tClose = 800)
8 constructor (sx, sy, ex, ey, sprite, layer, isMenu, tOpen = 600, tClose = 800)
9 {
9 {
10 super(sx, sy, ex, ey, sprite, layer, tOpen, tClose);
10 super(sx, sy, ex, ey, sprite, layer, isMenu, tOpen, tClose);
11 }
11 }
12
12
13 addedToScene ()
13 addedToScene ()
14 {
14 {
15 super.addedToScene();
16
17 this.initialiseChildren();
15 this.initialiseChildren();
18 }
16 }
19
17
18 onClick (btn)
19 {
20 this.menu.onClick(btn);
21 }
22
20 initialiseChildren ()
23 initialiseChildren ()
21 {
24 {
22 let target = this.getNextTargetPosition();
25 let target = this.getNextTargetPosition();
23 let buttonFrog = this.scene.addObject(new BaseMenuButton(this.originPosition.x, this.originPosition.y, target.x, target.y, this.scene.game.images.btnFrog, 3));
26 let buttonFrog = this.scene.addObject(new MoveableMenuItem(this.originPosition.x, this.originPosition.y, target.x, target.y, this.scene.game.images.btnFrog, 3));
24 buttonFrog.onClick = function ()
27 buttonFrog.onClick = function ()
25 {
28 {
26 MinigameInitialiser.StartFrogGame(this.scene, new vector(this.targetPosition.x - this.transform.size.x / 2, this.targetPosition.y - this.transform.size.y / 2), this.transform.size);
29 MinigameInitialiser.StartFrogGame(this.scene, new vector(this.targetPosition.x - this.transform.size.x / 2, this.targetPosition.y - this.transform.size.y / 2), this.transform.size);
@@ -29,24 +32,24 @@ class BtnGames extends BaseMenu
29
32
30 buttonFrog.createActiveStateTween = function (time, onDone)
33 buttonFrog.createActiveStateTween = function (time, onDone)
31 {
34 {
32 return BaseMenuButton.prototype.createActiveStateTween(time, onDone, this)
35 return MoveableMenuItem.prototype.createActiveStateTween(time, onDone, this)
33 .to({ x: [this.targetPosition.x], y: [this.originPosition.y, this.originPosition.y, this.originPosition.y, this.targetPosition.y] }, time)
36 .to({ x: [this.targetPosition.x], y: [this.originPosition.y, this.originPosition.y, this.originPosition.y, this.targetPosition.y] }, time)
34 .easing(TWEEN.Easing.Back.Out);
37 .easing(TWEEN.Easing.Back.Out);
35 };
38 };
36
39
37 buttonFrog.createInactiveStateTween = function (time, onDone)
40 buttonFrog.createInactiveStateTween = function (time, onDone)
38 {
41 {
39 return BaseMenuButton.prototype.createInactiveStateTween(time, onDone, this)
42 return MoveableMenuItem.prototype.createInactiveStateTween(time, onDone, this)
40 .to({ x: [this.targetPosition.x, this.targetPosition.x, this.targetPosition.x, this.targetPosition.x, this.originPosition.x], y: [this.originPosition.y] }, time)
43 .to({ x: [this.targetPosition.x, this.targetPosition.x, this.targetPosition.x, this.targetPosition.x, this.originPosition.x], y: [this.originPosition.y] }, time)
41 .easing(TWEEN.Easing.Quintic.Out);
44 .easing(TWEEN.Easing.Quintic.Out);
42 };
45 };
43
46
44 this.addChildButton("btnFrog", buttonFrog);
47 this.menu.addChildButton("btnFrog", buttonFrog);
45 }
48 }
46
49
47 getNextTargetPosition ()
50 getNextTargetPosition ()
48 {
51 {
49 let buttonArray = Object.values(this.children);
52 let buttonArray = Object.values(this.menu.children);
50 if (buttonArray == 0)
53 if (buttonArray == 0)
51 {
54 {
52 return new vector(this.transform.position.x + this.transform.size.x * 2 + this.buttonPadding, this.transform.position.y + this.buttonPadding);
55 return new vector(this.transform.position.x + this.transform.size.x * 2 + this.buttonPadding, this.transform.position.y + this.buttonPadding);
src/objects/menus/btnPlants.js +1 −1
@@ -1,4 +1,4 @@
1 class BtnPlants extends BaseMenuButton
1 class BtnPlants extends MoveableMenuItem
2 2 {
3 3
4 4 }
@@ -1,4 +1,4 @@
1class BtnPlants extends BaseMenuButton
1class BtnPlants extends MoveableMenuItem
2{
2{
3
3
4}
4}
src/objects/menus/btnToys.js +1 −1
@@ -1,4 +1,4 @@
1 class BtnToys extends BaseMenuButton
1 class BtnToys extends MoveableMenuItem
2 2 {
3 3
4 4 }
@@ -1,4 +1,4 @@
1class BtnToys extends BaseMenuButton
1class BtnToys extends MoveableMenuItem
2{
2{
3
3
4}
4}
src/objects/menus/fruitInventory.js +1 −1
@@ -95,7 +95,7 @@ class FruitInventory extends GameObject
95 95 this.moveToClose();
96 96 }, this);
97 97
98 MainMenu.Instance.isOpened.add(function ()
98 MainMenu.Instance.menu.isOpened.add(function ()
99 99 {
100 100 this.moveToClose();
101 101 }, this);
@@ -95,7 +95,7 @@ class FruitInventory extends GameObject
95 this.moveToClose();
95 this.moveToClose();
96 }, this);
96 }, this);
97
97
98 MainMenu.Instance.isOpened.add(function ()
98 MainMenu.Instance.menu.isOpened.add(function ()
99 {
99 {
100 this.moveToClose();
100 this.moveToClose();
101 }, this);
101 }, this);
src/objects/menus/mainMenu.js +18 −13
@@ -1,4 +1,4 @@
1 class MainMenu extends BaseMenu
1 class MainMenu extends MoveableMenuItem
2 2 {
3 3 static Instance;
4 4
@@ -10,44 +10,49 @@ class MainMenu extends BaseMenu
10 10
11 11 closedTargetX = -15;
12 12
13 constructor (sx, sy, ex, ey, sprite, layer, tOpen, tClose)
13 constructor (sx, sy, ex, ey, sprite, layer, isMenu, tOpen = 800, tClose = 1000)
14 14 {
15 super(sx, sy, ex, ey, sprite, layer, tOpen, tClose);
15 super(sx, sy, ex, ey, sprite, layer, isMenu, tOpen, tClose);
16 16 MainMenu.Instance = this;
17
17 18 }
18 19
19 20 addedToScene ()
20 21 {
21 super.addedToScene();
22 22
23 23 this.initialiseChildren();
24 24
25 this.moveSelfOnOpen();
26 this.moveSelfOnClose();
25 this.menu.moveSelfOnOpen();
26 this.menu.moveSelfOnClose();
27
28 this.menu.open(() => this.menu.close());
29 }
27 30
28 this.open(() => this.close());
31 onClick (btn)
32 {
33 this.menu.onClick(btn);
29 34 }
30 35
31 36 initialiseChildren ()
32 37 {
33 38 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)));
39 this.menu.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 40
36 41 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)));
42 this.menu.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 43
39 44 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)));
45 this.menu.addChildButton("btnGames", this.scene.addObject(new BtnGames(vectorOrigin.x, vectorOrigin.y, this.targetPosition.x + this.buttonXOffset, vectorOrigin.y, this.scene.game.images.btnGames, 4, true)));
41 46
42 47 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))
48 this.menu.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 49 );
45 50
46 51 }
47 52
48 53 getNextOriginPosition ()
49 54 {
50 let buttonArray = Object.values(this.children);
55 let buttonArray = Object.values(this.menu.children);
51 56 if (buttonArray.length == 0)
52 57 {
53 58 return new vector(this.transform.position.x + this.buttonXOffset, this.transform.position.y + this.transform.size.y + this.buttonPadding);
@@ -75,7 +80,7 @@ class MainMenu extends BaseMenu
75 80 {
76 81 if (this.activeTween == null &&
77 82 (this.transform.position.x != this.originPosition.x || this.transform.position.y != this.originPosition.y) &&
78 this.state == MenuStates.closed)
83 this.menu.state == MenuStates.closed)
79 84 {
80 85 this.createInactiveStateTween(400, null, this).start();
81 86 }
@@ -1,4 +1,4 @@
1class MainMenu extends BaseMenu
1class MainMenu extends MoveableMenuItem
2{
2{
3 static Instance;
3 static Instance;
4
4
@@ -10,44 +10,49 @@ class MainMenu extends BaseMenu
10
10
11 closedTargetX = -15;
11 closedTargetX = -15;
12
12
13 constructor (sx, sy, ex, ey, sprite, layer, tOpen, tClose)
13 constructor (sx, sy, ex, ey, sprite, layer, isMenu, tOpen = 800, tClose = 1000)
14 {
14 {
15 super(sx, sy, ex, ey, sprite, layer, tOpen, tClose);
15 super(sx, sy, ex, ey, sprite, layer, isMenu, tOpen, tClose);
16 MainMenu.Instance = this;
16 MainMenu.Instance = this;
17
17 }
18 }
18
19
19 addedToScene ()
20 addedToScene ()
20 {
21 {
21 super.addedToScene();
22
22
23 this.initialiseChildren();
23 this.initialiseChildren();
24
24
25 this.moveSelfOnOpen();
25 this.menu.moveSelfOnOpen();
26 this.moveSelfOnClose();
26 this.menu.moveSelfOnClose();
27
28 this.menu.open(() => this.menu.close());
29 }
27
30
28 this.open(() => this.close());
31 onClick (btn)
32 {
33 this.menu.onClick(btn);
29 }
34 }
30
35
31 initialiseChildren ()
36 initialiseChildren ()
32 {
37 {
33 let vectorOrigin = this.getNextOriginPosition();
38 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)));
39 this.menu.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
40
36 vectorOrigin = this.getNextOriginPosition();
41 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)));
42 this.menu.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
43
39 vectorOrigin = this.getNextOriginPosition();
44 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)));
45 this.menu.addChildButton("btnGames", this.scene.addObject(new BtnGames(vectorOrigin.x, vectorOrigin.y, this.targetPosition.x + this.buttonXOffset, vectorOrigin.y, this.scene.game.images.btnGames, 4, true)));
41
46
42 vectorOrigin = this.getNextOriginPosition();
47 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))
48 this.menu.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 );
49 );
45
50
46 }
51 }
47
52
48 getNextOriginPosition ()
53 getNextOriginPosition ()
49 {
54 {
50 let buttonArray = Object.values(this.children);
55 let buttonArray = Object.values(this.menu.children);
51 if (buttonArray.length == 0)
56 if (buttonArray.length == 0)
52 {
57 {
53 return new vector(this.transform.position.x + this.buttonXOffset, this.transform.position.y + this.transform.size.y + this.buttonPadding);
58 return new vector(this.transform.position.x + this.buttonXOffset, this.transform.position.y + this.transform.size.y + this.buttonPadding);
@@ -75,7 +80,7 @@ class MainMenu extends BaseMenu
75 {
80 {
76 if (this.activeTween == null &&
81 if (this.activeTween == null &&
77 (this.transform.position.x != this.originPosition.x || this.transform.position.y != this.originPosition.y) &&
82 (this.transform.position.x != this.originPosition.x || this.transform.position.y != this.originPosition.y) &&
78 this.state == MenuStates.closed)
83 this.menu.state == MenuStates.closed)
79 {
84 {
80 this.createInactiveStateTween(400, null, this).start();
85 this.createInactiveStateTween(400, null, this).start();
81 }
86 }