Search in sources :

Example 1 with ReadOnlyBinding

use of org.terasology.nui.databinding.ReadOnlyBinding in project Terasology by MovingBlocks.

the class BehaviorEditorScreen method initialise.

@Override
public void initialise() {
    entityProperties = find("entity_properties", PropertyLayout.class);
    behaviorEditor = find("tree", BehaviorEditor.class);
    properties = find("properties", PropertyLayout.class);
    selectTree = find("select_tree", UIDropdown.class);
    selectEntity = find("select_entity", UIDropdown.class);
    palette = find("palette", UIList.class);
    behaviorEditor.initialize(context);
    behaviorEditor.bindSelection(new Binding<RenderableNode>() {

        private PropertyProvider provider = new PropertyProvider(context.get(ReflectFactory.class), providerFactory);

        @Override
        public RenderableNode get() {
            return selectedNode;
        }

        @Override
        public void set(RenderableNode value) {
            onNodeSelected(value, provider);
        }
    });
    Binding<List<BehaviorTree>> treeBinding = new ReadOnlyBinding<List<BehaviorTree>>() {

        @Override
        public List<BehaviorTree> get() {
            return behaviorSystem.getTrees();
        }
    };
    selectTree.bindOptions(treeBinding);
    providerFactory.register("behaviorTrees", treeBinding);
    selectTree.bindSelection(new Binding<BehaviorTree>() {

        @Override
        public BehaviorTree get() {
            return behaviorEditor.getTree();
        }

        @Override
        public void set(BehaviorTree value) {
            onTreeSelected(value);
        }
    });
    selectEntity.bindOptions(new ReadOnlyBinding<List<Interpreter>>() {

        @Override
        public List<Interpreter> get() {
            return behaviorSystem.getInterpreters();
        }
    });
    selectEntity.bindSelection(new Binding<Interpreter>() {

        private PropertyProvider provider = new PropertyProvider(context.get(ReflectFactory.class), providerFactory);

        @Override
        public Interpreter get() {
            return selectedInterpreter;
        }

        @Override
        public void set(Interpreter value) {
            onEntitySelected(value, provider);
        }
    });
    palette.bindSelection(new Binding<BehaviorNodeComponent>() {

        @Override
        public BehaviorNodeComponent get() {
            return null;
        }

        @Override
        public void set(BehaviorNodeComponent value) {
            onPaletteSelected(value);
        }
    });
    palette.bindList(new ReadOnlyBinding<List<BehaviorNodeComponent>>() {

        @Override
        public List<BehaviorNodeComponent> get() {
            return paletteItems;
        }
    });
    palette.setItemRenderer(new ToStringTextRenderer<BehaviorNodeComponent>() {

        @Override
        public String getTooltip(BehaviorNodeComponent value) {
            return value.description;
        }
    });
    WidgetUtil.trySubscribe(this, "copy", button -> onCopyPressed());
    WidgetUtil.trySubscribe(this, "layout", button -> onLayoutPressed());
    WidgetUtil.trySubscribe(this, "new", button -> onNewPressed());
    WidgetUtil.trySubscribe(this, "assign", button -> onAssignPressed());
    WidgetUtil.trySubscribe(this, "remove", button -> onRemovePressed());
    WidgetUtil.trySubscribe(this, "debug_run", button -> {
        if (selectedInterpreter != null) {
            selectedInterpreter.run();
        }
    });
    WidgetUtil.trySubscribe(this, "debug_pause", button -> {
        if (selectedInterpreter != null) {
            selectedInterpreter.pause();
        }
    });
    WidgetUtil.trySubscribe(this, "debug_reset", button -> {
        if (selectedInterpreter != null) {
            selectedInterpreter.reset();
        }
    });
    WidgetUtil.trySubscribe(this, "debug_step", button -> {
        if (selectedInterpreter != null) {
            selectedInterpreter.tick(0.1f);
        }
    });
    paletteItems = findPaletteItems();
}
Also used : Interpreter(org.terasology.engine.logic.behavior.Interpreter) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) UIList(org.terasology.nui.widgets.UIList) BehaviorTree(org.terasology.engine.logic.behavior.asset.BehaviorTree) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) PropertyLayout(org.terasology.nui.layouts.PropertyLayout) PropertyProvider(org.terasology.nui.properties.PropertyProvider) UIDropdown(org.terasology.nui.widgets.UIDropdown) List(java.util.List) UIList(org.terasology.nui.widgets.UIList)

Example 2 with ReadOnlyBinding

use of org.terasology.nui.databinding.ReadOnlyBinding 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 3 with ReadOnlyBinding

use of org.terasology.nui.databinding.ReadOnlyBinding in project Terasology by MovingBlocks.

the class AdvancedGameSetupScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    remoteModuleRegistryUpdater = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat(new TargetLengthBasedClassNameAbbreviator(36).abbreviate(getClass().getName()) + "-%d").setDaemon(true).build()).submit(moduleManager.getInstallManager().updateRemoteRegistry());
    final UIText seed = find("seed", UIText.class);
    if (seed != null) {
        seed.setText(new FastRandom().nextString(32));
    }
    // skip loading module configs, limit shown modules to locally present ones
    selectModulesConfig = new SelectModulesConfig();
    selectModulesConfig.getSelectedStandardModuleExtensions().forEach(selectModulesConfig::unselectStandardModuleExtension);
    selectModulesConfig.toggleIsLocalOnlySelected();
    dependencyResolver = new DependencyResolver(moduleManager.getRegistry());
    modulesLookup = Maps.newHashMap();
    sortedModules = Lists.newArrayList();
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        Module latestVersion = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
        ModuleSelectionInfo info = ModuleSelectionInfo.local(latestVersion);
        modulesLookup.put(info.getMetadata().getId(), info);
        sortedModules.add(info);
    }
    sortedModules.sort(moduleInfoComparator);
    allSortedModules = new ArrayList<>(sortedModules);
    final UIList<ModuleSelectionInfo> moduleList = find("moduleList", UIList.class);
    if (moduleList != null) {
        moduleList.setList(sortedModules);
        moduleList.setItemRenderer(new AbstractItemRenderer<ModuleSelectionInfo>() {

            String getString(ModuleSelectionInfo value) {
                return value.getMetadata().getDisplayName().toString();
            }

            @Override
            public void draw(ModuleSelectionInfo value, Canvas canvas) {
                if (isSelectedGameplayModule(value) && value.isValidToSelect()) {
                    canvas.setMode("gameplay");
                } else if (value.isSelected() && value.isExplicitSelection()) {
                    canvas.setMode("enabled");
                } else if (value.isSelected()) {
                    canvas.setMode("dependency");
                } else if (!value.isPresent()) {
                    canvas.setMode("disabled");
                } else if (!value.isValidToSelect()) {
                    canvas.setMode("invalid");
                } else {
                    canvas.setMode("available");
                }
                canvas.drawText(getString(value), canvas.getRegion());
            }

            @Override
            public Vector2i getPreferredSize(ModuleSelectionInfo value, Canvas canvas) {
                String text = getString(value);
                return new Vector2i(canvas.getCurrentStyle().getFont().getWidth(text), canvas.getCurrentStyle().getFont().getLineHeight());
            }
        });
        // ItemActivateEventListener is triggered by double clicking
        moduleList.subscribe((widget, item) -> {
            if (item.isSelected() && moduleList.getSelection().isExplicitSelection()) {
                deselect(item);
            } else if (item.isValidToSelect()) {
                select(item);
            }
        });
        moduleSearch = find("moduleSearch", ResettableUIText.class);
        if (moduleSearch != null) {
            moduleSearch.subscribe((TextChangeEventListener) (oldText, newText) -> filterModules());
        }
        final Binding<ModuleMetadata> moduleInfoBinding = new ReadOnlyBinding<ModuleMetadata>() {

            @Override
            public ModuleMetadata get() {
                if (moduleList.getSelection() != null) {
                    return moduleList.getSelection().getMetadata();
                }
                return null;
            }
        };
        UILabel name = find("name", UILabel.class);
        if (name != null) {
            name.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    if (moduleInfoBinding.get() != null) {
                        return moduleInfoBinding.get().getDisplayName().toString();
                    }
                    return "";
                }
            });
        }
        UILabel installedVersion = find("installedVersion", UILabel.class);
        if (installedVersion != null) {
            installedVersion.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    ModuleSelectionInfo sel = moduleList.getSelection();
                    if (sel == null) {
                        return "";
                    }
                    return sel.isPresent() ? sel.getMetadata().getVersion().toString() : translationSystem.translate("${engine:menu#module-version-installed-none}");
                }
            });
        }
        UILabel onlineVersion = find("onlineVersion", UILabel.class);
        if (onlineVersion != null) {
            onlineVersion.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    ModuleSelectionInfo sel = moduleList.getSelection();
                    if (sel == null) {
                        return "";
                    }
                    return (sel.getOnlineVersion() != null) ? sel.getOnlineVersion().getVersion().toString() : "none";
                }
            });
        }
        UILabel description = find("description", UILabel.class);
        if (description != null) {
            description.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    ModuleMetadata moduleMetadata = moduleInfoBinding.get();
                    if (moduleMetadata != null) {
                        StringBuilder dependenciesNames;
                        List<DependencyInfo> dependencies = moduleMetadata.getDependencies();
                        if (dependencies != null && !dependencies.isEmpty()) {
                            dependenciesNames = new StringBuilder(translationSystem.translate("${engine:menu#module-dependencies-exist}") + ":" + '\n');
                            for (DependencyInfo dependency : dependencies) {
                                dependenciesNames.append("   ").append(dependency.getId().toString()).append('\n');
                            }
                        } else {
                            dependenciesNames = new StringBuilder(translationSystem.translate("${engine:menu#module-dependencies-empty}") + ".");
                        }
                        return moduleMetadata.getDescription().toString() + '\n' + '\n' + dependenciesNames;
                    }
                    return "";
                }
            });
        }
        UILabel status = find("status", UILabel.class);
        if (status != null) {
            status.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    ModuleSelectionInfo info = moduleList.getSelection();
                    if (info != null) {
                        if (isSelectedGameplayModule(info)) {
                            return translationSystem.translate("${engine:menu#module-status-activegameplay}");
                        } else if (info.isSelected() && info.isExplicitSelection()) {
                            return translationSystem.translate("${engine:menu#module-status-activated}");
                        } else if (info.isSelected()) {
                            return translationSystem.translate("${engine:menu#module-status-dependency}");
                        } else if (!info.isPresent()) {
                            return translationSystem.translate("${engine:menu#module-status-notpresent}");
                        } else if (info.isValidToSelect()) {
                            return translationSystem.translate("${engine:menu#module-status-available}");
                        } else {
                            return translationSystem.translate("${engine:menu#module-status-error}");
                        }
                    }
                    return "";
                }
            });
        }
        UIButton toggleActivate = find("toggleActivation", UIButton.class);
        if (toggleActivate != null) {
            toggleActivate.subscribe(button -> {
                ModuleSelectionInfo info = moduleList.getSelection();
                if (info != null) {
                    // Toggle
                    if (info.isSelected() && info.isExplicitSelection()) {
                        deselect(info);
                    } else if (info.isValidToSelect()) {
                        select(info);
                    }
                }
            });
            toggleActivate.bindEnabled(new ReadOnlyBinding<Boolean>() {

                @Override
                public Boolean get() {
                    ModuleSelectionInfo info = moduleList.getSelection();
                    return info != null && info.isPresent() && !isSelectedGameplayModule(info) && (info.isSelected() || info.isValidToSelect());
                }
            });
            toggleActivate.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    if (moduleList.getSelection() != null) {
                        if (moduleList.getSelection().isExplicitSelection()) {
                            return translationSystem.translate("${engine:menu#deactivate-module}");
                        } else {
                            return translationSystem.translate("${engine:menu#activate-module}");
                        }
                    }
                    // button should be disabled
                    return translationSystem.translate("${engine:menu#activate-module}");
                }
            });
        }
        UIButton downloadButton = find("download", UIButton.class);
        if (downloadButton != null) {
            downloadButton.subscribe(button -> {
                if (moduleList.getSelection() != null) {
                    ModuleSelectionInfo info = moduleList.getSelection();
                    startDownloadingNewestModulesRequiredFor(info);
                }
            });
            downloadButton.bindEnabled(new ReadOnlyBinding<Boolean>() {

                @Override
                public Boolean get() {
                    ModuleSelectionInfo selection = moduleList.getSelection();
                    if (null == selection) {
                        return false;
                    }
                    return selection.getOnlineVersion() != null;
                }
            });
            downloadButton.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    ModuleSelectionInfo info = moduleList.getSelection();
                    if (info != null && !info.isPresent()) {
                        return translationSystem.translate("${engine:menu#download-module}");
                    } else {
                        return translationSystem.translate("${engine:menu#update-module}");
                    }
                }
            });
        }
        UIButton disableAll = find("disableAll", UIButton.class);
        if (disableAll != null) {
            disableAll.subscribe(button -> sortedModules.stream().filter(info -> info.isSelected() && info.isExplicitSelection()).forEach(this::deselect));
        }
        for (CheckboxAssociationEnum checkboxAssociation : CheckboxAssociationEnum.values()) {
            String checkboxName = checkboxAssociation.getCheckboxName();
            StandardModuleExtension standardModuleExtension = checkboxAssociation.getStandardModuleExtension();
            UICheckbox checkBox = find(checkboxName, UICheckbox.class);
            if (null != checkBox) {
                checkBox.setChecked(selectModulesConfig.isStandardModuleExtensionSelected(standardModuleExtension));
                checkBox.subscribe(e -> {
                    selectModulesConfig.toggleStandardModuleExtensionSelected(standardModuleExtension);
                    checkBox.setChecked(selectModulesConfig.isStandardModuleExtensionSelected(standardModuleExtension));
                    filterModules();
                });
            } else {
                logger.error("Unable to find checkbox named " + checkboxName + " in " + ASSET_URI.toString());
                selectModulesConfig.unselectStandardModuleExtension(standardModuleExtension);
            }
        }
        UICheckbox localOnlyCheckbox = find("localOnlyCheckbox", UICheckbox.class);
        localOnlyCheckbox.setChecked(selectModulesConfig.isLocalOnlySelected());
        localOnlyCheckbox.subscribe(e -> {
            selectModulesConfig.toggleIsLocalOnlySelected();
            localOnlyCheckbox.setChecked(selectModulesConfig.isLocalOnlySelected());
            filterModules();
        });
        UICheckbox uncategorizedCheckbox = find("uncategorizedCheckbox", UICheckbox.class);
        uncategorizedCheckbox.setChecked(selectModulesConfig.isUncategorizedSelected());
        uncategorizedCheckbox.subscribe(e -> {
            selectModulesConfig.toggleUncategorizedSelected();
            boolean isUncategorizedSelected = selectModulesConfig.isUncategorizedSelected();
            uncategorizedCheckbox.setChecked(isUncategorizedSelected);
            for (CheckboxAssociationEnum checkboxAssociation : CheckboxAssociationEnum.values()) {
                final String checkboxName = checkboxAssociation.getCheckboxName();
                UICheckbox checkbox = find(checkboxName, UICheckbox.class);
                if (null != checkbox) {
                    checkbox.setEnabled(!isUncategorizedSelected);
                }
            }
            filterModules();
        });
        UIButton resetAdvancedFilters = find("resetFilters", UIButton.class);
        if (resetAdvancedFilters != null) {
            // on clicking 'reset category filters' button, uncheck all advanced filters
            localOnlyCheckbox.setChecked(selectModulesConfig.isLocalOnlySelected());
            uncategorizedCheckbox.setChecked(selectModulesConfig.isUncategorizedSelected());
            resetAdvancedFilters.subscribe(button -> {
                if (selectModulesConfig.isLocalOnlySelected()) {
                    selectModulesConfig.toggleIsLocalOnlySelected();
                    localOnlyCheckbox.setChecked(selectModulesConfig.isLocalOnlySelected());
                }
                if (selectModulesConfig.isUncategorizedSelected()) {
                    selectModulesConfig.toggleUncategorizedSelected();
                    uncategorizedCheckbox.setChecked(selectModulesConfig.isUncategorizedSelected());
                }
                filterModules();
            });
            for (CheckboxAssociationEnum checkboxAssociation : CheckboxAssociationEnum.values()) {
                StandardModuleExtension standardModuleExtension = checkboxAssociation.getStandardModuleExtension();
                String checkboxName = checkboxAssociation.getCheckboxName();
                UICheckbox checkbox = find(checkboxName, UICheckbox.class);
                if (null != checkbox) {
                    checkbox.setChecked(selectModulesConfig.isStandardModuleExtensionSelected(standardModuleExtension));
                    resetAdvancedFilters.subscribe(button -> {
                        checkbox.setEnabled(!selectModulesConfig.isUncategorizedSelected());
                        if (selectModulesConfig.isStandardModuleExtensionSelected(standardModuleExtension)) {
                            selectModulesConfig.toggleStandardModuleExtensionSelected(standardModuleExtension);
                            checkbox.setChecked(selectModulesConfig.isStandardModuleExtensionSelected(standardModuleExtension));
                        }
                        filterModules();
                    });
                }
            }
            final UIButton moduleDetails = find("moduleDetails", UIButton.class);
            if (moduleDetails != null) {
                moduleDetails.bindEnabled(new ReadOnlyBinding<Boolean>() {

                    @Override
                    public Boolean get() {
                        return moduleInfoBinding.get() != null;
                    }
                });
                moduleDetails.subscribe(b -> {
                    final ModuleDetailsScreen moduleDetailsScreen = getManager().createScreen(ModuleDetailsScreen.ASSET_URI, ModuleDetailsScreen.class);
                    final Collection<Module> modules = sortedModules.stream().map(ModuleSelectionInfo::getMetadata).filter(Objects::nonNull).map(meta -> moduleManager.getRegistry().getLatestModuleVersion(meta.getId())).filter(Objects::nonNull).collect(Collectors.toList());
                    moduleDetailsScreen.setModules(modules);
                    moduleDetailsScreen.setSelectedModule(modules.stream().filter(module -> module.getId().equals(moduleInfoBinding.get().getId())).findFirst().orElse(null));
                    getManager().pushScreen(moduleDetailsScreen);
                });
            }
        }
    }
    WidgetUtil.trySubscribe(this, "createWorld", button -> {
        final UniverseSetupScreen universeSetupScreen = getManager().createScreen(UniverseSetupScreen.ASSET_URI, UniverseSetupScreen.class);
        universeWrapper.setSeed(seed.getText());
        saveConfiguration();
        universeSetupScreen.setEnvironment(universeWrapper);
        triggerForwardAnimation(universeSetupScreen);
    });
    WidgetUtil.trySubscribe(this, "play", button -> {
        if (StringUtils.isBlank(seed.getText())) {
            getManager().createScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error", "Game seed cannot be empty!");
        } else {
            universeWrapper.setSeed(seed.getText());
            saveConfiguration();
            final GameManifest gameManifest = GameManifestProvider.createGameManifest(universeWrapper, moduleManager, config);
            if (gameManifest != null) {
                gameEngine.changeState(new StateLoading(gameManifest, (universeWrapper.getLoadingAsServer()) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
            } else {
                getManager().createScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error", "Can't create new game!");
            }
        }
    });
    WidgetUtil.trySubscribe(this, "return", button -> triggerBackAnimation());
    WidgetUtil.trySubscribe(this, "mainMenu", button -> {
        getManager().pushScreen("engine:mainMenuScreen");
    });
}
Also used : ModuleInstaller(org.terasology.engine.core.module.ModuleInstaller) WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) In(org.terasology.engine.registry.In) LoggerFactory(org.slf4j.LoggerFactory) WidgetUtil(org.terasology.nui.WidgetUtil) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) Future(java.util.concurrent.Future) Map(java.util.Map) AbstractItemRenderer(org.terasology.nui.itemRendering.AbstractItemRenderer) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo) Canvas(org.terasology.nui.Canvas) ResettableUIText(org.terasology.nui.widgets.ResettableUIText) StateLoading(org.terasology.engine.core.modes.StateLoading) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) Binding(org.terasology.nui.databinding.Binding) ImmutableSet(com.google.common.collect.ImmutableSet) StringUtils(org.codehaus.plexus.util.StringUtils) GameEngine(org.terasology.engine.core.GameEngine) CancellationException(java.util.concurrent.CancellationException) Module(org.terasology.gestalt.module.Module) Collection(java.util.Collection) UniverseWrapper(org.terasology.engine.rendering.nui.layers.mainMenu.UniverseWrapper) WaitPopup(org.terasology.engine.rendering.nui.layers.mainMenu.WaitPopup) Set(java.util.Set) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) SimpleUri(org.terasology.engine.core.SimpleUri) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Objects(java.util.Objects) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) Vector2i(org.joml.Vector2i) UIList(org.terasology.nui.widgets.UIList) Name(org.terasology.gestalt.naming.Name) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) TerasologyConstants(org.terasology.engine.core.TerasologyConstants) ModuleManager(org.terasology.engine.core.module.ModuleManager) ModuleDetailsScreen(org.terasology.engine.rendering.nui.layers.mainMenu.moduleDetailsScreen.ModuleDetailsScreen) NetworkMode(org.terasology.engine.network.NetworkMode) TargetLengthBasedClassNameAbbreviator(ch.qos.logback.classic.pattern.TargetLengthBasedClassNameAbbreviator) DependencyResolutionFailedException(org.terasology.engine.core.module.DependencyResolutionFailedException) FastRandom(org.terasology.engine.utilities.random.FastRandom) ArrayList(java.util.ArrayList) StandardModuleExtension(org.terasology.engine.core.module.StandardModuleExtension) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) GameManifest(org.terasology.engine.game.GameManifest) Lists(com.google.common.collect.Lists) ConfirmPopup(org.terasology.engine.rendering.nui.layers.mainMenu.ConfirmPopup) GameManifestProvider(org.terasology.engine.rendering.nui.layers.mainMenu.GameManifestProvider) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) ModuleConfig(org.terasology.engine.config.ModuleConfig) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) UILabel(org.terasology.nui.widgets.UILabel) SelectModulesConfig(org.terasology.engine.config.SelectModulesConfig) Maps(com.google.common.collect.Maps) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) UICheckbox(org.terasology.nui.widgets.UICheckbox) ExecutionException(java.util.concurrent.ExecutionException) Config(org.terasology.engine.config.Config) TextChangeEventListener(org.terasology.nui.widgets.TextChangeEventListener) UIButton(org.terasology.nui.widgets.UIButton) UniverseSetupScreen(org.terasology.engine.rendering.nui.layers.mainMenu.UniverseSetupScreen) Comparator(java.util.Comparator) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) Name(org.terasology.gestalt.naming.Name) SelectModulesConfig(org.terasology.engine.config.SelectModulesConfig) ModuleDetailsScreen(org.terasology.engine.rendering.nui.layers.mainMenu.moduleDetailsScreen.ModuleDetailsScreen) UIButton(org.terasology.nui.widgets.UIButton) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ResettableUIText(org.terasology.nui.widgets.ResettableUIText) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) UIList(org.terasology.nui.widgets.UIList) ArrayList(java.util.ArrayList) Vector2i(org.joml.Vector2i) StandardModuleExtension(org.terasology.engine.core.module.StandardModuleExtension) UILabel(org.terasology.nui.widgets.UILabel) UniverseSetupScreen(org.terasology.engine.rendering.nui.layers.mainMenu.UniverseSetupScreen) StateLoading(org.terasology.engine.core.modes.StateLoading) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) Canvas(org.terasology.nui.Canvas) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) FastRandom(org.terasology.engine.utilities.random.FastRandom) UICheckbox(org.terasology.nui.widgets.UICheckbox) TargetLengthBasedClassNameAbbreviator(ch.qos.logback.classic.pattern.TargetLengthBasedClassNameAbbreviator) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) ResettableUIText(org.terasology.nui.widgets.ResettableUIText) GameManifest(org.terasology.engine.game.GameManifest) Module(org.terasology.gestalt.module.Module)

Example 4 with ReadOnlyBinding

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

Example 5 with ReadOnlyBinding

use of org.terasology.nui.databinding.ReadOnlyBinding in project Terasology by MovingBlocks.

the class ModuleDetailsScreen method setUpUpdateModuleButton.

private void setUpUpdateModuleButton() {
    updateModuleButton.bindEnabled(new ReadOnlyBinding<Boolean>() {

        @Override
        public Boolean get() {
            final String online = onlineVersion.getText();
            final String installed = installedVersion.getText();
            if (StringUtils.isNotBlank(online) && StringUtils.isNotBlank(installed)) {
                return new Version(online).compareTo(new Version(installed)) > 0;
            }
            return false;
        }
    });
    updateModuleButton.subscribe((button -> {
        if (dependencyInfoBinding.get() != null) {
            startDownloadingNewestModulesRequiredFor(dependencyInfoBinding.get());
        }
    }));
}
Also used : ModuleInstaller(org.terasology.engine.core.module.ModuleInstaller) Arrays(java.util.Arrays) In(org.terasology.engine.registry.In) Color(org.terasology.nui.Color) LoggerFactory(org.slf4j.LoggerFactory) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) AbstractItemRenderer(org.terasology.nui.itemRendering.AbstractItemRenderer) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo) Canvas(org.terasology.nui.Canvas) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) DateFormat(java.text.DateFormat) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) StringTextRenderer(org.terasology.nui.itemRendering.StringTextRenderer) Binding(org.terasology.nui.databinding.Binding) StringUtils(org.codehaus.plexus.util.StringUtils) Module(org.terasology.gestalt.module.Module) Collection(java.util.Collection) WaitPopup(org.terasology.engine.rendering.nui.layers.mainMenu.WaitPopup) Set(java.util.Set) Version(org.terasology.gestalt.naming.Version) Collectors(java.util.stream.Collectors) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Objects(java.util.Objects) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) Context(org.terasology.engine.context.Context) Stream(java.util.stream.Stream) Vector2i(org.joml.Vector2i) ExtraDataModuleExtension(org.terasology.engine.core.module.ExtraDataModuleExtension) UIList(org.terasology.nui.widgets.UIList) Name(org.terasology.gestalt.naming.Name) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) ModuleManager(org.terasology.engine.core.module.ModuleManager) UIButtonWebBrowser(org.terasology.engine.rendering.nui.widgets.UIButtonWebBrowser) SimpleDateFormat(java.text.SimpleDateFormat) DownloadPopupProgressListener(org.terasology.engine.rendering.nui.layers.mainMenu.advancedGameSetupScreen.DownloadPopupProgressListener) DependencyResolutionFailedException(org.terasology.engine.core.module.DependencyResolutionFailedException) HashSet(java.util.HashSet) StandardModuleExtension(org.terasology.engine.core.module.StandardModuleExtension) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ConfirmPopup(org.terasology.engine.rendering.nui.layers.mainMenu.ConfirmPopup) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) Logger(org.slf4j.Logger) UILabel(org.terasology.nui.widgets.UILabel) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) UIButton(org.terasology.nui.widgets.UIButton) Comparator(java.util.Comparator) RemoteModuleExtension(org.terasology.engine.core.module.RemoteModuleExtension) Collections(java.util.Collections) Version(org.terasology.gestalt.naming.Version)

Aggregations

ReadOnlyBinding (org.terasology.nui.databinding.ReadOnlyBinding)5 UIButton (org.terasology.nui.widgets.UIButton)4 UILabel (org.terasology.nui.widgets.UILabel)4 List (java.util.List)3 UIList (org.terasology.nui.widgets.UIList)3 Collection (java.util.Collection)2 Comparator (java.util.Comparator)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Future (java.util.concurrent.Future)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.codehaus.plexus.util.StringUtils)2 Vector2i (org.joml.Vector2i)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 DependencyResolutionFailedException (org.terasology.engine.core.module.DependencyResolutionFailedException)2 ModuleInstaller (org.terasology.engine.core.module.ModuleInstaller)2 ModuleManager (org.terasology.engine.core.module.ModuleManager)2 StandardModuleExtension (org.terasology.engine.core.module.StandardModuleExtension)2 TranslationSystem (org.terasology.engine.i18n.TranslationSystem)2