Started creating GuiEditKeyframe
Therefore, added support for floating point numbers in GuiNumberInput
This commit is contained in:
@@ -5,19 +5,30 @@ import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
public class GuiNumberInput extends GuiTextField {
|
||||
|
||||
private int limit;
|
||||
private Double minimum, maximum;
|
||||
|
||||
private boolean acceptFloats = false;
|
||||
|
||||
public GuiNumberInput(int id, FontRenderer fontRenderer,
|
||||
int xPos, int yPos, int width, int limit) {
|
||||
int xPos, int yPos, int width, Double minimum, Double maximum, Double defaultValue, boolean acceptFloats) {
|
||||
super(id, fontRenderer, xPos, yPos, width, 20);
|
||||
this.limit = limit;
|
||||
this.minimum = minimum;
|
||||
this.maximum = maximum;
|
||||
this.acceptFloats = acceptFloats;
|
||||
if(defaultValue != null) setText(""+defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeText(String text) {
|
||||
try {
|
||||
Integer.valueOf(text);
|
||||
if(limit > 0 && (getText() + text).length() > limit) return;
|
||||
double val;
|
||||
if(acceptFloats) {
|
||||
val = Double.valueOf(getText() + text);
|
||||
} else {
|
||||
val = Integer.valueOf(getText() + text);
|
||||
}
|
||||
if(minimum != null && val < minimum) return;
|
||||
if(maximum != null && val > maximum) return;
|
||||
super.writeText(text);
|
||||
} catch(NumberFormatException e) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user