Marker Keyframes are now being saved in a KeyframeList in the ReplayHandler

Made MarkerKeyframes names editable in GuiEditKeyframe
Shows "Unnamed Marker" if Marker name is empty
This commit is contained in:
CrushedPixel
2015-07-13 01:21:48 +02:00
parent f55f169d01
commit 66c595eb04
5 changed files with 66 additions and 33 deletions

View File

@@ -1,10 +1,13 @@
package eu.crushedpixel.replaymod.gui; package eu.crushedpixel.replaymod.gui;
import eu.crushedpixel.replaymod.ReplayMod; import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.gui.elements.GuiAdvancedTextField;
import eu.crushedpixel.replaymod.gui.elements.GuiArrowButton; import eu.crushedpixel.replaymod.gui.elements.GuiArrowButton;
import eu.crushedpixel.replaymod.gui.elements.GuiDraggingNumberInput;
import eu.crushedpixel.replaymod.gui.elements.GuiNumberInput; import eu.crushedpixel.replaymod.gui.elements.GuiNumberInput;
import eu.crushedpixel.replaymod.holders.Keyframe;
import eu.crushedpixel.replaymod.holders.AdvancedPosition; import eu.crushedpixel.replaymod.holders.AdvancedPosition;
import eu.crushedpixel.replaymod.holders.Keyframe;
import eu.crushedpixel.replaymod.holders.Marker;
import eu.crushedpixel.replaymod.holders.TimestampValue; import eu.crushedpixel.replaymod.holders.TimestampValue;
import eu.crushedpixel.replaymod.interpolation.KeyframeList; import eu.crushedpixel.replaymod.interpolation.KeyframeList;
import eu.crushedpixel.replaymod.replay.ReplayHandler; import eu.crushedpixel.replaymod.replay.ReplayHandler;
@@ -31,6 +34,8 @@ public class GuiEditKeyframe extends GuiScreen {
private GuiNumberInput xCoord, yCoord, zCoord, pitch, yaw, roll; private GuiNumberInput xCoord, yCoord, zCoord, pitch, yaw, roll;
private GuiNumberInput min, sec, ms; private GuiNumberInput min, sec, ms;
private GuiAdvancedTextField markerNameInput;
private List<GuiTextField> inputs = new ArrayList<GuiTextField>(); private List<GuiTextField> inputs = new ArrayList<GuiTextField>();
private List<GuiTextField> posInputs = new ArrayList<GuiTextField>(); private List<GuiTextField> posInputs = new ArrayList<GuiTextField>();
@@ -41,6 +46,7 @@ public class GuiEditKeyframe extends GuiScreen {
private Keyframe keyframeBackup; private Keyframe keyframeBackup;
private boolean save; private boolean save;
private boolean posKeyframe; private boolean posKeyframe;
private boolean markerKeyframe;
private Keyframe previous, next; private Keyframe previous, next;
@@ -55,12 +61,12 @@ public class GuiEditKeyframe extends GuiScreen {
this.keyframe = keyframe; this.keyframe = keyframe;
this.keyframeBackup = keyframe.copy(); this.keyframeBackup = keyframe.copy();
this.posKeyframe = keyframe.getValue() instanceof AdvancedPosition; this.posKeyframe = keyframe.getValue() instanceof AdvancedPosition;
this.markerKeyframe = keyframe.getValue() instanceof Marker;
boolean timeKeyframe = keyframe.getValue() instanceof TimestampValue; boolean timeKeyframe = keyframe.getValue() instanceof TimestampValue;
ReplayHandler.selectKeyframe(null);
KeyframeList<AdvancedPosition> positionKeyframes = ReplayHandler.getPositionKeyframes(); KeyframeList<AdvancedPosition> positionKeyframes = ReplayHandler.getPositionKeyframes();
KeyframeList<TimestampValue> timeKeyframes = ReplayHandler.getTimeKeyframes(); KeyframeList<TimestampValue> timeKeyframes = ReplayHandler.getTimeKeyframes();
KeyframeList<Marker> markerKeyframes = ReplayHandler.getMarkers();
if(posKeyframe) { if(posKeyframe) {
previous = positionKeyframes.getPreviousKeyframe(keyframe.getRealTimestamp() - 1); previous = positionKeyframes.getPreviousKeyframe(keyframe.getRealTimestamp() - 1);
@@ -72,10 +78,11 @@ public class GuiEditKeyframe extends GuiScreen {
next = timeKeyframes.getNextKeyframe(keyframe.getRealTimestamp() + 1); next = timeKeyframes.getNextKeyframe(keyframe.getRealTimestamp() + 1);
screenTitle = I18n.format("replaymod.gui.editkeyframe.title.time"); screenTitle = I18n.format("replaymod.gui.editkeyframe.title.time");
} else if(markerKeyframe) {
previous = markerKeyframes.getPreviousKeyframe(keyframe.getRealTimestamp() - 1);
next = markerKeyframes.getNextKeyframe(keyframe.getRealTimestamp() + 1);
} }
ReplayHandler.selectKeyframe(keyframe);
ReplayMod.replaySender.setReplaySpeed(0); ReplayMod.replaySender.setReplaySpeed(0);
} }
@@ -97,9 +104,9 @@ public class GuiEditKeyframe extends GuiScreen {
//Real Time Input //Real Time Input
int timestamp = keyframe.getRealTimestamp(); int timestamp = keyframe.getRealTimestamp();
min = new GuiNumberInput(fontRendererObj, 0, 0, 30, 0, 9, TimestampUtils.getMinutesFromTimestamp(timestamp), false); min = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 30, 0d, 9d, (double)TimestampUtils.getMinutesFromTimestamp(timestamp), false);
sec = new GuiNumberInput(fontRendererObj, 0, 0, 25, 0, 59, TimestampUtils.getSecondsFromTimestamp(timestamp), false); sec = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 25, 0d, 59d, (double)TimestampUtils.getSecondsFromTimestamp(timestamp), false);
ms = new GuiNumberInput(fontRendererObj, 0, 0, 35, 0, 999, TimestampUtils.getMillisecondsFromTimestamp(timestamp), false); ms = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 35, 0d, 999d, (double)TimestampUtils.getMillisecondsFromTimestamp(timestamp), false);
inputs.add(min); inputs.add(min);
inputs.add(sec); inputs.add(sec);
@@ -108,12 +115,12 @@ public class GuiEditKeyframe extends GuiScreen {
//Position/Virtual Time Input //Position/Virtual Time Input
if(posKeyframe) { if(posKeyframe) {
AdvancedPosition pos = ((Keyframe<AdvancedPosition>)keyframe).getValue(); AdvancedPosition pos = ((Keyframe<AdvancedPosition>)keyframe).getValue();
xCoord = new GuiNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round2Decimals(pos.getX()), true); xCoord = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round2Decimals(pos.getX()), true);
yCoord = new GuiNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round2Decimals(pos.getY()), true); yCoord = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round2Decimals(pos.getY()), true);
zCoord = new GuiNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round2Decimals(pos.getZ()), true); zCoord = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round2Decimals(pos.getZ()), true);
yaw = new GuiNumberInput(fontRendererObj, 0, 0, 100, -90d, 90d, RoundUtils.round2Decimals(pos.getYaw()), true); yaw = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 100, -90d, 90d, RoundUtils.round2Decimals(pos.getYaw()), true);
pitch = new GuiNumberInput(fontRendererObj, 0, 0, 100, -180d, 180d, RoundUtils.round2Decimals(pos.getPitch()), true); pitch = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 100, -180d, 180d, RoundUtils.round2Decimals(pos.getPitch()), true);
roll = new GuiNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round2Decimals(pos.getRoll()), true); roll = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round2Decimals(pos.getRoll()), true);
posInputs.add(xCoord); posInputs.add(xCoord);
posInputs.add(yCoord); posInputs.add(yCoord);
@@ -123,6 +130,14 @@ public class GuiEditKeyframe extends GuiScreen {
posInputs.add(roll); posInputs.add(roll);
inputs.addAll(posInputs); inputs.addAll(posInputs);
} else if(markerKeyframe) {
String name = ((Keyframe<Marker>)keyframe).getValue().getName();
if(name == null) name = "";
markerNameInput = new GuiAdvancedTextField(fontRendererObj, 0, 0, 200, 20);
markerNameInput.hint = I18n.format("replaymod.gui.editkeyframe.markername");
markerNameInput.setText(name);
inputs.add(markerNameInput);
} }
} }
@@ -159,6 +174,9 @@ public class GuiEditKeyframe extends GuiScreen {
input.yPosition = i < 3 ? virtualY + 20 + i*30 : virtualY + 20 + (i-3)*30; input.yPosition = i < 3 ? virtualY + 20 + i*30 : virtualY + 20 + (i-3)*30;
i++; i++;
} }
} else if(markerKeyframe) {
markerNameInput.xPosition = width/2 - 100;
markerNameInput.yPosition = height/2-10;
} }
saveButton.yPosition = cancelButton.yPosition = virtualY + virtualHeight - 20 - 5; saveButton.yPosition = cancelButton.yPosition = virtualY + virtualHeight - 20 - 5;
@@ -184,15 +202,23 @@ public class GuiEditKeyframe extends GuiScreen {
@Override @Override
public void onGuiClosed() { public void onGuiClosed() {
if(!save) { if(!save) {
if(!markerKeyframe) {
ReplayHandler.removeKeyframe(keyframe); ReplayHandler.removeKeyframe(keyframe);
ReplayHandler.addKeyframe(keyframeBackup); ReplayHandler.addKeyframe(keyframeBackup);
ReplayHandler.selectKeyframe(keyframeBackup); ReplayHandler.selectKeyframe(keyframeBackup);
} else {
ReplayHandler.getMarkers().remove(keyframe);
ReplayHandler.getMarkers().add(keyframeBackup);
ReplayHandler.selectMarkerKeyframe(keyframeBackup);
}
} else { } else {
keyframe.setRealTimestamp(TimestampUtils.calculateTimestamp(min.getIntValue(), sec.getIntValue(), ms.getIntValue())); keyframe.setRealTimestamp(TimestampUtils.calculateTimestamp(min.getIntValue(), sec.getIntValue(), ms.getIntValue()));
if(posKeyframe) { if(posKeyframe) {
((Keyframe<AdvancedPosition>)keyframe).setValue(new AdvancedPosition(xCoord.getPreciseValue(), yCoord.getPreciseValue(), ((Keyframe<AdvancedPosition>)keyframe).setValue(new AdvancedPosition(xCoord.getPreciseValue(), yCoord.getPreciseValue(),
zCoord.getPreciseValue(), new Float(pitch.getPreciseValue()), (float) yaw.getPreciseValue(), zCoord.getPreciseValue(), new Float(pitch.getPreciseValue()), (float) yaw.getPreciseValue(),
(float) roll.getPreciseValue(), null)); (float) roll.getPreciseValue(), null));
} else if(markerKeyframe) {
((Keyframe<Marker>)keyframe).getValue().setName(markerNameInput.getText().trim());
} }
} }
ReplayHandler.fireKeyframesModifyEvent(); ReplayHandler.fireKeyframesModifyEvent();

View File

@@ -1,6 +1,7 @@
package eu.crushedpixel.replaymod.gui.elements.timelines; package eu.crushedpixel.replaymod.gui.elements.timelines;
import eu.crushedpixel.replaymod.ReplayMod; import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.gui.GuiEditKeyframe;
import eu.crushedpixel.replaymod.holders.Keyframe; import eu.crushedpixel.replaymod.holders.Keyframe;
import eu.crushedpixel.replaymod.holders.Marker; import eu.crushedpixel.replaymod.holders.Marker;
import eu.crushedpixel.replaymod.replay.ReplayHandler; import eu.crushedpixel.replaymod.replay.ReplayHandler;
@@ -51,7 +52,7 @@ public class GuiMarkerTimeline extends GuiTimeline {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
if(closest != null) { if(closest != null) {
if(currentTime - clickTime < 500) { // if double clicked then open GUI instead if(currentTime - clickTime < 500) { // if double clicked then open GUI instead
//TODO: Make Marker Name editable mc.displayGuiScreen(new GuiEditKeyframe(closest));
this.clickedKeyFrame = null; this.clickedKeyFrame = null;
} else { } else {
this.clickedKeyFrame = closest; this.clickedKeyFrame = closest;
@@ -155,7 +156,7 @@ public class GuiMarkerTimeline extends GuiTimeline {
if(MouseUtils.isMouseWithinBounds(keyframeX - 2, this.positionY + BORDER_TOP + 10 + 1, 5, 5)) { if(MouseUtils.isMouseWithinBounds(keyframeX - 2, this.positionY + BORDER_TOP + 10 + 1, 5, 5)) {
Point mouse = MouseUtils.getMousePos(); Point mouse = MouseUtils.getMousePos();
String markerName = marker.getValue().getName(); String markerName = marker.getValue().getName();
if(markerName == null) markerName = I18n.format("replaymod.gui.ingame.unnamedmarker"); if(markerName == null || markerName.isEmpty()) markerName = I18n.format("replaymod.gui.ingame.unnamedmarker");
ReplayMod.tooltipRenderer.drawTooltip(mouse.getX(), mouse.getY(), markerName, null, Color.WHITE); ReplayMod.tooltipRenderer.drawTooltip(mouse.getX(), mouse.getY(), markerName, null, Color.WHITE);
drawn = true; drawn = true;

View File

@@ -2,11 +2,13 @@ package eu.crushedpixel.replaymod.interpolation;
import eu.crushedpixel.replaymod.holders.Keyframe; import eu.crushedpixel.replaymod.holders.Keyframe;
import eu.crushedpixel.replaymod.holders.KeyframeComparator; import eu.crushedpixel.replaymod.holders.KeyframeComparator;
import lombok.NoArgsConstructor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@NoArgsConstructor
public class KeyframeList<K extends KeyframeValue> extends ArrayList<Keyframe<K>> { public class KeyframeList<K extends KeyframeValue> extends ArrayList<Keyframe<K>> {
private static final KeyframeComparator KEYFRAME_COMPARATOR = new KeyframeComparator(); private static final KeyframeComparator KEYFRAME_COMPARATOR = new KeyframeComparator();
@@ -15,6 +17,12 @@ public class KeyframeList<K extends KeyframeValue> extends ArrayList<Keyframe<K>
private Interpolation<K> interpolation; private Interpolation<K> interpolation;
public KeyframeList(List<Keyframe<K>> initial) {
for(Keyframe<K> kf : initial) {
add(kf);
}
}
@Override @Override
public boolean add(Keyframe<K> t) { public boolean add(Keyframe<K> t) {
//remove keyframes that have same timestamp //remove keyframes that have same timestamp

View File

@@ -59,8 +59,8 @@ public class ReplayHandler {
private static Entity currentEntity = null; private static Entity currentEntity = null;
private static AdvancedPosition lastPosition = null; private static AdvancedPosition lastPosition = null;
private static Keyframe<Marker>[] initialMarkers = new Keyframe[0]; private static KeyframeList<Marker> initialMarkers = new KeyframeList<Marker>();
private static List<Keyframe<Marker>> markerKeyframes = new ArrayList<Keyframe<Marker>>(); private static KeyframeList<Marker> markerKeyframes = new KeyframeList<Marker>();
private static float cameraTilt = 0; private static float cameraTilt = 0;
@@ -95,13 +95,13 @@ public class ReplayHandler {
} }
} }
public static Keyframe<Marker>[] getMarkers() { public static KeyframeList<Marker> getMarkers() {
return markerKeyframes.toArray(new Keyframe[markerKeyframes.size()]); return markerKeyframes;
} }
public static void setMarkers(Keyframe<Marker>[] m, boolean write) { public static void setMarkers(KeyframeList<Marker> m, boolean write) {
markerKeyframes.clear(); markerKeyframes.clear();
Collections.addAll(markerKeyframes, m); markerKeyframes.addAll(m);
if(write) { if(write) {
try { try {
@@ -440,12 +440,9 @@ public class ReplayHandler {
KeyframeSet[] paths = currentReplayFile.paths().get(); KeyframeSet[] paths = currentReplayFile.paths().get();
ReplayHandler.setKeyframeRepository(paths == null ? new KeyframeSet[0] : paths, false); ReplayHandler.setKeyframeRepository(paths == null ? new KeyframeSet[0] : paths, false);
List<Keyframe<Marker>> markerList = currentReplayFile.markers().get(); KeyframeList<Marker> markerList = new KeyframeList<Marker>(currentReplayFile.markers().get());
Keyframe<Marker>[] markers; ReplayHandler.setMarkers(markerList, false);
if(markerList == null) markers = new Keyframe[0]; ReplayHandler.initialMarkers = markerList;
else markers = markerList.toArray(new Keyframe[markerList.size()]);
ReplayHandler.setMarkers(markers, false);
ReplayHandler.initialMarkers = markers;
PlayerVisibility visibility = currentReplayFile.visibility().get(); PlayerVisibility visibility = currentReplayFile.visibility().get();
PlayerHandler.loadPlayerVisibilityConfiguration(visibility); PlayerHandler.loadPlayerVisibilityConfiguration(visibility);
@@ -522,7 +519,7 @@ public class ReplayHandler {
try { try {
//only if Marker keyframes changed, rewrite them //only if Marker keyframes changed, rewrite them
if(!Arrays.equals(getMarkers(), initialMarkers)) { if(!initialMarkers.equals(markerKeyframes)) {
File markerFile = File.createTempFile(ReplayFile.ENTRY_MARKERS, "json"); File markerFile = File.createTempFile(ReplayFile.ENTRY_MARKERS, "json");
ReplayFileIO.write(getMarkers(), markerFile); ReplayFileIO.write(getMarkers(), markerFile);
ReplayMod.replayFileAppender.registerModifiedFile(markerFile, ReplayFile.ENTRY_MARKERS, ReplayHandler.getReplayFile()); ReplayMod.replayFileAppender.registerModifiedFile(markerFile, ReplayFile.ENTRY_MARKERS, ReplayHandler.getReplayFile());

View File

@@ -4,6 +4,7 @@ import com.google.gson.Gson;
import eu.crushedpixel.replaymod.ReplayMod; import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.assets.CustomObjectRepository; import eu.crushedpixel.replaymod.assets.CustomObjectRepository;
import eu.crushedpixel.replaymod.holders.*; import eu.crushedpixel.replaymod.holders.*;
import eu.crushedpixel.replaymod.interpolation.KeyframeList;
import eu.crushedpixel.replaymod.recording.PacketSerializer; import eu.crushedpixel.replaymod.recording.PacketSerializer;
import eu.crushedpixel.replaymod.recording.ReplayMetaData; import eu.crushedpixel.replaymod.recording.ReplayMetaData;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@@ -163,7 +164,7 @@ public class ReplayFileIO {
write((Object) metaData, file); write((Object) metaData, file);
} }
public static void write(Keyframe<Marker>[] markers, File file) throws IOException { public static void write(KeyframeList<Marker> markers, File file) throws IOException {
write((Object) markers, file); write((Object) markers, file);
} }