Search in sources :

Example 11 with UILabel

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

Example 12 with UILabel

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

Example 13 with UILabel

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

Example 14 with UILabel

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

Example 15 with UILabel

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());
            }
        });
    }
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) ReadOnlyBinding(org.terasology.rendering.nui.databinding.ReadOnlyBinding) ServerInfo(org.terasology.config.ServerInfo) UIButton(org.terasology.rendering.nui.widgets.UIButton)

Aggregations

UILabel (org.terasology.rendering.nui.widgets.UILabel)23 UIButton (org.terasology.rendering.nui.widgets.UIButton)6 RowLayout (org.terasology.rendering.nui.layouts.RowLayout)5 UICheckbox (org.terasology.rendering.nui.widgets.UICheckbox)5 Vector2i (org.terasology.math.geom.Vector2i)4 UIWidget (org.terasology.rendering.nui.UIWidget)4 ReadOnlyBinding (org.terasology.rendering.nui.databinding.ReadOnlyBinding)4 UISpace (org.terasology.rendering.nui.widgets.UISpace)4 List (java.util.List)3 DependencyResolver (org.terasology.module.DependencyResolver)3 Module (org.terasology.module.Module)3 Name (org.terasology.naming.Name)3 JsonElement (com.google.gson.JsonElement)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ServerInfo (org.terasology.config.ServerInfo)2 SimpleUri (org.terasology.engine.SimpleUri)2 RegisterBindButton (org.terasology.input.RegisterBindButton)2 ResolutionResult (org.terasology.module.ResolutionResult)2 Canvas (org.terasology.rendering.nui.Canvas)2