Started creating GuiEditKeyframe

Therefore, added support for floating point numbers in GuiNumberInput
This commit is contained in:
CrushedPixel
2015-05-20 16:40:54 +02:00
parent ce9e717d21
commit 4754ecc6bf
18 changed files with 248 additions and 52 deletions

View File

@@ -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) {
}