Search in sources :

Example 1 with TubeModuleRedstoneReceiving

use of pneumaticCraft.common.block.tubes.TubeModuleRedstoneReceiving in project PneumaticCraft by MineMaarten.

the class GuiPressureModule method drawScreen.

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    super.drawScreen(mouseX, mouseY, partialTicks);
    GL11.glDisable(GL11.GL_LIGHTING);
    if (!lowerBoundField.isFocused())
        lowerBoundField.setText(PneumaticCraftUtils.roundNumberTo(module.lowerBound, 1));
    if (!higherBoundField.isFocused())
        higherBoundField.setText(PneumaticCraftUtils.roundNumberTo(module.higherBound, 1));
    FMLClientHandler.instance().getClient().getTextureManager().bindTexture(getTexture());
    int scrollbarLowerBoundX = (int) (guiLeft + 16 + (158 - 11) * (module.lowerBound / (module.maxValue + 1)));
    int scrollbarHigherBoundX = (int) (guiLeft + 16 + (158 - 11) * (module.higherBound / (module.maxValue + 1)));
    if (!Mouse.isButtonDown(0))
        waitTillRelease = false;
    if (!waitTillRelease && Mouse.isButtonDown(0)) {
        if (new Rectangle(guiLeft + 11, guiTop + 59, 158, 15).contains(mouseX, mouseY)) {
            module.higherBound = (float) (mouseX - 6 - (guiLeft + 11)) / (158 - 11) * module.maxValue;
            if (module.higherBound < -1)
                module.higherBound = -1;
            if (module.higherBound > module.maxValue)
                module.higherBound = module.maxValue;
            //higherBoundField.setText(PneumaticCraftUtils.roundNumberTo(module.higherBound, 1));
            NetworkHandler.sendToServer(new PacketUpdatePressureModule(module, 1, module.higherBound));
        } else if (new Rectangle(guiLeft + 11, guiTop + 73, 158, 15).contains(mouseX, mouseY)) {
            module.lowerBound = (float) (mouseX - 6 - (guiLeft + 11)) / (158 - 11) * module.maxValue;
            if (module.lowerBound < -1)
                module.lowerBound = -1;
            if (module.lowerBound > module.maxValue)
                module.lowerBound = module.maxValue;
            // lowerBoundField.setText(PneumaticCraftUtils.roundNumberTo(module.lowerBound, 1));
            NetworkHandler.sendToServer(new PacketUpdatePressureModule(module, 0, module.lowerBound));
        }
    }
    drawTexturedModalRect(scrollbarLowerBoundX, guiTop + 73, 183, 0, 15, 12);
    drawTexturedModalRect(scrollbarHigherBoundX, guiTop + 59, 183, 0, 15, 12);
    lowerBoundField.drawTextBox();
    higherBoundField.drawTextBox();
    /*
         * Draw graph
         */
    drawVerticalLine(graphLeft, graphHighY, graphLowY, 0xFF000000);
    for (int i = 0; i < 16; i++) {
        boolean longer = i % 5 == 0;
        if (longer) {
            fontRendererObj.drawString(i + "", graphLeft - 5 - fontRendererObj.getStringWidth(i + ""), graphHighY + (graphLowY - graphHighY) * (15 - i) / 15 - 3, 0xFF000000);
            drawHorizontalLine(graphLeft + 4, graphRight, graphHighY + (graphLowY - graphHighY) * (15 - i) / 15, i == 0 ? 0xFF000000 : 0x33000000);
        }
        drawHorizontalLine(graphLeft - (longer ? 5 : 3), graphLeft + 3, graphHighY + (graphLowY - graphHighY) * (15 - i) / 15, 0xFF000000);
    }
    for (int i = 0; i < 31; i++) {
        boolean longer = i % 5 == 0;
        if (longer) {
            fontRendererObj.drawString(i + "", graphLeft + (graphRight - graphLeft) * i / 30 - fontRendererObj.getStringWidth(i + "") / 2 + 1, graphLowY + 6, 0xFF000000);
            drawVerticalLine(graphLeft + (graphRight - graphLeft) * i / 30, graphHighY, graphLowY - 2, 0x33000000);
        }
        drawVerticalLine(graphLeft + (graphRight - graphLeft) * i / 30, graphLowY - 3, graphLowY + (longer ? 5 : 3), 0xFF000000);
    }
    if (module instanceof TubeModuleRedstoneReceiving) {
        ((TubeModuleRedstoneReceiving) module).onNeighborBlockUpdate();
        drawHorizontalLine(graphLeft + 4, graphRight, graphHighY + (graphLowY - graphHighY) * (15 - ((TubeModuleRedstoneReceiving) module).getReceivingRedstoneLevel()) / 15, 0xFFFF0000);
        String status = "Current threshold: " + PneumaticCraftUtils.roundNumberTo(((TubeModuleRedstoneReceiving) module).getThreshold(), 1) + " bar";
        fontRendererObj.drawString(status, guiLeft + xSize / 2 - fontRendererObj.getStringWidth(status) / 2, guiTop + 173, 0xFF000000);
    }
    /*
         * Draw the data in the graph 
         */
    double zLevel = 90;
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    Tessellator t = Tessellator.instance;
    t.startDrawing(GL11.GL_LINE_STRIP);
    t.setColorOpaque_I(0);
    for (int i = 0; i < 16; i++) {
        double y = graphHighY + (graphLowY - graphHighY) * (15 - i) / 15;
        double x = graphLeft + (graphRight - graphLeft) * module.getThreshold(i) / 30;
        t.addVertex(x, y, zLevel);
    }
    t.draw();
    GL11.glEnable(GL11.GL_TEXTURE_2D);
}
Also used : PacketUpdatePressureModule(pneumaticCraft.common.network.PacketUpdatePressureModule) Tessellator(net.minecraft.client.renderer.Tessellator) TubeModuleRedstoneReceiving(pneumaticCraft.common.block.tubes.TubeModuleRedstoneReceiving) Rectangle(java.awt.Rectangle)

Example 2 with TubeModuleRedstoneReceiving

use of pneumaticCraft.common.block.tubes.TubeModuleRedstoneReceiving in project PneumaticCraft by MineMaarten.

the class GuiPressureModuleSimple method initGui.

@Override
public void initGui() {
    super.initGui();
    String title = I18n.format("item." + module.getType() + ".name");
    addLabel(title, width / 2 - fontRendererObj.getStringWidth(title) / 2, guiTop + 5);
    advancedMode = new GuiCheckBox(0, guiLeft + 6, guiTop + 15, 0xFF000000, "gui.tubeModule.advancedConfig").setTooltip(I18n.format("gui.tubeModule.advancedConfig.tooltip"));
    advancedMode.checked = false;
    addWidget(advancedMode);
    thresholdField = new WidgetTextFieldNumber(fontRendererObj, guiLeft + 110, guiTop + 33, 30, fontRendererObj.FONT_HEIGHT).setDecimals(1);
    addWidget(thresholdField);
    if (module instanceof TubeModuleRedstoneReceiving) {
        thresholdField.setValue(((TubeModuleRedstoneReceiving) module).getThreshold());
        addLabel(I18n.format("gui.tubeModule.simpleConfig.threshold"), guiLeft + 6, guiTop + 33);
    } else {
        thresholdField.setValue(module.lowerBound);
        addLabel(I18n.format("gui.tubeModule.simpleConfig.turn"), guiLeft + 6, guiTop + 33);
        moreOrLessButton = new GuiButtonSpecial(1, guiLeft + 85, guiTop + 28, 20, 20, module.lowerBound < module.higherBound ? ">" : "<");
        moreOrLessButton.setTooltipText(I18n.format(module.lowerBound < module.higherBound ? "gui.tubeModule.simpleConfig.higherThan" : "gui.tubeModule.simpleConfig.lowerThan"));
        addWidget(moreOrLessButton);
    }
    addLabel(I18n.format("gui.general.bar"), guiLeft + 145, guiTop + 34);
}
Also used : WidgetTextFieldNumber(pneumaticCraft.client.gui.widget.WidgetTextFieldNumber) TubeModuleRedstoneReceiving(pneumaticCraft.common.block.tubes.TubeModuleRedstoneReceiving) GuiCheckBox(pneumaticCraft.client.gui.widget.GuiCheckBox) GuiButtonSpecial(pneumaticCraft.client.gui.GuiButtonSpecial)

Aggregations

TubeModuleRedstoneReceiving (pneumaticCraft.common.block.tubes.TubeModuleRedstoneReceiving)2 Rectangle (java.awt.Rectangle)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 GuiButtonSpecial (pneumaticCraft.client.gui.GuiButtonSpecial)1 GuiCheckBox (pneumaticCraft.client.gui.widget.GuiCheckBox)1 WidgetTextFieldNumber (pneumaticCraft.client.gui.widget.WidgetTextFieldNumber)1 PacketUpdatePressureModule (pneumaticCraft.common.network.PacketUpdatePressureModule)1