Search in sources :

Example 16 with Vector2i

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

the class GameDetailsScreen method setUpGameModules.

private void setUpGameModules() {
    gameModules.subscribeSelection((widget, moduleSelectionInfo) -> {
        if (moduleSelectionInfo == null) {
            return;
        }
        descriptionTitle.setText(translationSystem.translate("${engine:menu#game-details-module-description}"));
        description.setText(getModuleDescription(moduleSelectionInfo));
        gameWorlds.setSelection(null);
        blocks.setSelection(null);
    });
    gameModules.setItemRenderer(new AbstractItemRenderer<ModuleSelectionInfo>() {

        String getString(ModuleSelectionInfo value) {
            if (value.getMetadata() != null) {
                return value.getMetadata().getDisplayName().toString();
            } else if (value.isUnavailableVersion()) {
                return value.getUnavailableModuleName();
            }
            return "";
        }

        @Override
        public void draw(ModuleSelectionInfo value, Canvas canvas) {
            if (value.isStrictVersion()) {
                canvas.setMode("strict");
            } else if (value.isLatestVersion()) {
                canvas.setMode("latest");
            } else {
                canvas.setMode("invalid");
            }
            canvas.drawText(getString(value), canvas.getRegion());
        }

        @Override
        public Vector2i getPreferredSize(ModuleSelectionInfo value, Canvas canvas) {
            String text = getString(value);
            return new Vector2i(canvas.getCurrentStyle().getFont().getWidth(text), canvas.getCurrentStyle().getFont().getLineHeight());
        }
    });
    gameModules.subscribe(((widget, item) -> openModuleDetailsScreen()));
}
Also used : WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) In(org.terasology.engine.registry.In) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) WorldInfo(org.terasology.engine.world.internal.WorldInfo) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) Map(java.util.Map) 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) Binding(org.terasology.nui.databinding.Binding) SelectGameScreen(org.terasology.engine.rendering.nui.layers.mainMenu.SelectGameScreen) StringUtils(org.codehaus.plexus.util.StringUtils) Module(org.terasology.gestalt.module.Module) Collection(java.util.Collection) UIImage(org.terasology.nui.widgets.UIImage) DateTimeHelper(org.terasology.engine.utilities.time.DateTimeHelper) Collectors(java.util.stream.Collectors) SimpleUri(org.terasology.engine.core.SimpleUri) 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) NameVersion(org.terasology.gestalt.naming.NameVersion) GameInfo(org.terasology.engine.rendering.nui.layers.mainMenu.savedGames.GameInfo) UIList(org.terasology.nui.widgets.UIList) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) TerasologyConstants(org.terasology.engine.core.TerasologyConstants) ModuleManager(org.terasology.engine.core.module.ModuleManager) ModuleDetailsScreen(org.terasology.engine.rendering.nui.layers.mainMenu.moduleDetailsScreen.ModuleDetailsScreen) SimpleDateFormat(java.text.SimpleDateFormat) UITabBox(org.terasology.nui.widgets.UITabBox) ArrayList(java.util.ArrayList) WorldGeneratorInfo(org.terasology.engine.world.generator.internal.WorldGeneratorInfo) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Lists(com.google.common.collect.Lists) UIImageSlideshow(org.terasology.nui.widgets.UIImageSlideshow) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) Logger(org.slf4j.Logger) UILabel(org.terasology.nui.widgets.UILabel) Maps(com.google.common.collect.Maps) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) UIButton(org.terasology.nui.widgets.UIButton) Comparator(java.util.Comparator) Canvas(org.terasology.nui.Canvas) Vector2i(org.joml.Vector2i)

Example 17 with Vector2i

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

the class InputSettingsScreen method addInputSection.

private void addInputSection(ColumnLayout layout, String name, ControllerInfo info) {
    UILabel categoryHeader = new UILabel(name);
    categoryHeader.setFamily("subheading");
    layout.addWidget(categoryHeader);
    float columnRatio = 0.4f;
    UICheckbox invertX = new UICheckbox();
    invertX.bindChecked(BindHelper.bindBeanProperty("invertX", info, Boolean.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-x}")), invertX).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    UICheckbox invertY = new UICheckbox();
    invertY.bindChecked(BindHelper.bindBeanProperty("invertY", info, Boolean.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-y}")), invertY).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    UICheckbox invertZ = new UICheckbox();
    invertZ.bindChecked(BindHelper.bindBeanProperty("invertZ", info, Boolean.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-z}")), invertZ).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    UISlider mvmtDeadZone = new UISlider();
    mvmtDeadZone.setIncrement(0.01f);
    mvmtDeadZone.setMinimum(0);
    mvmtDeadZone.setRange(1);
    mvmtDeadZone.setPrecision(2);
    mvmtDeadZone.bindValue(BindHelper.bindBeanProperty("movementDeadZone", info, Float.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#movement-dead-zone}")), mvmtDeadZone).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    UISlider rotDeadZone = new UISlider();
    rotDeadZone.setIncrement(0.01f);
    rotDeadZone.setMinimum(0);
    rotDeadZone.setRange(1);
    rotDeadZone.setPrecision(2);
    rotDeadZone.bindValue(BindHelper.bindBeanProperty("rotationDeadZone", info, Float.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#rotation-dead-zone}")), rotDeadZone).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    layout.addWidget(new UISpace(new Vector2i(0, 16)));
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) UISlider(org.terasology.nui.widgets.UISlider) RowLayout(org.terasology.nui.layouts.RowLayout) UISpace(org.terasology.nui.widgets.UISpace) Vector2i(org.joml.Vector2i) UICheckbox(org.terasology.nui.widgets.UICheckbox)

Example 18 with Vector2i

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

the class InputSettingsScreen method addInputSection.

private void addInputSection(InputCategory category, ColumnLayout layout, Map<SimpleUri, RegisterBindButton> inputsById) {
    if (category != null) {
        layout.addWidget(new UISpace(new Vector2i(0, 16)));
        UILabel categoryHeader = new UILabel(translationSystem.translate(category.displayName()));
        categoryHeader.setFamily("subheading");
        layout.addWidget(categoryHeader);
        Set<SimpleUri> processedBinds = Sets.newHashSet();
        for (String bindId : category.ordering()) {
            SimpleUri bindUri = new SimpleUri(bindId);
            if (bindUri.isValid()) {
                RegisterBindButton bind = inputsById.get(new SimpleUri(bindId));
                if (bind != null) {
                    addInputBindRow(bindUri, bind, layout);
                    processedBinds.add(bindUri);
                }
            }
        }
        List<ExtensionBind> extensionBindList = Lists.newArrayList();
        for (Map.Entry<SimpleUri, RegisterBindButton> bind : inputsById.entrySet()) {
            if (bind.getValue().category().equals(category.id()) && !processedBinds.contains(bind.getKey())) {
                extensionBindList.add(new ExtensionBind(bind.getKey(), bind.getValue()));
            }
        }
        Collections.sort(extensionBindList);
        for (ExtensionBind extension : extensionBindList) {
            addInputBindRow(extension.uri, extension.bind, layout);
        }
    }
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) SimpleUri(org.terasology.engine.core.SimpleUri) UISpace(org.terasology.nui.widgets.UISpace) Vector2i(org.joml.Vector2i) Map(java.util.Map)

Example 19 with Vector2i

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

the class InputSettingsScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    ColumnLayout mainLayout = find("main", ColumnLayout.class);
    UIButton azerty = find("azerty", UIButton.class);
    if (azerty != null) {
        azerty.subscribe(event -> {
            BindCommands.AZERTY.forEach(this::setPrimaryBind);
            bindsManager.registerBinds();
        });
    }
    UIButton dvorak = find("dvorak", UIButton.class);
    if (dvorak != null) {
        dvorak.subscribe(event -> {
            BindCommands.DVORAK.forEach(this::setPrimaryBind);
            bindsManager.registerBinds();
        });
    }
    UIButton neo = find("neo", UIButton.class);
    if (neo != null) {
        neo.subscribe(event -> {
            BindCommands.NEO.forEach(this::setPrimaryBind);
            bindsManager.registerBinds();
        });
    }
    UISlider mouseSensitivity = new UISlider("mouseSensitivity");
    mouseSensitivity.bindValue(BindHelper.bindBeanProperty("mouseSensitivity", inputDeviceConfiguration, Float.TYPE));
    mouseSensitivity.setIncrement(0.025f);
    mouseSensitivity.setPrecision(3);
    UICheckbox mouseInverted = new UICheckbox("mouseYAxisInverted");
    mouseInverted.bindChecked(BindHelper.bindBeanProperty("mouseYAxisInverted", inputDeviceConfiguration, Boolean.TYPE));
    if (mainLayout != null) {
        mainLayout.addWidget(new UILabel("mouseLabel", "subheading", translationSystem.translate("${engine:menu" + "#category-mouse}")));
        mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#mouse" + "-sensitivity}") + ":"), mouseSensitivity).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
        mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-mouse}") + ":"), mouseInverted).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
    }
    Map<String, InputCategory> inputCategories = Maps.newHashMap();
    Map<SimpleUri, RegisterBindButton> inputsById = Maps.newHashMap();
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
        ResolutionResult result = resolver.resolve(moduleId);
        if (result.isSuccess()) {
            try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
                for (Class<?> holdingType : environment.getTypesAnnotatedWith(InputCategory.class, new FromModule(environment, moduleId))) {
                    InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
                    inputCategories.put(module.getId() + ":" + inputCategory.id(), inputCategory);
                }
                for (Class<?> bindEvent : environment.getTypesAnnotatedWith(RegisterBindButton.class, new FromModule(environment, moduleId))) {
                    if (BindButtonEvent.class.isAssignableFrom(bindEvent)) {
                        RegisterBindButton bindRegister = bindEvent.getAnnotation(RegisterBindButton.class);
                        inputsById.put(new SimpleUri(module.getId(), bindRegister.id()), bindRegister);
                    }
                }
            }
        }
    }
    if (mainLayout != null) {
        addInputSection(inputCategories.remove("engine:movement"), mainLayout, inputsById);
        addInputSection(inputCategories.remove("engine:interaction"), mainLayout, inputsById);
        addInputSection(inputCategories.remove("engine:inventory"), mainLayout, inputsById);
        addInputSection(inputCategories.remove("engine:general"), mainLayout, inputsById);
        for (InputCategory category : inputCategories.values()) {
            addInputSection(category, mainLayout, inputsById);
        }
        mainLayout.addWidget(new UISpace(new Vector2i(1, 16)));
        List<String> controllers = inputSystem.getControllerDevice().getControllers();
        for (String name : controllers) {
            ControllerInfo cfg = inputDeviceConfiguration.getController(name);
            addInputSection(mainLayout, name, cfg);
        }
    }
    WidgetUtil.trySubscribe(this, "reset", button -> {
        inputDeviceConfiguration.reset();
        bindsManager.getBindsConfig().setBinds(bindsManager.getDefaultBindsConfig());
    });
    WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation());
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) UISlider(org.terasology.nui.widgets.UISlider) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) UICheckbox(org.terasology.nui.widgets.UICheckbox) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Name(org.terasology.gestalt.naming.Name) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) ColumnLayout(org.terasology.nui.layouts.ColumnLayout) UIButton(org.terasology.nui.widgets.UIButton) RowLayout(org.terasology.nui.layouts.RowLayout) InputCategory(org.terasology.input.InputCategory) UISpace(org.terasology.nui.widgets.UISpace) Vector2i(org.joml.Vector2i) FromModule(org.terasology.gestalt.module.predicates.FromModule) Module(org.terasology.gestalt.module.Module) FromModule(org.terasology.gestalt.module.predicates.FromModule) ControllerInfo(org.terasology.engine.config.ControllerConfig.ControllerInfo)

Example 20 with Vector2i

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

the class DocumentRenderer method renderParagraph.

public static int renderParagraph(Canvas canvas, ParagraphRenderable.HyperlinkRegister register, ParagraphRenderStyle baseRenderStyle, int xShift, int leftIndent, int rightIndent, ContainerRenderSpace containerRenderSpace, int containerWidth, int startY, ParagraphData paragraphData) {
    int yShift = startY;
    ParagraphRenderable paragraphContents = paragraphData.getParagraphContents();
    ParagraphRenderStyle paragraphRenderStyle = getParagraphRenderStyle(baseRenderStyle, paragraphData);
    ParagraphRenderStyle.ClearStyle clearStyle = paragraphRenderStyle.getClearStyle();
    if (clearStyle != ParagraphRenderStyle.ClearStyle.NONE) {
        yShift = Math.max(yShift, containerRenderSpace.getNextClearYPosition(clearStyle));
    }
    ParagraphRenderStyle.FloatStyle floatStyle = paragraphRenderStyle.getFloatStyle();
    if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT || floatStyle == ParagraphRenderStyle.FloatStyle.RIGHT) {
        int leftParagraphIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth);
        int rightParagraphIndent = paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
        int paragraphWidth = Math.max(paragraphRenderStyle.getParagraphMinimumWidth().getValue(containerWidth), paragraphContents.getContentsMinWidth(paragraphRenderStyle) + leftParagraphIndent + rightParagraphIndent);
        int height = paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
        int paragraphHeight = paragraphContents.getPreferredContentsHeight(paragraphRenderStyle, 0, new ContainerFlowContainerRenderSpace(paragraphWidth), leftParagraphIndent + rightParagraphIndent);
        height += paragraphHeight;
        height += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
        Rectanglei position;
        if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT) {
            position = containerRenderSpace.addLeftFloat(yShift, paragraphWidth, height);
        } else {
            position = containerRenderSpace.addRightFloat(yShift, paragraphWidth, height);
        }
        Rectanglei paragraphBorderRegion = new Rectanglei(position.minX + paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth), position.minY + paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth), position.maxX - paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) - 1, position.maxY - paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth) - 1);
        Color paragraphBackground = paragraphRenderStyle.getParagraphBackground();
        if (paragraphBackground != null) {
            canvas.drawFilledRectangle(paragraphBorderRegion, paragraphBackground);
        }
        Vector2i paragraphStart = new Vector2i(position.minX, position.minY + paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth));
        paragraphContents.renderContents(canvas, paragraphStart, new ContainerFlowContainerRenderSpace(paragraphWidth), leftParagraphIndent, rightParagraphIndent, paragraphRenderStyle, paragraphRenderStyle.getHorizontalAlignment(), register);
        yShift = position.minY;
    } else {
        yShift += paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth);
        int leftParagraphIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth);
        int rightParagraphIndent = paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
        int paragraphHeight = paragraphContents.getPreferredContentsHeight(paragraphRenderStyle, yShift + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth), containerRenderSpace, leftIndent + leftParagraphIndent + rightParagraphIndent + rightIndent);
        Color paragraphBackground = paragraphRenderStyle.getParagraphBackground();
        if (paragraphBackground != null) {
            int borderAdvance = 0;
            int borderHeight = paragraphHeight + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth);
            while (borderAdvance < borderHeight) {
                int backgroundStart = yShift + borderAdvance;
                int availableBackgroundWidth = containerRenderSpace.getWidthForVerticalPosition(backgroundStart);
                int backgroundAdvance = containerRenderSpace.getAdvanceForVerticalPosition(backgroundStart);
                int maxSpace = containerRenderSpace.getNextWidthChange(backgroundStart);
                Rectanglei backgroundRegion = RectUtility.createFromMinAndSize(xShift + paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + backgroundAdvance, backgroundStart, availableBackgroundWidth - 1, Math.min(maxSpace, borderHeight - borderAdvance) - 1);
                canvas.drawFilledRectangle(backgroundRegion, paragraphBackground);
                borderAdvance += maxSpace - backgroundStart;
            }
        }
        yShift += paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
        paragraphContents.renderContents(canvas, new Vector2i(xShift, yShift), containerRenderSpace, leftIndent + leftParagraphIndent, rightIndent + rightParagraphIndent, paragraphRenderStyle, paragraphRenderStyle.getHorizontalAlignment(), register);
        yShift += paragraphHeight;
        yShift += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth);
        yShift += paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
    }
    return yShift - startY;
}
Also used : Color(org.terasology.nui.Color) Rectanglei(org.terasology.joml.geom.Rectanglei) Vector2i(org.joml.Vector2i) FallbackParagraphRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.FallbackParagraphRenderStyle) ParagraphRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle)

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