Search in sources :

Example 1 with IGuiElement

use of buildcraft.lib.gui.IGuiElement in project BuildCraft by BuildCraft.

the class GuiElementContainerResizing method calculateSizes.

@Override
public void calculateSizes() {
    maxX = minX = maxY = minY = 0;
    double x0, x1, y0, y1;
    double x = childRoot.getX();
    double y = childRoot.getY();
    x0 = x1 = x;
    y0 = y1 = y;
    for (IGuiElement elem : getChildElements()) {
        x0 = Math.min(x0, elem.getX());
        y0 = Math.min(y0, elem.getY());
        x1 = Math.max(x1, elem.getEndX());
        y1 = Math.max(y1, elem.getEndY());
    }
    minX = x0 - x;
    maxX = x1 - x;
    minY = y0 - y;
    maxY = y1 - y;
}
Also used : IGuiElement(buildcraft.lib.gui.IGuiElement)

Example 2 with IGuiElement

use of buildcraft.lib.gui.IGuiElement in project BuildCraft by BuildCraft.

the class LedgerHelp method drawForeground.

@Override
public void drawForeground(float partialTicks) {
    super.drawForeground(partialTicks);
    if (!shouldDrawOpen()) {
        return;
    }
    boolean set = false;
    List<HelpPosition> elements = new ArrayList<>();
    for (IGuiElement element : gui.shownElements) {
        element.addHelpElements(elements);
        foundAny |= elements.size() > 0;
        for (HelpPosition info : elements) {
            IGuiArea rect = info.target;
            boolean isHovered = rect.contains(gui.mouse);
            if (isHovered) {
                if (selected != element && !set) {
                    selected = element;
                    GuiElementContainerHelp container = new GuiElementContainerHelp(gui, positionLedgerInnerStart);
                    info.info.addGuiElements(container);
                    if (openElements.size() == 2) {
                        openElements.remove(1);
                    }
                    openElements.add(container);
                    title = LocaleUtil.localize("gui.ledger.help") + ": " + LocaleUtil.localize(info.info.title);
                    calculateMaxSize();
                    set = true;
                }
            }
            boolean isSelected = selected == element;
            SpriteNineSliced split = SPRITE_HELP_SPLIT[isHovered ? 1 : 0][isSelected ? 1 : 0];
            RenderUtil.setGLColorFromInt(info.info.colour);
            split.draw(rect);
        }
        elements.clear();
    }
    GlStateManager.color(1, 1, 1);
}
Also used : HelpPosition(buildcraft.lib.gui.help.ElementHelpInfo.HelpPosition) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ArrayList(java.util.ArrayList) IGuiElement(buildcraft.lib.gui.IGuiElement) GuiElementContainerHelp(buildcraft.lib.gui.elem.GuiElementContainerHelp) SpriteNineSliced(buildcraft.lib.client.sprite.SpriteNineSliced)

Example 3 with IGuiElement

use of buildcraft.lib.gui.IGuiElement in project BuildCraft by BuildCraft.

the class Ledger_Neptune method onMouseClicked.

@Override
public void onMouseClicked(int button) {
    boolean childClicked = false;
    for (IGuiElement elem : openElements) {
        if (elem instanceof IInteractionElement) {
            ((IInteractionElement) elem).onMouseClicked(button);
            childClicked |= elem.contains(gui.mouse);
        }
    }
    for (IGuiElement elem : closedElements) {
        if (elem instanceof IInteractionElement) {
            ((IInteractionElement) elem).onMouseClicked(button);
            childClicked |= elem.contains(gui.mouse);
        }
    }
    if (!childClicked && contains(gui.mouse)) {
        boolean nowOpen = false;
        if (currentDifference == 1) {
            currentDifference = -1;
        } else {
            currentDifference = 1;
            nowOpen = true;
        }
        if (isOpenProperty != null) {
            isOpenProperty.set(nowOpen);
        }
    }
}
Also used : IInteractionElement(buildcraft.lib.gui.IInteractionElement) IGuiElement(buildcraft.lib.gui.IGuiElement)

Example 4 with IGuiElement

use of buildcraft.lib.gui.IGuiElement in project BuildCraft by BuildCraft.

the class GuiElementContainerHelp method recalcSize.

private void recalcSize() {
    calc = true;
    width = 0;
    height = 0;
    double w = 0;
    double h = 0;
    for (IGuiElement element : internalElements) {
        w = Math.max(w, element.getEndX());
        h = Math.max(h, element.getEndY());
    }
    width = w;
    height = h;
    calc = false;
}
Also used : IGuiElement(buildcraft.lib.gui.IGuiElement)

Example 5 with IGuiElement

use of buildcraft.lib.gui.IGuiElement in project BuildCraft by BuildCraft.

the class ElementType method deserialize.

public final IGuiElement deserialize(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    IGuiElement element = deserialize0(gui, parent, info, json);
    if (element instanceof GuiElementSimple) {
        ((GuiElementSimple) element).name = json.fullName;
    }
    gui.context.putConstant(json.fullName + ".pos", IGuiPosition.class, element);
    gui.context.putConstant(json.fullName + ".area", IGuiArea.class, element);
    gui.varData.addNodes(json.createTickableNodes());
    List<IGuiElement> children = new ArrayList<>();
    IContainingElement container;
    if (element instanceof IContainingElement) {
        container = (IContainingElement) element;
    } else {
        container = new GuiElementContainerResizing(gui, element);
        container.getChildElements().add(element);
    }
    addChildren(gui, container.getChildElementPosition(), info, json, "children", children::add);
    // Special case tooltips + help
    if (json.json.has("help") && !(this instanceof ElementTypeHelp)) {
        addType(gui, parent, info, json, "help", children::add, ElementTypeHelp.INSTANCE);
    }
    if (json.json.has("tooltip") && !(this instanceof ElementTypeToolTip)) {
        addType(gui, parent, info, json, "tooltip", children::add, ElementTypeToolTip.INSTANCE);
    }
    if (!children.isEmpty()) {
        element = container;
        container.getChildElements().addAll(children);
        container.calculateSizes();
    }
    return element;
}
Also used : IContainingElement(buildcraft.lib.gui.IContainingElement) GuiElementSimple(buildcraft.lib.gui.GuiElementSimple) ArrayList(java.util.ArrayList) IGuiElement(buildcraft.lib.gui.IGuiElement) GuiElementContainerResizing(buildcraft.lib.gui.elem.GuiElementContainerResizing)

Aggregations

IGuiElement (buildcraft.lib.gui.IGuiElement)14 IReference (buildcraft.lib.misc.data.IReference)3 ArrayList (java.util.ArrayList)3 ISprite (buildcraft.api.core.render.ISprite)2 SpriteNineSliced (buildcraft.lib.client.sprite.SpriteNineSliced)2 IContainingElement (buildcraft.lib.gui.IContainingElement)2 HelpPosition (buildcraft.lib.gui.help.ElementHelpInfo.HelpPosition)2 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)2 AutoGlScissor (buildcraft.lib.misc.GuiUtil.AutoGlScissor)2 EnumPipePart (buildcraft.api.core.EnumPipePart)1 IGuiSlot (buildcraft.api.statements.IGuiSlot)1 IStatementParameter (buildcraft.api.statements.IStatementParameter)1 WidgetListSlot (buildcraft.core.list.ContainerList.WidgetListSlot)1 ResourceLoaderContext (buildcraft.lib.client.model.ResourceLoaderContext)1 InvalidExpressionException (buildcraft.lib.expression.api.InvalidExpressionException)1 GuiElementSimple (buildcraft.lib.gui.GuiElementSimple)1 GuiIcon (buildcraft.lib.gui.GuiIcon)1 IInteractionElement (buildcraft.lib.gui.IInteractionElement)1 GuiImageButton (buildcraft.lib.gui.button.GuiImageButton)1 GuiElementContainerHelp (buildcraft.lib.gui.elem.GuiElementContainerHelp)1