Search in sources :

Example 1 with WorldGeneratorInfo

use of org.terasology.engine.world.generator.internal.WorldGeneratorInfo in project Terasology by MovingBlocks.

the class GameDetailsScreen method getGeneralInfo.

private String getGeneralInfo(final GameInfo theGameInfo) {
    SimpleUri name = theGameInfo.getManifest().getWorldInfo(TerasologyConstants.MAIN_WORLD).getWorldGenerator();
    WorldGeneratorInfo wgi = worldGeneratorManager.getWorldGeneratorInfo(name);
    String display = "ERROR: generator " + name + " not found.";
    if (wgi != null) {
        display = wgi.getDisplayName();
    }
    return translationSystem.translate("${engine:menu#game-details-game-title} ") + theGameInfo.getManifest().getTitle() + '\n' + '\n' + translationSystem.translate("${engine:menu#game-details-last-play}: ") + DATE_FORMAT.format(theGameInfo.getTimestamp()) + '\n' + '\n' + translationSystem.translate("${engine:menu#game-details-game-duration} ") + DateTimeHelper.getDeltaBetweenTimestamps(new Date(0).getTime(), theGameInfo.getManifest().getTime()) + '\n' + '\n' + translationSystem.translate("${engine:menu#game-details-game-seed} ") + theGameInfo.getManifest().getSeed() + '\n' + '\n' + translationSystem.translate("${engine:menu#game-details-world-generator}: ") + '\t' + display;
}
Also used : SimpleUri(org.terasology.engine.core.SimpleUri) Date(java.util.Date) WorldGeneratorInfo(org.terasology.engine.world.generator.internal.WorldGeneratorInfo)

Example 2 with WorldGeneratorInfo

use of org.terasology.engine.world.generator.internal.WorldGeneratorInfo in project Terasology by MovingBlocks.

the class NewGameScreen method setDefaultGeneratorOfGameplayModule.

// Sets the default generator of the passed in gameplay module. Make sure it's already selected.
private void setDefaultGeneratorOfGameplayModule(Module module) {
    // Set the default generator of the selected gameplay module
    SimpleUri defaultWorldGenerator = StandardModuleExtension.getDefaultWorldGenerator(module);
    if (defaultWorldGenerator != null) {
        for (WorldGeneratorInfo worldGenInfo : worldGeneratorManager.getWorldGenerators()) {
            if (worldGenInfo.getUri().equals(defaultWorldGenerator)) {
                config.getWorldGeneration().setDefaultGenerator(worldGenInfo.getUri());
            }
        }
    }
    config.save();
}
Also used : SimpleUri(org.terasology.engine.core.SimpleUri) WorldGeneratorInfo(org.terasology.engine.world.generator.internal.WorldGeneratorInfo)

Example 3 with WorldGeneratorInfo

use of org.terasology.engine.world.generator.internal.WorldGeneratorInfo in project Terasology by MovingBlocks.

the class UniverseSetupScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    final UIDropdownScrollable<WorldGeneratorInfo> worldGenerator = find("worldGenerators", 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 AdvancedGameSetupScreen
                final Set<Name> enabledModuleNames = new HashSet<>(getAllEnabledModuleNames());
                final 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 UIDropdownScrollable worldsDropdown = find("worlds", UIDropdownScrollable.class);
    worldsDropdown.bindSelection(new Binding<String>() {

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

        @Override
        public void set(String value) {
            selectedWorld = value;
            indexOfSelectedWorld = findIndex(worlds, selectedWorld);
        }
    });
    WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation());
    WidgetUtil.trySubscribe(this, "worldConfig", button -> {
        final WorldSetupScreen worldSetupScreen = getManager().createScreen(WorldSetupScreen.ASSET_URI, WorldSetupScreen.class);
        try {
            if (!worlds.isEmpty() || !selectedWorld.isEmpty()) {
                worldSetupScreen.setWorld(context, findWorldByName(), worldsDropdown);
                triggerForwardAnimation(worldSetupScreen);
            } else {
                getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Worlds List Empty!", "No world found to configure.");
            }
        } catch (UnresolvedWorldGeneratorException e) {
            logger.error("Can't configure the world! due to {}", e.getMessage());
        }
    });
    WidgetUtil.trySubscribe(this, "addGenerator", button -> {
        // modules may do
        if (worldGenerator.getSelection().getUri().toString().equals("CoreWorlds:heightMap")) {
            getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("HeightMap not supported", "HeightMap is not supported for advanced setup right now, a game template will be introduced soon.");
        } else {
            addNewWorld(worldGenerator.getSelection());
            worldsDropdown.setOptions(worldNames());
        }
    });
    WidgetUtil.trySubscribe(this, "continue", button -> {
        final WorldPreGenerationScreen worldPreGenerationScreen = getManager().createScreen(WorldPreGenerationScreen.ASSET_URI, WorldPreGenerationScreen.class);
        if (!worlds.isEmpty()) {
            final WaitPopup<Boolean> loadPopup = getManager().pushScreen(WaitPopup.ASSET_URI, WaitPopup.class);
            loadPopup.setMessage("Loading", "please wait ...");
            loadPopup.onSuccess(result -> {
                if (result != null && result) {
                    triggerForwardAnimation(worldPreGenerationScreen);
                } else {
                    getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error", "Can't load world pre generation screen! Please, try again!");
                }
            });
            loadPopup.startOperation(() -> {
                try {
                    worldPreGenerationScreen.setEnvironment(context);
                } catch (UnresolvedWorldGeneratorException e) {
                    return false;
                }
                return true;
            }, true);
        } else {
            getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Worlds List Empty!", "Please select a world generator and add words to the dropdown!");
        }
    });
    WidgetUtil.trySubscribe(this, "mainMenu", button -> {
        getManager().pushScreen("engine:mainMenuScreen");
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) WorldGeneratorInfo(org.terasology.engine.world.generator.internal.WorldGeneratorInfo) List(java.util.List)

Example 4 with WorldGeneratorInfo

use of org.terasology.engine.world.generator.internal.WorldGeneratorInfo in project Terasology by MovingBlocks.

the class SelectionScreen method updateDescription.

void updateDescription(final GameInfo gameInfo) {
    if (gameInfo == null) {
        worldGenerator.setText("");
        moduleNames.setText("");
        loadPreviewImages(null);
        return;
    }
    final WorldGeneratorInfo wgi = worldGeneratorManager.getWorldGeneratorInfo(gameInfo.getManifest().getWorldInfo(TerasologyConstants.MAIN_WORLD).getWorldGenerator());
    String mainWorldGenerator = "ERROR: world generator ";
    if (wgi != null) {
        mainWorldGenerator = wgi.getDisplayName();
    } else {
        mainWorldGenerator = mainWorldGenerator + gameInfo.getManifest().getWorldInfo(TerasologyConstants.MAIN_WORLD).getWorldGenerator().toString() + " not found";
    }
    final String commaSeparatedModules = gameInfo.getManifest().getModules().stream().map(NameVersion::getName).map(Name::toString).sorted(String::compareToIgnoreCase).collect(Collectors.joining(", "));
    worldGenerator.setText(mainWorldGenerator);
    moduleNames.setText(commaSeparatedModules.length() > MODULES_LINE_LIMIT ? commaSeparatedModules.substring(0, MODULES_LINE_LIMIT) + "..." : commaSeparatedModules);
    loadPreviewImages(gameInfo);
}
Also used : WorldGeneratorInfo(org.terasology.engine.world.generator.internal.WorldGeneratorInfo) Name(org.terasology.gestalt.naming.Name)

Aggregations

WorldGeneratorInfo (org.terasology.engine.world.generator.internal.WorldGeneratorInfo)4 SimpleUri (org.terasology.engine.core.SimpleUri)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 UnresolvedWorldGeneratorException (org.terasology.engine.world.generator.UnresolvedWorldGeneratorException)1 Name (org.terasology.gestalt.naming.Name)1 UIDropdownScrollable (org.terasology.nui.widgets.UIDropdownScrollable)1