diff --git a/gradle.properties b/gradle.properties index 7e417f2..2628a39 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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. diff --git a/src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java b/src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java index 50b9ce3..6615bc7 100644 --- a/src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java +++ b/src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java @@ -7,11 +7,11 @@ import java.util.HashSet; public interface ChatLineHook { - HashSet> chatLines = new HashSet<>(); - boolean hasDetected(); - NetworkPlayerInfo getPlayerInfo(); + HashSet> chatting$chatLines = new HashSet<>(); + boolean chatting$hasDetected(); + NetworkPlayerInfo chatting$getPlayerInfo(); - void updatePlayerInfo(); + void chatting$updatePlayerInfo(); - long getUniqueId(); + long chatting$getUniqueId(); } diff --git a/src/main/java/org/polyfrost/chatting/hook/GuiChatHook.java b/src/main/java/org/polyfrost/chatting/hook/GuiChatHook.java new file mode 100644 index 0000000..36e0f48 --- /dev/null +++ b/src/main/java/org/polyfrost/chatting/hook/GuiChatHook.java @@ -0,0 +1,5 @@ +package org.polyfrost.chatting.hook; + +public interface GuiChatHook { + void chatting$triggerButtonReset(); +} diff --git a/src/main/java/org/polyfrost/chatting/hook/GuiNewChatHook.java b/src/main/java/org/polyfrost/chatting/hook/GuiNewChatHook.java index 84097bd..c07da97 100644 --- a/src/main/java/org/polyfrost/chatting/hook/GuiNewChatHook.java +++ b/src/main/java/org/polyfrost/chatting/hook/GuiNewChatHook.java @@ -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(); } diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java index 2e5f21c..0e44ae8 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java @@ -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 nicknameCache = new HashMap<>(); @@ -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 { @@ -108,7 +108,7 @@ public void updatePlayerInfo() { } @Override - public long getUniqueId() { + public long chatting$getUniqueId() { return uniqueId; } } diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java index e95d256..6052817 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java @@ -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; @@ -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 @@ -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")) @@ -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(); + } } } @@ -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) @@ -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(); + } } diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMapMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMapMixin.java index ca1c0df..eeeb01e 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMapMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMapMixin.java @@ -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); } } diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java index bc90730..7696483 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java @@ -2,6 +2,7 @@ import cc.polyfrost.oneconfig.libs.universal.UMouse; import cc.polyfrost.oneconfig.utils.Notifications; +import cc.polyfrost.oneconfig.utils.color.ColorUtils; import org.polyfrost.chatting.Chatting; import org.polyfrost.chatting.chat.ChatSearchingManager; import org.polyfrost.chatting.config.ChattingConfig; @@ -62,6 +63,11 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Unique private static final ResourceLocation DELETE = new ResourceLocation("chatting:delete.png"); + @Unique + private boolean chatting$lineInBounds = false; + @Unique + private ChatLine chatting$chatLine; + /*? @Unique private final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); @@ -95,11 +101,18 @@ private int setChatLimitWhenYes(int linesToDraw) { : linesToDraw; } - private boolean lineInBounds = false; + @ModifyVariable(method = "drawChat", at = @At("STORE"), ordinal = 0) + private ChatLine captureChatLine(ChatLine chatLine) { + chatting$chatLine = chatLine; + return chatLine; + } @ModifyArgs(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V"), slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/util/MathHelper;clamp_double(DDD)D"), to = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;enableBlend()V"))) - private void captureDrawRect(Args args) { - args.set(4, ChattingConfig.INSTANCE.getChatBackgroundColor().getRGB()); + private void captureDrawRect(Args args, int updateCounter) { + int opacity = chatting$getOpacity(updateCounter); + if (opacity != Integer.MIN_VALUE) { + args.set(4, ColorUtils.setAlpha(ChattingConfig.INSTANCE.getChatBackgroundColor().getRGB(), opacity / 2)); + } if (mc.currentScreen instanceof GuiChat) { int left = args.get(0); int top = args.get(1); @@ -107,12 +120,40 @@ private void captureDrawRect(Args args) { int bottom = args.get(3); if (isInBounds(left, top, right, bottom, getChatScale())) { chatting$isHovering = true; - lineInBounds = true; + chatting$lineInBounds = true; args.set(4, ChattingConfig.INSTANCE.getHoveredChatBackgroundColor().getRGB()); } } } + @Unique + private int chatting$getOpacity(int updateCounter) { + if (chatting$chatLine != null) { + float f = this.mc.gameSettings.chatOpacity * 0.9F + 0.1F; + int n = updateCounter - chatting$chatLine.getUpdatedCounter(); + if (n < 200 || getChatOpen()) { + int backgroundAlpha = ChattingConfig.INSTANCE.getChatBackgroundColor().getAlpha() * 2; + double d = (double)n / 200.0; + d = 1.0 - d; + d *= 10.0; + d = MathHelper.clamp_double(d, 0.0, 1.0); + d *= d; + int o = (int)(backgroundAlpha * d); + if (getChatOpen()) { + o = backgroundAlpha; + } + o = (int)((float)o * f); + if (o <= 3) { + o = 0; + } + return o; + } else { + return 0; + } + } + return Integer.MIN_VALUE; + } + @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) { @@ -121,12 +162,12 @@ private void drawChatBox(Args args) { 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$isHovering && lineInBounds) || isInBounds(left, top, right, bottom, f)) { + if ((chatting$isHovering && chatting$lineInBounds) || isInBounds(left, top, right, bottom, f)) { chatting$isHovering = true; drawCopyChatBox(right, top); } } - lineInBounds = false; + chatting$lineInBounds = false; } private boolean isInBounds(int left, int top, int right, int bottom, float chatScale) { @@ -137,9 +178,13 @@ private boolean isInBounds(int left, int top, int right, int bottom, float chatS return mouseX >= (left + ModCompatHooks.getXOffset()) && mouseY < bottom && mouseX < (right + 23 + ModCompatHooks.getXOffset()) && mouseY >= top; } - @ModifyVariable(method = "drawChat", at = @At("STORE"), ordinal = 7) - private int modifyYeah(int value) { - return chatting$textOpacity = (int) (((float) (getChatOpen() ? 255 : value)) * (mc.gameSettings.chatOpacity * 0.9F + 0.1F)); + @ModifyVariable(method = "drawChat", at = @At("STORE"), ordinal = 0) + private double modifyYeah(double value, int updateCounter) { + chatting$textOpacity = chatting$getOpacity(updateCounter); + if (chatting$textOpacity == Integer.MIN_VALUE) { + chatting$textOpacity = 0; + } + return value; } /*/ @Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;scale(FFF)V")) @@ -162,12 +207,12 @@ private void checkStuff(int j2, CallbackInfo ci) { } @Override - public int getRight() { + public int chatting$getRight() { return chatting$right; } @Override - public boolean isHovering() { + public boolean chatting$isHovering() { return chatting$isHovering; } @@ -178,33 +223,43 @@ private void drawCopyChatBox(int right, int top) { GlStateManager.enableDepth(); GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); GlStateManager.pushMatrix(); - mc.getTextureManager().bindTexture(COPY); - 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); - chatting$right = right; - drawModalRectWithCustomSizedTexture(right + 1, top, 0f, 0f, 9, 9, 9, 9); - 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())) ? ChattingConfig.INSTANCE.getChatButtonHoveredBackgroundColor().getRGB() : ChattingConfig.INSTANCE.getChatButtonBackgroundColor().getRGB())); - 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); - 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())) ? ChattingConfig.INSTANCE.getChatButtonHoveredBackgroundColor().getRGB() : ChattingConfig.INSTANCE.getChatButtonBackgroundColor().getRGB())); + int posLeft = right + 1; + int posRight = right + 10; + if (ChattingConfig.INSTANCE.getChatCopy()) { + mc.getTextureManager().bindTexture(COPY); + 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); + chatting$right = right; + drawModalRectWithCustomSizedTexture(posLeft, top, 0f, 0f, 9, 9, 9, 9); + drawRect(posLeft, top, posRight, top + 9, (((right + ModCompatHooks.getXOffset() + 3) <= (UMouse.getScaledX() / mc.ingameGUI.getChatGUI().getChatScale()) && (right + ModCompatHooks.getXOffset()) + 13 > (UMouse.getScaledX() / mc.ingameGUI.getChatGUI().getChatScale())) ? ChattingConfig.INSTANCE.getChatButtonHoveredBackgroundColor().getRGB() : ChattingConfig.INSTANCE.getChatButtonBackgroundColor().getRGB())); + posLeft += 10; + posRight += 10; + GlStateManager.disableAlpha(); + GlStateManager.disableRescaleNormal(); + } + if (ChattingConfig.INSTANCE.getChatDelete()) { + 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); + drawModalRectWithCustomSizedTexture(posLeft, top, 0f, 0f, 9, 9, 9, 9); + drawRect(posLeft, top, posRight, top + 9, (((right + ModCompatHooks.getXOffset() + 13) <= (UMouse.getScaledX() / mc.ingameGUI.getChatGUI().getChatScale()) && (right + ModCompatHooks.getXOffset()) + 23 > (UMouse.getScaledX() / mc.ingameGUI.getChatGUI().getChatScale())) ? ChattingConfig.INSTANCE.getChatButtonHoveredBackgroundColor().getRGB() : ChattingConfig.INSTANCE.getChatButtonBackgroundColor().getRGB())); + GlStateManager.disableAlpha(); + GlStateManager.disableRescaleNormal(); + } GlStateManager.disableLighting(); GlStateManager.popMatrix(); } @Override - public ChatLine getHoveredLine(int mouseY) { + public ChatLine chatting$getHoveredLine(int mouseY) { if (this.getChatOpen()) { ScaledResolution scaledresolution = new ScaledResolution(this.mc); int i = scaledresolution.getScaleFactor(); @@ -230,10 +285,10 @@ public ChatLine getHoveredLine(int mouseY) { } @Override - public Transferable getChattingChatComponent(int mouseY) { - ChatLine subLine = getHoveredLine(mouseY); + public Transferable chatting$getChattingChatComponent(int mouseY) { + ChatLine subLine = chatting$getHoveredLine(mouseY); if (subLine != null) { - ChatLine fullLine = this.getFullMessage(subLine); + ChatLine fullLine = this.chatting$getFullMessage(subLine); if (GuiScreen.isShiftKeyDown()) { if (fullLine != null) { BufferedImage image = Chatting.INSTANCE.screenshotLine(subLine); @@ -251,7 +306,7 @@ public Transferable getChattingChatComponent(int mouseY) { } @Override - public int getTextOpacity() { + public int chatting$getTextOpacity() { return chatting$textOpacity; } } diff --git a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt index 0e8745c..87ec63b 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt @@ -245,7 +245,7 @@ object Chatting { } val fr: FontRenderer = ModCompatHooks.fontRenderer - val width = messages.maxOf { fr.getStringWidth(it.value) + (if (ChattingConfig.showChatHeads && ((it.key as ChatLineHook).hasDetected() || ChattingConfig.offsetNonPlayerMessages)) 10 else 0) } + 4 + val width = messages.maxOf { fr.getStringWidth(it.value) + (if (ChattingConfig.showChatHeads && ((it.key as ChatLineHook).`chatting$hasDetected`() || ChattingConfig.offsetNonPlayerMessages)) 10 else 0) } + 4 val fb: Framebuffer = createBindFramebuffer(width * 2, (messages.size * 9) * 2) val file = File(Minecraft.getMinecraft().mcDataDir, "screenshots/chat/" + fileFormatter.format(Date())) diff --git a/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt b/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt index 0701471..75272ae 100644 --- a/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt +++ b/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt @@ -7,6 +7,7 @@ import cc.polyfrost.oneconfig.config.data.InfoType import cc.polyfrost.oneconfig.config.data.Mod 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 org.polyfrost.chatting.Chatting import org.polyfrost.chatting.chat.ChatShortcuts @@ -14,6 +15,7 @@ import org.polyfrost.chatting.chat.ChatTab import org.polyfrost.chatting.chat.ChatTabs import org.polyfrost.chatting.gui.components.TabButton import org.polyfrost.chatting.hook.ChatLineHook +import org.polyfrost.chatting.hook.GuiChatHook import org.polyfrost.chatting.utils.ModCompatHooks import java.io.File @@ -39,17 +41,11 @@ object ChattingConfig : Config( var chatBackgroundColor = OneColor(0, 0, 0, 128) @Color( - name = "Copy Chat Message Background Color", category = "General", + name = "Hover Message Background Color", category = "General", description = "The color of the chat background when hovering over a message." ) var hoveredChatBackgroundColor = OneColor(80, 80, 80, 128) - @Switch( - name = "Right Click to Copy Chat Message", category = "General", - description = "Enable right clicking on a chat message to copy it." - ) - var rightClickCopy = false - @Switch( name = "Compact Input Box", category = "General", description = "Make the chat input box the same width as the chat box." @@ -62,18 +58,6 @@ object ChattingConfig : Config( ) var inputBoxBackgroundColor = OneColor(0, 0, 0, 128) - @Color( - name = "Chat Button Background Color", category = "General", - description = "The color of the chat button background." - ) - var chatButtonBackgroundColor = OneColor(0, 0, 0, 128) - - @Color( - name = "Chat Button Hovered Background Color", category = "General", - description = "The color of the chat button background when hovered." - ) - var chatButtonHoveredBackgroundColor = OneColor(255, 255, 255, 128) - @Switch( name = "Inform Outdated Mods", category = "General", description = "Inform the user when a mod can be replaced by Chatting." @@ -117,6 +101,54 @@ object ChattingConfig : Config( ) var removeScrollBar = true + @Color( + name = "Chat Button Background Color", category = "Buttons", + description = "The color of the chat button background." + ) + var chatButtonBackgroundColor = OneColor(0, 0, 0, 128) + + @Color( + name = "Chat Button Hovered Background Color", category = "Buttons", + description = "The color of the chat button background when hovered." + ) + var chatButtonHoveredBackgroundColor = OneColor(255, 255, 255, 128) + + @Switch( + name = "Chat Copying Button", category = "Buttons", + description = "Enable copying chat messages via a button." + ) + var chatCopy = true + + @Switch( + name = "Right Click to Copy Chat Message", category = "Buttons", + description = "Enable right clicking on a chat message to copy it." + ) + var rightClickCopy = false + + @Switch( + name = "Delete Chat Message Button", category = "Buttons", + description = "Enable deleting individual chat messages via a button." + ) + var chatDelete = true + + @Switch( + name = "Delete Chat History Button", category = "Buttons", + description = "Enable deleting chat history via a button." + ) + var chatDeleteHistory = true + + @Switch( + name = "Chat Screenshot Button", category = "Buttons", + description = "Enable taking a screenshot of the chat via a button." + ) + var chatScreenshot = true + + @Switch( + name = "Chat Searching", category = "Buttons", + description = "Enable searching through chat messages." + ) + var chatSearch = true + @Switch( name = "Show Chat Heads", description = "Show the chat heads of players in chat", category = "Chat Heads", ) @@ -202,12 +234,6 @@ object ChattingConfig : Config( ) var copyMode = 0 - @Checkbox( - name = "Chat Searching", category = "Searching", - description = "Enable searching through chat messages." - ) - var chatSearch = true - @Switch( name = "Chat Tabs", category = "Tabs", description = "Allow filtering chat messages by a tab." @@ -272,7 +298,7 @@ object ChattingConfig : Config( return@addDependency !ModCompatHooks.betterChatSmoothMessages } addListener("hideChatHeadOnConsecutiveMessages") { - ChatLineHook.chatLines.map { it.get() as ChatLineHook? }.forEach { it?.updatePlayerInfo() } + ChatLineHook.`chatting$chatLines`.map { it.get() as ChatLineHook? }.forEach { it?.`chatting$updatePlayerInfo`() } } addListener("chatTabs") { ChatTabs.initialize() @@ -308,6 +334,19 @@ object ChattingConfig : Config( addListener("chatShortcuts") { ChatShortcuts.initialize() } + listOf( + "chatSearch", + "chatScreenshot", + "chatDeleteHistory", + "chatTabs" + ).forEach { + addListener(it) { + UMinecraft.getMinecraft().currentScreen?.let { screen -> + if (screen is GuiChatHook) { + screen.`chatting$triggerButtonReset`() + } + } + } } // addDependency("showTimestampHover", "showTimestamp") } } diff --git a/src/main/kotlin/org/polyfrost/chatting/gui/components/CleanButton.kt b/src/main/kotlin/org/polyfrost/chatting/gui/components/CleanButton.kt index d4c4acd..06554dc 100644 --- a/src/main/kotlin/org/polyfrost/chatting/gui/components/CleanButton.kt +++ b/src/main/kotlin/org/polyfrost/chatting/gui/components/CleanButton.kt @@ -90,7 +90,7 @@ open class CleanButton( ((xPosition + width / 2) - (fontrenderer.getStringWidth(displayString) / 2)).toFloat(), (yPosition + (height - 8) / 2).toFloat(), j, - (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity + (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).`chatting$getTextOpacity`() ) } } diff --git a/src/main/kotlin/org/polyfrost/chatting/gui/components/ClearButton.kt b/src/main/kotlin/org/polyfrost/chatting/gui/components/ClearButton.kt index 535cfca..e4c1594 100644 --- a/src/main/kotlin/org/polyfrost/chatting/gui/components/ClearButton.kt +++ b/src/main/kotlin/org/polyfrost/chatting/gui/components/ClearButton.kt @@ -9,9 +9,10 @@ import net.minecraft.client.Minecraft import net.minecraft.client.gui.Gui import net.minecraft.client.renderer.GlStateManager import net.minecraft.util.ResourceLocation +import org.polyfrost.chatting.config.ChattingConfig class ClearButton : - CleanButton(13379014, { UResolution.scaledWidth - 28 }, { UResolution.scaledHeight - 27 }, 12, 12, "", + CleanButton(13379014, { if (ChattingConfig.chatSearch) UResolution.scaledWidth - 28 else UResolution.scaledWidth - 14 }, { UResolution.scaledHeight - 27 }, 12, 12, "", { RenderType.NONE }) { var times = 0 diff --git a/src/main/kotlin/org/polyfrost/chatting/gui/components/ScreenshotButton.kt b/src/main/kotlin/org/polyfrost/chatting/gui/components/ScreenshotButton.kt index d8da4ad..206ace0 100644 --- a/src/main/kotlin/org/polyfrost/chatting/gui/components/ScreenshotButton.kt +++ b/src/main/kotlin/org/polyfrost/chatting/gui/components/ScreenshotButton.kt @@ -9,9 +9,12 @@ import net.minecraft.client.gui.Gui import net.minecraft.client.gui.GuiChat import net.minecraft.client.renderer.GlStateManager import net.minecraft.util.ResourceLocation +import org.polyfrost.chatting.config.ChattingConfig class ScreenshotButton : - CleanButton(448318, { UResolution.scaledWidth - 42 }, { UResolution.scaledHeight - 27 }, 12, 12, "", + CleanButton(448318, { + if (ChattingConfig.chatSearch && ChattingConfig.chatDeleteHistory) UResolution.scaledWidth - 42 else if (ChattingConfig.chatSearch || ChattingConfig.chatDeleteHistory) UResolution.scaledWidth - 28 else UResolution.scaledWidth - 14 + }, { UResolution.scaledHeight - 27 }, 12, 12, "", { RenderType.NONE }) { override fun onMousePress() { diff --git a/src/main/kotlin/org/polyfrost/chatting/utils/ModCompatHooks.kt b/src/main/kotlin/org/polyfrost/chatting/utils/ModCompatHooks.kt index b6198fa..9257638 100644 --- a/src/main/kotlin/org/polyfrost/chatting/utils/ModCompatHooks.kt +++ b/src/main/kotlin/org/polyfrost/chatting/utils/ModCompatHooks.kt @@ -58,10 +58,10 @@ object ModCompatHooks { var actualX = x if (showChatHeads && !screenshot) { val hook = chatLine as ChatLineHook - if (hook.hasDetected() || offsetNonPlayerMessages) { + if (hook.`chatting$hasDetected`() || offsetNonPlayerMessages) { actualX += 10f } - val networkPlayerInfo = hook.playerInfo + val networkPlayerInfo = hook.`chatting$getPlayerInfo`() if (networkPlayerInfo != null) { GlStateManager.enableBlend() GlStateManager.enableAlpha() @@ -102,7 +102,7 @@ object ModCompatHooks { actualX, y, color, - (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity) + (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).`chatting$getTextOpacity`()) else -> fontRenderer.drawString(text, actualX, y, color, true) } }