Keyframes are now moveable by dragging them on the real timeline

This commit is contained in:
CrushedPixel
2015-05-22 00:01:50 +02:00
parent 03e176b9ec
commit 9396687802
4 changed files with 50 additions and 13 deletions

View File

@@ -250,7 +250,7 @@ public class GuiReplayOverlay extends Gui {
x = 20;
}
if(ReplayHandler.getSelected() != null && ReplayHandler.getSelected() instanceof PositionKeyframe) {
if(ReplayHandler.getSelectedKeyframe() != null && ReplayHandler.getSelectedKeyframe() instanceof PositionKeyframe) {
y += 20;
}
@@ -258,10 +258,10 @@ public class GuiReplayOverlay extends Gui {
if(hover && Mouse.isButtonDown(0) && isClick() && FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)
&& !ReplayHandler.isInPath()) {
if(ReplayHandler.getSelected() == null || !(ReplayHandler.getSelected() instanceof PositionKeyframe)) {
if(ReplayHandler.getSelectedKeyframe() == null || !(ReplayHandler.getSelectedKeyframe() instanceof PositionKeyframe)) {
addPlaceKeyframe();
} else {
ReplayHandler.removeKeyframe(ReplayHandler.getSelected());
ReplayHandler.removeKeyframe(ReplayHandler.getSelectedKeyframe());
}
}
@@ -275,7 +275,7 @@ public class GuiReplayOverlay extends Gui {
y = 40;
boolean timeSelected = false;
if(ReplayHandler.getSelected() != null && ReplayHandler.getSelected() instanceof TimeKeyframe) {
if(ReplayHandler.getSelectedKeyframe() != null && ReplayHandler.getSelectedKeyframe() instanceof TimeKeyframe) {
timeSelected = true;
x = 40;
y = 0;
@@ -299,10 +299,10 @@ public class GuiReplayOverlay extends Gui {
mc.renderEngine.bindTexture(extended_gui);
if(hover && Mouse.isButtonDown(0) && isClick() && FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
if(ReplayHandler.getSelected() == null || !(ReplayHandler.getSelected() instanceof TimeKeyframe) && !ReplayHandler.isInPath()) {
if(ReplayHandler.getSelectedKeyframe() == null || !(ReplayHandler.getSelectedKeyframe() instanceof TimeKeyframe) && !ReplayHandler.isInPath()) {
addTimeKeyframe();
} else {
ReplayHandler.removeKeyframe(ReplayHandler.getSelected());
ReplayHandler.removeKeyframe(ReplayHandler.getSelectedKeyframe());
}
}
@@ -368,6 +368,10 @@ public class GuiReplayOverlay extends Gui {
private long keyframeSelectionTime = 0;
private boolean liftedSinceSelection = false;
private int selectionTimestamp = 0;
private boolean overcameToleranceSinceSelection = false;
private void drawRealTimeline(int minX, int maxX, int y, int mouseX, int mouseY) {
int zero = minX + tl_begin_width;
int full = maxX - tl_end_width;
@@ -548,9 +552,20 @@ public class GuiReplayOverlay extends Gui {
float rel_pos = (float) rel_x / (float) width;
float abs_width = (zoom_scale * (float) timelineLength);
int real_pos = Math.round(left_real + ((rel_pos) * abs_width));
int real_pos = (int)Math.floor(left_real + ((rel_pos) * abs_width));
ReplayHandler.setRealTimelineCursor(real_pos);
if(liftedSinceSelection) {
ReplayHandler.setRealTimelineCursor(real_pos);
} else if(ReplayHandler.getSelectedKeyframe() != null) {
int tolerance = Math.round(abs_width / (float) width);
if(Math.abs(selectionTimestamp - real_pos) > tolerance || overcameToleranceSinceSelection) {
ReplayHandler.setRealTimelineCursor(real_pos);
ReplayHandler.getSelectedKeyframe().setRealTimestamp(real_pos);
ReplayHandler.sortKeyframes();
overcameToleranceSinceSelection = true;
}
}
//Keyframe click handling here
if(isClick()) {
@@ -567,6 +582,14 @@ public class GuiReplayOverlay extends Gui {
}
if(close != null) {
liftedSinceSelection = false;
overcameToleranceSinceSelection = false;
selectionTimestamp = close.getRealTimestamp();
float perc = (selectionTimestamp - left_real) / abs_width;
int newX = Math.round(minX + tl_begin_width + (perc * width));
MouseUtils.moveMouse(newX, mouseY);
ReplayHandler.setRealTimelineCursor(selectionTimestamp);
long cur = System.currentTimeMillis();
if(cur - keyframeSelectionTime < 500) { //if double click on Keyframe
mc.displayGuiScreen(new GuiEditKeyframe(close));
@@ -575,6 +598,8 @@ public class GuiReplayOverlay extends Gui {
}
}
}
} else if(!Mouse.isButtonDown(0)) {
liftedSinceSelection = true;
}
//Draw Realtime Cursor

View File

@@ -2,7 +2,7 @@ package eu.crushedpixel.replaymod.holders;
public class Keyframe implements Cloneable {
private final int realTimestamp;
private int realTimestamp;
@Override
public Object clone() {
@@ -17,6 +17,8 @@ public class Keyframe implements Cloneable {
return realTimestamp;
}
public void setRealTimestamp(int realTimestamp) { this.realTimestamp = realTimestamp; }
@Override
public boolean equals(Object o2) {
if(o2 == null) return false;

View File

@@ -132,7 +132,6 @@ public class ReplayHandler {
keyframes.add(keyframe);
selectKeyframe(keyframe);
if(keyframe instanceof PositionKeyframe) {
Float a = null;
Float b;
@@ -411,7 +410,7 @@ public class ReplayHandler {
inReplay = false;
}
public static Keyframe getSelected() {
public static Keyframe getSelectedKeyframe() {
return selectedKeyframe;
}
@@ -436,7 +435,7 @@ public class ReplayHandler {
}
public static TimeKeyframe getFirstTimeKeyframe() {
Keyframe sel = getSelected();
Keyframe sel = getSelectedKeyframe();
sortKeyframes();
for(Keyframe k : getKeyframes()) {
if(k instanceof TimeKeyframe) {
@@ -449,7 +448,7 @@ public class ReplayHandler {
}
public static PositionKeyframe getFirstPositionKeyframe() {
Keyframe sel = getSelected();
Keyframe sel = getSelectedKeyframe();
sortKeyframes();
for(Keyframe k : getKeyframes()) {
if(k instanceof PositionKeyframe) {

View File

@@ -21,6 +21,17 @@ public class MouseUtils {
return new Point(mouseX, mouseY);
}
public static void moveMouse(int mouseX, int mouseY) {
Point scaled = getScaledDimensions();
int width = (int) scaled.getX();
int height = (int) scaled.getY();
int x = (int)Math.round(((mouseX+0.5)*mc.displayWidth)/width);
int y = (mouseY*mc.displayHeight)/height;
Mouse.setCursorPosition(x, y);
}
public static Point getScaledDimensions() {
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
final int width = sr.getScaledWidth();