Created CustomObjectRepository which can be serialized by Gson, storing all CustomImageObjects created
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
This commit is contained in:
@@ -9,19 +9,23 @@ 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, "");
|
||||
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 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) {
|
||||
@@ -40,16 +44,10 @@ public class GuiDraggingNumberInput extends GuiNumberInputWithText {
|
||||
int diff = mouseX - prevMouseX;
|
||||
prevMouseX = mouseX;
|
||||
|
||||
int bounds = 100;
|
||||
|
||||
if(minimum != null && maximum != null) {
|
||||
bounds = (int)(maximum-minimum);
|
||||
}
|
||||
|
||||
double value = getPreciseValue();
|
||||
double valueDiff = RoundUtils.round2Decimals((diff / 200f) * bounds);
|
||||
double valueDiff = diff * stepSize;
|
||||
|
||||
this.setValue(value+valueDiff);
|
||||
this.setValue(RoundUtils.round2Decimals(value + valueDiff));
|
||||
}
|
||||
super.mouseDrag(mc, mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public class GuiEntryList<T extends GuiEntryListEntry> extends GuiAdvancedTextFi
|
||||
fireSelectionChangeEvent();
|
||||
}
|
||||
|
||||
public List<T> getCopyOfElements() {
|
||||
public ArrayList<T> getCopyOfElements() {
|
||||
return new ArrayList<T>(elements);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.NumberValueChangeListener;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiNumberInput extends GuiAdvancedTextField {
|
||||
|
||||
private List<NumberValueChangeListener> valueChangeListeners = new ArrayList<NumberValueChangeListener>();
|
||||
|
||||
protected Double minimum, maximum;
|
||||
|
||||
protected boolean acceptFloats = false;
|
||||
@@ -25,7 +31,11 @@ public class GuiNumberInput extends GuiAdvancedTextField {
|
||||
this(fontRenderer, xPos, yPos, width, (double) minimum, (double) maximum, (double) defaultValue, acceptFloats);
|
||||
}
|
||||
|
||||
public void setValue(double value) {
|
||||
/**
|
||||
* Sets this GuiNumberInput's value without notifying the listeners.
|
||||
* @param value The value to set
|
||||
*/
|
||||
public void setValueQuietly(double value) {
|
||||
if(minimum != null && value < minimum) {
|
||||
setText(acceptFloats ? minimum.toString() : Integer.toString((int) Math.round(minimum)));
|
||||
} else if(maximum != null && value > maximum) {
|
||||
@@ -40,6 +50,22 @@ public class GuiNumberInput extends GuiAdvancedTextField {
|
||||
setCursorPositionZero();
|
||||
}
|
||||
|
||||
public void setValue(double value) {
|
||||
setValueQuietly(value);
|
||||
fireValueChangeEvent();
|
||||
}
|
||||
|
||||
public void addValueChangeListener(NumberValueChangeListener listener) {
|
||||
this.valueChangeListeners.add(listener);
|
||||
}
|
||||
|
||||
private void fireValueChangeEvent() {
|
||||
double val = acceptFloats ? getPreciseValue() : getIntValue();
|
||||
for(NumberValueChangeListener listener : valueChangeListeners) {
|
||||
listener.onValueChange(val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeText(String text) {
|
||||
String textBefore = getText();
|
||||
@@ -59,6 +85,8 @@ public class GuiNumberInput extends GuiAdvancedTextField {
|
||||
} else if(maximum != null && val > maximum) {
|
||||
setText(acceptFloats ? maximum.toString() : Integer.toString((int) Math.round(maximum)));
|
||||
}
|
||||
|
||||
fireValueChangeEvent();
|
||||
} catch(NumberFormatException e) {
|
||||
setText(textBefore);
|
||||
setCursorPosition(cursorPositionBefore);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements.listeners;
|
||||
|
||||
public interface NumberValueChangeListener {
|
||||
|
||||
void onValueChange(double value);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user