Made GuiNumberInput a subclass of GuiAdvancedTextField and removed unneccessary IDs from Constructor and GuiConstants
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
|
||||
public class GuiDraggingNumberInput extends GuiNumberInput {
|
||||
|
||||
public GuiDraggingNumberInput(FontRenderer fontRenderer,
|
||||
int xPos, int yPos, int width, Double minimum, Double maximum, Double defaultValue, boolean acceptFloats) {
|
||||
super(fontRenderer, xPos, yPos, width, minimum, maximum, defaultValue, acceptFloats);
|
||||
}
|
||||
|
||||
private int prevMouseX;
|
||||
private boolean dragging;
|
||||
|
||||
@Override
|
||||
public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
|
||||
dragging = false;
|
||||
prevMouseX = mouseX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) {
|
||||
if(mouseX != prevMouseX) {
|
||||
dragging = true;
|
||||
int diff = mouseX - prevMouseX;
|
||||
prevMouseX = mouseX;
|
||||
|
||||
int bounds = 100;
|
||||
|
||||
if(minimum != null && maximum != null) {
|
||||
bounds = (int)(maximum-minimum);
|
||||
}
|
||||
|
||||
double value = getPreciseValue();
|
||||
double valueDiff = (diff/200) * bounds;
|
||||
|
||||
this.setValue(value+valueDiff);
|
||||
}
|
||||
super.mouseDrag(mc, mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) {
|
||||
if(!dragging) {
|
||||
super.mouseClick(mc, mouseX, mouseY, button);
|
||||
}
|
||||
super.mouseRelease(mc, mouseX, mouseY, button);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
public class GuiNumberInput extends GuiTextField {
|
||||
public class GuiNumberInput extends GuiAdvancedTextField {
|
||||
|
||||
private Double minimum, maximum;
|
||||
protected Double minimum, maximum;
|
||||
|
||||
private boolean acceptFloats = false;
|
||||
protected boolean acceptFloats = false;
|
||||
|
||||
public GuiNumberInput(int id, FontRenderer fontRenderer,
|
||||
public GuiNumberInput(FontRenderer fontRenderer,
|
||||
int xPos, int yPos, int width, Double minimum, Double maximum, Double defaultValue, boolean acceptFloats) {
|
||||
super(id, fontRenderer, xPos, yPos, width, 20);
|
||||
super(fontRenderer, xPos, yPos, width, 20);
|
||||
this.minimum = minimum;
|
||||
this.maximum = maximum;
|
||||
this.acceptFloats = acceptFloats;
|
||||
@@ -21,9 +20,9 @@ public class GuiNumberInput extends GuiTextField {
|
||||
}
|
||||
}
|
||||
|
||||
public GuiNumberInput(int id, FontRenderer fontRenderer,
|
||||
public GuiNumberInput(FontRenderer fontRenderer,
|
||||
int xPos, int yPos, int width, int minimum, int maximum, int defaultValue, boolean acceptFloats) {
|
||||
this(id, fontRenderer, xPos, yPos, width, (double) minimum, (double) maximum, (double) defaultValue, acceptFloats);
|
||||
this(fontRenderer, xPos, yPos, width, (double) minimum, (double) maximum, (double) defaultValue, acceptFloats);
|
||||
}
|
||||
|
||||
public void setValue(double value) {
|
||||
|
||||
@@ -9,11 +9,11 @@ public class GuiNumberInputWithText extends GuiNumberInput {
|
||||
|
||||
private String suffix;
|
||||
|
||||
public GuiNumberInputWithText(int id, FontRenderer fontRenderer,
|
||||
public GuiNumberInputWithText(FontRenderer fontRenderer,
|
||||
int xPos, int yPos, int width, Double minimum, Double maximum, Double defaultValue,
|
||||
boolean acceptFloats, String suffix) {
|
||||
|
||||
super(id, fontRenderer, xPos, yPos, width, minimum, maximum, defaultValue, acceptFloats);
|
||||
super(fontRenderer, xPos, yPos, width, minimum, maximum, defaultValue, acceptFloats);
|
||||
if(suffix == null) suffix = "";
|
||||
|
||||
this.suffix = suffix;
|
||||
|
||||
Reference in New Issue
Block a user