Search in sources :

Example 6 with IGuiPosition

use of buildcraft.lib.gui.pos.IGuiPosition 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 7 with IGuiPosition

use of buildcraft.lib.gui.pos.IGuiPosition 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 8 with IGuiPosition

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

the class GuiUtil method moveRectangleToCentre.

public static IGuiArea moveRectangleToCentre(GuiRectangle area) {
    final double w = area.width;
    final double h = area.height;
    DoubleSupplier posX = () -> (AREA_WHOLE_SCREEN.getWidth() - w) / 2;
    DoubleSupplier posY = () -> (AREA_WHOLE_SCREEN.getHeight() - h) / 2;
    IGuiPosition position = IGuiPosition.create(posX, posY);
    return IGuiArea.create(position, area.width, area.height);
}
Also used : DoubleSupplier(java.util.function.DoubleSupplier) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Example 9 with IGuiPosition

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

the class ElementTypeText method deserialize0.

// pos: the position of the text
// text: The text to be drawn. Will be localised first, and used as a fallback
// expression: A replacement for text -- uses an expression rather than as a literal.
// colour: Default colour to be drawn
// centered: If true then the text will be centered around pos
@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    IGuiPosition pos = resolvePosition(json, "pos", parent, ctx);
    INodeObject<String> text;
    String prop;
    if ((prop = json.properties.get("text")) != null) {
        String localized = LocaleUtil.localize(prop);
        text = new NodeConstantObject<>(String.class, localized);
    } else if ((prop = json.properties.get("expression")) != null) {
        try {
            text = GenericExpressionCompiler.compileExpressionString(prop, ctx);
        } catch (InvalidExpressionException e) {
            throw new JsonSyntaxException("Invalid expression for '" + json.name + "'", e);
        }
    } else {
        throw new JsonSyntaxException("Require either 'text' or 'expression'!");
    }
    int colour;
    if (json.properties.containsKey("colour")) {
        colour = resolveEquationInt(json, "colour", ctx);
    } else {
        colour = resolveEquationInt(json, "color", ctx);
    }
    GuiElementText element = new GuiElementText(gui, pos, text, colour);
    element.setCentered("true".equals(json.properties.get("centered")));
    element.setDropShadow("true".equals(json.properties.get("shadow")));
    element.setForeground("true".equals(json.properties.get("foreground")));
    return element;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) InvalidExpressionException(buildcraft.lib.expression.api.InvalidExpressionException) GuiElementText(buildcraft.lib.gui.elem.GuiElementText) FunctionContext(buildcraft.lib.expression.FunctionContext) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Aggregations

IGuiPosition (buildcraft.lib.gui.pos.IGuiPosition)9 FunctionContext (buildcraft.lib.expression.FunctionContext)4 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 INodeBoolean (buildcraft.lib.expression.api.IExpressionNode.INodeBoolean)2 InvalidExpressionException (buildcraft.lib.expression.api.InvalidExpressionException)2 ISimpleDrawable (buildcraft.lib.gui.ISimpleDrawable)2 GuiElementDrawable (buildcraft.lib.gui.elem.GuiElementDrawable)2 GuiElementText (buildcraft.lib.gui.elem.GuiElementText)2 DoubleSupplier (java.util.function.DoubleSupplier)2 ISprite (buildcraft.api.core.render.ISprite)1 BCCoreSprites (buildcraft.core.BCCoreSprites)1 BCLibSprites (buildcraft.lib.BCLibSprites)1 SpriteNineSliced (buildcraft.lib.client.sprite.SpriteNineSliced)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 GuiStack (buildcraft.lib.gui.GuiStack)1 IGuiElement (buildcraft.lib.gui.IGuiElement)1