Search in sources :

Example 1 with UILabel

use of org.terasology.nui.widgets.UILabel in project Terasology by MovingBlocks.

the class NUIEditorScreen method resetPreviewWidget.

/**
 * {@inheritDoc}
 */
@Override
public void resetPreviewWidget() {
    try {
        // Serialize the editor's contents and update the widget.
        JsonElement element = JsonTreeConverter.deserialize(getEditor().getRoot());
        UIWidget widget = new UIFormat().load(element, alternativeLocale).getRootWidget();
        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) UIFormat(org.terasology.engine.rendering.nui.asset.UIFormat) JsonElement(com.google.gson.JsonElement) UIWidget(org.terasology.nui.UIWidget)

Example 2 with UILabel

use of org.terasology.nui.widgets.UILabel in project Terasology by MovingBlocks.

the class JoinGameScreen method refreshPing.

private void refreshPing() {
    String address = visibleList.getSelection().getAddress();
    int port = visibleList.getSelection().getPort();
    String name = visibleList.getSelection().getName();
    UILabel ping = find("ping", UILabel.class);
    ping.setText("Requested");
    Thread getPing = new Thread(() -> {
        PingService pingService = new PingService(address, port);
        // we're not on the game thread, so we cannot modify GUI elements directly
        try {
            long responseTime = pingService.call();
            if (visibleList.getSelection().getAddress().equals(address)) {
                GameThread.asynch(() -> ping.setText(responseTime + " ms."));
            }
        } catch (IOException e) {
            String text = translationSystem.translate("${engine:menu#connection-failed}");
            // Check if selection name is same as earlier when response is received before updating ping field
            if (name.equals(visibleList.getSelection().getName())) {
                GameThread.asynch(() -> ping.setText(FontColor.getColored(text, Color.RED)));
            }
        }
    });
    // TODO: once the common thread pool is in place this could be posted there and the
    // returned Future could be kept and cancelled as soon the selected menu entry changes
    getPing.start();
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) PingService(org.terasology.engine.network.PingService) IOException(java.io.IOException) GameThread(org.terasology.engine.core.GameThread)

Example 3 with UILabel

use of org.terasology.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.nui.widgets.UILabel) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) ServerInfo(org.terasology.engine.config.ServerInfo) UIButton(org.terasology.nui.widgets.UIButton)

Example 4 with UILabel

use of org.terasology.nui.widgets.UILabel in project Terasology by MovingBlocks.

the class MainMenuScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    UILabel versionLabel = find("version", UILabel.class);
    versionLabel.setText(TerasologyVersion.getInstance().getHumanVersion());
    UILabel jvmWarningLabel = find("nonNativeJvmWarning", UILabel.class);
    jvmWarningLabel.setVisible(NonNativeJVMDetector.JVM_ARCH_IS_NONNATIVE);
    SelectGameScreen selectScreen = getManager().createScreen(SelectGameScreen.ASSET_URI, SelectGameScreen.class);
    UniverseWrapper universeWrapper = new UniverseWrapper();
    WidgetUtil.trySubscribe(this, "singleplayer", button -> {
        universeWrapper.setLoadingAsServer(false);
        selectScreen.setUniverseWrapper(universeWrapper);
        triggerForwardAnimation(selectScreen);
    });
    WidgetUtil.trySubscribe(this, "multiplayer", button -> {
        universeWrapper.setLoadingAsServer(true);
        selectScreen.setUniverseWrapper(universeWrapper);
        triggerForwardAnimation(selectScreen);
    });
    WidgetUtil.trySubscribe(this, "join", button -> {
        if (storageService.getStatus() == StorageServiceWorkerStatus.WORKING) {
            ConfirmPopup confirmPopup = getManager().pushScreen(ConfirmPopup.ASSET_URI, ConfirmPopup.class);
            confirmPopup.setMessage(translationSystem.translate("${engine:menu#warning}"), translationSystem.translate("${engine:menu#storage-service-working}"));
            confirmPopup.setOkHandler(() -> triggerForwardAnimation(JoinGameScreen.ASSET_URI));
        } else {
            triggerForwardAnimation(JoinGameScreen.ASSET_URI);
        }
    });
    WidgetUtil.trySubscribe(this, "settings", button -> triggerForwardAnimation(SettingsMenuScreen.ASSET_URI));
    WidgetUtil.trySubscribe(this, "extras", button -> triggerForwardAnimation(ExtrasMenuScreen.ASSET_URI));
    WidgetUtil.trySubscribe(this, "exit", button -> engine.shutdown());
    WidgetUtil.trySubscribe(this, "storageServiceAction", widget -> triggerForwardAnimation(PlayerSettingsScreen.ASSET_URI));
}
Also used : UILabel(org.terasology.nui.widgets.UILabel)

Example 5 with UILabel

use of org.terasology.nui.widgets.UILabel in project Terasology by MovingBlocks.

the class MessagePopup 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