diff options
author | Kiwi <42833050+Kiwi233@users.noreply.github.com> | 2020-05-24 08:28:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-24 08:28:19 +0800 |
commit | f0bce85d3faf040d87a22d83250ae2d9767c3642 (patch) | |
tree | ed60c1d975c8b06a27cae03d148714f7bb9e9805 /src/main/java/gregtech/common/gui | |
parent | ac7282a30ef161101cabc921e52db5c5d7e0096c (diff) | |
parent | d6c19a9b6434c8a4c59ea8452603f85cfd2ad208 (diff) | |
download | GT5-Unofficial-f0bce85d3faf040d87a22d83250ae2d9767c3642.tar.gz GT5-Unofficial-f0bce85d3faf040d87a22d83250ae2d9767c3642.tar.bz2 GT5-Unofficial-f0bce85d3faf040d87a22d83250ae2d9767c3642.zip |
Merge pull request #1 from GTNewHorizons/experimental
5/24
Diffstat (limited to 'src/main/java/gregtech/common/gui')
3 files changed, 409 insertions, 167 deletions
diff --git a/src/main/java/gregtech/common/gui/GT_ContainerVolumetricFlask.java b/src/main/java/gregtech/common/gui/GT_ContainerVolumetricFlask.java new file mode 100644 index 0000000000..2f8fd2a356 --- /dev/null +++ b/src/main/java/gregtech/common/gui/GT_ContainerVolumetricFlask.java @@ -0,0 +1,20 @@ +package gregtech.common.gui; + +import gregtech.common.items.GT_VolumetricFlask; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; + +public final class GT_ContainerVolumetricFlask extends Container { + ItemStack flask; + + public GT_ContainerVolumetricFlask(InventoryPlayer inventoryPlayer) { + flask = inventoryPlayer.getCurrentItem(); + } + + @Override + public boolean canInteractWith(EntityPlayer p) { + return (flask != null) && (flask.stackSize > 0) && ((flask.getItem() instanceof GT_VolumetricFlask)); + } +} diff --git a/src/main/java/gregtech/common/gui/GT_Container_Regulator.java b/src/main/java/gregtech/common/gui/GT_Container_Regulator.java index 6a3d7b2f47..ecd371893d 100644 --- a/src/main/java/gregtech/common/gui/GT_Container_Regulator.java +++ b/src/main/java/gregtech/common/gui/GT_Container_Regulator.java @@ -1,167 +1,167 @@ -package gregtech.common.gui;
-
-import cpw.mods.fml.relauncher.Side;
-import cpw.mods.fml.relauncher.SideOnly;
-import gregtech.api.gui.GT_ContainerMetaTile_Machine;
-import gregtech.api.gui.GT_Slot_Holo;
-import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
-import gregtech.api.util.GT_Utility;
-import gregtech.common.tileentities.automation.GT_MetaTileEntity_Regulator;
-import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.entity.player.InventoryPlayer;
-import net.minecraft.inventory.ICrafting;
-import net.minecraft.inventory.Slot;
-import net.minecraft.item.ItemStack;
-
-import java.util.Iterator;
-
-public class GT_Container_Regulator
- extends GT_ContainerMetaTile_Machine {
- public int[] mTargetSlots = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-
- public GT_Container_Regulator(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) {
- super(aInventoryPlayer, aTileEntity);
- }
-
- public void addSlots(InventoryPlayer aInventoryPlayer) {
- this.mTargetSlots = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
-
- addSlotToContainer(new Slot(this.mTileEntity, 0, 8, 6));
- addSlotToContainer(new Slot(this.mTileEntity, 1, 26, 6));
- addSlotToContainer(new Slot(this.mTileEntity, 2, 44, 6));
- addSlotToContainer(new Slot(this.mTileEntity, 3, 8, 24));
- addSlotToContainer(new Slot(this.mTileEntity, 4, 26, 24));
- addSlotToContainer(new Slot(this.mTileEntity, 5, 44, 24));
- addSlotToContainer(new Slot(this.mTileEntity, 6, 8, 42));
- addSlotToContainer(new Slot(this.mTileEntity, 7, 26, 42));
- addSlotToContainer(new Slot(this.mTileEntity, 8, 44, 42));
-
- addSlotToContainer(new Slot(this.mTileEntity, 19, 44, 63));
-
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 9, 64, 7, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 10, 81, 7, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 11, 98, 7, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 12, 64, 24, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 13, 81, 24, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 14, 98, 24, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 15, 64, 41, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 16, 81, 41, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 17, 98, 41, false, true, 1));
-
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 119, 7, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 136, 7, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 153, 7, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 119, 24, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 136, 24, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 153, 24, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 119, 41, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 136, 41, false, true, 1));
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 153, 41, false, true, 1));
-
- addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 8, 63, false, true, 1));
- }
-
- public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) {
- if (aSlotIndex < 10) {
- return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer);
- }
- Slot tSlot = (Slot) this.inventorySlots.get(aSlotIndex);
- if (tSlot != null) {
- if (this.mTileEntity.getMetaTileEntity() == null) {
- return null;
- }
- if (aSlotIndex == 28) {
- ((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).bOutput = (!((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).bOutput);
- if (((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).bOutput) {
- GT_Utility.sendChatToPlayer(aPlayer, trans("116", "Emit Energy to Outputside"));
- } else {
- GT_Utility.sendChatToPlayer(aPlayer, trans("117", "Don't emit Energy"));
- }
- return null;
- }
- if ((aSlotIndex < 19)) {
- ItemStack tStack = aPlayer.inventory.getItemStack();
- if (tStack != null) {
- tSlot.putStack(GT_Utility.copy(new Object[]{tStack}));
- } else if (tSlot.getStack() != null) {
- if (aMouseclick == 0) {
- tSlot.getStack().stackSize -= (aShifthold == 1 ? 8 : 1);
- if (tSlot.getStack().stackSize <= 0) {
- tSlot.putStack(null);
- }
- } else {
- tSlot.getStack().stackSize += (aShifthold == 1 ? 8 : 1);
- if (tSlot.getStack().stackSize > tSlot.getStack().getMaxStackSize()) {
- tSlot.getStack().stackSize = tSlot.getStack().getMaxStackSize();
- }
- }
- }
- return null;
- }
- if ((aSlotIndex < 28)) {
- ((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).mTargetSlots[(aSlotIndex - 19)] = Math.min(99, Math.max(0, ((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).mTargetSlots[(aSlotIndex - 19)] + (aMouseclick == 0 ? -1 : 1) * (aShifthold == 0 ? 1 : 16)));
- return null;
- }
- }
- return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer);
- }
-
- public void detectAndSendChanges() {
- super.detectAndSendChanges();
- if ((this.mTileEntity.isClientSide()) || (this.mTileEntity.getMetaTileEntity() == null)) {
- return;
- }
- this.mTargetSlots = new int[9];
- for (int i = 0; i < 9; i++) {
- this.mTargetSlots[i] = ((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).mTargetSlots[i];
- }
- Iterator var2 = this.crafters.iterator();
- while (var2.hasNext()) {
- ICrafting var1 = (ICrafting) var2.next();
- for (int i = 0; i < 9; i++) {
- var1.sendProgressBarUpdate(this, 100 + i, this.mTargetSlots[i]);
- }
- }
- }
-
- @SideOnly(Side.CLIENT)
- public void updateProgressBar(int par1, int par2) {
- super.updateProgressBar(par1, par2);
- switch (par1) {
- case 100:
- this.mTargetSlots[0] = par2;
- break;
- case 101:
- this.mTargetSlots[1] = par2;
- break;
- case 102:
- this.mTargetSlots[2] = par2;
- break;
- case 103:
- this.mTargetSlots[3] = par2;
- break;
- case 104:
- this.mTargetSlots[4] = par2;
- break;
- case 105:
- this.mTargetSlots[5] = par2;
- break;
- case 106:
- this.mTargetSlots[6] = par2;
- break;
- case 107:
- this.mTargetSlots[7] = par2;
- break;
- case 108:
- this.mTargetSlots[8] = par2;
- }
- }
-
- public int getSlotCount() {
- return 10;
- }
-
- public int getShiftClickSlotCount() {
- return 10;
- }
-}
+package gregtech.common.gui; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.gui.GT_ContainerMetaTile_Machine; +import gregtech.api.gui.GT_Slot_Holo; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.util.GT_Utility; +import gregtech.common.tileentities.automation.GT_MetaTileEntity_Regulator; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import java.util.Iterator; + +public class GT_Container_Regulator + extends GT_ContainerMetaTile_Machine { + public int[] mTargetSlots = {0, 0, 0, 0, 0, 0, 0, 0, 0}; + + public GT_Container_Regulator(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { + super(aInventoryPlayer, aTileEntity); + } + + public void addSlots(InventoryPlayer aInventoryPlayer) { + this.mTargetSlots = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0}; + + addSlotToContainer(new Slot(this.mTileEntity, 0, 8, 6)); + addSlotToContainer(new Slot(this.mTileEntity, 1, 26, 6)); + addSlotToContainer(new Slot(this.mTileEntity, 2, 44, 6)); + addSlotToContainer(new Slot(this.mTileEntity, 3, 8, 24)); + addSlotToContainer(new Slot(this.mTileEntity, 4, 26, 24)); + addSlotToContainer(new Slot(this.mTileEntity, 5, 44, 24)); + addSlotToContainer(new Slot(this.mTileEntity, 6, 8, 42)); + addSlotToContainer(new Slot(this.mTileEntity, 7, 26, 42)); + addSlotToContainer(new Slot(this.mTileEntity, 8, 44, 42)); + + addSlotToContainer(new Slot(this.mTileEntity, 19, 44, 63)); + + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 9, 64, 7, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 10, 81, 7, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 11, 98, 7, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 12, 64, 24, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 13, 81, 24, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 14, 98, 24, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 15, 64, 41, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 16, 81, 41, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 17, 98, 41, false, true, 1)); + + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 119, 7, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 136, 7, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 153, 7, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 119, 24, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 136, 24, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 153, 24, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 119, 41, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 136, 41, false, true, 1)); + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 153, 41, false, true, 1)); + + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 8, 63, false, true, 1)); + } + + public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { + if (aSlotIndex < 10) { + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + Slot tSlot = (Slot) this.inventorySlots.get(aSlotIndex); + if (tSlot != null) { + if (this.mTileEntity.getMetaTileEntity() == null) { + return null; + } + if (aSlotIndex == 28) { + ((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).bOutput = (!((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).bOutput); + if (((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).bOutput) { + GT_Utility.sendChatToPlayer(aPlayer, trans("116", "Emit Energy to Outputside")); + } else { + GT_Utility.sendChatToPlayer(aPlayer, trans("117", "Don't emit Energy")); + } + return null; + } + if ((aSlotIndex < 19)) { + ItemStack tStack = aPlayer.inventory.getItemStack(); + if (tStack != null) { + tSlot.putStack(GT_Utility.copy(new Object[]{tStack})); + } else if (tSlot.getStack() != null) { + if (aMouseclick == 0) { + tSlot.getStack().stackSize -= (aShifthold == 1 ? 8 : 1); + if (tSlot.getStack().stackSize <= 0) { + tSlot.putStack(null); + } + } else { + tSlot.getStack().stackSize += (aShifthold == 1 ? 8 : 1); + if (tSlot.getStack().stackSize > tSlot.getStack().getMaxStackSize()) { + tSlot.getStack().stackSize = tSlot.getStack().getMaxStackSize(); + } + } + } + return null; + } + if ((aSlotIndex < 28)) { + ((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).mTargetSlots[(aSlotIndex - 19)] = Math.min(99, Math.max(0, ((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).mTargetSlots[(aSlotIndex - 19)] + (aMouseclick == 0 ? -1 : 1) * (aShifthold == 0 ? 1 : 16))); + return null; + } + } + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + public void detectAndSendChanges() { + super.detectAndSendChanges(); + if ((this.mTileEntity.isClientSide()) || (this.mTileEntity.getMetaTileEntity() == null)) { + return; + } + this.mTargetSlots = new int[9]; + for (int i = 0; i < 9; i++) { + this.mTargetSlots[i] = ((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).mTargetSlots[i]; + } + Iterator var2 = this.crafters.iterator(); + while (var2.hasNext()) { + ICrafting var1 = (ICrafting) var2.next(); + for (int i = 0; i < 9; i++) { + var1.sendProgressBarUpdate(this, 100 + i, this.mTargetSlots[i]); + } + } + } + + @SideOnly(Side.CLIENT) + public void updateProgressBar(int par1, int par2) { + super.updateProgressBar(par1, par2); + switch (par1) { + case 100: + this.mTargetSlots[0] = par2; + break; + case 101: + this.mTargetSlots[1] = par2; + break; + case 102: + this.mTargetSlots[2] = par2; + break; + case 103: + this.mTargetSlots[3] = par2; + break; + case 104: + this.mTargetSlots[4] = par2; + break; + case 105: + this.mTargetSlots[5] = par2; + break; + case 106: + this.mTargetSlots[6] = par2; + break; + case 107: + this.mTargetSlots[7] = par2; + break; + case 108: + this.mTargetSlots[8] = par2; + } + } + + public int getSlotCount() { + return 10; + } + + public int getShiftClickSlotCount() { + return 10; + } +} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainerVolumetricFlask.java b/src/main/java/gregtech/common/gui/GT_GUIContainerVolumetricFlask.java new file mode 100644 index 0000000000..779fced498 --- /dev/null +++ b/src/main/java/gregtech/common/gui/GT_GUIContainerVolumetricFlask.java @@ -0,0 +1,222 @@ +package gregtech.common.gui; + + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.GT_Values; +import gregtech.common.items.GT_VolumetricFlask; +import gregtech.common.net.MessageSetFlaskCapacity; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +import java.text.DecimalFormat; +import java.text.ParseException; + +@SideOnly(Side.CLIENT) +public final class GT_GUIContainerVolumetricFlask extends GuiContainer { + private static final ResourceLocation BACKGROUND = new ResourceLocation("gregtech:textures/gui/VolumetricFlask.png"); + + private GuiIntegerBox amount; + private GuiButton apply; + private GuiButton plus1; + private GuiButton plus10; + private GuiButton plus100; + private GuiButton plus1000; + private GuiButton minus1; + private GuiButton minus10; + private GuiButton minus100; + private GuiButton minus1000; + private GT_ContainerVolumetricFlask container; + + public GT_GUIContainerVolumetricFlask(GT_ContainerVolumetricFlask container) { + super(container); + this.container = container; + } + + public void initGui() { + super.initGui(); + + buttonList.add(plus1 = new GuiButton(0, guiLeft + 20, guiTop + 26, 22, 20, "+1")); + buttonList.add(plus10 = new GuiButton(0, guiLeft + 48, guiTop + 26, 28, 20, "+10")); + buttonList.add(plus100 = new GuiButton(0, guiLeft + 82, guiTop + 26, 32, 20, "+100")); + buttonList.add(plus1000 = new GuiButton(0, guiLeft + 120, guiTop + 26, 38, 20, "+1000")); + + buttonList.add(minus1 = new GuiButton(0, guiLeft + 20, guiTop + 75, 22, 20, "-1")); + buttonList.add(minus10 = new GuiButton(0, guiLeft + 48, guiTop + 75, 28, 20, "-10")); + buttonList.add(minus100 = new GuiButton(0, guiLeft + 82, guiTop + 75, 32, 20, "-100")); + buttonList.add(minus1000 = new GuiButton(0, guiLeft + 120, guiTop + 75, 38, 20, "-1000")); + + buttonList.add(apply = new GuiButton(0, guiLeft + 128, guiTop + 51, 38, 20, "Accept")); + + amount = new GuiIntegerBox(fontRendererObj, guiLeft + 62, guiTop + 57, 59, fontRendererObj.FONT_HEIGHT, ((GT_VolumetricFlask) container.flask.getItem()).getMaxCapacity()); + amount.setEnableBackgroundDrawing(false); + amount.setMaxStringLength(16); + amount.setTextColor(16777215); + amount.setVisible(true); + amount.setFocused(true); + amount.setText("1"); + System.out.println(((GT_VolumetricFlask) container.flask.getItem()).getCapacity(container.flask)); + amount.setText(String.valueOf(((GT_VolumetricFlask) container.flask.getItem()).getCapacity(container.flask))); + } + + + protected final void drawGuiContainerBackgroundLayer(float f, int x, int y) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + mc.getTextureManager().bindTexture(BACKGROUND); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); + + try { + Long.parseLong(amount.getText()); + apply.enabled = (amount.getText().length() > 0); + } catch (NumberFormatException e) { + apply.enabled = false; + } + + amount.drawTextBox(); + } + + + protected void keyTyped(char character, int key) { + if (!checkHotbarKeys(key)) { + if (key == 28) + actionPerformed(apply); + if (((key == 211) || (key == 205) || (key == 203) || (key == 14) || (character == '-') || (Character.isDigit(character))) && (amount.textboxKeyTyped(character, key))) { + try { + String out = amount.getText(); + boolean fixed = false; + while ((out.startsWith("0")) && (out.length() > 1)) { + out = out.substring(1); + fixed = true; + } + if (fixed) { + amount.setText(out); + } + if (out.isEmpty()) { + out = "0"; + } + long result = Long.parseLong(out); + if (result < 0L) { + amount.setText("1"); + } + + } catch (NumberFormatException localNumberFormatException) { + } + } else { + super.keyTyped(character, key); + } + } + } + + protected void actionPerformed(GuiButton btn) { + try { + if (btn == apply) { + GT_Values.NW.sendToServer(new MessageSetFlaskCapacity(Integer.parseInt(amount.getText()), Minecraft.getMinecraft().thePlayer)); + mc.thePlayer.closeScreen(); + } + + } catch (NumberFormatException e) { + amount.setText("1"); + } + + boolean isPlus = (btn == plus1) || (btn == plus10) || (btn == plus100) || (btn == plus1000); + boolean isMinus = (btn == minus1) || (btn == minus10) || (btn == minus100) || (btn == minus1000); + + if ((isPlus) || (isMinus)) { + addQty(getQty(btn)); + } + } + + private void addQty(int i) { + try { + String out = amount.getText(); + + boolean fixed = false; + while ((out.startsWith("0")) && (out.length() > 1)) { + out = out.substring(1); + fixed = true; + } + + if (fixed) { + amount.setText(out); + } + if (out.isEmpty()) { + out = "0"; + } + long result = Integer.parseInt(out); + + if ((result == 1L) && (i > 1)) { + result = 0L; + } + result += i; + if (result < 1L) { + result = 1L; + } + out = Long.toString(result); + Integer.parseInt(out); + amount.setText(out); + } catch (NumberFormatException localNumberFormatException) { + } + } + + + protected int getQty(GuiButton btn) { + try { + DecimalFormat df = new DecimalFormat("+#;-#"); + return df.parse(btn.displayString).intValue(); + } catch (ParseException e) { + } + + return 0; + } + + public class GuiIntegerBox extends GuiTextField { + private final int maxValue; + + public GuiIntegerBox(FontRenderer fontRenderer, int x, int y, int width, int height) { + this(fontRenderer, x, y, width, height, Integer.MAX_VALUE); + } + + public GuiIntegerBox(FontRenderer fontRenderer, int x, int y, int width, int height, int maxValue) { + super(fontRenderer, x, y, width, height); + this.maxValue = maxValue; + } + + + public void writeText(String selectedText) { + String original = getText(); + super.writeText(selectedText); + + try { + int i = Integer.parseInt(getText()); + if (i > maxValue) { + setText(String.valueOf(maxValue)); + } else if (i < 0) { + setText("0"); + } + } catch (NumberFormatException e) { + setText(original); + } + } + + + public void setText(String s) { + try { + int i = Integer.parseInt(s); + if (i > maxValue) { + s = String.valueOf(maxValue); + } else if (i < 0) { + s = "0"; + } + } catch (NumberFormatException e) { + s = String.valueOf(maxValue); + } + super.setText(s); + } + } + +}
\ No newline at end of file |