Markers are now subclasses of Keyframe

Markers can now be moved and jumped to on the Replay Timeline
This commit is contained in:
CrushedPixel
2015-06-09 22:55:20 +02:00
parent d30ef19c89
commit b2ad52d5b6
13 changed files with 133 additions and 99 deletions

View File

@@ -1,7 +1,9 @@
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.replay.ReplayHandler;
@@ -16,15 +18,23 @@ 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 = 40;
private static final int KEYFRAME_MARKER_Y = 39;
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) {
public GuiKeyframeTimeline(int positionX, int positionY, int width, boolean showMarkers,
boolean showMarkerKeyframes, boolean showPlaceKeyframes, boolean showTimeKeyframes) {
super(positionX, positionY, width);
showMarkers = true;
showMarkerIndicators = false;
this.showMarkers = showMarkers;
this.markerKeyframes = showMarkerKeyframes;
this.timeKeyframes = showTimeKeyframes;
this.placeKeyframes = showPlaceKeyframes;
}
@Override
@@ -34,13 +44,15 @@ public class GuiKeyframeTimeline extends GuiTimeline {
return;
}
int tolerance = (int) (2 * Math.round(zoom * timelineLength / width));
int tolerance = (int)(2 * Math.round(zoom * timelineLength / width));
Keyframe closest;
if (mouseY >= positionY + BORDER_TOP + 5) {
if (mouseY >= positionY + BORDER_TOP + 5 && timeKeyframes) {
closest = ReplayHandler.getClosestTimeKeyframeForRealTime((int) time, tolerance);
} else if (mouseY >= positionY + BORDER_TOP) {
} 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);
} else {
closest = null;
}
@@ -85,6 +97,10 @@ public class GuiKeyframeTimeline extends GuiTimeline {
@Override
public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) {
mouseDrag(mc, mouseX, mouseY, button);
if(clickedKeyFrame instanceof MarkerKeyframe && dragging == false) {
ReplayMod.replaySender.jumpToTime(clickedKeyFrame.getRealTimestamp());
ReplayHandler.setLastPosition(((MarkerKeyframe)clickedKeyFrame).getPosition());
}
clickedKeyFrame = null;
dragging = false;
}
@@ -169,7 +185,8 @@ public class GuiKeyframeTimeline extends GuiTimeline {
int keyframeX = getKeyframeX(kf.getRealTimestamp(), leftTime, bodyWidth, segmentLength);
if (kf instanceof PositionKeyframe) {
if(kf instanceof PositionKeyframe) {
if(!placeKeyframes) return;
textureX = KEYFRAME_PLACE_X;
textureY = KEYFRAME_PLACE_Y;
y += 0;
@@ -179,10 +196,16 @@ public class GuiKeyframeTimeline extends GuiTimeline {
textureX = KEYFRAME_SPEC_X;
textureY = KEYFRAME_SPEC_Y;
}
} else if (kf instanceof TimeKeyframe) {
} else if(kf instanceof TimeKeyframe) {
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());
}

View File

@@ -1,8 +1,6 @@
package eu.crushedpixel.replaymod.gui.elements;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.holders.Marker;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
@@ -27,11 +25,6 @@ public class GuiTimeline extends Gui implements GuiElement {
protected static final int BORDER_RIGHT = 4;
protected static final int BODY_WIDTH = TEXTURE_WIDTH - BORDER_LEFT - BORDER_RIGHT;
protected static final int MARKER_TEXTURE_X = 40;
protected static final int MARKER_TEXTURE_Y = 39;
protected static final int MARKER_TEXTURE_WIDTH = 5;
protected static final int MARKER_TEXTURE_HEIGHT = 5;
/**
* Current position of the cursor. Should normally be between 0 and {@link #timelineLength}.
*/
@@ -59,11 +52,6 @@ public class GuiTimeline extends Gui implements GuiElement {
*/
public boolean showMarkers;
/**
* Whether to draw indicators for Replay Markers.
*/
public boolean showMarkerIndicators = true;
protected final int positionX;
protected final int positionY;
protected final int width;
@@ -150,26 +138,6 @@ public class GuiTimeline extends Gui implements GuiElement {
}
}
if(showMarkerIndicators) {
double segmentLength = timelineLength * zoom;
for(Marker marker : ReplayHandler.getMarkers()) {
if(marker.getTimestamp() <= rightTime && marker.getTimestamp() >= leftTime) {
int textureX = MARKER_TEXTURE_X;
int textureY = MARKER_TEXTURE_Y;
int y = positionY;
int markerX = getMarkerX(marker.getTimestamp(), leftTime, bodyWidth, segmentLength);
if(ReplayHandler.isSelected(marker)) {
textureX += MARKER_TEXTURE_WIDTH;
}
rect(markerX - 2, y + HEIGHT - 3 - MARKER_TEXTURE_HEIGHT, textureX, textureY, MARKER_TEXTURE_WIDTH, MARKER_TEXTURE_HEIGHT);
}
}
}
drawTimelineCursor(leftTime, rightTime, bodyWidth);
}

View File

@@ -7,6 +7,7 @@ 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.Position;
import eu.crushedpixel.replaymod.holders.PositionKeyframe;
import eu.crushedpixel.replaymod.holders.TimeKeyframe;
@@ -181,6 +182,28 @@ public class GuiReplayOverlay extends Gui {
}
};
private final GuiElement buttonMarker = new DelegatingElement() {
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()));
}
}, "replaymod.gui.ingame.menu.addtimekeyframe");
private final GuiElement buttonSelected = texturedButton(BUTTON_TIME_X, BOTTOM_ROW, 0, 100, 20, new Runnable() {
@Override
public void run() {
ReplayHandler.removeKeyframe(ReplayHandler.getSelectedKeyframe());
}
}, "replaymod.gui.ingame.menu.removetimekeyframe");
@Override
public GuiElement delegate() {
return ReplayHandler.getSelectedKeyframe() instanceof TimeKeyframe ? buttonSelected : buttonNotSelected;
}
};
private final GuiElement buttonZoomIn = texturedButton(WIDTH - 14 - 9, BOTTOM_ROW, 40, 20, 9, new Runnable() {
@Override
public void run() {
@@ -197,14 +220,16 @@ public class GuiReplayOverlay extends Gui {
}
}, "replaymod.gui.ingame.menu.zoomout");
private final GuiTimeline timeline = new GuiTimeline(TIMELINE_X, TOP_ROW - 1, WIDTH - 14 - TIMELINE_X) {
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) {
performJump(timeline.getTimeAt(mouseX, mouseY));
super.mouseClick(mc, mouseX, mouseY, button);
if(!(ReplayHandler.getSelectedKeyframe() instanceof MarkerKeyframe))
performJump(timeline.getTimeAt(mouseX, mouseY));
}
};
private final GuiKeyframeTimeline timelineReal = new GuiKeyframeTimeline(TIMELINE_REAL_X, BOTTOM_ROW - 1, TIMELINE_REAL_WIDTH);
private final GuiKeyframeTimeline timelineReal = new GuiKeyframeTimeline(TIMELINE_REAL_X, BOTTOM_ROW - 1, TIMELINE_REAL_WIDTH, true, false, true, true);
{
timelineReal.timelineLength = 10 * 60 * 1000;
}