Search in sources :

Example 1 with ComposedGuiElement

use of de.johni0702.minecraft.gui.element.ComposedGuiElement in project jGui by ReplayMod.

the class AbstractGuiContainer method draw.

@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
    super.draw(renderer, size, renderInfo);
    if (backgroundColor != null && renderInfo.getLayer() == 0) {
        renderer.drawRect(0, 0, size.getWidth(), size.getHeight(), backgroundColor);
    }
    for (final Map.Entry<GuiElement, Pair<ReadablePoint, ReadableDimension>> e : layedOutElements.entrySet()) {
        GuiElement element = e.getKey();
        boolean strict;
        if (element instanceof ComposedGuiElement) {
            if (((ComposedGuiElement) element).getMaxLayer() < renderInfo.layer) {
                continue;
            }
            strict = renderInfo.layer == 0;
        } else {
            if (element.getLayer() != renderInfo.layer) {
                continue;
            }
            strict = true;
        }
        final ReadablePoint ePosition = e.getValue().getLeft();
        final ReadableDimension eSize = e.getValue().getRight();
        try {
            OffsetGuiRenderer eRenderer = new OffsetGuiRenderer(renderer, ePosition, eSize, strict);
            eRenderer.startUsing();
            e.getKey().draw(eRenderer, eSize, renderInfo.offsetMouse(ePosition.getX(), ePosition.getY()).layer(renderInfo.getLayer() - e.getKey().getLayer()));
            eRenderer.stopUsing();
        } catch (Exception ex) {
            CrashReport crashReport = CrashReport.create(ex, "Rendering Gui");
            renderInfo.addTo(crashReport);
            CrashReportSection category = crashReport.addElement("Gui container details");
            MCVer.addDetail(category, "Container", this::toString);
            MCVer.addDetail(category, "Width", () -> "" + size.getWidth());
            MCVer.addDetail(category, "Height", () -> "" + size.getHeight());
            MCVer.addDetail(category, "Layout", layout::toString);
            category = crashReport.addElement("Gui element details");
            MCVer.addDetail(category, "Element", () -> e.getKey().toString());
            MCVer.addDetail(category, "Position", ePosition::toString);
            MCVer.addDetail(category, "Size", eSize::toString);
            if (e.getKey() instanceof GuiContainer) {
                MCVer.addDetail(category, "Layout", () -> ((GuiContainer) e.getKey()).getLayout().toString());
            }
            throw new CrashException(crashReport);
        }
    }
}
Also used : CrashException(net.minecraft.util.crash.CrashException) CrashReport(net.minecraft.util.crash.CrashReport) CrashReportSection(net.minecraft.util.crash.CrashReportSection) AbstractComposedGuiElement(de.johni0702.minecraft.gui.element.AbstractComposedGuiElement) ComposedGuiElement(de.johni0702.minecraft.gui.element.ComposedGuiElement) CrashException(net.minecraft.util.crash.CrashException) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) OffsetGuiRenderer(de.johni0702.minecraft.gui.OffsetGuiRenderer) AbstractComposedGuiElement(de.johni0702.minecraft.gui.element.AbstractComposedGuiElement) GuiElement(de.johni0702.minecraft.gui.element.GuiElement) ComposedGuiElement(de.johni0702.minecraft.gui.element.ComposedGuiElement) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with ComposedGuiElement

use of de.johni0702.minecraft.gui.element.ComposedGuiElement in project jGui by ReplayMod.

the class AbstractGuiContainer method layout.

@Override
public void layout(ReadableDimension size, RenderInfo renderInfo) {
    super.layout(size, renderInfo);
    if (size == null)
        return;
    try {
        layedOutElements = layout.layOut(this, size);
    } catch (Exception ex) {
        CrashReport crashReport = CrashReport.create(ex, "Gui Layout");
        renderInfo.addTo(crashReport);
        CrashReportSection category = crashReport.addElement("Gui container details");
        MCVer.addDetail(category, "Container", this::toString);
        MCVer.addDetail(category, "Layout", layout::toString);
        throw new CrashException(crashReport);
    }
    for (final Map.Entry<GuiElement, Pair<ReadablePoint, ReadableDimension>> e : layedOutElements.entrySet()) {
        GuiElement element = e.getKey();
        if (element instanceof ComposedGuiElement) {
            if (((ComposedGuiElement) element).getMaxLayer() < renderInfo.layer) {
                continue;
            }
        } else {
            if (element.getLayer() != renderInfo.layer) {
                continue;
            }
        }
        ReadablePoint ePosition = e.getValue().getLeft();
        ReadableDimension eSize = e.getValue().getRight();
        element.layout(eSize, renderInfo.offsetMouse(ePosition.getX(), ePosition.getY()).layer(renderInfo.getLayer() - element.getLayer()));
    }
}
Also used : CrashException(net.minecraft.util.crash.CrashException) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) CrashReport(net.minecraft.util.crash.CrashReport) CrashReportSection(net.minecraft.util.crash.CrashReportSection) AbstractComposedGuiElement(de.johni0702.minecraft.gui.element.AbstractComposedGuiElement) GuiElement(de.johni0702.minecraft.gui.element.GuiElement) ComposedGuiElement(de.johni0702.minecraft.gui.element.ComposedGuiElement) AbstractComposedGuiElement(de.johni0702.minecraft.gui.element.AbstractComposedGuiElement) ComposedGuiElement(de.johni0702.minecraft.gui.element.ComposedGuiElement) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) CrashException(net.minecraft.util.crash.CrashException) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

AbstractComposedGuiElement (de.johni0702.minecraft.gui.element.AbstractComposedGuiElement)2 ComposedGuiElement (de.johni0702.minecraft.gui.element.ComposedGuiElement)2 GuiElement (de.johni0702.minecraft.gui.element.GuiElement)2 ReadableDimension (de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension)2 ReadablePoint (de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)2 CrashException (net.minecraft.util.crash.CrashException)2 CrashReport (net.minecraft.util.crash.CrashReport)2 CrashReportSection (net.minecraft.util.crash.CrashReportSection)2 Pair (org.apache.commons.lang3.tuple.Pair)2 OffsetGuiRenderer (de.johni0702.minecraft.gui.OffsetGuiRenderer)1