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/skyhanni/features/misc | |
| 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/skyhanni/features/misc')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/BetterSignEditing.kt | 75 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt | 29 |
2 files changed, 75 insertions, 29 deletions
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 |
