Search in sources :

Example 36 with Point

use of binnie.core.gui.geometry.Point in project Binnie by ForestryMC.

the class WindowCompartment method initialiseClient.

// TODO: Clean Up, Localise
@Override
@SideOnly(Side.CLIENT)
public void initialiseClient() {
    IInventory inventory = this.getInventory();
    IMachine machine = Machine.getMachine(inventory);
    MachinePackage machinePackage = machine.getPackage();
    this.setTitle(machinePackage.getDisplayName());
    int x = 16;
    final int y = 32;
    final ComponentCompartmentInventory inv = machine.getInterface(ComponentCompartmentInventory.class);
    Integer[] tabs1 = new Integer[0];
    Integer[] tabs2 = new Integer[0];
    if (inv.getTabCount() == 4) {
        tabs1 = new Integer[] { 0, 1 };
        tabs2 = new Integer[] { 2, 3 };
    }
    if (inv.getTabCount() == 6) {
        tabs1 = new Integer[] { 0, 1, 2 };
        tabs2 = new Integer[] { 3, 4, 5 };
    }
    if (inv.getTabCount() == 8) {
        tabs1 = new Integer[] { 0, 1, 2, 3 };
        tabs2 = new Integer[] { 4, 5, 6, 7 };
    }
    final boolean doubleTabbed = tabs2.length > 0;
    final int compartmentPageWidth = 16 + 18 * inv.getPageSize() / 5;
    final int compartmentPageHeight = 106;
    final int compartmentWidth = compartmentPageWidth + (doubleTabbed ? 48 : 24);
    final int compartmentHeight = compartmentPageHeight;
    final Control controlCompartment = new Control(this, x, y, compartmentWidth, compartmentHeight);
    final ControlTabBar<Integer> tab = new ControlTabBar<>(controlCompartment, 0, 0, 24, compartmentPageHeight, Alignment.LEFT, Arrays.asList(tabs1), (x1, y1, w, h, value) -> {
        return new CompartmentTabIcon(this, x1, y1, w, h, value);
    });
    final String[] tabHelp = { "Compartment Tab", "Tabs that divide the inventory into sections. Each one can be labelled seperately." };
    tab.addHelp(tabHelp);
    tab.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, tab, event -> {
        if (event.getValue() == null) {
            return;
        }
        final NBTTagCompound nbt = new NBTTagCompound();
        final int i = (Integer) event.getValue();
        nbt.setByte("i", (byte) i);
        Window.get(tab).sendClientAction("tab-change", nbt);
        WindowCompartment.this.currentTab = i;
    });
    x += 24;
    final ControlPages<Integer> compartmentPages = new ControlPages<>(controlCompartment, 24, 0, compartmentPageWidth, compartmentPageHeight);
    final ControlPage[] page = new ControlPage[inv.getTabCount()];
    for (int p = 0; p < inv.getTabCount(); ++p) {
        page[p] = new ControlPage<>(compartmentPages, p);
    }
    CraftGUIUtil.linkWidgets(tab, compartmentPages);
    int i = 0;
    for (int p2 = 0; p2 < inv.getTabCount(); ++p2) {
        final ControlPage thisPage = page[p2];
        final Panel panel = new CompartmentCenterPanel(this, thisPage);
        this.panels.put(panel, p2);
        final int[] slotsIDs = new int[inv.getPageSize()];
        for (int k = 0; k < inv.getPageSize(); ++k) {
            slotsIDs[k] = i++;
        }
        new ControlSlotArray.Builder(thisPage, 8, 8, inv.getPageSize() / 5, 5).create(slotsIDs);
    }
    x += compartmentPageWidth;
    if (tabs2.length > 0) {
        final ControlTabBar<Integer> tab2 = new ControlTabBar<>(controlCompartment, 24 + compartmentPageWidth, 0, 24, compartmentPageHeight, Alignment.RIGHT, Arrays.asList(tabs2), (x1, y1, w, h, value) -> {
            return new CompartmentTabIcon(this, x1, y1, w, h, value);
        });
        tab2.setValue(tabs1[0]);
        tab2.addHelp(tabHelp);
        tab2.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, tab2, event -> {
            if (event.getValue() == null) {
                return;
            }
            final NBTTagCompound nbt = new NBTTagCompound();
            final int iVal = (Integer) event.getValue();
            nbt.setByte("i", (byte) iVal);
            Window.get(tab).sendClientAction("tab-change", nbt);
            WindowCompartment.this.currentTab = iVal;
        });
        CraftGUIUtil.linkWidgets(tab2, compartmentPages);
        x += 24;
    }
    x += 16;
    this.setSize(new Point(Math.max(32 + compartmentWidth, 252), this.getHeight()));
    controlCompartment.setPosition(new Point((this.getWidth() - controlCompartment.getWidth()) / 2, controlCompartment.getYPos()));
    final ControlPlayerInventory invent = new ControlPlayerInventory(this, true);
    final ControlSlide slide = new ControlSlide(this, 0, 134, 136, 92, Alignment.LEFT);
    slide.setLabel("Tab Properties");
    slide.setSlide(false);
    slide.addHelp("Tab Properties");
    slide.addHelp("The label, colour and icon of the Tab can be altered here. Clicking on the icon with a held item will change it.");
    final Panel tabPropertyPanel = new Panel(slide, 16, 8, 112, 76, MinecraftGUI.PanelType.GRAY);
    int y2 = 4;
    new ControlText(tabPropertyPanel, new Point(4, y2), "Tab Name:");
    final Panel parent = tabPropertyPanel;
    final int x2 = 4;
    y2 += 12;
    (this.tabName = new ControlTextEdit(parent, x2, y2, 104, 12)).addEventHandler(EventTextEdit.class, EventHandlerOrigin.SELF, this.tabName, event -> {
        final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab();
        currentTab.setName(event.getValue());
        final NBTTagCompound nbt = new NBTTagCompound();
        currentTab.writeToNBT(nbt);
        WindowCompartment.this.sendClientAction("comp-change-tab", nbt);
    });
    y2 += 20;
    new ControlText(tabPropertyPanel, new Point(4, y2), "Tab Icon: ");
    (this.tabIcon = new ControlItemDisplay(tabPropertyPanel, 58, y2 - 4)).setItemStack(new ItemStack(Items.PAPER));
    this.tabIcon.addAttribute(Attribute.MOUSE_OVER);
    this.tabIcon.addSelfEventHandler(EventMouse.Down.class, event -> {
        if (WindowCompartment.this.getHeldItemStack().isEmpty()) {
            return;
        }
        final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab();
        final ItemStack stack = WindowCompartment.this.getHeldItemStack().copy();
        stack.setCount(1);
        currentTab.setIcon(stack);
        final NBTTagCompound nbt = new NBTTagCompound();
        currentTab.writeToNBT(nbt);
        WindowCompartment.this.sendClientAction("comp-change-tab", nbt);
    });
    this.tabColour = new ControlColourSelector(tabPropertyPanel, 82, y2 - 4, 16, 16, EnumColor.WHITE);
    this.tabIcon.addHelp("Icon for Current Tab");
    this.tabIcon.addHelp("Click here with an item to change");
    y2 += 20;
    new ControlText(tabPropertyPanel, new Point(4, y2), "Colour: ");
    final int cw = 8;
    final Panel panelColour = new Panel(tabPropertyPanel, 40, y2 - 4, cw * 8 + 2, cw * 2 + 1, MinecraftGUI.PanelType.GRAY);
    for (int cc = 0; cc < 16; ++cc) {
        final ControlColourSelector color = new ControlColourSelector(panelColour, 1 + cw * (cc % 8), 1 + cw * (cc / 8), cw, cw, EnumColor.values()[cc]);
        color.addSelfEventHandler(EventMouse.Down.class, event -> {
            final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab();
            currentTab.setColor(color.getValue());
            final NBTTagCompound nbt = new NBTTagCompound();
            currentTab.writeToNBT(nbt);
            WindowCompartment.this.sendClientAction("comp-change-tab", nbt);
        });
        color.addHelp("Colour Selector");
        color.addHelp("Select a colour to highlight the current tab");
    }
    y2 += 20;
    final ControlButton searchButton = new SearchButton(this, controlCompartment, compartmentWidth, compartmentPageHeight);
    searchButton.addHelp("Search Button");
    searchButton.addHelp("Clicking this will open the Search dialog. This allows you to search the inventory for specific items.");
}
Also used : ControlItemDisplay(binnie.core.gui.minecraft.control.ControlItemDisplay) ControlSlotArray(binnie.core.gui.minecraft.control.ControlSlotArray) ControlPage(binnie.core.gui.controls.page.ControlPage) ControlTextEdit(binnie.core.gui.controls.ControlTextEdit) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Control(binnie.core.gui.controls.core.Control) ControlPlayerInventory(binnie.core.gui.minecraft.control.ControlPlayerInventory) ControlSlide(binnie.core.gui.minecraft.control.ControlSlide) IInventory(net.minecraft.inventory.IInventory) IMachine(binnie.core.machines.IMachine) ControlText(binnie.core.gui.controls.ControlText) Point(binnie.core.gui.geometry.Point) MachinePackage(binnie.core.machines.MachinePackage) Point(binnie.core.gui.geometry.Point) ControlTabBar(binnie.core.gui.controls.tab.ControlTabBar) ControlButton(binnie.core.gui.controls.button.ControlButton) Panel(binnie.core.gui.window.Panel) ControlPages(binnie.core.gui.controls.page.ControlPages) EventMouse(binnie.core.gui.events.EventMouse) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 37 with Point

use of binnie.core.gui.geometry.Point in project Binnie by ForestryMC.

the class ControlLiquidTank method onRenderBackground.

@Override
@SideOnly(Side.CLIENT)
public void onRenderBackground(int guiWidth, int guiHeight) {
    CraftGUI.RENDER.texture(this.horizontal ? CraftGUITexture.HORIZONTAL_LIQUID_TANK : CraftGUITexture.LIQUID_TANK, Point.ZERO);
    GuiCraftGUI gui = Window.get(this).getGui();
    if (this.isMouseOver() && gui.isHelpMode()) {
        final int c = -1442840576 + MinecraftTooltip.getOutline(Tooltip.Type.HELP);
        RenderUtil.drawGradientRect(this.getArea().inset(1), c, c);
    } else if (ControlLiquidTank.tankError.contains(this.tankID)) {
        final int c = -1442840576 + MinecraftTooltip.getOutline(MinecraftTooltip.Type.ERROR);
        RenderUtil.drawGradientRect(this.getArea().inset(1), c, c);
    } else if (this.getTopParent().getMousedOverWidget() == this) {
        if (!gui.getDraggedItem().isEmpty()) {
            RenderUtil.drawGradientRect(this.getArea().inset(1), -1426089575, -1426089575);
        } else {
            RenderUtil.drawGradientRect(this.getArea().inset(1), -2130706433, -2130706433);
        }
    }
    if (this.isTankValid()) {
        final int height = this.horizontal ? 16 : 58;
        final int squaled = Math.round(height * (this.getTank().getAmount() / this.getTank().getCapacity()));
        final int yPos = height + 1;
        final Fluid fluid = this.getTank().getLiquid().getFluid();
        final int hex = fluid.getColor(this.getTank().getLiquid());
        final int r = (hex & 0xFF0000) >> 16;
        final int g = (hex & 0xFF00) >> 8;
        final int b = hex & 0xFF;
        GlStateManager.color(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f);
        GlStateManager.enableBlend();
        {
            GlStateManager.blendFunc(770, 771);
            final IPoint pos = this.getAbsolutePosition();
            final IPoint offset = new Point(0, height - squaled);
            final IArea limited = this.getArea().inset(1);
            if (this.horizontal) {
                limited.setSize(new Point(limited.width() - 1, limited.height()));
            }
            CraftGUI.RENDER.limitArea(new Area(limited.pos().add(pos).add(offset), limited.size().sub(offset)), guiWidth, guiHeight);
            GL11.glEnable(GL11.GL_SCISSOR_TEST);
            {
                BinnieCore.getBinnieProxy().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
                for (int y = 0; y < height; y += 16) {
                    for (int x = 0; x < (this.horizontal ? 58 : 16); x += 16) {
                        final TextureAtlasSprite icon = BinnieCore.getBinnieProxy().getTextureAtlasSprite(fluid.getStill());
                        RenderUtil.drawSprite(new Point(1 + x, 1 + y), icon);
                    }
                }
            }
            GL11.glDisable(GL11.GL_SCISSOR_TEST);
        }
        GlStateManager.disableBlend();
        GlStateManager.color(1, 1, 1, 1);
    }
}
Also used : Area(binnie.core.gui.geometry.Area) IArea(binnie.core.api.gui.IArea) IArea(binnie.core.api.gui.IArea) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Fluid(net.minecraftforge.fluids.Fluid) GuiCraftGUI(binnie.core.gui.minecraft.GuiCraftGUI) IPoint(binnie.core.api.gui.IPoint) IPoint(binnie.core.api.gui.IPoint) Point(binnie.core.gui.geometry.Point) IPoint(binnie.core.api.gui.IPoint) Point(binnie.core.gui.geometry.Point) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 38 with Point

use of binnie.core.gui.geometry.Point in project Binnie by ForestryMC.

the class GuiCraftGUI method drawScreen.

@Override
public void drawScreen(final int mouseX, final int mouseY, final float partialTicks) {
    this.window.setMousePosition(mouseX - this.window.getPosition().xPos(), mouseY - this.window.getPosition().yPos());
    this.drawDefaultBackground();
    GlStateManager.disableRescaleNormal();
    RenderHelper.disableStandardItemLighting();
    GlStateManager.disableLighting();
    GlStateManager.disableDepth();
    this.zLevel = 10.0f;
    // GuiScreen.itemRender.zLevel = this.zLevel;
    this.window.render(this.width, this.height);
    GlStateManager.pushMatrix();
    GlStateManager.enableRescaleNormal();
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0f, 240.0f);
    final InventoryPlayer playerInventory = this.mc.player.inventory;
    this.draggedItem = playerInventory.getItemStack();
    if (!this.draggedItem.isEmpty()) {
        GlStateManager.translate(0, 0, 200);
        RenderUtil.drawItem(new Point(mouseX - 8, mouseY - 8), this.draggedItem, false);
    }
    RenderHelper.enableGUIStandardItemLighting();
    GlStateManager.disableRescaleNormal();
    GlStateManager.popMatrix();
    GlStateManager.disableLighting();
    GlStateManager.disableDepth();
    if (draggedItem.isEmpty()) {
        ITooltipFlag tooltipFlag = this.mc.gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL;
        final MinecraftTooltip tooltip = new MinecraftTooltip();
        boolean helpMode = this.isHelpMode();
        if (helpMode || this.showBasicHelpTooltips()) {
            tooltip.setType(Tooltip.Type.HELP);
            ITooltipFlag helpTooltipFlag = helpMode ? ITooltipFlag.TooltipFlags.ADVANCED : tooltipFlag;
            if (!this.window.getHelpTooltip(tooltip, helpTooltipFlag)) {
                // fallback if there is no help tooltip
                this.window.getTooltip(tooltip, tooltipFlag);
            }
        } else {
            tooltip.setType(Tooltip.Type.STANDARD);
            this.window.getTooltip(tooltip, tooltipFlag);
        }
        if (tooltip.exists()) {
            this.renderTooltip(new Point(mouseX, mouseY), tooltip);
        }
    }
    this.zLevel = 0.0f;
    GlStateManager.enableLighting();
    GlStateManager.enableDepth();
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ITooltipFlag(net.minecraft.client.util.ITooltipFlag) IPoint(binnie.core.api.gui.IPoint) Point(binnie.core.gui.geometry.Point)

Example 39 with Point

use of binnie.core.gui.geometry.Point in project Binnie by ForestryMC.

the class GuiCraftGUI method resize.

public void resize(final IPoint size) {
    this.xSize = size.xPos();
    this.ySize = size.yPos();
    this.guiLeft = (this.width - this.xSize) / 2;
    this.guiTop = (this.height - this.ySize) / 2;
    this.window.setPosition(new Point(this.guiLeft, this.guiTop));
}
Also used : IPoint(binnie.core.api.gui.IPoint) Point(binnie.core.gui.geometry.Point)

Example 40 with Point

use of binnie.core.gui.geometry.Point in project Binnie by ForestryMC.

the class GuiCraftGUI method renderTooltip.

public void renderTooltip(final Point mousePosition, final MinecraftTooltip tooltip) {
    final int mouseX = mousePosition.xPos();
    final int mouseY = mousePosition.yPos();
    final FontRenderer font = this.getFontRenderer();
    ItemStack itemStack = tooltip.getItemStack();
    boolean containsItemRender = false;
    List<String> textLines = new ArrayList<>();
    for (final String string : tooltip.getList()) {
        if (string != null) {
            if (!string.contains(Tooltip.NBT_SEPARATOR)) {
                textLines.addAll(font.listFormattedStringToWidth(string, tooltip.getMaxWidth()));
            } else {
                textLines.add(string);
                containsItemRender = true;
            }
        }
    }
    int tooltipTextWidth = 0;
    for (String textLine : textLines) {
        int textLineWidth = font.getStringWidth(textLine);
        if (textLine.contains(Tooltip.NBT_SEPARATOR)) {
            textLineWidth = 12 + font.getStringWidth(textLine.replaceAll(Tooltip.NBT_SEPARATOR + "(.*?)" + Tooltip.NBT_SEPARATOR, ""));
        }
        if (textLineWidth > tooltipTextWidth) {
            tooltipTextWidth = textLineWidth;
        }
    }
    if (!containsItemRender) {
        GuiUtils.drawHoveringText(itemStack, textLines, mouseX, mouseY, width, height, tooltip.getMaxWidth(), font);
    } else {
        drawHoveringText(itemStack, textLines, mouseX, mouseY, font, tooltipTextWidth, tooltip);
    }
}
Also used : ArrayList(java.util.ArrayList) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) IPoint(binnie.core.api.gui.IPoint) Point(binnie.core.gui.geometry.Point)

Aggregations

Point (binnie.core.gui.geometry.Point)46 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)25 IPoint (binnie.core.api.gui.IPoint)15 Area (binnie.core.gui.geometry.Area)13 ControlText (binnie.core.gui.controls.ControlText)10 ItemStack (net.minecraft.item.ItemStack)10 ControlItemDisplay (binnie.core.gui.minecraft.control.ControlItemDisplay)6 IArea (binnie.core.api.gui.IArea)5 Map (java.util.Map)5 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)5 ControlTextEdit (binnie.core.gui.controls.ControlTextEdit)4 ControlScrollableContent (binnie.core.gui.controls.scroll.ControlScrollableContent)4 ControlTabBar (binnie.core.gui.controls.tab.ControlTabBar)4 EventWidget (binnie.core.gui.events.EventWidget)4 Panel (binnie.core.gui.window.Panel)4 ArrayList (java.util.ArrayList)4 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)3 IWidget (binnie.core.api.gui.IWidget)3 Control (binnie.core.gui.controls.core.Control)3 ControlPlayerInventory (binnie.core.gui.minecraft.control.ControlPlayerInventory)3