Warning, GIGANTIC COMMIT!
Replaced Keyframe subclasses with Generic Types of Keyframe and replaced all instanceof calls Replaced implementations of Linear and Spline interpolation to interpolate any Object that extends KeyframeValue and contains at least one public double Field. I'll need this for Keyframe interpolation in CustomImageObject Transformations Made MarkerKeyframe *no* subclass of Keyframe to avoid conflicts with PositionKeyframe in instanceof checks for Keyframe#getValue Created KeyframeList which extends ArrayList to provide some helping functions which DRY up the ReplayHandler Split up ReplayHandler's keyframeList into timeKeyframeList and positionKeyframeList
This commit is contained in:
@@ -1,264 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.gui;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.gui.elements.*;
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.FileChooseListener;
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.SelectionListener;
|
||||
import eu.crushedpixel.replaymod.holders.CustomImageObject;
|
||||
import eu.crushedpixel.replaymod.holders.Position;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiAssetAdder extends GuiScreen {
|
||||
|
||||
private String screenTitle;
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private GuiEntryList<CustomImageObject> objectList;
|
||||
private GuiButton removeButton;
|
||||
private GuiFileChooser addButton;
|
||||
private GuiFileChooser guiFileChooser;
|
||||
|
||||
private GuiAdvancedTextField nameInput;
|
||||
|
||||
private GuiNumberInput xInput, yInput, zInput, yawInput, pitchInput, rollInput, scaleInput, opacityInput;
|
||||
|
||||
private List<GuiTextField> textFields = new ArrayList<GuiTextField>();
|
||||
|
||||
public GuiAssetAdder() {
|
||||
ReplayMod.replaySender.setReplaySpeed(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
if(!initialized) {
|
||||
screenTitle = I18n.format("replaymod.gui.assets.title");
|
||||
|
||||
objectList = new GuiEntryList<CustomImageObject>(fontRendererObj, 0, 0, 0, 0);
|
||||
objectList.setEmptyMessage(I18n.format("replaymod.gui.assets.emptylist"));
|
||||
|
||||
for(CustomImageObject object : ReplayHandler.getCustomImageObjects()) {
|
||||
objectList.addElement(object);
|
||||
}
|
||||
|
||||
removeButton = new GuiButton(GuiConstants.ASSET_ADDER_REMOVE_BUTTON, 0, 0, I18n.format("replaymod.gui.remove"));
|
||||
|
||||
addButton = new GuiFileChooser(1, 0, 0, I18n.format("replaymod.gui.add"), null, ImageIO.getReaderFileSuffixes()) {
|
||||
@Override protected void updateDisplayString() {}
|
||||
};
|
||||
|
||||
addButton.addFileChooseListener(new FileChooseListener() {
|
||||
@Override
|
||||
public void onFileChosen(File file) {
|
||||
try {
|
||||
objectList.addElement(new CustomImageObject(new Position(mc.getRenderViewEntity()),
|
||||
I18n.format("replaymod.gui.assets.defaultname"), file));
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
nameInput = new GuiAdvancedTextField(fontRendererObj, 2, 0, 0, 20);
|
||||
nameInput.hint = I18n.format("replaymod.gui.assets.namehint");
|
||||
|
||||
xInput = new GuiNumberInput(3, fontRendererObj, 0, 0, 0, null, null, 0d, true);
|
||||
yInput = new GuiNumberInput(4, fontRendererObj, 0, 0, 0, null, null, 0d, true);
|
||||
zInput = new GuiNumberInput(5, fontRendererObj, 0, 0, 0, null, null, 0d, true);
|
||||
|
||||
yawInput = new GuiNumberInput(6, fontRendererObj, 0, 0, 0, -360d, 360d, 0d, true);
|
||||
pitchInput = new GuiNumberInput(7, fontRendererObj, 0, 0, 0, -360d, 360d, 0d, true);
|
||||
rollInput = new GuiNumberInput(8, fontRendererObj, 0, 0, 0, -360d, 360d, 0d, true);
|
||||
|
||||
scaleInput = new GuiNumberInputWithText(9, fontRendererObj, 0, 0, 0, 0d, 10000d, 100d, true, "%");
|
||||
opacityInput = new GuiNumberInputWithText(10, fontRendererObj, 0, 0, 0, 0d, 100d, 100d, true, "%");
|
||||
|
||||
guiFileChooser = new GuiFileChooser(3, 0, 0, I18n.format("replaymod.gui.assets.filechooser")+": ", null, ImageIO.getReaderFileSuffixes());
|
||||
guiFileChooser.addFileChooseListener(new FileChooseListener() {
|
||||
@Override
|
||||
public void onFileChosen(File file) {
|
||||
try {
|
||||
objectList.getElement(objectList.getSelectionIndex()).setImageFile(file);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
guiFileChooser.enabled = false;
|
||||
|
||||
textFields.add(objectList);
|
||||
textFields.add(nameInput);
|
||||
textFields.add(xInput);
|
||||
textFields.add(yInput);
|
||||
textFields.add(zInput);
|
||||
textFields.add(pitchInput);
|
||||
textFields.add(yawInput);
|
||||
textFields.add(rollInput);
|
||||
textFields.add(scaleInput);
|
||||
textFields.add(opacityInput);
|
||||
|
||||
objectList.addSelectionListener(new SelectionListener() {
|
||||
@Override
|
||||
public void onSelectionChanged(int selectionIndex) {
|
||||
CustomImageObject object = objectList.getElement(selectionIndex);
|
||||
if(object == null) {
|
||||
guiFileChooser.enabled = false;
|
||||
for(GuiTextField tf : textFields) {
|
||||
tf.setEnabled(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
guiFileChooser.enabled = true;
|
||||
for(GuiTextField tf : textFields) {
|
||||
tf.setEnabled(true);
|
||||
}
|
||||
|
||||
nameInput.setText(object.getName());
|
||||
guiFileChooser.setSelectedFile(object.getImageFile());
|
||||
xInput.setValue(object.getPosition().getX());
|
||||
yInput.setValue(object.getPosition().getY());
|
||||
zInput.setValue(object.getPosition().getZ());
|
||||
pitchInput.setValue(object.getPosition().getPitch());
|
||||
yawInput.setValue(object.getPosition().getYaw());
|
||||
rollInput.setValue(object.getPosition().getRoll());
|
||||
scaleInput.setValue(object.getPosition().getScale()*100);
|
||||
opacityInput.setValue(object.getPosition().getOpacity()*100);
|
||||
}
|
||||
});
|
||||
|
||||
if(objectList.getEntryCount() > 0) {
|
||||
objectList.setSelectionIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
int h = (int)Math.floor(((double)this.height-(45+20+15+20))/14);
|
||||
|
||||
objectList.width = guiFileChooser.width = nameInput.width = 150;
|
||||
objectList.xPosition = width/2 - objectList.width - 5;
|
||||
objectList.setVisibleElements(h);
|
||||
objectList.yPosition = 45;
|
||||
|
||||
addButton.width = removeButton.width = 75;
|
||||
addButton.xPosition = objectList.xPosition;
|
||||
removeButton.xPosition = addButton.xPosition+addButton.width;
|
||||
addButton.yPosition = removeButton.yPosition = objectList.yPosition + objectList.height + 2;
|
||||
|
||||
nameInput.xPosition = this.width/2 + 5;
|
||||
nameInput.yPosition = 45;
|
||||
|
||||
guiFileChooser.xPosition = this.width/2 + 5;
|
||||
guiFileChooser.yPosition = nameInput.yPosition + 20 + 5;
|
||||
|
||||
xInput.yPosition = yInput.yPosition = zInput.yPosition = guiFileChooser.yPosition + 20 + 5 + 15;
|
||||
yawInput.yPosition = pitchInput.yPosition = rollInput.yPosition = xInput.yPosition + 20 + 5 + 15;
|
||||
scaleInput.yPosition = opacityInput.yPosition = yawInput.yPosition + 20 + 5 + 15;
|
||||
|
||||
xInput.xPosition = scaleInput.xPosition = pitchInput.xPosition = this.width/2 + 8;
|
||||
yInput.xPosition = yawInput.xPosition = xInput.xPosition + 50;
|
||||
zInput.xPosition = rollInput.xPosition = yInput.xPosition + 50;
|
||||
opacityInput.xPosition = scaleInput.xPosition + 75;
|
||||
|
||||
xInput.width = yInput.width = zInput.width = yawInput.width = pitchInput.width = rollInput.width = 43;
|
||||
scaleInput.width = opacityInput.width = 68;
|
||||
|
||||
buttonList.add(removeButton);
|
||||
buttonList.add(addButton);
|
||||
buttonList.add(guiFileChooser);
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
this.drawCenteredString(fontRendererObj, screenTitle, this.width / 2, 5, Color.WHITE.getRGB());
|
||||
|
||||
int leftBorder = 10;
|
||||
int topBorder = 20;
|
||||
|
||||
drawGradientRect(leftBorder, topBorder, width - leftBorder, this.height - 10, -1072689136, -804253680);
|
||||
|
||||
for(GuiTextField textField : textFields) {
|
||||
textField.drawTextBox();
|
||||
}
|
||||
|
||||
drawCenteredString(fontRendererObj, "X", xInput.xPosition + (xInput.width/2), xInput.yPosition - 12, Color.WHITE.getRGB());
|
||||
drawCenteredString(fontRendererObj, "Y", yInput.xPosition + (yInput.width/2), yInput.yPosition - 12, Color.WHITE.getRGB());
|
||||
drawCenteredString(fontRendererObj, "Z", zInput.xPosition + (zInput.width/2), zInput.yPosition - 12, Color.WHITE.getRGB());
|
||||
|
||||
drawCenteredString(fontRendererObj, "Yaw", yawInput.xPosition + (yawInput.width/2), yawInput.yPosition - 12, Color.WHITE.getRGB());
|
||||
drawCenteredString(fontRendererObj, "Pitch", pitchInput.xPosition + (pitchInput.width/2), pitchInput.yPosition - 12, Color.WHITE.getRGB());
|
||||
drawCenteredString(fontRendererObj, "Roll", rollInput.xPosition + (rollInput.width/2), rollInput.yPosition - 12, Color.WHITE.getRGB());
|
||||
|
||||
drawCenteredString(fontRendererObj, "Scale", scaleInput.xPosition + (scaleInput.width/2), scaleInput.yPosition - 12, Color.WHITE.getRGB());
|
||||
drawCenteredString(fontRendererObj, "Opacity", opacityInput.xPosition + (opacityInput.width/2), opacityInput.yPosition - 12, Color.WHITE.getRGB());
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
for(GuiTextField textField : textFields) {
|
||||
textField.updateCursorCounter();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
for(GuiTextField textField : textFields) {
|
||||
textField.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
for(GuiTextField textField : textFields) {
|
||||
textField.textboxKeyTyped(typedChar, keyCode);
|
||||
}
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
|
||||
if(guiFileChooser.enabled) {
|
||||
CustomImageObject current = objectList.getElement(objectList.getSelectionIndex());
|
||||
if(current == null) return;
|
||||
|
||||
current.setName(nameInput.getText().trim());
|
||||
current.getPosition().setX(xInput.getPreciseValue());
|
||||
current.getPosition().setY(yInput.getPreciseValue());
|
||||
current.getPosition().setZ(zInput.getPreciseValue());
|
||||
current.getPosition().setPitch((float) pitchInput.getPreciseValue());
|
||||
current.getPosition().setYaw((float) yawInput.getPreciseValue());
|
||||
current.getPosition().setRoll((float) rollInput.getPreciseValue());
|
||||
current.getPosition().setScale((float) scaleInput.getPreciseValue() / 100f);
|
||||
current.getPosition().setOpacity((float) opacityInput.getPreciseValue() / 100f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
ReplayHandler.setCustomImageObjects(objectList.getCopyOfElements());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
if(!button.enabled) return;
|
||||
|
||||
if(button.id == GuiConstants.ASSET_ADDER_REMOVE_BUTTON) {
|
||||
CustomImageObject current = objectList.getElement(objectList.getSelectionIndex());
|
||||
if(current == null) return;
|
||||
|
||||
objectList.removeElement(objectList.getSelectionIndex());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package eu.crushedpixel.replaymod.gui;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.events.KeyframesModifyEvent;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiAdvancedTextField;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiArrowButton;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiNumberInput;
|
||||
import eu.crushedpixel.replaymod.holders.*;
|
||||
import eu.crushedpixel.replaymod.holders.Keyframe;
|
||||
import eu.crushedpixel.replaymod.holders.Position;
|
||||
import eu.crushedpixel.replaymod.holders.TimestampValue;
|
||||
import eu.crushedpixel.replaymod.interpolation.KeyframeList;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.utils.RoundUtils;
|
||||
import eu.crushedpixel.replaymod.utils.TimestampUtils;
|
||||
@@ -13,7 +14,6 @@ import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -31,8 +31,6 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
private GuiNumberInput xCoord, yCoord, zCoord, pitch, yaw, roll;
|
||||
private GuiNumberInput min, sec, ms;
|
||||
|
||||
private GuiAdvancedTextField markerNameInput;
|
||||
|
||||
private List<GuiTextField> inputs = new ArrayList<GuiTextField>();
|
||||
private List<GuiTextField> posInputs = new ArrayList<GuiTextField>();
|
||||
|
||||
@@ -43,7 +41,6 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
private Keyframe keyframeBackup;
|
||||
private boolean save;
|
||||
private boolean posKeyframe;
|
||||
private boolean markerKeyframe;
|
||||
|
||||
private Keyframe previous, next;
|
||||
|
||||
@@ -57,27 +54,24 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
public GuiEditKeyframe(Keyframe keyframe) {
|
||||
this.keyframe = keyframe;
|
||||
this.keyframeBackup = keyframe.copy();
|
||||
this.posKeyframe = keyframe instanceof PositionKeyframe;
|
||||
boolean timeKeyframe = keyframe instanceof TimeKeyframe;
|
||||
this.markerKeyframe = keyframe instanceof MarkerKeyframe;
|
||||
this.posKeyframe = keyframe.getValue() instanceof Position;
|
||||
boolean timeKeyframe = keyframe.getValue() instanceof TimestampValue;
|
||||
|
||||
ReplayHandler.selectKeyframe(null);
|
||||
|
||||
KeyframeList<Keyframe<Position>> positionKeyframes = ReplayHandler.getPositionKeyframes();
|
||||
KeyframeList<Keyframe<TimestampValue>> timeKeyframes = ReplayHandler.getTimeKeyframes();
|
||||
|
||||
if(posKeyframe) {
|
||||
previous = ReplayHandler.getPreviousPositionKeyframe(keyframe.getRealTimestamp() - 1);
|
||||
next = ReplayHandler.getNextPositionKeyframe(keyframe.getRealTimestamp() + 1);
|
||||
previous = positionKeyframes.getPreviousKeyframe(keyframe.getRealTimestamp() - 1);
|
||||
next = positionKeyframes.getNextKeyframe(keyframe.getRealTimestamp() + 1);
|
||||
|
||||
screenTitle = I18n.format("replaymod.gui.editkeyframe.title.pos");
|
||||
} else if(timeKeyframe) {
|
||||
previous = ReplayHandler.getPreviousTimeKeyframe(keyframe.getRealTimestamp() - 1);
|
||||
next = ReplayHandler.getNextTimeKeyframe(keyframe.getRealTimestamp() + 1);
|
||||
previous = timeKeyframes.getPreviousKeyframe(keyframe.getRealTimestamp() - 1);
|
||||
next = timeKeyframes.getNextKeyframe(keyframe.getRealTimestamp() + 1);
|
||||
|
||||
screenTitle = I18n.format("replaymod.gui.editkeyframe.title.time");
|
||||
} else if(markerKeyframe) {
|
||||
previous = ReplayHandler.getPreviousMarkerKeyframe(keyframe.getRealTimestamp() - 1);
|
||||
next = ReplayHandler.getNextMarkerKeyframe(keyframe.getRealTimestamp() + 1);
|
||||
|
||||
screenTitle = I18n.format("replaymod.gui.editkeyframe.title.marker");
|
||||
}
|
||||
|
||||
ReplayHandler.selectKeyframe(keyframe);
|
||||
@@ -113,7 +107,7 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
|
||||
//Position/Virtual Time Input
|
||||
if(posKeyframe) {
|
||||
Position pos = ((PositionKeyframe)keyframe).getPosition();
|
||||
Position pos = ((Keyframe<Position>)keyframe).getValue();
|
||||
xCoord = new GuiNumberInput(GuiConstants.KEYFRAME_EDITOR_X_INPUT, fontRendererObj, 0, 0, 100, null, null, RoundUtils.round(pos.getX()), true);
|
||||
yCoord = new GuiNumberInput(GuiConstants.KEYFRAME_EDITOR_Y_INPUT, fontRendererObj, 0, 0, 100, null, null, RoundUtils.round(pos.getY()), true);
|
||||
zCoord = new GuiNumberInput(GuiConstants.KEYFRAME_EDITOR_Z_INPUT, fontRendererObj, 0, 0, 100, null, null, RoundUtils.round(pos.getZ()), true);
|
||||
@@ -129,11 +123,6 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
posInputs.add(roll);
|
||||
|
||||
inputs.addAll(posInputs);
|
||||
} else if(markerKeyframe) {
|
||||
markerNameInput = new GuiAdvancedTextField(fontRendererObj, 0, 0, 300, 20);
|
||||
markerNameInput.setText(((MarkerKeyframe)keyframe).getName() == null ? "" : ((MarkerKeyframe)keyframe).getName());
|
||||
inputs.add(markerNameInput);
|
||||
markerNameInput.hint = I18n.format("replaymod.gui.editkeyframe.markername");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,9 +159,6 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
input.yPosition = i < 3 ? virtualY + 20 + i*30 : virtualY + 20 + (i-3)*30;
|
||||
i++;
|
||||
}
|
||||
} else if(markerKeyframe) {
|
||||
markerNameInput.xPosition = (width-markerNameInput.width)/2;
|
||||
markerNameInput.yPosition = virtualY + (virtualHeight-markerNameInput.height)/2;
|
||||
}
|
||||
|
||||
saveButton.yPosition = cancelButton.yPosition = virtualY + virtualHeight - 20 - 5;
|
||||
@@ -204,14 +190,12 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
} else {
|
||||
keyframe.setRealTimestamp(TimestampUtils.calculateTimestamp(min.getIntValue(), sec.getIntValue(), ms.getIntValue()));
|
||||
if(posKeyframe) {
|
||||
((PositionKeyframe)keyframe).setPosition(new Position(xCoord.getPreciseValue(), yCoord.getPreciseValue(),
|
||||
zCoord.getPreciseValue(), new Float(pitch.getPreciseValue()), (float)yaw.getPreciseValue(),
|
||||
(float)roll.getPreciseValue()));
|
||||
} else if(markerKeyframe) {
|
||||
((MarkerKeyframe)keyframe).setName(markerNameInput.getText().trim());
|
||||
((Keyframe<Position>)keyframe).setValue(new Position(xCoord.getPreciseValue(), yCoord.getPreciseValue(),
|
||||
zCoord.getPreciseValue(), new Float(pitch.getPreciseValue()), (float) yaw.getPreciseValue(),
|
||||
(float) roll.getPreciseValue(), null));
|
||||
}
|
||||
}
|
||||
FMLCommonHandler.instance().bus().post(new KeyframesModifyEvent(ReplayHandler.getKeyframes()));
|
||||
ReplayHandler.fireKeyframesModifyEvent();
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import eu.crushedpixel.replaymod.gui.elements.listeners.SelectionListener;
|
||||
import eu.crushedpixel.replaymod.gui.overlay.GuiReplayOverlay;
|
||||
import eu.crushedpixel.replaymod.holders.Keyframe;
|
||||
import eu.crushedpixel.replaymod.holders.KeyframeSet;
|
||||
import eu.crushedpixel.replaymod.holders.MarkerKeyframe;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
@@ -132,12 +131,9 @@ public class GuiKeyframeRepository extends GuiScreen implements GuiReplayOverlay
|
||||
if(!button.enabled) return;
|
||||
switch(button.id) {
|
||||
case GuiConstants.KEYFRAME_REPOSITORY_ADD_BUTTON:
|
||||
List<Keyframe> kfs = new ArrayList<Keyframe>(ReplayHandler.getKeyframes());
|
||||
for(Keyframe kf : new ArrayList<Keyframe>(kfs)) {
|
||||
if(kf instanceof MarkerKeyframe) kfs.remove(kf);
|
||||
}
|
||||
List<Keyframe> kfs = new ArrayList<Keyframe>(ReplayHandler.getAllKeyframes());
|
||||
|
||||
Keyframe[] keyframes = kfs.toArray(new Keyframe[ReplayHandler.getKeyframes().size()]);
|
||||
Keyframe[] keyframes = kfs.toArray(new Keyframe[ReplayHandler.getAllKeyframes().size()]);
|
||||
KeyframeSet newSet = new KeyframeSet(I18n.format("replaymod.gui.keyframerepository.preset.defaultname"), keyframes);
|
||||
if(newSet.getPositionKeyframeCount() < 2 || newSet.getTimeKeyframeCount() < 1) {
|
||||
message = I18n.format("replaymod.chat.morekeyframes");
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.gui.GuiEditKeyframe;
|
||||
import eu.crushedpixel.replaymod.holders.Keyframe;
|
||||
import eu.crushedpixel.replaymod.holders.MarkerKeyframe;
|
||||
import eu.crushedpixel.replaymod.holders.PositionKeyframe;
|
||||
import eu.crushedpixel.replaymod.holders.TimeKeyframe;
|
||||
import eu.crushedpixel.replaymod.holders.Position;
|
||||
import eu.crushedpixel.replaymod.holders.TimestampValue;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import org.lwjgl.util.Point;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class GuiKeyframeTimeline extends GuiTimeline {
|
||||
@@ -22,21 +16,17 @@ public class GuiKeyframeTimeline extends GuiTimeline {
|
||||
private static final int KEYFRAME_TIME_Y = 25;
|
||||
private static final int KEYFRAME_SPEC_X = 74;
|
||||
private static final int KEYFRAME_SPEC_Y = 30;
|
||||
private static final int KEYFRAME_MARKER_X = 109;
|
||||
private static final int KEYFRAME_MARKER_Y = 20;
|
||||
|
||||
private Keyframe clickedKeyFrame;
|
||||
private long clickTime;
|
||||
private boolean dragging;
|
||||
private boolean markerKeyframes;
|
||||
private boolean timeKeyframes;
|
||||
private boolean placeKeyframes;
|
||||
|
||||
public GuiKeyframeTimeline(int positionX, int positionY, int width, boolean showMarkers,
|
||||
boolean showMarkerKeyframes, boolean showPlaceKeyframes, boolean showTimeKeyframes) {
|
||||
boolean showPlaceKeyframes, boolean showTimeKeyframes) {
|
||||
super(positionX, positionY, width);
|
||||
this.showMarkers = showMarkers;
|
||||
this.markerKeyframes = showMarkerKeyframes;
|
||||
this.timeKeyframes = showTimeKeyframes;
|
||||
this.placeKeyframes = showPlaceKeyframes;
|
||||
}
|
||||
@@ -55,11 +45,9 @@ public class GuiKeyframeTimeline extends GuiTimeline {
|
||||
|
||||
Keyframe closest;
|
||||
if(mouseY >= positionY + BORDER_TOP + 5 && timeKeyframes) {
|
||||
closest = ReplayHandler.getClosestTimeKeyframeForRealTime((int) time, tolerance);
|
||||
closest = ReplayHandler.getTimeKeyframes().getClosestKeyframeForTimestamp((int) time, tolerance);
|
||||
} else if(mouseY >= positionY + BORDER_TOP && placeKeyframes) {
|
||||
closest = ReplayHandler.getClosestPlaceKeyframeForRealTime((int) time, tolerance);
|
||||
} else if(mouseY >= positionY + BORDER_TOP + 10 && markerKeyframes) {
|
||||
closest = ReplayHandler.getClosestMarkerForRealTime((int) time, tolerance);
|
||||
closest = ReplayHandler.getPositionKeyframes().getClosestKeyframeForTimestamp((int) time, tolerance);
|
||||
} else {
|
||||
closest = null;
|
||||
}
|
||||
@@ -84,26 +72,6 @@ public class GuiKeyframeTimeline extends GuiTimeline {
|
||||
}
|
||||
this.clickTime = currentTime;
|
||||
|
||||
} else if(button == 1) {
|
||||
if(markerKeyframes) {
|
||||
long time = getTimeAt(mouseX, mouseY);
|
||||
if(time == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
int tolerance = (int) (2 * Math.round(zoom * timelineLength / width));
|
||||
|
||||
MarkerKeyframe closest = null;
|
||||
if(mouseY >= positionY + BORDER_TOP + 10 && markerKeyframes) {
|
||||
closest = ReplayHandler.getClosestMarkerForRealTime((int) time, tolerance);
|
||||
}
|
||||
|
||||
if(closest != null) {
|
||||
//Jump to clicked Marker Keyframe
|
||||
ReplayHandler.setLastPosition(closest.getPosition());
|
||||
ReplayMod.replaySender.jumpToTime(closest.getRealTimestamp());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +85,8 @@ public class GuiKeyframeTimeline extends GuiTimeline {
|
||||
|
||||
if (dragging || Math.abs(clickedKeyFrame.getRealTimestamp() - time) > tolerance) {
|
||||
clickedKeyFrame.setRealTimestamp((int) time);
|
||||
ReplayHandler.sortKeyframes();
|
||||
ReplayHandler.getPositionKeyframes().sort();
|
||||
ReplayHandler.getTimeKeyframes().sort();
|
||||
dragging = true;
|
||||
}
|
||||
} else if (dragging && placeKeyframes) {
|
||||
@@ -146,22 +115,22 @@ public class GuiKeyframeTimeline extends GuiTimeline {
|
||||
|
||||
//iterate over keyframes to find spectator segments
|
||||
if(placeKeyframes) {
|
||||
ListIterator<Keyframe> iterator = ReplayHandler.getKeyframes().listIterator();
|
||||
ListIterator<Keyframe<Position>> iterator = ReplayHandler.getPositionKeyframes().listIterator();
|
||||
while(iterator.hasNext()) {
|
||||
Keyframe kf = iterator.next();
|
||||
Keyframe<Position> kf = iterator.next();
|
||||
|
||||
if(!(kf instanceof PositionKeyframe) || ((PositionKeyframe) kf).getSpectatedEntityID() == null)
|
||||
if(kf.getValue().getSpectatedEntityID() == null)
|
||||
continue;
|
||||
|
||||
int i = iterator.nextIndex();
|
||||
int nextSpectatorKeyframeRealTime = -1;
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Keyframe kf2 = iterator.next();
|
||||
Keyframe<Position> kf2 = iterator.next();
|
||||
|
||||
if(kf2 instanceof PositionKeyframe) {
|
||||
if(((PositionKeyframe) kf).getSpectatedEntityID()
|
||||
.equals(((PositionKeyframe) kf2).getSpectatedEntityID())) {
|
||||
if(kf2.getValue() instanceof Position) {
|
||||
if(kf.getValue().getSpectatedEntityID()
|
||||
.equals(kf2.getValue().getSpectatedEntityID())) {
|
||||
|
||||
nextSpectatorKeyframeRealTime = kf2.getRealTimestamp();
|
||||
}
|
||||
@@ -189,7 +158,7 @@ public class GuiKeyframeTimeline extends GuiTimeline {
|
||||
|
||||
|
||||
//Draw Keyframe logos
|
||||
for (Keyframe kf : ReplayHandler.getKeyframes()) {
|
||||
for (Keyframe kf : ReplayHandler.getAllKeyframes()) {
|
||||
if (kf != null && !kf.equals(ReplayHandler.getSelectedKeyframe()))
|
||||
drawKeyframe(kf, bodyWidth, leftTime, rightTime, segmentLength);
|
||||
}
|
||||
@@ -214,21 +183,6 @@ public class GuiKeyframeTimeline extends GuiTimeline {
|
||||
long leftTime = Math.round(timeStart * timelineLength);
|
||||
double segmentLength = timelineLength * zoom;
|
||||
|
||||
if(markerKeyframes) {
|
||||
for(MarkerKeyframe marker : ReplayHandler.getMarkers()) {
|
||||
int keyframeX = getKeyframeX(marker.getRealTimestamp(), leftTime, bodyWidth, segmentLength);
|
||||
|
||||
if(MouseUtils.isMouseWithinBounds(keyframeX - 2, this.positionY + BORDER_TOP + 10 + 1, 5, 5)) {
|
||||
Point mouse = MouseUtils.getMousePos();
|
||||
String markerName = marker.getName();
|
||||
if(markerName == null) markerName = I18n.format("replaymod.gui.ingame.unnamedmarker");
|
||||
ReplayMod.tooltipRenderer.drawTooltip(mouse.getX(), mouse.getY(), markerName, null, Color.WHITE);
|
||||
|
||||
drawn = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!drawn) {
|
||||
super.drawOverlay(mc, mouseX, mouseY);
|
||||
}
|
||||
@@ -242,27 +196,22 @@ public class GuiKeyframeTimeline extends GuiTimeline {
|
||||
|
||||
int keyframeX = getKeyframeX(kf.getRealTimestamp(), leftTime, bodyWidth, segmentLength);
|
||||
|
||||
if(kf instanceof PositionKeyframe) {
|
||||
if(kf.getValue() instanceof Position) {
|
||||
if(!placeKeyframes) return;
|
||||
textureX = KEYFRAME_PLACE_X;
|
||||
textureY = KEYFRAME_PLACE_Y;
|
||||
y += 0;
|
||||
|
||||
//If Spectator Keyframe, use different texture
|
||||
if(((PositionKeyframe) kf).getSpectatedEntityID() != null) {
|
||||
if(((Keyframe<Position>) kf).getValue().getSpectatedEntityID() != null) {
|
||||
textureX = KEYFRAME_SPEC_X;
|
||||
textureY = KEYFRAME_SPEC_Y;
|
||||
}
|
||||
} else if(kf instanceof TimeKeyframe) {
|
||||
} else if(kf.getValue() instanceof TimestampValue) {
|
||||
if(!timeKeyframes) return;
|
||||
textureX = KEYFRAME_TIME_X;
|
||||
textureY = KEYFRAME_TIME_Y;
|
||||
y += 5;
|
||||
} else if(kf instanceof MarkerKeyframe) {
|
||||
if(!markerKeyframes) return;
|
||||
textureX = KEYFRAME_MARKER_X;
|
||||
textureY = KEYFRAME_MARKER_Y;
|
||||
y += 10;
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Unknown keyframe type: " + kf.getClass());
|
||||
}
|
||||
|
||||
@@ -7,10 +7,9 @@ import eu.crushedpixel.replaymod.gui.GuiMouseInput;
|
||||
import eu.crushedpixel.replaymod.gui.GuiRenderSettings;
|
||||
import eu.crushedpixel.replaymod.gui.GuiReplaySpeedSlider;
|
||||
import eu.crushedpixel.replaymod.gui.elements.*;
|
||||
import eu.crushedpixel.replaymod.holders.MarkerKeyframe;
|
||||
import eu.crushedpixel.replaymod.holders.Keyframe;
|
||||
import eu.crushedpixel.replaymod.holders.Position;
|
||||
import eu.crushedpixel.replaymod.holders.PositionKeyframe;
|
||||
import eu.crushedpixel.replaymod.holders.TimeKeyframe;
|
||||
import eu.crushedpixel.replaymod.holders.TimestampValue;
|
||||
import eu.crushedpixel.replaymod.registry.ReplayGuiRegistry;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
@@ -98,7 +97,7 @@ public class GuiReplayOverlay extends Gui {
|
||||
@Override
|
||||
public void run() {
|
||||
//if not enough keyframes, abort and leave chat message
|
||||
if(ReplayHandler.getPosKeyframeCount() < 2 || ReplayHandler.getTimeKeyframeCount() < 1) {
|
||||
if(ReplayHandler.getPositionKeyframes().size() < 2 || ReplayHandler.getTimeKeyframes().size() < 1) {
|
||||
ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.morekeyframes", ChatMessageHandler.ChatMessageType.WARNING);
|
||||
} else {
|
||||
mc.displayGuiScreen(new GuiRenderSettings());
|
||||
@@ -137,12 +136,12 @@ public class GuiReplayOverlay extends Gui {
|
||||
Entity cam = mc.getRenderViewEntity();
|
||||
if (cam != null) {
|
||||
Position position = new Position(cam.posX, cam.posY, cam.posZ, cam.rotationPitch,
|
||||
cam.rotationYaw % 360, ReplayHandler.getCameraTilt());
|
||||
cam.rotationYaw % 360, ReplayHandler.getCameraTilt(), null);
|
||||
|
||||
if (ReplayHandler.isCamera())
|
||||
ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), position));
|
||||
ReplayHandler.addKeyframe(new Keyframe<Position>(ReplayHandler.getRealTimelineCursor(), position));
|
||||
else
|
||||
ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), cam.getEntityId()));
|
||||
ReplayHandler.addKeyframe(new Keyframe<Position>(ReplayHandler.getRealTimelineCursor(), new Position(cam.getEntityId(), true)));
|
||||
}
|
||||
}
|
||||
}, "replaymod.gui.ingame.menu.addposkeyframe");
|
||||
@@ -160,12 +159,12 @@ public class GuiReplayOverlay extends Gui {
|
||||
Entity cam = mc.getRenderViewEntity();
|
||||
if (cam != null) {
|
||||
Position position = new Position(cam.posX, cam.posY, cam.posZ, cam.rotationPitch,
|
||||
cam.rotationYaw % 360, ReplayHandler.getCameraTilt());
|
||||
cam.rotationYaw % 360, ReplayHandler.getCameraTilt(), null);
|
||||
|
||||
if (ReplayHandler.isCamera())
|
||||
ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), position));
|
||||
ReplayHandler.addKeyframe(new Keyframe<Position>(ReplayHandler.getRealTimelineCursor(), position));
|
||||
else
|
||||
ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), cam.getEntityId()));
|
||||
ReplayHandler.addKeyframe(new Keyframe<Position>(ReplayHandler.getRealTimelineCursor(), new Position(cam.getEntityId(), true)));
|
||||
}
|
||||
}
|
||||
}, "replaymod.gui.ingame.menu.addspeckeyframe");
|
||||
@@ -179,10 +178,10 @@ public class GuiReplayOverlay extends Gui {
|
||||
|
||||
@Override
|
||||
public GuiElement delegate() {
|
||||
boolean selected = ReplayHandler.getSelectedKeyframe() instanceof PositionKeyframe;
|
||||
boolean selected = ReplayHandler.getSelectedKeyframe() != null && ReplayHandler.getSelectedKeyframe().getValue() instanceof Position;
|
||||
boolean camera;
|
||||
if(selected) {
|
||||
camera = ((PositionKeyframe)ReplayHandler.getSelectedKeyframe()).getSpectatedEntityID() == null;
|
||||
camera = ((Keyframe<Position>)ReplayHandler.getSelectedKeyframe()).getValue().getSpectatedEntityID() == null;
|
||||
} else {
|
||||
camera = ReplayHandler.isCamera();
|
||||
}
|
||||
@@ -200,7 +199,7 @@ public class GuiReplayOverlay extends Gui {
|
||||
private final GuiElement buttonNotSelected = texturedButton(BUTTON_TIME_X, BOTTOM_ROW, 0, 80, 20, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayHandler.addKeyframe(new TimeKeyframe(ReplayHandler.getRealTimelineCursor(), ReplayMod.replaySender.currentTimeStamp()));
|
||||
ReplayHandler.addKeyframe(new Keyframe<TimestampValue>(ReplayHandler.getRealTimelineCursor(), new TimestampValue(ReplayMod.replaySender.currentTimeStamp())));
|
||||
}
|
||||
}, "replaymod.gui.ingame.menu.addtimekeyframe");
|
||||
|
||||
@@ -213,7 +212,7 @@ public class GuiReplayOverlay extends Gui {
|
||||
|
||||
@Override
|
||||
public GuiElement delegate() {
|
||||
return ReplayHandler.getSelectedKeyframe() instanceof TimeKeyframe ? buttonSelected : buttonNotSelected;
|
||||
return ReplayHandler.getSelectedKeyframe() != null && ReplayHandler.getSelectedKeyframe().getValue() instanceof TimestampValue ? buttonSelected : buttonNotSelected;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -233,17 +232,12 @@ public class GuiReplayOverlay extends Gui {
|
||||
}
|
||||
}, "replaymod.gui.ingame.menu.zoomout");
|
||||
|
||||
private final GuiKeyframeTimeline timeline = new GuiKeyframeTimeline(TIMELINE_X, TOP_ROW - 1, WIDTH - 14 - TIMELINE_X, false, true, false, false) {
|
||||
@Override
|
||||
public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
|
||||
if(!enabled) return;
|
||||
super.mouseClick(mc, mouseX, mouseY, button);
|
||||
if(!(ReplayHandler.getSelectedKeyframe() instanceof MarkerKeyframe))
|
||||
performJump(timeline.getTimeAt(mouseX, mouseY));
|
||||
}
|
||||
//TODO: GuiMarkerKeyframeTimeline
|
||||
private final GuiKeyframeTimeline timeline = new GuiKeyframeTimeline(TIMELINE_X, TOP_ROW - 1, WIDTH - 14 - TIMELINE_X, false, false, false) {
|
||||
|
||||
};
|
||||
|
||||
private final GuiKeyframeTimeline timelineReal = new GuiKeyframeTimeline(TIMELINE_REAL_X, BOTTOM_ROW - 1, TIMELINE_REAL_WIDTH, true, false, true, true);
|
||||
private final GuiKeyframeTimeline timelineReal = new GuiKeyframeTimeline(TIMELINE_REAL_X, BOTTOM_ROW - 1, TIMELINE_REAL_WIDTH, true, true, true);
|
||||
{
|
||||
timelineReal.timelineLength = 10 * 60 * 1000;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user