Search in sources :

Example 1 with UILabel

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

the class DebugOverlay method initialise.

@Override
public void initialise() {
    bindVisible(new ReadOnlyBinding<Boolean>() {

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

            @Override
            public String get() {
                double memoryUsage = ((double) Runtime.getRuntime().totalMemory() - (double) Runtime.getRuntime().freeMemory()) / 1048576.0;
                return String.format("fps: %.2f, mem usage: %.2f MB, total mem: %.2f MB, max mem: %.2f MB", time.getFps(), memoryUsage, Runtime.getRuntime().totalMemory() / 1048576.0, Runtime.getRuntime().maxMemory() / 1048576.0);
            }
        });
    }
    UILabel debugLine2 = find("debugLine2", UILabel.class);
    if (debugLine2 != null) {
        debugLine2.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                return String.format("Active Entities: %s, Current Target: %s", entityManager.getActiveEntityCount(), cameraTarget.toString());
            }
        });
    }
    UILabel debugLine3 = find("debugLine3", UILabel.class);
    if (debugLine3 != null) {
        debugLine3.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                Vector3f pos = localPlayer.getPosition();
                Vector3i chunkPos = ChunkMath.calcChunkPos((int) pos.x, (int) pos.y, (int) pos.z);
                Vector3f rotation = localPlayer.getViewDirection();
                Vector3f cameraPos = localPlayer.getViewPosition();
                return String.format(Locale.US, "Pos (%.2f, %.2f, %.2f), Chunk (%d, %d, %d), Eye (%.2f, %.2f, %.2f), Rot (%.2f, %.2f, %.2f)", pos.x, pos.y, pos.z, chunkPos.x, chunkPos.y, chunkPos.z, cameraPos.x, cameraPos.y, cameraPos.z, rotation.x, rotation.y, rotation.z);
            }
        });
    }
    UILabel debugLine4 = find("debugLine4", UILabel.class);
    if (debugLine4 != null) {
        debugLine4.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                String biomeId = "unavailable";
                Vector3i blockPos = new Vector3i(localPlayer.getPosition());
                if (worldProvider.isBlockRelevant(blockPos)) {
                    Biome biome = worldProvider.getBiome(blockPos);
                    biomeId = CoreRegistry.get(BiomeManager.class).getBiomeId(biome);
                }
                return String.format("total vus: %s | worldTime: %.3f | tiDi: %.1f |  biome: %s", ChunkTessellator.getVertexArrayUpdateCount(), // use floor instead of rounding up
                worldProvider.getTime().getDays() - 0.0005f, time.getGameTimeDilation(), biomeId);
            }
        });
    }
    UILabel saveStatusLabel = find("saveStatusLabel", UILabel.class);
    // clients do not have a storage manager
    if (saveStatusLabel != null && storageManager != null) {
        saveStatusLabel.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                return "Saving... ";
            }
        });
        saveStatusLabel.bindVisible(new ReadOnlyBinding<Boolean>() {

            @Override
            public Boolean get() {
                return storageManager.isSaving();
            }
        });
    }
    metricsLabel = find("metrics", UILabel.class);
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) BiomeManager(org.terasology.world.biomes.BiomeManager) Biome(org.terasology.world.biomes.Biome) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i)

Example 2 with UILabel

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

the class CreateGameScreen method initialise.

@Override
@SuppressWarnings("unchecked")
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 UIText worldName = find("worldName", UIText.class);
    setGameName(worldName);
    final UIText seed = find("seed", UIText.class);
    if (seed != null) {
        seed.setText(new FastRandom().nextString(32));
    }
    final UIDropdownScrollable<Module> gameplay = find("gameplay", UIDropdownScrollable.class);
    gameplay.setOptions(getGameplayModules());
    gameplay.setVisibleOptions(3);
    gameplay.bindSelection(new Binding<Module>() {

        Module selected;

        @Override
        public Module get() {
            return selected;
        }

        @Override
        public void set(Module value) {
            setSelectedGameplayModule(value);
            selected = value;
        }
    });
    gameplay.setOptionRenderer(new StringTextRenderer<Module>() {

        @Override
        public String getString(Module value) {
            return value.getMetadata().getDisplayName().value();
        }

        @Override
        public void draw(Module value, Canvas canvas) {
            canvas.getCurrentStyle().setTextColor(validateModuleDependencies(value.getId()) ? Color.WHITE : Color.RED);
            super.draw(value, canvas);
            canvas.getCurrentStyle().setTextColor(Color.WHITE);
        }
    });
    UILabel gameplayDescription = find("gameplayDescription", UILabel.class);
    gameplayDescription.bindText(new ReadOnlyBinding<String>() {

        @Override
        public String get() {
            Module selectedModule = gameplay.getSelection();
            if (selectedModule != null) {
                return selectedModule.getMetadata().getDescription().value();
            } else {
                return "";
            }
        }
    });
    final UIDropdownScrollable<WorldGeneratorInfo> worldGenerator = find("worldGenerator", UIDropdownScrollable.class);
    if (worldGenerator != null) {
        worldGenerator.bindOptions(new ReadOnlyBinding<List<WorldGeneratorInfo>>() {

            @Override
            public List<WorldGeneratorInfo> get() {
                // grab all the module names and their dependencies
                // This grabs modules from `config.getDefaultModSelection()` which is updated in SelectModulesScreen
                Set<Name> enabledModuleNames = getAllEnabledModuleNames().stream().collect(Collectors.toSet());
                List<WorldGeneratorInfo> result = Lists.newArrayList();
                for (WorldGeneratorInfo option : worldGeneratorManager.getWorldGenerators()) {
                    if (enabledModuleNames.contains(option.getUri().getModuleName())) {
                        result.add(option);
                    }
                }
                return result;
            }
        });
        worldGenerator.setVisibleOptions(3);
        worldGenerator.bindSelection(new Binding<WorldGeneratorInfo>() {

            @Override
            public WorldGeneratorInfo get() {
                // get the default generator from the config. This is likely to have a user triggered selection.
                WorldGeneratorInfo info = worldGeneratorManager.getWorldGeneratorInfo(config.getWorldGeneration().getDefaultGenerator());
                if (info != null && getAllEnabledModuleNames().contains(info.getUri().getModuleName())) {
                    return info;
                }
                // just use the first available generator
                for (WorldGeneratorInfo worldGenInfo : worldGeneratorManager.getWorldGenerators()) {
                    if (getAllEnabledModuleNames().contains(worldGenInfo.getUri().getModuleName())) {
                        set(worldGenInfo);
                        return worldGenInfo;
                    }
                }
                return null;
            }

            @Override
            public void set(WorldGeneratorInfo value) {
                if (value != null) {
                    config.getWorldGeneration().setDefaultGenerator(value.getUri());
                }
            }
        });
        worldGenerator.setOptionRenderer(new StringTextRenderer<WorldGeneratorInfo>() {

            @Override
            public String getString(WorldGeneratorInfo value) {
                if (value != null) {
                    return value.getDisplayName();
                }
                return "";
            }
        });
        final UIButton playButton = find("play", UIButton.class);
        playButton.bindEnabled(new Binding<Boolean>() {

            @Override
            public Boolean get() {
                return validateModuleDependencies(gameplay.getSelection().getId());
            }

            @Override
            public void set(Boolean value) {
                playButton.setEnabled(value);
            }
        });
    }
    WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation());
    WidgetUtil.trySubscribe(this, "play", button -> {
        if (worldGenerator.getSelection() == null) {
            MessagePopup errorMessagePopup = getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
            if (errorMessagePopup != null) {
                errorMessagePopup.setMessage("No World Generator Selected", "Select a world generator (you may need to activate a mod with a generator first).");
            }
        } else {
            GameManifest gameManifest = new GameManifest();
            gameManifest.setTitle(worldName.getText());
            gameManifest.setSeed(seed.getText());
            DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
            ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
            if (!result.isSuccess()) {
                MessagePopup errorMessagePopup = getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
                if (errorMessagePopup != null) {
                    errorMessagePopup.setMessage("Invalid Module Selection", "Please review your module seleciton and try again");
                }
                return;
            }
            for (Module module : result.getModules()) {
                gameManifest.addModule(module.getId(), module.getVersion());
            }
            // Time at dawn + little offset to spawn in a brighter env.
            float timeOffset = 0.25f + 0.025f;
            WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, gameManifest.getSeed(), (long) (WorldTime.DAY_LENGTH * timeOffset), worldGenerator.getSelection().getUri());
            gameManifest.addWorld(worldInfo);
            gameEngine.changeState(new StateLoading(gameManifest, (loadingAsServer) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
        }
    });
    UIButton previewSeed = find("previewSeed", UIButton.class);
    ReadOnlyBinding<Boolean> worldGeneratorSelected = new ReadOnlyBinding<Boolean>() {

        @Override
        public Boolean get() {
            return worldGenerator != null && worldGenerator.getSelection() != null;
        }
    };
    previewSeed.bindEnabled(worldGeneratorSelected);
    PreviewWorldScreen screen = getManager().createScreen(PreviewWorldScreen.ASSET_URI, PreviewWorldScreen.class);
    WidgetUtil.trySubscribe(this, "previewSeed", button -> {
        if (screen != null) {
            screen.bindSeed(BindHelper.bindBeanProperty("text", seed, String.class));
            try {
                screen.setEnvironment();
                triggerForwardAnimation(screen);
            } catch (Exception e) {
                String msg = "Unable to load world for a 2D preview:\n" + e.toString();
                getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error", msg);
                logger.error("Unable to load world for a 2D preview", e);
            }
        }
    });
    WidgetUtil.trySubscribe(this, "mods", w -> triggerForwardAnimation(SelectModulesScreen.ASSET_URI));
}
Also used : Set(java.util.Set) ResolutionResult(org.terasology.module.ResolutionResult) WorldGeneratorInfo(org.terasology.world.generator.internal.WorldGeneratorInfo) UIButton(org.terasology.rendering.nui.widgets.UIButton) UIText(org.terasology.rendering.nui.widgets.UIText) WorldInfo(org.terasology.world.internal.WorldInfo) List(java.util.List) UILabel(org.terasology.rendering.nui.widgets.UILabel) StateLoading(org.terasology.engine.modes.StateLoading) ReadOnlyBinding(org.terasology.rendering.nui.databinding.ReadOnlyBinding) Canvas(org.terasology.rendering.nui.Canvas) FastRandom(org.terasology.utilities.random.FastRandom) DependencyResolver(org.terasology.module.DependencyResolver) GameManifest(org.terasology.game.GameManifest) Module(org.terasology.module.Module)

Example 3 with UILabel

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

the class MainMenuScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    storageServiceStatus = find("storageServiceStatus", UILabel.class);
    updateStorageServiceStatus();
    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);
    WidgetUtil.trySubscribe(this, "singleplayer", button -> {
        selectScreen.setLoadingAsServer(false);
        triggerForwardAnimation(selectScreen);
    });
    WidgetUtil.trySubscribe(this, "multiplayer", button -> {
        selectScreen.setLoadingAsServer(true);
        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, "credits", button -> triggerForwardAnimation(CreditsScreen.ASSET_URI));
    WidgetUtil.trySubscribe(this, "exit", button -> engine.shutdown());
    WidgetUtil.trySubscribe(this, "telemetry", button -> triggerForwardAnimation(TelemetryScreen.ASSET_URI));
    WidgetUtil.trySubscribe(this, "crashReporter", widget -> CrashReporter.report(new Throwable("There is no error."), LoggingContext.getLoggingPath(), CrashReporter.MODE.ISSUE_REPORTER));
    WidgetUtil.trySubscribe(this, "storageServiceAction", widget -> triggerForwardAnimation(PlayerSettingsScreen.ASSET_URI));
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel)

Example 4 with UILabel

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

Example 5 with UILabel

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

the class InputSettingsScreen method addInputSection.

private void addInputSection(ColumnLayout layout, String name, ControllerInfo info) {
    UILabel categoryHeader = new UILabel(name);
    categoryHeader.setFamily("subheading");
    layout.addWidget(categoryHeader);
    float columnRatio = 0.4f;
    UICheckbox invertX = new UICheckbox();
    invertX.bindChecked(BindHelper.bindBeanProperty("invertX", info, Boolean.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-x}")), invertX).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    UICheckbox invertY = new UICheckbox();
    invertY.bindChecked(BindHelper.bindBeanProperty("invertY", info, Boolean.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-y}")), invertY).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    UICheckbox invertZ = new UICheckbox();
    invertZ.bindChecked(BindHelper.bindBeanProperty("invertZ", info, Boolean.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-z}")), invertZ).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    UISlider mvmtDeadZone = new UISlider();
    mvmtDeadZone.setIncrement(0.01f);
    mvmtDeadZone.setMinimum(0);
    mvmtDeadZone.setRange(1);
    mvmtDeadZone.setPrecision(2);
    mvmtDeadZone.bindValue(BindHelper.bindBeanProperty("movementDeadZone", info, Float.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#movement-dead-zone}")), mvmtDeadZone).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    UISlider rotDeadZone = new UISlider();
    rotDeadZone.setIncrement(0.01f);
    rotDeadZone.setMinimum(0);
    rotDeadZone.setRange(1);
    rotDeadZone.setPrecision(2);
    rotDeadZone.bindValue(BindHelper.bindBeanProperty("rotationDeadZone", info, Float.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#rotation-dead-zone}")), rotDeadZone).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    layout.addWidget(new UISpace(new Vector2i(0, 16)));
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) UISlider(org.terasology.rendering.nui.widgets.UISlider) RowLayout(org.terasology.rendering.nui.layouts.RowLayout) UISpace(org.terasology.rendering.nui.widgets.UISpace) Vector2i(org.terasology.math.geom.Vector2i) UICheckbox(org.terasology.rendering.nui.widgets.UICheckbox)

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