OSDN Git Service

とりあえずGUIのTabの切り替えできるようにした
authormozipi <mozipi@users.sourceforge.jp>
Sun, 9 Dec 2012 09:59:04 +0000 (18:59 +0900)
committermozipi <mozipi@users.sourceforge.jp>
Sun, 9 Dec 2012 09:59:04 +0000 (18:59 +0900)
common/chemicraft/AtomInfo.java
common/chemicraft/ChemiCraftTab.java
common/chemicraft/GuiScienceCraftingTable.java
common/chemicraft/PacketHandler.java
common/chemicraft/TileEntityScienceCraftingTable.java

index 73630f5..264b35a 100644 (file)
@@ -37,6 +37,8 @@ public class AtomInfo {
         */\r
        private World world;\r
 \r
+\r
+\r
        /**\r
         * AtomInfoのデータをupdateします\r
         * @param par1World Worldのインスタンス\r
index 1caba5f..acc7711 100644 (file)
@@ -1,5 +1,7 @@
 package chemicraft;\r
 \r
+import net.minecraft.src.ItemStack;\r
+\r
 public class ChemiCraftTab {\r
 \r
        /**\r
@@ -9,9 +11,9 @@ public class ChemiCraftTab {
 \r
 \r
        /**\r
-        * TabにOverlayするTextureID\r
+        * TabにOverlayするItemStack\r
         */\r
-       private int texture;\r
+       private ItemStack renderItemStack;\r
 \r
 \r
        /**\r
@@ -29,13 +31,13 @@ public class ChemiCraftTab {
 \r
        /**\r
         * ChemiCraftTabを作成します\r
-        * @param id TabのID\r
-        * @param texture TabにOverlayする画像のTextureID\r
-        * @param tabName Tabの名前(最初は大文字にすること)\r
+        * @param id\r
+        * @param tabName\r
+        * @param renderItemStack\r
         */\r
-       public ChemiCraftTab(int id, int texture, String tabName){\r
+       public ChemiCraftTab(int id, String tabName, ItemStack renderItemStack){\r
                this.id = id;\r
-               this.texture = texture;\r
+               this.renderItemStack = renderItemStack;\r
                this.tabName = tabName;\r
        }\r
 \r
@@ -52,11 +54,11 @@ public class ChemiCraftTab {
 \r
 \r
        /**\r
-        * TabにOverlayするTextureIDを返します\r
-        * @return TabにOverlayするTextureID\r
+        * TabにOverlayするItemStackを返します\r
+        * @return TabにOverlayするItemStack\r
         */\r
-       public int getTexture(){\r
-               return this.texture;\r
+       public ItemStack getRenderItemStack(){\r
+               return this.renderItemStack;\r
        }\r
 \r
 \r
index b85bac6..1f55bda 100644 (file)
@@ -3,10 +3,11 @@ package chemicraft;
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import net.minecraft.src.Block;
 import net.minecraft.src.GuiContainer;
 import net.minecraft.src.InventoryBasic;
 import net.minecraft.src.InventoryPlayer;
-import net.minecraft.src.Item;
+import net.minecraft.src.ItemStack;
 import cpw.mods.fml.common.Side;
 import cpw.mods.fml.common.asm.SideOnly;
 
@@ -49,10 +50,14 @@ public class GuiScienceCraftingTable extends GuiContainer {
        public GuiScienceCraftingTable(InventoryPlayer par1InventoryPlayer, TileEntityScienceCraftingTable par2){
                super(new ContainerScienceCraftingTable(par1InventoryPlayer, par2));
                //TabListにTabを追加する
-               tabList.add(new ChemiCraftTab(0, Item.potion.getIconFromDamage(0), "Decomposition"));
+               this.addTabs(0, "Decomposition", new ItemStack(Block.tnt.blockID, 1, 1));
+               this.addTabs(1, "Test", new ItemStack(Block.bedrock.blockID, 1, 1));
                //ActiveTabの初期化
-               /*未実装*/
-               /*Debug*/ this.tabList.get(0).setActive(true); for(int i = 0;i < tabList.size();i++){ if(this.tabList.get(i).isActive()){ this.activeTabName = this.tabList.get(i).getTabName(); } }
+               for(int i = 0;i < tabList.size();i++){
+                       if(this.tabList.get(i).getTabName().equals(par2.getActiveTab())){
+                               this.activeTabName = this.tabList.get(i).getTabName();
+                       }
+               }
        }
 
 
@@ -60,12 +65,23 @@ public class GuiScienceCraftingTable extends GuiContainer {
        @Override
        protected void mouseClicked(int par1, int par2, int par3){
                super.mouseClicked(par1, par2, par3);
+
+               int var1 = par1 - this.guiLeft;
+               int var2 = par2 - this.guiTop;
+               if(var1 < this.tabList.size() * 28 && var1 >= 0){
+                       String var3 = this.tabList.get(var1 / 28).getTabName();
+                       if(!var3.equals(this.activeTabName)){
+                               this.activeTabName = var3;
+                       }
+               }
        }
 
 
 
        @Override
        protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3){
+               //Active Reset
+               this.func_00003();
                //Texture Load.
                this.func_00002();
                //Draw Tabs.
@@ -86,11 +102,13 @@ public class GuiScienceCraftingTable extends GuiContainer {
                        if(!this.tabList.get(i).isActive()){
                                this.mc.renderEngine.bindTexture(this.otherImageMap.get("tabs"));
                                this.drawTexturedModalRect(var1 + (28 * i), var2, 0, 0, 28, 32);
-                               this.mc.renderEngine.bindTexture(this.tabList.get(i).getTexture());
-                               this.drawTexturedModalRect(var1 + (28 * i) + 14, var2 + 16, 0, 0, 16, 16);
+                               this.itemRenderer.renderItemIntoGUI(this.fontRenderer, this.mc.renderEngine, this.tabList.get(i).getRenderItemStack(), var1 + (28 * i) + 6, var2 + 9);
+                               this.itemRenderer.renderItemOverlayIntoGUI(this.fontRenderer, this.mc.renderEngine, this.tabList.get(i).getRenderItemStack(), var1 + (28 * i) + 6, var2 + 9);
                        }else{
                                this.mc.renderEngine.bindTexture(this.otherImageMap.get("tabs"));
                                this.drawTexturedModalRect(var1 + (28 * i), var2, 0, 32, 28, 32);
+                               this.itemRenderer.renderItemIntoGUI(this.fontRenderer, this.mc.renderEngine, this.tabList.get(i).getRenderItemStack(), var1 + (28 * i) + 6, var2 + 9);
+                               this.itemRenderer.renderItemOverlayIntoGUI(this.fontRenderer, this.mc.renderEngine, this.tabList.get(i).getRenderItemStack(), var1 + (28 * i) + 6, var2 + 9);
                        }
                }
        }
@@ -106,6 +124,18 @@ public class GuiScienceCraftingTable extends GuiContainer {
 
 
 
+       private void func_00003(){
+               for(int i = 0;i < this.tabList.size();i++){
+                       if(!this.tabList.get(i).getTabName().equals(this.activeTabName)){
+                               this.tabList.get(i).setActive(false);
+                       }else{
+                               this.tabList.get(i).setActive(true);
+                       }
+               }
+       }
+
+
+
        /**
         * Activeなtabの名前を返します
         * @return ActiveなTabの名前
@@ -133,7 +163,7 @@ public class GuiScienceCraftingTable extends GuiContainer {
         * @param name Tabの名前
         * @throws Exception IDが重複している場合にスローされます
         */
-       private void addTabs(int id, int texture, String name){
+       private void addTabs(int id, String name, ItemStack renderItemStack){
                for(int i = 0;i < this.tabList.size();i++){
                        if(id == this.tabList.get(i).getID()){
                                try {
@@ -143,7 +173,7 @@ public class GuiScienceCraftingTable extends GuiContainer {
                                }
                        }
                }
-               this.tabList.add(new ChemiCraftTab(id, texture, name));
+               this.tabList.add(new ChemiCraftTab(id, name, renderItemStack));
        }
 
 }
index a55e9c5..bd26cda 100644 (file)
@@ -18,58 +18,58 @@ import cpw.mods.fml.common.network.Player;
 \r
 /**\r
  * サーバーとクライアントのデータの同期に必要なクラス\r
- * \r
+ *\r
  * @author Lilly\r
- * \r
+ *\r
  */\r
 public class PacketHandler implements IPacketHandler {\r
 \r
-    @Override\r
-    public void onPacketData(NetworkManager manager, Packet250CustomPayload packet, Player player) {\r
-       if (packet.channel.equals("chemicraft")) {\r
-           ByteArrayDataInput var1 = ByteStreams.newDataInput(packet.data);\r
-           int x, y, z;\r
+       @Override\r
+       public void onPacketData(NetworkManager manager, Packet250CustomPayload packet, Player player) {\r
+               if (packet.channel.equals("chemicraft")) {\r
+                       ByteArrayDataInput var1 = ByteStreams.newDataInput(packet.data);\r
+                       int x, y, z;\r
 \r
-           // パケットからデータ読み込み\r
-           x = var1.readInt();\r
-           y = var1.readInt();\r
-           z = var1.readInt();\r
+                       // パケットからデータ読み込み\r
+                       x = var1.readInt();\r
+                       y = var1.readInt();\r
+                       z = var1.readInt();\r
 \r
-           // TileEntityを取得し読み込んだデータを送る\r
-           World world = ChemiCraft.proxy.getClientWorld();\r
-           TileEntity tileEntity = world.getBlockTileEntity(x, y, z);\r
-           if (tileEntity instanceof TileEntityScienceCraftingTable) {\r
-               TileEntityScienceCraftingTable var2 = (TileEntityScienceCraftingTable) tileEntity;\r
-               var2.handlePacket(null);\r
-           }\r
+                       // TileEntityを取得し読み込んだデータを送る\r
+                       World world = ChemiCraft.proxy.getClientWorld();\r
+                       TileEntity tileEntity = world.getBlockTileEntity(x, y, z);\r
+                       if (tileEntity instanceof TileEntityScienceCraftingTable) {\r
+                               TileEntityScienceCraftingTable var2 = (TileEntityScienceCraftingTable) tileEntity;\r
+                               var2.handlePacket(null);\r
+                       }\r
+               }\r
        }\r
-    }\r
 \r
 \r
-    public static Packet getPacket(TileEntityScienceCraftingTable tileEntity) {\r
-       ByteArrayOutputStream var1 = new ByteArrayOutputStream(128);\r
-       DataOutputStream var2 = new DataOutputStream(var1);\r
-       int x, y, z;\r
+       public static Packet getPacket(TileEntityScienceCraftingTable tileEntity) {\r
+               ByteArrayOutputStream var1 = new ByteArrayOutputStream(128);\r
+               DataOutputStream var2 = new DataOutputStream(var1);\r
+               int x, y, z;\r
 \r
-       // データの用意\r
-       x = tileEntity.xCoord;\r
-       y = tileEntity.yCoord;\r
-       z = tileEntity.zCoord;\r
+               // データの用意\r
+               x = tileEntity.xCoord;\r
+               y = tileEntity.yCoord;\r
+               z = tileEntity.zCoord;\r
 \r
-       try {\r
-           var2.writeInt(x);\r
-           var2.writeInt(y);\r
-           var2.writeInt(z);\r
-       } catch (IOException e) {\r
-           e.printStackTrace();\r
-       }\r
+               try {\r
+                       var2.writeInt(x);\r
+                       var2.writeInt(y);\r
+                       var2.writeInt(z);\r
+               } catch (IOException e) {\r
+                       e.printStackTrace();\r
+               }\r
 \r
-       // パケットの作成\r
-       Packet250CustomPayload packet = new Packet250CustomPayload();\r
-       packet.channel = "chemicraft";\r
-       packet.data = var1.toByteArray();\r
-       packet.length = var1.size();\r
-       packet.isChunkDataPacket = true;\r
-       return packet;\r
-    }\r
+               // パケットの作成\r
+               Packet250CustomPayload packet = new Packet250CustomPayload();\r
+               packet.channel = "chemicraft";\r
+               packet.data = var1.toByteArray();\r
+               packet.length = var1.size();\r
+               packet.isChunkDataPacket = true;\r
+               return packet;\r
+       }\r
 }\r
index 0568574..0e26ea7 100644 (file)
@@ -11,108 +11,124 @@ import net.minecraftforge.common.ISidedInventory;
 
 public class TileEntityScienceCraftingTable extends TileEntity implements IInventory, ISidedInventory {
 
-    /**
-     * InventorySlotのItemStack配列
-     */
-    private ItemStack[] inventory = new ItemStack[17];
+       /**
+        * InventorySlotのItemStack配列
+        */
+       private ItemStack[] inventory = new ItemStack[17];
 
 
-    public TileEntityScienceCraftingTable() {
-    }
+       /**
+        * ActiveなTabの名前
+        */
+       private String activeTab;
 
 
-    @Override
-    public void updateEntity() {
-       super.updateEntity();
-    }
 
+       public TileEntityScienceCraftingTable() {
+               //ActiveTabのデフォルトを設定
+               this.activeTab = "Decomposition";
+       }
 
-    @Override
-    public void readFromNBT(NBTTagCompound par1) {
-    }
 
+       @Override
+       public void updateEntity() {
+               super.updateEntity();
+       }
 
-    @Override
-    public void writeToNBT(NBTTagCompound par1) {
-    }
 
+       @Override
+       public void readFromNBT(NBTTagCompound par1) {
+               par1.setString("activeTab", this.activeTab);
+       }
 
-    @Override
-    public int getSizeInventory() {
-       return inventory.length;
-    }
 
+       @Override
+       public void writeToNBT(NBTTagCompound par1) {
+               this.activeTab = par1.getString("activeTab");
+       }
 
-    @Override
-    public ItemStack getStackInSlot(int var1) {
-       return inventory[var1];
-    }
 
+       public String getActiveTab(){
+               return this.activeTab;
+       }
 
-    @Override
-    public ItemStack decrStackSize(int var1, int var2) {
-       return null;
-    }
 
+       @Override
+       public int getSizeInventory() {
+               return inventory.length;
+       }
 
-    @Override
-    public ItemStack getStackInSlotOnClosing(int var1) {
-       return null;
-    }
 
+       @Override
+       public ItemStack getStackInSlot(int var1) {
+               return inventory[var1];
+       }
 
-    @Override
-    public void setInventorySlotContents(int var1, ItemStack var2) {
-    }
 
+       @Override
+       public ItemStack decrStackSize(int var1, int var2) {
+               return null;
+       }
 
-    @Override
-    public String getInvName() {
-       return null;
-    }
 
+       @Override
+       public ItemStack getStackInSlotOnClosing(int var1) {
+               return null;
+       }
 
-    @Override
-    public int getInventoryStackLimit() {
-       return 64;
-    }
 
+       @Override
+       public void setInventorySlotContents(int var1, ItemStack var2) {
+       }
 
-    @Override
-    public boolean isUseableByPlayer(EntityPlayer var1) {
-       return false;
-    }
 
+       @Override
+       public String getInvName() {
+               return null;
+       }
 
-    @Override
-    public void openChest() {
-    }
 
+       @Override
+       public int getInventoryStackLimit() {
+               return 64;
+       }
 
-    @Override
-    public void closeChest() {
-    }
 
+       @Override
+       public boolean isUseableByPlayer(EntityPlayer var1) {
+               return false;
+       }
 
-    @Override
-    public Packet getDescriptionPacket() {
-       return PacketHandler.getPacket(this);
-    }
 
+       @Override
+       public void openChest() {
+       }
 
-    public void handlePacket(Object[] data) {
 
-    }
+       @Override
+       public void closeChest() {
+       }
 
 
-    @Override
-    public int getStartInventorySide(ForgeDirection side) {
-       return 0;
-    }
+       @Override
+       public Packet getDescriptionPacket() {
+               return PacketHandler.getPacket(this);
+       }
 
 
-    @Override
-    public int getSizeInventorySide(ForgeDirection side) {
-       return 0;
-    }
+       public void handlePacket(Object[] data) {
+
+       }
+
+
+       @Override
+       public int getStartInventorySide(ForgeDirection side) {
+               return 0;
+       }
+
+
+       @Override
+       public int getSizeInventorySide(ForgeDirection side) {
+               return 0;
+       }
 }