2021-06-03 16:55:54 +02:00
|
|
|
package engine.object;
|
|
|
|
|
|
|
|
import engine.Engine;
|
2021-06-04 17:29:17 +02:00
|
|
|
import engine.gui.UIElement;
|
2021-06-03 16:55:54 +02:00
|
|
|
import engine.math.Vector3f;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2021-06-04 20:14:10 +02:00
|
|
|
/**
|
|
|
|
* Un texte construit selon la même logique qu'une sprite pour faire un element d'interface utilisez UIElementText
|
|
|
|
*/
|
2021-06-03 16:55:54 +02:00
|
|
|
public class Text {
|
|
|
|
|
2021-06-14 17:03:10 +02:00
|
|
|
private List<Letter> charList;
|
2021-06-03 22:07:52 +02:00
|
|
|
private final float size;
|
|
|
|
private final Engine engine;
|
|
|
|
private final float zPos;
|
2021-06-04 00:53:14 +02:00
|
|
|
|
|
|
|
private Vector3f transformation;
|
2021-06-03 16:55:54 +02:00
|
|
|
|
|
|
|
public Text(String text, float z, float size, Engine engine){
|
|
|
|
this.charList = new ArrayList<>();
|
|
|
|
this.zPos = z;
|
|
|
|
this.size = size;
|
|
|
|
this.engine = engine;
|
2021-06-04 00:53:14 +02:00
|
|
|
this.transformation = new Vector3f();
|
2021-06-03 16:55:54 +02:00
|
|
|
this.textToArrayObjectGl(text);
|
2021-06-04 20:14:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void show(){
|
2021-06-03 22:07:52 +02:00
|
|
|
this.addCharListInEngine();
|
2021-06-03 16:55:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void textToArrayObjectGl(String s){
|
|
|
|
for (int i = 0; i < s.length(); i++){
|
2021-06-14 14:47:05 +02:00
|
|
|
this.charList.add(this.charToObjectGl(s.charAt(i), i));
|
2021-06-03 16:55:54 +02:00
|
|
|
}
|
2021-06-03 22:07:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addCharListInEngine(){
|
2021-06-03 16:55:54 +02:00
|
|
|
int i = 0;
|
2021-06-14 17:03:10 +02:00
|
|
|
for (Letter obj : this.charList){
|
2021-06-03 22:48:54 +02:00
|
|
|
addCharInEngine(i, obj);
|
2021-06-03 16:55:54 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-14 17:03:10 +02:00
|
|
|
private void addCharInEngine(int i, Letter obj){
|
2021-06-03 22:48:54 +02:00
|
|
|
obj.translate(new Vector3f(i * 10.0f * this.size, 0.0f, 0.0f));
|
2021-06-04 00:53:14 +02:00
|
|
|
obj.translate(transformation);
|
2021-06-03 22:48:54 +02:00
|
|
|
this.engine.add_objectGl(obj);
|
|
|
|
}
|
|
|
|
|
2021-06-04 00:53:14 +02:00
|
|
|
public void linkToUIElement(UIElement ui){
|
|
|
|
}
|
|
|
|
|
2021-06-03 22:07:52 +02:00
|
|
|
public void setNewText(String text){
|
2021-06-03 22:48:54 +02:00
|
|
|
int i = 0;
|
2021-06-14 17:03:10 +02:00
|
|
|
for (Letter obj : this.charList) {
|
2021-06-03 22:48:54 +02:00
|
|
|
ObjectGlSetCharWrap(text.charAt(i), obj);
|
|
|
|
i++;
|
|
|
|
if (i >= text.length()) break;
|
|
|
|
}
|
|
|
|
while (i < text.length()){
|
2021-06-14 17:03:10 +02:00
|
|
|
Letter obj = this.charToObjectGl(text.charAt(i), i);
|
2021-06-03 22:48:54 +02:00
|
|
|
this.charList.add(obj);
|
|
|
|
addCharInEngine(i, obj);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (i < this.charList.size()) removeFromIndexToEnd(i);
|
|
|
|
|
2021-06-03 22:07:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-04 00:16:03 +02:00
|
|
|
public void translate(Vector3f vec){
|
2021-06-04 00:53:14 +02:00
|
|
|
transformation = transformation.addXYZ(vec);
|
2021-06-04 00:16:03 +02:00
|
|
|
for (ObjectGl obj : this.charList){
|
|
|
|
obj.translate(vec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-03 20:19:58 +02:00
|
|
|
public void remove(){
|
|
|
|
for (ObjectGl obj : this.charList){
|
|
|
|
this.engine.remove_objectGl(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-04 00:16:03 +02:00
|
|
|
public List<ObjectGl> getObj(){
|
|
|
|
return new ArrayList<>(this.charList);
|
|
|
|
}
|
|
|
|
|
2021-06-03 22:48:54 +02:00
|
|
|
private void removeFromIndexToEnd(int i){
|
|
|
|
int j = 0;
|
2021-06-14 17:03:10 +02:00
|
|
|
for (Letter objectGl : this.charList){
|
2021-06-04 01:05:05 +02:00
|
|
|
if (j >= i) {
|
|
|
|
this.engine.remove_objectGl(objectGl);
|
|
|
|
}
|
2021-06-03 22:48:54 +02:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
this.charList = this.charList.subList(0, i);
|
|
|
|
}
|
|
|
|
|
2021-06-14 17:03:10 +02:00
|
|
|
private Letter charToObjectGl(char a, int index){
|
|
|
|
Letter objectGl = new Letter(this.zPos, 1.0f, 1.0f, this.size, "textures/dejavu10x10_gs_tc.png", null, index);
|
2021-06-03 16:55:54 +02:00
|
|
|
objectGl.setShader("shaders/StylishShaders/BasicVert.glsl","shaders/StylishShaders/TextFrag.glsl");
|
2021-06-03 22:48:54 +02:00
|
|
|
ObjectGlSetCharWrap(a, objectGl);
|
|
|
|
return objectGl;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ObjectGlSetCharWrap(char a, ObjectGl obj){
|
2021-06-03 17:19:09 +02:00
|
|
|
if (a < 132 && a > 96){
|
2021-06-03 22:48:54 +02:00
|
|
|
obj.setTextureWrap(0.0f + (a - 97) * 10.0f,40.0f,10.0f,10.0f, ObjectGl.DEFAULT);
|
2021-06-03 17:19:09 +02:00
|
|
|
}
|
|
|
|
else if (a < 91 && a > 64){
|
2021-06-03 22:48:54 +02:00
|
|
|
obj.setTextureWrap(0.0f + (a - 65) * 10.0f,30.0f,10.0f,10.0f, ObjectGl.DEFAULT);
|
2021-06-03 16:55:54 +02:00
|
|
|
}
|
2021-06-03 22:07:52 +02:00
|
|
|
else if (a < 64 && a > 31){
|
2021-06-03 22:48:54 +02:00
|
|
|
obj.setTextureWrap(0.0f + (a - 32) * 10.0f,0.0f,10.0f,10.0f, ObjectGl.DEFAULT);
|
2021-06-03 22:07:52 +02:00
|
|
|
}
|
2021-06-03 16:55:54 +02:00
|
|
|
}
|
|
|
|
|
2021-06-14 17:03:10 +02:00
|
|
|
public List<Letter> getCharList(){
|
2021-06-04 22:35:31 +02:00
|
|
|
return this.charList;
|
|
|
|
}
|
|
|
|
|
2021-06-03 16:55:54 +02:00
|
|
|
}
|