Search in sources :

Example 1 with GuiRectangle

use of buildcraft.lib.gui.pos.GuiRectangle in project BuildCraft by BuildCraft.

the class ElementTypeButton method deserialize0.

@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    // TODO: Find a sane way of making the position variable!
    inheritProperty(json, "area[0]", "pos[0]");
    inheritProperty(json, "area[1]", "pos[1]");
    inheritProperty(json, "area[2]", "size[0]");
    inheritProperty(json, "area[3]", "size[1]");
    inheritProperty(json, "size[0]", "modes.enabled[2]");
    inheritProperty(json, "size[1]", "modes.enabled[3]");
    inheritProperty(json, "sprite", "modes.enabled.sprite");
    inheritProperty(json, "texture", "modes.enabled.texture");
    inheritProperty(json, "size[0]", "modes.disabled[2]");
    inheritProperty(json, "size[1]", "modes.disabled[3]");
    inheritProperty(json, "sprite", "modes.disabled.sprite");
    inheritProperty(json, "texture", "modes.disabled.texture");
    inheritProperty(json, "size[0]", "modes.active[2]");
    inheritProperty(json, "size[1]", "modes.active[3]");
    inheritProperty(json, "sprite", "modes.active.sprite");
    inheritProperty(json, "texture", "modes.active.texture");
    inheritProperty(json, "size[0]", "modes.hovered[2]");
    inheritProperty(json, "size[1]", "modes.hovered[3]");
    inheritProperty(json, "sprite", "modes.hovered.sprite");
    inheritProperty(json, "texture", "modes.hovered.texture");
    inheritProperty(json, "size[0]", "modes.active_hovered[2]");
    inheritProperty(json, "size[1]", "modes.active_hovered[3]");
    inheritProperty(json, "sprite", "modes.active_hovered.sprite");
    inheritProperty(json, "texture", "modes.active_hovered.texture");
    int posX = resolveEquationInt(json, "pos[0]", ctx);
    int posY = resolveEquationInt(json, "pos[1]", ctx);
    int sizeX = resolveEquationInt(json, "size[0]", ctx);
    int sizeY = resolveEquationInt(json, "size[1]", ctx);
    String buttonId;
    if (json.properties.containsKey("button")) {
        buttonId = json.properties.get("button");
    } else {
        buttonId = resolveEquation(json, "button_expression", ctx);
    }
    ISimpleDrawable drEnabled = resolveDrawable(ctx, info, json, gui, sizeX, sizeY, "modes.enabled");
    GuiRectangle rect = new GuiRectangle(posX, posY, sizeX, sizeY);
    GuiButtonDrawable.Builder buttonBuilder = new GuiButtonDrawable.Builder(rect, drEnabled);
    buttonBuilder.active = resolveDrawable(ctx, info, json, gui, sizeX, sizeY, "modes.active");
    buttonBuilder.hovered = resolveDrawable(ctx, info, json, gui, sizeX, sizeY, "modes.hovered");
    buttonBuilder.activeHovered = resolveDrawable(ctx, info, json, gui, sizeX, sizeY, "modes.active_hovered");
    buttonBuilder.disabled = resolveDrawable(ctx, info, json, gui, sizeX, sizeY, "modes.disabled");
    buttonBuilder.disabledActive = resolveDrawable(ctx, info, json, gui, sizeX, sizeY, "modes.active_disabled");
    GuiButtonDrawable button = new GuiButtonDrawable(gui, json.name, parent, buttonBuilder);
    IButtonBehaviour behaviour = gui.properties.get(buttonId, IButtonBehaviour.class);
    if (behaviour != null) {
        button.setBehaviour(behaviour);
    }
    Boolean current = gui.properties.get(buttonId, Boolean.class);
    if (current != null) {
        button.setActive(current.booleanValue());
    }
    IButtonClickEventListener listener = gui.properties.get(buttonId, IButtonClickEventListener.class);
    if (listener == null) {
        BCLog.logger.warn("[lib.gui.json] Unknown button id '" + buttonId + "'");
    } else {
        button.registerListener(listener);
    }
    return button;
}
Also used : IButtonClickEventListener(buildcraft.lib.gui.button.IButtonClickEventListener) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) IButtonBehaviour(buildcraft.lib.gui.button.IButtonBehaviour) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) GuiButtonDrawable(buildcraft.lib.gui.button.GuiButtonDrawable) FunctionContext(buildcraft.lib.expression.FunctionContext)

Example 2 with GuiRectangle

use of buildcraft.lib.gui.pos.GuiRectangle in project BuildCraft by BuildCraft.

the class BuildCraftGui method onMouseClicked.

/**
 * @return True if the {@link #currentMenu} {@link IMenuElement#shouldFullyOverride() fully overrides} other mouse
 *         clicks, false otherwise.
 */
public boolean onMouseClicked(int mouseX, int mouseY, int mouseButton) {
    mouse.setMousePosition(mouseX, mouseY);
    if (isDebuggingShown.evaluate()) {
        GuiRectangle debugRect = new GuiRectangle(0, 0, 16, 16);
        if (debugRect.contains(mouse)) {
            isDebuggingEnabled.set(!isDebuggingEnabled.evaluate());
        }
    }
    IMenuElement m = currentMenu;
    if (m != null) {
        m.onMouseClicked(mouseButton);
        if (m.shouldFullyOverride()) {
            return true;
        }
    }
    for (IGuiElement element : shownElements) {
        if (element instanceof IInteractionElement) {
            ((IInteractionElement) element).onMouseClicked(mouseButton);
        }
    }
    return false;
}
Also used : GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle)

Example 3 with GuiRectangle

use of buildcraft.lib.gui.pos.GuiRectangle in project BuildCraft by BuildCraft.

the class GuiElementStatementVariant method create.

public static GuiElementStatementVariant create(BuildCraftGui gui, IGuiArea parent, IReference<? extends IGuiSlot> ref, IGuiSlot[] possible) {
    int count = Math.min(OFFSET_HOVER.length, possible.length);
    possible = possible.length == count ? possible : Arrays.copyOf(possible, count);
    IGuiArea[] posPossible = new IGuiArea[count];
    IGuiArea base = new GuiRectangle(18, 18).offset(parent);
    for (int i = 0; i < count; i++) {
        posPossible[i] = base.offset(OFFSET_HOVER[i][0] * 18, OFFSET_HOVER[i][1] * 18);
    }
    int sub = 18 * (count > 9 ? 2 : 1);
    int add = 18 * (count > 9 ? 3 : 1);
    int offset = -sub - 4;
    int size = 8 + add + 18 * 2;
    IGuiArea area = new GuiRectangle(offset, offset, size, size).offset(parent);
    return new GuiElementStatementVariant(gui, area, ref, possible, posPossible);
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle)

Example 4 with GuiRectangle

use of buildcraft.lib.gui.pos.GuiRectangle in project BuildCraft by BuildCraft.

the class GuidePartNote method renderIntoArea.

@Override
public PagePosition renderIntoArea(int x, int y, int width, int height, PagePosition current, int index) {
    current = current.guaranteeSpace(HEIGHT + 10, height);
    if (current.page == index) {
        timeSinceRender = 0;
        int _x = x + (width - WIDTH) / 2;
        int _y = y + current.pixel + 5;
        int _w = WIDTH;
        int _h = HEIGHT;
        float partialTicks = gui.getLastPartialTicks();
        if (partialTicks < 0)
            partialTicks = 0;
        if (partialTicks > 1)
            partialTicks = 1;
        int interpOpenStage = (int) ((openStage * partialTicks) + lastOpenStage * (1 - partialTicks));
        if (openStage == lastOpenStage) {
            interpOpenStage = openStage;
        }
        thisRect = new GuiRectangle(_x, _y - interpOpenStage, _w, _h + interpOpenStage);
        _x = x + (width - GuiGuide.NOTE_PAGE.width) / 2;
        _y = y + current.pixel + 5 - interpOpenStage;
        _w = GuiGuide.NOTE_PAGE.width;
        _h = HEIGHT + interpOpenStage - 5;
        try (AutoGlScissor scissor = GuiUtil.scissor(_x, _y, _w, _h)) {
            GuiGuide.NOTE_PAGE.drawAt(_x, _y);
        }
        _x += 8;
        _y += 4;
        _w -= 16;
        _h -= 4;
        try (AutoGlScissor scissor = GuiUtil.scissor(_x, _y, _w, _h)) {
            PagePosition innerPosition = new PagePosition(index, 4);
            for (GuidePart part : parts) {
                innerPosition = part.renderIntoArea(_x, _y, _w, 400, innerPosition, index);
            }
        }
    }
    return current.nextLine(HEIGHT, height);
}
Also used : AutoGlScissor(buildcraft.lib.misc.GuiUtil.AutoGlScissor) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle)

Example 5 with GuiRectangle

use of buildcraft.lib.gui.pos.GuiRectangle in project BuildCraft by BuildCraft.

the class GuideAssembly method renderIntoArea.

@Override
public PagePosition renderIntoArea(int x, int y, int width, int height, PagePosition current, int index) {
    if (current.pixel + PIXEL_HEIGHT > height) {
        current = current.newPage();
    }
    x += OFFSET.x;
    y += OFFSET.y + current.pixel;
    if (current.page == index) {
        INPUT_LIST.drawAt(x, y);
        // Render the item
        GlStateManager.enableRescaleNormal();
        RenderHelper.enableGUIStandardItemLighting();
        for (int i = 0; i < input.length; i++) {
            GuiRectangle rect = ITEM_POSITION[i];
            ItemStack stack = input[i].get();
            drawItemStack(stack, x + (int) rect.x, y + (int) rect.y);
        }
        drawItemStack(output.get(), x + (int) OUT_POSITION.x, y + (int) OUT_POSITION.y);
        if (MJ_POSITION.offset(x, y).contains(gui.mouse)) {
            gui.tooltip.add(LocaleUtil.localizeMj(mjCost.get()));
        }
        RenderHelper.disableStandardItemLighting();
        GlStateManager.disableRescaleNormal();
    }
    current = current.nextLine(PIXEL_HEIGHT, height);
    return current;
}
Also used : GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) ItemStack(net.minecraft.item.ItemStack) ChangingItemStack(buildcraft.lib.recipe.ChangingItemStack)

Aggregations

GuiRectangle (buildcraft.lib.gui.pos.GuiRectangle)23 ItemStack (net.minecraft.item.ItemStack)5 ISimpleDrawable (buildcraft.lib.gui.ISimpleDrawable)4 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)4 ChangingItemStack (buildcraft.lib.recipe.ChangingItemStack)4 GuiIcon (buildcraft.lib.gui.GuiIcon)3 ISprite (buildcraft.api.core.render.ISprite)2 IFontRenderer (buildcraft.lib.client.guide.font.IFontRenderer)2 FunctionContext (buildcraft.lib.expression.FunctionContext)2 GuiButtonDrawable (buildcraft.lib.gui.button.GuiButtonDrawable)2 GuiElementDrawable (buildcraft.lib.gui.elem.GuiElementDrawable)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 BCCoreSprites (buildcraft.core.BCCoreSprites)1 WidgetListSlot (buildcraft.core.list.ContainerList.WidgetListSlot)1 BCLibSprites (buildcraft.lib.BCLibSprites)1 FormatString (buildcraft.lib.client.guide.node.FormatString)1 Title (buildcraft.lib.client.guide.parts.contents.ContentsList.Title)1 SubHeader (buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader)1 PageLink (buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLink)1 SpriteRaw (buildcraft.lib.client.sprite.SpriteRaw)1