Register keys for simplepathing only once (fixes #63)
This commit is contained in:
@@ -14,6 +14,7 @@ import net.minecraftforge.fml.common.Mod;
|
|||||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
@Mod(modid = ReplayModSimplePathing.MOD_ID,
|
@Mod(modid = ReplayModSimplePathing.MOD_ID,
|
||||||
version = "@MOD_VERSION@",
|
version = "@MOD_VERSION@",
|
||||||
@@ -42,6 +43,19 @@ public class ReplayModSimplePathing {
|
|||||||
|
|
||||||
PathPreview pathPreview = new PathPreview(this);
|
PathPreview pathPreview = new PathPreview(this);
|
||||||
pathPreview.register();
|
pathPreview.register();
|
||||||
|
|
||||||
|
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.keyframerepository", Keyboard.KEY_X, () -> {
|
||||||
|
if (guiPathing != null) guiPathing.keyframeRepoButtonPressed();
|
||||||
|
});
|
||||||
|
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.clearkeyframes", Keyboard.KEY_C, () -> {
|
||||||
|
if (guiPathing != null) guiPathing.clearKeyframesButtonPressed();
|
||||||
|
});
|
||||||
|
core.getKeyBindingRegistry().registerRepeatedKeyBinding("replaymod.input.synctimeline", Keyboard.KEY_V, () -> {
|
||||||
|
if (guiPathing != null) guiPathing.syncTimeButtonPressed();
|
||||||
|
});
|
||||||
|
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_DELETE, () -> {
|
||||||
|
if (guiPathing != null) guiPathing.deleteButtonPressed();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.replaymod.simplepathing.gui;
|
package com.replaymod.simplepathing.gui;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.util.concurrent.FutureCallback;
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@@ -256,6 +257,7 @@ public class GuiPathing {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final ReplayMod core;
|
||||||
private final ReplayModSimplePathing mod;
|
private final ReplayModSimplePathing mod;
|
||||||
private final ReplayHandler replayHandler;
|
private final ReplayHandler replayHandler;
|
||||||
private final RealtimeTimelinePlayer player;
|
private final RealtimeTimelinePlayer player;
|
||||||
@@ -265,6 +267,7 @@ public class GuiPathing {
|
|||||||
private SettableFuture<Void> entityTrackerFuture;
|
private SettableFuture<Void> entityTrackerFuture;
|
||||||
|
|
||||||
public GuiPathing(final ReplayMod core, final ReplayModSimplePathing mod, final ReplayHandler replayHandler) {
|
public GuiPathing(final ReplayMod core, final ReplayModSimplePathing mod, final ReplayHandler replayHandler) {
|
||||||
|
this.core = core;
|
||||||
this.mod = mod;
|
this.mod = mod;
|
||||||
this.replayHandler = replayHandler;
|
this.replayHandler = replayHandler;
|
||||||
this.player = new RealtimeTimelinePlayer(replayHandler);
|
this.player = new RealtimeTimelinePlayer(replayHandler);
|
||||||
@@ -400,94 +403,90 @@ public class GuiPathing {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.keyframerepository", Keyboard.KEY_X, new Runnable() {
|
startLoadingEntityTracker();
|
||||||
@Override
|
}
|
||||||
public void run() {
|
|
||||||
if (!overlay.isVisible()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
GuiKeyframeRepository gui = new GuiKeyframeRepository(
|
|
||||||
mod.getCurrentTimeline(), replayHandler.getReplayFile(), mod.getCurrentTimeline().getTimeline());
|
|
||||||
Futures.addCallback(gui.getFuture(), new FutureCallback<Timeline>() {
|
|
||||||
@Override
|
|
||||||
public void onSuccess(Timeline result) {
|
|
||||||
if (result != null) {
|
|
||||||
mod.setCurrentTimeline(new SPTimeline(result));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public void keyframeRepoButtonPressed() {
|
||||||
public void onFailure(Throwable t) {
|
try {
|
||||||
t.printStackTrace();
|
GuiKeyframeRepository gui = new GuiKeyframeRepository(
|
||||||
core.printWarningToChat("Error loading timeline: " + t.getMessage());
|
mod.getCurrentTimeline(), replayHandler.getReplayFile(), mod.getCurrentTimeline().getTimeline());
|
||||||
}
|
Futures.addCallback(gui.getFuture(), new FutureCallback<Timeline>() {
|
||||||
});
|
|
||||||
gui.display();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
core.printWarningToChat("Error loading timeline: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.clearkeyframes", Keyboard.KEY_C, () -> {
|
|
||||||
GuiYesNoPopup popup = GuiYesNoPopup.open(overlay,
|
|
||||||
new GuiLabel().setI18nText("replaymod.gui.clearcallback.title").setColor(Colors.BLACK)
|
|
||||||
).setYesI18nLabel("gui.yes").setNoI18nLabel("gui.no");
|
|
||||||
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Boolean delete) {
|
public void onSuccess(Timeline result) {
|
||||||
if (delete) {
|
if (result != null) {
|
||||||
mod.clearCurrentTimeline();
|
mod.setCurrentTimeline(new SPTimeline(result));
|
||||||
if (entityTracker != null) {
|
|
||||||
mod.getCurrentTimeline().setEntityTracker(entityTracker);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable t) {
|
public void onFailure(Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
|
core.printWarningToChat("Error loading timeline: " + t.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
gui.display();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
core.printWarningToChat("Error loading timeline: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
core.getKeyBindingRegistry().registerRepeatedKeyBinding("replaymod.input.synctimeline", Keyboard.KEY_V, () -> {
|
public void clearKeyframesButtonPressed() {
|
||||||
// Current replay time
|
GuiYesNoPopup popup = GuiYesNoPopup.open(replayHandler.getOverlay(),
|
||||||
int time = replayHandler.getReplaySender().currentTimeStamp();
|
new GuiLabel().setI18nText("replaymod.gui.clearcallback.title").setColor(Colors.BLACK)
|
||||||
// Position of the cursor
|
).setYesI18nLabel("gui.yes").setNoI18nLabel("gui.no");
|
||||||
int cursor = timeline.getCursorPosition();
|
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() {
|
||||||
// Get the last time keyframe before the cursor
|
@Override
|
||||||
mod.getCurrentTimeline().getTimePath().getKeyframes().stream()
|
public void onSuccess(Boolean delete) {
|
||||||
.filter(it -> it.getTime() <= cursor).reduce((__, last) -> last).ifPresent(keyframe -> {
|
if (delete) {
|
||||||
// Cursor position at the keyframe
|
mod.clearCurrentTimeline();
|
||||||
int keyframeCursor = (int) keyframe.getTime();
|
if (entityTracker != null) {
|
||||||
// Replay time at the keyframe
|
mod.getCurrentTimeline().setEntityTracker(entityTracker);
|
||||||
// This is a keyframe from the time path, so it _should_ always have a time property
|
}
|
||||||
int keyframeTime = keyframe.getValue(TimestampProperty.PROPERTY).get();
|
}
|
||||||
// Replay time passed
|
|
||||||
int timePassed = time - keyframeTime;
|
|
||||||
// Speed (set to 1 when shift is held)
|
|
||||||
double speed = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ? 1 : overlay.getSpeedSliderValue();
|
|
||||||
// Cursor time passed
|
|
||||||
int cursorPassed = (int) (timePassed / speed);
|
|
||||||
// Move cursor to new position
|
|
||||||
timeline.setCursorPosition(keyframeCursor + cursorPassed);
|
|
||||||
// Deselect keyframe to allow the user to add a new one right away
|
|
||||||
mod.setSelected(null, 0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_DELETE, () -> {
|
|
||||||
if (!overlay.isVisible()) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (mod.getSelectedPath() != null) {
|
|
||||||
updateKeyframe(mod.getSelectedPath());
|
@Override
|
||||||
|
public void onFailure(Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void syncTimeButtonPressed() {
|
||||||
|
// Current replay time
|
||||||
|
int time = replayHandler.getReplaySender().currentTimeStamp();
|
||||||
|
// Position of the cursor
|
||||||
|
int cursor = timeline.getCursorPosition();
|
||||||
|
// Get the last time keyframe before the cursor
|
||||||
|
mod.getCurrentTimeline().getTimePath().getKeyframes().stream()
|
||||||
|
.filter(it -> it.getTime() <= cursor).reduce((__, last) -> last).ifPresent(keyframe -> {
|
||||||
|
// Cursor position at the keyframe
|
||||||
|
int keyframeCursor = (int) keyframe.getTime();
|
||||||
|
// Replay time at the keyframe
|
||||||
|
// This is a keyframe from the time path, so it _should_ always have a time property
|
||||||
|
int keyframeTime = keyframe.getValue(TimestampProperty.PROPERTY).get();
|
||||||
|
// Replay time passed
|
||||||
|
int timePassed = time - keyframeTime;
|
||||||
|
// Speed (set to 1 when shift is held)
|
||||||
|
double speed = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ? 1 : replayHandler.getOverlay().getSpeedSliderValue();
|
||||||
|
// Cursor time passed
|
||||||
|
int cursorPassed = (int) (timePassed / speed);
|
||||||
|
// Move cursor to new position
|
||||||
|
timeline.setCursorPosition(keyframeCursor + cursorPassed);
|
||||||
|
// Deselect keyframe to allow the user to add a new one right away
|
||||||
|
mod.setSelected(null, 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteButtonPressed() {
|
||||||
|
if (mod.getSelectedPath() != null) {
|
||||||
|
updateKeyframe(mod.getSelectedPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startLoadingEntityTracker() {
|
||||||
|
Preconditions.checkState(entityTrackerFuture == null);
|
||||||
// Start loading entity tracker
|
// Start loading entity tracker
|
||||||
entityTrackerFuture = SettableFuture.create();
|
entityTrackerFuture = SettableFuture.create();
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user