From dcecf15229464e10ac2b5ad558cd282df8f3217a Mon Sep 17 00:00:00 2001 From: Redth Date: Thu, 4 Jan 2024 11:41:27 +0800 Subject: [PATCH] input draft --- .../chatting/mixin/GuiChatMixin.java | 22 ++++++++++++++++++- .../org/polyfrost/chatting/chat/DraftHooks.kt | 8 +++++++ .../chatting/config/ChattingConfig.kt | 16 +++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/org/polyfrost/chatting/chat/DraftHooks.kt diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java index 6052817..e60436d 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java @@ -1,6 +1,7 @@ package org.polyfrost.chatting.mixin; import cc.polyfrost.oneconfig.libs.universal.UDesktop; +import net.minecraft.client.gui.GuiTextField; import org.polyfrost.chatting.chat.*; import org.polyfrost.chatting.config.ChattingConfig; import org.polyfrost.chatting.gui.components.CleanButton; @@ -24,6 +25,7 @@ import org.polyfrost.chatting.chat.ChatShortcuts; import org.polyfrost.chatting.utils.ModCompatHooks; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -36,7 +38,7 @@ @Mixin(GuiChat.class) public abstract class GuiChatMixin extends GuiScreen implements GuiChatHook { - + @Shadow protected GuiTextField inputField; /** * Gets the modifier key name depending on the operating system * @return "OPTION" if macOS, otherwise, "ALT" @@ -63,6 +65,9 @@ public abstract class GuiChatMixin extends GuiScreen implements GuiChatHook { @Inject(method = "initGui", at = @At("TAIL")) private void init(CallbackInfo ci) { chatting$initButtons(); + if (ChattingConfig.INSTANCE.getInputFieldDraft()) { + inputField.setText(DraftHooks.INSTANCE.getDraft()); + } } @Inject(method = "updateScreen", at = @At("HEAD")) @@ -141,6 +146,21 @@ private String modifySentMessage(String original) { return original; } + @Inject(method = "keyTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;sendChatMessage(Ljava/lang/String;)V")) + private void clearDraft(CallbackInfo ci) { + if (ChattingConfig.INSTANCE.getInputFieldDraft()) { + inputField.setText(""); + } + } + + @Inject(method = "onGuiClosed", at = @At("HEAD")) + private void saveDraft(CallbackInfo ci) { + if (ChattingConfig.INSTANCE.getInputFieldDraft()) { + DraftHooks.INSTANCE.setDraft(inputField.getText()); + } + } + + @Inject(method = "handleMouseInput", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;scroll(I)V")) private void handleMouseInput(CallbackInfo ci) { ChatScrollingHook.INSTANCE.setShouldSmooth(true); diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/DraftHooks.kt b/src/main/kotlin/org/polyfrost/chatting/chat/DraftHooks.kt new file mode 100644 index 0000000..8e08bb1 --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/chat/DraftHooks.kt @@ -0,0 +1,8 @@ +package org.polyfrost.chatting.chat + +object DraftHooks { + var draft = "" + fun resetDraft() { + draft = "" + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt b/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt index 75272ae..3b2a266 100644 --- a/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt +++ b/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt @@ -9,10 +9,12 @@ import cc.polyfrost.oneconfig.config.data.ModType import cc.polyfrost.oneconfig.config.migration.VigilanceMigrator import cc.polyfrost.oneconfig.libs.universal.UMinecraft import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils +import club.sk1er.patcher.config.PatcherConfig import org.polyfrost.chatting.Chatting import org.polyfrost.chatting.chat.ChatShortcuts import org.polyfrost.chatting.chat.ChatTab import org.polyfrost.chatting.chat.ChatTabs +import org.polyfrost.chatting.chat.DraftHooks import org.polyfrost.chatting.gui.components.TabButton import org.polyfrost.chatting.hook.ChatLineHook import org.polyfrost.chatting.hook.GuiChatHook @@ -64,6 +66,12 @@ object ChattingConfig : Config( ) var informForAlternatives = true + @Switch( + name = "Input Field Draft", category = "General", + description = "Drafts the text you wrote in the input field after closing the chat and back it up when opening the chat again." + ) + var inputFieldDraft = true + @Switch( name = "Smooth Chat Messages", category = "Animations", subcategory = "Messages", @@ -295,7 +303,13 @@ object ChattingConfig : Config( addDependency("scrollingSpeed", "smoothScrolling") addDependency("messageSpeed", "smoothChat") addDependency("smoothChat", "BetterChat Smooth Chat") { - return@addDependency !ModCompatHooks.betterChatSmoothMessages + !ModCompatHooks.betterChatSmoothMessages + } + addDependency("inputBoxBackgroundColor", "Patcher's Transparent Chat Input Field. Please turn it off to use this feature.") { + !Chatting.isPatcher || !PatcherConfig.transparentChatInputField + } + addListener("inputFieldDraft") { + DraftHooks.resetDraft() } addListener("hideChatHeadOnConsecutiveMessages") { ChatLineHook.`chatting$chatLines`.map { it.get() as ChatLineHook? }.forEach { it?.`chatting$updatePlayerInfo`() }