Search in sources :

Example 1 with GuiElementDrawable

use of buildcraft.lib.gui.elem.GuiElementDrawable in project BuildCraft by BuildCraft.

the class GuiEmzuliPipe_BC8 method addButton.

private void addButton(SlotIndex index, int x, int y) {
    Supplier<EnumDyeColor> getter = () -> container.behaviour.slotColours.get(index);
    Consumer<EnumDyeColor> setter = c -> container.paintWidgets.get(index).setColour(c);
    IGuiPosition elem = mainGui.rootElement.offset(x, y);
    GuiButtonDrawable button = new GuiButtonDrawable(mainGui, index.name(), elem, PAINT_BUTTON_BUILDER);
    button.registerListener((b, key) -> {
        final EnumDyeColor old = getter.get();
        EnumDyeColor nColour;
        switch(key) {
            case 0:
                {
                    nColour = ColourUtil.getNextOrNull(old);
                    break;
                }
            case 1:
                {
                    nColour = ColourUtil.getPrevOrNull(old);
                    break;
                }
            case 2:
                {
                    nColour = null;
                    break;
                }
            default:
                {
                    return;
                }
        }
        setter.accept(nColour);
    });
    mainGui.shownElements.add(button);
    // Button paintbrush
    IGuiArea area = new GuiRectangle(20, 20).offset(elem);
    ISimpleDrawable paintIcon = (px, py) -> {
        EnumDyeColor colour = getter.get();
        if (colour == null) {
            ICON_NO_PAINT.drawAt(px + 2, py + 2);
        } else {
            ISprite sprite = BCTransportSprites.ACTION_PIPE_COLOUR[colour.ordinal()];
            GuiIcon.drawAt(sprite, px + 2, py + 2, 16);
        }
    };
    mainGui.shownElements.add(new GuiElementDrawable(mainGui, area, paintIcon, false));
    ITooltipElement tooltips = list -> {
        EnumDyeColor colour = getter.get();
        String line;
        if (colour == null) {
            line = LocaleUtil.localize("gui.pipes.emzuli.nopaint");
        } else {
            line = LocaleUtil.localize("gui.pipes.emzuli.paint", ColourUtil.getTextFullTooltip(colour));
        }
        list.add(new ToolTip(line));
    };
    mainGui.shownElements.add(new GuiElementToolTip(mainGui, area, tooltips));
}
Also used : ITooltipElement(buildcraft.lib.gui.ITooltipElement) Supplier(java.util.function.Supplier) ISprite(buildcraft.api.core.render.ISprite) GuiIcon(buildcraft.lib.gui.GuiIcon) SlotIndex(buildcraft.transport.pipe.behaviour.PipeBehaviourEmzuli.SlotIndex) GuiBC8(buildcraft.lib.gui.GuiBC8) GuiElementDrawable(buildcraft.lib.gui.elem.GuiElementDrawable) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) BCLibSprites(buildcraft.lib.BCLibSprites) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GuiElementToolTip(buildcraft.lib.gui.GuiElementToolTip) BCTransportSprites(buildcraft.transport.BCTransportSprites) LocaleUtil(buildcraft.lib.misc.LocaleUtil) PipeBehaviourEmzuli(buildcraft.transport.pipe.behaviour.PipeBehaviourEmzuli) Consumer(java.util.function.Consumer) ToolTip(buildcraft.lib.gui.elem.ToolTip) EnumDyeColor(net.minecraft.item.EnumDyeColor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ResourceLocation(net.minecraft.util.ResourceLocation) ColourUtil(buildcraft.lib.misc.ColourUtil) ContainerEmzuliPipe_BC8(buildcraft.transport.container.ContainerEmzuliPipe_BC8) BCCoreSprites(buildcraft.core.BCCoreSprites) GuiButtonDrawable(buildcraft.lib.gui.button.GuiButtonDrawable) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition) GuiElementToolTip(buildcraft.lib.gui.GuiElementToolTip) ToolTip(buildcraft.lib.gui.elem.ToolTip) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) ITooltipElement(buildcraft.lib.gui.ITooltipElement) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) ISprite(buildcraft.api.core.render.ISprite) GuiButtonDrawable(buildcraft.lib.gui.button.GuiButtonDrawable) GuiElementDrawable(buildcraft.lib.gui.elem.GuiElementDrawable) EnumDyeColor(net.minecraft.item.EnumDyeColor) GuiElementToolTip(buildcraft.lib.gui.GuiElementToolTip) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Example 2 with GuiElementDrawable

use of buildcraft.lib.gui.elem.GuiElementDrawable in project BuildCraft by BuildCraft.

the class ElementTypeDrawnStack method deserialize0.

@Override
protected IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    IGuiPosition pos = resolvePosition(json, "pos", parent, ctx);
    INodeBoolean visible = getEquationBool(json, "visible", ctx, true);
    boolean foreground = resolveEquationBool(json, "foreground", ctx, false);
    Item item = JsonUtils.getItem(json.json, "id");
    int meta = resolveEquationInt(json, "meta", ctx);
    ItemStack stack = new ItemStack(item, 1, meta);
    ISimpleDrawable icon = new GuiStack(stack);
    IGuiArea area = IGuiArea.create(pos, 16, 16);
    return new GuiElementDrawable(gui, area, icon, foreground, visible);
}
Also used : Item(net.minecraft.item.Item) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GuiElementDrawable(buildcraft.lib.gui.elem.GuiElementDrawable) INodeBoolean(buildcraft.lib.expression.api.IExpressionNode.INodeBoolean) ItemStack(net.minecraft.item.ItemStack) GuiStack(buildcraft.lib.gui.GuiStack) FunctionContext(buildcraft.lib.expression.FunctionContext) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Example 3 with GuiElementDrawable

use of buildcraft.lib.gui.elem.GuiElementDrawable in project BuildCraft by BuildCraft.

the class ElementTypeSprite method deserialize0.

@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    inheritProperty(json, "pos[0]", "area[0]");
    inheritProperty(json, "pos[1]", "area[1]");
    inheritProperty(json, "size[0]", "area[2]");
    inheritProperty(json, "size[1]", "area[3]");
    inheritProperty(json, "source.pos[0]", "source.area[0]");
    inheritProperty(json, "source.pos[1]", "source.area[1]");
    inheritProperty(json, "source.size[0]", "source.area[2]");
    inheritProperty(json, "source.size[1]", "source.area[3]");
    inheritProperty(json, "area", "source.area");
    inheritProperty(json, "area[0]", "source.area[0]");
    inheritProperty(json, "area[1]", "source.area[1]");
    inheritProperty(json, "area[2]", "source.area[2]");
    inheritProperty(json, "area[3]", "source.area[3]");
    IGuiArea area = resolveArea(json, "area", parent, ctx);
    IGuiArea srcArea = resolveArea(json, "source.area", PositionAbsolute.ORIGIN, ctx);
    INodeBoolean visible = getEquationBool(json, "visible", ctx, true);
    boolean foreground = resolveEquationBool(json, "foreground", ctx, false);
    // TODO: Allow the source sprite to be changing as well!
    SrcTexture tex = resolveTexture(info, json, "source");
    String origin = tex.origin;
    int texSize = tex.texSize;
    if (// 
    !json.properties.containsKey("source.area[2]") && // 
    !json.properties.containsKey("source.area[3]") && !json.properties.containsKey("source.area")) {
        srcArea = new GuiRectangle(texSize, texSize);
    }
    ISprite sprite = gui.properties.get(origin, ISprite.class);
    if (sprite == null) {
        ResourceLocation loc = SpriteUtil.transformLocation(new ResourceLocation(origin));
        sprite = new SpriteRaw(loc, 0, 0, 1, 1);
    }
    if (srcArea instanceof GuiRectangle) {
        double u = srcArea.getX();
        double v = srcArea.getY();
        double uSize = srcArea.getWidth();
        double vSize = srcArea.getHeight();
        sprite = GuiUtil.subRelative(sprite, u, v, uSize, vSize, texSize);
    } else {
        final IGuiArea a = srcArea;
        INodeDouble u = () -> a.getX() / texSize;
        INodeDouble v = () -> a.getY() / texSize;
        INodeDouble uSize = () -> a.getEndX() / texSize;
        INodeDouble vSize = () -> a.getEndY() / texSize;
        sprite = new SubSpriteChanging(sprite, u, v, uSize, vSize);
    }
    ISimpleDrawable icon = new GuiSpriteScaled(sprite, area.offsetToOrigin());
    GuiElementDrawable element = new GuiElementDrawable(gui, area, icon, foreground, visible);
    return element;
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) ISprite(buildcraft.api.core.render.ISprite) GuiElementDrawable(buildcraft.lib.gui.elem.GuiElementDrawable) INodeBoolean(buildcraft.lib.expression.api.IExpressionNode.INodeBoolean) FunctionContext(buildcraft.lib.expression.FunctionContext) SubSpriteChanging(buildcraft.lib.client.sprite.SubSpriteChanging) INodeDouble(buildcraft.lib.expression.api.IExpressionNode.INodeDouble) ResourceLocation(net.minecraft.util.ResourceLocation) GuiSpriteScaled(buildcraft.lib.gui.GuiSpriteScaled) SpriteRaw(buildcraft.lib.client.sprite.SpriteRaw)

Aggregations

ISimpleDrawable (buildcraft.lib.gui.ISimpleDrawable)3 GuiElementDrawable (buildcraft.lib.gui.elem.GuiElementDrawable)3 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)3 ISprite (buildcraft.api.core.render.ISprite)2 FunctionContext (buildcraft.lib.expression.FunctionContext)2 INodeBoolean (buildcraft.lib.expression.api.IExpressionNode.INodeBoolean)2 GuiRectangle (buildcraft.lib.gui.pos.GuiRectangle)2 IGuiPosition (buildcraft.lib.gui.pos.IGuiPosition)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 BCCoreSprites (buildcraft.core.BCCoreSprites)1 BCLibSprites (buildcraft.lib.BCLibSprites)1 SpriteRaw (buildcraft.lib.client.sprite.SpriteRaw)1 SubSpriteChanging (buildcraft.lib.client.sprite.SubSpriteChanging)1 INodeDouble (buildcraft.lib.expression.api.IExpressionNode.INodeDouble)1 GuiBC8 (buildcraft.lib.gui.GuiBC8)1 GuiElementToolTip (buildcraft.lib.gui.GuiElementToolTip)1 GuiIcon (buildcraft.lib.gui.GuiIcon)1 GuiSpriteScaled (buildcraft.lib.gui.GuiSpriteScaled)1 GuiStack (buildcraft.lib.gui.GuiStack)1 ITooltipElement (buildcraft.lib.gui.ITooltipElement)1