diff --git a/src/engine/Engine.java b/src/engine/Engine.java index 7c495d2..999fab6 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -186,6 +186,10 @@ public class Engine { this.objectsGl.remove(obj); } + public void remove_objectsGl(List obj) { + this.objectsGl.removeAll(obj); + } + /* UIElement Management */ diff --git a/src/engine/gui/UIElementText.java b/src/engine/gui/UIElementText.java index f6eb4aa..cc89d03 100644 --- a/src/engine/gui/UIElementText.java +++ b/src/engine/gui/UIElementText.java @@ -4,7 +4,7 @@ import engine.Engine; import engine.math.Vector3f; import engine.object.Letter; import engine.object.ObjectGl; -import engine.object.Text; +import engine.object_wrapper.Text; import java.util.List; diff --git a/src/engine/gui/UIInputList.java b/src/engine/gui/UIInputList.java new file mode 100644 index 0000000..907625d --- /dev/null +++ b/src/engine/gui/UIInputList.java @@ -0,0 +1,116 @@ +package engine.gui; + +import engine.Engine; +import engine.loader.ControllerPromptTextureLoader; +import engine.object.ObjectGl; +import gameplay.input.InputBuffer; +import gameplay.input.Inputs; + +import java.util.ArrayList; +import java.util.List; + +public class UIInputList extends UIDummy{ + + private InputBuffer inputBuffer; + private int posBuffer; + private int sizeBuffer; + private List listIcon; + private ControllerPromptTextureLoader tex; + + public UIInputList(InputBuffer inputBuffer, float size, float posX, float posY, float posZ, Engine engine){ + this.engine = engine; + this.camera = engine.getCamera(); + this.scalingFactor = size; + this.xPos = posX; + this.yPos = posY; + this.zPos = posZ; + this.inputBuffer = inputBuffer; + this.tex = new ControllerPromptTextureLoader(); + } + + public void init(){ + this.posBuffer = this.inputBuffer.getPos(); + this.sizeBuffer = this.inputBuffer.getSize(); + this.listIcon = new ArrayList<>(); + } + + protected void getObjInPosition(){ + } + + public void createNextButton(int i){ + boolean[] input = inputBuffer.getInputList()[i].getTab(); + if (input[0]) { + // UP + ObjectGl obj = new ObjectGl(100f, 10f, 10f, 10f, null, null); + obj.setTexture(tex.up); + listIcon.add(obj); + } if (input[1]){ + // DOWN + ObjectGl obj = new ObjectGl(100f, 10f, 10f, 10f, null, null); + obj.setTexture(tex.down); + listIcon.add(obj); + } if (input[2]){ //Pour l'instant on fait comme si l'avant était toujours à droite donc arrière à gauche + // BACK + ObjectGl obj = new ObjectGl(100f, 10f, 10f, 10f, null, null); + obj.setTexture(tex.left); + listIcon.add(obj); + } if (input[3]){ + // FORWARD + ObjectGl obj = new ObjectGl(100f, 10f, 10f, 10f, null, null); + obj.setTexture(tex.right); + listIcon.add(obj); + } if (input[4]){ + // A + ObjectGl obj = new ObjectGl(100f, 10f, 10f, 10f, null, null); + obj.setTexture(tex.X); + listIcon.add(obj); + } if (input[5]){ + // B + ObjectGl obj = new ObjectGl(100f, 10f, 10f, 10f, null, null); + obj.setTexture(tex.A); + listIcon.add(obj); + } if (input[6]){ + // C + ObjectGl obj = new ObjectGl(100f, 10f, 10f, 10f, null, null); + obj.setTexture(tex.Y); + listIcon.add(obj); + } if (input[7]){ + // D + ObjectGl obj = new ObjectGl(100f, 10f, 10f, 10f, null, null); + obj.setTexture(tex.B); + listIcon.add(obj); + } + for (ObjectGl obj : listIcon){ + obj.setShader("shaders/ObjectGlTex/vert.glsl", "shaders/ObjectGlTex/frag.glsl"); + } + } + + public void createButtonList(){ + + engine.remove_objectsGl(listIcon); + listIcon = new ArrayList<>(); + + int count = 0; + int index = this.posBuffer; + do { + createNextButton(index); + index --; + count ++; + if (index < 0){ + index = this.sizeBuffer - 1; + } + } while(count < 30); + + engine.add_objectsGl(listIcon); + } + + /** + * Encules les perfs :( le problème c'est forcement le chargement des textures + */ + public void update(){ + this.posBuffer = this.inputBuffer.getPos(); + createButtonList(); + // Mettre à la bonne position + this.getObjInPosition(); + } +} diff --git a/src/engine/loader/ControllerPromptTextureLoader.java b/src/engine/loader/ControllerPromptTextureLoader.java new file mode 100644 index 0000000..c759bb8 --- /dev/null +++ b/src/engine/loader/ControllerPromptTextureLoader.java @@ -0,0 +1,26 @@ +package engine.loader; + +import engine.graphics.Texture; + +public class ControllerPromptTextureLoader { + + public Texture up; + public Texture down; + public Texture left; + public Texture right; + public Texture X; + public Texture A; + public Texture Y; + public Texture B; + + public ControllerPromptTextureLoader(){ + up = new Texture("textures/keyboard_pad_glyphs/xbox/XboxOne_Dpad_Up.png", 0); + down = new Texture("textures/keyboard_pad_glyphs/xbox/XboxOne_Dpad_Down.png", 0); + left = new Texture("textures/keyboard_pad_glyphs/xbox/XboxOne_Dpad_Left.png", 0); + right = new Texture("textures/keyboard_pad_glyphs/xbox/XboxOne_Dpad_Right.png", 0); + A = new Texture("textures/keyboard_pad_glyphs/xbox/XboxOne_A.png", 0); + B = new Texture("textures/keyboard_pad_glyphs/xbox/XboxOne_B.png", 0); + X = new Texture("textures/keyboard_pad_glyphs/xbox/XboxOne_X.png", 0); + Y = new Texture("textures/keyboard_pad_glyphs/xbox/XboxOne_Y.png", 0); + } +} diff --git a/src/engine/object/ObjectGl.java b/src/engine/object/ObjectGl.java index 552ccf1..a4d7edb 100644 --- a/src/engine/object/ObjectGl.java +++ b/src/engine/object/ObjectGl.java @@ -154,6 +154,14 @@ public class ObjectGl { this.texture = new Texture(texPath, 0); } + /** + * Set a new texture to be used + * @param texture already loaded Texture + */ + public void setTexture(Texture texture) { + this.texture = texture; + } + /** * Change the wrapping coordinate, beware every sprite have to be of the same size if you don't want strange behavior * @param x starting wrapping on the horizontal axis diff --git a/src/engine/object/Text.java b/src/engine/object_wrapper/Text.java similarity index 97% rename from src/engine/object/Text.java rename to src/engine/object_wrapper/Text.java index ffd7d1b..d1ba373 100644 --- a/src/engine/object/Text.java +++ b/src/engine/object_wrapper/Text.java @@ -1,8 +1,10 @@ -package engine.object; +package engine.object_wrapper; import engine.Engine; import engine.gui.UIElement; import engine.math.Vector3f; +import engine.object.Letter; +import engine.object.ObjectGl; import java.util.ArrayList; import java.util.List; diff --git a/src/gameplay/hitboxes/HitBox.java b/src/gameplay/hitboxes/HitBox.java index fafbc86..56515ce 100644 --- a/src/gameplay/hitboxes/HitBox.java +++ b/src/gameplay/hitboxes/HitBox.java @@ -99,7 +99,7 @@ public class HitBox { } public void reverseHorizontally() { - this.position_x = 138*4 - position_x; //Il faut la largeur de la sprite + this.position_x = 138*4 - position_x; this.size_x = -this.size_x; } } \ No newline at end of file diff --git a/src/gameplay/input/InputBuffer.java b/src/gameplay/input/InputBuffer.java index b4452ac..81252b1 100644 --- a/src/gameplay/input/InputBuffer.java +++ b/src/gameplay/input/InputBuffer.java @@ -149,5 +149,17 @@ public class InputBuffer { } this.pos = 0; } + + public Inputs[] getInputList(){ + return inputList; + } + + public int getPos(){ + return pos; + } + + public int getSize(){ + return size; + } } diff --git a/src/gameplay/input/Inputs.java b/src/gameplay/input/Inputs.java index ee429cf..1a0fec6 100644 --- a/src/gameplay/input/Inputs.java +++ b/src/gameplay/input/Inputs.java @@ -126,5 +126,9 @@ public class Inputs { this.tab[i] = false; } } + + public boolean[] getTab(){ + return tab; + } } diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java index a3db35e..2ca4a7f 100644 --- a/src/gameplay/match/match.java +++ b/src/gameplay/match/match.java @@ -3,6 +3,7 @@ package gameplay.match; import engine.Engine; import engine.gui.UIElement; import engine.gui.UIElementText; +import engine.gui.UIInputList; import engine.input.Button; import engine.input.GamepadInput; import engine.math.Vector3f; @@ -77,10 +78,11 @@ public class match { private static HorizontalProgressBar healthBarP1Obj; private static HorizontalProgressBar healthBarP2Obj; private static UIElementText timerUI; + private static UIInputList inputListP1; // Debug private static boolean showP1Hitbox = true; // TODO modifier pour le rendre activable - private static boolean showP2Hitbox = false; + private static boolean showP2Hitbox = true; private static List listHitboxObj = new ArrayList<>(); private static Sprite objP1,objP2; @@ -103,6 +105,10 @@ public class match { // TODO meilleur implémentation possible objP1.getShadow().translate(new Vector3f(0f,p1.getPosY(),0)); objP2.getShadow().translate(new Vector3f(0f,p2.getPosY(),0)); + // Crée l'InputList + inputListP1 = new UIInputList(inputsP1, 10f, 0f, 0.3f, 110f, engine); + engine.add_uiElement(inputListP1); + inputListP1.init(); } /**