Search in sources :

Example 16 with UILabel

use of org.terasology.rendering.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();
    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}");
            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.rendering.nui.widgets.UILabel) PingService(org.terasology.network.PingService) IOException(java.io.IOException) GameThread(org.terasology.engine.GameThread)

Example 17 with UILabel

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

the class JoinGameScreen method bindInfoLabels.

private void bindInfoLabels() {
    final ReadOnlyBinding<ServerInfo> infoBinding = new ReadOnlyBinding<ServerInfo>() {

        @Override
        public ServerInfo get() {
            return visibleList.getSelection();
        }
    };
    UILabel name = find("name", UILabel.class);
    if (name != null) {
        name.bindText(BindHelper.bindBoundBeanProperty("name", infoBinding, ServerInfo.class, String.class));
    }
    UILabel owner = find("owner", UILabel.class);
    if (owner != null) {
        owner.bindText(BindHelper.bindBoundBeanProperty("owner", infoBinding, ServerInfo.class, String.class));
    }
    UILabel address = find("address", UILabel.class);
    if (address != null) {
        address.bindText(BindHelper.bindBoundBeanProperty("address", infoBinding, ServerInfo.class, String.class));
    }
    UILabel port = find("port", UILabel.class);
    if (port != null) {
        port.bindText(new IntToStringBinding(BindHelper.bindBoundBeanProperty("port", infoBinding, ServerInfo.class, int.class)));
    }
    UILabel onlinePlayers = find("onlinePlayers", UILabel.class);
    onlinePlayers.bindText(new ReadOnlyBinding<String>() {

        @Override
        public String get() {
            Future<ServerInfoMessage> info = extInfo.get(visibleList.getSelection());
            if (info != null) {
                if (info.isDone()) {
                    return getOnlinePlayersText(info);
                } else {
                    return translationSystem.translate("${engine:menu#join-server-requested}");
                }
            }
            return null;
        }
    });
    UILabel modules = find("modules", UILabel.class);
    modules.bindText(new ReadOnlyBinding<String>() {

        @Override
        public String get() {
            Future<ServerInfoMessage> info = extInfo.get(visibleList.getSelection());
            if (info != null) {
                if (info.isDone()) {
                    return getModulesText(info);
                } else {
                    return translationSystem.translate("${engine:menu#join-server-requested}");
                }
            }
            return null;
        }
    });
    UILabel worlds = find("worlds", UILabel.class);
    worlds.bindText(new ReadOnlyBinding<String>() {

        @Override
        public String get() {
            Future<ServerInfoMessage> info = extInfo.get(visibleList.getSelection());
            if (info != null) {
                if (info.isDone()) {
                    return getWorldText(info);
                } else {
                    return translationSystem.translate("${engine:menu#join-server-requested}");
                }
            }
            return null;
        }
    });
    UIButton joinButton = find("join", UIButton.class);
    if (joinButton != null) {
        joinButton.bindEnabled(new ReadOnlyBinding<Boolean>() {

            @Override
            public Boolean get() {
                return infoBinding.get() != null;
            }
        });
        joinButton.subscribe(button -> {
            config.save();
            ServerInfo item = infoBinding.get();
            if (item != null) {
                join(item.getAddress(), item.getPort());
            }
        });
    }
    UIButton refreshButton = find("refresh", UIButton.class);
    if (refreshButton != null) {
        refreshButton.bindEnabled(new ReadOnlyBinding<Boolean>() {

            @Override
            public Boolean get() {
                return visibleList.getSelection() != null;
            }
        });
        refreshButton.subscribe(button -> {
            refresh();
        });
    }
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) ReadOnlyBinding(org.terasology.rendering.nui.databinding.ReadOnlyBinding) IntToStringBinding(org.terasology.rendering.nui.databinding.IntToStringBinding) ServerInfo(org.terasology.config.ServerInfo) UIButton(org.terasology.rendering.nui.widgets.UIButton) Future(java.util.concurrent.Future)

Example 18 with UILabel

use of org.terasology.rendering.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.rendering.nui.widgets.UILabel)

Example 19 with UILabel

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

the class SelectGameScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    UILabel gameTypeTitle = find("gameTypeTitle", UILabel.class);
    if (gameTypeTitle != null) {
        gameTypeTitle.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                if (loadingAsServer) {
                    return translationSystem.translate("${engine:menu#select-multiplayer-game-sub-title}");
                } else {
                    return translationSystem.translate("${engine:menu#select-singleplayer-game-sub-title}");
                }
            }
        });
    }
    final UILabel saveGamePath = find("saveGamePath", UILabel.class);
    if (saveGamePath != null) {
        saveGamePath.setText(translationSystem.translate("${engine:menu#save-game-path} ") + PathManager.getInstance().getSavesPath().toAbsolutePath().toString());
    }
    final UIList<GameInfo> gameList = find("gameList", UIList.class);
    refreshList(gameList);
    gameList.select(0);
    gameList.subscribe((widget, item) -> loadGame(item));
    CreateGameScreen screen = getManager().createScreen(CreateGameScreen.ASSET_URI, CreateGameScreen.class);
    WidgetUtil.trySubscribe(this, "create", button -> {
        screen.setLoadingAsServer(loadingAsServer);
        triggerForwardAnimation(screen);
    });
    WidgetUtil.trySubscribe(this, "load", button -> {
        GameInfo gameInfo = gameList.getSelection();
        if (gameInfo != null) {
            loadGame(gameInfo);
        }
    });
    WidgetUtil.trySubscribe(this, "delete", button -> {
        GameInfo gameInfo = gameList.getSelection();
        if (gameInfo != null) {
            Path world = PathManager.getInstance().getSavePath(gameInfo.getManifest().getTitle());
            try {
                FilesUtil.recursiveDelete(world);
                gameList.getList().remove(gameInfo);
                gameList.setSelection(null);
            } catch (Exception e) {
                logger.error("Failed to delete saved game", e);
                getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error Deleting Game", e.getMessage());
            }
        }
    });
    WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation());
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) Path(java.nio.file.Path) GameInfo(org.terasology.rendering.nui.layers.mainMenu.savedGames.GameInfo)

Example 20 with UILabel

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

the class InputSettingsScreen method addInputSection.

private void addInputSection(InputCategory category, ColumnLayout layout, Map<SimpleUri, RegisterBindButton> inputsById) {
    if (category != null) {
        layout.addWidget(new UISpace(new Vector2i(0, 16)));
        UILabel categoryHeader = new UILabel(translationSystem.translate(category.displayName()));
        categoryHeader.setFamily("subheading");
        layout.addWidget(categoryHeader);
        Set<SimpleUri> processedBinds = Sets.newHashSet();
        for (String bindId : category.ordering()) {
            SimpleUri bindUri = new SimpleUri(bindId);
            if (bindUri.isValid()) {
                RegisterBindButton bind = inputsById.get(new SimpleUri(bindId));
                if (bind != null) {
                    addInputBindRow(bindUri, bind, layout);
                    processedBinds.add(bindUri);
                }
            }
        }
        List<ExtensionBind> extensionBindList = Lists.newArrayList();
        for (Map.Entry<SimpleUri, RegisterBindButton> bind : inputsById.entrySet()) {
            if (bind.getValue().category().equals(category.id()) && !processedBinds.contains(bind.getKey())) {
                extensionBindList.add(new ExtensionBind(bind.getKey(), bind.getValue()));
            }
        }
        Collections.sort(extensionBindList);
        for (ExtensionBind extension : extensionBindList) {
            addInputBindRow(extension.uri, extension.bind, layout);
        }
    }
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) RegisterBindButton(org.terasology.input.RegisterBindButton) SimpleUri(org.terasology.engine.SimpleUri) UISpace(org.terasology.rendering.nui.widgets.UISpace) Vector2i(org.terasology.math.geom.Vector2i) Map(java.util.Map)

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