Localized Keyboard Bindings and added "Synchronize Timeline" and "Clear Keyframes"

This commit is contained in:
CrushedPixel
2015-04-30 17:46:13 +02:00
parent bc9fbfa786
commit ae5eca9c99
7 changed files with 134 additions and 43 deletions

View File

@@ -65,7 +65,6 @@ public class GuiReplayOverlay extends Gui {
private int place_ButtonY = realTimelineY + 1; private int place_ButtonY = realTimelineY + 1;
private int time_ButtonX = 85; private int time_ButtonX = 85;
private int time_ButtonY = realTimelineY + 1; private int time_ButtonY = realTimelineY + 1;
private long lastSystemTime = System.currentTimeMillis();
private ResourceLocation replay_gui = new ResourceLocation("replaymod", "replay_gui.png"); private ResourceLocation replay_gui = new ResourceLocation("replaymod", "replay_gui.png");
private ResourceLocation extended_gui = new ResourceLocation("replaymod", "extended_gui.png"); private ResourceLocation extended_gui = new ResourceLocation("replaymod", "extended_gui.png");
private ResourceLocation timeline_icons = new ResourceLocation("replaymod", "timeline_icons.png"); private ResourceLocation timeline_icons = new ResourceLocation("replaymod", "timeline_icons.png");
@@ -79,7 +78,6 @@ public class GuiReplayOverlay extends Gui {
private int tl_y = 40; private int tl_y = 40;
private float zoom_scale = 0.1f; //can see 1/10th of the timeline private float zoom_scale = 0.1f; //can see 1/10th of the timeline
private float pos_left = 0f; //left border of timeline is at 0% private float pos_left = 0f; //left border of timeline is at 0%
private float cursor_pos = 0f; //cursor is at 0%
private long timelineLength = 10 * 60 * 1000; //10 min of timeline private long timelineLength = 10 * 60 * 1000; //10 min of timeline
private float zoom_steps = 0.05f; private float zoom_steps = 0.05f;
private boolean wasSliding = false; private boolean wasSliding = false;
@@ -218,7 +216,6 @@ public class GuiReplayOverlay extends Gui {
} }
} }
//TODO: Save Video Button
hover = false; hover = false;
x = 0; x = 0;
y = 18; y = 18;

View File

@@ -91,16 +91,6 @@ public class TickAndRenderListener {
public void tick(TickEvent event) { public void tick(TickEvent event) {
if(!ReplayHandler.isInReplay()) return; if(!ReplayHandler.isInReplay()) return;
/*
if(Keyboard.getEventKeyState() && Keyboard.isKeyDown(Keyboard.KEY_F1)
&& ReplayHandler.isInPath() && !ReplayProcess.isVideoRecording()
&& mc.currentScreen instanceof GuiMouseInput && !f1Down) {
mc.gameSettings.hideGUI = !mc.gameSettings.hideGUI;
}
f1Down = Keyboard.isKeyDown(Keyboard.KEY_F1) && Keyboard.getEventKeyState();
*/
if(ReplayHandler.getCameraEntity() != null) if(ReplayHandler.getCameraEntity() != null)
ReplayHandler.getCameraEntity().updateMovement(); ReplayHandler.getCameraEntity().updateMovement();
if(ReplayHandler.isInPath()) { if(ReplayHandler.isInPath()) {
@@ -110,14 +100,14 @@ public class TickAndRenderListener {
mc.displayGuiScreen(new GuiMouseInput()); mc.displayGuiScreen(new GuiMouseInput());
} }
} else onMouseMove(new MouseEvent()); } else onMouseMove(new MouseEvent());
FMLCommonHandler.instance().bus().post(new InputEvent.KeyInputEvent()); FMLCommonHandler.instance().bus().post(new InputEvent.KeyInputEvent());
} }
@SubscribeEvent @SubscribeEvent
public void onMouseMove(MouseEvent event) { public void onMouseMove(MouseEvent event) {
if(!ReplayHandler.isInReplay()) return; if(!ReplayHandler.isInReplay()) return;
boolean flag = Display.isActive(); boolean flag = true;
flag = true;
mc.mcProfiler.startSection("mouse"); mc.mcProfiler.startSection("mouse");

View File

@@ -10,17 +10,21 @@ import java.util.List;
public class KeybindRegistry { public class KeybindRegistry {
public static final String KEY_LIGHTING = "Toggle Lighting"; public static final String KEY_LIGHTING = "replaymod.input.lighting";
public static final String KEY_THUMBNAIL = "Create Thumbnail"; public static final String KEY_THUMBNAIL = "replaymod.input.thumbnail";
public static final String KEY_SPECTATE = "Spectate Entity"; public static final String KEY_SPECTATE = "replaymod.input.spectate";
public static final String KEY_CLEAR_KEYFRAMES = "replaymod.input.clearkeyframes";
public static final String KEY_SYNC_TIMELINE = "replaymod.input.synctimeline";
private static Minecraft mc = Minecraft.getMinecraft(); private static Minecraft mc = Minecraft.getMinecraft();
public static void initialize() { public static void initialize() {
List<KeyBinding> bindings = new ArrayList<KeyBinding>(Arrays.asList(mc.gameSettings.keyBindings)); List<KeyBinding> bindings = new ArrayList<KeyBinding>(Arrays.asList(mc.gameSettings.keyBindings));
bindings.add(new KeyBinding(KEY_LIGHTING, Keyboard.KEY_V, "Replay Mod")); bindings.add(new KeyBinding(KEY_LIGHTING, Keyboard.KEY_M, "replaymod.title"));
bindings.add(new KeyBinding(KEY_THUMBNAIL, Keyboard.KEY_B, "Replay Mod")); bindings.add(new KeyBinding(KEY_THUMBNAIL, Keyboard.KEY_N, "replaymod.title"));
bindings.add(new KeyBinding(KEY_SPECTATE, Keyboard.KEY_C, "Replay Mod")); bindings.add(new KeyBinding(KEY_SPECTATE, Keyboard.KEY_B, "replaymod.title"));
bindings.add(new KeyBinding(KEY_SYNC_TIMELINE, Keyboard.KEY_V, "replaymod.title"));
bindings.add(new KeyBinding(KEY_CLEAR_KEYFRAMES, Keyboard.KEY_C, "replaymod.title"));
mc.gameSettings.keyBindings = bindings.toArray(new KeyBinding[bindings.size()]); mc.gameSettings.keyBindings = bindings.toArray(new KeyBinding[bindings.size()]);
} }

View File

@@ -343,4 +343,84 @@ public class ReplayHandler {
} }
return null; return null;
} }
public static TimeKeyframe getFirstTimeKeyframe() {
Keyframe sel = getSelected();
sortKeyframes();
for(Keyframe k : getKeyframes()) {
if(k instanceof TimeKeyframe) {
selectKeyframe(sel);
return (TimeKeyframe)k;
}
}
selectKeyframe(sel);
return null;
}
public static PositionKeyframe getFirstPositionKeyframe() {
Keyframe sel = getSelected();
sortKeyframes();
for(Keyframe k : getKeyframes()) {
if(k instanceof PositionKeyframe) {
selectKeyframe(sel);
return (PositionKeyframe)k;
}
}
selectKeyframe(sel);
return null;
}
public static TimeKeyframe getLastTimeKeyframe() {
ArrayList<Keyframe> rev = new ArrayList<Keyframe>(getKeyframes());
Collections.reverse(rev);
for(Keyframe k : rev) {
if(k instanceof TimeKeyframe) {
return (TimeKeyframe)k;
}
}
return null;
}
public static PositionKeyframe getLastPositionKeyframe() {
ArrayList<Keyframe> rev = new ArrayList<Keyframe>(getKeyframes());
Collections.reverse(rev);
for(Keyframe k : rev) {
if(k instanceof PositionKeyframe) {
return (PositionKeyframe)k;
}
}
return null;
}
public static void syncTimeCursor(boolean shiftMode) {
selectKeyframe(null);
int curTime = ReplayMod.replaySender.currentTimeStamp();
int prevTime, prevRealTime;
TimeKeyframe keyframe;
//if shift is down, it will refer to the previous Time Keyframe instead of the last one
if(shiftMode) {
int realTime = getRealTimelineCursor();
keyframe = getPreviousTimeKeyframe(realTime);
} else {
keyframe = getLastTimeKeyframe();
}
if(keyframe == null) {
prevTime = 0;
prevRealTime = 0;
} else {
prevTime = keyframe.getTimestamp();
prevRealTime = keyframe.getRealTimestamp();
}
int newCursorPos = prevRealTime+(curTime-prevTime);
setRealTimelineCursor(newCursorPos);
}
} }

View File

@@ -55,12 +55,9 @@ public class ReplayProcess {
return isVideoRecording; return isVideoRecording;
} }
public static void startReplayProcess(boolean record) { private static void resetProcess() {
ReplayHandler.selectKeyframe(null);
firstTime = true; firstTime = true;
isVideoRecording = record;
lastPosition = null; lastPosition = null;
motionSpline = null; motionSpline = null;
motionLinear = null; motionLinear = null;
@@ -70,12 +67,6 @@ public class ReplayProcess {
ReplayMod.replaySender.resetToleratedTimeStamp(); ReplayMod.replaySender.resetToleratedTimeStamp();
ReplayMod.chatMessageHandler.initialize();
if(ReplayHandler.getPosKeyframeCount() < 2 && ReplayHandler.getTimeKeyframeCount() < 2) {
ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.notenoughkeyframes", ChatMessageType.WARNING);
return;
}
blocked = deepBlock = false; blocked = deepBlock = false;
startRealTime = System.currentTimeMillis(); startRealTime = System.currentTimeMillis();
@@ -84,13 +75,31 @@ public class ReplayProcess {
lastTimestamp = -1; lastTimestamp = -1;
lastSpeed = 1f; lastSpeed = 1f;
linear = ReplayMod.replaySettings.isLinearMovement(); linear = ReplayMod.replaySettings.isLinearMovement();
ReplayHandler.sortKeyframes();
ReplayHandler.setInPath(true);
previousReplaySpeed = ReplayMod.replaySender.getReplaySpeed(); previousReplaySpeed = ReplayMod.replaySender.getReplaySpeed();
EnchantmentTimer.resetRecordingTime(); EnchantmentTimer.resetRecordingTime();
}
TimeKeyframe tf = ReplayHandler.getNextTimeKeyframe(-1); public static void startReplayProcess(boolean record) {
ReplayHandler.selectKeyframe(null);
resetProcess();
isVideoRecording = record;
ReplayMod.chatMessageHandler.initialize();
//if not enough keyframes, abort and leave chat message
if(ReplayHandler.getPosKeyframeCount() < 2 && ReplayHandler.getTimeKeyframeCount() < 2) {
ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.notenoughkeyframes", ChatMessageType.WARNING);
return;
}
ReplayHandler.sortKeyframes();
ReplayHandler.setInPath(true);
//gets first Timestamp and sets Replay Time to it
TimeKeyframe tf = ReplayHandler.getFirstTimeKeyframe();
if(tf != null) { if(tf != null) {
int ts = tf.getTimestamp(); int ts = tf.getTimestamp();
if(ts < ReplayMod.replaySender.currentTimeStamp()) { if(ts < ReplayMod.replaySender.currentTimeStamp()) {
@@ -101,6 +110,7 @@ public class ReplayProcess {
ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.pathstarted", ChatMessageType.INFORMATION); ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.pathstarted", ChatMessageType.INFORMATION);
//if video is recording, the Replay Process takes control over the Minecraft Timer
if(isVideoRecording()) { if(isVideoRecording()) {
MCTimerHandler.setTimerSpeed(1f); MCTimerHandler.setTimerSpeed(1f);
MCTimerHandler.setPassiveTimer(); MCTimerHandler.setPassiveTimer();
@@ -109,6 +119,8 @@ public class ReplayProcess {
public static void stopReplayProcess(boolean finished) { public static void stopReplayProcess(boolean finished) {
if(!ReplayHandler.isInPath()) return; if(!ReplayHandler.isInPath()) return;
//if canceled, display a different chat message
if(finished) ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.pathfinished", ChatMessageType.INFORMATION); if(finished) ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.pathfinished", ChatMessageType.INFORMATION);
else { else {
ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.pathinterrupted", ChatMessageType.INFORMATION); ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.pathinterrupted", ChatMessageType.INFORMATION);
@@ -116,8 +128,11 @@ public class ReplayProcess {
VideoWriter.abortRecording(); VideoWriter.abortRecording();
} }
} }
ReplayHandler.setInPath(false); ReplayHandler.setInPath(false);
ReplayMod.replaySender.stopHurrying(); ReplayMod.replaySender.stopHurrying();
MCTimerHandler.setActiveTimer(); MCTimerHandler.setActiveTimer();
ReplayMod.replaySender.setReplaySpeed(previousReplaySpeed); ReplayMod.replaySender.setReplaySpeed(previousReplaySpeed);
ReplayMod.replaySender.setReplaySpeed(0); ReplayMod.replaySender.setReplaySpeed(0);
@@ -126,13 +141,13 @@ public class ReplayProcess {
public static void unblockAndTick(boolean justCheck) { public static void unblockAndTick(boolean justCheck) {
if(!deepBlock) blocked = false; if(!deepBlock) blocked = false;
if(!blocked || !isVideoRecording()) if(!blocked || !isVideoRecording())
ReplayProcess.tickReplay(justCheck); pathTick(isVideoRecording(), justCheck);
}
public static void tickReplay(boolean justCheck) {
pathTick(isVideoRecording(), justCheck);
} }
//if justCheck is true, no Screenshot will be taken, it will only be checked
//whether all chunks have been rendered. This is necessary because no Render ticks
//are called if the Timer speed is set to 0, leading to this method never being
//called from the RenderWorldLastEvent handlers.
private static void pathTick(boolean recording, boolean justCheck) { private static void pathTick(boolean recording, boolean justCheck) {
if(ReplayMod.replaySender.isHurrying()) { if(ReplayMod.replaySender.isHurrying()) {
lastRealTime = System.currentTimeMillis(); lastRealTime = System.currentTimeMillis();
@@ -312,7 +327,7 @@ public class ReplayProcess {
} }
} else { } else {
if(posCount == 1) { if(posCount == 1) {
pos = ReplayHandler.getNextPositionKeyframe(-1).getPosition(); pos = ReplayHandler.getFirstPositionKeyframe().getPosition();
} }
} }

View File

@@ -141,7 +141,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
* If hurrying, don't wait for correct timing. * If hurrying, don't wait for correct timing.
*/ */
if(!hurryToTimestamp && ReplayHandler.isInPath()) { if(!hurryToTimestamp && ReplayHandler.isInPath()) {
continue; continue;
} }
@@ -149,7 +148,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
PacketData pd = ReplayFileIO.readPacketData(dis); PacketData pd = ReplayFileIO.readPacketData(dis);
currentTimeStamp = pd.getTimestamp(); currentTimeStamp = pd.getTimestamp();
//System.out.println(currentTimeStamp);
if(!ReplayHandler.isInPath() && !hurryToTimestamp && hasWorldLoaded) { if(!ReplayHandler.isInPath() && !hurryToTimestamp && hasWorldLoaded) {
int timeWait = (int) Math.round((currentTimeStamp - lastTimeStamp) / replaySpeed); int timeWait = (int) Math.round((currentTimeStamp - lastTimeStamp) / replaySpeed);

View File

@@ -137,4 +137,11 @@ replaymod.gui.settings.videoquality.good=Good
replaymod.gui.settings.videoquality.best=Best replaymod.gui.settings.videoquality.best=Best
replaymod.gui.settings.warning.linea=WARNING: Recording settings will be replaymod.gui.settings.warning.linea=WARNING: Recording settings will be
replaymod.gui.settings.warning.lineb=applied the next time you join a world. replaymod.gui.settings.warning.lineb=applied the next time you join a world.
#Replay Mod Keybindings
replaymod.input.lighting=Toggle Lighting
replaymod.input.thumbnail=Capture Thumbnail
replaymod.input.spectate=Spectate Players
replaymod.input.clearkeyframes=Clear Keyframes
replaymod.input.synctimeline=Synchronize Timeline