summaryrefslogtreecommitdiff
path: root/ihl/flexible_cable/IronWorkbenchGui.java
blob: dedb9d84dfd8b10a725868cc547161a1e73afee7 (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
176
177
178
179
180
181
182
183
184
185
186
package ihl.flexible_cable;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ic2.core.IC2;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

import ihl.interfaces.IItemHasMiniGUI;
import ihl.interfaces.ItemMiniGUI;
import ihl.utils.IHLRenderUtils;

@SideOnly(Side.CLIENT)
public class IronWorkbenchGui extends GuiContainer {
	private static final ResourceLocation background = new ResourceLocation("ihl", "textures/gui/GUIIronWorkbench.png");
	private IronWorkbenchContainer container;
	private ItemMiniGUI miniGui;
	private static final short outputslotoffset=66;

    public IronWorkbenchGui (IronWorkbenchContainer container1) {
            super(container1);
            this.container=container1;
            this.ySize=IronWorkbenchContainer.height;
    }
    
    @Override
    protected void drawGuiContainerForegroundLayer(int par1, int par2) 
    {
        int x = (width - xSize) / 2;
        int y = (height - ySize) / 2;
        for(int row = 1;row<6;row++)
        {
       		if(!this.container.tileEntity.workspaceElements.ready[row] && this.container.tileEntity.workspaceElements.get(row)!=null)
       		{
       			IHLRenderUtils.instance.drawWorkspaceElementTooltip(par1, par2, 8+x, 8+y+row*18, this.container.tileEntity.workspaceElements.get(row));
       		}
        }
		if(miniGui!=null)
		{
			miniGui.displayGUI();
		}
    }
    
    @Override
    protected void keyTyped(char characterTyped, int keyIndex)
    {
    	super.keyTyped(characterTyped, keyIndex);
		if(miniGui!=null && miniGui.handleKeyTyped(characterTyped, keyIndex))
		{
			miniGui.onGUIClosed();
			miniGui=null;
		}
    }
    
    @Override
    protected void mouseClicked(int mouseX, int mouseY, int mouseButton)
    {
        int x = (width - xSize) / 2;
        int y = (height - ySize) / 2;
		if(miniGui==null || !miniGui.handleMouseClick(mouseX-x, mouseY-y, mouseButton))
		{
			if(miniGui!=null)
			{
				miniGui.onGUIClosed();
				miniGui=null;
			}
	    	super.mouseClicked(mouseX, mouseY, mouseButton);
		}
    }
    
    @Override
    protected void mouseMovedOrUp(int mouseX, int mouseY, int mouseButton)
    {
    	super.mouseMovedOrUp(mouseX, mouseY, mouseButton);
        int x = (width - xSize) / 2;
        int y = (height - ySize) / 2;
		if(miniGui!=null)
		{
			miniGui.handleMouseClick(mouseX-x, mouseY-y, mouseButton);
		}
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float par1, int par2,
                    int par3) {
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            this.mc.renderEngine.bindTexture(background);
            int x = (width - xSize) / 2;
            int y = (height - ySize) / 2;
            this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
            if (this.container.tileEntity.progress > 0)
            {
                int frameNum=0;
                short slotRecipeNum=this.container.tileEntity.output.slotRecipe[0];
                for(int row = 0;row<6;row++)
           	   	{
                   for (int col = 0; col<3; ++col)
                   {
             		   if(slotRecipeNum!=this.container.tileEntity.output.slotRecipe[col+row*3])
             		   {
             			 frameNum++;
             			 slotRecipeNum=this.container.tileEntity.output.slotRecipe[col+row*3];
             		   }
             		   if(this.container.tileEntity.currentSlot==slotRecipeNum)
             		   {
             			   int i1 = Math.min(this.container.tileEntity.gaugeProgressScaled(18),18);
             			   this.drawTexturedModalRect(115+x+col*18, 7+y+row*18, 176, 72,i1,18);
             			   this.drawTexturedModalRect(115+x+col*18, 7+y+row*18, 176+getFrameX(frameNum), getFrameY(frameNum),18,18);
             		   }
             	   }
                }
            }
            else
            {
               int frameNum=0;
               short slotRecipeNum=this.container.tileEntity.output.slotRecipe[0];
           	   for(int row = 0;row<6;row++)
           	   {
                 for (int col = 0;col<3; ++col)
                 {
             		   if(slotRecipeNum!=this.container.tileEntity.output.slotRecipe[col+row*3])
             		   {
             			 frameNum++;
             			 slotRecipeNum=this.container.tileEntity.output.slotRecipe[col+row*3];
             		   }
             		   if(this.container.tileEntity.output.get(col+row*3)!=null)
             		   {
             			   this.drawTexturedModalRect(115+x+col*18, 7+y+row*18, 176+getFrameX(frameNum), getFrameY(frameNum),18,18);
             		   }
             	   }
                }
            }
           for(int row = 1;row<6;row++)
           {
       			   if(!this.container.tileEntity.workspaceElements.ready[row])
       			   {
       				   this.drawTexturedModalRect(20+x, 9+y+row*18, 194, 74,3,14);
      			   }
           }
    }
    
    @Override
	public void onGuiClosed()
    {
    	super.onGuiClosed();
    	this.container.tileEntity.isGuiScreenOpened=false;
		IC2.network.get().initiateClientTileEntityEvent(this.container.tileEntity, 16);
    }
    
    @Override
    public void handleMouseClick(Slot slot,int slotNumber,int mouseButton/*0=left 1=right*/,int arg3)
    {
    	if(miniGui==null  && slot!=null && slot.slotNumber>=outputslotoffset && slot.slotNumber<outputslotoffset+18)
    	{
    		if(mouseButton==0)
    		{
        		IC2.network.get().initiateClientTileEntityEvent(this.container.tileEntity, slot.slotNumber-outputslotoffset);
    		}
    		else if(mouseButton==1)
    		{
    			if(slot.getHasStack() && slot.getStack().getItem() instanceof IItemHasMiniGUI)
    			{
    				if(miniGui!=null)
    				{
    					miniGui.onGUIClosed();
    				}
    				miniGui = ((IItemHasMiniGUI)slot.getStack().getItem()).getMiniGUI(this, slot);
    			}
    		}
    	}
    	super.handleMouseClick(slot, slotNumber, mouseButton, arg3);
    }
    
    private int getFrameX(int number)
    {
    	return (number % 4) * 18;
    }
    private int getFrameY(int number)
    {
    	return ((number>>2) & 3)*18;
    }

}