diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2023-01-14 12:13:13 -0500 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2023-01-14 12:13:13 -0500 |
commit | 1b3670de60500c491e5c61b0d304bcde7e30080f (patch) | |
tree | 9657ad419ac41545ea73e11cfea63ff90463f114 /src/main/java/cc/woverflow | |
parent | f80dad6f297a60f23ca3066742c2df78e3b6fc83 (diff) | |
download | Chatting-1b3670de60500c491e5c61b0d304bcde7e30080f.tar.gz Chatting-1b3670de60500c491e5c61b0d304bcde7e30080f.tar.bz2 Chatting-1b3670de60500c491e5c61b0d304bcde7e30080f.zip |
various new features
- right click to copy chat message
- tooltip text render type
- delete button for individual chat lines
- copying chat messages now always shows a notification output
Diffstat (limited to 'src/main/java/cc/woverflow')
7 files changed, 102 insertions, 43 deletions
diff --git a/src/main/java/cc/woverflow/chatting/hook/ChatLineHook.java b/src/main/java/cc/woverflow/chatting/hook/ChatLineHook.java index fb10225..9460e0c 100644 --- a/src/main/java/cc/woverflow/chatting/hook/ChatLineHook.java +++ b/src/main/java/cc/woverflow/chatting/hook/ChatLineHook.java @@ -12,4 +12,6 @@ public interface ChatLineHook { NetworkPlayerInfo getPlayerInfo(); void updatePlayerInfo(); + + long getUniqueId(); } diff --git a/src/main/java/cc/woverflow/chatting/hook/GuiNewChatHook.java b/src/main/java/cc/woverflow/chatting/hook/GuiNewChatHook.java index 51b19d4..d2ca6c1 100644 --- a/src/main/java/cc/woverflow/chatting/hook/GuiNewChatHook.java +++ b/src/main/java/cc/woverflow/chatting/hook/GuiNewChatHook.java @@ -7,7 +7,9 @@ import java.awt.datatransfer.Transferable; public interface GuiNewChatHook { int getRight(); - boolean shouldCopy(); + boolean isHovering(); + + ChatLine getHoveredLine(int mouseY); Transferable getChattingChatComponent(int mouseY); diff --git a/src/main/java/cc/woverflow/chatting/mixin/ChatLineMixin.java b/src/main/java/cc/woverflow/chatting/mixin/ChatLineMixin.java index ab052ae..beef37b 100644 --- a/src/main/java/cc/woverflow/chatting/mixin/ChatLineMixin.java +++ b/src/main/java/cc/woverflow/chatting/mixin/ChatLineMixin.java @@ -29,9 +29,13 @@ public class ChatLineMixin implements ChatLineHook { private NetworkPlayerInfo playerInfo; private NetworkPlayerInfo detectedPlayerInfo; private static NetworkPlayerInfo lastPlayerInfo; + private static long lastUniqueId = 0; + private long uniqueId = 0; @Inject(method = "<init>", at = @At("RETURN")) private void onInit(int i, IChatComponent iChatComponent, int j, CallbackInfo ci) { + lastUniqueId++; + uniqueId = lastUniqueId; chatLines.add(new WeakReference<>((ChatLine) (Object) this)); NetHandlerPlayClient netHandler = Minecraft.getMinecraft().getNetHandler(); if (netHandler == null) return; @@ -102,4 +106,9 @@ public class ChatLineMixin implements ChatLineHook { playerInfo = detectedPlayerInfo; } } + + @Override + public long getUniqueId() { + return uniqueId; + } } diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java b/src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java index 1774f82..a633a3d 100644 --- a/src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java +++ b/src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java @@ -8,10 +8,12 @@ import cc.woverflow.chatting.config.ChattingConfig; import cc.woverflow.chatting.gui.components.ClearButton; import cc.woverflow.chatting.gui.components.ScreenshotButton; import cc.woverflow.chatting.gui.components.SearchButton; +import cc.woverflow.chatting.hook.ChatLineHook; import cc.woverflow.chatting.hook.GuiNewChatHook; import cc.woverflow.chatting.utils.ModCompatHooks; import com.google.common.collect.Lists; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ChatLine; import net.minecraft.client.gui.GuiChat; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; @@ -85,7 +87,7 @@ public abstract class GuiChatMixin extends GuiScreen { GuiNewChatHook hook = ((GuiNewChatHook) Minecraft.getMinecraft().ingameGUI.getChatGUI()); float f = mc.ingameGUI.getChatGUI().getChatScale(); int x = MathHelper.floor_float((float) mouseX / f); - if (hook.shouldCopy() && (hook.getRight() + ModCompatHooks.getXOffset() + 3) <= x && (hook.getRight() + ModCompatHooks.getXOffset()) + 13 > x) { + 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(); } @@ -101,15 +103,23 @@ public abstract class GuiChatMixin extends GuiScreen { GuiNewChatHook hook = ((GuiNewChatHook) Minecraft.getMinecraft().ingameGUI.getChatGUI()); float f = mc.ingameGUI.getChatGUI().getChatScale(); int x = MathHelper.floor_float((float) mouseX / f); - if (hook.shouldCopy() && (hook.getRight() + ModCompatHooks.getXOffset() + 3) <= x && (hook.getRight() + ModCompatHooks.getXOffset()) + 13 > x) { - Transferable message = hook.getChattingChatComponent(Mouse.getY()); - if (message == null) return; - try { - Toolkit.getDefaultToolkit().getSystemClipboard().setContents(message, null); - } catch (Exception e) { - e.printStackTrace(); + 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 (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()); + if (chatLine == null) return; + ((GuiNewChatAccessor) Minecraft.getMinecraft().ingameGUI.getChatGUI()).getDrawnChatLines().removeIf(line -> ((ChatLineHook) line).getUniqueId() == ((ChatLineHook) chatLine).getUniqueId()); + ((GuiNewChatAccessor) Minecraft.getMinecraft().ingameGUI.getChatGUI()).getChatLines().removeIf(line -> ((ChatLineHook) line).getUniqueId() == ((ChatLineHook) chatLine).getUniqueId()); } } + } @ModifyArg(method = "keyTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;sendChatMessage(Ljava/lang/String;)V"), index = 0) diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatAccessor.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatAccessor.java index 8b81a50..d4fd524 100644 --- a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatAccessor.java +++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatAccessor.java @@ -13,5 +13,8 @@ public interface GuiNewChatAccessor { List<ChatLine> getDrawnChatLines(); @Accessor + List<ChatLine> getChatLines(); + + @Accessor int getScrollPos(); } diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java index e0a76d5..17106bc 100644 --- a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java +++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java @@ -1,20 +1,18 @@ package cc.woverflow.chatting.mixin; import cc.polyfrost.oneconfig.config.core.OneColor; -import cc.polyfrost.oneconfig.utils.color.ColorUtils; +import cc.polyfrost.oneconfig.libs.universal.UMouse; +import cc.polyfrost.oneconfig.utils.Notifications; import cc.woverflow.chatting.Chatting; import cc.woverflow.chatting.chat.ChatSearchingManager; import cc.woverflow.chatting.chat.ChatTabs; import cc.woverflow.chatting.config.ChattingConfig; import cc.woverflow.chatting.gui.components.CleanButton; -import cc.woverflow.chatting.hook.ChatLineHook; import cc.woverflow.chatting.hook.GuiNewChatHook; import cc.woverflow.chatting.utils.ModCompatHooks; import cc.woverflow.chatting.utils.RenderUtils; -import cc.polyfrost.oneconfig.libs.universal.UMouse; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.*; -import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; @@ -42,7 +40,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Unique private int chatting$right = 0; @Unique - private boolean chatting$shouldCopy; + private boolean chatting$isHovering; @Unique private boolean chatting$chatCheck; @Unique @@ -79,6 +77,8 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Unique private static final ResourceLocation COPY = new ResourceLocation("chatting:copy.png"); + @Unique + private static final ResourceLocation DELETE = new ResourceLocation("chatting:delete.png"); @Inject(method = "printChatMessageWithOptionalDeletion", at = @At("HEAD"), cancellable = true) private void handlePrintChatMessage(IChatComponent chatComponent, int chatLineId, CallbackInfo ci) { @@ -107,6 +107,14 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { */ + @Unique + private ChatLine chatting$drawingLine = null; + + @Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/ChatLine;getChatComponent()Lnet/minecraft/util/IChatComponent;"), locals = LocalCapture.CAPTURE_FAILSOFT) + private void captureChatLine(int updateCounter, CallbackInfo ci, int i, boolean bl, int j, int k, float f, float g, int l, int m, ChatLine chatLine, int n, double d, int o, int p, int q) { + chatting$drawingLine = chatLine; + } + @Inject(method = "drawChat", at = @At("HEAD")) private void checkScreenshotKeybind(int j2, CallbackInfo ci) { if (Chatting.INSTANCE.getKeybind().isPressed()) { @@ -138,21 +146,13 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { int right = args.get(2); int bottom = args.get(3); if (isInBounds(left, top, right, bottom, getChatScale())) { - chatting$shouldCopy = true; + chatting$isHovering = true; lineInBounds = true; args.set(4, changeChatBackgroundColor(ChattingConfig.INSTANCE.getHoveredChatBackgroundColor(), args.get(4))); } } } - @Unique - private ChatLine chatting$drawingLine = null; - - @Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/ChatLine;getChatComponent()Lnet/minecraft/util/IChatComponent;"), locals = LocalCapture.CAPTURE_FAILSOFT) - private void captureChatLine(int updateCounter, CallbackInfo ci, int i, boolean bl, int j, int k, float f, float g, int l, int m, ChatLine chatLine, int n, double d, int o, int p, int q) { - chatting$drawingLine = chatLine; - } - @ModifyArgs(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I")) private void drawChatBox(Args args) { if (mc.currentScreen instanceof GuiChat) { @@ -161,8 +161,8 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { int top = (int) ((float) args.get(2) - 1); int right = MathHelper.ceiling_float_int((float)getChatWidth() / f) + 4; int bottom = (int) ((float) args.get(2) + 8); - if ((chatting$shouldCopy && lineInBounds) || isInBounds(left, top, right, bottom, f)) { - chatting$shouldCopy = true; + if ((chatting$isHovering && lineInBounds) || isInBounds(left, top, right, bottom, f)) { + chatting$isHovering = true; drawCopyChatBox(right, top); } } @@ -174,7 +174,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { int mouseY = MathHelper.floor_double(UMouse.getScaledY()) - 27 + ModCompatHooks.getYOffset() - ModCompatHooks.getChatPosition(); mouseX = MathHelper.floor_float((float) mouseX / chatScale); mouseY = -(MathHelper.floor_float((float) mouseY / chatScale)); //WHY DO I NEED TO DO THIS - return mouseX >= (left + ModCompatHooks.getXOffset()) && mouseY < bottom && mouseX < (right + 11 + ModCompatHooks.getXOffset()) && mouseY >= top; + return mouseX >= (left + ModCompatHooks.getXOffset()) && mouseY < bottom && mouseX < (right + 23 + ModCompatHooks.getXOffset()) && mouseY >= top; } private int changeChatBackgroundColor(OneColor color, int alphaColor) { @@ -227,8 +227,8 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Inject(method = "drawChat", at = @At("RETURN")) private void checkStuff(int j2, CallbackInfo ci) { - if (!chatting$chatCheck && chatting$shouldCopy) { - chatting$shouldCopy = false; + if (!chatting$chatCheck && chatting$isHovering) { + chatting$isHovering = false; } } @@ -244,8 +244,8 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { } @Override - public boolean shouldCopy() { - return chatting$shouldCopy; + public boolean isHovering() { + return chatting$isHovering; } private void handleChatTabMessage(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { @@ -285,12 +285,21 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { drawRect(right + 1, top, right + 10, top + 9, (((right + ModCompatHooks.getXOffset() + 3) <= (UMouse.getScaledX() / mc.ingameGUI.getChatGUI().getChatScale()) && (right + ModCompatHooks.getXOffset()) + 13 > (UMouse.getScaledX() / mc.ingameGUI.getChatGUI().getChatScale())) ? CleanButton.Companion.getHoveredColor() : CleanButton.Companion.getColor())); GlStateManager.disableAlpha(); GlStateManager.disableRescaleNormal(); + mc.getTextureManager().bindTexture(DELETE); + GlStateManager.enableRescaleNormal(); + GlStateManager.enableAlpha(); + GlStateManager.alphaFunc(516, 0.1f); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(770, 771); + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); + Gui.drawModalRectWithCustomSizedTexture(right + 11, top, 0f, 0f, 9, 9, 9, 9); + drawRect(right + 11, top, right + 20, top + 9, (((right + ModCompatHooks.getXOffset() + 13) <= (UMouse.getScaledX() / mc.ingameGUI.getChatGUI().getChatScale()) && (right + ModCompatHooks.getXOffset()) + 23 > (UMouse.getScaledX() / mc.ingameGUI.getChatGUI().getChatScale())) ? CleanButton.Companion.getHoveredColor() : CleanButton.Companion.getColor())); GlStateManager.disableLighting(); GlStateManager.popMatrix(); } @Override - public Transferable getChattingChatComponent(int mouseY) { + public ChatLine getHoveredLine(int mouseY) { if (this.getChatOpen()) { ScaledResolution scaledresolution = new ScaledResolution(this.mc); int i = scaledresolution.getScaleFactor(); @@ -305,18 +314,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { int i1 = k / this.mc.fontRendererObj.FONT_HEIGHT + this.scrollPos; if (i1 >= 0 && i1 < this.drawnChatLines.size()) { - ChatLine subLine = this.drawnChatLines.get(i1); - ChatLine fullLine = this.getFullMessage(subLine); - if (GuiScreen.isShiftKeyDown()) { - if (fullLine != null) { - BufferedImage image = Chatting.INSTANCE.screenshotLine(fullLine); - if (image != null) RenderUtils.copyToClipboard(image); - } - return null; - } - ChatLine line = GuiScreen.isCtrlKeyDown() ? subLine : fullLine; - String message = line == null ? "Could not find chat message." : line.getChatComponent().getFormattedText(); - return new StringSelection(GuiScreen.isAltKeyDown() ? message : EnumChatFormatting.getTextWithoutFormattingCodes(message)); + return this.drawnChatLines.get(i1); } } @@ -326,6 +324,27 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { } @Override + public Transferable getChattingChatComponent(int mouseY) { + ChatLine subLine = getHoveredLine(mouseY); + if (subLine != null) { + ChatLine fullLine = this.getFullMessage(subLine); + if (GuiScreen.isShiftKeyDown()) { + if (fullLine != null) { + BufferedImage image = Chatting.INSTANCE.screenshotLine(fullLine); + if (image != null) RenderUtils.copyToClipboard(image); + } + return null; + } + ChatLine line = GuiScreen.isCtrlKeyDown() ? subLine : fullLine; + String message = line == null ? "Could not find chat message." : line.getChatComponent().getFormattedText(); + String actualMessage = GuiScreen.isAltKeyDown() ? message : EnumChatFormatting.getTextWithoutFormattingCodes(message); + Notifications.INSTANCE.send("Chatting", line == null ? "Could not find chat message." : "Copied following text: " + actualMessage); + return new StringSelection(actualMessage); + } + return null; + } + + @Override public String getPrevText() { return chatting$previousText; } diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiUtilsMixin.java b/src/main/java/cc/woverflow/chatting/mixin/GuiUtilsMixin.java index 6489f67..d939d6b 100644 --- a/src/main/java/cc/woverflow/chatting/mixin/GuiUtilsMixin.java +++ b/src/main/java/cc/woverflow/chatting/mixin/GuiUtilsMixin.java @@ -1,6 +1,8 @@ package cc.woverflow.chatting.mixin; +import cc.polyfrost.oneconfig.renderer.TextRenderer; import cc.woverflow.chatting.config.ChattingConfig; +import net.minecraft.client.gui.FontRenderer; import net.minecraftforge.fml.client.config.GuiUtils; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -19,4 +21,16 @@ public class GuiUtilsMixin { drawGradientRect(zLevel, left, top, right, bottom, startColor, endColor); } } + + @Redirect(method = "drawHoveringText", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I")) + private static int redirectText(FontRenderer instance, String text, float x, float y, int color) { + switch (ChattingConfig.INSTANCE.getTooltipTextRenderType()) { + case 0: + return instance.drawString(text, x, y, color, false); + case 2: + return TextRenderer.drawBorderedText(text, x, y, color, 255); + default: + return instance.drawStringWithShadow(text, x, y, color); + } + } } |