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);
}
}
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);
}
}
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);
}
}
}
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;
}
Aggregations