diff --git a/src/main/java/codechicken/nei/FormattedTextField.java b/src/main/java/codechicken/nei/FormattedTextField.java index 749f2c14..707dd5a2 100644 --- a/src/main/java/codechicken/nei/FormattedTextField.java +++ b/src/main/java/codechicken/nei/FormattedTextField.java @@ -21,6 +21,7 @@ public class FormattedTextField extends GuiTextField { protected FontRenderer fontRenderer; protected String rawText = ""; protected String formattedText = ""; + protected String placeholder = ""; protected boolean editable = true; protected int editableColor = 14737632; protected int notEditableColor = 7368816; @@ -37,6 +38,10 @@ public class FormattedTextField extends GuiTextField { this.formatter = formatter; } + public void setPlaceholder(String placeholder) { + this.placeholder = placeholder; + } + @Override public void updateCursorCounter() { super.updateCursorCounter(); @@ -103,10 +108,14 @@ public class FormattedTextField extends GuiTextField { this.editable = p_146184_1_; } + protected boolean beforeWrite(String text) { + return true; + } + @Override - public void writeText(String p_146191_1_) { + public void writeText(String textPart) { String newText = ""; - String substr = ChatAllowedCharacters.filerAllowedCharacters(p_146191_1_); + String substr = ChatAllowedCharacters.filerAllowedCharacters(textPart); int cursorPosition = getCursorPosition(); int maxStringLength = getMaxStringLength(); String text = getText(); @@ -127,8 +136,10 @@ public class FormattedTextField extends GuiTextField { cursorPosition = Math.min(textStart.length() + substr.length(), newText.length()); } - setText(newText); - setCursorPosition(cursorPosition); + if (beforeWrite(newText)) { + setText(newText); + setCursorPosition(cursorPosition); + } } @Override @@ -138,87 +149,99 @@ public class FormattedTextField extends GuiTextField { @Override public void drawTextBox() { - if (this.getVisible()) { - if (this.getEnableBackgroundDrawing()) { - drawRect( - this.xPosition - 1, - this.yPosition - 1, - this.xPosition + this.width + 1, - this.yPosition + this.height + 1, - -6250336); - drawRect( - this.xPosition, - this.yPosition, - this.xPosition + this.width, - this.yPosition + this.height, - -16777216); + + if (!this.getVisible()) { + return; + } + + if (this.getEnableBackgroundDrawing()) { + drawRect( + this.xPosition - 1, + this.yPosition - 1, + this.xPosition + this.width + 1, + this.yPosition + this.height + 1, + -6250336); + drawRect( + this.xPosition, + this.yPosition, + this.xPosition + this.width, + this.yPosition + this.height, + -16777216); + } + + if (!this.rawText.equals(getText())) { + this.rawText = getText(); + this.formattedText = this.formatter.format(this.rawText); + if (!EnumChatFormatting.getTextWithoutFormattingCodes(this.formattedText).toLowerCase() + .equals(this.rawText.toLowerCase())) { + this.formattedText = this.rawText; } + } - if (!this.rawText.equals(getText())) { - this.rawText = getText(); - this.formattedText = this.formatter.format(this.rawText); - if (!EnumChatFormatting.getTextWithoutFormattingCodes(this.formattedText).toLowerCase() - .equals(this.rawText.toLowerCase())) { - this.formattedText = this.rawText; - } + if (!isFocused() && this.formattedText.isEmpty()) { + int x = getEnableBackgroundDrawing() ? this.xPosition + 4 : this.xPosition; + int y = getEnableBackgroundDrawing() ? this.yPosition + (this.height - 8) / 2 : this.yPosition; + this.fontRenderer.drawStringWithShadow( + this.fontRenderer.trimStringToWidth(this.placeholder, this.getWidth()), + x, + y, + this.notEditableColor); + return; + } + + int firstCharacterIndex = getFormattedTextShift(this.lineScrollOffset); + String rawTextClipped = this.fontRenderer + .trimStringToWidth(this.rawText.substring(this.lineScrollOffset), this.getWidth()); + String textClipped = this.formattedText + .substring(firstCharacterIndex, getFormattedTextShift(this.lineScrollOffset + rawTextClipped.length())); + int cursorPosition = getFormattedTextShift(getCursorPosition()); + int selectionEnd = getFormattedTextShift(getSelectionEnd()); + + int color = this.editable ? this.editableColor : this.notEditableColor; + int cursorA = cursorPosition - firstCharacterIndex; + int cursorB = selectionEnd - firstCharacterIndex; + boolean flag = cursorA >= 0 && cursorA <= textClipped.length(); + boolean flag1 = isFocused() && this.frame / 6 % 2 == 0 && flag; + boolean flag2 = getCursorPosition() < this.rawText.length() || this.rawText.length() >= getMaxStringLength(); + int x = getEnableBackgroundDrawing() ? this.xPosition + 4 : this.xPosition; + int y = getEnableBackgroundDrawing() ? this.yPosition + (this.height - 8) / 2 : this.yPosition; + int x2 = x; + + if (cursorB > textClipped.length()) { + cursorB = textClipped.length(); + } + + if (textClipped.length() > 0) { + String s1 = flag ? textClipped.substring(0, cursorA) : textClipped; + String colorA = getPreviousColor(firstCharacterIndex); + x2 = this.fontRenderer.drawStringWithShadow(colorA + s1, x, y, color); + } + + int k1 = x2; + + if (!flag) { + k1 = cursorA > 0 ? x + this.width : x; + } else if (flag2) { + k1 = x2 - 1; + --x2; + } + + if (textClipped.length() > 0 && flag && cursorA < textClipped.length()) { + String colorB = getPreviousColor(firstCharacterIndex + cursorA); + this.fontRenderer.drawStringWithShadow(colorB + textClipped.substring(cursorA), x2, y, color); + } + + if (flag1) { + if (flag2) { + Gui.drawRect(k1, y - 1, k1 + 1, y + 1 + this.fontRenderer.FONT_HEIGHT, -3092272); + } else { + this.fontRenderer.drawStringWithShadow("_", k1, y, color); } + } - int firstCharacterIndex = getFormattedTextShift(this.lineScrollOffset); - String rawTextClipped = this.fontRenderer - .trimStringToWidth(this.rawText.substring(this.lineScrollOffset), this.getWidth()); - String textClipped = this.formattedText.substring( - firstCharacterIndex, - getFormattedTextShift(this.lineScrollOffset + rawTextClipped.length())); - int cursorPosition = getFormattedTextShift(this.getCursorPosition()); - int selectionEnd = getFormattedTextShift(this.getSelectionEnd()); - - int color = this.editable ? this.editableColor : this.notEditableColor; - int cursorA = cursorPosition - firstCharacterIndex; - int cursorB = selectionEnd - firstCharacterIndex; - boolean flag = cursorA >= 0 && cursorA <= textClipped.length(); - boolean flag1 = this.isFocused() && this.frame / 6 % 2 == 0 && flag; - boolean flag2 = this.getCursorPosition() < this.rawText.length() - || this.rawText.length() >= this.getMaxStringLength(); - int x = this.getEnableBackgroundDrawing() ? this.xPosition + 4 : this.xPosition; - int y = this.getEnableBackgroundDrawing() ? this.yPosition + (this.height - 8) / 2 : this.yPosition; - int x2 = x; - - if (cursorB > textClipped.length()) { - cursorB = textClipped.length(); - } - - if (textClipped.length() > 0) { - String s1 = flag ? textClipped.substring(0, cursorA) : textClipped; - String colorA = getPreviousColor(firstCharacterIndex); - x2 = this.fontRenderer.drawStringWithShadow(colorA + s1, x, y, color); - } - - int k1 = x2; - - if (!flag) { - k1 = cursorA > 0 ? x + this.width : x; - } else if (flag2) { - k1 = x2 - 1; - --x2; - } - - if (textClipped.length() > 0 && flag && cursorA < textClipped.length()) { - String colorB = getPreviousColor(firstCharacterIndex + cursorA); - this.fontRenderer.drawStringWithShadow(colorB + textClipped.substring(cursorA), x2, y, color); - } - - if (flag1) { - if (flag2) { - Gui.drawRect(k1, y - 1, k1 + 1, y + 1 + this.fontRenderer.FONT_HEIGHT, -3092272); - } else { - this.fontRenderer.drawStringWithShadow("_", k1, y, color); - } - } - - if (cursorB != cursorA) { - int l1 = x + this.fontRenderer.getStringWidth(textClipped.substring(0, cursorB)); - drawCursorVertical(k1, y - 1, l1 - 1, y + 1 + this.fontRenderer.FONT_HEIGHT); - } + if (cursorB != cursorA) { + int l1 = x + this.fontRenderer.getStringWidth(textClipped.substring(0, cursorB)); + drawCursorVertical(k1, y - 1, l1 - 1, y + 1 + this.fontRenderer.FONT_HEIGHT); } } diff --git a/src/main/java/codechicken/nei/ItemQuantityField.java b/src/main/java/codechicken/nei/ItemQuantityField.java index 23c91927..8189597d 100644 --- a/src/main/java/codechicken/nei/ItemQuantityField.java +++ b/src/main/java/codechicken/nei/ItemQuantityField.java @@ -1,9 +1,10 @@ package codechicken.nei; -import static codechicken.nei.NEIClientUtils.translate; - +import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; +import org.lwjgl.input.Keyboard; + import codechicken.nei.recipe.StackInfo; public class ItemQuantityField extends TextField { @@ -14,13 +15,63 @@ public class ItemQuantityField extends TextField { field.setDisabledTextColour(0xFF303030); } - public int intValue() { - return intValue(text()); + @Override + protected void initInternalTextField() { + field = new FormattedTextField(Minecraft.getMinecraft().fontRenderer, 0, 0, 0, 0) { + + { + setPlaceholder(NEIClientUtils.translate("itempanel.quantity.default")); + } + + @Override + public String getText() { + String text = super.getText(); + return !isFocused() && "0".equals(text) ? "" : text; + } + + @Override + protected boolean beforeWrite(String text) { + if (text == null || text.isEmpty()) return true; + try { + return Integer.parseInt(text) >= 0; + } catch (NumberFormatException e) { + return false; + } + } + + @Override + public boolean textboxKeyTyped(char keyChar, int keyID) { + if (!isFocused()) return false; + + if (super.textboxKeyTyped(keyChar, keyID)) { + return true; + } else if (keyID == Keyboard.KEY_DOWN) { + setText(Integer.toString(Math.max(0, getInteger() - 1))); + return true; + } else if (keyID == Keyboard.KEY_UP) { + setText(Integer.toString(getInteger() + 1)); + return true; + } + + return false; + } + + private int getInteger() { + try { + return Math.max(0, Integer.parseInt(text())); + } catch (NumberFormatException nfe) { + return 0; + } + } + + }; + field.setMaxStringLength(maxSearchLength); + field.setCursorPositionZero(); } - public int intValue(String s) { + private int getInteger() { try { - return Math.max(0, Integer.parseInt(s)); + return Math.max(0, Integer.parseInt(text())); } catch (NumberFormatException nfe) { return 0; } @@ -56,36 +107,21 @@ public class ItemQuantityField extends TextField { @Override public void onTextChange(String oldText) { - NEIClientUtils.setItemQuantity(intValue()); - } - - @Override - public void draw(int mousex, int mousey) { - - if (!focused() && intValue() == 0) { - field.setText(translate("itempanel.quantity.default")); - field.setCursorPositionZero(); - field.setEnabled(false); - super.draw(mousex, mousey); - field.setEnabled(true); - field.setText("0"); - } else { - super.draw(mousex, mousey); - } + NEIClientUtils.setItemQuantity(getInteger()); } @Override public boolean onMouseWheel(int i, int mx, int my) { if (!contains(mx, my)) return false; int multiplier = 1; + if (NEIClientUtils.shiftKey()) { multiplier = 10; } else if (NEIClientUtils.controlKey()) { multiplier = 64; } - int quantity = intValue() + i * multiplier; - setText(Integer.toString(quantity)); + setText(Integer.toString(Math.max(0, getInteger() + i * multiplier))); return true; } diff --git a/src/main/java/codechicken/nei/SearchField.java b/src/main/java/codechicken/nei/SearchField.java index 608b2781..57c11457 100644 --- a/src/main/java/codechicken/nei/SearchField.java +++ b/src/main/java/codechicken/nei/SearchField.java @@ -100,6 +100,8 @@ public class SearchField extends TextField implements ItemFilterProvider { super(Minecraft.getMinecraft().fontRenderer, 0, 0, 0, 0); this.searchParser = searchParser; setFormatter(new SearchTextFormatter(searchParser)); + setDisabledTextColour(0xFF303030); + setPlaceholder(NEIClientUtils.translate("inventory.search.placeholder")); } public ItemFilter getFilter() { diff --git a/src/main/resources/assets/nei/lang/en_US.lang b/src/main/resources/assets/nei/lang/en_US.lang index 33ebbb9a..0cc035c7 100644 --- a/src/main/resources/assets/nei/lang/en_US.lang +++ b/src/main/resources/assets/nei/lang/en_US.lang @@ -46,6 +46,7 @@ nei.bookmark.crafting_chain.missing=Missing Items nei.bookmark.crafting_chain.output=Results nei.bookmark.crafting_chain.remainder=Remainders nei.bookmark.crafting_chain.available=Available Items +nei.inventory.search.placeholder=Search... nei.itempanel.quantity.default=One stack nei.itempanel.loading=Loading Item List... nei.itempanel.deleteItem=Delete Item @@ -430,6 +431,9 @@ nei.options.tools.handler_load_from_config.false=JAR nei.options.tools.catalyst_load_from_config=Load catalysts from Config nei.options.tools.catalyst_load_from_config.true=Config nei.options.tools.catalyst_load_from_config.false=JAR +nei.options.tools.handler_info=Handler Info Widget +nei.options.tools.handler_info.true=Enabled +nei.options.tools.handler_info.false=Disabled nei.options.tools.dump=Data Dumps nei.options.tools.dump.dump=Dump nei.options.tools.dump.dumped=%s IDs dumped to %s