aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/core/gui/machine/GUIPestKiller.java
blob: e42f6a9da95973010664c34b7d8f5eb3f03a0a3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package gtPlusPlus.core.gui.machine;

import static gregtech.api.enums.Mods.GTPlusPlus;

import java.awt.Color;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.IFluidTank;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gtPlusPlus.core.container.ContainerPestKiller;
import gtPlusPlus.core.material.MaterialMisc;
import gtPlusPlus.core.tileentities.machines.TileEntityPestKiller;
import gtPlusPlus.core.util.math.MathUtils;

@SideOnly(Side.CLIENT)
public class GUIPestKiller extends GuiContainer {

    private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation(
        GTPlusPlus.ID,
        "textures/gui/PestKiller.png");
    private final TileEntityPestKiller mTileKiller;

    public GUIPestKiller(final InventoryPlayer player_inventory, final TileEntityPestKiller te) {
        super(new ContainerPestKiller(player_inventory, te));
        mTileKiller = te;
    }

    @Override
    protected void drawGuiContainerForegroundLayer(final int i, final int j) {
        if (mTileKiller != null) {
            this.fontRendererObj.drawString(I18n.format(mTileKiller.getInventoryName()), 4, 6, 4210752);
            drawFluidTank(mTileKiller.getTank(), 134, 35);
        }
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(final float f, final int i, final int j) {
        GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
        this.mc.renderEngine.bindTexture(craftingTableGuiTextures);
        final int x = (this.width - this.xSize) / 2;
        final int y = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize);
    }

    // This method is called when the Gui is first called!
    @Override
    public void initGui() {
        super.initGui();
    }

    private void drawFluidTank(IFluidTank tank, int x, int y) {
        Color startGrad = new Color(50, 50, 50);
        Color endGrad = new Color(20, 20, 20);
        ContainerPestKiller aCont = (ContainerPestKiller) this.inventorySlots;

        double aPercentage = 0;
        double aDivisor = (100 / 16);
        int aFrameHeight = 16;

        boolean didRender = false;
        if (aCont != null) {
            TileEntityPestKiller aTile = mTileKiller;
            if (aTile != null) {
                FluidTank aTank = aTile.getTank();
                int aTier = aTile.getTier();
                drawGradientRect(x, y, x + 16, y + 16, startGrad.getRGB(), endGrad.getRGB());
                if (aTier <= 0 || aTier > 2) {
                    if (aTank != null && aTank.getFluidAmount() > 0) {
                        aPercentage = MathUtils.findPercentage(aTank.getFluidAmount(), aTank.getCapacity());
                        // Logger.INFO("Percent = "+aPercentage);
                        // aFrameHeight = (int) (aPercentage / aDivisor);
                        // Logger.INFO("Frame Height = "+aFrameHeight);
                    }
                    this.fontRendererObj.drawString("Tier: 0", 4, 18, 4210752);
                    this.fontRendererObj.drawString("Range: 1x1", 4, 30, 4210752);
                    this.fontRendererObj.drawString("Poison: None", 4, 42, 4210752);
                    this.fontRendererObj.drawString("Amount: 0", 4, 64, 4210752);
                    didRender = true;
                } else if (aTier == 1) {
                    if (aTank != null && aTank.getFluidAmount() > 0) {
                        aPercentage = MathUtils.findPercentage(aTank.getFluidAmount(), aTank.getCapacity());
                        // Logger.INFO("Percent = "+aPercentage);
                        aFrameHeight = (int) (aPercentage / aDivisor);
                        // Logger.INFO("Frame Height = "+aFrameHeight);
                    }
                    startGrad = new Color(240, 50, 240);
                    endGrad = new Color(130, 30, 130);
                    drawGradientRect(x, y + (16 - aFrameHeight), x + 16, y + 16, startGrad.getRGB(), endGrad.getRGB());
                    this.fontRendererObj.drawString("Tier: 1", 4, 18, 4210752);
                    this.fontRendererObj.drawString("Range: 5x5", 4, 30, 4210752);
                    this.fontRendererObj.drawString("Poison: ", 4, 42, 4210752);
                    this.fontRendererObj.drawString(
                        aTile.getTank()
                            .getFluid()
                            .getLocalizedName(),
                        4,
                        54,
                        4210752);
                    this.fontRendererObj.drawString(
                        "Amount: " + aTile.getTank()
                            .getFluidAmount(),
                        4,
                        64,
                        4210752);
                    didRender = true;
                } else if (aTier == 2) {
                    if (aTank != null && aTank.getFluidAmount() > 0) {
                        aPercentage = MathUtils.findPercentage(aTank.getFluidAmount(), aTank.getCapacity());
                        // Logger.INFO("Percent = "+aPercentage);
                        aFrameHeight = (int) (aPercentage / aDivisor);
                        // Logger.INFO("Frame Height = "+aFrameHeight);
                    }
                    short[] aRGB = MaterialMisc.HYDROGEN_CYANIDE.getRGB();
                    startGrad = new Color(aRGB[0], aRGB[1], aRGB[2]);
                    endGrad = new Color(Math.max(aRGB[0], 0), Math.max(aRGB[1], 0), Math.max(aRGB[2], 0));
                    drawGradientRect(x, y + (16 - aFrameHeight), x + 16, y + 16, startGrad.getRGB(), endGrad.getRGB());
                    this.fontRendererObj.drawString("Tier: 2", 4, 18, 4210752);
                    this.fontRendererObj.drawString("Range: 9x9", 4, 30, 4210752);
                    this.fontRendererObj.drawString("Poison: ", 4, 42, 4210752);
                    this.fontRendererObj.drawString(
                        aTile.getTank()
                            .getFluid()
                            .getLocalizedName(),
                        4,
                        54,
                        4210752);
                    this.fontRendererObj.drawString(
                        "Amount: " + aTile.getTank()
                            .getFluidAmount(),
                        4,
                        64,
                        4210752);
                    didRender = true;
                }
            }
        }
        if (!didRender) {
            startGrad = new Color(255, 30, 120);
            endGrad = new Color(255, 0, 50);
            drawGradientRect(x, y, x + 16, y + 16, startGrad.getRGB(), endGrad.getRGB());
            this.fontRendererObj.drawString("Tier: 0", 4, 18, 4210752);
        }

        /*
         * FluidStack fluid = tank.getFluid(); TextureManager manager = mc.getTextureManager(); if (fluid != null) {
         * manager.bindTexture(manager.getResourceLocation(0)); float amount = fluid.amount; float capacity =
         * tank.getCapacity(); float scale = amount / capacity; int fluidTankHeight = 60; int fluidAmount = (int) (scale
         * * fluidTankHeight); drawFluid(x, y + fluidTankHeight - fluidAmount, fluid.getFluid().getIcon(fluid), 16,
         * fluidAmount); }
         */
    }

    private void drawFluid(int x, int y, IIcon icon, int width, int height) {
        int i = 0;
        int j = 0;
        int drawHeight = 0;
        int drawWidth = 0;
        for (i = 0; i < width; i += 16) {
            for (j = 0; j < height; j += 16) {
                drawWidth = Math.min(width - i, 16);
                drawHeight = Math.min(height - j, 16);
                drawTexturedModelRectFromIcon(x + i, y + j, icon, drawWidth, drawHeight);
            }
        }
    }
}