Search in sources :

Example 11 with GuiRectangle

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

the class GuideCrafting method handleMouseClick.

@Override
public PagePosition handleMouseClick(int x, int y, int width, int height, PagePosition current, int index, int mouseX, int mouseY) {
    if (current.pixel + PIXEL_HEIGHT > height) {
        current = current.newPage();
    }
    x += OFFSET.x;
    y += OFFSET.y + current.pixel;
    if (current.page == index) {
        for (int itemX = 0; itemX < input.length; itemX++) {
            for (int itemY = 0; itemY < input[itemX].length; itemY++) {
                GuiRectangle rect = ITEM_POSITION[itemX][itemY];
                ItemStack stack = input[itemX][itemY].get();
                testClickItemStack(stack, x + (int) rect.x, y + (int) rect.y);
            }
        }
        testClickItemStack(output.get(), x + (int) OUT_POSITION.x, y + (int) OUT_POSITION.y);
    }
    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)

Example 12 with GuiRectangle

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

the class GuidePart method renderLine.

/**
 * @param current The current location of the rendering. This will be different from start if this line needed to
 *            render over 2 (or more!) pages
 * @param line The line to render
 * @param x The x position the page rendering started from
 * @param y The y position the page rendering started from
 * @param width The width of rendering space available
 * @param height The height of rendering space available
 * @return The position for the next line to render at. Will automatically be the next page or line if necessary.
 */
protected PagePosition renderLine(PagePosition current, PageLine line, int x, int y, int width, int height, int pageRenderIndex) {
    wasHovered = false;
    wasIconHovered = false;
    // Firstly break off the last chunk if the total length is greater than the width allows
    int allowedWidth = width - INDENT_WIDTH * line.indent;
    if (allowedWidth <= 0) {
        throw new IllegalStateException("Was indented too far");
    }
    String toRender = line.text;
    ISimpleDrawable icon = line.startIcon;
    FormatString next = FormatString.split(line.text);
    int neededSpace = fontRenderer.getFontHeight(line.text);
    if (icon != null) {
        neededSpace = Math.max(16, neededSpace);
    }
    current = current.guaranteeSpace(neededSpace, height);
    int _x = x + INDENT_WIDTH * line.indent;
    if (icon != null && current.page == pageRenderIndex) {
        int iconX = _x - 18;
        int iconY = y + current.pixel - 5;
        GuiRectangle rect = new GuiRectangle(iconX, iconY, 16, 16);
        if (rect.contains(gui.mouse) && line.startIconHovered != null) {
            icon = line.startIconHovered;
        }
        icon.drawAt(iconX, iconY);
    }
    while (next != null) {
        FormatString[] strings = next.wrap(fontRenderer, allowedWidth);
        String text = strings[0].getFormatted();
        boolean render = current.page == pageRenderIndex;
        int _y = y + current.pixel;
        int _w = fontRenderer.getStringWidth(text);
        GuiRectangle rect = new GuiRectangle(_x, _y, _w, neededSpace);
        wasHovered |= rect.contains(gui.mouse);
        if (render) {
            if (wasHovered && line.link) {
                Gui.drawRect(_x - 2, _y - 2, _x + _w + 2, _y - 2 + neededSpace, 0xFFD3AD6C);
            }
            fontRenderer.drawString(text, _x, _y, 0);
        }
        next = strings.length == 1 ? null : strings[1];
        current = current.nextLine(fontRenderer.getFontHeight(text) + 3, height);
    }
    int additional = LINE_HEIGHT - fontRenderer.getFontHeight(toRender) - 3;
    current = current.nextLine(additional, height);
    return current;
}
Also used : ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) FormatString(buildcraft.lib.client.guide.node.FormatString) FormatString(buildcraft.lib.client.guide.node.FormatString)

Example 13 with GuiRectangle

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

the class GuiAssemblyTable method drawBackgroundLayer.

@Override
protected void drawBackgroundLayer(float partialTicks) {
    ICON_GUI.drawAt(mainGui.rootElement);
    long target = container.tile.getTarget();
    if (target != 0) {
        double v = (double) container.tile.power / target;
        ICON_PROGRESS.drawCutInside(new GuiRectangle(RECT_PROGRESS.x, (int) (RECT_PROGRESS.y + RECT_PROGRESS.height * Math.max(1 - v, 0)), RECT_PROGRESS.width, (int) Math.ceil(RECT_PROGRESS.height * Math.min(v, 1))).offset(mainGui.rootElement));
    }
    for (int i = 0; i < container.tile.recipesStates.size(); i++) {
        EnumAssemblyRecipeState state = new ArrayList<>(container.tile.recipesStates.values()).get(i);
        if (state == EnumAssemblyRecipeState.SAVED) {
            ICON_SAVED.drawAt(getArea(i));
        }
        if (state == EnumAssemblyRecipeState.SAVED_ENOUGH) {
            ICON_SAVED_ENOUGH.drawAt(getArea(i));
        }
        if (state == EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE) {
            ICON_SAVED_ENOUGH_ACTIVE.drawAt(getArea(i));
        }
    }
}
Also used : GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) EnumAssemblyRecipeState(buildcraft.silicon.EnumAssemblyRecipeState)

Example 14 with GuiRectangle

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

the class GuidePageContents method handleMouseClick.

@Override
public void handleMouseClick(int x, int y, int width, int height, int mouseX, int mouseY, int mouseButton, int index, boolean isEditing) {
    super.handleMouseClick(x, y, width, height, mouseX, mouseY, mouseButton, index, isEditing);
    if (index % 2 == 0) {
        int oX = x + ORDER_OFFSET_X;
        int oY = y + ORDER_OFFSET_Y;
        for (int i = 0; i < GuiGuide.ORDERS.length; i++) {
            GuiRectangle rect = new GuiRectangle(oX, oY, 14, 14);
            if (rect.contains(gui.mouse)) {
                gui.sortingOrderIndex = i;
                loadMainGui();
                gui.refreshChapters();
                contents.setFontRenderer(getFontRenderer());
                return;
            }
            oY += 14;
        }
        if (!searchText.mouseClicked(mouseX, mouseY, mouseButton) && !searchText.isFocused() && new GuiRectangle(x - 2, y - 34, 40, 34).contains(mouseX, mouseY)) {
            searchText.setFocused(true);
        }
        if (mouseButton == 1 && mouseX >= searchText.x && mouseX < searchText.x + searchText.width && mouseY >= searchText.y && mouseY < searchText.y + searchText.height) {
            searchText.setText("");
        }
    }
    if (mouseButton == 0) {
        if (index == 0) {
            IFontRenderer f = getFontRenderer();
            String text = XmlPageLoader.SHOW_LORE ? "Show Lore [x]" : "Show Lore [ ]";
            int fWidth = f.getStringWidth(text);
            GuiRectangle rect;
            rect = new GuiRectangle(x + (width - fWidth) / 2, y + height / 2 + 12, fWidth, f.getFontHeight(text));
            if (rect.contains(mouseX, mouseY)) {
                XmlPageLoader.SHOW_LORE = !XmlPageLoader.SHOW_LORE;
            }
            text = XmlPageLoader.SHOW_HINTS ? "Show Hints [x]" : "Show Hints [ ]";
            fWidth = f.getStringWidth(text);
            rect = new GuiRectangle(x + (width - fWidth) / 2, y + height / 2 + 26, fWidth, f.getFontHeight(text));
            if (rect.contains(mouseX, mouseY)) {
                XmlPageLoader.SHOW_HINTS = !XmlPageLoader.SHOW_HINTS;
            }
        }
    }
    if (new GuiRectangle(x, y, width, height).contains(mouseX, mouseY)) {
        PagePosition pos = new PagePosition(2, 0);
        search: for (Title title : contents.visibleTitles) {
            SubHeader firstHeader = title.visibleHeaders[0];
            PageLink firstPage = firstHeader.visiblePages[0];
            pos = pos.guaranteeSpace(32 + gui.getCurrentFont().getFontHeight(firstPage.text.text.text), height);
            pos = title.chapter.renderIntoArea(x, y, width, height, pos, -1);
            for (SubHeader header : title.visibleHeaders) {
                firstPage = header.visiblePages[0];
                pos = pos.guaranteeSpace(gui.getCurrentFont().getFontHeight(firstPage.text.text.text), height);
                pos = header.text.renderIntoArea(x, y, width, height, pos, -1);
                for (PageLink page : header.visiblePages) {
                    pos = page.text.renderIntoArea(x, y, width, height, pos, -1);
                    if (pos.page == index && page.text.wasHovered()) {
                        page.onClicked();
                        break search;
                    }
                }
            }
        }
    }
}
Also used : GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) SubHeader(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader) PageLink(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLink) Title(buildcraft.lib.client.guide.parts.contents.ContentsList.Title) IFontRenderer(buildcraft.lib.client.guide.font.IFontRenderer)

Example 15 with GuiRectangle

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

the class GuideCrafting 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) {
        CRAFTING_GRID.drawAt(x, y);
        // Render the item
        GlStateManager.enableRescaleNormal();
        RenderHelper.enableGUIStandardItemLighting();
        for (int itemX = 0; itemX < input.length; itemX++) {
            for (int itemY = 0; itemY < input[itemX].length; itemY++) {
                GuiRectangle rect = ITEM_POSITION[itemX][itemY];
                ItemStack stack = input[itemX][itemY].get();
                drawItemStack(stack, x + (int) rect.x, y + (int) rect.y);
            }
        }
        drawItemStack(output.get(), x + (int) OUT_POSITION.x, y + (int) OUT_POSITION.y);
        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