Search in sources :

Example 11 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class AtlasFormat method load.

@Override
public AtlasData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
    try (Reader reader = new InputStreamReader(inputs.get(0).openStream(), Charsets.UTF_8)) {
        AtlasDefinition def = gson.fromJson(reader, AtlasDefinition.class);
        Optional<? extends Texture> texture = assetManager.getAsset(def.getTexture(), Texture.class);
        if (texture.isPresent()) {
            Vector2i size = def.getTextureSize();
            if (size == null) {
                size = new Vector2i(texture.get().getWidth(), texture.get().getHeight());
            }
            Map<Name, SubtextureData> result = Maps.newHashMap();
            if (def.getGrid() != null) {
                process(def.getGrid(), texture.get(), size, result);
            }
            if (def.getGrids() != null) {
                for (GridDefinition grid : def.getGrids()) {
                    process(grid, texture.get(), size, result);
                }
            }
            if (def.getSubimage() != null) {
                process(def.getSubimage(), texture.get(), size, result);
            }
            if (def.getSubimages() != null) {
                for (FreeformDefinition freeform : def.getSubimages()) {
                    process(freeform, texture.get(), size, result);
                }
            }
            return new AtlasData(result);
        }
        return null;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) SubtextureData(org.terasology.engine.rendering.assets.texture.subtexture.SubtextureData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Vector2i(org.joml.Vector2i) Name(org.terasology.gestalt.naming.Name)

Example 12 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class NUIManagerInternal method mouseWheelEvent.

// mouse wheel events
@ReceiveEvent(components = ClientComponent.class, priority = EventPriority.PRIORITY_HIGH)
public void mouseWheelEvent(MouseWheelEvent event, EntityRef entity) {
    if (!mouse.isVisible()) {
        return;
    }
    Vector2i mousePosition = event.getMousePosition();
    if (focus != null) {
        NUIMouseWheelEvent nuiEvent = new NUIMouseWheelEvent(mouse, keyboard, mousePosition, event.getWheelTurns());
        focus.onMouseWheelEvent(nuiEvent);
        if (nuiEvent.isConsumed()) {
            event.consume();
            return;
        }
    }
    if (canvas.processMouseWheel(event.getWheelTurns(), mousePosition)) {
        event.consume();
    }
    if (isReleasingMouse()) {
        event.consume();
    }
}
Also used : NUIMouseWheelEvent(org.terasology.nui.events.NUIMouseWheelEvent) Vector2i(org.joml.Vector2i) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 13 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class ContextMenuScreen method onDraw.

@Override
public void onDraw(Canvas canvas) {
    canvas.addInteractionRegion(mainListener);
    Vector2i currentPosition = null;
    int currentWidth = 0;
    for (UIList<AbstractContextMenuItem> level : menuWidgets) {
        if (level.isVisible()) {
            if (currentPosition == null) {
                currentPosition = new Vector2i(position);
            } else {
                currentPosition.x += currentWidth;
            }
            Vector2i preferredSize = canvas.calculatePreferredSize(level);
            Rectanglei region = new Rectanglei(currentPosition.x, currentPosition.y).setSize(preferredSize.x, preferredSize.y);
            double percentageThreshold = 0.9;
            int canvasHeight = canvas.getRegion().getSizeY();
            if (region.maxY > canvasHeight * percentageThreshold) {
                region = new Rectanglei(region.minX, region.minY - (region.maxY - canvasHeight) - (int) (canvasHeight * (1 - percentageThreshold))).setSize(region.maxX, canvasHeight);
            }
            currentWidth = canvas.calculatePreferredSize(level).x() - 8;
            canvas.drawWidget(level, region);
        }
    }
}
Also used : Vector2i(org.joml.Vector2i) Rectanglei(org.terasology.joml.geom.Rectanglei)

Example 14 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class ModuleDetailsScreen method setUpModules.

private void setUpModules() {
    modules.subscribeSelection(((widget, item) -> {
        if (item != null) {
            dependencies.setList(getSortedDependencies(item));
            dependencies.setSelection(null);
            dependencies.select(0);
            this.updateOpenInBrowserButton();
        }
    }));
    modules.setItemRenderer(new StringTextRenderer<Module>() {

        @Override
        public String getString(Module value) {
            if (value != null) {
                return value.getMetadata().getDisplayName().toString();
            }
            return "";
        }

        @Override
        public void draw(Module value, Canvas canvas) {
            if (!validateModuleDependencies(value.getId())) {
                canvas.setMode(("invalid"));
            } else {
                canvas.setMode("available");
            }
            canvas.drawText(getString(value), canvas.getRegion());
        }

        @Override
        public Vector2i getPreferredSize(Module value, Canvas canvas) {
            String text = getString(value);
            return new Vector2i(canvas.getCurrentStyle().getFont().getWidth(text), canvas.getCurrentStyle().getFont().getLineHeight());
        }
    });
}
Also used : ModuleInstaller(org.terasology.engine.core.module.ModuleInstaller) Arrays(java.util.Arrays) In(org.terasology.engine.registry.In) Color(org.terasology.nui.Color) LoggerFactory(org.slf4j.LoggerFactory) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) AbstractItemRenderer(org.terasology.nui.itemRendering.AbstractItemRenderer) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo) Canvas(org.terasology.nui.Canvas) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) DateFormat(java.text.DateFormat) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) StringTextRenderer(org.terasology.nui.itemRendering.StringTextRenderer) Binding(org.terasology.nui.databinding.Binding) StringUtils(org.codehaus.plexus.util.StringUtils) Module(org.terasology.gestalt.module.Module) Collection(java.util.Collection) WaitPopup(org.terasology.engine.rendering.nui.layers.mainMenu.WaitPopup) Set(java.util.Set) Version(org.terasology.gestalt.naming.Version) Collectors(java.util.stream.Collectors) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Objects(java.util.Objects) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) Context(org.terasology.engine.context.Context) Stream(java.util.stream.Stream) Vector2i(org.joml.Vector2i) ExtraDataModuleExtension(org.terasology.engine.core.module.ExtraDataModuleExtension) UIList(org.terasology.nui.widgets.UIList) Name(org.terasology.gestalt.naming.Name) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) ModuleManager(org.terasology.engine.core.module.ModuleManager) UIButtonWebBrowser(org.terasology.engine.rendering.nui.widgets.UIButtonWebBrowser) SimpleDateFormat(java.text.SimpleDateFormat) DownloadPopupProgressListener(org.terasology.engine.rendering.nui.layers.mainMenu.advancedGameSetupScreen.DownloadPopupProgressListener) DependencyResolutionFailedException(org.terasology.engine.core.module.DependencyResolutionFailedException) HashSet(java.util.HashSet) StandardModuleExtension(org.terasology.engine.core.module.StandardModuleExtension) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ConfirmPopup(org.terasology.engine.rendering.nui.layers.mainMenu.ConfirmPopup) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) Logger(org.slf4j.Logger) UILabel(org.terasology.nui.widgets.UILabel) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) UIButton(org.terasology.nui.widgets.UIButton) Comparator(java.util.Comparator) RemoteModuleExtension(org.terasology.engine.core.module.RemoteModuleExtension) Collections(java.util.Collections) Canvas(org.terasology.nui.Canvas) Vector2i(org.joml.Vector2i) Module(org.terasology.gestalt.module.Module)

Example 15 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class ModuleDetailsScreen method setUpDependencies.

private void setUpDependencies() {
    dependencies.setList(Collections.emptyList());
    dependencies.setItemRenderer(new AbstractItemRenderer<DependencyInfo>() {

        private String getString(DependencyInfo value) {
            if (value != null) {
                return value.getId().toString();
            }
            return "";
        }

        @Override
        public void draw(DependencyInfo value, Canvas canvas) {
            Module module = moduleManager.getRegistry().getLatestModuleVersion(value.getId());
            if (module == null || !(value.versionPredicate().test(module.getVersion()))) {
                canvas.setMode("invalid");
            } else {
                canvas.setMode("available");
            }
            canvas.drawText(getString(value), canvas.getRegion());
        }

        @Override
        public Vector2i getPreferredSize(DependencyInfo value, Canvas canvas) {
            String text = getString(value);
            canvas.getCurrentStyle().setTextColor(Color.RED);
            return new Vector2i(canvas.getCurrentStyle().getFont().getWidth(text), canvas.getCurrentStyle().getFont().getLineHeight());
        }
    });
    dependencies.subscribe(((widget, item) -> {
        if (item != null) {
            modules.getList().stream().filter(m -> item.getId().equals(m.getId())).findFirst().ifPresent(m -> modules.setSelection(m));
        }
    }));
}
Also used : ModuleInstaller(org.terasology.engine.core.module.ModuleInstaller) Arrays(java.util.Arrays) In(org.terasology.engine.registry.In) Color(org.terasology.nui.Color) LoggerFactory(org.slf4j.LoggerFactory) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) AbstractItemRenderer(org.terasology.nui.itemRendering.AbstractItemRenderer) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo) Canvas(org.terasology.nui.Canvas) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) DateFormat(java.text.DateFormat) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) StringTextRenderer(org.terasology.nui.itemRendering.StringTextRenderer) Binding(org.terasology.nui.databinding.Binding) StringUtils(org.codehaus.plexus.util.StringUtils) Module(org.terasology.gestalt.module.Module) Collection(java.util.Collection) WaitPopup(org.terasology.engine.rendering.nui.layers.mainMenu.WaitPopup) Set(java.util.Set) Version(org.terasology.gestalt.naming.Version) Collectors(java.util.stream.Collectors) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Objects(java.util.Objects) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) Context(org.terasology.engine.context.Context) Stream(java.util.stream.Stream) Vector2i(org.joml.Vector2i) ExtraDataModuleExtension(org.terasology.engine.core.module.ExtraDataModuleExtension) UIList(org.terasology.nui.widgets.UIList) Name(org.terasology.gestalt.naming.Name) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) ModuleManager(org.terasology.engine.core.module.ModuleManager) UIButtonWebBrowser(org.terasology.engine.rendering.nui.widgets.UIButtonWebBrowser) SimpleDateFormat(java.text.SimpleDateFormat) DownloadPopupProgressListener(org.terasology.engine.rendering.nui.layers.mainMenu.advancedGameSetupScreen.DownloadPopupProgressListener) DependencyResolutionFailedException(org.terasology.engine.core.module.DependencyResolutionFailedException) HashSet(java.util.HashSet) StandardModuleExtension(org.terasology.engine.core.module.StandardModuleExtension) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ConfirmPopup(org.terasology.engine.rendering.nui.layers.mainMenu.ConfirmPopup) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) Logger(org.slf4j.Logger) UILabel(org.terasology.nui.widgets.UILabel) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) UIButton(org.terasology.nui.widgets.UIButton) Comparator(java.util.Comparator) RemoteModuleExtension(org.terasology.engine.core.module.RemoteModuleExtension) Collections(java.util.Collections) Canvas(org.terasology.nui.Canvas) Vector2i(org.joml.Vector2i) Module(org.terasology.gestalt.module.Module) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo)

Aggregations

Vector2i (org.joml.Vector2i)41 Test (org.junit.jupiter.api.Test)12 Rectanglei (org.terasology.joml.geom.Rectanglei)9 Canvas (org.terasology.nui.Canvas)9 UILabel (org.terasology.nui.widgets.UILabel)6 List (java.util.List)5 Objects (java.util.Objects)5 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)5 Vector2f (org.joml.Vector2f)4 Vector2ic (org.joml.Vector2ic)4 Module (org.terasology.gestalt.module.Module)4 Name (org.terasology.gestalt.naming.Name)4 UIButton (org.terasology.nui.widgets.UIButton)4 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Collection (java.util.Collection)3 Comparator (java.util.Comparator)3 Iterator (java.util.Iterator)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3