Search in sources :

Example 6 with UIButton

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

the class EnterUsernamePopup method initialise.

@Override
public void initialise() {
    playerConfig = config.getPlayer();
    username = find("username", UIText.class);
    username.setText(playerConfig.getName());
    username.bindTooltipString(new ReadOnlyBinding<String>() {

        @Override
        public String get() {
            return validateUserName();
        }
    });
    UIButton okButton = find("ok", UIButton.class);
    if (okButton != null) {
        okButton.subscribe(button -> {
            playerConfig.setName(username.getText().trim());
            playerConfig.setHasEnteredUsername(true);
            getManager().popScreen();
        });
        okButton.bindEnabled(new ReadOnlyBinding<Boolean>() {

            @Override
            public Boolean get() {
                return Strings.isNullOrEmpty(validateUserName());
            }
        });
        okButton.setTooltipDelay(0);
        okButton.bindTooltipString(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                return validateUserName();
            }
        });
    }
    WidgetUtil.trySubscribe(this, "cancel", button -> {
        playerConfig.setHasEnteredUsername(true);
        getManager().popScreen();
    });
}
Also used : UIButton(org.terasology.rendering.nui.widgets.UIButton) UIText(org.terasology.rendering.nui.widgets.UIText)

Example 7 with UIButton

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

the class FilePickerPopup method initialise.

@Override
public void initialise() {
    WidgetUtil.trySubscribe(this, "gotoParent", button -> setCurrentDirectoryParent());
    WidgetUtil.trySubscribe(this, "gotoRoot", button -> setCurrentDirectoryRoot());
    WidgetUtil.trySubscribe(this, "gotoHome", button -> setCurrentDirectoryHome());
    find("gotoParent", UIButton.class).bindEnabled(new ReadOnlyBinding<Boolean>() {

        @Override
        public Boolean get() {
            return currentPath != null;
        }
    });
    find("currentPath", UILabel.class).bindText(new ReadOnlyBinding<String>() {

        @Override
        public String get() {
            return currentPath == null ? translationSystem.translate("${engine:menu#file-picker-roots-title}") : pathToString(currentPath, false);
        }
    });
    find("fileName", UIText.class).bindText(new Binding<String>() {

        @Override
        public String get() {
            return fileName;
        }

        @Override
        public void set(String value) {
            fileName = value;
        }
    });
    find("filePath", UILabel.class).bindText(new ReadOnlyBinding<String>() {

        @Override
        public String get() {
            if (currentPath == null) {
                return translationSystem.translate("${engine:menu#file-picker-invalid-location}");
            } else {
                return isValidFilename(fileName) ? translationSystem.translate("") + getPathToFile().toString() : translationSystem.translate("${engine:menu#file-picker-invalid-file-name}");
            }
        }
    });
    directoryContentsScroller = find("directoryContentsScroller", ScrollableArea.class);
    directoryContentsList = find("directoryContentsList", UIList.class);
    directoryContentsList.subscribeSelection((widget, item) -> handleItemSelection(item));
    setCurrentDirectoryHome();
    UIButton ok = find("ok", UIButton.class);
    ok.bindEnabled(new ReadOnlyBinding<Boolean>() {

        @Override
        public Boolean get() {
            return isValid();
        }
    });
    ok.subscribe(button -> {
        if (isValid()) {
            getManager().popScreen();
            okHandler.accept(getPathToFile());
        }
    });
    WidgetUtil.trySubscribe(this, "cancel", button -> getManager().popScreen());
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) ScrollableArea(org.terasology.rendering.nui.layouts.ScrollableArea) UIList(org.terasology.rendering.nui.widgets.UIList) UIButton(org.terasology.rendering.nui.widgets.UIButton) UIText(org.terasology.rendering.nui.widgets.UIText)

Example 8 with UIButton

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

Example 9 with UIButton

use of org.terasology.rendering.nui.widgets.UIButton 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 10 with UIButton

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

the class LaunchPopup method setOptionButtonText.

public void setOptionButtonText(String buttonText) {
    UIButton optionButton = find("option", UIButton.class);
    optionButton.setText(buttonText);
}
Also used : UIButton(org.terasology.rendering.nui.widgets.UIButton)

Aggregations

UIButton (org.terasology.rendering.nui.widgets.UIButton)12 UILabel (org.terasology.rendering.nui.widgets.UILabel)8 ReadOnlyBinding (org.terasology.rendering.nui.databinding.ReadOnlyBinding)4 UIText (org.terasology.rendering.nui.widgets.UIText)4 ResourceUrn (org.terasology.assets.ResourceUrn)3 Component (java.awt.Component)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 JDialog (javax.swing.JDialog)2 JFileChooser (javax.swing.JFileChooser)2 LookAndFeel (javax.swing.LookAndFeel)2 UnsupportedLookAndFeelException (javax.swing.UnsupportedLookAndFeelException)2 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)2 AssetDataFile (org.terasology.assets.format.AssetDataFile)2 ServerInfo (org.terasology.config.ServerInfo)2 DependencyResolver (org.terasology.module.DependencyResolver)2 Module (org.terasology.module.Module)2 Canvas (org.terasology.rendering.nui.Canvas)2 NUIEditorMenuTreeBuilder (org.terasology.rendering.nui.editor.utils.NUIEditorMenuTreeBuilder)2