setBackground added in UIElementText.java

This commit is contained in:
Antoine 2021-06-16 16:05:06 +02:00
parent 9edc455895
commit 24fc20be39
2 changed files with 26 additions and 5 deletions

View File

@ -13,8 +13,10 @@ import java.util.List;
*/ */
public class UIElementText extends UIDummy{ public class UIElementText extends UIDummy{
private final List<Letter> objs; private List<Letter> objs;
private final Text txt; private final Text txt;
private ObjectGl background;
private Vector3f colorBg;
/** /**
* Crée du texte qui suit la caméra * Crée du texte qui suit la caméra
@ -33,6 +35,13 @@ public class UIElementText extends UIDummy{
this.yPos = posY; this.yPos = posY;
this.zPos = posZ; this.zPos = posZ;
this.getObjInPosition(); this.getObjInPosition();
this.background = null;
}
public void setBackground(Vector3f color){
this.colorBg = color;
this.background = new ObjectGl(this.zPos, objs.size() * 10f, 10f, this.scalingFactor, null, this.colorBg );
engine.add_objectGl(this.background);
} }
/** /**
@ -50,6 +59,11 @@ public class UIElementText extends UIDummy{
*/ */
public void setText(String txt){ public void setText(String txt){
this.txt.setNewText(txt); this.txt.setNewText(txt);
this.objs = this.txt.getCharList(); //Trop bizarre, on dirait que this.objs prends bien en compte le rajout des nouveaux elements mais pas les suppressions ??????????????
if (this.background != null){
engine.remove_objectGl(background);
setBackground(this.colorBg);
}
} }
public void setShader(String vert, String frag, boolean indexBasedShader, boolean useTime){ public void setShader(String vert, String frag, boolean indexBasedShader, boolean useTime){
@ -62,20 +76,25 @@ public class UIElementText extends UIDummy{
protected void getObjInPosition(){ protected void getObjInPosition(){
int i = 0; int i = 0;
for (ObjectGl obj : this.txt.getCharList()){
obj.resetTransform();
obj.scale(new Vector3f(this.scalingFactor, this.scalingFactor, 1.0f));
// Position in the camera space
float dimension = this.camera.getDimension(); float dimension = this.camera.getDimension();
float ar = this.camera.getAspectRatio().y / this.camera.getAspectRatio().x; float ar = this.camera.getAspectRatio().y / this.camera.getAspectRatio().x;
float x = dimension * 2 * this.xPos - dimension; float x = dimension * 2 * this.xPos - dimension;
float y = dimension * ar * 2 * this.yPos - dimension * ar; float y = dimension * ar * 2 * this.yPos - dimension * ar;
for (ObjectGl obj : this.txt.getCharList()){
obj.resetTransform();
obj.scale(new Vector3f(this.scalingFactor, this.scalingFactor, 1.0f));
// Position in the camera space
obj.translate(new Vector3f(x, y, this.zPos)); obj.translate(new Vector3f(x, y, this.zPos));
obj.translate(new Vector3f(10.0f * i * this.scalingFactor)); // 10.0f est dependant de la taille de la police à changer si besoin rendre dynamique si plusieurs police obj.translate(new Vector3f(10.0f * i * this.scalingFactor)); // 10.0f est dependant de la taille de la police à changer si besoin rendre dynamique si plusieurs police
// Camera position // Camera position
obj.translate(new Vector3f(- engine.getTransformationView().x, - engine.getTransformationView().y)); obj.translate(new Vector3f(- engine.getTransformationView().x, - engine.getTransformationView().y));
i++; i++;
} }
if (background != null){
background.resetTransform();
background.scale(new Vector3f(this.scalingFactor, this.scalingFactor, 1f));
background.translate(new Vector3f(x, y));
}
} }
} }

View File

@ -179,8 +179,10 @@ public class match {
// GUI setup // GUI setup
coordP1 = new UIElementText("objP1: " + objP1.getXPos() + ":" + objP1.getYPos() + " P1: " + p1.getPosX() +":" + p1.getPosY(), 5f, 0f, 0.2f, 80f, engine); coordP1 = new UIElementText("objP1: " + objP1.getXPos() + ":" + objP1.getYPos() + " P1: " + p1.getPosX() +":" + p1.getPosY(), 5f, 0f, 0.2f, 80f, engine);
coordP1.setBackground(new Vector3f(0f,0f,0f));
engine.add_uiElement(coordP1); engine.add_uiElement(coordP1);
coordP2 = new UIElementText("objP2: " + objP2.getXPos() + ":" + objP2.getYPos() + " P1: " + p2.getPosX() +":" + p2.getPosY(), 5f, 0f, 0.1f, 80f, engine); coordP2 = new UIElementText("objP2: " + objP2.getXPos() + ":" + objP2.getYPos() + " P1: " + p2.getPosX() +":" + p2.getPosY(), 5f, 0f, 0.1f, 80f, engine);
coordP2.setBackground(new Vector3f(0f,0f,0f));
engine.add_uiElement(coordP2); engine.add_uiElement(coordP2);
// Barre de vie // Barre de vie
healthBarP1Obj = new HorizontalProgressBar(90f, 8.5f, 0.4f, 100f, p1.getCurrentHP(), p1.getMaxHP(), false); healthBarP1Obj = new HorizontalProgressBar(90f, 8.5f, 0.4f, 100f, p1.getCurrentHP(), p1.getMaxHP(), false);