use of org.terasology.rendering.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, UISkin.class));
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.rendering.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.rendering.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class CanvasImpl method addInteractionRegion.
@Override
public void addInteractionRegion(InteractionListener listener, String tooltip, Rect2i region) {
UIWidget tooltipLabelWidget = (tooltip == null || tooltip.isEmpty()) ? null : new UILabel(tooltip);
addInteractionRegion(listener, tooltipLabelWidget, region);
}
use of org.terasology.rendering.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class ConfirmPopup 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);
}
}
use of org.terasology.rendering.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class JoinGameScreen method bindCustomButtons.
private void bindCustomButtons() {
UIList<?> customServerList = find("customServerList", UIList.class);
ReadOnlyBinding<Boolean> localSelectedServerOnly = new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return customServerList.getSelection() != null;
}
};
UIButton add = find("add", UIButton.class);
if (add != null) {
add.subscribe(button -> {
AddServerPopup popup = getManager().pushScreen(AddServerPopup.ASSET_URI, AddServerPopup.class);
// select the entry if added successfully
popup.onSuccess(item -> {
config.getNetwork().addServerInfo(item);
visibleList.setSelection(item);
});
});
}
UIButton edit = find("edit", UIButton.class);
if (edit != null) {
edit.bindEnabled(localSelectedServerOnly);
edit.subscribe(button -> {
AddServerPopup popup = getManager().pushScreen(AddServerPopup.ASSET_URI, AddServerPopup.class);
ServerInfo info = visibleList.getSelection();
popup.setServerInfo(info);
// editing invalidates the currently known info, so query it again
popup.onSuccess(item -> extInfo.put(item, infoService.requestInfo(item.getAddress(), item.getPort())));
});
}
UIButton removeButton = find("remove", UIButton.class);
if (removeButton != null) {
removeButton.bindEnabled(localSelectedServerOnly);
removeButton.subscribe(button -> {
ServerInfo info = visibleList.getSelection();
if (info != null) {
config.getNetwork().removeServerInfo(info);
extInfo.remove(info);
visibleList.setSelection(null);
}
});
}
UILabel downloadLabel = find("download", UILabel.class);
if (downloadLabel != null) {
downloadLabel.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
return translationSystem.translate(downloader.getStatus());
}
});
}
}
Aggregations