diff options
author | Obsidian <108832807+Obsidianninja11@users.noreply.github.com> | 2023-12-11 16:05:48 -0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-12 02:05:48 +0100 |
commit | 6cfe7aa0f56878c4729ca6e2479170e05260fae6 (patch) | |
tree | a0cbc3f072589bd8d0d72322f9e1ac592ee01773 /src/main/java/at/hannibal2 | |
parent | 411fde4bf782de1045d3339e04dabf912f50578d (diff) | |
download | skyhanni-6cfe7aa0f56878c4729ca6e2479170e05260fae6.tar.gz skyhanni-6cfe7aa0f56878c4729ca6e2479170e05260fae6.tar.bz2 skyhanni-6cfe7aa0f56878c4729ca6e2479170e05260fae6.zip |
Better sign editing (#751)
Changes ctrl+v in signs to better sign editing. #751
Diffstat (limited to 'src/main/java/at/hannibal2')
5 files changed, 82 insertions, 36 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 5b11e02cc..89061d433 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -233,7 +233,7 @@ import at.hannibal2.skyhanni.features.misc.MovementSpeedDisplay import at.hannibal2.skyhanni.features.misc.NonGodPotEffectDisplay import at.hannibal2.skyhanni.features.misc.ParticleHider import at.hannibal2.skyhanni.features.misc.PartyMemberOutlines -import at.hannibal2.skyhanni.features.misc.PasteIntoSigns +import at.hannibal2.skyhanni.features.misc.BetterSignEditing import at.hannibal2.skyhanni.features.misc.PatcherSendCoordinates import at.hannibal2.skyhanni.features.misc.PetCandyUsedDisplay import at.hannibal2.skyhanni.features.misc.PetExpTooltip @@ -553,7 +553,7 @@ class SkyHanniMod { loadModule(ComposterDisplay()) loadModule(GardenComposterInventoryFeatures()) loadModule(MinionCollectLogic()) - loadModule(PasteIntoSigns()) + loadModule(BetterSignEditing()) loadModule(PatcherSendCoordinates()) loadModule(EstimatedItemValue) loadModule(EstimatedWardrobePrice()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java index 47dcf1ed4..53a70019b 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java @@ -139,10 +139,10 @@ public class MiscConfig { public boolean hideFireOverlay = false; @Expose - @ConfigOption(name = "Paste Into Signs", desc = "Allows you to paste the clipboard into signs when you press Ctrl + V.") + @ConfigOption(name = "Better Sign Editing", desc = "Allows pasting (Ctrl+V), copying (Ctrl+C), and deleting whole words/lines (Ctrl+Backspace/Ctrl+Shift+Backspace) in signs.") @ConfigEditorBoolean @FeatureToggle - public boolean pasteIntoSigns = true; + public boolean betterSignEditing = true; @Expose @ConfigOption(name = "Movement Speed", desc = "Show the player movement speed in blocks per second.") diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/BetterSignEditing.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/BetterSignEditing.kt new file mode 100644 index 000000000..1fffb43eb --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/BetterSignEditing.kt @@ -0,0 +1,75 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.mixins.transformers.AccessorGuiEditSign +import at.hannibal2.skyhanni.utils.ClipboardUtils +import at.hannibal2.skyhanni.utils.KeyboardManager +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.OSUtils +import kotlinx.coroutines.launch +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.GuiScreen +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.input.Keyboard + +class BetterSignEditing { + private var pasteLastClicked = false + private var copyLastClicked = false + private var deleteWordLastClicked = false + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!LorenzUtils.onHypixel) return + if (!SkyHanniMod.feature.misc.betterSignEditing) return + + val gui = Minecraft.getMinecraft().currentScreen + checkPaste() + checkCopying(gui) + checkDeleting(gui) + } + + private fun checkDeleting(gui: GuiScreen?) { + val deleteWordClicked = Keyboard.KEY_BACK.isKeyHeld() && KeyboardManager.isModifierKeyDown() + if (!deleteWordLastClicked && deleteWordClicked && gui is AccessorGuiEditSign) { + SkyHanniMod.coroutineScope.launch { + val newLine = if (KeyboardManager.isShiftKeyDown()) "" else { + val currentLine = gui.tileSign.signText[gui.editLine].unformattedText + val lastSpaceIndex = currentLine.lastIndexOf(' ') + if (lastSpaceIndex >= 0) currentLine.substring(0, lastSpaceIndex + 1) else "" + } + LorenzUtils.setTextIntoSign(newLine, gui.editLine) + } + } + deleteWordLastClicked = deleteWordClicked + } + + private fun checkCopying(gui: GuiScreen?) { + val copyClicked = KeyboardManager.isCopyingKeysDown() + if (!copyLastClicked && copyClicked && gui is AccessorGuiEditSign) { + SkyHanniMod.coroutineScope.launch { + ClipboardUtils.copyToClipboard(gui.tileSign.signText[gui.editLine].unformattedText) + } + } + copyLastClicked = copyClicked + } + + private fun checkPaste() { + val pasteClicked = KeyboardManager.isPastingKeysDown() + if (!pasteLastClicked && pasteClicked) { + SkyHanniMod.coroutineScope.launch { + OSUtils.readFromClipboard()?.let { + LorenzUtils.addTextIntoSign(it) + } + } + } + pasteLastClicked = pasteClicked + } + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(16, "misc.pasteIntoSigns", "misc.betterSignEditing") + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt deleted file mode 100644 index 5bedd57cc..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt +++ /dev/null @@ -1,29 +0,0 @@ -package at.hannibal2.skyhanni.features.misc - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.LorenzTickEvent -import at.hannibal2.skyhanni.utils.KeyboardManager -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.OSUtils -import kotlinx.coroutines.launch -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class PasteIntoSigns { - private var lastClicked = false - - @SubscribeEvent - fun onTick(event: LorenzTickEvent) { - if (!LorenzUtils.onHypixel) return - if (!SkyHanniMod.feature.misc.pasteIntoSigns) return - - val currentlyClicked = KeyboardManager.isPastingKeysDown() - if (!lastClicked && currentlyClicked) { - SkyHanniMod.coroutineScope.launch { - OSUtils.readFromClipboard()?.let { - LorenzUtils.addTextIntoSign(it.take(15)) - } - } - } - lastClicked = currentlyClicked - } -}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 190d093a3..a216b88e1 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -287,10 +287,10 @@ object LorenzUtils { } } - fun setTextIntoSign(text: String) { + fun setTextIntoSign(text: String, line: Int = 0) { val gui = Minecraft.getMinecraft().currentScreen if (gui !is AccessorGuiEditSign) return - gui.tileSign.signText[0] = ChatComponentText(text) + gui.tileSign.signText[line] = ChatComponentText(text) } fun addTextIntoSign(addedText: String) { @@ -299,7 +299,7 @@ object LorenzUtils { val lines = gui.tileSign.signText val index = gui.editLine val text = lines[index].unformattedText + addedText - lines[index] = ChatComponentText(text.capAtMinecraftLength(90)) + lines[index] = ChatComponentText(text.capAtMinecraftLength(91)) } /** |