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

@@ -7,12 +7,16 @@ import java.awt.*;
public class GuiArrowButton extends GuiButton {
private boolean upwards = false;
public enum Direction {
UP, DOWN, RIGHT, LEFT;
}
public GuiArrowButton(int buttonId, int x, int y, String buttonText, boolean upwards) {
private Direction dir;
public GuiArrowButton(int buttonId, int x, int y, String buttonText, Direction dir) {
super(buttonId, x, y, buttonText);
this.upwards = upwards;
this.dir = dir;
width = 20;
height = 20;
}
@@ -21,14 +25,18 @@ public class GuiArrowButton extends GuiButton {
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
try {
super.drawButton(mc, mouseX, mouseY);
if(upwards) {
if(dir == Direction.UP) {
for(int i = 0; i <= Math.ceil(height / 2) - 5; i++) {
drawHorizontalLine(xPosition + width - height + i + 4, xPosition + width - i - 6, yPosition + height - ((height / 3) + i + 2), Color.BLACK.getRGB());
}
} else {
} else if(dir == Direction.DOWN) {
for(int i = 0; i <= Math.ceil(height / 2) - 5; i++) {
drawHorizontalLine(xPosition + width - height + i + 4, xPosition + width - i - 6, yPosition + (height / 3) + i + 2, Color.BLACK.getRGB());
}
} else if(dir == Direction.LEFT) {
} else if(dir == Direction.RIGHT) {
}
} catch(Exception e) {
e.printStackTrace();

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

View File

@@ -1,6 +1,6 @@
package eu.crushedpixel.replaymod.gui.elements;
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
import eu.crushedpixel.replaymod.utils.ResourceHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;