33import cc .polyfrost .oneconfig .libs .universal .UDesktop ;
44import org .polyfrost .chatting .chat .*;
55import org .polyfrost .chatting .config .ChattingConfig ;
6+ import org .polyfrost .chatting .gui .components .CleanButton ;
67import org .polyfrost .chatting .gui .components .ClearButton ;
78import org .polyfrost .chatting .gui .components .ScreenshotButton ;
89import org .polyfrost .chatting .gui .components .SearchButton ;
910import org .polyfrost .chatting .hook .ChatLineHook ;
11+ import org .polyfrost .chatting .hook .GuiChatHook ;
1012import org .polyfrost .chatting .hook .GuiNewChatHook ;
1113import com .google .common .collect .Lists ;
1214import net .minecraft .client .Minecraft ;
3335import java .util .List ;
3436
3537@ Mixin (GuiChat .class )
36- public abstract class GuiChatMixin extends GuiScreen {
38+ public abstract class GuiChatMixin extends GuiScreen implements GuiChatHook {
3739
3840 /**
3941 * Gets the modifier key name depending on the operating system
@@ -55,20 +57,12 @@ public abstract class GuiChatMixin extends GuiScreen {
5557 "\u00A7 b\u00A7 l" + chatting$getModifierKey () + "\u00A7 r \u00A7 8- \u00A7 7Formatting Codes" );
5658
5759 private SearchButton searchButton ;
60+ private ScreenshotButton screenshotButton ;
61+ private ClearButton clearButton ;
5862
5963 @ Inject (method = "initGui" , at = @ At ("TAIL" ))
6064 private void init (CallbackInfo ci ) {
61- if (ChattingConfig .INSTANCE .getChatSearch ()) {
62- searchButton = new SearchButton ();
63- buttonList .add (searchButton );
64- }
65- buttonList .add (new ScreenshotButton ());
66- buttonList .add (new ClearButton ());
67- if (ChattingConfig .INSTANCE .getChatTabs ()) {
68- for (ChatTab chatTab : ChatTabs .INSTANCE .getTabs ()) {
69- buttonList .add (chatTab .getButton ());
70- }
71- }
65+ chatting$initButtons ();
7266 }
7367
7468 @ Inject (method = "updateScreen" , at = @ At ("HEAD" ))
@@ -93,12 +87,14 @@ private void keyTyped(char typedChar, int keyCode, CallbackInfo ci) {
9387
9488 @ Inject (method = "drawScreen" , at = @ At ("HEAD" ))
9589 private void onDrawScreen (int mouseX , int mouseY , float partialTicks , CallbackInfo ci ) {
96- GuiNewChatHook hook = ((GuiNewChatHook ) Minecraft .getMinecraft ().ingameGUI .getChatGUI ());
97- float f = mc .ingameGUI .getChatGUI ().getChatScale ();
98- int x = MathHelper .floor_float ((float ) mouseX / f );
99- if (hook .isHovering () && (hook .getRight () + ModCompatHooks .getXOffset () + 3 ) <= x && (hook .getRight () + ModCompatHooks .getXOffset ()) + 13 > x ) {
100- GuiUtils .drawHoveringText (COPY_TOOLTIP , mouseX , mouseY , width , height , -1 , fontRendererObj );
101- GlStateManager .disableLighting ();
90+ if (ChattingConfig .INSTANCE .getChatCopy ()) {
91+ GuiNewChatHook hook = ((GuiNewChatHook ) Minecraft .getMinecraft ().ingameGUI .getChatGUI ());
92+ float f = mc .ingameGUI .getChatGUI ().getChatScale ();
93+ int x = MathHelper .floor_float ((float ) mouseX / f );
94+ if (hook .chatting$isHovering () && (hook .chatting$getRight () + ModCompatHooks .getXOffset () + 3 ) <= x && (hook .chatting$getRight () + ModCompatHooks .getXOffset ()) + 13 > x ) {
95+ GuiUtils .drawHoveringText (COPY_TOOLTIP , mouseX , mouseY , width , height , -1 , fontRendererObj );
96+ GlStateManager .disableLighting ();
97+ }
10298 }
10399 }
104100
@@ -117,23 +113,22 @@ private void mouseClicked(int mouseX, int mouseY, int mouseButton, CallbackInfo
117113 GuiNewChatHook hook = ((GuiNewChatHook ) Minecraft .getMinecraft ().ingameGUI .getChatGUI ());
118114 float f = mc .ingameGUI .getChatGUI ().getChatScale ();
119115 int x = MathHelper .floor_float ((float ) mouseX / f );
120- if (hook .isHovering ()) {
121- if ((( hook .getRight () + ModCompatHooks .getXOffset () + 3 ) <= x && (hook .getRight () + ModCompatHooks .getXOffset ()) + 13 > x ) || (mouseButton == 1 && ChattingConfig .INSTANCE .getRightClickCopy ())) {
122- Transferable message = hook .getChattingChatComponent (Mouse .getY ());
116+ if (hook .chatting$ isHovering ()) {
117+ if (ChattingConfig . INSTANCE . getChatCopy () && ((( hook .chatting$ getRight () + ModCompatHooks .getXOffset () + 3 ) <= x && (hook .chatting$ getRight () + ModCompatHooks .getXOffset ()) + 13 > x ) || (mouseButton == 1 && ChattingConfig .INSTANCE .getRightClickCopy () ))) {
118+ Transferable message = hook .chatting$ getChattingChatComponent (Mouse .getY ());
123119 if (message == null ) return ;
124120 try {
125121 Toolkit .getDefaultToolkit ().getSystemClipboard ().setContents (message , null );
126122 } catch (Exception e ) {
127123 e .printStackTrace ();
128124 }
129- } else if (( hook .getRight () + ModCompatHooks .getXOffset () + 13 ) <= x && (hook .getRight () + ModCompatHooks .getXOffset ()) + 23 > x ) {
130- ChatLine chatLine = hook .getHoveredLine (Mouse .getY ());
125+ } else if (ChattingConfig . INSTANCE . getChatDelete () && (( hook .chatting$ getRight () + ModCompatHooks .getXOffset () + 13 ) <= x && (hook .chatting$ getRight () + ModCompatHooks .getXOffset ()) + 23 > x ) ) {
126+ ChatLine chatLine = hook .chatting$ getHoveredLine (Mouse .getY ());
131127 if (chatLine == null ) return ;
132- ModCompatHooks .getDrawnChatLines ().removeIf (line -> ((ChatLineHook ) line ).getUniqueId () == ((ChatLineHook ) chatLine ).getUniqueId ());
133- ModCompatHooks .getChatLines ().removeIf (line -> ((ChatLineHook ) line ).getUniqueId () == ((ChatLineHook ) chatLine ).getUniqueId ());
128+ ModCompatHooks .getDrawnChatLines ().removeIf (line -> ((ChatLineHook ) line ).chatting$ getUniqueId () == ((ChatLineHook ) chatLine ).chatting$ getUniqueId ());
129+ ModCompatHooks .getChatLines ().removeIf (line -> ((ChatLineHook ) line ).chatting$ getUniqueId () == ((ChatLineHook ) chatLine ).chatting$ getUniqueId ());
134130 }
135131 }
136-
137132 }
138133
139134 @ ModifyArg (method = "keyTyped" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/gui/GuiChat;sendChatMessage(Ljava/lang/String;)V" ), index = 0 )
@@ -150,4 +145,31 @@ private String modifySentMessage(String original) {
150145 private void handleMouseInput (CallbackInfo ci ) {
151146 ChatScrollingHook .INSTANCE .setShouldSmooth (true );
152147 }
148+
149+ @ Unique
150+ private void chatting$initButtons () {
151+ searchButton = new SearchButton ();
152+ if (ChattingConfig .INSTANCE .getChatSearch ()) {
153+ buttonList .add (searchButton );
154+ }
155+ screenshotButton = new ScreenshotButton ();
156+ if (ChattingConfig .INSTANCE .getChatScreenshot ()) {
157+ buttonList .add (screenshotButton );
158+ }
159+ clearButton = new ClearButton ();
160+ if (ChattingConfig .INSTANCE .getChatDeleteHistory ()) {
161+ buttonList .add (clearButton );
162+ }
163+ if (ChattingConfig .INSTANCE .getChatTabs ()) {
164+ for (ChatTab chatTab : ChatTabs .INSTANCE .getTabs ()) {
165+ buttonList .add (chatTab .getButton ());
166+ }
167+ }
168+ }
169+
170+ @ Override
171+ public void chatting$triggerButtonReset () {
172+ buttonList .removeIf (button -> button instanceof CleanButton );
173+ chatting$initButtons ();
174+ }
153175}
0 commit comments