use of org.terasology.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class ObjectLayoutBuilder method populate.
@Override
protected void populate(Binding<T> binding, ColumnLayout layout, ColumnLayout mainLayout) {
layout.removeAllWidgets();
UILabel nameWidget = mainLayout.find(LABEL_WIDGET_ID, UILabel.class);
assert nameWidget != null;
if (binding.get() == null) {
populateNullLayout(binding, layout, nameWidget);
} else {
buildEditorLayout(binding, layout, nameWidget);
}
}
use of org.terasology.nui.widgets.UILabel in project Anatomy by Terasology.
the class AnatomyScreenWindow method updateStatuses.
private void updateStatuses() {
// Only update the statuses if the player character entity actually exists.
if (player == null || player == EntityRef.NULL || player.getId() == 0) {
return;
}
AnatomyStatusGatheringEvent event = new AnatomyStatusGatheringEvent();
player.send(event);
Map<String, List<String>> partEffectsMap = event.getEffectsMap();
Collection<UILabel> labels = findAll(UILabel.class);
for (UILabel label : labels) {
if (label.getId().contains(ANATOMY_PART_PREFIX)) {
String partID = label.getId().substring(ANATOMY_PART_PREFIX.length());
List<String> partEffects = partEffectsMap.get(partID);
if (partEffects == null) {
// No effects for this part
label.setSkin(greenTextSkin);
label.bindTooltipString(new ReadOnlyBinding<String>() {
@Override
public String get() {
return null;
}
});
} else {
// This part has effects
label.setSkin(redTextSkin);
label.setTooltipDelay(0);
label.bindTooltipString(new ReadOnlyBinding<String>() {
@Override
public String get() {
return String.join(",", partEffects);
}
});
}
}
}
}
use of org.terasology.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class ChatScreen method initialise.
@Override
public void initialise() {
final ScrollableArea scrollArea = find("scrollArea", ScrollableArea.class);
scrollArea.moveToBottom();
commandLine = find("commandLine", UIText.class);
getManager().setFocus(commandLine);
commandLine.subscribe(widget -> {
String text = commandLine.getText();
if (StringUtils.isNotBlank(text)) {
String command = "say";
List<String> params = Collections.singletonList(text);
// TODO: move command execution to separate class
console.execute(new Name(command), params, localPlayer.getClientEntity());
commandLine.setText("");
scrollArea.moveToBottom();
NotificationOverlay overlay = nuiManager.addOverlay(NotificationOverlay.ASSET_URI, NotificationOverlay.class);
overlay.setVisible(true);
nuiManager.closeScreen(this);
} else {
commandLine.setText("");
nuiManager.closeScreen(this);
}
});
final UILabel history = find("messageHistory", UILabel.class);
history.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
Iterable<Message> messageIterable = console.getMessages(CoreMessageType.CHAT, CoreMessageType.NOTIFICATION);
Stream<Message> messageStream = StreamSupport.stream(messageIterable.spliterator(), false);
return messageStream.map(Message::getMessage).collect(Collectors.joining(Console.NEW_LINE));
}
});
}
use of org.terasology.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class NUISkinEditorScreen method resetPreviewWidget.
/**
* {@inheritDoc}
*/
@Override
public void resetPreviewWidget() {
if (selectedScreen != null) {
try {
// Construct a UISkinData instance.
JsonElement skinElement = JsonTreeConverter.deserialize(getEditor().getRoot());
UISkinData data = new UISkinFormat().load(skinElement);
// Get the selected screen asset.
Optional<UIElement> sourceAsset = assetManager.getAsset(selectedScreen, UIElement.class);
if (!sourceAsset.isPresent()) {
throw new FileNotFoundException(String.format("Asset %s not found", selectedScreen));
}
AssetDataFile source = sourceAsset.get().getSource();
String content;
try (JsonReader reader = new JsonReader(new InputStreamReader(source.openStream(), Charsets.UTF_8))) {
reader.setLenient(true);
content = new JsonParser().parse(reader).toString();
}
if (content != null) {
JsonTree node = JsonTreeConverter.serialize(new JsonParser().parse(content));
JsonElement screenElement = JsonTreeConverter.deserialize(node);
UIWidget widget = new UIFormat().load(screenElement, alternativeLocale).getRootWidget();
// Set the screen's skin using the previously generated UISkinData.
widget.setSkin(Assets.generateAsset(data, UISkinAsset.class).getSkin());
selectedScreenBox.setContent(widget);
}
} catch (Throwable t) {
String truncatedStackTrace = Joiner.on(System.lineSeparator()).join(Arrays.copyOfRange(ExceptionUtils.getStackFrames(t), 0, 10));
selectedScreenBox.setContent(new UILabel(truncatedStackTrace));
}
}
}
use of org.terasology.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class LaunchPopup method setMessage.
public void setMessage(String title, String message) {
UILabel titleLabel = find("title", UILabel.class);
if (titleLabel != null) {
titleLabel.setText(title);
}
UILabel messageLabel = find("message", UILabel.class);
if (messageLabel != null) {
messageLabel.setText(message);
}
}
Aggregations