Skip to content

Commit

Permalink
input draft
Browse files Browse the repository at this point in the history
  • Loading branch information
RedthMC committed Jan 4, 2024
1 parent f2470e4 commit dcecf15
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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"
Expand All @@ -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"))
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/org/polyfrost/chatting/chat/DraftHooks.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.polyfrost.chatting.chat

object DraftHooks {
var draft = ""
fun resetDraft() {
draft = ""
}
}
16 changes: 15 additions & 1 deletion src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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`() }
Expand Down

0 comments on commit dcecf15

Please sign in to comment.