001 package net.minecraft.src; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 import java.io.ByteArrayOutputStream; 006 import java.io.DataOutputStream; 007 import org.lwjgl.opengl.GL11; 008 import org.lwjgl.opengl.GL12; 009 010 @SideOnly(Side.CLIENT) 011 public class GuiMerchant extends GuiContainer 012 { 013 private IMerchant field_74203_o; 014 private GuiButtonMerchant nextRecipeButtonIndex; 015 private GuiButtonMerchant previousRecipeButtonIndex; 016 private int currentRecipeIndex = 0; 017 018 public GuiMerchant(InventoryPlayer par1InventoryPlayer, IMerchant par2IMerchant, World par3World) 019 { 020 super(new ContainerMerchant(par1InventoryPlayer, par2IMerchant, par3World)); 021 this.field_74203_o = par2IMerchant; 022 } 023 024 /** 025 * Adds the buttons (and other controls) to the screen in question. 026 */ 027 public void initGui() 028 { 029 super.initGui(); 030 int var1 = (this.width - this.xSize) / 2; 031 int var2 = (this.height - this.ySize) / 2; 032 this.controlList.add(this.nextRecipeButtonIndex = new GuiButtonMerchant(1, var1 + 120 + 27, var2 + 24 - 1, true)); 033 this.controlList.add(this.previousRecipeButtonIndex = new GuiButtonMerchant(2, var1 + 36 - 19, var2 + 24 - 1, false)); 034 this.nextRecipeButtonIndex.enabled = false; 035 this.previousRecipeButtonIndex.enabled = false; 036 } 037 038 /** 039 * Draw the foreground layer for the GuiContainer (everything in front of the items) 040 */ 041 protected void drawGuiContainerForegroundLayer() 042 { 043 this.fontRenderer.drawString(StatCollector.translateToLocal("entity.Villager.name"), 56, 6, 4210752); 044 this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752); 045 } 046 047 /** 048 * Called from the main game loop to update the screen. 049 */ 050 public void updateScreen() 051 { 052 super.updateScreen(); 053 MerchantRecipeList var1 = this.field_74203_o.getRecipes(this.mc.thePlayer); 054 055 if (var1 != null) 056 { 057 this.nextRecipeButtonIndex.enabled = this.currentRecipeIndex < var1.size() - 1; 058 this.previousRecipeButtonIndex.enabled = this.currentRecipeIndex > 0; 059 } 060 } 061 062 /** 063 * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e). 064 */ 065 protected void actionPerformed(GuiButton par1GuiButton) 066 { 067 boolean var2 = false; 068 069 if (par1GuiButton == this.nextRecipeButtonIndex) 070 { 071 ++this.currentRecipeIndex; 072 var2 = true; 073 } 074 else if (par1GuiButton == this.previousRecipeButtonIndex) 075 { 076 --this.currentRecipeIndex; 077 var2 = true; 078 } 079 080 if (var2) 081 { 082 ((ContainerMerchant)this.inventorySlots).setCurrentRecipeIndex(this.currentRecipeIndex); 083 ByteArrayOutputStream var3 = new ByteArrayOutputStream(); 084 DataOutputStream var4 = new DataOutputStream(var3); 085 086 try 087 { 088 var4.writeInt(this.currentRecipeIndex); 089 this.mc.getSendQueue().addToSendQueue(new Packet250CustomPayload("MC|TrSel", var3.toByteArray())); 090 } 091 catch (Exception var6) 092 { 093 var6.printStackTrace(); 094 } 095 } 096 } 097 098 /** 099 * Draw the background layer for the GuiContainer (everything behind the items) 100 */ 101 protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) 102 { 103 int var4 = this.mc.renderEngine.getTexture("/gui/trading.png"); 104 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); 105 this.mc.renderEngine.bindTexture(var4); 106 int var5 = (this.width - this.xSize) / 2; 107 int var6 = (this.height - this.ySize) / 2; 108 this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize); 109 } 110 111 /** 112 * Draws the screen and all the components in it. 113 */ 114 public void drawScreen(int par1, int par2, float par3) 115 { 116 super.drawScreen(par1, par2, par3); 117 MerchantRecipeList var4 = this.field_74203_o.getRecipes(this.mc.thePlayer); 118 119 if (var4 != null && !var4.isEmpty()) 120 { 121 int var5 = (this.width - this.xSize) / 2; 122 int var6 = (this.height - this.ySize) / 2; 123 GL11.glPushMatrix(); 124 int var7 = this.currentRecipeIndex; 125 MerchantRecipe var8 = (MerchantRecipe)var4.get(var7); 126 ItemStack var9 = var8.getItemToBuy(); 127 ItemStack var10 = var8.getSecondItemToBuy(); 128 ItemStack var11 = var8.getItemToSell(); 129 RenderHelper.enableGUIStandardItemLighting(); 130 GL11.glDisable(GL11.GL_LIGHTING); 131 GL11.glEnable(GL12.GL_RESCALE_NORMAL); 132 GL11.glEnable(GL11.GL_COLOR_MATERIAL); 133 GL11.glEnable(GL11.GL_LIGHTING); 134 itemRenderer.zLevel = 100.0F; 135 itemRenderer.renderItemIntoGUI(this.fontRenderer, this.mc.renderEngine, var9, var5 + 36, var6 + 24); 136 itemRenderer.renderItemOverlayIntoGUI(this.fontRenderer, this.mc.renderEngine, var9, var5 + 36, var6 + 24); 137 138 if (var10 != null) 139 { 140 itemRenderer.renderItemIntoGUI(this.fontRenderer, this.mc.renderEngine, var10, var5 + 62, var6 + 24); 141 itemRenderer.renderItemOverlayIntoGUI(this.fontRenderer, this.mc.renderEngine, var10, var5 + 62, var6 + 24); 142 } 143 144 itemRenderer.renderItemIntoGUI(this.fontRenderer, this.mc.renderEngine, var11, var5 + 120, var6 + 24); 145 itemRenderer.renderItemOverlayIntoGUI(this.fontRenderer, this.mc.renderEngine, var11, var5 + 120, var6 + 24); 146 itemRenderer.zLevel = 0.0F; 147 GL11.glDisable(GL11.GL_LIGHTING); 148 149 if (this.func_74188_c(36, 24, 16, 16, par1, par2)) 150 { 151 this.func_74184_a(var9, par1, par2); 152 } 153 else if (var10 != null && this.func_74188_c(62, 24, 16, 16, par1, par2)) 154 { 155 this.func_74184_a(var10, par1, par2); 156 } 157 else if (this.func_74188_c(120, 24, 16, 16, par1, par2)) 158 { 159 this.func_74184_a(var11, par1, par2); 160 } 161 162 GL11.glPopMatrix(); 163 GL11.glEnable(GL11.GL_LIGHTING); 164 GL11.glEnable(GL11.GL_DEPTH_TEST); 165 RenderHelper.enableStandardItemLighting(); 166 } 167 } 168 169 public IMerchant func_74199_h() 170 { 171 return this.field_74203_o; 172 } 173 }