Mrolas

GuiCoinBank.java

Dec 31st, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.83 KB | None | 0 0
  1. package mrolas.muchMoney.common.gui;
  2.  
  3. import java.util.List;
  4.  
  5. import mrolas.muchMoney.common.gui.container.ContainerCoinBank;
  6. import mrolas.muchMoney.common.gui.elements.coinBank.GuiRect;
  7. import mrolas.muchMoney.common.lib.EnumCoins;
  8. import mrolas.muchMoney.common.lib.Reference;
  9. import mrolas.muchMoney.common.network.PacketHandler;
  10. import mrolas.muchMoney.common.tileEntities.TileEntityCoinBank;
  11. import net.minecraft.client.Minecraft;
  12. import net.minecraft.client.gui.GuiButton;
  13. import net.minecraft.client.gui.inventory.GuiContainer;
  14. import net.minecraft.entity.player.EntityPlayer;
  15. import net.minecraft.entity.player.InventoryPlayer;
  16. import net.minecraft.util.ResourceLocation;
  17.  
  18. import org.lwjgl.opengl.GL11;
  19.  
  20. public class GuiCoinBank
  21.     extends GuiContainer
  22. {  
  23.     private static final ResourceLocation texture = new ResourceLocation("muchmoney", "textures/gui/coin_bank.png");
  24.    
  25.     private TileEntityCoinBank coinBank;
  26.    
  27.     private GuiRect lock;
  28.    
  29.     public GuiCoinBank (InventoryPlayer inventory, TileEntityCoinBank entity)
  30.     {
  31.         super(new ContainerCoinBank(inventory, entity));
  32.        
  33.         this.coinBank = entity;
  34.        
  35.         xSize = 223;
  36.         ySize = 242;
  37.     }
  38.    
  39.     @Override
  40.     protected void drawGuiContainerBackgroundLayer (float f, int i, int j)
  41.     {
  42.         GL11.glColor4f(1, 1, 1, 1);
  43.        
  44.         Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
  45.         drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
  46.        
  47.         int srcY = 0;
  48.         if (coinBank.locked)
  49.         {
  50.             srcY += 18;
  51.         }
  52.         lock = new GuiRect(83, 30, 18, 18);
  53.         lock.draw(this, xSize, srcY);
  54.     }
  55.    
  56.     @Override
  57.     protected void drawGuiContainerForegroundLayer (int i, int j)
  58.     {
  59.         fontRenderer.drawString("Coin Bank", 86, 12, Reference.HEX_DARK_GREY);
  60.        
  61.         //Stored Coin Value
  62.         fontRenderer.drawString("Stored", 179, 32, Reference.HEX_DARK_GREY);
  63.         fontRenderer.drawString("Coins", 179, 43, Reference.HEX_DARK_GREY);
  64.         for (EnumCoins c : EnumCoins.values())
  65.         {
  66.             fontRenderer.drawString(getCoinValueString(c), 179, 57 + 12*c.ord, Reference.HEX_WHITE);
  67.         }
  68.        
  69.         if (coinBank.getHasError())
  70.         {
  71.             //Error Message
  72.             fontRenderer.drawString(coinBank.getError(), 176 / 2 - fontRenderer.getStringWidth(coinBank.getError()) / 2, 57, Reference.HEX_RED);
  73.         }
  74.         else
  75.         {
  76.             //Withdrawl labels
  77.             fontRenderer.drawString(coinBank.getWithdrawlO() + "", 16 - fontRenderer.getStringWidth(coinBank.getWithdrawlO() + "") / 2, 57, Reference.HEX_DARK_GREY);
  78.             fontRenderer.drawString(coinBank.getWithdrawlP() + "", 52 - fontRenderer.getStringWidth(coinBank.getWithdrawlP() + "") / 2, 57, Reference.HEX_DARK_GREY);
  79.             fontRenderer.drawString(coinBank.getWithdrawlG() + "", 88 - fontRenderer.getStringWidth(coinBank.getWithdrawlG() + "") / 2, 57, Reference.HEX_DARK_GREY);
  80.             fontRenderer.drawString(coinBank.getWithdrawlS() + "", 124 - fontRenderer.getStringWidth(coinBank.getWithdrawlS() + "") / 2, 57, Reference.HEX_DARK_GREY);
  81.             fontRenderer.drawString(coinBank.getWithdrawlC() + "", 160 - fontRenderer.getStringWidth(coinBank.getWithdrawlC() + "") / 2, 57, Reference.HEX_DARK_GREY);
  82.         }
  83.        
  84.         //Owner
  85.         if (coinBank.locked)
  86.         {
  87.             if (lock.inRect(this, i, j))
  88.             {
  89.                 lock.drawString(this, i, j, "Owner:\n   " + coinBank.owner);
  90.             }
  91.         }
  92.     }
  93.    
  94.     @Override
  95.     public void initGui()
  96.     {
  97.         super.initGui();
  98.         buttonList.clear();
  99.        
  100.         GuiButton depositButton = new GuiButton(0, guiLeft + 7, guiTop + 7, 50, 18, "Deposit");
  101.         buttonList.add(depositButton);
  102.        
  103.         GuiButton clearButton = new GuiButton(1, guiLeft + 7, guiTop + 31, 35, 18, "Clear");
  104.         buttonList.add(clearButton);
  105.        
  106.         GuiButton withdrawlButton = new GuiButton(2, guiLeft + 7, guiTop + 137, 68, 18, "Withdrawl");
  107.         withdrawlButton.enabled = !coinBank.getHasError();
  108.         buttonList.add(withdrawlButton);
  109.        
  110.         GuiButton copper1 = new GuiButton(3, guiLeft + 151, guiTop + 91, 18, 18, "+1");
  111.         GuiButton copper8 = new GuiButton(4, guiLeft + 151, guiTop + 113, 18, 18, "+8");
  112.         buttonList.add(copper1);
  113.         buttonList.add(copper8);
  114.        
  115.         GuiButton silver1 = new GuiButton(5, guiLeft + 115, guiTop + 91, 18, 18, "+1");
  116.         GuiButton silver8 = new GuiButton(6, guiLeft + 115, guiTop + 113, 18, 18, "+8");
  117.         buttonList.add(silver1);
  118.         buttonList.add(silver8);
  119.        
  120.         GuiButton gold1 = new GuiButton(7, guiLeft + 79, guiTop + 91, 18, 18, "+1");
  121.         GuiButton gold8 = new GuiButton(8, guiLeft + 79, guiTop + 113, 18, 18, "+8");
  122.         buttonList.add(gold1);
  123.         buttonList.add(gold8);
  124.        
  125.         GuiButton platinum1 = new GuiButton(9, guiLeft + 43, guiTop + 91, 18, 18, "+1");
  126.         GuiButton platinum8 = new GuiButton(10, guiLeft + 43, guiTop + 113, 18, 18, "+8");
  127.         buttonList.add(platinum1);
  128.         buttonList.add(platinum8);
  129.        
  130.         GuiButton osmium1 = new GuiButton(11, guiLeft + 7, guiTop + 91, 18, 18, "+1");
  131.         GuiButton osmium8 = new GuiButton(12, guiLeft + 7, guiTop + 113, 18, 18, "+8");
  132.         buttonList.add(osmium1);
  133.         buttonList.add(osmium8);
  134.     }
  135.    
  136.     @Override
  137.     protected void actionPerformed (GuiButton button)
  138.     {
  139.         PacketHandler.sendButtonPacket((byte)0, (byte)button.id);
  140.     }
  141.    
  142.     @Override
  143.     protected void mouseClicked (int i, int j, int button)
  144.     {
  145.         super.mouseClicked(i, j, button);
  146.        
  147.         if (lock.inRect(this, i, j))
  148.         {
  149.             if (coinBank.locked)
  150.             {
  151.                 PacketHandler.sendButtonPacket((byte)0, (byte)13);
  152.             }
  153.             else
  154.             {
  155.                 PacketHandler.sendButtonPacket((byte)0, (byte)14);
  156.             }
  157.         }
  158.     }
  159.    
  160.     private String getCoinValueString (EnumCoins coin)
  161.     {
  162.         long value = coinBank.getStoredValue();
  163.         int o = (int)(value / EnumCoins.osmium.value);
  164.         value = value % EnumCoins.osmium.value;
  165.         int p = (int)(value / EnumCoins.platinum.value);
  166.         value = value % EnumCoins.platinum.value;
  167.         int g = (int)(value / EnumCoins.gold.value);
  168.         value = value % EnumCoins.gold.value;
  169.         int s = (int)(value / EnumCoins.silver.value);
  170.         value = value % EnumCoins.silver.value;
  171.         int c = (int)(value / EnumCoins.copper.value);
  172.        
  173.         if (coin == EnumCoins.copper)
  174.         {
  175.             return c + " c";
  176.         }
  177.         else if (coin == EnumCoins.silver)
  178.         {
  179.             return s + " s";
  180.         }
  181.         else if (coin == EnumCoins.gold)
  182.         {
  183.             return g + " g";
  184.         }
  185.         else if (coin == EnumCoins.platinum)
  186.         {
  187.             return p + " p";
  188.         }
  189.         else if (coin == EnumCoins.osmium)
  190.         {
  191.             if (o > 10000000)
  192.                 return (o / 1000000) + "kk o";
  193.             else if (o > 10000)
  194.                 return (o / 1000) + "k o";
  195.             else
  196.                 return o + " o";
  197.         }
  198.         else
  199.         {
  200.             return null;
  201.         }
  202.     }
  203.    
  204.     public int getLeft ()
  205.     {
  206.         return guiLeft;
  207.     }
  208.    
  209.     public int getTop ()
  210.     {
  211.         return guiTop;
  212.     }
  213.    
  214.     public void drawHoverString (List list, int x, int y)
  215.     {
  216.         drawHoveringText(list, x, y, fontRenderer);
  217.     }
  218.    
  219.     public byte[] stringToByteArray (String str)
  220.     {
  221.         char[] buffer = str.toCharArray();
  222.         byte[] array = new byte[buffer.length];
  223.         for (int i = 0; i < buffer.length; i++)
  224.             array[i] = (byte)buffer[i];
  225.         return array;
  226.     }
  227.    
  228.     public String byteArrayToString (byte[] array)
  229.     {
  230.         return new String(array);
  231.     }
  232. }
Add Comment
Please, Sign In to add comment