CustomObjectRepository is now being saved to and loaded from the ReplayFile The CustomObjectRenderer uses the GuiObjectManager's timeline cursor position as interpolation timestamp for the CustomImageObjects which are drawn if a GuiObjectManager is open (instant preview) KeyframeList's add() method now removes Keyframes with the same timestamp before adding the new Keyframe Transformations class now holds default values to prevent NullPointerExceptions in methods calling getTransformationForTimestamp() Added Javadoc to Transformation POJO Created NumberValueChangeListener which can be applied to GuiNumberInput objects Made step size customizable in GuiDraggingNumberInput Changing a ReplayImageAssets image now notifies the CustomImageObjects linked to that asset Modified RoundUtils to provide a round() method which uses the DecimalFormat class instead of Math.round which is unstable
64 lines
2.2 KiB
Java
64 lines
2.2 KiB
Java
package eu.crushedpixel.replaymod.gui.elements;
|
|
|
|
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
|
import eu.crushedpixel.replaymod.utils.RoundUtils;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.gui.FontRenderer;
|
|
|
|
public class GuiDraggingNumberInput extends GuiNumberInputWithText {
|
|
|
|
public GuiDraggingNumberInput(FontRenderer fontRenderer,
|
|
int xPos, int yPos, int width, Double minimum, Double maximum, Double defaultValue, boolean acceptFloats) {
|
|
this(fontRenderer, xPos, yPos, width, minimum, maximum, defaultValue, acceptFloats, "", 0.5f);
|
|
}
|
|
|
|
public GuiDraggingNumberInput(FontRenderer fontRenderer,
|
|
int xPos, int yPos, int width, Double minimum,
|
|
Double maximum, Double defaultValue, boolean acceptFloats, String suffix, double stepSize) {
|
|
super(fontRenderer, xPos, yPos, width, minimum, maximum, defaultValue, acceptFloats, suffix);
|
|
|
|
this.stepSize = stepSize;
|
|
}
|
|
|
|
private int prevMouseX;
|
|
private boolean dragging;
|
|
private boolean clicked;
|
|
|
|
private double stepSize;
|
|
|
|
@Override
|
|
public boolean mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
|
|
if(MouseUtils.isMouseWithinBounds(xPosition, yPosition, width, height) && isEnabled) {
|
|
dragging = false;
|
|
clicked = true;
|
|
prevMouseX = mouseX;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) {
|
|
if(clicked && mouseX != prevMouseX) {
|
|
dragging = true;
|
|
int diff = mouseX - prevMouseX;
|
|
prevMouseX = mouseX;
|
|
|
|
double value = getPreciseValue();
|
|
double valueDiff = diff * stepSize;
|
|
|
|
this.setValue(RoundUtils.round2Decimals(value + valueDiff));
|
|
}
|
|
super.mouseDrag(mc, mouseX, mouseY, button);
|
|
}
|
|
|
|
@Override
|
|
public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) {
|
|
clicked = false;
|
|
if(!dragging) {
|
|
super.mouseClick(mc, mouseX, mouseY, button);
|
|
}
|
|
super.mouseRelease(mc, mouseX, mouseY, button);
|
|
}
|
|
}
|