Skip to content

Commit c028987

Browse files
committed
Add toggles for all chatting buttons
Fix transparency issues with chat fading
1 parent 5acee0e commit c028987

File tree

14 files changed

+239
-114
lines changed

14 files changed

+239
-114
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod_name = Chatting
22
mod_id = chatting
3-
mod_version = 1.5.0
3+
mod_version = 1.5.1
44
mod_archives_name = Chatting
55

66
# Gradle Configuration -- DO NOT TOUCH THESE VALUES.

src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import java.util.HashSet;
88

99
public interface ChatLineHook {
10-
HashSet<WeakReference<ChatLine>> chatLines = new HashSet<>();
11-
boolean hasDetected();
12-
NetworkPlayerInfo getPlayerInfo();
10+
HashSet<WeakReference<ChatLine>> chatting$chatLines = new HashSet<>();
11+
boolean chatting$hasDetected();
12+
NetworkPlayerInfo chatting$getPlayerInfo();
1313

14-
void updatePlayerInfo();
14+
void chatting$updatePlayerInfo();
1515

16-
long getUniqueId();
16+
long chatting$getUniqueId();
1717
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.polyfrost.chatting.hook;
2+
3+
public interface GuiChatHook {
4+
void chatting$triggerButtonReset();
5+
}

src/main/java/org/polyfrost/chatting/hook/GuiNewChatHook.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
import java.awt.datatransfer.Transferable;
66

77
public interface GuiNewChatHook {
8-
int getRight();
8+
int chatting$getRight();
99

10-
boolean isHovering();
10+
boolean chatting$isHovering();
1111

12-
ChatLine getHoveredLine(int mouseY);
12+
ChatLine chatting$getHoveredLine(int mouseY);
1313

14-
Transferable getChattingChatComponent(int mouseY);
14+
Transferable chatting$getChattingChatComponent(int mouseY);
1515

16-
default ChatLine getFullMessage(ChatLine line) {
16+
default ChatLine chatting$getFullMessage(ChatLine line) {
1717
throw new AssertionError("getFullMessage not overridden on GuiNewChat");
1818
}
1919

20-
int getTextOpacity();
20+
int chatting$getTextOpacity();
2121
}

src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class ChatLineMixin implements ChatLineHook {
3636
private void onInit(int i, IChatComponent iChatComponent, int j, CallbackInfo ci) {
3737
lastUniqueId++;
3838
uniqueId = lastUniqueId;
39-
chatLines.add(new WeakReference<>((ChatLine) (Object) this));
39+
chatting$chatLines.add(new WeakReference<>((ChatLine) (Object) this));
4040
NetHandlerPlayClient netHandler = Minecraft.getMinecraft().getNetHandler();
4141
if (netHandler == null) return;
4242
Map<String, NetworkPlayerInfo> nicknameCache = new HashMap<>();
@@ -89,17 +89,17 @@ private static NetworkPlayerInfo getPlayerFromNickname(String word, NetHandlerPl
8989
}
9090

9191
@Override
92-
public boolean hasDetected() {
92+
public boolean chatting$hasDetected() {
9393
return detected;
9494
}
9595

9696
@Override
97-
public NetworkPlayerInfo getPlayerInfo() {
97+
public NetworkPlayerInfo chatting$getPlayerInfo() {
9898
return playerInfo;
9999
}
100100

101101
@Override
102-
public void updatePlayerInfo() {
102+
public void chatting$updatePlayerInfo() {
103103
if (ChattingConfig.INSTANCE.getHideChatHeadOnConsecutiveMessages() && !first) {
104104
playerInfo = null;
105105
} else {
@@ -108,7 +108,7 @@ public void updatePlayerInfo() {
108108
}
109109

110110
@Override
111-
public long getUniqueId() {
111+
public long chatting$getUniqueId() {
112112
return uniqueId;
113113
}
114114
}

src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import cc.polyfrost.oneconfig.libs.universal.UDesktop;
44
import org.polyfrost.chatting.chat.*;
55
import org.polyfrost.chatting.config.ChattingConfig;
6+
import org.polyfrost.chatting.gui.components.CleanButton;
67
import org.polyfrost.chatting.gui.components.ClearButton;
78
import org.polyfrost.chatting.gui.components.ScreenshotButton;
89
import org.polyfrost.chatting.gui.components.SearchButton;
910
import org.polyfrost.chatting.hook.ChatLineHook;
11+
import org.polyfrost.chatting.hook.GuiChatHook;
1012
import org.polyfrost.chatting.hook.GuiNewChatHook;
1113
import com.google.common.collect.Lists;
1214
import net.minecraft.client.Minecraft;
@@ -33,7 +35,7 @@
3335
import 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
"\u00A7b\u00A7l"+ chatting$getModifierKey() + "\u00A7r \u00A78- \u00A77Formatting 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
}

src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMapMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void handleChatCleared(CallbackInfo ci) {
7272
}
7373

7474
@Override
75-
public ChatLine getFullMessage(ChatLine line) {
75+
public ChatLine chatting$getFullMessage(ChatLine line) {
7676
return drawnToFull.getOrDefault(line, null);
7777
}
7878
}

0 commit comments

Comments
 (0)