aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAscynx <78341107+Ascynx@users.noreply.github.com>2022-10-21 03:25:08 +0200
committerGitHub <noreply@github.com>2022-10-20 21:25:08 -0400
commit19175cb01395cd0a74714a0202152a0d52a561d4 (patch)
tree2eada68339dba9920379eb1ece89f96c956fc2ce /src/main/java
parentebf61799fb28c971d94a02815924018b0964dea4 (diff)
downloadNotEnoughUpdates-19175cb01395cd0a74714a0202152a0d52a561d4.tar.gz
NotEnoughUpdates-19175cb01395cd0a74714a0202152a0d52a561d4.tar.bz2
NotEnoughUpdates-19175cb01395cd0a74714a0202152a0d52a561d4.zip
Ctrl + Z and (Ctrl + Y and Ctrl + Shift + Z) support (#358)
* Ctrl + Z and Ctrl + Y support currently for Bazaar and AH search along with the search bar. (might have issues as my brain jumbled up during the making of this and also probably missing a few places that could use it.) * Ctrl + Z and Ctrl + Y support but on a bigger scale Removed it from Auction and Bazaar search and created a new mixin for GuiTextField containing the Undo (Ctrl + z) and Redo (Ctrl + y) action. * Ctrl + shift + Z for redo and stack cut. After redo/undo if you type a character or remove one it will cut the stack to that index (won't be able to rewind what you already rewound before.) * Moved the undo/redo detection to MixinGuiTextField#addToStack * Added an override for if something goes wrong see misc > "Enable text field tweaks" Also removed the space that hannibal wanted gone. :) * i hate files changed with only new lines Co-authored-by: nopo <nopotheemail@gmail.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiTextField.java136
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java8
3 files changed, 145 insertions, 1 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
index 14078069..2f55c338 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
@@ -1035,7 +1035,7 @@ public class NEUOverlay extends Gui {
return false;
}
- if (Keyboard.isKeyDown(Keyboard.KEY_Y) && NotEnoughUpdates.INSTANCE.config.hidden.dev) {
+ if ((Keyboard.isKeyDown(Keyboard.KEY_Y) && !Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) && NotEnoughUpdates.INSTANCE.config.hidden.dev) {
displayInformationPane(new DevInfoPane(this, manager));
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiTextField.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiTextField.java
new file mode 100644
index 00000000..55a5a098
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiTextField.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2022 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.mixins;
+
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import net.minecraft.client.gui.GuiTextField;
+import org.lwjgl.input.Keyboard;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
+
+import java.util.ArrayList;
+
+@Mixin(GuiTextField.class)
+public abstract class MixinGuiTextField {
+
+ private final ArrayList<String> stringStack = new ArrayList<String>() {
+ {
+ //allows the ability to undo the entire textField
+ add("");
+ }
+ };
+ private int currentStringStackIndex = -1;
+
+ @Shadow private int maxStringLength;
+
+ @Shadow
+ private String text;
+
+ @Shadow
+ public abstract void setCursorPositionEnd();
+
+ @Shadow
+ public abstract void setText(String string);
+
+ private void addToStack(String string) {
+ if (currentStringStackIndex != -1 && currentStringStackIndex != stringStack.size() - 1) {
+ //did redo/undo before
+ stringStack.subList(currentStringStackIndex, stringStack.size()).clear();
+ }
+ if (stringStack.size() > 20) {
+ stringStack.remove(0);
+ }
+ stringStack.add(string);
+ currentStringStackIndex = stringStack.size() - 1;
+ }
+
+ @Inject(method = "setText", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILSOFT)
+ public void setText_stringStack(String string, CallbackInfo ci) {
+ if (NotEnoughUpdates.INSTANCE.config.misc.textFieldTweaksEnabled) {
+ addToStack(string.length() > this.maxStringLength ? string.substring(0, this.maxStringLength) : string);
+ }
+ }
+
+ @Inject(method = "writeText", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiTextField;moveCursorBy(I)V"), locals = LocalCapture.CAPTURE_FAILSOFT)
+ public void writeText_stringStack(String string, CallbackInfo ci, String string2, String string3, int i, int j, int l) {
+ if (NotEnoughUpdates.INSTANCE.config.misc.textFieldTweaksEnabled) {
+ addToStack(string2);
+ }
+ }
+
+ @Inject(method = "deleteFromCursor", at = @At(value = "INVOKE", target = "Lcom/google/common/base/Predicate;apply(Ljava/lang/Object;)Z"), locals = LocalCapture.PRINT)
+ public void deleteFromCursor_stringStack(int i, CallbackInfo ci, boolean bl, int j, int k, String string) {
+ if (NotEnoughUpdates.INSTANCE.config.misc.textFieldTweaksEnabled) {
+ addToStack(string);
+ }
+ }
+
+ @Inject(method = "textboxKeyTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiScreen;isKeyComboCtrlA(I)Z"), cancellable = true)
+ public void textboxKeyTyped_stringStack(char c, int i, CallbackInfoReturnable<Boolean> cir) {
+ if (NotEnoughUpdates.INSTANCE.config.misc.textFieldTweaksEnabled) {
+ if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
+ if (currentStringStackIndex == -1 && stringStack.size() > 0) {
+ currentStringStackIndex = stringStack.size() - 1;
+ }
+
+ if (Keyboard.isKeyDown(Keyboard.KEY_Y) || (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) && Keyboard.isKeyDown(
+ Keyboard.KEY_Z))) {
+ //go forward in action stack
+ if (currentStringStackIndex != stringStack.size() - 1) {
+ text = stringStack.get(currentStringStackIndex + 1);
+ currentStringStackIndex += 1;
+ setCursorPositionEnd();
+ }
+ cir.setReturnValue(true);
+ } else if (Keyboard.isKeyDown(Keyboard.KEY_Z)) {
+ //go back in action stack
+ if (!stringStack.isEmpty() && currentStringStackIndex > 0 && stringStack.get(currentStringStackIndex - 1) !=
+ null) {
+ text = stringStack.get(currentStringStackIndex - 1);
+ currentStringStackIndex -= 1;
+ setCursorPositionEnd();
+ }
+ cir.setReturnValue(true);
+ }
+ }
+ }
+ }
+
+ @Inject(method = "setMaxStringLength", at = @At(value = "INVOKE", target = "Ljava/lang/String;length()I"))
+ public void setMaxStringLength_stringStack(int i, CallbackInfo ci) {
+ //will remove the possibility of creating a bug in the matrix (untested)
+ if (NotEnoughUpdates.INSTANCE.config.misc.textFieldTweaksEnabled) {
+ for (int j = 0; j < stringStack.size(); j++) {
+ String string = stringStack.get(j);
+ if (string.length() > i) {
+ stringStack.set(j, string.substring(0, j));
+ if (j < currentStringStackIndex) {
+ currentStringStackIndex -= 1;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java
index 34495ae4..86c4c5dd 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java
@@ -237,4 +237,12 @@ public class Misc {
@ConfigEditorBoolean
public boolean coopWarning = true;
+ @Expose
+ @ConfigOption(
+ name = "Enable text field tweaks",
+ desc = "Allows the use of ctrl + z, ctrl + y and ctrl + Lshift + z in text fields"
+ )
+ @ConfigEditorBoolean
+ public boolean textFieldTweaksEnabled = true;
+
}