Search in sources :

Example 16 with UILabel

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);
    }
}
Also used : UILabel(org.terasology.nui.widgets.UILabel)

Example 17 with UILabel

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);
                    }
                });
            }
        }
    }
}
Also used : AnatomyStatusGatheringEvent(org.terasology.anatomy.event.AnatomyStatusGatheringEvent) UILabel(org.terasology.nui.widgets.UILabel) List(java.util.List)

Example 18 with UILabel

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));
        }
    });
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) Message(org.terasology.engine.logic.console.Message) ScrollableArea(org.terasology.nui.layouts.ScrollableArea) UIText(org.terasology.nui.widgets.UIText) Stream(java.util.stream.Stream) Name(org.terasology.gestalt.naming.Name)

Example 19 with UILabel

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));
        }
    }
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) UISkinFormat(org.terasology.engine.rendering.nui.skin.UISkinFormat) UIElement(org.terasology.nui.asset.UIElement) InputStreamReader(java.io.InputStreamReader) UIFormat(org.terasology.engine.rendering.nui.asset.UIFormat) JsonTree(org.terasology.nui.widgets.treeView.JsonTree) UISkinData(org.terasology.nui.skin.UISkinData) FileNotFoundException(java.io.FileNotFoundException) UIWidget(org.terasology.nui.UIWidget) JsonElement(com.google.gson.JsonElement) AssetDataFile(org.terasology.gestalt.assets.format.AssetDataFile) JsonReader(com.google.gson.stream.JsonReader) JsonParser(com.google.gson.JsonParser)

Example 20 with UILabel

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);
    }
}
Also used : UILabel(org.terasology.nui.widgets.UILabel)

Aggregations

UILabel (org.terasology.nui.widgets.UILabel)27 UIButton (org.terasology.nui.widgets.UIButton)7 List (java.util.List)5 RowLayout (org.terasology.nui.layouts.RowLayout)5 Vector2i (org.joml.Vector2i)4 UICheckbox (org.terasology.nui.widgets.UICheckbox)4 UISpace (org.terasology.nui.widgets.UISpace)4 UIText (org.terasology.nui.widgets.UIText)4 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 UIWidget (org.terasology.nui.UIWidget)3 ColumnLayout (org.terasology.nui.layouts.ColumnLayout)3 UISlider (org.terasology.nui.widgets.UISlider)3 Defaults (com.google.common.base.Defaults)2 JsonElement (com.google.gson.JsonElement)2 Constructor (java.lang.reflect.Constructor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Parameter (java.lang.reflect.Parameter)2