OSDN Git Service

化学作業台のBlock画像追加
[chemicraft/chemicraft.git] / common / chemicraft / GuiChemicalCraftingTable.java
1 package chemicraft;\r
2 \r
3 import java.util.ArrayList;\r
4 import java.util.HashMap;\r
5 \r
6 import net.minecraft.src.Block;\r
7 import net.minecraft.src.EntityPlayer;\r
8 import net.minecraft.src.GuiContainer;\r
9 import net.minecraft.src.InventoryBasic;\r
10 import net.minecraft.src.InventoryPlayer;\r
11 import net.minecraft.src.ItemStack;\r
12 import cpw.mods.fml.common.Side;\r
13 import cpw.mods.fml.common.asm.SideOnly;\r
14 import cpw.mods.fml.common.network.PacketDispatcher;\r
15 import cpw.mods.fml.common.network.Player;\r
16 \r
17 @SideOnly(Side.CLIENT)\r
18 public class GuiChemicalCraftingTable extends GuiContainer {\r
19 \r
20         /**\r
21          * 分解機GUIのInventoryBasicクラス\r
22          */\r
23         private static InventoryBasic decompositionSlots = new InventoryBasic("Decomposition", 17);\r
24 \r
25 \r
26         /**\r
27          * TabListのArrayList\r
28          */\r
29         private ArrayList<ChemiCraftTab> tabList = new ArrayList<ChemiCraftTab>();\r
30 \r
31 \r
32         /**\r
33          * Gui画像のHashMap\r
34          * キーの名前は拡張子を除くファイル名にする\r
35          */\r
36         private HashMap<String, Integer> guiImageMap = new HashMap<String, Integer>();\r
37 \r
38 \r
39         /**\r
40          * 画像のHashMap\r
41          * キーの名前は拡張子を除くファイル名にする\r
42          */\r
43         private HashMap<String, Integer> otherImageMap = new HashMap<String, Integer>();\r
44 \r
45 \r
46         /**\r
47          * the TileEntity.\r
48          */\r
49         private TileEntityChemicalCraftingTable tileEntity;\r
50 \r
51 \r
52         /**\r
53          * the InventoryPlayer.\r
54          */\r
55         private InventoryPlayer inventoryPlayer;\r
56 \r
57 \r
58         /**\r
59          * the Container\r
60          */\r
61         private ContainerChemicalCraftingTable container;\r
62 \r
63 \r
64 \r
65         public GuiChemicalCraftingTable(EntityPlayer par1EntityPlayer, TileEntityChemicalCraftingTable par2){\r
66                 super(new ContainerChemicalCraftingTable(par1EntityPlayer, par2));\r
67                 //TileEntityを設定\r
68                 this.inventoryPlayer = par1EntityPlayer.inventory;\r
69                 this.tileEntity = par2;\r
70                 this.container = (ContainerChemicalCraftingTable) this.inventorySlots;\r
71                 //TabListにTabを追加する\r
72                 this.addTabs(0, "Decomposition", new ItemStack(Block.tnt.blockID, 1, 1));\r
73                 this.addTabs(1, "Test", new ItemStack(Block.bedrock.blockID, 1, 1));\r
74                 //ActiveTabの初期化\r
75                 for(int i = 0;i < tabList.size();i++){\r
76                         String field_00001 = this.tabList.get(i).getTabName();\r
77                         String field_00002 = this.tileEntity.getActiveTab();\r
78                         if(field_00001.equals(field_00002)){\r
79                                 this.tileEntity.setActiveTab(this.tabList.get(i).getTabName());\r
80                         }\r
81                 }\r
82         }\r
83 \r
84 \r
85 \r
86         @Override\r
87         protected void mouseClicked(int par1, int par2, int par3){\r
88                 super.mouseClicked(par1, par2, par3);\r
89 \r
90                 int var1 = par1 - this.guiLeft;\r
91                 int var2 = par2 - this.guiTop;\r
92                 if(var1 < this.tabList.size() * 28 && var1 >= 0 && var2 < 0){\r
93                         String var3 = this.tabList.get(var1 / 28).getTabName();\r
94                         if(!var3.equals(this.tileEntity.getActiveTab())){\r
95                                 this.tileEntity.setActiveTab(var3);\r
96                                 this.inventoryPlayer.player.openGui(ChemiCraft.instance, ChemiCraft.instance.guiChemicalCraftingTableID, this.tileEntity.worldObj, this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord);\r
97                                 this.onGuiClosed();\r
98                         }\r
99                 }\r
100         }\r
101 \r
102 \r
103 \r
104         @Override\r
105         protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3){\r
106                 //ActiveTab Reset.\r
107                 this.func_00003();\r
108                 //Texture Load.\r
109                 this.func_00002();\r
110                 //Draw Tabs.\r
111                 this.func_00001(par1, par2, par3);\r
112                 //Draw GUI\r
113                 if(this.tileEntity.getActiveTab().equals("Decomposition")){\r
114                         this.mc.renderEngine.bindTexture(this.guiImageMap.get("Decomposition"));\r
115                         this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);\r
116                 }\r
117         }\r
118 \r
119 \r
120 \r
121         private void func_00001(float par1, int par2, int par3){\r
122                 int var1 = this.guiLeft;\r
123                 int var2 = this.guiTop - 32;\r
124                 for(int i = 0;i < this.tabList.size();i++){\r
125                         if(!this.tabList.get(i).isActive()){\r
126                                 this.mc.renderEngine.bindTexture(this.otherImageMap.get("tabs"));\r
127                                 this.drawTexturedModalRect(var1 + (28 * i), var2, 0, 0, 28, 32);\r
128                                 this.itemRenderer.renderItemIntoGUI(this.fontRenderer, this.mc.renderEngine, this.tabList.get(i).getRenderItemStack(), var1 + (28 * i) + 6, var2 + 9);\r
129                                 this.itemRenderer.renderItemOverlayIntoGUI(this.fontRenderer, this.mc.renderEngine, this.tabList.get(i).getRenderItemStack(), var1 + (28 * i) + 6, var2 + 9);\r
130                         }else{\r
131                                 this.mc.renderEngine.bindTexture(this.otherImageMap.get("tabs"));\r
132                                 this.drawTexturedModalRect(var1 + (28 * i), var2, 0, 32, 28, 32);\r
133                                 this.itemRenderer.renderItemIntoGUI(this.fontRenderer, this.mc.renderEngine, this.tabList.get(i).getRenderItemStack(), var1 + (28 * i) + 6, var2 + 9);\r
134                                 this.itemRenderer.renderItemOverlayIntoGUI(this.fontRenderer, this.mc.renderEngine, this.tabList.get(i).getRenderItemStack(), var1 + (28 * i) + 6, var2 + 9);\r
135                         }\r
136                 }\r
137         }\r
138 \r
139 \r
140 \r
141         private void func_00002(){\r
142                 //guiImageMapに画像を格納する\r
143                 guiImageMap.put("Decomposition", this.mc.renderEngine.getTexture("/resources/chemicraft/guis/Decomposition.png"));\r
144                 //otherImageMapに画像を格納する\r
145                 otherImageMap.put("tabs", this.mc.renderEngine.getTexture("/resources/chemicraft/guis/tabs.png"));\r
146         }\r
147 \r
148 \r
149 \r
150         private void func_00003(){\r
151                 for(int i = 0;i < this.tabList.size();i++){\r
152                         if(!this.tabList.get(i).getTabName().equals(this.tileEntity.getActiveTab())){\r
153                                 this.tabList.get(i).setActive(false);\r
154                         }else{\r
155                                 this.tabList.get(i).setActive(true);\r
156                         }\r
157                 }\r
158         }\r
159 \r
160 \r
161 \r
162         /**\r
163          * ChemiCraftTabを追加します。\r
164          * @param id TabのID\r
165          * @param texture OverlayするTextureID\r
166          * @param name Tabの名前\r
167          * @throws Exception IDが重複している場合にスローされます\r
168          */\r
169         private void addTabs(int id, String name, ItemStack renderItemStack){\r
170                 for(int i = 0;i < this.tabList.size();i++){\r
171                         if(id == this.tabList.get(i).getID()){\r
172                                 try {\r
173                                         throw new Exception("ChemiCraft内でエラー:ChemiCraftTabのIDが重複しています");\r
174                                 } catch (Exception e) {\r
175                                         e.printStackTrace();\r
176                                 }\r
177                         }\r
178                 }\r
179                 this.tabList.add(new ChemiCraftTab(id, name, renderItemStack));\r
180         }\r
181 \r
182 }\r