diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index 00126d4ef..22868f2e5 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -241,7 +241,7 @@ public boolean onClick(int button) { tag.getTag("inventory.history.historyColor").setComment("Color of the history area display") .getHexValue(0xee555555); - API.addOption(new OptionIntegerField("inventory.history.historyColor")); + API.addOption(new OptionIntegerField("inventory.history.historyColor", 0, OptionIntegerField.UNSIGNED_INT_MAX)); tag.getTag("inventory.history.useRows").setComment("Rows used in historical areas").getIntValue(2); API.addOption(new OptionIntegerField("inventory.history.useRows", 1, 5)); @@ -267,11 +267,19 @@ public boolean onClick(int button) { tag.getTag("inventory.collapsibleItems.expandedColor") .setComment("Color of the collapsible item expanded state").getHexValue(0x335555EE); - API.addOption(new OptionIntegerField("inventory.collapsibleItems.expandedColor")); + API.addOption( + new OptionIntegerField( + "inventory.collapsibleItems.expandedColor", + 0, + OptionIntegerField.UNSIGNED_INT_MAX)); tag.getTag("inventory.collapsibleItems.collapsedColor") .setComment("Color of the collapsible item collapsed state").getHexValue(0x335555EE); - API.addOption(new OptionIntegerField("inventory.collapsibleItems.collapsedColor")); + API.addOption( + new OptionIntegerField( + "inventory.collapsibleItems.collapsedColor", + 0, + OptionIntegerField.UNSIGNED_INT_MAX)); API.addOption( new OptionButton( @@ -309,7 +317,7 @@ public boolean onClick(int button) { API.addOption(new OptionToggleButton("inventory.itemzoom.showName", true)); tag.getTag("inventory.itemzoom.nameColor").getHexValue(0xFFFFFFFF); - API.addOption(new OptionIntegerField("inventory.itemzoom.nameColor")); + API.addOption(new OptionIntegerField("inventory.itemzoom.nameColor", 0, OptionIntegerField.UNSIGNED_INT_MAX)); tag.getTag("inventory.itemIDs").getIntValue(1); API.addOption(new OptionCycled("inventory.itemIDs", 3, true)); diff --git a/src/main/java/codechicken/nei/NEIClientUtils.java b/src/main/java/codechicken/nei/NEIClientUtils.java index dcaa933bf..2e4ddea34 100644 --- a/src/main/java/codechicken/nei/NEIClientUtils.java +++ b/src/main/java/codechicken/nei/NEIClientUtils.java @@ -322,7 +322,7 @@ public static void setHourForward(int hour) { } public static void sendCommand(String command, Object... args) { - if (command.length() == 0) return; + if (command.isEmpty()) return; NumberFormat numberformat = NumberFormat.getIntegerInstance(); numberformat.setGroupingUsed(false); diff --git a/src/main/java/codechicken/nei/NEIServerConfig.java b/src/main/java/codechicken/nei/NEIServerConfig.java index 9e03dfaec..dae4a5e2b 100644 --- a/src/main/java/codechicken/nei/NEIServerConfig.java +++ b/src/main/java/codechicken/nei/NEIServerConfig.java @@ -197,7 +197,7 @@ private static void loadBannedItems() { FileReader r = new FileReader(file); int line = 0; for (String s : IOUtils.readLines(r)) { - if (s.charAt(0) == '#' || s.trim().length() == 0) continue; + if (s.charAt(0) == '#' || s.trim().isEmpty()) continue; int delim = s.lastIndexOf('='); if (delim < 0) { logger.error("line " + line + ": Missing ="); diff --git a/src/main/java/codechicken/nei/config/OptionIntegerField.java b/src/main/java/codechicken/nei/config/OptionIntegerField.java index 7504864ac..d2c1e689c 100644 --- a/src/main/java/codechicken/nei/config/OptionIntegerField.java +++ b/src/main/java/codechicken/nei/config/OptionIntegerField.java @@ -1,11 +1,15 @@ package codechicken.nei.config; +import codechicken.lib.gui.GuiDraw; + public class OptionIntegerField extends OptionTextField { - public final int min; - public final int max; + public static final long UNSIGNED_INT_MAX = 0xFFFFFFFFL; + + public final long min; + public final long max; - public OptionIntegerField(String name, int min, int max) { + public OptionIntegerField(String name, long min, long max) { super(name); this.min = min; this.max = max; @@ -15,13 +19,23 @@ public OptionIntegerField(String name) { this(name, Integer.MIN_VALUE, Integer.MAX_VALUE); } + @Override + protected int getMaxInputWidth() { + + if (renderTag().getValue().startsWith("0x")) { + return GuiDraw.getStringWidth("0x" + Long.toHexString(this.max).toUpperCase()) + 32; + } + + return GuiDraw.getStringWidth(String.valueOf(this.max)) + 32; + } + @Override public boolean isValidInput(String s) { - if (s.length() == 0) return true; + if (s.isEmpty()) return true; try { if (s.startsWith("0x")) { - Long.parseLong(s.substring(2), 16); + Long.parseUnsignedLong(s.substring(2), 16); } else { Integer.parseInt(s); } @@ -33,15 +47,15 @@ public boolean isValidInput(String s) { @Override public boolean isValidValue(String s) { - if (s.length() == 0 || !isValidInput(s)) return false; - int i = 0; + if (s.isEmpty() || !isValidInput(s)) return false; + long i = 0; if (s.startsWith("0x")) { - i = (int) Long.parseLong(s.substring(2), 16); + i = Long.parseUnsignedLong(s.substring(2), 16); } else { i = Integer.parseInt(s); } - return i >= min && i <= max; + return i >= this.min && i <= this.max; } } diff --git a/src/main/java/codechicken/nei/config/OptionTextField.java b/src/main/java/codechicken/nei/config/OptionTextField.java index dec8a6490..97f896902 100644 --- a/src/main/java/codechicken/nei/config/OptionTextField.java +++ b/src/main/java/codechicken/nei/config/OptionTextField.java @@ -1,13 +1,10 @@ package codechicken.nei.config; -import static codechicken.lib.gui.GuiDraw.drawString; -import static codechicken.lib.gui.GuiDraw.getStringWidth; - import java.util.List; +import codechicken.lib.gui.GuiDraw; import codechicken.lib.vec.Rectangle4i; import codechicken.nei.TextField; -import codechicken.nei.config.GuiOptionList.OptionScrollSlot; public class OptionTextField extends Option { @@ -36,11 +33,6 @@ public OptionTextField(String name) { super(name); } - @Override - public void onAdded(OptionScrollSlot slot) { - super.onAdded(slot); - } - @Override public void update() { textField.update(); @@ -51,11 +43,16 @@ public String getPrefix() { return translateN(name); } + protected int getMaxInputWidth() { + return slot.slotWidth(); + } + @Override public void draw(int mousex, int mousey, float frame) { - drawString(getPrefix(), 10, 6, -1); + GuiDraw.drawString(getPrefix(), 10, 6, -1); - textField.w = slot.slotWidth() - getStringWidth(getPrefix()) - 16; + textField.w = Math + .max(60, Math.min(getMaxInputWidth(), slot.slotWidth() - GuiDraw.getStringWidth(getPrefix())) - 16); textField.x = slot.slotWidth() - textField.w; textField.draw(mousex, mousey); } diff --git a/src/main/java/codechicken/nei/config/OptionToggleButton.java b/src/main/java/codechicken/nei/config/OptionToggleButton.java index a218a2d92..b7c48ba96 100644 --- a/src/main/java/codechicken/nei/config/OptionToggleButton.java +++ b/src/main/java/codechicken/nei/config/OptionToggleButton.java @@ -17,6 +17,7 @@ public boolean state() { return renderTag().getBooleanValue(); } + @Override public String getButtonText() { return translateN(name + (state() ? ".true" : ".false")); }