From 23b77b23752cd2229bf7e075f56751f5cb5d7968 Mon Sep 17 00:00:00 2001 From: CrushedPixel Date: Sun, 19 Jul 2015 11:23:38 +0200 Subject: [PATCH] Right-Clicking a Position Keyframe teleports the Camera to that Keyframe's Position, Right-Clicking a Time Keyframe jumps to its Timestamp | https://trello.com/c/dL48nHyG/ DRYed closest Keyframe calculation on GuiKeyframeTimeline DRYed closest Keyframe calculation on GuiMarkerTimeline --- .../timelines/GuiKeyframeTimeline.java | 42 ++++++++++++------- .../elements/timelines/GuiMarkerTimeline.java | 37 ++++++---------- 2 files changed, 38 insertions(+), 41 deletions(-) diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/elements/timelines/GuiKeyframeTimeline.java b/src/main/java/eu/crushedpixel/replaymod/gui/elements/timelines/GuiKeyframeTimeline.java index 41b93bcb..2215cae7 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/elements/timelines/GuiKeyframeTimeline.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/elements/timelines/GuiKeyframeTimeline.java @@ -1,5 +1,6 @@ package eu.crushedpixel.replaymod.gui.elements.timelines; +import eu.crushedpixel.replaymod.ReplayMod; import eu.crushedpixel.replaymod.gui.GuiEditKeyframe; import eu.crushedpixel.replaymod.holders.AdvancedPosition; import eu.crushedpixel.replaymod.holders.Keyframe; @@ -35,24 +36,25 @@ public class GuiKeyframeTimeline extends GuiTimeline { @Override public boolean mouseClick(Minecraft mc, int mouseX, int mouseY, int button) { if(!enabled) return false; + + long time = getTimeAt(mouseX, mouseY); + if(time == -1) { + return false; + } + + int tolerance = (int) (2 * Math.round(zoom * timelineLength / width)); + + Keyframe closest; + if(mouseY >= positionY + BORDER_TOP + 5 && timeKeyframes) { + closest = ReplayHandler.getTimeKeyframes().getClosestKeyframeForTimestamp((int) time, tolerance); + } else if(mouseY >= positionY + BORDER_TOP && placeKeyframes) { + closest = ReplayHandler.getPositionKeyframes().getClosestKeyframeForTimestamp((int) time, tolerance); + } else { + closest = null; + } + //left mouse button if(button == 0) { - long time = getTimeAt(mouseX, mouseY); - if(time == -1) { - return false; - } - - int tolerance = (int) (2 * Math.round(zoom * timelineLength / width)); - - Keyframe closest; - if(mouseY >= positionY + BORDER_TOP + 5 && timeKeyframes) { - closest = ReplayHandler.getTimeKeyframes().getClosestKeyframeForTimestamp((int) time, tolerance); - } else if(mouseY >= positionY + BORDER_TOP && placeKeyframes) { - closest = ReplayHandler.getPositionKeyframes().getClosestKeyframeForTimestamp((int) time, tolerance); - } else { - closest = null; - } - ReplayHandler.selectKeyframe(closest); //can be null, deselects keyframe // If we clicked on a key frame, then continue monitoring the mouse for movements @@ -71,6 +73,14 @@ public class GuiKeyframeTimeline extends GuiTimeline { } this.clickTime = currentTime; + } else if(button == 1) { + if(closest != null) { + if(closest.getValue() instanceof AdvancedPosition) { + ReplayHandler.getCameraEntity().moveAbsolute((AdvancedPosition)closest.getValue()); + } else if(closest.getValue() instanceof TimestampValue) { + ReplayMod.replaySender.jumpToTime(((TimestampValue)closest.getValue()).asInt()); + } + } } return isHovering(mouseX, mouseY); diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/elements/timelines/GuiMarkerTimeline.java b/src/main/java/eu/crushedpixel/replaymod/gui/elements/timelines/GuiMarkerTimeline.java index 82ee531f..ca49d7c1 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/elements/timelines/GuiMarkerTimeline.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/elements/timelines/GuiMarkerTimeline.java @@ -29,20 +29,20 @@ public class GuiMarkerTimeline extends GuiTimeline { public boolean mouseClick(Minecraft mc, int mouseX, int mouseY, int button) { if(!enabled) return false; + long time = getTimeAt(mouseX, mouseY); + if(time == -1) { + return false; + } + + int tolerance = (int) (2 * Math.round(zoom * timelineLength / width)); + + Keyframe closest = null; + if(mouseY >= positionY + BORDER_TOP + 10) { + closest = ReplayHandler.getMarkerKeyframes().getClosestKeyframeForTimestamp((int) time, tolerance); + } + //left mouse button if(button == 0) { - long time = getTimeAt(mouseX, mouseY); - if(time == -1) { - return false; - } - - int tolerance = (int) (2 * Math.round(zoom * timelineLength / width)); - - Keyframe closest = null; - if(mouseY >= positionY + BORDER_TOP + 10) { - closest = ReplayHandler.getMarkerKeyframes().getClosestKeyframeForTimestamp((int) time, tolerance); - } - ReplayHandler.selectKeyframe(closest); if(closest == null) { //if no keyframe clicked, jump in time @@ -65,19 +65,6 @@ public class GuiMarkerTimeline extends GuiTimeline { } } else if(button == 1) { - - long time = getTimeAt(mouseX, mouseY); - if(time == -1) { - return false; - } - - int tolerance = (int) (2 * Math.round(zoom * timelineLength / width)); - - Keyframe closest = null; - if(mouseY >= positionY + BORDER_TOP + 10) { - closest = ReplayHandler.getMarkerKeyframes().getClosestKeyframeForTimestamp((int) time, tolerance); - } - if(closest != null) { //Jump to clicked Marker Keyframe ReplayHandler.setLastPosition(closest.getValue().getPosition());