Search in sources :

Example 1 with UIImage

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

the class StartPlayingScreen method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    UIImage previewImage = find("preview", UIImage.class);
    previewImage.setImage(texture);
    UILabel subitle = find("subtitle", UILabel.class);
    subitle.setText(translationSystem.translate("${engine:menu#start-playing}") + " in " + targetWorld.getWorldName().toString());
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) UIImage(org.terasology.nui.widgets.UIImage)

Example 2 with UIImage

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

the class ColorConstraintWidgetFactory method bindWidgetToSetting.

@Override
protected void bindWidgetToSetting(UIWidget widget) {
    UIImage img = widget.find("image", UIImage.class);
    if (img != null) {
        ResourceUrn uri = TextureUtil.getTextureUriForColor(Color.WHITE);
        Texture tex = assetManager.getAsset(uri, Texture.class).get();
        img.setImage(tex);
        img.bindTint(new SettingBinding<>(getSetting()));
    }
    UISlider slider = widget.find("tone", UISlider.class);
    slider.setIncrement(0.01f);
    // ensure a certain width
    Function<Object, String> constant = Functions.constant("  ");
    slider.setLabelFunction(constant);
    slider.bindValue(new MappingBinding<>(new SettingBinding<>(getSetting()), this::findClosestColor, this::findClosestIndex));
}
Also used : UISlider(org.terasology.nui.widgets.UISlider) SettingBinding(org.terasology.engine.config.flexible.bindings.SettingBinding) UIImage(org.terasology.nui.widgets.UIImage) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Texture(org.terasology.engine.rendering.assets.texture.Texture)

Example 3 with UIImage

use of org.terasology.nui.widgets.UIImage 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

UIImage (org.terasology.nui.widgets.UIImage)3 Texture (org.terasology.engine.rendering.assets.texture.Texture)2 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)2 UILabel (org.terasology.nui.widgets.UILabel)2 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)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 Config (org.terasology.engine.config.Config)1 PlayerConfig (org.terasology.engine.config.PlayerConfig)1 SettingBinding (org.terasology.engine.config.flexible.bindings.SettingBinding)1 TerasologyConstants (org.terasology.engine.core.TerasologyConstants)1 TranslationSystem (org.terasology.engine.i18n.TranslationSystem)1 GamePreviewImageProvider (org.terasology.engine.persistence.internal.GamePreviewImageProvider)1