Search in sources :

Example 1 with StatementParameterSlot

use of buildcraft.core.lib.gui.StatementParameterSlot in project BuildCraft by BuildCraft.

the class GuiGateInterface method doSlotClick.

private void doSlotClick(AdvancedSlot slot, int k) {
    if (slot instanceof TriggerSlot && container.hasTriggers()) {
        TriggerSlot triggerSlot = (TriggerSlot) slot;
        IStatement changed = null;
        if (!isShiftKeyDown()) {
            if (triggerSlot.getStatement() == null) {
                if (k == 0) {
                    changed = container.getFirstTrigger();
                } else {
                    changed = container.getLastTrigger();
                }
            } else {
                Iterator<IStatement> it = container.getTriggerIterator(k != 0);
                for (; it.hasNext(); ) {
                    IStatement trigger = it.next();
                    if (!it.hasNext()) {
                        break;
                    }
                    if (trigger == triggerSlot.getStatement()) {
                        changed = it.next();
                        break;
                    }
                }
            }
        }
        if (changed == null) {
            container.setTrigger(triggerSlot.slot, null, true);
        } else {
            container.setTrigger(triggerSlot.slot, changed.getUniqueTag(), true);
        }
        for (StatementParameterSlot p : triggerSlot.parameters) {
            IStatementParameter parameter = null;
            if (changed != null && p.slot < changed.minParameters()) {
                parameter = changed.createParameter(p.slot);
            }
            container.setTriggerParameter(triggerSlot.slot, p.slot, parameter, true);
        }
    } else if (slot instanceof ActionSlot) {
        ActionSlot actionSlot = (ActionSlot) slot;
        IStatement changed = null;
        if (!isShiftKeyDown()) {
            if (actionSlot.getStatement() == null) {
                if (k == 0) {
                    changed = container.getFirstAction();
                } else {
                    changed = container.getLastAction();
                }
            } else {
                Iterator<IStatement> it = container.getActionIterator(k != 0);
                for (; it.hasNext(); ) {
                    IStatement action = it.next();
                    if (!it.hasNext()) {
                        break;
                    }
                    if (action == actionSlot.getStatement()) {
                        changed = it.next();
                        break;
                    }
                }
            }
        }
        if (changed == null) {
            container.setAction(actionSlot.slot, null, true);
        } else {
            container.setAction(actionSlot.slot, changed.getUniqueTag(), true);
        }
        for (StatementParameterSlot p : actionSlot.parameters) {
            IStatementParameter parameter = null;
            if (changed != null && p.slot < changed.minParameters()) {
                parameter = changed.createParameter(p.slot);
            }
            container.setActionParameter(actionSlot.slot, p.slot, parameter, true);
        }
    } else if (slot instanceof StatementParameterSlot) {
        StatementParameterSlot paramSlot = (StatementParameterSlot) slot;
        StatementSlot statement = paramSlot.statementSlot;
        if (statement.isDefined() && statement.getStatement().maxParameters() > paramSlot.slot) {
            IStatementParameter param = paramSlot.getParameter();
            if (param == null) {
                param = statement.getStatement().createParameter(paramSlot.slot);
            }
            if (param != null) {
                param.onClick(gate, statement.getStatement(), mc.thePlayer.inventory.getItemStack(), new StatementMouseClick(k, isShiftKeyDown()));
                paramSlot.setParameter(param, true);
            }
        }
    }
    container.markDirty();
}
Also used : StatementSlot(buildcraft.core.lib.gui.StatementSlot) Iterator(java.util.Iterator) StatementMouseClick(buildcraft.api.statements.StatementMouseClick) IStatementParameter(buildcraft.api.statements.IStatementParameter) IStatement(buildcraft.api.statements.IStatement) StatementParameterSlot(buildcraft.core.lib.gui.StatementParameterSlot)

Example 2 with StatementParameterSlot

use of buildcraft.core.lib.gui.StatementParameterSlot in project BuildCraft by BuildCraft.

the class GuiGateInterface method drawGuiContainerBackgroundLayer.

@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
    container.synchronize();
    if (gate == null) {
        return;
    }
    ResourceLocation texture = container.getGateGuiFile();
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    mc.renderEngine.bindTexture(texture);
    drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
    for (AdvancedSlot slot : slots) {
        if (slot instanceof TriggerSlot) {
            boolean halfWidth = container.actionsState[((TriggerSlot) slot).slot] == ActionActiveState.Partial;
            if (container.actionsState[((TriggerSlot) slot).slot] != ActionActiveState.Deactivated) {
                mc.renderEngine.bindTexture(texture);
                drawTexturedModalRect(guiLeft + slot.x + 17 + 18 * gate.material.numTriggerParameters, guiTop + slot.y + 6, 176, 18, halfWidth ? 9 : 18, 4);
            }
        } else if (slot instanceof StatementParameterSlot) {
            StatementParameterSlot paramSlot = (StatementParameterSlot) slot;
            StatementSlot statement = paramSlot.statementSlot;
            mc.renderEngine.bindTexture(texture);
            if (statement.isDefined()) {
                if (!paramSlot.isAllowed()) {
                    drawTexturedModalRect(guiLeft + slot.x - 1, guiTop + slot.y - 1, 176, 0, 18, 18);
                } else if (paramSlot.isRequired() && paramSlot.getParameter() == null) {
                    drawTexturedModalRect(guiLeft + slot.x - 1, guiTop + slot.y - 1, 176, 22, 18, 18);
                }
            } else {
                drawTexturedModalRect(guiLeft + slot.x - 1, guiTop + slot.y - 1, 176, 0, 18, 18);
            }
        }
    }
    drawBackgroundSlots(x, y);
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    // Make sure that render states are reset, an ItemStack can derp them up.
    GL11.glDisable(GL11.GL_LIGHTING);
    GlStateManager.disableLighting();
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GlStateManager.enableAlpha();
    GL11.glEnable(GL11.GL_BLEND);
    GlStateManager.enableBlend();
    tooltip = null;
    int sX = 18;
    int sY = OPTION_TRIGGERS_Y.getAsInt();
    int width = OPTION_TRIGGERS_WIDE.getAsInt() * 18;
    triggerRows = 1;
    for (IStatement statement : container.getTriggerCollection(false)) {
        int pX = this.guiLeft - sX;
        int pY = this.guiTop + sY;
        if (x > pX & x < pX + 16 && y > pY && y < pY + 16) {
            String desc = statement.getDescription();
            tooltip = I18n.format(desc);
        }
        drawStatement(pX, pY, statement);
        if (sX >= width) {
            sX = 18;
            sY += 18;
            triggerRows++;
        } else {
            sX += 18;
            lastTriggerRowSize = sX;
        }
    }
    width = OPTION_ACTIONS_WIDE.getAsInt() * 18;
    sX = 0;
    sY = OPTION_ACTIONS_Y.getAsInt();
    actionRows = 1;
    for (IStatement statement : container.getActionCollection(false)) {
        int pX = this.guiLeft + this.xSize() + sX;
        int pY = this.guiTop + sY;
        drawStatement(pX, pY, statement);
        if (x > pX & x < pX + 16 && y > pY && y < pY + 16) {
            String desc = statement.getDescription();
            tooltip = I18n.format(desc);
        }
        if (sX >= width - 18) {
            sX = 0;
            sY += 18;
            actionRows++;
        } else {
            sX += 18;
            lastActionRowSize = sX;
        }
    }
    if (index != -1) {
        Collection<IStatement> collect;
        if (trigger)
            collect = container.getTriggerCollection(false);
        else
            collect = container.getActionCollection(false);
        IStatement state = null;
        int i = index;
        Iterator<IStatement> it = collect.iterator();
        while (i >= 0) {
            state = it.next();
            i--;
        }
        AdvancedSlot hoverSlot = getSlotAtLocation(x, y);
        boolean isValid = (trigger && hoverSlot instanceof TriggerSlot) || (!trigger && hoverSlot instanceof ActionSlot);
        if (!isValid) {
            GlStateManager.color(0.95f, 0.6f, 0.6f);
        }
        drawStatement(x - 8, y - 8, state);
        GlStateManager.color(1.0f, 1.0f, 1.0f);
    }
    GlStateManager.enableLighting();
    GlStateManager.disableAlpha();
    GlStateManager.disableBlend();
}
Also used : StatementSlot(buildcraft.core.lib.gui.StatementSlot) AdvancedSlot(buildcraft.core.lib.gui.AdvancedSlot) ResourceLocation(net.minecraft.util.ResourceLocation) IStatement(buildcraft.api.statements.IStatement) StatementParameterSlot(buildcraft.core.lib.gui.StatementParameterSlot)

Example 3 with StatementParameterSlot

use of buildcraft.core.lib.gui.StatementParameterSlot in project BuildCraft by BuildCraft.

the class GuiGateInterface method mouseReleased.

@Override
protected void mouseReleased(int mouseX, int mouseY, int eventType) {
    super.mouseReleased(mouseX, mouseY, eventType);
    if (index >= 0) {
        int i = index;
        index = -1;
        IStatement changeTo;
        Iterator<IStatement> it;
        if (trigger)
            it = container.getTriggerIterator(false);
        else
            it = container.getActionIterator(false);
        do {
            changeTo = it.next();
            i--;
        } while (i >= 0);
        AdvancedSlot slot = getSlotAtLocation(mouseX, mouseY);
        if (slot == null)
            return;
        if (trigger && slot instanceof TriggerSlot) {
            TriggerSlot trig = (TriggerSlot) slot;
            container.setTrigger(trig.slot, changeTo.getUniqueTag(), true);
            for (StatementParameterSlot p : trig.parameters) {
                IStatementParameter parameter = null;
                if (p.slot < changeTo.minParameters()) {
                    parameter = changeTo.createParameter(p.slot);
                }
                container.setTriggerParameter(trig.slot, p.slot, parameter, true);
            }
        }
        if (!trigger && slot instanceof ActionSlot) {
            ActionSlot trig = (ActionSlot) slot;
            container.setAction(trig.slot, changeTo.getUniqueTag(), true);
            for (StatementParameterSlot p : trig.parameters) {
                IStatementParameter parameter = null;
                if (p.slot < changeTo.minParameters()) {
                    parameter = changeTo.createParameter(p.slot);
                }
                container.setActionParameter(trig.slot, p.slot, parameter, true);
            }
        }
    }
}
Also used : AdvancedSlot(buildcraft.core.lib.gui.AdvancedSlot) IStatementParameter(buildcraft.api.statements.IStatementParameter) IStatement(buildcraft.api.statements.IStatement) StatementParameterSlot(buildcraft.core.lib.gui.StatementParameterSlot)

Aggregations

IStatement (buildcraft.api.statements.IStatement)3 StatementParameterSlot (buildcraft.core.lib.gui.StatementParameterSlot)3 IStatementParameter (buildcraft.api.statements.IStatementParameter)2 AdvancedSlot (buildcraft.core.lib.gui.AdvancedSlot)2 StatementSlot (buildcraft.core.lib.gui.StatementSlot)2 StatementMouseClick (buildcraft.api.statements.StatementMouseClick)1 Iterator (java.util.Iterator)1 ResourceLocation (net.minecraft.util.ResourceLocation)1