Browse code

clean up control API

devnewton authored on 11/05/2014 at 09:21:42
Showing 7 changed files
... ...
@@ -34,7 +34,7 @@ import java.util.List;
34 34
  */
35 35
 public interface NuitControls {
36 36
 
37
-    List<Control> getPossibleControls();
37
+    Control[] getPossibleControls();
38 38
 
39 39
     Control[] getDefaultMenuUpControls();
40 40
 
... ...
@@ -59,6 +59,7 @@ public class NuitToolkit extends Toolkit<Widget, Table> {
59 59
     private int virtualResolutionWidth = 1920;
60 60
     private int virtualResolutionHeight = 1080;
61 61
     private final NuitAudio audio;
62
+    private Action pressAnyKeyAction;
62 63
 
63 64
     public NuitToolkit(NuitDisplay display, NuitControls controls, NuitTranslator translator, NuitFont font, NuitRenderer renderer, NuitAudio audio) {
64 65
         this.font = font;
... ...
@@ -235,7 +236,7 @@ public class NuitToolkit extends Toolkit<Widget, Table> {
235 235
         menuCancel.reset();
236 236
     }
237 237
 
238
-    public List<Control> getPossibleControls() {
238
+    public Control[] getPossibleControls() {
239 239
         return controls.getPossibleControls();
240 240
     }
241 241
 
... ...
@@ -301,4 +302,11 @@ public class NuitToolkit extends Toolkit<Widget, Table> {
301 301
         return display.canChangeResolution();
302 302
     }
303 303
 
304
+    public Action getPressAnyKeyAction() {
305
+        if(null == pressAnyKeyAction) {
306
+            pressAnyKeyAction = new Action("nuit.action.press.any.key", getPossibleControls());
307
+        }
308
+        return pressAnyKeyAction;
309
+    }
310
+
304 311
 }
... ...
@@ -80,7 +80,9 @@ public class NuitTranslator {
80 80
         addTranslation(NuitLocale.ENGLISH, "nuit.action.menu.right", "Right");
81 81
         addTranslation(NuitLocale.ENGLISH, "nuit.action.menu.ok", "OK");
82 82
         addTranslation(NuitLocale.ENGLISH, "nuit.action.menu.cancel", "Cancel");
83
-
83
+        
84
+        addTranslation(NuitLocale.ENGLISH, "nuit.action.press.any.key", "Press any key");
85
+        
84 86
         addTranslation(NuitLocale.ENGLISH, "nuit.video.configurator.mode", "Mode");
85 87
         addTranslation(NuitLocale.ENGLISH, "nuit.video.configurator.fullscreen", "Fullscreen");
86 88
         addTranslation(NuitLocale.ENGLISH, "nuit.video.configurator.apply", "Apply");
... ...
@@ -114,6 +116,8 @@ public class NuitTranslator {
114 114
         addTranslation(NuitLocale.FRENCH, "nuit.action.menu.right", "Droite");
115 115
         addTranslation(NuitLocale.FRENCH, "nuit.action.menu.ok", "OK");
116 116
         addTranslation(NuitLocale.FRENCH, "nuit.action.menu.cancel", "Annuler");
117
+        
118
+        addTranslation(NuitLocale.FRENCH, "nuit.action.press.any.key", "Appuyer sur une touche");
117 119
 
118 120
         addTranslation(NuitLocale.FRENCH, "nuit.video.configurator.mode", "Mode");
119 121
         addTranslation(NuitLocale.FRENCH, "nuit.video.configurator.fullscreen", "Plein écran");
... ...
@@ -33,7 +33,7 @@ public class Action {
33 33
     
34 34
     public Action(String name, Control... ctrls) {
35 35
         this.name = name;
36
-        controls = new Control[2];
36
+        controls = new Control[Math.max(2, ctrls.length)];
37 37
         int i=0;
38 38
         for(int n= Math.min(controls.length, ctrls.length); i<n; ++i) {
39 39
             controls[i] = ctrls[i];
... ...
@@ -56,12 +56,12 @@ public class ActionActivatedDetector {
56 56
         
57 57
     public void poll() {
58 58
         Control[] controls = action.getControls();
59
-        int nbActions = controls.length;
60
-        if(null == previousStates || nbActions != previousStates.length) {
61
-            previousStates = new Float[nbActions];
59
+        int nbControls = controls.length;
60
+        if(null == previousStates || nbControls != previousStates.length) {
61
+            previousStates = new Float[nbControls];
62 62
         }
63 63
         activated = false;
64
-        for(int i=0; i<nbActions; ++i) {
64
+        for(int i=0; i<nbControls; ++i) {
65 65
             Control control = controls[i];
66 66
             float newState =  control.getValue();
67 67
             if(null != previousStates[i]) {
... ...
@@ -51,7 +51,7 @@ import org.lwjgl.input.Mouse;
51 51
 public class LwjglNuitControls implements NuitControls {
52 52
 
53 53
     @Override
54
-    public List<Control> getPossibleControls() {
54
+    public Control[] getPossibleControls() {
55 55
         List<Control> possibleControls = new ArrayList<Control>();
56 56
         try {
57 57
             if (!Controllers.isCreated()) {
... ...
@@ -84,7 +84,7 @@ public class LwjglNuitControls implements NuitControls {
84 84
         for (int m = 0; m < Mouse.getButtonCount(); ++m) {
85 85
             possibleControls.add(new MouseButtonControl(m));
86 86
         }
87
-        return possibleControls;
87
+        return possibleControls.toArray(new Control[possibleControls.size()]);
88 88
     }
89 89
 
90 90
     @Override
... ...
@@ -126,7 +126,7 @@ public class PlaynNuitControls implements NuitControls {
126 126
     }
127 127
 
128 128
     @Override
129
-    public List<Control> getPossibleControls() {
129
+    public Control[] getPossibleControls() {
130 130
         List<Control> possibleControls = new ArrayList<Control>();
131 131
         for (Key key : Key.values()) {
132 132
             possibleControls.add(new KeyControl(this, key));
... ...
@@ -136,7 +136,7 @@ public class PlaynNuitControls implements NuitControls {
136 136
             possibleControls.add(getRightClickControl());
137 137
             possibleControls.add(getMiddleClickControl());
138 138
         }
139
-        return possibleControls;
139
+        return possibleControls.toArray(new Control[possibleControls.size()]);
140 140
     }
141 141
 
142 142
     public MouseButtonControl getMiddleClickControl() {