From 24fc20be3999ea0ac9e18f2742a6191bd166254d Mon Sep 17 00:00:00 2001 From: Antoine Date: Wed, 16 Jun 2021 16:05:06 +0200 Subject: [PATCH] setBackground added in UIElementText.java --- src/engine/gui/UIElementText.java | 29 ++++++++++++++++++++++++----- src/gameplay/match/match.java | 2 ++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/engine/gui/UIElementText.java b/src/engine/gui/UIElementText.java index f6e4248..357536b 100644 --- a/src/engine/gui/UIElementText.java +++ b/src/engine/gui/UIElementText.java @@ -13,8 +13,10 @@ import java.util.List; */ public class UIElementText extends UIDummy{ - private final List objs; + private List objs; private final Text txt; + private ObjectGl background; + private Vector3f colorBg; /** * Crée du texte qui suit la caméra @@ -33,6 +35,13 @@ public class UIElementText extends UIDummy{ this.yPos = posY; this.zPos = posZ; 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){ 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){ @@ -62,20 +76,25 @@ public class UIElementText extends UIDummy{ protected void getObjInPosition(){ int i = 0; + float dimension = this.camera.getDimension(); + float ar = this.camera.getAspectRatio().y / this.camera.getAspectRatio().x; + float x = dimension * 2 * this.xPos - dimension; + 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 - float dimension = this.camera.getDimension(); - float ar = this.camera.getAspectRatio().y / this.camera.getAspectRatio().x; - float x = dimension * 2 * this.xPos - dimension; - float y = dimension * ar * 2 * this.yPos - dimension * ar; 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 // Camera position obj.translate(new Vector3f(- engine.getTransformationView().x, - engine.getTransformationView().y)); i++; } + if (background != null){ + background.resetTransform(); + background.scale(new Vector3f(this.scalingFactor, this.scalingFactor, 1f)); + background.translate(new Vector3f(x, y)); + } } } \ No newline at end of file diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java index 05649d6..eda292c 100644 --- a/src/gameplay/match/match.java +++ b/src/gameplay/match/match.java @@ -179,8 +179,10 @@ public class match { // GUI setup 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); 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); // Barre de vie healthBarP1Obj = new HorizontalProgressBar(90f, 8.5f, 0.4f, 100f, p1.getCurrentHP(), p1.getMaxHP(), false);