Search in sources :

Example 81 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class NUIManagerInternal method pushScreen.

@Override
public void pushScreen(UIScreenLayer screen) {
    TabbingManager.setInitialized(false);
    if (!screen.isLowerLayerVisible()) {
        UIScreenLayer current = screens.peek();
        if (current != null) {
            current.onHide();
        }
    }
    screens.push(screen);
    screen.onOpened();
    String id = screen.getId();
    if (ResourceUrn.isValid(id)) {
        ResourceUrn uri = new ResourceUrn(id);
        screenLookup.put(uri, screen);
    }
}
Also used : UIScreenLayer(org.terasology.engine.rendering.nui.UIScreenLayer) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 82 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class NUIManagerInternal method invalidate.

@Override
public void invalidate() {
    assetManager.getLoadedAssets(UIElement.class).forEach(UIElement::dispose);
    boolean hudVisible = isHUDVisible();
    if (hudVisible) {
        setHUDVisible(false);
    }
    Deque<ResourceUrn> reverseUrns = new LinkedList<>();
    Map<UIScreenLayer, ResourceUrn> inverseLookup = screenLookup.inverse();
    for (UIScreenLayer screen : screens) {
        screen.onClosed();
        reverseUrns.addFirst(inverseLookup.get(screen));
    }
    screens.clear();
    screenLookup.clear();
    reverseUrns.forEach(this::pushScreen);
    if (hudVisible) {
        setHUDVisible(true);
    }
}
Also used : UIElement(org.terasology.nui.asset.UIElement) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) UIScreenLayer(org.terasology.engine.rendering.nui.UIScreenLayer) LinkedList(java.util.LinkedList)

Example 83 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class NUIEditorSettingsScreen method initialise.

@Override
public void initialise() {
    WidgetUtil.tryBindCheckbox(this, "disableAutosave", BindHelper.bindBeanProperty("disableAutosave", config.getNuiEditor(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "disableIcons", BindHelper.bindBeanProperty("disableIcons", config.getNuiEditor(), Boolean.TYPE));
    WidgetUtil.trySubscribe(this, "close", button -> getManager().closeScreen(ASSET_URI));
    alternativeLocale = find("alternativeLocale", UIDropdownScrollable.class);
    if (alternativeLocale != null) {
        // Build the list of available locales and set the dropdown's options to them.
        TranslationProject menuProject = translationSystem.getProject(new ResourceUrn("engine:menu"));
        List<Locale> locales = new ArrayList<>(menuProject.getAvailableLocales());
        Collections.sort(locales, ((Object o1, Object o2) -> (o1.toString().compareTo(o2.toString()))));
        alternativeLocale.setOptions(Lists.newArrayList(locales));
        alternativeLocale.setVisibleOptions(5);
        alternativeLocale.setOptionRenderer(new LocaleRenderer(translationSystem));
        // If an alternative locale has been previously selected, select it; otherwise select the system locale.
        if (config.getNuiEditor().getAlternativeLocale() != null) {
            alternativeLocale.setSelection(config.getNuiEditor().getAlternativeLocale());
        } else {
            alternativeLocale.setSelection(systemConfig.locale.get());
        }
    }
}
Also used : Locale(java.util.Locale) LocaleRenderer(org.terasology.engine.rendering.nui.layers.mainMenu.settings.LocaleRenderer) TranslationProject(org.terasology.engine.i18n.TranslationProject) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) ArrayList(java.util.ArrayList) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 84 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class WorldPreGenerationScreen method genTexture.

/**
 * Generates a texture and sets it to the image view, thus previewing the world.
 */
private void genTexture() {
    int imgWidth = 384;
    int imgHeight = 384;
    ByteBuffer buffer = ByteBuffer.allocateDirect(imgWidth * imgHeight * Integer.BYTES);
    ByteBuffer[] data = new ByteBuffer[] { buffer };
    ResourceUrn uri = new ResourceUrn("engine:terrainPreview");
    TextureData texData = new TextureData(imgWidth, imgHeight, data, Texture.WrapMode.CLAMP, Texture.FilterMode.LINEAR);
    texture = Assets.generateAsset(uri, texData, Texture.class);
    previewImage = find("preview", UIImage.class);
    previewImage.setImage(texture);
}
Also used : TextureData(org.terasology.engine.rendering.assets.texture.TextureData) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) UIImage(org.terasology.nui.widgets.UIImage) ByteBuffer(java.nio.ByteBuffer) Texture(org.terasology.engine.rendering.assets.texture.Texture)

Example 85 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn 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

ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)90 Test (org.junit.jupiter.api.Test)19 Name (org.terasology.gestalt.naming.Name)12 BeforeEach (org.junit.jupiter.api.BeforeEach)11 BlockFamilyDefinitionData (org.terasology.engine.world.block.loader.BlockFamilyDefinitionData)10 IOException (java.io.IOException)9 AssetManager (org.terasology.gestalt.assets.management.AssetManager)9 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)8 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)8 PrefabData (org.terasology.engine.entitySystem.prefab.PrefabData)7 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)7 BlockUri (org.terasology.engine.world.block.BlockUri)7 AssetDataFile (org.terasology.gestalt.assets.format.AssetDataFile)7 Texture (org.terasology.engine.rendering.assets.texture.Texture)5 BlockManagerImpl (org.terasology.engine.world.block.internal.BlockManagerImpl)5 BlockFamilyDefinition (org.terasology.engine.world.block.loader.BlockFamilyDefinition)5 NullWorldAtlas (org.terasology.engine.world.block.tiles.NullWorldAtlas)5 ExtraBlockDataManager (org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager)5 StringComponent (org.terasology.unittest.stubs.StringComponent)5 ByteBuffer (java.nio.ByteBuffer)4