Allow keyframe timeline cursor sync to be toggled (closes #290)
This commit is contained in:
2
jGui
2
jGui
Submodule jGui updated: 23e291e0c3...afe093a35f
@@ -41,6 +41,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class KeyBindingRegistry extends EventRegistrations {
|
public class KeyBindingRegistry extends EventRegistrations {
|
||||||
private static final String CATEGORY = "replaymod.title";
|
private static final String CATEGORY = "replaymod.title";
|
||||||
@@ -176,6 +177,8 @@ public class KeyBindingRegistry extends EventRegistrations {
|
|||||||
public final KeyBinding keyBinding;
|
public final KeyBinding keyBinding;
|
||||||
private final List<Runnable> handlers = new ArrayList<>();
|
private final List<Runnable> handlers = new ArrayList<>();
|
||||||
private final List<Runnable> repeatedHandlers = new ArrayList<>();
|
private final List<Runnable> repeatedHandlers = new ArrayList<>();
|
||||||
|
private boolean autoActivation;
|
||||||
|
private Consumer<Boolean> autoActivationUpdate;
|
||||||
|
|
||||||
public Binding(String name, KeyBinding keyBinding) {
|
public Binding(String name, KeyBinding keyBinding) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -199,5 +202,26 @@ public class KeyBindingRegistry extends EventRegistrations {
|
|||||||
acc.setPressTime(acc.getPressTime() + 1);
|
acc.setPressTime(acc.getPressTime() + 1);
|
||||||
handleKeyBindings();
|
handleKeyBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void registerAutoActivationSupport(boolean active, Consumer<Boolean> update) {
|
||||||
|
this.autoActivation = active;
|
||||||
|
this.autoActivationUpdate = update;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean supportsAutoActivation() {
|
||||||
|
return autoActivationUpdate != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAutoActivating() {
|
||||||
|
return supportsAutoActivation() && autoActivation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoActivating(boolean active) {
|
||||||
|
if (this.autoActivation == active) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.autoActivation = active;
|
||||||
|
this.autoActivationUpdate.accept(active);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ import de.johni0702.minecraft.gui.container.GuiPanel;
|
|||||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||||
import de.johni0702.minecraft.gui.element.GuiElement;
|
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||||
import de.johni0702.minecraft.gui.layout.GridLayout;
|
import de.johni0702.minecraft.gui.layout.GridLayout;
|
||||||
import de.johni0702.minecraft.gui.layout.LayoutData;
|
import de.johni0702.minecraft.gui.layout.LayoutData;
|
||||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.resource.language.I18n;
|
import net.minecraft.client.resource.language.I18n;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -71,9 +73,25 @@ public class HotkeyButtons extends EventRegistrations implements Extra {
|
|||||||
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||||
// There doesn't seem to be an KeyBindingUpdate event, so we'll just update it every time
|
// There doesn't seem to be an KeyBindingUpdate event, so we'll just update it every time
|
||||||
setLabel(keyBinding.isBound() ? keyBinding.getBoundKey() : "");
|
setLabel(keyBinding.isBound() ? keyBinding.getBoundKey() : "");
|
||||||
|
|
||||||
|
if (keyBinding.supportsAutoActivation()) {
|
||||||
|
setTooltip(new GuiTooltip().setText(new String[]{
|
||||||
|
I18n.translate("replaymod.gui.ingame.autoactivating"),
|
||||||
|
I18n.translate("replaymod.gui.ingame.autoactivating."
|
||||||
|
+ (keyBinding.isAutoActivating() ? "disable" : "enable")),
|
||||||
|
}));
|
||||||
|
setLabelColor(keyBinding.isAutoActivating() ? 0x00ff00 : 0xe0e0e0);
|
||||||
|
}
|
||||||
|
|
||||||
super.draw(renderer, size, renderInfo);
|
super.draw(renderer, size, renderInfo);
|
||||||
}
|
}
|
||||||
}.onClick(keyBinding::trigger);
|
}.onClick(() -> {
|
||||||
|
if (keyBinding.supportsAutoActivation() && Screen.hasControlDown()) {
|
||||||
|
keyBinding.setAutoActivating(!keyBinding.isAutoActivating());
|
||||||
|
} else {
|
||||||
|
keyBinding.trigger();
|
||||||
|
}
|
||||||
|
});
|
||||||
GuiLabel label = new GuiLabel().setI18nText(keyBinding.name);
|
GuiLabel label = new GuiLabel().setI18nText(keyBinding.name);
|
||||||
panel.addElements(null, new GuiPanel().setLayout(new CustomLayout<GuiPanel>() {
|
panel.addElements(null, new GuiPanel().setLayout(new CustomLayout<GuiPanel>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.replaymod.simplepathing;
|
|||||||
import com.replaymod.core.KeyBindingRegistry;
|
import com.replaymod.core.KeyBindingRegistry;
|
||||||
import com.replaymod.core.Module;
|
import com.replaymod.core.Module;
|
||||||
import com.replaymod.core.ReplayMod;
|
import com.replaymod.core.ReplayMod;
|
||||||
|
import com.replaymod.core.SettingsRegistry;
|
||||||
import com.replaymod.core.events.SettingsChangedCallback;
|
import com.replaymod.core.events.SettingsChangedCallback;
|
||||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||||
import com.replaymod.core.versions.MCVer.Keyboard;
|
import com.replaymod.core.versions.MCVer.Keyboard;
|
||||||
@@ -41,6 +42,7 @@ public class ReplayModSimplePathing extends EventRegistrations implements Module
|
|||||||
private ReplayMod core;
|
private ReplayMod core;
|
||||||
public KeyBindingRegistry.Binding keyPositionKeyframe;
|
public KeyBindingRegistry.Binding keyPositionKeyframe;
|
||||||
public KeyBindingRegistry.Binding keyTimeKeyframe;
|
public KeyBindingRegistry.Binding keyTimeKeyframe;
|
||||||
|
public KeyBindingRegistry.Binding keySyncTime;
|
||||||
|
|
||||||
public static Logger LOGGER = LogManager.getLogger();
|
public static Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
@@ -87,9 +89,14 @@ public class ReplayModSimplePathing extends EventRegistrations implements Module
|
|||||||
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.clearkeyframes", Keyboard.KEY_C, () -> {
|
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.clearkeyframes", Keyboard.KEY_C, () -> {
|
||||||
if (guiPathing != null) guiPathing.clearKeyframesButtonPressed();
|
if (guiPathing != null) guiPathing.clearKeyframesButtonPressed();
|
||||||
}, true);
|
}, true);
|
||||||
core.getKeyBindingRegistry().registerRepeatedKeyBinding("replaymod.input.synctimeline", Keyboard.KEY_V, () -> {
|
keySyncTime = core.getKeyBindingRegistry().registerRepeatedKeyBinding("replaymod.input.synctimeline", Keyboard.KEY_V, () -> {
|
||||||
if (guiPathing != null) guiPathing.syncTimeButtonPressed();
|
if (guiPathing != null) guiPathing.syncTimeButtonPressed();
|
||||||
}, true);
|
}, true);
|
||||||
|
SettingsRegistry settingsRegistry = core.getSettingsRegistry();
|
||||||
|
keySyncTime.registerAutoActivationSupport(settingsRegistry.get(Setting.AUTO_SYNC), active -> {
|
||||||
|
settingsRegistry.set(Setting.AUTO_SYNC, active);
|
||||||
|
settingsRegistry.save();
|
||||||
|
});
|
||||||
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_DELETE, () -> {
|
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_DELETE, () -> {
|
||||||
if (guiPathing != null) guiPathing.deleteButtonPressed();
|
if (guiPathing != null) guiPathing.deleteButtonPressed();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public final class Setting<T> extends SettingsRegistry.SettingKeys<T> {
|
public final class Setting<T> extends SettingsRegistry.SettingKeys<T> {
|
||||||
public static final Setting<Boolean> PATH_PREVIEW = make("pathpreview", "pathpreview", true);
|
public static final Setting<Boolean> PATH_PREVIEW = make("pathpreview", "pathpreview", true);
|
||||||
|
public static final Setting<Boolean> AUTO_SYNC = make("autosync", null, true);
|
||||||
public static final Setting<Integer> TIMELINE_LENGTH = make("timelineLength", null, 30 * 60);
|
public static final Setting<Integer> TIMELINE_LENGTH = make("timelineLength", null, 30 * 60);
|
||||||
public static final SettingsRegistry.MultipleChoiceSettingKeys<String> DEFAULT_INTERPOLATION;
|
public static final SettingsRegistry.MultipleChoiceSettingKeys<String> DEFAULT_INTERPOLATION;
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import com.replaymod.simplepathing.SPTimeline.SPPath;
|
|||||||
import com.replaymod.simplepathing.Setting;
|
import com.replaymod.simplepathing.Setting;
|
||||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||||
import de.johni0702.minecraft.gui.RenderInfo;
|
import de.johni0702.minecraft.gui.RenderInfo;
|
||||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
|
||||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||||
@@ -222,6 +221,7 @@ public class GuiPathing {
|
|||||||
private final ReplayMod core;
|
private final ReplayMod core;
|
||||||
private final ReplayModSimplePathing mod;
|
private final ReplayModSimplePathing mod;
|
||||||
private final ReplayHandler replayHandler;
|
private final ReplayHandler replayHandler;
|
||||||
|
private final GuiReplayOverlay overlay;
|
||||||
private final RealtimeTimelinePlayer player;
|
private final RealtimeTimelinePlayer player;
|
||||||
|
|
||||||
// Whether any error which occured during entity tracker loading has already been shown to the user
|
// Whether any error which occured during entity tracker loading has already been shown to the user
|
||||||
@@ -234,8 +234,8 @@ public class GuiPathing {
|
|||||||
this.core = core;
|
this.core = core;
|
||||||
this.mod = mod;
|
this.mod = mod;
|
||||||
this.replayHandler = replayHandler;
|
this.replayHandler = replayHandler;
|
||||||
|
this.overlay = replayHandler.getOverlay();
|
||||||
this.player = new RealtimeTimelinePlayer(replayHandler);
|
this.player = new RealtimeTimelinePlayer(replayHandler);
|
||||||
final GuiReplayOverlay overlay = replayHandler.getOverlay();
|
|
||||||
|
|
||||||
timeline.setLength(core.getSettingsRegistry().get(Setting.TIMELINE_LENGTH) * 1000);
|
timeline.setLength(core.getSettingsRegistry().get(Setting.TIMELINE_LENGTH) * 1000);
|
||||||
|
|
||||||
@@ -364,6 +364,7 @@ public class GuiPathing {
|
|||||||
overlay.setLayout(new CustomLayout<GuiReplayOverlay>(overlay.getLayout()) {
|
overlay.setLayout(new CustomLayout<GuiReplayOverlay>(overlay.getLayout()) {
|
||||||
@Override
|
@Override
|
||||||
protected void layout(GuiReplayOverlay container, int width, int height) {
|
protected void layout(GuiReplayOverlay container, int width, int height) {
|
||||||
|
checkForAutoSync();
|
||||||
pos(panel, 10, y(overlay.topPanel) + height(overlay.topPanel) + 3);
|
pos(panel, 10, y(overlay.topPanel) + height(overlay.topPanel) + 3);
|
||||||
size(panel, width - 20, 40);
|
size(panel, width - 20, 40);
|
||||||
}
|
}
|
||||||
@@ -419,6 +420,28 @@ public class GuiPathing {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int prevSpeed = -1;
|
||||||
|
private int prevTime = -1;
|
||||||
|
private void checkForAutoSync() {
|
||||||
|
if (!mod.keySyncTime.isAutoActivating()) {
|
||||||
|
prevSpeed = -1;
|
||||||
|
prevTime = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int speed = overlay.speedSlider.getValue();
|
||||||
|
if (prevSpeed != speed && prevSpeed != -1) {
|
||||||
|
syncTimeButtonPressed();
|
||||||
|
}
|
||||||
|
prevSpeed = speed;
|
||||||
|
|
||||||
|
int time = replayHandler.getReplaySender().currentTimeStamp();
|
||||||
|
if (prevTime != time && prevTime != -1 && !player.isActive()) {
|
||||||
|
syncTimeButtonPressed();
|
||||||
|
}
|
||||||
|
prevTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
public void syncTimeButtonPressed() {
|
public void syncTimeButtonPressed() {
|
||||||
// Current replay time
|
// Current replay time
|
||||||
int time = replayHandler.getReplaySender().currentTimeStamp();
|
int time = replayHandler.getReplaySender().currentTimeStamp();
|
||||||
|
|||||||
Reference in New Issue
Block a user