Search in sources :

Example 1 with GuiElement

use of mekanism.client.gui.element.GuiElement in project Mekanism by mekanism.

the class GuiMinerFilterHelper method addMinerDefaults.

default void addMinerDefaults(IGuiWrapper gui, MinerFilter<?> filter, int slotOffset, UnaryOperator<GuiElement> childAdder) {
    childAdder.apply(new GuiSlot(SlotType.NORMAL, gui, getRelativeX() + 148, getRelativeY() + slotOffset).setRenderHover(true).stored(() -> new ItemStack(filter.replaceTarget)).setGhostHandler((IGhostBlockItemConsumer) ingredient -> {
        filter.replaceTarget = ((ItemStack) ingredient).getItem();
        Minecraft.getInstance().getSoundManager().play(SimpleSound.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
    }));
    childAdder.apply(new MekanismImageButton(gui, getRelativeX() + 148, getRelativeY() + 45, 14, 16, MekanismUtils.getResource(ResourceType.GUI_BUTTON, "exclamation.png"), () -> filter.requiresReplacement = !filter.requiresReplacement, (onHover, matrix, xAxis, yAxis) -> gui.displayTooltip(matrix, MekanismLang.MINER_REQUIRE_REPLACE.translate(YesNo.of(filter.requiresReplacement)), xAxis, yAxis)));
}
Also used : GuiFilter(mekanism.client.gui.element.window.filter.GuiFilter) SimpleSound(net.minecraft.client.audio.SimpleSound) GuiElement(mekanism.client.gui.element.GuiElement) SlotType(mekanism.client.gui.element.slot.SlotType) ResourceType(mekanism.common.util.MekanismUtils.ResourceType) UnaryOperator(java.util.function.UnaryOperator) MinerFilter(mekanism.common.content.miner.MinerFilter) TileEntityDigitalMiner(mekanism.common.tile.machine.TileEntityDigitalMiner) SoundEvents(net.minecraft.util.SoundEvents) MekanismUtils(mekanism.common.util.MekanismUtils) ItemStack(net.minecraft.item.ItemStack) MekanismImageButton(mekanism.client.gui.element.button.MekanismImageButton) Minecraft(net.minecraft.client.Minecraft) IGuiWrapper(mekanism.client.gui.IGuiWrapper) YesNo(mekanism.common.util.text.BooleanStateDisplay.YesNo) GuiFilterHelper(mekanism.client.gui.element.window.filter.GuiFilterHelper) MekanismLang(mekanism.common.MekanismLang) IGhostBlockItemConsumer(mekanism.client.jei.interfaces.IJEIGhostTarget.IGhostBlockItemConsumer) GuiSlot(mekanism.client.gui.element.slot.GuiSlot) GuiSlot(mekanism.client.gui.element.slot.GuiSlot) IGhostBlockItemConsumer(mekanism.client.jei.interfaces.IJEIGhostTarget.IGhostBlockItemConsumer) MekanismImageButton(mekanism.client.gui.element.button.MekanismImageButton) ItemStack(net.minecraft.item.ItemStack)

Example 2 with GuiElement

use of mekanism.client.gui.element.GuiElement in project Mekanism by mekanism.

the class GuiMekanism method incrementFocus.

@Override
public void incrementFocus(GuiElement current) {
    int index = focusListeners.indexOf(current);
    if (index != -1) {
        GuiElement next = focusListeners.get((index + 1) % focusListeners.size());
        next.setFocused(true);
        focusChange(next);
    }
}
Also used : GuiElement(mekanism.client.gui.element.GuiElement)

Example 3 with GuiElement

use of mekanism.client.gui.element.GuiElement in project Mekanism by mekanism.

the class GuiMekanism method renderLabels.

@Override
protected void renderLabels(@Nonnull MatrixStack matrix, int mouseX, int mouseY) {
    matrix.translate(0, 0, 300);
    RenderSystem.translatef(-leftPos, -topPos, 0);
    children().stream().filter(c -> c instanceof GuiElement).forEach(c -> ((GuiElement) c).onDrawBackground(matrix, mouseX, mouseY, MekanismRenderer.getPartialTick()));
    RenderSystem.translatef(leftPos, topPos, 0);
    drawForegroundText(matrix, mouseX, mouseY);
    int xAxis = mouseX - leftPos;
    int yAxis = mouseY - topPos;
    // first render general foregrounds
    maxZOffset = 200;
    int zOffset = 200;
    for (Widget widget : this.buttons) {
        if (widget instanceof GuiElement) {
            matrix.pushPose();
            ((GuiElement) widget).onRenderForeground(matrix, mouseX, mouseY, zOffset, zOffset);
            matrix.popPose();
        }
    }
    // now render overlays in reverse-order (i.e. back to front)
    zOffset = maxZOffset;
    for (LRU<GuiWindow>.LRUIterator iter = getWindowsDescendingIterator(); iter.hasNext(); ) {
        GuiWindow overlay = iter.next();
        zOffset += 150;
        matrix.pushPose();
        overlay.onRenderForeground(matrix, mouseX, mouseY, zOffset, zOffset);
        if (iter.hasNext()) {
            // if this isn't the focused window, render a 'blur' effect over it
            overlay.renderBlur(matrix);
        }
        matrix.popPose();
    }
    // then render tooltips, translating above max z offset to prevent clashing
    GuiElement tooltipElement = getWindowHovering(mouseX, mouseY);
    if (tooltipElement == null) {
        for (int i = buttons.size() - 1; i >= 0; i--) {
            Widget widget = buttons.get(i);
            if (widget instanceof GuiElement && widget.isMouseOver(mouseX, mouseY)) {
                tooltipElement = (GuiElement) widget;
                break;
            }
        }
    }
    // translate forwards using RenderSystem. this should never have to happen as we do all the necessary translations with MatrixStacks,
    // but Minecraft has decided to not fully adopt MatrixStacks for many crucial ContainerScreen render operations. should be re-evaluated
    // when mc updates related logic on their end (IMPORTANT)
    RenderSystem.translatef(0, 0, maxZOffset);
    if (tooltipElement != null) {
        tooltipElement.renderToolTip(matrix, xAxis, yAxis);
    }
    // render item tooltips
    RenderSystem.translatef(-leftPos, -topPos, 0);
    renderTooltip(matrix, mouseX, mouseY);
    RenderSystem.translatef(leftPos, topPos, 0);
    // IMPORTANT: additional hacky translation so held items render okay. re-evaluate as discussed above
    RenderSystem.translatef(0, 0, 200);
}
Also used : GuiElement(mekanism.client.gui.element.GuiElement) LRU(mekanism.common.lib.collection.LRU) ResourceType(mekanism.common.util.MekanismUtils.ResourceType) SelectedWindowData(mekanism.common.inventory.container.SelectedWindowData) BooleanSupplier(java.util.function.BooleanSupplier) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration) Pair(org.apache.commons.lang3.tuple.Pair) SlotOverlay(mekanism.common.inventory.container.slot.SlotOverlay) GuiWindow(mekanism.client.gui.element.window.GuiWindow) Collection(java.util.Collection) SlotType(mekanism.client.gui.element.slot.SlotType) MekanismUtils(mekanism.common.util.MekanismUtils) WarningTracker(mekanism.client.gui.warning.WarningTracker) List(java.util.List) IWarningTracker(mekanism.client.gui.warning.IWarningTracker) MekanismRenderer(mekanism.client.render.MekanismRenderer) Optional(java.util.Optional) MekanismContainer(mekanism.common.inventory.container.MekanismContainer) GuiSlot(mekanism.client.gui.element.slot.GuiSlot) GuiWarningTab(mekanism.client.gui.element.tab.GuiWarningTab) Container(net.minecraft.inventory.container.Container) IGuiEventListener(net.minecraft.client.gui.IGuiEventListener) IVirtualSlot(mekanism.common.inventory.container.slot.IVirtualSlot) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ITextComponent(net.minecraft.util.text.ITextComponent) WarningType(mekanism.client.gui.warning.WarningTracker.WarningType) ItemStack(net.minecraft.item.ItemStack) ItemRenderer(net.minecraft.client.renderer.ItemRenderer) Minecraft(net.minecraft.client.Minecraft) Slot(net.minecraft.inventory.container.Slot) ILangEntry(mekanism.api.text.ILangEntry) Nonnull(javax.annotation.Nonnull) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) Nullable(javax.annotation.Nullable) TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) Mekanism(mekanism.common.Mekanism) PlayerInventory(net.minecraft.entity.player.PlayerInventory) Widget(net.minecraft.client.gui.widget.Widget) DataType(mekanism.common.tile.component.config.DataType) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) IFancyFontRenderer(mekanism.client.render.IFancyFontRenderer) ContainerSlotType(mekanism.common.inventory.container.slot.ContainerSlotType) FontRenderer(net.minecraft.client.gui.FontRenderer) IHoverable(mekanism.client.gui.element.GuiElement.IHoverable) MekanismTileContainer(mekanism.common.inventory.container.tile.MekanismTileContainer) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ResourceLocation(net.minecraft.util.ResourceLocation) GuiVirtualSlot(mekanism.client.gui.element.slot.GuiVirtualSlot) Widget(net.minecraft.client.gui.widget.Widget) GuiWindow(mekanism.client.gui.element.window.GuiWindow) GuiElement(mekanism.client.gui.element.GuiElement) LRU(mekanism.common.lib.collection.LRU)

Example 4 with GuiElement

use of mekanism.client.gui.element.GuiElement in project Mekanism by mekanism.

the class GuiMekanism method init.

@Override
public void init(@Nonnull Minecraft minecraft, int width, int height) {
    // Mark that we are not switching to JEI if we start being initialized again
    switchingToJEI = false;
    // Note: We are forced to do the logic that normally would be inside the "resize" method
    // here in init, as when mods like JEI take over the screen to show recipes, and then
    // return the screen to the "state" it was beforehand it does not actually properly
    // transfer the state from the previous instance to the new instance. If we run the
    // code we normally would run for when things get resized, we then are able to
    // properly reinstate/transfer the states of the various elements
    List<Pair<Integer, GuiElement>> prevElements = new ArrayList<>();
    for (int i = 0; i < buttons.size(); i++) {
        Widget widget = buttons.get(i);
        if (widget instanceof GuiElement && ((GuiElement) widget).hasPersistentData()) {
            prevElements.add(Pair.of(i, (GuiElement) widget));
        }
    }
    // flush the focus listeners list unless it's an overlay
    focusListeners.removeIf(element -> !element.isOverlay);
    int prevLeft = leftPos, prevTop = topPos;
    super.init(minecraft, width, height);
    windows.forEach(window -> window.resize(prevLeft, prevTop, leftPos, topPos));
    prevElements.forEach(e -> {
        if (e.getLeft() < buttons.size()) {
            Widget widget = buttons.get(e.getLeft());
            // ensured by the class comparison, and the restrictions of what can go in prevElements
            if (widget.getClass() == e.getRight().getClass()) {
                ((GuiElement) widget).syncFrom(e.getRight());
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Widget(net.minecraft.client.gui.widget.Widget) GuiElement(mekanism.client.gui.element.GuiElement) Pair(org.apache.commons.lang3.tuple.Pair)

Example 5 with GuiElement

use of mekanism.client.gui.element.GuiElement in project Mekanism by mekanism.

the class GhostIngredientHandler method getTargets.

private <INGREDIENT> List<TargetInfo<INGREDIENT>> getTargets(List<? extends IGuiEventListener> children, INGREDIENT ingredient) {
    List<TargetInfo<INGREDIENT>> ghostTargets = new ArrayList<>();
    for (IGuiEventListener child : children) {
        if (child instanceof Widget) {
            Widget widget = (Widget) child;
            if (widget.visible) {
                if (widget instanceof GuiElement) {
                    // Start by adding any grandchild ghost targets we have as they are the "top" layer, and we want them
                    // to get checked/interacted with first
                    ghostTargets.addAll(getTargets(((GuiElement) widget).children(), ingredient));
                }
                // Then go ahead and check if our element is a ghost target and if it is, and it supports the ingredient add it
                if (widget instanceof IJEIGhostTarget) {
                    IJEIGhostTarget ghostTarget = (IJEIGhostTarget) widget;
                    IGhostIngredientConsumer ghostHandler = ghostTarget.getGhostHandler();
                    if (ghostHandler != null && ghostHandler.supportsIngredient(ingredient)) {
                        ghostTargets.add(new TargetInfo<>(ghostTarget, ghostHandler, widget.x, widget.y, widget.getWidth(), widget.getHeight()));
                    }
                }
            }
        }
    }
    return ghostTargets;
}
Also used : IGuiEventListener(net.minecraft.client.gui.IGuiEventListener) ArrayList(java.util.ArrayList) Widget(net.minecraft.client.gui.widget.Widget) IJEIGhostTarget(mekanism.client.jei.interfaces.IJEIGhostTarget) IGhostIngredientConsumer(mekanism.client.jei.interfaces.IJEIGhostTarget.IGhostIngredientConsumer) GuiElement(mekanism.client.gui.element.GuiElement)

Aggregations

GuiElement (mekanism.client.gui.element.GuiElement)7 Widget (net.minecraft.client.gui.widget.Widget)4 ArrayList (java.util.ArrayList)3 GuiSlot (mekanism.client.gui.element.slot.GuiSlot)3 SlotType (mekanism.client.gui.element.slot.SlotType)3 MekanismUtils (mekanism.common.util.MekanismUtils)3 ResourceType (mekanism.common.util.MekanismUtils.ResourceType)3 IGuiEventListener (net.minecraft.client.gui.IGuiEventListener)3 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)2 BooleanSupplier (java.util.function.BooleanSupplier)2 UnaryOperator (java.util.function.UnaryOperator)2 Nullable (javax.annotation.Nullable)2 IGuiWrapper (mekanism.client.gui.IGuiWrapper)2 MekanismImageButton (mekanism.client.gui.element.button.MekanismImageButton)2 GuiFilterHelper (mekanism.client.gui.element.window.filter.GuiFilterHelper)2 IFancyFontRenderer (mekanism.client.render.IFancyFontRenderer)2 MekanismLang (mekanism.common.MekanismLang)2 Minecraft (net.minecraft.client.Minecraft)2 ItemStack (net.minecraft.item.ItemStack)2 Pair (org.apache.commons.lang3.tuple.Pair)2