Search in sources :

Example 1 with GuiWindow

use of mekanism.client.gui.element.window.GuiWindow in project Mekanism by mekanism.

the class GuiElementHandler method getGuiClickableAreas.

@Override
public Collection<IGuiClickableArea> getGuiClickableAreas(GuiMekanism<?> gui, double mouseX, double mouseY) {
    // Make mouseX and mouseY not be relative
    mouseX += gui.getGuiLeft();
    mouseY += gui.getGuiTop();
    GuiWindow guiWindow = gui.getWindowHovering(mouseX, mouseY);
    if (guiWindow == null) {
        // If no window is being hovered, then check the elements in general
        return getGuiClickableArea(gui.children(), mouseX, mouseY);
    }
    // Otherwise, check the elements of the window
    return getGuiClickableArea(guiWindow.children(), mouseX, mouseY);
}
Also used : GuiWindow(mekanism.client.gui.element.window.GuiWindow)

Example 2 with GuiWindow

use of mekanism.client.gui.element.window.GuiWindow in project Mekanism by mekanism.

the class GuiQIOItemViewer method transferWindows.

protected void transferWindows(Collection<GuiWindow> windows) {
    for (GuiWindow window : windows) {
        // Transition all current popup windows over to the new screen.
        if (window instanceof GuiCraftingWindow) {
            // Updating the references for listeners and the like for crafting windows
            craftingWindowTab.adoptWindows(window);
            // Update the container the virtual slots point to be correct
            ((GuiCraftingWindow) window).updateContainer(menu);
        }
        addWindow(window);
        window.transferToNewGui(this);
    }
}
Also used : GuiWindow(mekanism.client.gui.element.window.GuiWindow) GuiCraftingWindow(mekanism.client.gui.element.window.GuiCraftingWindow)

Example 3 with GuiWindow

use of mekanism.client.gui.element.window.GuiWindow in project Mekanism by mekanism.

the class GuiMekanism method removeWindow.

@Override
public void removeWindow(GuiWindow window) {
    if (!windows.isEmpty()) {
        GuiWindow top = windows.iterator().next();
        windows.remove(window);
        if (window == top) {
            // If the window was the top window, make it lose focus
            window.onFocusLost();
            // Amd check if a new window is now in focus
            GuiWindow newTop = windows.isEmpty() ? null : windows.iterator().next();
            if (newTop == null) {
                // If there isn't any because they have all been removed
                // fire an "event" for any post all windows being closed
                lastWindowRemoved();
            } else {
                // Otherwise, mark the new window as being focused
                newTop.onFocused();
            }
            // Update the listener to being the window that is now selected or null if none are
            setFocused(newTop);
        }
    }
}
Also used : GuiWindow(mekanism.client.gui.element.window.GuiWindow)

Example 4 with GuiWindow

use of mekanism.client.gui.element.window.GuiWindow in project Mekanism by mekanism.

the class GuiMekanism method addWindow.

@Override
public void addWindow(GuiWindow window) {
    GuiWindow top = windows.isEmpty() ? null : windows.iterator().next();
    if (top != null) {
        top.onFocusLost();
    }
    windows.add(window);
    window.onFocused();
}
Also used : GuiWindow(mekanism.client.gui.element.window.GuiWindow)

Example 5 with GuiWindow

use of mekanism.client.gui.element.window.GuiWindow in project Mekanism by mekanism.

the class GuiMekanism method mouseClicked.

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
    hasClicked = true;
    // first try to send the mouse event to our overlays
    GuiWindow top = windows.isEmpty() ? null : windows.iterator().next();
    GuiWindow focused = windows.stream().filter(overlay -> overlay.mouseClicked(mouseX, mouseY, button)).findFirst().orElse(null);
    if (focused != null) {
        if (windows.contains(focused)) {
            // Validate that the focused window is still one of our windows, as if it wasn't focused/on top, and
            // it is being closed, we don't want to update and mark it as focused, as our defocusing code won't
            // run as we ran it when we pressed the button
            setFocused(focused);
            if (button == 0) {
                setDragging(true);
            }
            // this check prevents us from moving the window to the top of the stack if the clicked window opened up an additional window
            if (top != focused) {
                top.onFocusLost();
                windows.moveUp(focused);
                focused.onFocused();
            }
        }
        return true;
    }
    // otherwise, we send it to the current element
    for (int i = buttons.size() - 1; i >= 0; i--) {
        IGuiEventListener listener = buttons.get(i);
        if (listener.mouseClicked(mouseX, mouseY, button)) {
            setFocused(listener);
            if (button == 0) {
                setDragging(true);
            }
            return true;
        }
    }
    return super.mouseClicked(mouseX, mouseY, button);
}
Also used : IGuiEventListener(net.minecraft.client.gui.IGuiEventListener) GuiWindow(mekanism.client.gui.element.window.GuiWindow)

Aggregations

GuiWindow (mekanism.client.gui.element.window.GuiWindow)10 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Nullable (javax.annotation.Nullable)3 GuiSlot (mekanism.client.gui.element.slot.GuiSlot)3 GuiVirtualSlot (mekanism.client.gui.element.slot.GuiVirtualSlot)3 IVirtualSlot (mekanism.common.inventory.container.slot.IVirtualSlot)3 InventoryContainerSlot (mekanism.common.inventory.container.slot.InventoryContainerSlot)3 LRU (mekanism.common.lib.collection.LRU)3 Slot (net.minecraft.inventory.container.Slot)3 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)2 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)2 Collection (java.util.Collection)2 Optional (java.util.Optional)2 BooleanSupplier (java.util.function.BooleanSupplier)2 Supplier (java.util.function.Supplier)2 Nonnull (javax.annotation.Nonnull)2 ILangEntry (mekanism.api.text.ILangEntry)2 GuiElement (mekanism.client.gui.element.GuiElement)2 IHoverable (mekanism.client.gui.element.GuiElement.IHoverable)2