Search in sources :

Example 1 with IButtonClickEventListener

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

use of buildcraft.lib.gui.button.IButtonClickEventListener in project BuildCraft by BuildCraft.

the class GuiFillerPlanner method preLoad.

protected void preLoad(BuildCraftJsonGui json) {
    TypedKeyMap<String, Object> properties = json.properties;
    FunctionContext context = json.context;
    properties.put("filler.possible", FillerStatementContext.CONTEXT_ALL);
    properties.put("filler.pattern", container.getPatternStatementClient());
    properties.put("filler.pattern.sprite", SPRITE_PATTERN);
    context.put_b("filler.invert", () -> container.addon.inverted);
    properties.put("filler.invert", IButtonBehaviour.TOGGLE);
    properties.put("filler.invert", container.addon.inverted);
    properties.put("filler.invert", (IButtonClickEventListener) (b, k) -> container.sendInverted(b.isButtonActive()));
}
Also used : ContainerFillerPlanner(buildcraft.builders.container.ContainerFillerPlanner) GuiBC8(buildcraft.lib.gui.GuiBC8) SpriteDelegate(buildcraft.lib.gui.json.SpriteDelegate) ResourceLocation(net.minecraft.util.ResourceLocation) IButtonClickEventListener(buildcraft.lib.gui.button.IButtonClickEventListener) BuildCraftJsonGui(buildcraft.lib.gui.json.BuildCraftJsonGui) FunctionContext(buildcraft.lib.expression.FunctionContext) FillerStatementContext(buildcraft.builders.filler.FillerStatementContext) IButtonBehaviour(buildcraft.lib.gui.button.IButtonBehaviour) TypedKeyMap(buildcraft.lib.misc.collect.TypedKeyMap) FunctionContext(buildcraft.lib.expression.FunctionContext)

Example 3 with IButtonClickEventListener

use of buildcraft.lib.gui.button.IButtonClickEventListener in project BuildCraft by BuildCraft.

the class GuiFiller method preLoad.

protected void preLoad(BuildCraftJsonGui json) {
    TypedKeyMap<String, Object> properties = json.properties;
    FunctionContext context = json.context;
    properties.put("filler.inventory", new InventorySlotHolder(container, container.tile.invResources));
    properties.put("statement.container", container.tile);
    properties.put("controllable", container.tile);
    properties.put("controllable.sprite", SPRITE_CONTROL_MODE);
    context.put_o("controllable.mode", Mode.class, container.tile::getControlMode);
    context.put_b("filler.is_finished", container.tile::isFinished);
    context.put_b("filler.is_locked", container.tile::isLocked);
    context.put_l("filler.to_break", container.tile::getCountToBreak);
    context.put_l("filler.to_place", container.tile::getCountToPlace);
    properties.put("filler.possible", FillerStatementContext.CONTEXT_ALL);
    properties.put("filler.pattern", container.getPatternStatementClient());
    properties.put("filler.pattern.sprite", SPRITE_PATTERN);
    context.put_b("filler.invert", container::isInverted);
    properties.put("filler.invert", IButtonBehaviour.TOGGLE);
    properties.put("filler.invert", container.isInverted());
    properties.put("filler.invert", (IButtonClickEventListener) (b, k) -> container.sendInverted(b.isButtonActive()));
    context.put_b("filler.excavate", container.tile::canExcavate);
    properties.put("filler.excavate", IButtonBehaviour.TOGGLE);
    properties.put("filler.excavate", container.tile.canExcavate());
    properties.put("filler.excavate", (IButtonClickEventListener) (b, k) -> container.tile.sendCanExcavate(b.isButtonActive()));
}
Also used : Mode(buildcraft.api.tiles.IControllable.Mode) InventorySlotHolder(buildcraft.lib.gui.json.InventorySlotHolder) SpriteDelegate(buildcraft.lib.gui.json.SpriteDelegate) IFillerPattern(buildcraft.api.filler.IFillerPattern) FunctionContext(buildcraft.lib.expression.FunctionContext) FillerStatementContext(buildcraft.builders.filler.FillerStatementContext) IButtonBehaviour(buildcraft.lib.gui.button.IButtonBehaviour) GuiBC8(buildcraft.lib.gui.GuiBC8) ResourceLocation(net.minecraft.util.ResourceLocation) IButtonClickEventListener(buildcraft.lib.gui.button.IButtonClickEventListener) BuildCraftJsonGui(buildcraft.lib.gui.json.BuildCraftJsonGui) BCCoreSprites(buildcraft.core.BCCoreSprites) ContainerFiller(buildcraft.builders.container.ContainerFiller) TypedKeyMap(buildcraft.lib.misc.collect.TypedKeyMap) FunctionContext(buildcraft.lib.expression.FunctionContext) InventorySlotHolder(buildcraft.lib.gui.json.InventorySlotHolder)

Example 4 with IButtonClickEventListener

use of buildcraft.lib.gui.button.IButtonClickEventListener in project BuildCraft by BuildCraft.

the class GuiGate method preLoad.

protected void preLoad(BuildCraftJsonGui json) {
    GateLogic gate = container.gate;
    TypedKeyMap<String, Object> properties = json.properties;
    FunctionContext context = json.context;
    properties.put("statement.container", gate);
    context.putConstantBoolean("gate.two_columns", gate.isSplitInTwo());
    context.putConstantLong("gate.slots", gate.variant.numSlots);
    context.putConstantLong("gate.triggers.args", gate.variant.numTriggerArgs);
    context.putConstantLong("gate.actions.args", gate.variant.numActionArgs);
    context.put_b("gate.two_columns", () -> gate.isOn);
    context.putConstant("gate.material", String.class, gate.variant.material.tag);
    context.putConstant("gate.modifier", String.class, gate.variant.modifier.tag);
    context.putConstant("gate.logic", String.class, gate.variant.logic.tag);
    context.putConstant("gate.variant", String.class, gate.variant.getLocalizedName());
    properties.put("gate.triggers.possible", container.possibleTriggersContext);
    properties.put("gate.actions.possible", container.possibleActionsContext);
    context.put_l_b("gate.is_connected", (i) -> {
        if (i < 0 || i >= gate.connections.length) {
            return false;
        }
        return gate.connections[(int) i];
    }).setNeverInline();
    context.put_l_b("gate.trigger.is_on", (i) -> {
        if (i < 0 || i >= gate.triggerOn.length) {
            return false;
        }
        return gate.triggerOn[(int) i];
    }).setNeverInline();
    context.put_l_b("gate.set.is_on", (i) -> {
        if (i < 0 || i >= gate.triggerOn.length) {
            return false;
        }
        return gate.actionOn[(int) i];
    }).setNeverInline();
    context.put_l_b("gate.action.is_on", (i) -> {
        if (i < 0 || i >= gate.actionOn.length) {
            return false;
        }
        return gate.actionOn[(int) i] && gate.statements[(int) i].action.get() != null;
    }).setNeverInline();
    for (int s = 0; s < gate.variant.numSlots; s++) {
        final int i = s;
        String tName = "gate.trigger/" + i;
        String aName = "gate.action/" + i;
        properties.put(tName, gate.statements[i].trigger);
        properties.put(aName, gate.statements[i].action);
        properties.put(tName, container.possibleTriggersContext);
        properties.put(aName, container.possibleActionsContext);
    }
    for (int c = 0; c < gate.connections.length; c++) {
        final int connection = c;
        String name = "gate.connection/" + c;
        properties.put(name, gate.connections[c]);
        properties.put(name, IButtonBehaviour.TOGGLE);
        properties.put(name, (IButtonClickEventListener) (b, k) -> {
            container.setConnected(connection, b.isButtonActive());
        });
    }
}
Also used : GuiBC8(buildcraft.lib.gui.GuiBC8) ContainerGate(buildcraft.transport.container.ContainerGate) MessageUtil(buildcraft.lib.misc.MessageUtil) ResourceLocation(net.minecraft.util.ResourceLocation) IButtonClickEventListener(buildcraft.lib.gui.button.IButtonClickEventListener) BuildCraftJsonGui(buildcraft.lib.gui.json.BuildCraftJsonGui) GateLogic(buildcraft.transport.gate.GateLogic) FunctionContext(buildcraft.lib.expression.FunctionContext) IButtonBehaviour(buildcraft.lib.gui.button.IButtonBehaviour) TypedKeyMap(buildcraft.lib.misc.collect.TypedKeyMap) FunctionContext(buildcraft.lib.expression.FunctionContext) GateLogic(buildcraft.transport.gate.GateLogic)

Aggregations

FunctionContext (buildcraft.lib.expression.FunctionContext)4 IButtonBehaviour (buildcraft.lib.gui.button.IButtonBehaviour)4 IButtonClickEventListener (buildcraft.lib.gui.button.IButtonClickEventListener)4 GuiBC8 (buildcraft.lib.gui.GuiBC8)3 BuildCraftJsonGui (buildcraft.lib.gui.json.BuildCraftJsonGui)3 TypedKeyMap (buildcraft.lib.misc.collect.TypedKeyMap)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 FillerStatementContext (buildcraft.builders.filler.FillerStatementContext)2 SpriteDelegate (buildcraft.lib.gui.json.SpriteDelegate)2 IFillerPattern (buildcraft.api.filler.IFillerPattern)1 Mode (buildcraft.api.tiles.IControllable.Mode)1 ContainerFiller (buildcraft.builders.container.ContainerFiller)1 ContainerFillerPlanner (buildcraft.builders.container.ContainerFillerPlanner)1 BCCoreSprites (buildcraft.core.BCCoreSprites)1 ISimpleDrawable (buildcraft.lib.gui.ISimpleDrawable)1 GuiButtonDrawable (buildcraft.lib.gui.button.GuiButtonDrawable)1 InventorySlotHolder (buildcraft.lib.gui.json.InventorySlotHolder)1 GuiRectangle (buildcraft.lib.gui.pos.GuiRectangle)1 MessageUtil (buildcraft.lib.misc.MessageUtil)1 ContainerGate (buildcraft.transport.container.ContainerGate)1