Search in sources :

Example 1 with ColorComponent

use of org.terasology.network.ColorComponent in project Terasology by MovingBlocks.

the class PlayerNameTagSystem method onCharacterActivation.

/**
 * Listening for {@link org.terasology.logic.players.event.OnPlayerSpawnedEvent} does not work, as it is an
 * authority event that does not get processed at clients. That is why we listen for the activation.
 */
@ReceiveEvent(components = CharacterComponent.class)
public void onCharacterActivation(OnActivatedComponent event, EntityRef characterEntity, CharacterComponent characterComponent) {
    EntityRef ownerEntity = networkSystem.getOwnerEntity(characterEntity);
    if (ownerEntity == null) {
        // NPC
        return;
    }
    ClientComponent clientComponent = ownerEntity.getComponent(ClientComponent.class);
    if (clientComponent == null) {
        logger.warn("Can't create player based name tag for character as owner has no client component");
        return;
    }
    if (clientComponent.local) {
        // the character belongs to the local player and does not need a name tag
        return;
    }
    EntityRef clientInfoEntity = clientComponent.clientInfo;
    DisplayNameComponent displayNameComponent = clientInfoEntity.getComponent(DisplayNameComponent.class);
    if (displayNameComponent == null) {
        logger.error("Can't create player based name tag for character as client info has no DisplayNameComponent");
        return;
    }
    String name = displayNameComponent.name;
    float yOffset = characterComponent.nameTagOffset;
    Color color = Color.WHITE;
    ColorComponent colorComponent = clientInfoEntity.getComponent(ColorComponent.class);
    if (colorComponent != null) {
        color = colorComponent.color;
    }
    NameTagComponent nameTagComponent = characterEntity.getComponent(NameTagComponent.class);
    boolean newComponent = nameTagComponent == null;
    if (nameTagComponent == null) {
        nameTagComponent = new NameTagComponent();
    }
    nameTagComponent.text = name;
    nameTagComponent.textColor = color;
    nameTagComponent.yOffset = yOffset;
    if (newComponent) {
        characterEntity.addComponent(nameTagComponent);
    } else {
        characterEntity.saveComponent(nameTagComponent);
    }
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) ColorComponent(org.terasology.network.ColorComponent) Color(org.terasology.rendering.nui.Color) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 2 with ColorComponent

use of org.terasology.network.ColorComponent in project Terasology by MovingBlocks.

the class AbstractClient method addOrSetColorComponent.

private void addOrSetColorComponent(EntityRef clientInfo, Color color) {
    ColorComponent colorComp = clientInfo.getComponent(ColorComponent.class);
    if (colorComp != null) {
        colorComp.color = color;
        clientInfo.saveComponent(colorComp);
    } else {
        colorComp = new ColorComponent();
        colorComp.color = color;
        clientInfo.addComponent(colorComp);
    }
}
Also used : ColorComponent(org.terasology.network.ColorComponent)

Example 3 with ColorComponent

use of org.terasology.network.ColorComponent in project Terasology by MovingBlocks.

the class NetClient method setColor.

public void setColor(Color color) {
    this.color = color;
    ClientComponent client = getEntity().getComponent(ClientComponent.class);
    if (client != null) {
        ColorComponent colorInfo = client.clientInfo.getComponent(ColorComponent.class);
        if (colorInfo != null) {
            colorInfo.color = color;
            client.clientInfo.saveComponent(colorInfo);
        }
    }
}
Also used : ColorComponent(org.terasology.network.ColorComponent) ClientComponent(org.terasology.network.ClientComponent)

Example 4 with ColorComponent

use of org.terasology.network.ColorComponent in project Terasology by MovingBlocks.

the class PlayerUtil method getColoredPlayerName.

public static String getColoredPlayerName(EntityRef from) {
    DisplayNameComponent displayInfo = from.getComponent(DisplayNameComponent.class);
    ColorComponent colorInfo = from.getComponent(ColorComponent.class);
    String playerName = (displayInfo != null) ? displayInfo.name : "Unknown";
    if (colorInfo != null) {
        playerName = FontColor.getColored(playerName, colorInfo.color);
    }
    return playerName;
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) ColorComponent(org.terasology.network.ColorComponent)

Aggregations

ColorComponent (org.terasology.network.ColorComponent)4 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)2 ClientComponent (org.terasology.network.ClientComponent)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)1 Color (org.terasology.rendering.nui.Color)1