De la doc pour les classe dans UIElement, gestion du clavier dans la classe Button.
This commit is contained in:
parent
9ebf04338e
commit
d11a1fa293
@ -294,8 +294,8 @@ public class Engine {
|
|||||||
listZoomPlus.add(InputConst.buttonA);
|
listZoomPlus.add(InputConst.buttonA);
|
||||||
List<Integer> listZoomMinus = new ArrayList<>();
|
List<Integer> listZoomMinus = new ArrayList<>();
|
||||||
listZoomMinus.add(InputConst.buttonB);
|
listZoomMinus.add(InputConst.buttonB);
|
||||||
zoom = new Button("zoom", listZoomPlus, gamepad1);
|
zoom = new Button("zoom", listZoomPlus, new ArrayList<>(), gamepad1);
|
||||||
dezoom = new Button("dezoom", listZoomMinus, gamepad1);
|
dezoom = new Button("dezoom", listZoomMinus, new ArrayList<>(), gamepad1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,26 +1,39 @@
|
|||||||
package engine.gui;
|
package engine.gui;
|
||||||
|
|
||||||
|
import engine.Engine;
|
||||||
|
import engine.object.Camera;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classe dont hérite tous les autres élements d'interface
|
* Classe dont hérite tous les autres élements d'interface
|
||||||
*/
|
*/
|
||||||
public abstract class UIDummy {
|
public abstract class UIDummy {
|
||||||
|
|
||||||
|
protected Engine engine;
|
||||||
|
protected Camera camera;
|
||||||
|
protected float xPos;
|
||||||
|
protected float yPos;
|
||||||
|
protected float zPos;
|
||||||
protected float scalingFactor;
|
protected float scalingFactor;
|
||||||
|
|
||||||
public void init(){
|
public void init(){
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getObjInPosition(){
|
protected void getObjInPosition(){
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method pour le moteur ne pas utiliser
|
* Method pour le moteur ne pas utiliser
|
||||||
* @param scaleFactor
|
* @param scaleFactor tqt fréro
|
||||||
*/
|
*/
|
||||||
public void updateScalingFactor(float scaleFactor){
|
public void updateScalingFactor(float scaleFactor){
|
||||||
this.scalingFactor *= 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(){
|
public void update(){
|
||||||
|
this.getObjInPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package engine.gui;
|
package engine.gui;
|
||||||
|
|
||||||
|
|
||||||
import engine.Engine;
|
import engine.Engine;
|
||||||
import engine.math.Vector3f;
|
import engine.math.Vector3f;
|
||||||
import engine.object.Camera;
|
|
||||||
import engine.object.ObjectGl;
|
import engine.object.ObjectGl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,11 +10,6 @@ import engine.object.ObjectGl;
|
|||||||
public class UIElement extends UIDummy{
|
public class UIElement extends UIDummy{
|
||||||
|
|
||||||
private final ObjectGl obj;
|
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
|
* 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();
|
this.getObjInPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute l'ObjectGl lié à la liste de rendu du moteur lié
|
||||||
|
*/
|
||||||
public void init(){
|
public void init(){
|
||||||
this.engine.add_objectGl(obj);
|
this.engine.add_objectGl(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getObjInPosition(){
|
protected void getObjInPosition(){
|
||||||
obj.resetTransform();
|
obj.resetTransform();
|
||||||
obj.scale(new Vector3f(this.scalingFactor, this.scalingFactor, 1.0f));
|
obj.scale(new Vector3f(this.scalingFactor, this.scalingFactor, 1.0f));
|
||||||
// Position in the camera space
|
// Position in the camera space
|
||||||
@ -53,9 +49,4 @@ public class UIElement extends UIDummy{
|
|||||||
// Camera position
|
// Camera position
|
||||||
obj.translate(new Vector3f(- engine.transformationView.x, engine.transformationView.y));
|
obj.translate(new Vector3f(- engine.transformationView.x, engine.transformationView.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
|
||||||
this.getObjInPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
package engine.gui;
|
package engine.gui;
|
||||||
|
|
||||||
|
|
||||||
import engine.Engine;
|
import engine.Engine;
|
||||||
import engine.math.Vector3f;
|
import engine.math.Vector3f;
|
||||||
import engine.object.Camera;
|
|
||||||
import engine.object.ObjectGl;
|
import engine.object.ObjectGl;
|
||||||
import engine.object.Text;
|
import engine.object.Text;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,12 +13,7 @@ import java.util.List;
|
|||||||
public class UIElementText extends UIDummy{
|
public class UIElementText extends UIDummy{
|
||||||
|
|
||||||
private final List<ObjectGl> objs;
|
private final List<ObjectGl> objs;
|
||||||
private final Engine engine;
|
|
||||||
private final Camera camera;
|
|
||||||
private final Text txt;
|
private final Text txt;
|
||||||
private float xPos;
|
|
||||||
private float yPos;
|
|
||||||
private float zPos;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crée du texte qui suit la caméra
|
* Crée du texte qui suit la caméra
|
||||||
@ -57,7 +49,7 @@ public class UIElementText extends UIDummy{
|
|||||||
this.txt.setNewText(txt);
|
this.txt.setNewText(txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getObjInPosition(){
|
protected void getObjInPosition(){
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (ObjectGl obj : this.txt.getCharList()){
|
for (ObjectGl obj : this.txt.getCharList()){
|
||||||
obj.resetTransform();
|
obj.resetTransform();
|
||||||
@ -75,8 +67,4 @@ public class UIElementText extends UIDummy{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
|
||||||
this.getObjInPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,22 +1,30 @@
|
|||||||
package engine.input;
|
package engine.input;
|
||||||
|
|
||||||
|
import engine.Engine;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.lwjgl.glfw.GLFW.glfwGetKey;
|
||||||
|
|
||||||
public class Button {
|
public class Button {
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
private final List<Integer> buttons;
|
private final List<Integer> buttonsGamepad;
|
||||||
|
private final List<Integer> buttonsKeyboard;
|
||||||
private final GamepadInput controller;
|
private final GamepadInput controller;
|
||||||
|
|
||||||
public Button(String name, List<Integer> buttons, GamepadInput controller){
|
public Button(String name, List<Integer> buttonsGamepad, List<Integer> buttonsKeyboard, GamepadInput controller){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.buttons = buttons;
|
this.buttonsGamepad = buttonsGamepad;
|
||||||
|
this.buttonsKeyboard = buttonsKeyboard;
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isButtonPressed(){
|
public boolean isButtonPressed(){
|
||||||
for (int i : buttons){
|
for (int i : buttonsGamepad){
|
||||||
if (controller.checkPressed(i)) return true;
|
if (controller.checkPressed(i)) return true;
|
||||||
|
} for (int i : buttonsKeyboard){
|
||||||
|
if (glfwGetKey(Engine.getWindow(), i) == 1) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user