Update key and mouse handling in preparation for 1.21.9

This commit is contained in:
Jonas Herzig
2025-10-12 14:36:35 +02:00
parent f299644254
commit e6db9daf80
21 changed files with 153 additions and 134 deletions

View File

@@ -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();

View File

@@ -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;

View File

@@ -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);