Search in sources :

Example 1 with ColorComponent

use of org.terasology.engine.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.engine.network.ColorComponent) ClientComponent(org.terasology.engine.network.ClientComponent)

Example 2 with ColorComponent

use of org.terasology.engine.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.engine.logic.common.DisplayNameComponent) ColorComponent(org.terasology.engine.network.ColorComponent)

Example 3 with ColorComponent

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

the class AbstractClient method addOrSetColorComponent.

/**
 * Used to change or add a color to the client entity.
 * @param clientInfo
 * @param color Used to change the clients color to this
 */
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.engine.network.ColorComponent)

Example 4 with ColorComponent

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

the class WorldCommands method simulate.

@Command(shortDescription = "Random", runOnServer = true)
public String simulate(@Sender EntityRef sender) {
    EntityRef simulatedEntity = entityManager.create("engine:multiWorldSim");
    DisplayNameComponent displayNameComponent = simulatedEntity.getComponent(DisplayNameComponent.class);
    displayNameComponent.name = "I-Travel-Worlds-" + simulatedEntity.getId();
    simulatedEntity.saveComponent(displayNameComponent);
    ColorComponent colorComponent = simulatedEntity.getComponent(ColorComponent.class);
    colorComponent.color = Color.RED;
    simulatedEntity.saveComponent(colorComponent);
    sender.send(new ChatMessageEvent("yay", simulatedEntity));
    return "done";
}
Also used : DisplayNameComponent(org.terasology.engine.logic.common.DisplayNameComponent) ChatMessageEvent(org.terasology.engine.logic.chat.ChatMessageEvent) ColorComponent(org.terasology.engine.network.ColorComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 5 with ColorComponent

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

the class PlayerNameTagSystem method onCharacterActivation.

/**
 * Listening for {@link 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) {
        // the character is not owned by a client (no other player)
        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.debug("Cannot create name tag for client without DisplayNameComponent");
        return;
    }
    String name = displayNameComponent.name;
    float yOffset = characterComponent.nameTagOffset;
    ColorComponent colorComponent = clientInfoEntity.getComponent(ColorComponent.class);
    final Color color = colorComponent != null ? colorComponent.color : Color.WHITE;
    characterEntity.upsertComponent(NameTagComponent.class, maybeNameTag -> {
        NameTagComponent nameTagComponent = maybeNameTag.orElse(new NameTagComponent());
        nameTagComponent.text = name;
        nameTagComponent.textColor = color;
        nameTagComponent.yOffset = yOffset;
        return nameTagComponent;
    });
}
Also used : DisplayNameComponent(org.terasology.engine.logic.common.DisplayNameComponent) ColorComponent(org.terasology.engine.network.ColorComponent) Color(org.terasology.nui.Color) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

ColorComponent (org.terasology.engine.network.ColorComponent)5 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)3 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)2 ClientComponent (org.terasology.engine.network.ClientComponent)2 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)1 ChatMessageEvent (org.terasology.engine.logic.chat.ChatMessageEvent)1 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)1 Color (org.terasology.nui.Color)1