Search in sources :

Example 6 with GameInfo

use of org.terasology.engine.rendering.nui.layers.mainMenu.savedGames.GameInfo in project Terasology by MovingBlocks.

the class SelectGameScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    initWidgets();
    if (isValidScreen()) {
        if (gameTypeTitle != null) {
            gameTypeTitle.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    if (isLoadingAsServer()) {
                        return translationSystem.translate("${engine:menu#select-multiplayer-game-sub-title}");
                    } else {
                        return translationSystem.translate("${engine:menu#select-singleplayer-game-sub-title}");
                    }
                }
            });
        }
        initSaveGamePathWidget(PathManager.getInstance().getSavesPath());
        getGameInfos().subscribeSelection((widget, item) -> {
            load.setEnabled(item != null);
            delete.setEnabled(item != null);
            details.setEnabled(item != null);
            updateDescription(item);
        });
        getGameInfos().subscribe((widget, item) -> loadGame(item));
        load.subscribe(e -> {
            final GameInfo gameInfo = getGameInfos().getSelection();
            if (gameInfo != null) {
                loadGame(gameInfo);
            }
        });
        delete.subscribe(e -> {
            TwoButtonPopup confirmationPopup = getManager().pushScreen(TwoButtonPopup.ASSET_URI, TwoButtonPopup.class);
            confirmationPopup.setMessage(translationSystem.translate("${engine:menu#remove-confirmation-popup" + "-title}"), translationSystem.translate("${engine:menu#remove-confirmation-popup-message}"));
            confirmationPopup.setLeftButton(translationSystem.translate("${engine:menu#dialog-yes}"), this::removeSelectedGame);
            confirmationPopup.setRightButton(translationSystem.translate("${engine:menu#dialog-no}"), () -> {
            });
        });
        final NewGameScreen newGameScreen = getManager().createScreen(NewGameScreen.ASSET_URI, NewGameScreen.class);
        create.subscribe(e -> {
            newGameScreen.setUniverseWrapper(universeWrapper);
            triggerForwardAnimation(newGameScreen);
        });
        close.subscribe(e -> triggerBackAnimation());
        details.subscribe(e -> {
            final GameInfo gameInfo = getGameInfos().getSelection();
            if (gameInfo != null) {
                final GameDetailsScreen detailsScreen = getManager().createScreen(GameDetailsScreen.ASSET_URI, GameDetailsScreen.class);
                detailsScreen.setGameInfo(gameInfo);
                detailsScreen.setPreviews(previewSlideshow.getImages());
                getManager().pushScreen(detailsScreen);
            }
        });
    }
}
Also used : GameInfo(org.terasology.engine.rendering.nui.layers.mainMenu.savedGames.GameInfo) GameDetailsScreen(org.terasology.engine.rendering.nui.layers.mainMenu.gameDetailsScreen.GameDetailsScreen)

Example 7 with GameInfo

use of org.terasology.engine.rendering.nui.layers.mainMenu.savedGames.GameInfo in project Terasology by MovingBlocks.

the class SelectionScreen method loadPreviewImages.

private void loadPreviewImages(final GameInfo gameInfo) {
    List<Texture> textures = new ArrayList<>();
    if (gameInfo != null && gameInfo.getSavePath() != null) {
        final List<BufferedImage> bufferedImages = GamePreviewImageProvider.getAllPreviewImages(gameInfo.getSavePath());
        textures = bufferedImages.stream().map(buffImage -> {
            TextureData textureData;
            try {
                textureData = AWTTextureFormat.convertToTextureData(buffImage, Texture.FilterMode.LINEAR);
            } catch (IOException e) {
                logger.error("Converting preview image to texture data {} failed", e);
                return null;
            }
            return Assets.generateAsset(new ResourceUrn(PREVIEW_IMAGE_URI_PATTERN + bufferedImages.indexOf(buffImage)), textureData, Texture.class);
        }).filter(Objects::nonNull).collect(Collectors.toList());
    }
    if (textures.isEmpty()) {
        textures.add(Assets.getTexture(DEFAULT_PREVIEW_IMAGE_URI).get());
    }
    previewSlideshow.clean();
    textures.forEach(tex -> {
        UIImage image = new UIImage(null, tex, true);
        previewSlideshow.addImage(image);
    });
}
Also used : TerasologyConstants(org.terasology.engine.core.TerasologyConstants) WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) In(org.terasology.engine.registry.In) Texture(org.terasology.engine.rendering.assets.texture.Texture) LoggerFactory(org.slf4j.LoggerFactory) GamePreviewImageProvider(org.terasology.engine.persistence.internal.GamePreviewImageProvider) ArrayList(java.util.ArrayList) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) WorldGeneratorInfo(org.terasology.engine.world.generator.internal.WorldGeneratorInfo) UIImageSlideshow(org.terasology.nui.widgets.UIImageSlideshow) Path(java.nio.file.Path) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) Logger(org.slf4j.Logger) Assets(org.terasology.engine.utilities.Assets) UILabel(org.terasology.nui.widgets.UILabel) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) UIImage(org.terasology.nui.widgets.UIImage) Collectors(java.util.stream.Collectors) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) Objects(java.util.Objects) FilesUtil(org.terasology.engine.utilities.FilesUtil) List(java.util.List) Stream(java.util.stream.Stream) Config(org.terasology.engine.config.Config) NameVersion(org.terasology.gestalt.naming.NameVersion) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) GameInfo(org.terasology.engine.rendering.nui.layers.mainMenu.savedGames.GameInfo) UIList(org.terasology.nui.widgets.UIList) PlayerConfig(org.terasology.engine.config.PlayerConfig) AWTTextureFormat(org.terasology.engine.rendering.assets.texture.AWTTextureFormat) Name(org.terasology.gestalt.naming.Name) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) ArrayList(java.util.ArrayList) Objects(java.util.Objects) IOException(java.io.IOException) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) UIImage(org.terasology.nui.widgets.UIImage) Texture(org.terasology.engine.rendering.assets.texture.Texture) BufferedImage(java.awt.image.BufferedImage)

Aggregations

GameInfo (org.terasology.engine.rendering.nui.layers.mainMenu.savedGames.GameInfo)7 IOException (java.io.IOException)2 Config (org.terasology.engine.config.Config)2 BufferedImage (java.awt.image.BufferedImage)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 PlayerConfig (org.terasology.engine.config.PlayerConfig)1 WorldGenerationConfig (org.terasology.engine.config.WorldGenerationConfig)1 TerasologyConstants (org.terasology.engine.core.TerasologyConstants)1 StateLoading (org.terasology.engine.core.modes.StateLoading)1 GameManifest (org.terasology.engine.game.GameManifest)1 TranslationSystem (org.terasology.engine.i18n.TranslationSystem)1 GamePreviewImageProvider (org.terasology.engine.persistence.internal.GamePreviewImageProvider)1 In (org.terasology.engine.registry.In)1