UIInputList proto

This commit is contained in:
Antoine
2021-06-18 21:14:03 +02:00
parent ff16ea1ae9
commit 2b193c50f3
10 changed files with 182 additions and 4 deletions

View File

@ -186,6 +186,10 @@ public class Engine {
this.objectsGl.remove(obj);
}
public void remove_objectsGl(List<ObjectGl> obj) {
this.objectsGl.removeAll(obj);
}
/*
UIElement Management
*/

View File

@ -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;

View File

@ -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<ObjectGl> 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();
}
}

View File

@ -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);
}
}

View File

@ -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

View File

@ -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;