Search in sources :

Example 1 with GuiButtonDrawable

use of buildcraft.lib.gui.button.GuiButtonDrawable 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 GuiButtonDrawable

use of buildcraft.lib.gui.button.GuiButtonDrawable 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)

Aggregations

ISimpleDrawable (buildcraft.lib.gui.ISimpleDrawable)2 GuiButtonDrawable (buildcraft.lib.gui.button.GuiButtonDrawable)2 GuiRectangle (buildcraft.lib.gui.pos.GuiRectangle)2 ISprite (buildcraft.api.core.render.ISprite)1 BCCoreSprites (buildcraft.core.BCCoreSprites)1 BCLibSprites (buildcraft.lib.BCLibSprites)1 FunctionContext (buildcraft.lib.expression.FunctionContext)1 GuiBC8 (buildcraft.lib.gui.GuiBC8)1 GuiElementToolTip (buildcraft.lib.gui.GuiElementToolTip)1 GuiIcon (buildcraft.lib.gui.GuiIcon)1 ITooltipElement (buildcraft.lib.gui.ITooltipElement)1 IButtonBehaviour (buildcraft.lib.gui.button.IButtonBehaviour)1 IButtonClickEventListener (buildcraft.lib.gui.button.IButtonClickEventListener)1 GuiElementDrawable (buildcraft.lib.gui.elem.GuiElementDrawable)1 ToolTip (buildcraft.lib.gui.elem.ToolTip)1 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)1 IGuiPosition (buildcraft.lib.gui.pos.IGuiPosition)1 ColourUtil (buildcraft.lib.misc.ColourUtil)1 LocaleUtil (buildcraft.lib.misc.LocaleUtil)1 BCTransportSprites (buildcraft.transport.BCTransportSprites)1