Update key and mouse handling in preparation for 1.21.9
This commit is contained in:
2
jGui
2
jGui
Submodule jGui updated: 31106f5dae...2aa5291668
@@ -4,6 +4,7 @@ import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.replaymod.core.events.PreRenderCallback;
|
||||
import com.replaymod.core.mixin.KeyBindingAccessor;
|
||||
import de.johni0702.minecraft.gui.function.KeyInput;
|
||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||
import com.replaymod.core.events.KeyBindingEventCallback;
|
||||
import com.replaymod.core.events.KeyEventCallback;
|
||||
@@ -36,7 +37,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class KeyBindingRegistry extends EventRegistrations {
|
||||
private static final String CATEGORY = "replaymod.title";
|
||||
@@ -46,7 +47,7 @@ public class KeyBindingRegistry extends EventRegistrations {
|
||||
|
||||
private final Map<String, Binding> bindings = new HashMap<>();
|
||||
private Set<KeyBinding> onlyInReplay = new HashSet<>();
|
||||
private Multimap<Integer, Supplier<Boolean>> rawHandlers = ArrayListMultimap.create();
|
||||
private Multimap<Integer, Function<KeyInput, Boolean>> rawHandlers = ArrayListMultimap.create();
|
||||
|
||||
public Binding registerKeyBinding(String name, int keyCode, Runnable whenPressed, boolean onlyInRepay) {
|
||||
Binding binding = registerKeyBinding(name, keyCode, onlyInRepay);
|
||||
@@ -92,7 +93,7 @@ public class KeyBindingRegistry extends EventRegistrations {
|
||||
return binding;
|
||||
}
|
||||
|
||||
public void registerRaw(int keyCode, Supplier<Boolean> whenPressed) {
|
||||
public void registerRaw(int keyCode, Function<KeyInput, Boolean> whenPressed) {
|
||||
rawHandlers.put(keyCode, whenPressed);
|
||||
}
|
||||
|
||||
@@ -138,18 +139,18 @@ public class KeyBindingRegistry extends EventRegistrations {
|
||||
}
|
||||
}
|
||||
|
||||
{ on(KeyEventCallback.EVENT, (keyCode, scanCode, action, modifiers) -> handleRaw(keyCode, action)); }
|
||||
private boolean handleRaw(int keyCode, int action) {
|
||||
{ on(KeyEventCallback.EVENT, this::handleRaw); }
|
||||
private boolean handleRaw(KeyInput keyInput, int action) {
|
||||
if (action != KeyEventCallback.ACTION_PRESS) return false;
|
||||
for (final Supplier<Boolean> handler : rawHandlers.get(keyCode)) {
|
||||
for (final Function<KeyInput, Boolean> handler : rawHandlers.get(keyInput.key)) {
|
||||
try {
|
||||
if (handler.get()) {
|
||||
if (handler.apply(keyInput)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable cause) {
|
||||
CrashReport crashReport = CrashReport.create(cause, "Handling Raw Key Binding");
|
||||
CrashReportSection category = crashReport.addElement("Key Binding");
|
||||
category.add("Key Code", () -> "" + keyCode);
|
||||
category.add("Key Code", () -> "" + keyInput.key);
|
||||
category.add("Handler", handler::toString);
|
||||
throw new CrashException(crashReport);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.replaymod.core.events;
|
||||
|
||||
import de.johni0702.minecraft.gui.function.KeyInput;
|
||||
import de.johni0702.minecraft.gui.utils.Event;
|
||||
|
||||
public interface KeyEventCallback {
|
||||
Event<KeyEventCallback> EVENT = Event.create((listeners) ->
|
||||
(key, scanCode, action, modifiers) -> {
|
||||
(keyInput, action) -> {
|
||||
for (KeyEventCallback listener : listeners) {
|
||||
if (listener.onKeyEvent(key, scanCode, action, modifiers)) {
|
||||
if (listener.onKeyEvent(keyInput, action)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -22,5 +23,5 @@ public interface KeyEventCallback {
|
||||
//$$ int ACTION_PRESS = 1;
|
||||
//#endif
|
||||
|
||||
boolean onKeyEvent(int key, int scanCode, int action, int modifiers);
|
||||
boolean onKeyEvent(KeyInput keyInput, int action);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.replaymod.core.mixin;
|
||||
|
||||
import com.replaymod.core.events.KeyBindingEventCallback;
|
||||
import com.replaymod.core.events.KeyEventCallback;
|
||||
import de.johni0702.minecraft.gui.function.KeyInput;
|
||||
import net.minecraft.client.Keyboard;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -14,7 +15,8 @@ public class MixinKeyboardListener {
|
||||
|
||||
@Inject(method = "onKey", at = @At(value = "INVOKE", target = ON_KEY_PRESSED), cancellable = true)
|
||||
private void beforeKeyBindingTick(long windowPointer, int key, int scanCode, int action, int modifiers, CallbackInfo ci) {
|
||||
if (KeyEventCallback.EVENT.invoker().onKeyEvent(key, scanCode, action, modifiers)) {
|
||||
KeyInput keyInput = new KeyInput(key, scanCode, modifiers);
|
||||
if (KeyEventCallback.EVENT.invoker().onKeyEvent(keyInput, action)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,10 +621,6 @@ public class MCVer {
|
||||
//$$ public static final int KEY_Z = org.lwjgl.input.Keyboard.KEY_Z;
|
||||
//#endif
|
||||
|
||||
public static boolean hasControlDown() {
|
||||
return Screen.hasControlDown();
|
||||
}
|
||||
|
||||
public static boolean isKeyDown(int keyCode) {
|
||||
//#if MC>=11500
|
||||
return InputUtil.isKeyPressed(getMinecraft().getWindow().getHandle(), keyCode);
|
||||
|
||||
@@ -85,8 +85,8 @@ public class HotkeyButtons extends EventRegistrations implements Extra {
|
||||
|
||||
super.draw(renderer, size, renderInfo);
|
||||
}
|
||||
}.onClick(() -> {
|
||||
if (keyBinding.supportsAutoActivation() && Screen.hasControlDown()) {
|
||||
}.onClick(click -> {
|
||||
if (keyBinding.supportsAutoActivation() && click.hasCtrl()) {
|
||||
keyBinding.setAutoActivating(!keyBinding.isAutoActivating());
|
||||
} else {
|
||||
keyBinding.trigger();
|
||||
|
||||
@@ -49,13 +49,13 @@ public class GuiCreateScreenshot extends GuiRenderSettings implements Loadable {
|
||||
|
||||
exportArguments.setText(""); // To disable any preset-based checks
|
||||
buttonPanel.removeElement(queueButton);
|
||||
renderButton.setI18nLabel("replaymod.gui.advancedscreenshots.create").onClick(() -> {
|
||||
renderButton.setI18nLabel("replaymod.gui.advancedscreenshots.create").onClick(click -> {
|
||||
// Closing this GUI ensures that settings are saved
|
||||
close();
|
||||
|
||||
mod.runLater(() -> {
|
||||
try {
|
||||
RenderSettings settings = save(false);
|
||||
RenderSettings settings = save(false, click.hasCtrl());
|
||||
|
||||
boolean success = new ScreenshotRenderer(settings).renderScreenshot();
|
||||
if (success) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import de.johni0702.minecraft.gui.element.GuiImage;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||
import de.johni0702.minecraft.gui.element.IGuiCheckbox;
|
||||
import de.johni0702.minecraft.gui.function.Click;
|
||||
import de.johni0702.minecraft.gui.function.Closeable;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
@@ -52,13 +53,13 @@ public class PlayerOverviewGui extends GuiScreen implements Closeable {
|
||||
.setI18nLabel("replaymod.gui.playeroverview.remembersettings");
|
||||
public final GuiCheckbox checkAll = new GuiCheckbox(contentPanel){
|
||||
@Override
|
||||
public void onClick() {
|
||||
public void onClick(Click click) {
|
||||
playersScrollable.invokeAll(IGuiCheckbox.class, e -> e.setChecked(true));
|
||||
}
|
||||
}.setLabel("").setChecked(true).setTooltip(new GuiTooltip().setI18nText("replaymod.gui.playeroverview.showall"));
|
||||
public final GuiCheckbox uncheckAll = new GuiCheckbox(contentPanel){
|
||||
@Override
|
||||
public void onClick() {
|
||||
public void onClick(Click click) {
|
||||
playersScrollable.invokeAll(IGuiCheckbox.class, e -> e.setChecked(false));
|
||||
}
|
||||
}.setLabel("").setChecked(false).setTooltip(new GuiTooltip().setI18nText("replaymod.gui.playeroverview.hideall"));
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.replaymod.pathing.gui;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.utils.Utils;
|
||||
@@ -26,8 +24,10 @@ import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTextField;
|
||||
import de.johni0702.minecraft.gui.function.Click;
|
||||
import de.johni0702.minecraft.gui.function.Closeable;
|
||||
import de.johni0702.minecraft.gui.function.Typeable;
|
||||
import de.johni0702.minecraft.gui.function.KeyHandler;
|
||||
import de.johni0702.minecraft.gui.function.KeyInput;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.GridLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
@@ -36,7 +36,6 @@ import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import de.johni0702.minecraft.gui.utils.Consumer;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint;
|
||||
import net.minecraft.util.crash.CrashReport;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -56,7 +55,7 @@ import static de.johni0702.minecraft.gui.versions.MCVer.setClipboardString;
|
||||
/**
|
||||
* Gui for loading and saving {@link Timeline Timelines}.
|
||||
*/
|
||||
public class GuiKeyframeRepository extends GuiScreen implements Closeable, Typeable {
|
||||
public class GuiKeyframeRepository extends GuiScreen implements Closeable, KeyHandler {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
public final GuiPanel contentPanel = new GuiPanel(this).setBackgroundColor(Colors.DARK_TRANSPARENT);
|
||||
@@ -90,7 +89,7 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable, Typea
|
||||
@Override
|
||||
public void run() {
|
||||
if (popup.getYesButton().isEnabled()) {
|
||||
popup.getYesButton().onClick();
|
||||
popup.getYesButton().onClick(new Click(-1, -1, 0, 0));
|
||||
}
|
||||
}
|
||||
}).onTextChanged(new Consumer<String>() {
|
||||
@@ -138,7 +137,7 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable, Typea
|
||||
@Override
|
||||
public void run() {
|
||||
if (popup.getYesButton().isEnabled()) {
|
||||
popup.getYesButton().onClick();
|
||||
popup.getYesButton().onClick(new Click(-1, -1, 0, 0));
|
||||
}
|
||||
}
|
||||
}).onTextChanged(new Consumer<String>() {
|
||||
@@ -244,9 +243,9 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable, Typea
|
||||
GuiRenderSettings settingsGui = queue.addJob(timeline);
|
||||
settingsGui.buttonPanel.removeElement(settingsGui.renderButton);
|
||||
settingsGui.setOutputFileBaseName(name);
|
||||
Runnable orgOnClick = settingsGui.queueButton.getOnClick();
|
||||
settingsGui.queueButton.onClick(() -> {
|
||||
orgOnClick.run();
|
||||
Consumer<Click> orgOnClick = settingsGui.queueButton.getOnClick();
|
||||
settingsGui.queueButton.onClick(click -> {
|
||||
orgOnClick.consume(click);
|
||||
this.run();
|
||||
});
|
||||
settingsGui.open();
|
||||
@@ -348,9 +347,9 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable, Typea
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown) {
|
||||
if (MCVer.Keyboard.hasControlDown()) {
|
||||
switch (keyCode) {
|
||||
public boolean handleKey(KeyInput keyInput) {
|
||||
if (keyInput.hasCtrl()) {
|
||||
switch (keyInput.key) {
|
||||
case MCVer.Keyboard.KEY_A:
|
||||
if (selectedEntries.size() < timelines.size()) {
|
||||
for (GuiElement<?> child : list.getListPanel().getChildren()) {
|
||||
@@ -364,10 +363,10 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable, Typea
|
||||
updateButtons();
|
||||
return true;
|
||||
case MCVer.Keyboard.KEY_C:
|
||||
copyButton.onClick();
|
||||
copyButton.onClick(new Click(-1, -1, 0, 0));
|
||||
return true;
|
||||
case MCVer.Keyboard.KEY_V:
|
||||
pasteButton.onClick();
|
||||
pasteButton.onClick(new Click(-1, -1, 0, 0));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -396,8 +395,8 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable, Typea
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
if (!MCVer.Keyboard.hasControlDown()) {
|
||||
protected void onClick(Click click) {
|
||||
if (!click.hasCtrl()) {
|
||||
selectedEntries.clear();
|
||||
}
|
||||
if (selectedEntries.contains(this)) {
|
||||
|
||||
@@ -26,7 +26,9 @@ import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||
import de.johni0702.minecraft.gui.function.Typeable;
|
||||
import de.johni0702.minecraft.gui.function.Click;
|
||||
import de.johni0702.minecraft.gui.function.KeyHandler;
|
||||
import de.johni0702.minecraft.gui.function.KeyInput;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.GridLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
@@ -35,7 +37,6 @@ import de.johni0702.minecraft.gui.popup.GuiInfoPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.util.crash.CrashReport;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -59,7 +60,7 @@ import net.minecraft.text.TranslatableText;
|
||||
//$$ import com.replaymod.replaystudio.util.I18n;
|
||||
//#endif
|
||||
|
||||
public class GuiRenderQueue extends AbstractGuiPopup<GuiRenderQueue> implements Typeable {
|
||||
public class GuiRenderQueue extends AbstractGuiPopup<GuiRenderQueue> implements KeyHandler {
|
||||
private final GuiLabel title = new GuiLabel().setI18nText("replaymod.gui.renderqueue.title").setColor(Colors.BLACK);
|
||||
private final GuiVerticalList list = new GuiVerticalList().setDrawShadow(true).setDrawSlider(true);
|
||||
private final GuiButton addButton = new GuiButton().setI18nLabel("replaymod.gui.renderqueue.add").setSize(150, 20);
|
||||
@@ -272,8 +273,8 @@ public class GuiRenderQueue extends AbstractGuiPopup<GuiRenderQueue> implements
|
||||
if (!jobs.isEmpty()) {
|
||||
buttonPanel.removeElement(renderButton);
|
||||
}
|
||||
queueButton.onClick(() -> {
|
||||
RenderSettings settings = save(false);
|
||||
queueButton.onClick(click -> {
|
||||
RenderSettings settings = save(false, click.hasCtrl());
|
||||
|
||||
RenderJob newJob = new RenderJob();
|
||||
newJob.setSettings(settings);
|
||||
@@ -342,8 +343,8 @@ public class GuiRenderQueue extends AbstractGuiPopup<GuiRenderQueue> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown) {
|
||||
if (MCVer.Keyboard.hasControlDown() && keyCode == MCVer.Keyboard.KEY_A) {
|
||||
public boolean handleKey(KeyInput keyInput) {
|
||||
if (keyInput.hasCtrl() && keyInput.key == MCVer.Keyboard.KEY_A) {
|
||||
if (selectedEntries.size() < list.getListPanel().getChildren().size()) {
|
||||
for (GuiElement<?> child : list.getListPanel().getChildren()) {
|
||||
if (child instanceof Entry) {
|
||||
@@ -381,8 +382,8 @@ public class GuiRenderQueue extends AbstractGuiPopup<GuiRenderQueue> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
if (!MCVer.Keyboard.hasControlDown()) {
|
||||
protected void onClick(Click click) {
|
||||
if (!click.hasCtrl()) {
|
||||
selectedEntries.clear();
|
||||
}
|
||||
if (selectedEntries.contains(this)) {
|
||||
@@ -410,8 +411,8 @@ public class GuiRenderQueue extends AbstractGuiPopup<GuiRenderQueue> implements
|
||||
public GuiRenderSettings edit() {
|
||||
GuiRenderSettings gui = new GuiRenderSettings(container, replayHandler, job.getTimeline());
|
||||
gui.buttonPanel.removeElement(gui.renderButton);
|
||||
gui.queueButton.setI18nLabel("replaymod.gui.done").onClick(() -> {
|
||||
job.setSettings(gui.save(false));
|
||||
gui.queueButton.setI18nLabel("replaymod.gui.done").onClick(click -> {
|
||||
job.setSettings(gui.save(false, click.hasCtrl()));
|
||||
label.setText(job.getName());
|
||||
mod.saveRenderQueue();
|
||||
gui.close();
|
||||
|
||||
@@ -18,6 +18,7 @@ import de.johni0702.minecraft.gui.container.GuiVerticalList;
|
||||
import de.johni0702.minecraft.gui.element.*;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiColorPicker;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiDropdownMenu;
|
||||
import de.johni0702.minecraft.gui.function.Click;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.GridLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
@@ -232,13 +233,13 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
public final GuiButton queueButton = new GuiButton(buttonPanel)
|
||||
.setSize(100, 20)
|
||||
.setI18nLabel("replaymod.gui.rendersettings.addtoqueue");
|
||||
public final GuiButton renderButton = new GuiButton(buttonPanel).onClick(() -> ReplayMod.instance.runLaterWithoutLock(new Runnable() {
|
||||
public final GuiButton renderButton = new GuiButton(buttonPanel).onClick(click -> ReplayMod.instance.runLaterWithoutLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Closing this GUI ensures that settings are saved
|
||||
close();
|
||||
try {
|
||||
VideoRenderer videoRenderer = new VideoRenderer(save(false), replayHandler, timeline);
|
||||
VideoRenderer videoRenderer = new VideoRenderer(save(false, click.hasCtrl()), replayHandler, timeline);
|
||||
videoRenderer.renderVideo();
|
||||
} catch (FFmpegWriter.NoFFmpegException e) {
|
||||
LOGGER.error("Rendering video:", e);
|
||||
@@ -248,7 +249,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
// Update settings with fixed ffmpeg arguments
|
||||
exportArguments.setText(newSettings.getExportArguments());
|
||||
// Restart rendering, this will also save the changed ffmpeg arguments
|
||||
renderButton.onClick();
|
||||
renderButton.onClick(click);
|
||||
});
|
||||
} catch (Throwable t) {
|
||||
error(LOGGER, GuiRenderSettings.this, CrashReport.create(t, "Rendering video"), () -> {});
|
||||
@@ -349,7 +350,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
videoHeight.setTextColor(Colors.RED);
|
||||
}
|
||||
|
||||
String[] compatError = VideoRenderer.checkCompat(save(false));
|
||||
String[] compatError = VideoRenderer.checkCompat(save(false, false));
|
||||
if (resolutionError != null) {
|
||||
renderButton.setDisabled().setTooltip(new GuiTooltip().setI18nText(resolutionError));
|
||||
} else if (compatError != null) {
|
||||
@@ -552,7 +553,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
updateInputs();
|
||||
}
|
||||
|
||||
public RenderSettings save(boolean serialize) {
|
||||
public RenderSettings save(boolean serialize, boolean highPerformance) {
|
||||
int sphericalFov = MIN_SPHERICAL_FOV + sphericalFovSlider.getValue() * SPHERICAL_FOV_STEP_SIZE;
|
||||
|
||||
return new RenderSettings(
|
||||
@@ -576,7 +577,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
serialize || antiAliasingDropdown.isEnabled() ? antiAliasingDropdown.getSelectedValue() : RenderSettings.AntiAliasing.NONE,
|
||||
exportCommand.getText(),
|
||||
exportArguments.getText(),
|
||||
net.minecraft.client.gui.screen.Screen.hasControlDown()
|
||||
highPerformance
|
||||
);
|
||||
}
|
||||
|
||||
@@ -623,7 +624,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
RenderSettings settings = save(true);
|
||||
RenderSettings settings = save(true, false);
|
||||
String json = new Gson().toJson(settings);
|
||||
try {
|
||||
Files.write(getSettingsPath(), json.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
@@ -11,6 +11,7 @@ import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiCheckbox;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiProgressBar;
|
||||
import de.johni0702.minecraft.gui.function.Click;
|
||||
import de.johni0702.minecraft.gui.function.Tickable;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
@@ -67,8 +68,8 @@ public class GuiVideoRenderer extends GuiScreen implements Tickable {
|
||||
boolean waitingForConfirmation;
|
||||
|
||||
@Override
|
||||
public boolean mouseClick(ReadablePoint position, int button) {
|
||||
boolean result = super.mouseClick(position, button);
|
||||
public boolean mouseClick(Click click) {
|
||||
boolean result = super.mouseClick(click);
|
||||
if (waitingForConfirmation && !result) {
|
||||
setI18nLabel("replaymod.gui.rendering.cancel");
|
||||
waitingForConfirmation = false;
|
||||
@@ -77,8 +78,8 @@ public class GuiVideoRenderer extends GuiScreen implements Tickable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick() {
|
||||
super.onClick();
|
||||
public void onClick(Click click) {
|
||||
super.onClick(click);
|
||||
if (!waitingForConfirmation) {
|
||||
setI18nLabel("replaymod.gui.rendering.cancel.callback");
|
||||
waitingForConfirmation = true;
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.replaymod.replay.gui.screen.GuiModCompatWarning;
|
||||
import com.replaymod.replay.handler.GuiHandler;
|
||||
import com.replaymod.replaystudio.data.Marker;
|
||||
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import de.johni0702.minecraft.gui.function.Click;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -116,7 +117,7 @@ public class ReplayModReplay implements Module {
|
||||
@Override
|
||||
public void run() {
|
||||
if (replayHandler != null) {
|
||||
replayHandler.getOverlay().playPauseButton.onClick();
|
||||
replayHandler.getOverlay().playPauseButton.onClick(new Click(-1, -1, 0, 0));
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
|
||||
@@ -4,19 +4,19 @@ import com.google.common.base.Strings;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.element.*;
|
||||
import de.johni0702.minecraft.gui.function.Typeable;
|
||||
import de.johni0702.minecraft.gui.function.Click;
|
||||
import de.johni0702.minecraft.gui.function.KeyHandler;
|
||||
import de.johni0702.minecraft.gui.function.KeyInput;
|
||||
import de.johni0702.minecraft.gui.layout.GridLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import com.replaymod.core.versions.MCVer.Keyboard;
|
||||
import com.replaymod.replaystudio.data.Marker;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class GuiEditMarkerPopup extends AbstractGuiPopup<GuiEditMarkerPopup> implements Typeable {
|
||||
public class GuiEditMarkerPopup extends AbstractGuiPopup<GuiEditMarkerPopup> implements KeyHandler {
|
||||
private static GuiNumberField newGuiNumberField() {
|
||||
return new GuiNumberField().setSize(150, 20).setValidateOnFocusChange(true);
|
||||
}
|
||||
@@ -116,9 +116,9 @@ public class GuiEditMarkerPopup extends AbstractGuiPopup<GuiEditMarkerPopup> imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown) {
|
||||
if (keyCode == Keyboard.KEY_ESCAPE) {
|
||||
cancelButton.onClick();
|
||||
public boolean handleKey(KeyInput keyInput) {
|
||||
if (keyInput.isEscape()) {
|
||||
cancelButton.onClick(new Click(-1, -1, 0, keyInput.modifiers));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -10,8 +10,10 @@ import com.replaymod.replaystudio.util.Location;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.element.advanced.AbstractGuiTimeline;
|
||||
import de.johni0702.minecraft.gui.function.Click;
|
||||
import de.johni0702.minecraft.gui.function.Draggable;
|
||||
import de.johni0702.minecraft.gui.function.Typeable;
|
||||
import de.johni0702.minecraft.gui.function.KeyHandler;
|
||||
import de.johni0702.minecraft.gui.function.KeyInput;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.Point;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint;
|
||||
@@ -27,7 +29,7 @@ import java.util.function.Consumer;
|
||||
|
||||
import static de.johni0702.minecraft.gui.utils.Utils.clamp;
|
||||
|
||||
public class GuiMarkerTimeline extends AbstractGuiTimeline<GuiMarkerTimeline> implements Draggable, Typeable {
|
||||
public class GuiMarkerTimeline extends AbstractGuiTimeline<GuiMarkerTimeline> implements Draggable, KeyHandler {
|
||||
protected static final int TEXTURE_MARKER_X = 109;
|
||||
protected static final int TEXTURE_MARKER_Y = 20;
|
||||
protected static final int TEXTURE_MARKER_SELECTED_X = 114;
|
||||
@@ -149,15 +151,15 @@ public class GuiMarkerTimeline extends AbstractGuiTimeline<GuiMarkerTimeline> im
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClick(ReadablePoint position, int button) {
|
||||
Marker marker = getMarkerAt(position.getX(), position.getY());
|
||||
public boolean mouseClick(Click click) {
|
||||
Marker marker = getMarkerAt(click.x, click.y);
|
||||
if (marker != null) {
|
||||
if (button == 0) { // Left click
|
||||
if (click.button == 0) { // Left click
|
||||
long now = System.currentTimeMillis();
|
||||
selectedMarker = marker;
|
||||
if (Math.abs(lastClickTime - now) > 500) { // Single click
|
||||
draggingStartX = position.getX();
|
||||
draggingTimeDelta = marker.getTime() - getTimeAt(position.getX(), position.getY());
|
||||
draggingStartX = click.x;
|
||||
draggingTimeDelta = marker.getTime() - getTimeAt(click.x, click.y);
|
||||
} else { // Double click
|
||||
new GuiEditMarkerPopup(getContainer(), marker, (updatedMarker) -> {
|
||||
markers.remove(marker);
|
||||
@@ -166,7 +168,7 @@ public class GuiMarkerTimeline extends AbstractGuiTimeline<GuiMarkerTimeline> im
|
||||
}).open();
|
||||
}
|
||||
lastClickTime = now;
|
||||
} else if (button == 1) { // Right click
|
||||
} else if (click.button == 1) { // Right click
|
||||
selectedMarker = null;
|
||||
if (replayHandler != null) {
|
||||
CameraEntity cameraEntity = replayHandler.getCameraEntity();
|
||||
@@ -185,18 +187,18 @@ public class GuiMarkerTimeline extends AbstractGuiTimeline<GuiMarkerTimeline> im
|
||||
} else {
|
||||
selectedMarker = null;
|
||||
}
|
||||
return super.mouseClick(position, button);
|
||||
return super.mouseClick(click);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDrag(ReadablePoint position, int button, long timeSinceLastCall) {
|
||||
public boolean mouseDrag(Click click) {
|
||||
if (selectedMarker != null) {
|
||||
int diff = position.getX() - draggingStartX;
|
||||
int diff = click.y - draggingStartX;
|
||||
if (Math.abs(diff) > MARKER_SIZE) {
|
||||
dragging = true;
|
||||
}
|
||||
if (dragging) {
|
||||
int timeAt = getTimeAt(position.getX(), position.getY());
|
||||
int timeAt = getTimeAt(click.x, click.y);
|
||||
if (timeAt != -1) {
|
||||
selectedMarker.setTime(draggingTimeDelta + timeAt);
|
||||
}
|
||||
@@ -207,9 +209,9 @@ public class GuiMarkerTimeline extends AbstractGuiTimeline<GuiMarkerTimeline> im
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseRelease(ReadablePoint position, int button) {
|
||||
public boolean mouseRelease(Click click) {
|
||||
if (selectedMarker != null) {
|
||||
mouseDrag(position, button, 0);
|
||||
mouseDrag(click);
|
||||
if (dragging) {
|
||||
dragging = false;
|
||||
saveMarkers.accept(markers);
|
||||
@@ -237,8 +239,8 @@ public class GuiMarkerTimeline extends AbstractGuiTimeline<GuiMarkerTimeline> im
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown) {
|
||||
if (keyCode == Keyboard.KEY_DELETE && selectedMarker != null) {
|
||||
public boolean handleKey(KeyInput keyInput) {
|
||||
if (keyInput.key == Keyboard.KEY_DELETE && selectedMarker != null) {
|
||||
markers.remove(selectedMarker);
|
||||
saveMarkers.accept(markers);
|
||||
return true;
|
||||
|
||||
@@ -16,6 +16,7 @@ import de.johni0702.minecraft.gui.element.GuiElement;
|
||||
import de.johni0702.minecraft.gui.element.GuiSlider;
|
||||
import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||
import de.johni0702.minecraft.gui.element.advanced.IGuiTimeline;
|
||||
import de.johni0702.minecraft.gui.function.KeyInput;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||
@@ -181,13 +182,15 @@ public class GuiReplayOverlay extends AbstractGuiOverlay<GuiReplayOverlay> {
|
||||
}
|
||||
}
|
||||
|
||||
{ on(KeyEventCallback.EVENT, (int key, int scanCode, int action, int modifiers) -> { onKeyInput(key, action); return false; }); }
|
||||
private void onKeyInput(int key, int action) {
|
||||
if (action != KeyEventCallback.ACTION_PRESS) return;
|
||||
{ on(KeyEventCallback.EVENT, this::onKeyInput); }
|
||||
private boolean onKeyInput(KeyInput keyInput, int action) {
|
||||
if (action != KeyEventCallback.ACTION_PRESS) return false;
|
||||
// Allow F1 to be used to hide the replay gui (e.g. for recording with OBS)
|
||||
if (isMouseVisible() && key == Keyboard.KEY_F1) {
|
||||
if (isMouseVisible() && keyInput.key == Keyboard.KEY_F1) {
|
||||
hidden = !hidden;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,11 @@ import com.replaymod.render.rendering.VideoRenderer;
|
||||
import com.replaymod.render.utils.RenderJob;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.function.CharHandler;
|
||||
import de.johni0702.minecraft.gui.function.CharInput;
|
||||
import de.johni0702.minecraft.gui.function.Click;
|
||||
import de.johni0702.minecraft.gui.function.KeyHandler;
|
||||
import de.johni0702.minecraft.gui.function.KeyInput;
|
||||
import de.johni0702.minecraft.gui.versions.Image;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.util.Formatting;
|
||||
@@ -25,7 +30,6 @@ import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.*;
|
||||
import de.johni0702.minecraft.gui.element.advanced.AbstractGuiResourceLoadingList;
|
||||
import de.johni0702.minecraft.gui.function.Typeable;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
@@ -35,7 +39,6 @@ import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import de.johni0702.minecraft.gui.utils.Consumer;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint;
|
||||
import net.minecraft.client.gui.screen.NoticeScreen;
|
||||
import net.minecraft.util.crash.CrashReport;
|
||||
import net.minecraft.util.crash.CrashException;
|
||||
@@ -79,7 +82,7 @@ public class GuiReplayViewer extends GuiScreen {
|
||||
|
||||
public final GuiReplayList list = new GuiReplayList(this).onSelectionChanged(this::updateButtons).onSelectionDoubleClicked(() -> {
|
||||
if (this.loadButton.isEnabled()) {
|
||||
this.loadButton.onClick();
|
||||
this.loadButton.onClick(new Click(-1, -1, 0, 0));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -146,7 +149,7 @@ public class GuiReplayViewer extends GuiScreen {
|
||||
@Override
|
||||
public void run() {
|
||||
if (popup.getYesButton().isEnabled()) {
|
||||
popup.getYesButton().onClick();
|
||||
popup.getYesButton().onClick(new Click(-1, -1, 0, 0));
|
||||
}
|
||||
}
|
||||
}).onTextChanged(obj -> {
|
||||
@@ -352,7 +355,7 @@ public class GuiReplayViewer extends GuiScreen {
|
||||
}
|
||||
}
|
||||
|
||||
public static class GuiReplayList extends AbstractGuiResourceLoadingList<GuiReplayList, GuiReplayEntry> implements Typeable {
|
||||
public static class GuiReplayList extends AbstractGuiResourceLoadingList<GuiReplayList, GuiReplayEntry> implements KeyHandler, CharHandler {
|
||||
private File folder = null;
|
||||
|
||||
// Not actually a child of this element, we just use it for text manipulation
|
||||
@@ -417,8 +420,8 @@ public class GuiReplayViewer extends GuiScreen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown) {
|
||||
if (keyCode == Keyboard.KEY_F1) {
|
||||
public boolean handleKey(KeyInput keyInput) {
|
||||
if (keyInput.key == Keyboard.KEY_F1) {
|
||||
SettingsRegistry reg = ReplayMod.instance.getSettingsRegistry();
|
||||
reg.set(Setting.SHOW_SERVER_IPS, !reg.get(Setting.SHOW_SERVER_IPS));
|
||||
reg.save();
|
||||
@@ -426,16 +429,26 @@ public class GuiReplayViewer extends GuiScreen {
|
||||
}
|
||||
|
||||
boolean filterHasPriority = !filterTextField.getText().isEmpty();
|
||||
if (filterHasPriority && filterTextField.typeKey(mousePosition, keyCode, keyChar, ctrlDown, shiftDown)) {
|
||||
if (filterHasPriority && filterTextField.handleKey(keyInput)) {
|
||||
scrollY(0); // ensure we scroll to top if most entries are filtered
|
||||
return true;
|
||||
}
|
||||
|
||||
if (super.typeKey(mousePosition, keyCode, keyChar, ctrlDown, shiftDown)) {
|
||||
if (super.handleKey(keyInput)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!filterHasPriority && filterTextField.typeKey(mousePosition, keyCode, keyChar, ctrlDown, shiftDown)) {
|
||||
if (!filterHasPriority && filterTextField.handleKey(keyInput)) {
|
||||
scrollY(0); // ensure we scroll to top if most entries are filtered
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleChar(CharInput charInput) {
|
||||
if (filterTextField.handleChar(charInput)) {
|
||||
scrollY(0); // ensure we scroll to top if most entries are filtered
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class ReplayModSimplePathing extends EventRegistrations implements Module
|
||||
settingsRegistry.set(Setting.AUTO_SYNC, active);
|
||||
settingsRegistry.save();
|
||||
});
|
||||
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_DELETE, () ->
|
||||
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_DELETE, keyInput ->
|
||||
guiPathing != null && guiPathing.deleteButtonPressed());
|
||||
keyPositionKeyframe = core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.positionkeyframe", Keyboard.KEY_I, () -> {
|
||||
if (guiPathing != null) guiPathing.toggleKeyframe(SPPath.POSITION, false);
|
||||
@@ -115,10 +115,10 @@ public class ReplayModSimplePathing extends EventRegistrations implements Module
|
||||
guiPathing.toggleKeyframe(SPPath.POSITION, false);
|
||||
}
|
||||
}, true);
|
||||
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_Z, () -> {
|
||||
if (Screen.hasControlDown() && currentTimeline != null) {
|
||||
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_Z, keyInput -> {
|
||||
if (keyInput.hasCtrl() && currentTimeline != null) {
|
||||
Timeline timeline = currentTimeline.getTimeline();
|
||||
if (Screen.hasShiftDown()) {
|
||||
if (keyInput.hasShift()) {
|
||||
if (timeline.peekRedoStack() != null) {
|
||||
timeline.redoLastChange();
|
||||
}
|
||||
@@ -131,8 +131,8 @@ public class ReplayModSimplePathing extends EventRegistrations implements Module
|
||||
}
|
||||
return false;
|
||||
});
|
||||
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_Y, () -> {
|
||||
if (Screen.hasControlDown() && currentTimeline != null) {
|
||||
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_Y, keyInput -> {
|
||||
if (keyInput.hasCtrl() && currentTimeline != null) {
|
||||
Timeline timeline = currentTimeline.getTimeline();
|
||||
if (timeline.peekRedoStack() != null) {
|
||||
timeline.redoLastChange();
|
||||
|
||||
@@ -26,14 +26,15 @@ import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||
import de.johni0702.minecraft.gui.element.IGuiClickable;
|
||||
import de.johni0702.minecraft.gui.element.IGuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiDropdownMenu;
|
||||
import de.johni0702.minecraft.gui.function.Typeable;
|
||||
import de.johni0702.minecraft.gui.function.Click;
|
||||
import de.johni0702.minecraft.gui.function.KeyHandler;
|
||||
import de.johni0702.minecraft.gui.function.KeyInput;
|
||||
import de.johni0702.minecraft.gui.layout.GridLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import de.johni0702.minecraft.gui.utils.Consumer;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -41,15 +42,9 @@ import org.apache.logging.log4j.Logger;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
//#if MC>=11400
|
||||
import com.replaymod.core.versions.MCVer.Keyboard;
|
||||
//#else
|
||||
//$$ import org.lwjgl.input.Keyboard;
|
||||
//#endif
|
||||
|
||||
import static de.johni0702.minecraft.gui.utils.Utils.link;
|
||||
|
||||
public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends AbstractGuiPopup<T> implements Typeable {
|
||||
public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends AbstractGuiPopup<T> implements KeyHandler {
|
||||
private static GuiNumberField newGuiNumberField() {
|
||||
return new GuiNumberField().setPrecision(0).setValidateOnFocusChange(true);
|
||||
}
|
||||
@@ -134,9 +129,9 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown) {
|
||||
if (keyCode == Keyboard.KEY_ESCAPE) {
|
||||
cancelButton.onClick();
|
||||
public boolean handleKey(KeyInput keyInput) {
|
||||
if (keyInput.isEscape()) {
|
||||
cancelButton.onClick(new Click(-1, -1, 0, keyInput.modifiers));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.replaymod.simplepathing.SPTimeline;
|
||||
import com.replaymod.simplepathing.SPTimeline.SPPath;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.element.advanced.AbstractGuiTimeline;
|
||||
import de.johni0702.minecraft.gui.function.Click;
|
||||
import de.johni0702.minecraft.gui.function.Draggable;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.vector.Vector2f;
|
||||
import net.minecraft.client.render.BufferBuilder;
|
||||
@@ -407,14 +408,14 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClick(ReadablePoint position, int button) {
|
||||
int time = getTimeAt(position.getX(), position.getY());
|
||||
Pair<SPPath, Long> pathKeyframePair = getKeyframe(position);
|
||||
public boolean mouseClick(Click click) {
|
||||
int time = getTimeAt(click.x, click.y);
|
||||
Pair<SPPath, Long> pathKeyframePair = getKeyframe(click);
|
||||
if (pathKeyframePair.getRight() != null) {
|
||||
SPPath path = pathKeyframePair.getLeft();
|
||||
// Clicked on keyframe
|
||||
long keyframeTime = pathKeyframePair.getRight();
|
||||
if (button == 0) { // Left click
|
||||
if (click.button == 0) { // Left click
|
||||
long now = MCVer.milliTime();
|
||||
if (lastClickedKeyframe == keyframeTime) {
|
||||
// Clicked the same keyframe again, potentially a double click
|
||||
@@ -430,9 +431,9 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
lastClickedPath = path;
|
||||
gui.getMod().setSelected(lastClickedPath, lastClickedKeyframe);
|
||||
// We might be dragging
|
||||
draggingStartX = position.getX();
|
||||
draggingStartX = click.x;
|
||||
dragging = true;
|
||||
} else if (button == 1) { // Right click
|
||||
} else if (click.button == 1) { // Right click
|
||||
Keyframe keyframe = gui.getMod().getCurrentTimeline().getKeyframe(path, keyframeTime);
|
||||
for (Property property : keyframe.getProperties()) {
|
||||
applyPropertyToGame(property, keyframe);
|
||||
@@ -441,10 +442,10 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
return true;
|
||||
} else if (time != -1) {
|
||||
// Clicked on timeline but not on any keyframe
|
||||
if (button == 0) { // Left click
|
||||
if (click.button == 0) { // Left click
|
||||
setCursorPosition(time);
|
||||
gui.getMod().setSelected(null, 0);
|
||||
} else if (button == 1) { // Right click
|
||||
} else if (click.button == 1) { // Right click
|
||||
if (pathKeyframePair.getLeft() != null) {
|
||||
// Apply the value of the clicked path at the clicked position
|
||||
Path path = gui.getMod().getCurrentTimeline().getPath(pathKeyframePair.getLeft());
|
||||
@@ -475,11 +476,11 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDrag(ReadablePoint position, int button, long timeSinceLastCall) {
|
||||
public boolean mouseDrag(Click click) {
|
||||
if (!dragging) {
|
||||
if (button == 0) {
|
||||
if (click.button == 0) {
|
||||
// Left click, the user might try to move the cursor by clicking and holding
|
||||
int time = getTimeAt(position.getX(), position.getY());
|
||||
int time = getTimeAt(click.x, click.y);
|
||||
if (time != -1) {
|
||||
// and they are still on the timeline, so update the time appropriately
|
||||
setCursorPosition(time);
|
||||
@@ -491,15 +492,15 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
|
||||
if (!actuallyDragging) {
|
||||
// Check if threshold has been passed by now
|
||||
if (Math.abs(position.getX() - draggingStartX) >= DRAGGING_THRESHOLD) {
|
||||
if (Math.abs(click.x - draggingStartX) >= DRAGGING_THRESHOLD) {
|
||||
actuallyDragging = true;
|
||||
}
|
||||
}
|
||||
if (actuallyDragging) {
|
||||
if (!gui.loadEntityTracker(() -> mouseDrag(position, button, timeSinceLastCall))) return true;
|
||||
if (!gui.loadEntityTracker(() -> mouseDrag(click))) return true;
|
||||
// Threshold passed
|
||||
SPTimeline timeline = gui.getMod().getCurrentTimeline();
|
||||
Point mouse = new Point(position);
|
||||
Point mouse = new Point(click);
|
||||
getContainer().convertFor(this, mouse);
|
||||
int mouseX = mouse.getX();
|
||||
int width = getLastSize().getWidth();
|
||||
@@ -532,7 +533,7 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseRelease(ReadablePoint position, int button) {
|
||||
public boolean mouseRelease(Click click) {
|
||||
if (dragging) {
|
||||
if (actuallyDragging) {
|
||||
gui.getMod().getCurrentTimeline().getTimeline().pushChange(draggingChange);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.replaymod.core.mixin;
|
||||
|
||||
import com.replaymod.core.events.KeyBindingEventCallback;
|
||||
import com.replaymod.core.events.KeyEventCallback;
|
||||
import de.johni0702.minecraft.gui.function.KeyInput;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -15,7 +16,7 @@ public class MixinKeyboardListener {
|
||||
private static void beforeKeyBindingTick(CallbackInfo ci) {
|
||||
int keyCode = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey();
|
||||
int action = Keyboard.getEventKeyState() ? KeyEventCallback.ACTION_PRESS : KeyEventCallback.ACTION_RELEASE;
|
||||
if (KeyEventCallback.EVENT.invoker().onKeyEvent(keyCode, 0, action, 0)) {
|
||||
if (KeyEventCallback.EVENT.invoker().onKeyEvent(new KeyInput(keyCode), action)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user