From b1f4b996be8684612b883d3a7d58a23b601f8793 Mon Sep 17 00:00:00 2001 From: miozune Date: Fri, 29 Jul 2022 23:45:06 +0900 Subject: [PATCH] forgot these... --- .../client/gui/GuiCraftAmount.java | 114 +++++++----------- 1 file changed, 45 insertions(+), 69 deletions(-) diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java index 91951a8..4a1bb49 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java @@ -4,11 +4,13 @@ import appeng.api.AEApi; import appeng.api.definitions.IDefinitions; import appeng.api.definitions.IParts; import appeng.api.storage.ITerminalHost; -import appeng.client.gui.widgets.GuiNumberBox; import appeng.core.AEConfig; import appeng.core.localization.GuiText; import appeng.helpers.Reflected; +import appeng.util.calculators.ArithHelper; +import appeng.util.calculators.Calculator; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiTextField; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTabButton; @@ -22,7 +24,7 @@ import net.p455w0rd.wirelesscraftingterminal.items.ItemWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; public class GuiCraftAmount extends WCTBaseGui { - private GuiNumberBox amountToCraft; + private GuiTextField amountToCraft; private GuiTabButton originalGuiBtn; private GuiButton next; @@ -84,19 +86,15 @@ public class GuiCraftAmount extends WCTBaseGui { this.guiLeft + 154, this.guiTop - 4, myIcon, myIcon.getDisplayName(), itemRender)); } - this.amountToCraft = new GuiNumberBox( - this.fontRendererObj, - this.guiLeft + 62, - this.guiTop + 57, - 59, - this.fontRendererObj.FONT_HEIGHT, - Integer.class); + this.amountToCraft = new GuiTextField( + this.fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, this.fontRendererObj.FONT_HEIGHT); this.amountToCraft.setEnableBackgroundDrawing(false); this.amountToCraft.setMaxStringLength(16); this.amountToCraft.setTextColor(0xFFFFFF); this.amountToCraft.setVisible(true); this.amountToCraft.setFocused(true); this.amountToCraft.setText("1"); + this.amountToCraft.setSelectionPos(0); } @Override @@ -112,8 +110,18 @@ public class GuiCraftAmount extends WCTBaseGui { this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize); try { - Long.parseLong(this.amountToCraft.getText()); - this.next.enabled = this.amountToCraft.getText().length() > 0; + String out = this.amountToCraft.getText(); + + double resultD = Calculator.conversion(out); + int resultI; + + if (resultD <= 0 || Double.isNaN(resultD)) { + resultI = 0; + } else { + resultI = (int) ArithHelper.round(resultD, 0); + } + + this.next.enabled = resultI > 0; } catch (final NumberFormatException e) { this.next.enabled = false; } @@ -127,40 +135,8 @@ public class GuiCraftAmount extends WCTBaseGui { if (key == 28) { this.actionPerformed(this.next); } - if ((key == 211 - || key == 205 - || key == 203 - || key == 14 - || character == '-' - || Character.isDigit(character)) - && this.amountToCraft.textboxKeyTyped(character, key)) { - try { - String out = this.amountToCraft.getText(); - - boolean fixed = false; - while (out.startsWith("0") && out.length() > 1) { - out = out.substring(1); - fixed = true; - } - - if (fixed) { - this.amountToCraft.setText(out); - } - - if (out.isEmpty()) { - out = "0"; - } - - final long result = Long.parseLong(out); - if (result < 0) { - this.amountToCraft.setText("1"); - } - } catch (final NumberFormatException e) { - // :P - } - } else { - super.keyTyped(character, key); - } + this.amountToCraft.textboxKeyTyped(character, key); + super.keyTyped(character, key); } } @@ -174,9 +150,17 @@ public class GuiCraftAmount extends WCTBaseGui { NetworkHandler.instance.sendToServer(new PacketSwitchGuis(this.originalGui)); } - if (btn == this.next) { - NetworkHandler.instance.sendToServer( - new PacketCraftRequest(Integer.parseInt(this.amountToCraft.getText()), isShiftKeyDown())); + if (btn == this.next && btn.enabled) { + double resultD = Calculator.conversion(this.amountToCraft.getText()); + int resultI; + + if (resultD <= 0 || Double.isNaN(resultD)) { + resultI = 1; + } else { + resultI = (int) ArithHelper.round(resultD, 0); + } + + NetworkHandler.instance.sendToServer(new PacketCraftRequest(resultI, isShiftKeyDown())); } } catch (final NumberFormatException e) { // nope.. @@ -196,33 +180,25 @@ public class GuiCraftAmount extends WCTBaseGui { try { String out = this.amountToCraft.getText(); - boolean fixed = false; - while (out.startsWith("0") && out.length() > 1) { - out = out.substring(1); - fixed = true; + double resultD = Calculator.conversion(out); + int resultI; + + if (resultD <= 0 || Double.isNaN(resultD)) { + resultI = 0; + } else { + resultI = (int) ArithHelper.round(resultD, 0); } - if (fixed) { - this.amountToCraft.setText(out); + if (resultI == 1 && i > 1) { + resultI = 0; } - if (out.isEmpty()) { - out = "0"; + resultI += i; + if (resultI < 1) { + resultI = 1; } - long result = Integer.parseInt(out); - - if (result == 1 && i > 1) { - result = 0; - } - - result += i; - if (result < 1) { - result = 1; - } - - out = Long.toString(result); - Integer.parseInt(out); + out = Integer.toString(resultI); this.amountToCraft.setText(out); } catch (final NumberFormatException e) { // :P