2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
import static codechicken.nei.NEIClientUtils.translate;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public class ItemQuantityField extends TextField {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public ItemQuantityField(String ident) {
|
2014-04-29 10:54:20 +10:00
|
|
|
super(ident);
|
|
|
|
|
centered = true;
|
2022-08-19 15:03:42 +03:00
|
|
|
field.setDisabledTextColour(0xFF303030);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public int intValue() {
|
2014-04-29 10:54:20 +10:00
|
|
|
return intValue(text());
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public int intValue(String s) {
|
|
|
|
|
try {
|
2021-08-22 11:15:23 -06:00
|
|
|
return Math.max(0, Integer.parseInt(s));
|
2014-06-29 20:31:37 +10:00
|
|
|
} catch (NumberFormatException nfe) {
|
2014-04-29 10:54:20 +10:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2021-08-22 11:15:23 -06:00
|
|
|
@Override
|
|
|
|
|
public void gainFocus() {
|
|
|
|
|
if (text().equals("0")) {
|
|
|
|
|
setText("");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public void loseFocus() {
|
2014-04-29 10:54:20 +10:00
|
|
|
setText(Integer.toString(NEIClientConfig.getItemQuantity()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public void onTextChange(String oldText) {
|
2021-08-22 11:15:23 -06:00
|
|
|
NEIClientUtils.setItemQuantity(intValue());
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2022-08-19 15:03:42 +03:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void draw(int mousex, int mousey) {
|
|
|
|
|
|
|
|
|
|
if (!focused() && intValue() == 0) {
|
|
|
|
|
field.setText(translate("itempanel.quantity.default"));
|
|
|
|
|
field.setEnabled(false);
|
|
|
|
|
super.draw(mousex, mousey);
|
|
|
|
|
field.setEnabled(true);
|
|
|
|
|
field.setText("0");
|
|
|
|
|
} else {
|
|
|
|
|
super.draw(mousex, mousey);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|