OSDN Git Service

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