Browse code

redesign level selector layout

devnewton authored on 14/05/2015 10:24:03
Showing 2 changed files
1 1
Binary files a/assets/animation/bulle/bulle0.png and b/assets/animation/bulle/bulle0.png differ
... ...
@@ -25,17 +25,25 @@ package org.geekygoblin.nedetlesmaki.core.components.ui;
25 25
 
26 26
 import im.bci.jnuit.NuitToolkit;
27 27
 import im.bci.jnuit.widgets.Button;
28
+import im.bci.jnuit.widgets.NullWidget;
29
+import im.bci.jnuit.widgets.Table;
30
+import im.bci.jnuit.widgets.TableLayout;
31
+import im.bci.jnuit.widgets.Widget;
32
+import im.bci.jnuit.animation.IAnimation;
28 33
 import im.bci.jnuit.animation.IAnimationCollection;
29 34
 import im.bci.jnuit.animation.PlayMode;
35
+
30 36
 import javax.inject.Inject;
31 37
 import javax.inject.Provider;
32 38
 import javax.inject.Singleton;
39
+
33 40
 import im.bci.jnuit.background.TexturedBackground;
34 41
 import im.bci.jnuit.focus.NullFocusCursor;
35
-import im.bci.jnuit.widgets.Container;
42
+
36 43
 import org.geekygoblin.nedetlesmaki.core.NedGame;
37 44
 import org.geekygoblin.nedetlesmaki.core.IAssets;
38 45
 import org.geekygoblin.nedetlesmaki.core.components.Triggerable;
46
+import org.geekygoblin.nedetlesmaki.core.constants.VirtualResolution;
39 47
 import org.geekygoblin.nedetlesmaki.core.events.IStartGameTrigger;
40 48
 import org.geekygoblin.nedetlesmaki.core.events.ShowMenuTrigger;
41 49
 
... ...
@@ -44,69 +52,98 @@ import org.geekygoblin.nedetlesmaki.core.events.ShowMenuTrigger;
44 52
  * @author devnewton
45 53
  */
46 54
 @Singleton
47
-public class LevelSelector extends Container {
55
+public class LevelSelector extends Table {
48 56
 
49 57
     private final NedGame game;
50 58
     private final IAnimationCollection bulleAnimations;
51 59
     private final NuitToolkit toolkit;
52 60
     private final Provider<IStartGameTrigger> startGameTrigger;
53 61
     private final Provider<ShowMenuTrigger> showMenuTrigger;
62
+    private final Table buttonsTable;
63
+    private NullWidget portail;
64
+    private Button backButton;
65
+    private TexturedBackground portailFocusedBackground;
66
+    private TexturedBackground portailBackground;
54 67
 
55 68
     @Inject
56 69
     public LevelSelector(NedGame game, NuitToolkit toolkit, final IAssets assets, Provider<IStartGameTrigger> startGameTrigger, Provider<ShowMenuTrigger> showMenuTrigger) {
70
+        super(toolkit);
57 71
         this.game = game;
58 72
         this.toolkit = toolkit;
59 73
         this.startGameTrigger = startGameTrigger;
60 74
         this.showMenuTrigger = showMenuTrigger;
75
+        buttonsTable = this;
76
+        buttonsTable.setX(0);
77
+        buttonsTable.setY(0);
78
+        buttonsTable.setWidth(320);
79
+        buttonsTable.setHeight(VirtualResolution.HEIGHT);
80
+        buttonsTable.defaults().expandY().align(TableLayout.CENTER);
81
+        buttonsTable.columnDefaults(0).width(80.0f).pad(20.0f);
82
+        buttonsTable.columnDefaults(1).width(80.0f).pad(20.0f);
61 83
         bulleAnimations = assets.getAnimations("animation/bulle/bulle.json");
62 84
         setBackground(new TexturedBackground(assets.getAnimations("tour.png").getFirst().start(PlayMode.LOOP)));
63
-        setFocusedChild(addButton("level.01.name", "levels/t1/lvl01.tmx", 1045, 855, 1));
64
-        addButton("level.02.name", "levels/t1/lvl02.tmx", 870, 832, -1);
65
-        addButton("level.03.name", "levels/t1/lvl03.tmx", 1045, 809, 1);
66
-        addButton("level.04.name", "levels/t1/lvl04.tmx", 870, 786, -1);
67
-        addButton("level.05.name", "levels/t1/lvl05.tmx", 1045, 763, 1);
68
-        addButton("level.06.name", "levels/t1/lvl06.tmx", 870, 740, -1);
69
-        addButton("level.07.name", "levels/t1/lvl07.tmx", 1045, 717, 1);
70
-        addButton("level.08.name", "levels/t2/lvl01.tmx", 870, 694, -1);
71
-        addButton("level.09.name", "levels/t2/lvl02.tmx", 1045, 671, 1);
72
-        addButton("level.10.name", "levels/t2/lvl03.tmx", 870, 648, -1);
73
-        addButton("level.11.name", "levels/t2/lvl04.tmx", 1045, 625, 1);
74
-        addButton("level.12.name", "levels/t2/lvl05.tmx", 870, 602, -1);
75
-        addButton("level.13.name", "levels/t2/lvlAA.tmx", 1045, 579, 1);
76
-        addButton("level.14.name", "levels/t2/lvlAB.tmx", 870, 556, -1);
77
-        /*addButton("level.15.name", "levels/lvl15.tmx", 1087, 540, 1);
78
-         addButton("level.16.name", "levels/lvl16.tmx", 825, 512, -1);
79
-         addButton("level.17.name", "levels/lvl17.tmx", 1087, 483, 1);
80
-         addButton("level.18.name", "levels/lvl18.tmx", 825, 454, -1);
81
-         addButton("level.19.name", "levels/lvl19.tmx", 1087, 426, 1);
82
-         addButton("level.20.name", "levels/lvl20.tmx", 825, 398, -1);
83
-         addButton("level.21.name", "levels/lvl21.tmx", 1087, 369, 1);
84
-         addButton("level.22.name", "levels/lvl22.tmx", 825, 340, -1);
85
-         addButton("level.23.name", "levels/lvl23.tmx", 1087, 312, 1);
86
-         addButton("level.24.name", "levels/lvl24.tmx", 825, 284, -1);
87
-         addButton("level.25.name", "levels/lvl25.tmx", 1087, 256, 1);
88
-         addButton("level.26.name", "levels/lvl26.tmx", 825, 227, -1);
89
-         addButton("level.27.name", "levels/lvl27.tmx", 1087, 198, 1);
90
-         addButton("level.28.name", "levels/lvl28.tmx", 825, 170, -1);*/
91
-        addButton("level.29.name", "levels/test2020.tmx", 1087, 142, 1);
92
-        addButton("level.30.name", "levels/test.tmx", 825, 117, -1);
93
-
94
-        Button backButton = new Button(toolkit, "options.menu.button.back") {
95
-
85
+        buttonsTable.setFocusedChild(addButton("level.01.name", "levels/t1/lvl01.tmx"));
86
+        addButton("level.02.name", "levels/t1/lvl02.tmx");
87
+        buttonsTable.row();
88
+        addButton("level.03.name", "levels/t1/lvl03.tmx");
89
+        addButton("level.04.name", "levels/t1/lvl04.tmx");
90
+        buttonsTable.row();
91
+        addButton("level.05.name", "levels/t1/lvl05.tmx");
92
+        addButton("level.06.name", "levels/t1/lvl06.tmx");
93
+        buttonsTable.row();
94
+        addButton("level.07.name", "levels/t1/lvl07.tmx");
95
+        addButton("level.08.name", "levels/t2/lvl01.tmx");
96
+        buttonsTable.row();
97
+        addButton("level.09.name", "levels/t2/lvl02.tmx");
98
+        addButton("level.10.name", "levels/t2/lvl03.tmx");
99
+        buttonsTable.row();
100
+        addButton("level.11.name", "levels/t2/lvl04.tmx");
101
+        addButton("level.12.name", "levels/t2/lvl05.tmx");
102
+        buttonsTable.row();
103
+        addButton("level.13.name", "levels/t2/lvlAA.tmx");
104
+        addButton("level.14.name", "levels/t2/lvlAB.tmx");
105
+        buttonsTable.row();
106
+        addButton("level.29.name", "levels/test2020.tmx");
107
+        addButton("level.30.name", "levels/test.tmx");
108
+        buttonsTable.row();
109
+
110
+        IAnimation buttonSmallBackgroundAnimation = assets.getAnimations("animation/menu_buttons/menu_buttons.json").getAnimationByName("1_normal");
111
+        IAnimation buttonSmallFocusedBackgroundAnimation = assets.getAnimations("animation/menu_buttons/menu_buttons.json").getAnimationByName("1_survol");
112
+
113
+        backButton = new Button(toolkit, "options.menu.button.back") {
96 114
             @Override
97 115
             public void onOK() {
98 116
                 LevelSelector.this.onCancel();
99 117
             }
100
-
101 118
         };
102 119
         backButton.setFocusCursor(NullFocusCursor.INSTANCE);
103
-        backButton.setBackground(new TexturedBackground(assets.getAnimations("animation/portail/portail.json").getAnimationByName("normal").start(PlayMode.LOOP)));
104
-        backButton.setFocusedBackground(new TexturedBackground(assets.getAnimations("animation/portail/portail.json").getAnimationByName("survol").start(PlayMode.LOOP)));
105
-        backButton.setX(526);
106
-        backButton.setY(383);
107
-        backButton.setWidth(131);
108
-        backButton.setHeight(199);
109
-        this.add(backButton);
120
+        backButton.setBackground(new TexturedBackground(buttonSmallBackgroundAnimation.start(PlayMode.LOOP)));
121
+        backButton.setFocusedBackground(new TexturedBackground(buttonSmallFocusedBackgroundAnimation.start(PlayMode.LOOP)));
122
+        buttonsTable.cell(backButton).colspan(2).fill();
123
+        buttonsTable.cell(new NullWidget()).expand();
124
+
125
+        portail = new NullWidget();
126
+        portailBackground = new TexturedBackground(assets.getAnimations("animation/portail/portail.json").getAnimationByName("normal").start(PlayMode.LOOP));
127
+        portailFocusedBackground = new TexturedBackground(assets.getAnimations("animation/portail/portail.json").getAnimationByName("survol").start(PlayMode.LOOP));
128
+        portail.setBackground(portailBackground);
129
+        portail.setX(526);
130
+        portail.setY(383);
131
+        portail.setWidth(131);
132
+        portail.setHeight(199);
133
+        buttonsTable.add(portail);
134
+
135
+    }
136
+
137
+    @Override
138
+    public void setFocusedChild(Widget focusedChild) {
139
+        super.setFocusedChild(focusedChild);
140
+        if (null != portail) {
141
+            if (focusedChild == backButton) {
142
+                portail.setBackground(portailFocusedBackground);
143
+            } else {
144
+                portail.setBackground(portailBackground);
145
+            }
146
+        }
110 147
     }
111 148
 
112 149
     private class LevelSelectorButton extends Button {
... ...
@@ -125,23 +162,13 @@ public class LevelSelector extends Container {
125 162
         }
126 163
     }
127 164
 
128
-    private LevelSelectorButton addButton(String label, String levelName, int x, int y, int orientation) {
165
+    private LevelSelectorButton addButton(String label, String levelName) {
129 166
         LevelSelectorButton button = new LevelSelectorButton(toolkit, label, levelName);
130 167
         final TexturedBackground background = new TexturedBackground(bulleAnimations.getAnimationByName("bulle").start(PlayMode.LOOP));
131 168
         button.setBackground(background);
132 169
         final TexturedBackground focusedBackground = new TexturedBackground(bulleAnimations.getAnimationByName("bulle_selectionnee").start(PlayMode.LOOP));
133 170
         button.setFocusedBackground(focusedBackground);
134
-        button.setWidth(button.getMinWidth());
135
-        button.setHeight(button.getMinHeight());
136
-        if (orientation < 0) {
137
-            button.setX(x - button.getWidth());
138
-        } else {
139
-            button.setX(x);
140
-            background.setMirrorX(true);
141
-            focusedBackground.setMirrorX(true);
142
-        }
143
-        button.setY(y - button.getHeight() / 2);
144
-        this.add(button);
171
+        buttonsTable.cell(button);
145 172
         return button;
146 173
     }
147 174