Add keybindings for the two keyframe buttons (closes #312)

And one to add a position keyframe even when spectating.
And one to press both buttons with a single key.
This commit is contained in:
Jonas Herzig
2020-08-28 15:45:34 +02:00
parent c2f51d41fa
commit fd48e56238
3 changed files with 23 additions and 7 deletions

View File

@@ -91,6 +91,21 @@ public class ReplayModSimplePathing extends EventRegistrations implements Module
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_DELETE, () -> { core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_DELETE, () -> {
if (guiPathing != null) guiPathing.deleteButtonPressed(); if (guiPathing != null) guiPathing.deleteButtonPressed();
}); });
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.positionkeyframe", Keyboard.KEY_I, () -> {
if (guiPathing != null) guiPathing.toggleKeyframe(SPPath.POSITION, false);
}, true);
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.positiononlykeyframe", 0, () -> {
if (guiPathing != null) guiPathing.toggleKeyframe(SPPath.POSITION, true);
}, true);
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.timekeyframe", Keyboard.KEY_O, () -> {
if (guiPathing != null) guiPathing.toggleKeyframe(SPPath.TIME, false);
}, true);
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.bothkeyframes", 0, () -> {
if (guiPathing != null) {
guiPathing.toggleKeyframe(SPPath.TIME, false);
guiPathing.toggleKeyframe(SPPath.POSITION, false);
}
}, true);
} }
{ on(ReplayOpenedCallback.EVENT, this::onReplayOpened); } { on(ReplayOpenedCallback.EVENT, this::onReplayOpened); }

View File

@@ -368,7 +368,7 @@ public class GuiPathing {
}).onClick(new Runnable() { }).onClick(new Runnable() {
@Override @Override
public void run() { public void run() {
updateKeyframe(SPPath.POSITION); toggleKeyframe(SPPath.POSITION, false);
} }
}); });
@@ -395,7 +395,7 @@ public class GuiPathing {
}).onClick(new Runnable() { }).onClick(new Runnable() {
@Override @Override
public void run() { public void run() {
updateKeyframe(SPPath.TIME); toggleKeyframe(SPPath.TIME, false);
} }
}); });
@@ -487,7 +487,7 @@ public class GuiPathing {
public void deleteButtonPressed() { public void deleteButtonPressed() {
if (mod.getSelectedPath() != null) { if (mod.getSelectedPath() != null) {
updateKeyframe(mod.getSelectedPath()); toggleKeyframe(mod.getSelectedPath(), false);
} }
} }
@@ -603,10 +603,11 @@ public class GuiPathing {
/** /**
* Called when either one of the property buttons is pressed. * Called when either one of the property buttons is pressed.
* @param path {@code TIME} for the time property button, {@code POSITION} for the place property button * @param path {@code TIME} for the time property button, {@code POSITION} for the place property button
* @param neverSpectator when true, will insert a position keyframe even when currently spectating an entity
*/ */
private void updateKeyframe(SPPath path) { public void toggleKeyframe(SPPath path, boolean neverSpectator) {
LOGGER.debug("Updating keyframe on path {}" + path); LOGGER.debug("Updating keyframe on path {}" + path);
if (!loadEntityTracker(() -> updateKeyframe(path))) return; if (!loadEntityTracker(() -> toggleKeyframe(path, neverSpectator))) return;
int time = timeline.getCursorPosition(); int time = timeline.getCursorPosition();
SPTimeline timeline = mod.getCurrentTimeline(); SPTimeline timeline = mod.getCurrentTimeline();
@@ -640,7 +641,7 @@ public class GuiPathing {
LOGGER.debug("No position keyframe found -> adding new keyframe"); LOGGER.debug("No position keyframe found -> adding new keyframe");
CameraEntity camera = replayHandler.getCameraEntity(); CameraEntity camera = replayHandler.getCameraEntity();
int spectatedId = -1; int spectatedId = -1;
if (!replayHandler.isCameraView()) { if (!replayHandler.isCameraView() && !neverSpectator) {
spectatedId = getRenderViewEntity(replayHandler.getOverlay().getMinecraft()).getEntityId(); spectatedId = getRenderViewEntity(replayHandler.getOverlay().getMinecraft()).getEntityId();
} }
timeline.addPositionKeyframe(time, Entity_getX(camera), Entity_getY(camera), Entity_getZ(camera), timeline.addPositionKeyframe(time, Entity_getX(camera), Entity_getY(camera), Entity_getZ(camera),