From d11a1fa293236d8f4238c2368d5323c3680b23b6 Mon Sep 17 00:00:00 2001 From: Antoine Date: Sat, 5 Jun 2021 02:02:14 +0200 Subject: [PATCH] De la doc pour les classe dans UIElement, gestion du clavier dans la classe Button. --- src/engine/Engine.java | 4 ++-- src/engine/gui/UIDummy.java | 17 +++++++++++++++-- src/engine/gui/UIElement.java | 17 ++++------------- src/engine/gui/UIElementText.java | 14 +------------- src/engine/input/Button.java | 16 ++++++++++++---- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/engine/Engine.java b/src/engine/Engine.java index c79ac25..2ded70d 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -294,8 +294,8 @@ public class Engine { listZoomPlus.add(InputConst.buttonA); List listZoomMinus = new ArrayList<>(); listZoomMinus.add(InputConst.buttonB); - zoom = new Button("zoom", listZoomPlus, gamepad1); - dezoom = new Button("dezoom", listZoomMinus, gamepad1); + zoom = new Button("zoom", listZoomPlus, new ArrayList<>(), gamepad1); + dezoom = new Button("dezoom", listZoomMinus, new ArrayList<>(), gamepad1); } diff --git a/src/engine/gui/UIDummy.java b/src/engine/gui/UIDummy.java index baeb8bc..eb7186e 100644 --- a/src/engine/gui/UIDummy.java +++ b/src/engine/gui/UIDummy.java @@ -1,26 +1,39 @@ package engine.gui; +import engine.Engine; +import engine.object.Camera; + /** * Classe dont hérite tous les autres élements d'interface */ public abstract class UIDummy { + protected Engine engine; + protected Camera camera; + protected float xPos; + protected float yPos; + protected float zPos; protected float scalingFactor; public void init(){ } - private void getObjInPosition(){ + protected void getObjInPosition(){ } /** * Method pour le moteur ne pas utiliser - * @param scaleFactor + * @param scaleFactor tqt fréro */ public void updateScalingFactor(float scaleFactor){ this.scalingFactor *= scaleFactor; } + /** + * Recalcule la position de l'objet pour qu'il soit adapté au changement dans la projection ou de la position de la camera + * Si l'objet est correctement initialisé par un moteur ne pas utiliser ! + */ public void update(){ + this.getObjInPosition(); } } diff --git a/src/engine/gui/UIElement.java b/src/engine/gui/UIElement.java index f12330f..9c50523 100644 --- a/src/engine/gui/UIElement.java +++ b/src/engine/gui/UIElement.java @@ -1,9 +1,7 @@ package engine.gui; - import engine.Engine; import engine.math.Vector3f; -import engine.object.Camera; import engine.object.ObjectGl; /** @@ -12,11 +10,6 @@ import engine.object.ObjectGl; public class UIElement extends UIDummy{ private final ObjectGl obj; - private final Engine engine; - private final Camera camera; - private float xPos; - private float yPos; - private float zPos; /** * Crée un elements d'interface càd un sprite qui suis les mouvements de la camera, pas besoin d'ajouter l'ObjectGl @@ -37,11 +30,14 @@ public class UIElement extends UIDummy{ this.getObjInPosition(); } + /** + * Ajoute l'ObjectGl lié à la liste de rendu du moteur lié + */ public void init(){ this.engine.add_objectGl(obj); } - private void getObjInPosition(){ + protected void getObjInPosition(){ obj.resetTransform(); obj.scale(new Vector3f(this.scalingFactor, this.scalingFactor, 1.0f)); // Position in the camera space @@ -53,9 +49,4 @@ public class UIElement extends UIDummy{ // Camera position obj.translate(new Vector3f(- engine.transformationView.x, engine.transformationView.y)); } - - public void update(){ - this.getObjInPosition(); - } - } diff --git a/src/engine/gui/UIElementText.java b/src/engine/gui/UIElementText.java index e06fed8..a5208c8 100644 --- a/src/engine/gui/UIElementText.java +++ b/src/engine/gui/UIElementText.java @@ -1,13 +1,10 @@ package engine.gui; - import engine.Engine; import engine.math.Vector3f; -import engine.object.Camera; import engine.object.ObjectGl; import engine.object.Text; -import java.util.ArrayList; import java.util.List; /** @@ -16,12 +13,7 @@ import java.util.List; public class UIElementText extends UIDummy{ private final List objs; - private final Engine engine; - private final Camera camera; private final Text txt; - private float xPos; - private float yPos; - private float zPos; /** * Crée du texte qui suit la caméra @@ -57,7 +49,7 @@ public class UIElementText extends UIDummy{ this.txt.setNewText(txt); } - private void getObjInPosition(){ + protected void getObjInPosition(){ int i = 0; for (ObjectGl obj : this.txt.getCharList()){ obj.resetTransform(); @@ -75,8 +67,4 @@ public class UIElementText extends UIDummy{ } } - public void update(){ - this.getObjInPosition(); - } - } \ No newline at end of file diff --git a/src/engine/input/Button.java b/src/engine/input/Button.java index 942b13f..dd63e34 100644 --- a/src/engine/input/Button.java +++ b/src/engine/input/Button.java @@ -1,22 +1,30 @@ package engine.input; +import engine.Engine; + import java.util.List; +import static org.lwjgl.glfw.GLFW.glfwGetKey; + public class Button { public String name; - private final List buttons; + private final List buttonsGamepad; + private final List buttonsKeyboard; private final GamepadInput controller; - public Button(String name, List buttons, GamepadInput controller){ + public Button(String name, List buttonsGamepad, List buttonsKeyboard, GamepadInput controller){ this.name = name; - this.buttons = buttons; + this.buttonsGamepad = buttonsGamepad; + this.buttonsKeyboard = buttonsKeyboard; this.controller = controller; } public boolean isButtonPressed(){ - for (int i : buttons){ + for (int i : buttonsGamepad){ if (controller.checkPressed(i)) return true; + } for (int i : buttonsKeyboard){ + if (glfwGetKey(Engine.getWindow(), i) == 1) return true; } return false; }