Skip to content

Commit

Permalink
Add toggles for all chatting buttons
Browse files Browse the repository at this point in the history
Fix transparency issues with chat fading
  • Loading branch information
Wyvest committed Dec 17, 2023
1 parent 5acee0e commit c028987
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 114 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod_name = Chatting
mod_id = chatting
mod_version = 1.5.0
mod_version = 1.5.1
mod_archives_name = Chatting

# Gradle Configuration -- DO NOT TOUCH THESE VALUES.
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import java.util.HashSet;

public interface ChatLineHook {
HashSet<WeakReference<ChatLine>> chatLines = new HashSet<>();
boolean hasDetected();
NetworkPlayerInfo getPlayerInfo();
HashSet<WeakReference<ChatLine>> chatting$chatLines = new HashSet<>();
boolean chatting$hasDetected();
NetworkPlayerInfo chatting$getPlayerInfo();

void updatePlayerInfo();
void chatting$updatePlayerInfo();

long getUniqueId();
long chatting$getUniqueId();
}
5 changes: 5 additions & 0 deletions src/main/java/org/polyfrost/chatting/hook/GuiChatHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.polyfrost.chatting.hook;

public interface GuiChatHook {
void chatting$triggerButtonReset();
}
12 changes: 6 additions & 6 deletions src/main/java/org/polyfrost/chatting/hook/GuiNewChatHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import java.awt.datatransfer.Transferable;

public interface GuiNewChatHook {
int getRight();
int chatting$getRight();

boolean isHovering();
boolean chatting$isHovering();

ChatLine getHoveredLine(int mouseY);
ChatLine chatting$getHoveredLine(int mouseY);

Transferable getChattingChatComponent(int mouseY);
Transferable chatting$getChattingChatComponent(int mouseY);

default ChatLine getFullMessage(ChatLine line) {
default ChatLine chatting$getFullMessage(ChatLine line) {
throw new AssertionError("getFullMessage not overridden on GuiNewChat");
}

int getTextOpacity();
int chatting$getTextOpacity();
}
10 changes: 5 additions & 5 deletions src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ChatLineMixin implements ChatLineHook {
private void onInit(int i, IChatComponent iChatComponent, int j, CallbackInfo ci) {
lastUniqueId++;
uniqueId = lastUniqueId;
chatLines.add(new WeakReference<>((ChatLine) (Object) this));
chatting$chatLines.add(new WeakReference<>((ChatLine) (Object) this));
NetHandlerPlayClient netHandler = Minecraft.getMinecraft().getNetHandler();
if (netHandler == null) return;
Map<String, NetworkPlayerInfo> nicknameCache = new HashMap<>();
Expand Down Expand Up @@ -89,17 +89,17 @@ private static NetworkPlayerInfo getPlayerFromNickname(String word, NetHandlerPl
}

@Override
public boolean hasDetected() {
public boolean chatting$hasDetected() {
return detected;
}

@Override
public NetworkPlayerInfo getPlayerInfo() {
public NetworkPlayerInfo chatting$getPlayerInfo() {
return playerInfo;
}

@Override
public void updatePlayerInfo() {
public void chatting$updatePlayerInfo() {
if (ChattingConfig.INSTANCE.getHideChatHeadOnConsecutiveMessages() && !first) {
playerInfo = null;
} else {
Expand All @@ -108,7 +108,7 @@ public void updatePlayerInfo() {
}

@Override
public long getUniqueId() {
public long chatting$getUniqueId() {
return uniqueId;
}
}
74 changes: 48 additions & 26 deletions src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import cc.polyfrost.oneconfig.libs.universal.UDesktop;
import org.polyfrost.chatting.chat.*;
import org.polyfrost.chatting.config.ChattingConfig;
import org.polyfrost.chatting.gui.components.CleanButton;
import org.polyfrost.chatting.gui.components.ClearButton;
import org.polyfrost.chatting.gui.components.ScreenshotButton;
import org.polyfrost.chatting.gui.components.SearchButton;
import org.polyfrost.chatting.hook.ChatLineHook;
import org.polyfrost.chatting.hook.GuiChatHook;
import org.polyfrost.chatting.hook.GuiNewChatHook;
import com.google.common.collect.Lists;
import net.minecraft.client.Minecraft;
Expand All @@ -33,7 +35,7 @@
import java.util.List;

@Mixin(GuiChat.class)
public abstract class GuiChatMixin extends GuiScreen {
public abstract class GuiChatMixin extends GuiScreen implements GuiChatHook {

/**
* Gets the modifier key name depending on the operating system
Expand All @@ -55,20 +57,12 @@ public abstract class GuiChatMixin extends GuiScreen {
"\u00A7b\u00A7l"+ chatting$getModifierKey() + "\u00A7r \u00A78- \u00A77Formatting Codes");

private SearchButton searchButton;
private ScreenshotButton screenshotButton;
private ClearButton clearButton;

@Inject(method = "initGui", at = @At("TAIL"))
private void init(CallbackInfo ci) {
if (ChattingConfig.INSTANCE.getChatSearch()) {
searchButton = new SearchButton();
buttonList.add(searchButton);
}
buttonList.add(new ScreenshotButton());
buttonList.add(new ClearButton());
if (ChattingConfig.INSTANCE.getChatTabs()) {
for (ChatTab chatTab : ChatTabs.INSTANCE.getTabs()) {
buttonList.add(chatTab.getButton());
}
}
chatting$initButtons();
}

@Inject(method = "updateScreen", at = @At("HEAD"))
Expand All @@ -93,12 +87,14 @@ private void keyTyped(char typedChar, int keyCode, CallbackInfo ci) {

@Inject(method = "drawScreen", at = @At("HEAD"))
private void onDrawScreen(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) {
GuiNewChatHook hook = ((GuiNewChatHook) Minecraft.getMinecraft().ingameGUI.getChatGUI());
float f = mc.ingameGUI.getChatGUI().getChatScale();
int x = MathHelper.floor_float((float) mouseX / f);
if (hook.isHovering() && (hook.getRight() + ModCompatHooks.getXOffset() + 3) <= x && (hook.getRight() + ModCompatHooks.getXOffset()) + 13 > x) {
GuiUtils.drawHoveringText(COPY_TOOLTIP, mouseX, mouseY, width, height, -1, fontRendererObj);
GlStateManager.disableLighting();
if (ChattingConfig.INSTANCE.getChatCopy()) {
GuiNewChatHook hook = ((GuiNewChatHook) Minecraft.getMinecraft().ingameGUI.getChatGUI());
float f = mc.ingameGUI.getChatGUI().getChatScale();
int x = MathHelper.floor_float((float) mouseX / f);
if (hook.chatting$isHovering() && (hook.chatting$getRight() + ModCompatHooks.getXOffset() + 3) <= x && (hook.chatting$getRight() + ModCompatHooks.getXOffset()) + 13 > x) {
GuiUtils.drawHoveringText(COPY_TOOLTIP, mouseX, mouseY, width, height, -1, fontRendererObj);
GlStateManager.disableLighting();
}
}
}

Expand All @@ -117,23 +113,22 @@ private void mouseClicked(int mouseX, int mouseY, int mouseButton, CallbackInfo
GuiNewChatHook hook = ((GuiNewChatHook) Minecraft.getMinecraft().ingameGUI.getChatGUI());
float f = mc.ingameGUI.getChatGUI().getChatScale();
int x = MathHelper.floor_float((float) mouseX / f);
if (hook.isHovering()) {
if (((hook.getRight() + ModCompatHooks.getXOffset() + 3) <= x && (hook.getRight() + ModCompatHooks.getXOffset()) + 13 > x) || (mouseButton == 1 && ChattingConfig.INSTANCE.getRightClickCopy())) {
Transferable message = hook.getChattingChatComponent(Mouse.getY());
if (hook.chatting$isHovering()) {
if (ChattingConfig.INSTANCE.getChatCopy() && (((hook.chatting$getRight() + ModCompatHooks.getXOffset() + 3) <= x && (hook.chatting$getRight() + ModCompatHooks.getXOffset()) + 13 > x) || (mouseButton == 1 && ChattingConfig.INSTANCE.getRightClickCopy()))) {
Transferable message = hook.chatting$getChattingChatComponent(Mouse.getY());
if (message == null) return;
try {
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(message, null);
} catch (Exception e) {
e.printStackTrace();
}
} else if ((hook.getRight() + ModCompatHooks.getXOffset() + 13) <= x && (hook.getRight() + ModCompatHooks.getXOffset()) + 23 > x) {
ChatLine chatLine = hook.getHoveredLine(Mouse.getY());
} else if (ChattingConfig.INSTANCE.getChatDelete() && ((hook.chatting$getRight() + ModCompatHooks.getXOffset() + 13) <= x && (hook.chatting$getRight() + ModCompatHooks.getXOffset()) + 23 > x)) {
ChatLine chatLine = hook.chatting$getHoveredLine(Mouse.getY());
if (chatLine == null) return;
ModCompatHooks.getDrawnChatLines().removeIf(line -> ((ChatLineHook) line).getUniqueId() == ((ChatLineHook) chatLine).getUniqueId());
ModCompatHooks.getChatLines().removeIf(line -> ((ChatLineHook) line).getUniqueId() == ((ChatLineHook) chatLine).getUniqueId());
ModCompatHooks.getDrawnChatLines().removeIf(line -> ((ChatLineHook) line).chatting$getUniqueId() == ((ChatLineHook) chatLine).chatting$getUniqueId());
ModCompatHooks.getChatLines().removeIf(line -> ((ChatLineHook) line).chatting$getUniqueId() == ((ChatLineHook) chatLine).chatting$getUniqueId());
}
}

}

@ModifyArg(method = "keyTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;sendChatMessage(Ljava/lang/String;)V"), index = 0)
Expand All @@ -150,4 +145,31 @@ private String modifySentMessage(String original) {
private void handleMouseInput(CallbackInfo ci) {
ChatScrollingHook.INSTANCE.setShouldSmooth(true);
}

@Unique
private void chatting$initButtons() {
searchButton = new SearchButton();
if (ChattingConfig.INSTANCE.getChatSearch()) {
buttonList.add(searchButton);
}
screenshotButton = new ScreenshotButton();
if (ChattingConfig.INSTANCE.getChatScreenshot()) {
buttonList.add(screenshotButton);
}
clearButton = new ClearButton();
if (ChattingConfig.INSTANCE.getChatDeleteHistory()) {
buttonList.add(clearButton);
}
if (ChattingConfig.INSTANCE.getChatTabs()) {
for (ChatTab chatTab : ChatTabs.INSTANCE.getTabs()) {
buttonList.add(chatTab.getButton());
}
}
}

@Override
public void chatting$triggerButtonReset() {
buttonList.removeIf(button -> button instanceof CleanButton);
chatting$initButtons();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void handleChatCleared(CallbackInfo ci) {
}

@Override
public ChatLine getFullMessage(ChatLine line) {
public ChatLine chatting$getFullMessage(ChatLine line) {
return drawnToFull.getOrDefault(line, null);
}
}
Loading

0 comments on commit c028987

Please sign in to comment.