Search in sources :

Example 1 with FloatingTextComponent

use of org.terasology.engine.rendering.logic.FloatingTextComponent in project Terasology by MovingBlocks.

the class NameTagClientSystem method createOrUpdateNameTagFor.

private void createOrUpdateNameTagFor(EntityRef entity, NameTagComponent nameTagComponent) {
    EntityRef nameTag = nameTagEntityToFloatingTextMap.get(entity);
    Vector3f offset = new Vector3f(0, nameTagComponent.yOffset, 0);
    if (nameTag != null) {
        FloatingTextComponent floatingText = nameTag.getComponent(FloatingTextComponent.class);
        floatingText.text = nameTagComponent.text;
        floatingText.textColor = nameTagComponent.textColor;
        floatingText.scale = nameTagComponent.scale;
        nameTag.saveComponent(floatingText);
        LocationComponent nameTagLoc = nameTag.getComponent(LocationComponent.class);
        nameTagLoc.setLocalPosition(offset);
        nameTag.saveComponent(nameTagLoc);
    } else {
        EntityBuilder nameTagBuilder = entityManager.newBuilder();
        FloatingTextComponent floatingTextComponent = new FloatingTextComponent();
        nameTagBuilder.addComponent(floatingTextComponent);
        LocationComponent locationComponent = new LocationComponent();
        nameTagBuilder.addComponent(locationComponent);
        floatingTextComponent.text = nameTagComponent.text;
        floatingTextComponent.textColor = nameTagComponent.textColor;
        floatingTextComponent.scale = nameTagComponent.scale;
        nameTagBuilder.setOwner(entity);
        nameTagBuilder.setPersistent(false);
        nameTag = nameTagBuilder.build();
        nameTagEntityToFloatingTextMap.put(entity, nameTag);
        Location.attachChild(entity, nameTag, offset, new Quaternionf());
    }
}
Also used : Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf) FloatingTextComponent(org.terasology.engine.rendering.logic.FloatingTextComponent) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Aggregations

Quaternionf (org.joml.Quaternionf)1 Vector3f (org.joml.Vector3f)1 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1 FloatingTextComponent (org.terasology.engine.rendering.logic.FloatingTextComponent)1