Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mrolas.muchMoney.common.gui;
- import java.util.List;
- import mrolas.muchMoney.common.gui.container.ContainerCoinBank;
- import mrolas.muchMoney.common.gui.elements.coinBank.GuiRect;
- import mrolas.muchMoney.common.lib.EnumCoins;
- import mrolas.muchMoney.common.lib.Reference;
- import mrolas.muchMoney.common.network.PacketHandler;
- import mrolas.muchMoney.common.tileEntities.TileEntityCoinBank;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.gui.GuiButton;
- import net.minecraft.client.gui.inventory.GuiContainer;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.util.ResourceLocation;
- import org.lwjgl.opengl.GL11;
- public class GuiCoinBank
- extends GuiContainer
- {
- private static final ResourceLocation texture = new ResourceLocation("muchmoney", "textures/gui/coin_bank.png");
- private TileEntityCoinBank coinBank;
- private GuiRect lock;
- public GuiCoinBank (InventoryPlayer inventory, TileEntityCoinBank entity)
- {
- super(new ContainerCoinBank(inventory, entity));
- this.coinBank = entity;
- xSize = 223;
- ySize = 242;
- }
- @Override
- protected void drawGuiContainerBackgroundLayer (float f, int i, int j)
- {
- GL11.glColor4f(1, 1, 1, 1);
- Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
- drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
- int srcY = 0;
- if (coinBank.locked)
- {
- srcY += 18;
- }
- lock = new GuiRect(83, 30, 18, 18);
- lock.draw(this, xSize, srcY);
- }
- @Override
- protected void drawGuiContainerForegroundLayer (int i, int j)
- {
- fontRenderer.drawString("Coin Bank", 86, 12, Reference.HEX_DARK_GREY);
- //Stored Coin Value
- fontRenderer.drawString("Stored", 179, 32, Reference.HEX_DARK_GREY);
- fontRenderer.drawString("Coins", 179, 43, Reference.HEX_DARK_GREY);
- for (EnumCoins c : EnumCoins.values())
- {
- fontRenderer.drawString(getCoinValueString(c), 179, 57 + 12*c.ord, Reference.HEX_WHITE);
- }
- if (coinBank.getHasError())
- {
- //Error Message
- fontRenderer.drawString(coinBank.getError(), 176 / 2 - fontRenderer.getStringWidth(coinBank.getError()) / 2, 57, Reference.HEX_RED);
- }
- else
- {
- //Withdrawl labels
- fontRenderer.drawString(coinBank.getWithdrawlO() + "", 16 - fontRenderer.getStringWidth(coinBank.getWithdrawlO() + "") / 2, 57, Reference.HEX_DARK_GREY);
- fontRenderer.drawString(coinBank.getWithdrawlP() + "", 52 - fontRenderer.getStringWidth(coinBank.getWithdrawlP() + "") / 2, 57, Reference.HEX_DARK_GREY);
- fontRenderer.drawString(coinBank.getWithdrawlG() + "", 88 - fontRenderer.getStringWidth(coinBank.getWithdrawlG() + "") / 2, 57, Reference.HEX_DARK_GREY);
- fontRenderer.drawString(coinBank.getWithdrawlS() + "", 124 - fontRenderer.getStringWidth(coinBank.getWithdrawlS() + "") / 2, 57, Reference.HEX_DARK_GREY);
- fontRenderer.drawString(coinBank.getWithdrawlC() + "", 160 - fontRenderer.getStringWidth(coinBank.getWithdrawlC() + "") / 2, 57, Reference.HEX_DARK_GREY);
- }
- //Owner
- if (coinBank.locked)
- {
- if (lock.inRect(this, i, j))
- {
- lock.drawString(this, i, j, "Owner:\n " + coinBank.owner);
- }
- }
- }
- @Override
- public void initGui()
- {
- super.initGui();
- buttonList.clear();
- GuiButton depositButton = new GuiButton(0, guiLeft + 7, guiTop + 7, 50, 18, "Deposit");
- buttonList.add(depositButton);
- GuiButton clearButton = new GuiButton(1, guiLeft + 7, guiTop + 31, 35, 18, "Clear");
- buttonList.add(clearButton);
- GuiButton withdrawlButton = new GuiButton(2, guiLeft + 7, guiTop + 137, 68, 18, "Withdrawl");
- withdrawlButton.enabled = !coinBank.getHasError();
- buttonList.add(withdrawlButton);
- GuiButton copper1 = new GuiButton(3, guiLeft + 151, guiTop + 91, 18, 18, "+1");
- GuiButton copper8 = new GuiButton(4, guiLeft + 151, guiTop + 113, 18, 18, "+8");
- buttonList.add(copper1);
- buttonList.add(copper8);
- GuiButton silver1 = new GuiButton(5, guiLeft + 115, guiTop + 91, 18, 18, "+1");
- GuiButton silver8 = new GuiButton(6, guiLeft + 115, guiTop + 113, 18, 18, "+8");
- buttonList.add(silver1);
- buttonList.add(silver8);
- GuiButton gold1 = new GuiButton(7, guiLeft + 79, guiTop + 91, 18, 18, "+1");
- GuiButton gold8 = new GuiButton(8, guiLeft + 79, guiTop + 113, 18, 18, "+8");
- buttonList.add(gold1);
- buttonList.add(gold8);
- GuiButton platinum1 = new GuiButton(9, guiLeft + 43, guiTop + 91, 18, 18, "+1");
- GuiButton platinum8 = new GuiButton(10, guiLeft + 43, guiTop + 113, 18, 18, "+8");
- buttonList.add(platinum1);
- buttonList.add(platinum8);
- GuiButton osmium1 = new GuiButton(11, guiLeft + 7, guiTop + 91, 18, 18, "+1");
- GuiButton osmium8 = new GuiButton(12, guiLeft + 7, guiTop + 113, 18, 18, "+8");
- buttonList.add(osmium1);
- buttonList.add(osmium8);
- }
- @Override
- protected void actionPerformed (GuiButton button)
- {
- PacketHandler.sendButtonPacket((byte)0, (byte)button.id);
- }
- @Override
- protected void mouseClicked (int i, int j, int button)
- {
- super.mouseClicked(i, j, button);
- if (lock.inRect(this, i, j))
- {
- if (coinBank.locked)
- {
- PacketHandler.sendButtonPacket((byte)0, (byte)13);
- }
- else
- {
- PacketHandler.sendButtonPacket((byte)0, (byte)14);
- }
- }
- }
- private String getCoinValueString (EnumCoins coin)
- {
- long value = coinBank.getStoredValue();
- int o = (int)(value / EnumCoins.osmium.value);
- value = value % EnumCoins.osmium.value;
- int p = (int)(value / EnumCoins.platinum.value);
- value = value % EnumCoins.platinum.value;
- int g = (int)(value / EnumCoins.gold.value);
- value = value % EnumCoins.gold.value;
- int s = (int)(value / EnumCoins.silver.value);
- value = value % EnumCoins.silver.value;
- int c = (int)(value / EnumCoins.copper.value);
- if (coin == EnumCoins.copper)
- {
- return c + " c";
- }
- else if (coin == EnumCoins.silver)
- {
- return s + " s";
- }
- else if (coin == EnumCoins.gold)
- {
- return g + " g";
- }
- else if (coin == EnumCoins.platinum)
- {
- return p + " p";
- }
- else if (coin == EnumCoins.osmium)
- {
- if (o > 10000000)
- return (o / 1000000) + "kk o";
- else if (o > 10000)
- return (o / 1000) + "k o";
- else
- return o + " o";
- }
- else
- {
- return null;
- }
- }
- public int getLeft ()
- {
- return guiLeft;
- }
- public int getTop ()
- {
- return guiTop;
- }
- public void drawHoverString (List list, int x, int y)
- {
- drawHoveringText(list, x, y, fontRenderer);
- }
- public byte[] stringToByteArray (String str)
- {
- char[] buffer = str.toCharArray();
- byte[] array = new byte[buffer.length];
- for (int i = 0; i < buffer.length; i++)
- array[i] = (byte)buffer[i];
- return array;
- }
- public String byteArrayToString (byte[] array)
- {
- return new String(array);
- }
- }
Add Comment
Please, Sign In to add comment