Reworked GuiEditKeyframe to use ComposedElements
Made GuiArrowButton a subclass of GuiAdvancedButton Added consistency to ReplayHandler by renaming getMarkers() to getMarkerKeyframes() and removing redundant methods which can be accessed via KeyframeList class
This commit is contained in:
@@ -1,16 +1,14 @@
|
|||||||
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.*;
|
||||||
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.holders.AdvancedPosition;
|
import eu.crushedpixel.replaymod.holders.AdvancedPosition;
|
||||||
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.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;
|
||||||
|
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||||
import eu.crushedpixel.replaymod.utils.RoundUtils;
|
import eu.crushedpixel.replaymod.utils.RoundUtils;
|
||||||
import eu.crushedpixel.replaymod.utils.TimestampUtils;
|
import eu.crushedpixel.replaymod.utils.TimestampUtils;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
@@ -18,17 +16,17 @@ import net.minecraft.client.gui.GuiScreen;
|
|||||||
import net.minecraft.client.gui.GuiTextField;
|
import net.minecraft.client.gui.GuiTextField;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
|
import org.lwjgl.util.Point;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GuiEditKeyframe extends GuiScreen {
|
public class GuiEditKeyframe extends GuiScreen {
|
||||||
|
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
|
||||||
private GuiButton saveButton, cancelButton;
|
private GuiAdvancedButton saveButton, cancelButton;
|
||||||
private GuiArrowButton leftButton, rightButton;
|
private GuiArrowButton leftButton, rightButton;
|
||||||
|
|
||||||
private GuiNumberInput xCoord, yCoord, zCoord, pitch, yaw, roll;
|
private GuiNumberInput xCoord, yCoord, zCoord, pitch, yaw, roll;
|
||||||
@@ -36,8 +34,8 @@ public class GuiEditKeyframe extends GuiScreen {
|
|||||||
|
|
||||||
private GuiAdvancedTextField markerNameInput;
|
private GuiAdvancedTextField markerNameInput;
|
||||||
|
|
||||||
private List<GuiTextField> inputs = new ArrayList<GuiTextField>();
|
private ComposedElement inputs;
|
||||||
private List<GuiTextField> posInputs = new ArrayList<GuiTextField>();
|
private ComposedElement posInputs;
|
||||||
|
|
||||||
private int virtualHeight = 200;
|
private int virtualHeight = 200;
|
||||||
private int virtualY;
|
private int virtualY;
|
||||||
@@ -66,7 +64,7 @@ public class GuiEditKeyframe extends GuiScreen {
|
|||||||
|
|
||||||
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();
|
KeyframeList<Marker> markerKeyframes = ReplayHandler.getMarkerKeyframes();
|
||||||
|
|
||||||
if(posKeyframe) {
|
if(posKeyframe) {
|
||||||
previous = positionKeyframes.getPreviousKeyframe(keyframe.getRealTimestamp() - 1);
|
previous = positionKeyframes.getPreviousKeyframe(keyframe.getRealTimestamp() - 1);
|
||||||
@@ -93,24 +91,50 @@ public class GuiEditKeyframe extends GuiScreen {
|
|||||||
virtualY = this.height - virtualHeight - 10;
|
virtualY = this.height - virtualHeight - 10;
|
||||||
|
|
||||||
if(!initialized) {
|
if(!initialized) {
|
||||||
saveButton = new GuiButton(GuiConstants.KEYFRAME_EDITOR_SAVE_BUTTON, 0, 0, 100, 20, I18n.format("replaymod.gui.save"));
|
saveButton = new GuiAdvancedButton(GuiConstants.KEYFRAME_EDITOR_SAVE_BUTTON, 0, 0, I18n.format("replaymod.gui.save")) {
|
||||||
cancelButton = new GuiButton(GuiConstants.KEYFRAME_EDITOR_CANCEL_BUTTON, 0, 0, 100, 20, I18n.format("replaymod.gui.cancel"));
|
@Override
|
||||||
|
public void performAction() {
|
||||||
|
save = true;
|
||||||
|
mc.displayGuiScreen(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
leftButton = new GuiArrowButton(GuiConstants.KEYFRAME_EDITOR_LEFT_BUTTON, 0, 0, "", GuiArrowButton.Direction.LEFT);
|
cancelButton = new GuiAdvancedButton(GuiConstants.KEYFRAME_EDITOR_CANCEL_BUTTON, 0, 0, I18n.format("replaymod.gui.cancel")) {
|
||||||
rightButton = new GuiArrowButton(GuiConstants.KEYFRAME_EDITOR_RIGHT_BUTTON, 0, 0, "", GuiArrowButton.Direction.RIGHT);
|
@Override
|
||||||
|
public void performAction() {
|
||||||
|
save = false;
|
||||||
|
mc.displayGuiScreen(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
leftButton = new GuiArrowButton(GuiConstants.KEYFRAME_EDITOR_LEFT_BUTTON, 0, 0, "", GuiArrowButton.Direction.LEFT) {
|
||||||
|
@Override
|
||||||
|
public void performAction() {
|
||||||
|
save = true;
|
||||||
|
mc.displayGuiScreen(new GuiEditKeyframe(previous));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
rightButton = new GuiArrowButton(GuiConstants.KEYFRAME_EDITOR_RIGHT_BUTTON, 0, 0, "", GuiArrowButton.Direction.RIGHT){
|
||||||
|
@Override
|
||||||
|
public void performAction() {
|
||||||
|
save = true;
|
||||||
|
mc.displayGuiScreen(new GuiEditKeyframe(next));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
saveButton.width = cancelButton.width = 100;
|
||||||
|
|
||||||
leftButton.enabled = previous != null;
|
leftButton.enabled = previous != null;
|
||||||
rightButton.enabled = next != null;
|
rightButton.enabled = next != null;
|
||||||
|
|
||||||
//Real Time Input
|
//Real Time Input
|
||||||
int timestamp = keyframe.getRealTimestamp();
|
int timestamp = keyframe.getRealTimestamp();
|
||||||
min = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 30, 0d, 9d, (double)TimestampUtils.getMinutesFromTimestamp(timestamp), false);
|
min = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 30, 0d, 9d, (double)TimestampUtils.getMinutesFromTimestamp(timestamp), false, "", 1);
|
||||||
sec = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 25, 0d, 59d, (double)TimestampUtils.getSecondsFromTimestamp(timestamp), false);
|
sec = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 25, 0d, 59d, (double)TimestampUtils.getSecondsFromTimestamp(timestamp), false, "", 1);
|
||||||
ms = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 35, 0d, 999d, (double)TimestampUtils.getMillisecondsFromTimestamp(timestamp), false);
|
ms = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 35, 0d, 999d, (double)TimestampUtils.getMillisecondsFromTimestamp(timestamp), false, "", 1);
|
||||||
|
|
||||||
inputs.add(min);
|
inputs = new ComposedElement(min, sec, ms, saveButton, cancelButton, leftButton, rightButton);
|
||||||
inputs.add(sec);
|
|
||||||
inputs.add(ms);
|
|
||||||
|
|
||||||
//Position/Virtual Time Input
|
//Position/Virtual Time Input
|
||||||
if(posKeyframe) {
|
if(posKeyframe) {
|
||||||
@@ -122,14 +146,8 @@ public class GuiEditKeyframe extends GuiScreen {
|
|||||||
pitch = new GuiDraggingNumberInput(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 GuiDraggingNumberInput(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 = new ComposedElement(xCoord, yCoord, zCoord, yaw, pitch, roll);
|
||||||
posInputs.add(yCoord);
|
inputs.addPart(posInputs);
|
||||||
posInputs.add(zCoord);
|
|
||||||
posInputs.add(yaw);
|
|
||||||
posInputs.add(pitch);
|
|
||||||
posInputs.add(roll);
|
|
||||||
|
|
||||||
inputs.addAll(posInputs);
|
|
||||||
} else if(markerKeyframe) {
|
} else if(markerKeyframe) {
|
||||||
String name = ((Keyframe<Marker>)keyframe).getValue().getName();
|
String name = ((Keyframe<Marker>)keyframe).getValue().getName();
|
||||||
if(name == null) name = "";
|
if(name == null) name = "";
|
||||||
@@ -137,7 +155,7 @@ public class GuiEditKeyframe extends GuiScreen {
|
|||||||
markerNameInput.hint = I18n.format("replaymod.gui.editkeyframe.markername");
|
markerNameInput.hint = I18n.format("replaymod.gui.editkeyframe.markername");
|
||||||
markerNameInput.setText(name);
|
markerNameInput.setText(name);
|
||||||
|
|
||||||
inputs.add(markerNameInput);
|
inputs.addPart(markerNameInput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,10 +187,13 @@ public class GuiEditKeyframe extends GuiScreen {
|
|||||||
|
|
||||||
int x = w + left + 5;
|
int x = w + left + 5;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(GuiTextField input : posInputs) {
|
for(GuiElement input : posInputs.getParts()) {
|
||||||
input.xPosition = i < 3 ? x : left+totalWidth-100;
|
if(input instanceof GuiTextField) {
|
||||||
input.yPosition = i < 3 ? virtualY + 20 + i*30 : virtualY + 20 + (i-3)*30;
|
GuiTextField textField = (GuiTextField)input;
|
||||||
i++;
|
textField.xPosition = i < 3 ? x : left+totalWidth-100;
|
||||||
|
textField.yPosition = i < 3 ? virtualY + 20 + i*30 : virtualY + 20 + (i-3)*30;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if(markerKeyframe) {
|
} else if(markerKeyframe) {
|
||||||
markerNameInput.xPosition = width/2 - 100;
|
markerNameInput.xPosition = width/2 - 100;
|
||||||
@@ -207,8 +228,8 @@ public class GuiEditKeyframe extends GuiScreen {
|
|||||||
ReplayHandler.addKeyframe(keyframeBackup);
|
ReplayHandler.addKeyframe(keyframeBackup);
|
||||||
ReplayHandler.selectKeyframe(keyframeBackup);
|
ReplayHandler.selectKeyframe(keyframeBackup);
|
||||||
} else {
|
} else {
|
||||||
ReplayHandler.getMarkers().remove(keyframe);
|
ReplayHandler.getMarkerKeyframes().remove(keyframe);
|
||||||
ReplayHandler.getMarkers().add(keyframeBackup);
|
ReplayHandler.getMarkerKeyframes().add(keyframeBackup);
|
||||||
ReplayHandler.selectMarkerKeyframe(keyframeBackup);
|
ReplayHandler.selectMarkerKeyframe(keyframeBackup);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -227,9 +248,8 @@ public class GuiEditKeyframe extends GuiScreen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||||
for(GuiTextField input : inputs) {
|
Point mousePos = MouseUtils.getMousePos();
|
||||||
if(input != null) input.textboxKeyTyped(typedChar, keyCode);
|
inputs.buttonPressed(mc, mousePos.getX(), mousePos.getY(), typedChar, keyCode);
|
||||||
}
|
|
||||||
|
|
||||||
if(keyCode == Keyboard.KEY_ESCAPE) {
|
if(keyCode == Keyboard.KEY_ESCAPE) {
|
||||||
save = false;
|
save = false;
|
||||||
@@ -239,17 +259,25 @@ public class GuiEditKeyframe extends GuiScreen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||||
for(GuiTextField input : inputs) {
|
inputs.mouseClick(mc, mouseX, mouseY, mouseButton);
|
||||||
if(input != null) input.mouseClicked(mouseX, mouseY, mouseButton);
|
|
||||||
}
|
|
||||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||||
|
inputs.mouseDrag(mc, mouseX, mouseY, clickedMouseButton);
|
||||||
|
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void mouseReleased(int mouseX, int mouseY, int state) {
|
||||||
|
inputs.mouseRelease(mc, mouseX, mouseY, state);
|
||||||
|
super.mouseReleased(mouseX, mouseY, state);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateScreen() {
|
public void updateScreen() {
|
||||||
for(GuiTextField input : inputs) {
|
inputs.tick(mc);
|
||||||
if(input != null) input.updateCursorCounter();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -271,28 +299,8 @@ public class GuiEditKeyframe extends GuiScreen {
|
|||||||
drawString(fontRendererObj, I18n.format("replaymod.gui.editkeyframe.camroll"), left+totalWidth-100-5-w2, virtualY + 87, Color.WHITE.getRGB());
|
drawString(fontRendererObj, I18n.format("replaymod.gui.editkeyframe.camroll"), left+totalWidth-100-5-w2, virtualY + 87, Color.WHITE.getRGB());
|
||||||
}
|
}
|
||||||
|
|
||||||
for(GuiTextField input : inputs) {
|
inputs.draw(mc, mouseX, mouseY);
|
||||||
if(input != null) input.drawTextBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void actionPerformed(GuiButton button) throws IOException {
|
|
||||||
if(!button.enabled) return;
|
|
||||||
if(button.id == GuiConstants.KEYFRAME_EDITOR_SAVE_BUTTON) {
|
|
||||||
save = true;
|
|
||||||
mc.displayGuiScreen(null);
|
|
||||||
} else if(button.id == GuiConstants.KEYFRAME_EDITOR_CANCEL_BUTTON) {
|
|
||||||
save = false;
|
|
||||||
mc.displayGuiScreen(null);
|
|
||||||
} else if(button.id == GuiConstants.KEYFRAME_EDITOR_LEFT_BUTTON) {
|
|
||||||
save = false;
|
|
||||||
mc.displayGuiScreen(new GuiEditKeyframe(previous));
|
|
||||||
} else if(button.id == GuiConstants.KEYFRAME_EDITOR_RIGHT_BUTTON) {
|
|
||||||
save = false;
|
|
||||||
mc.displayGuiScreen(new GuiEditKeyframe(next));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package eu.crushedpixel.replaymod.gui.elements;
|
package eu.crushedpixel.replaymod.gui.elements;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class GuiArrowButton extends GuiButton {
|
public class GuiArrowButton extends GuiAdvancedButton {
|
||||||
|
|
||||||
public enum Direction {
|
public enum Direction {
|
||||||
UP, DOWN, RIGHT, LEFT
|
UP, DOWN, RIGHT, LEFT
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class GuiMarkerTimeline extends GuiTimeline {
|
|||||||
|
|
||||||
Keyframe<Marker> closest = null;
|
Keyframe<Marker> closest = null;
|
||||||
if(mouseY >= positionY + BORDER_TOP + 10) {
|
if(mouseY >= positionY + BORDER_TOP + 10) {
|
||||||
closest = ReplayHandler.getClosestMarkerForRealTime((int) time, tolerance);
|
closest = ReplayHandler.getMarkerKeyframes().getClosestKeyframeForTimestamp((int) time, tolerance);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReplayHandler.selectMarkerKeyframe(closest);
|
ReplayHandler.selectMarkerKeyframe(closest);
|
||||||
@@ -75,7 +75,7 @@ public class GuiMarkerTimeline extends GuiTimeline {
|
|||||||
|
|
||||||
Keyframe<Marker> closest = null;
|
Keyframe<Marker> closest = null;
|
||||||
if(mouseY >= positionY + BORDER_TOP + 10) {
|
if(mouseY >= positionY + BORDER_TOP + 10) {
|
||||||
closest = ReplayHandler.getClosestMarkerForRealTime((int) time, tolerance);
|
closest = ReplayHandler.getMarkerKeyframes().getClosestKeyframeForTimestamp((int) time, tolerance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(closest != null) {
|
if(closest != null) {
|
||||||
@@ -125,7 +125,7 @@ public class GuiMarkerTimeline extends GuiTimeline {
|
|||||||
drawTimelineCursor(leftTime, rightTime, bodyWidth);
|
drawTimelineCursor(leftTime, rightTime, bodyWidth);
|
||||||
|
|
||||||
//Draw Keyframe logos
|
//Draw Keyframe logos
|
||||||
for(Keyframe<Marker> kf : ReplayHandler.getMarkers()) {
|
for(Keyframe<Marker> kf : ReplayHandler.getMarkerKeyframes()) {
|
||||||
if (kf != null && !kf.equals(ReplayHandler.getSelectedMarkerKeyframe()))
|
if (kf != null && !kf.equals(ReplayHandler.getSelectedMarkerKeyframe()))
|
||||||
drawKeyframe(kf, bodyWidth, leftTime, rightTime, segmentLength);
|
drawKeyframe(kf, bodyWidth, leftTime, rightTime, segmentLength);
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ public class GuiMarkerTimeline extends GuiTimeline {
|
|||||||
long leftTime = Math.round(timeStart * timelineLength);
|
long leftTime = Math.round(timeStart * timelineLength);
|
||||||
double segmentLength = timelineLength * zoom;
|
double segmentLength = timelineLength * zoom;
|
||||||
|
|
||||||
for(Keyframe<Marker> marker : ReplayHandler.getMarkers()) {
|
for(Keyframe<Marker> marker : ReplayHandler.getMarkerKeyframes()) {
|
||||||
int keyframeX = getKeyframeX(marker.getRealTimestamp(), leftTime, bodyWidth, segmentLength);
|
int keyframeX = getKeyframeX(marker.getRealTimestamp(), leftTime, bodyWidth, segmentLength);
|
||||||
|
|
||||||
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)) {
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public class ReplayHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KeyframeList<Marker> getMarkers() {
|
public static KeyframeList<Marker> getMarkerKeyframes() {
|
||||||
return markerKeyframes;
|
return markerKeyframes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,54 +291,6 @@ public class ReplayHandler {
|
|||||||
fireKeyframesModifyEvent();
|
fireKeyframesModifyEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Keyframe<Marker> getClosestMarkerForRealTime(int realTime, int tolerance) {
|
|
||||||
List<Keyframe<Marker>> found = new ArrayList<Keyframe<Marker>>();
|
|
||||||
for(Keyframe<Marker> kf : markerKeyframes) {
|
|
||||||
if(Math.abs(kf.getRealTimestamp() - realTime) <= tolerance) {
|
|
||||||
found.add(kf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Keyframe<Marker> closest = null;
|
|
||||||
|
|
||||||
for(Keyframe<Marker> kf : found) {
|
|
||||||
if(closest == null || Math.abs(closest.getRealTimestamp() - realTime) > Math.abs(kf.getRealTimestamp() - realTime)) {
|
|
||||||
closest = kf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return closest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Keyframe<Marker> getPreviousMarkerKeyframe(int realTime) {
|
|
||||||
if(markerKeyframes.isEmpty()) return null;
|
|
||||||
Keyframe<Marker> backup = null;
|
|
||||||
List<Keyframe<Marker>> found = new ArrayList<Keyframe<Marker>>();
|
|
||||||
for(Keyframe<Marker> kf : markerKeyframes) {
|
|
||||||
if(kf.getRealTimestamp() < realTime) {
|
|
||||||
found.add((Keyframe<Marker>)kf);
|
|
||||||
} else if(kf.getRealTimestamp() == realTime) {
|
|
||||||
backup = (Keyframe<Marker>)kf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(found.size() > 0)
|
|
||||||
return found.get(found.size() - 1); //last element is nearest
|
|
||||||
else return backup;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Keyframe<Marker> getNextMarkerKeyframe(int realTime) {
|
|
||||||
if(markerKeyframes.isEmpty()) return null;
|
|
||||||
Keyframe<Marker> backup = null;
|
|
||||||
for(Keyframe<Marker> kf : markerKeyframes) {
|
|
||||||
if(kf.getRealTimestamp() > realTime) {
|
|
||||||
return kf; //first found element is next
|
|
||||||
} else if(kf.getRealTimestamp() == realTime) {
|
|
||||||
backup = kf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return backup;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static KeyframeList<AdvancedPosition> getPositionKeyframes() {
|
public static KeyframeList<AdvancedPosition> getPositionKeyframes() {
|
||||||
return positionKeyframes;
|
return positionKeyframes;
|
||||||
}
|
}
|
||||||
@@ -388,8 +340,8 @@ public class ReplayHandler {
|
|||||||
selectedKeyframe = kf;
|
selectedKeyframe = kf;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSelected(Keyframe<Marker> kf) {
|
public static boolean isSelected(Keyframe kf) {
|
||||||
return kf == selectedMarkerKeyframe || kf == selectedMarkerKeyframe;
|
return kf == selectedKeyframe || kf == selectedMarkerKeyframe;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void selectMarkerKeyframe(Keyframe<Marker> kf) { selectedMarkerKeyframe = kf; }
|
public static void selectMarkerKeyframe(Keyframe<Marker> kf) { selectedMarkerKeyframe = kf; }
|
||||||
@@ -521,7 +473,7 @@ public class ReplayHandler {
|
|||||||
//only if Marker keyframes changed, rewrite them
|
//only if Marker keyframes changed, rewrite them
|
||||||
if(!initialMarkers.equals(markerKeyframes)) {
|
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(getMarkerKeyframes(), markerFile);
|
||||||
ReplayMod.replayFileAppender.registerModifiedFile(markerFile, ReplayFile.ENTRY_MARKERS, ReplayHandler.getReplayFile());
|
ReplayMod.replayFileAppender.registerModifiedFile(markerFile, ReplayFile.ENTRY_MARKERS, ReplayHandler.getReplayFile());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user