diff options
Diffstat (limited to 'src')
4 files changed, 81 insertions, 75 deletions
diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java index a430f8e..2bc5592 100644 --- a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java +++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java @@ -167,23 +167,6 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { } } lineInBounds = false; - if (ChattingConfig.INSTANCE.getShowChatHeads()) { - ChatLineHook hook = ((ChatLineHook) chatting$drawingLine); - if (hook.hasDetected() || ChattingConfig.INSTANCE.getOffsetNonPlayerMessages()) { - args.set(1, ((float) args.get(1)) + 10f); - } - NetworkPlayerInfo networkPlayerInfo = hook.getPlayerInfo(); - if (networkPlayerInfo != null) { - GlStateManager.enableBlend(); - GlStateManager.enableAlpha(); - mc.getTextureManager().bindTexture(networkPlayerInfo.getLocationSkin()); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.color(1.0F, 1.0F, 1.0F, ColorUtils.getAlpha(args.get(3)) / 255f); - Gui.drawScaledCustomSizeModalRect((int) ((float) args.get(1) - 10f), (int) ((float) args.get(2) - 1f), 8.0F, 8.0F, 8, 8, 8, 8, 64.0F, 64.0F); - Gui.drawScaledCustomSizeModalRect((int) ((float) args.get(1) - 10f), (int) ((float) args.get(2) - 1f), 40.0F, 8.0F, 8, 8, 8, 8, 64.0F, 64.0F); - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - } - } } private boolean isInBounds(int left, int top, int right, int bottom, float chatScale) { @@ -225,7 +208,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I")) private int redirectDrawString(FontRenderer instance, String text, float x, float y, int color) { - return ModCompatHooks.redirectDrawString(text, x, y, color); + return ModCompatHooks.redirectDrawString(text, x, y, color, chatting$drawingLine); } @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 1)) diff --git a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt index 986a229..98b12fd 100644 --- a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt +++ b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt @@ -11,6 +11,7 @@ import cc.woverflow.chatting.chat.ChatSpamBlock import cc.woverflow.chatting.chat.ChatTabs import cc.woverflow.chatting.command.ChattingCommand import cc.woverflow.chatting.config.ChattingConfig +import cc.woverflow.chatting.hook.ChatLineHook import cc.woverflow.chatting.hook.GuiNewChatHook import cc.woverflow.chatting.mixin.GuiNewChatAccessor import cc.woverflow.chatting.utils.ModCompatHooks @@ -39,6 +40,7 @@ import java.awt.image.BufferedImage import java.io.File import java.text.SimpleDateFormat import java.util.* +import kotlin.collections.HashMap @Mod( @@ -173,13 +175,17 @@ object Chatting { val chat = hud.chatGUI val i = MathHelper.floor_float(chat.chatWidth / chat.chatScale) return screenshot( - GuiUtilRenderComponents.splitText( - line.chatComponent, - i, - Minecraft.getMinecraft().fontRendererObj, - false, - false - ).map { it.formattedText }.reversed() + hashMapOf<String, ChatLine>().also { + GuiUtilRenderComponents.splitText( + line.chatComponent, + i, + Minecraft.getMinecraft().fontRendererObj, + false, + false + ).map { it.formattedText }.reversed().forEach { string -> + it[string] = line + } + } ) } @@ -190,7 +196,7 @@ object Chatting { fun screenshotChat(scrollPos: Int) { val hud = Minecraft.getMinecraft().ingameGUI val chat = hud.chatGUI - val chatLines = ArrayList<String>() + val chatLines = HashMap<String, ChatLine>() ChatSearchingManager.filterMessages( (chat as GuiNewChatHook).prevText, (chat as GuiNewChatAccessor).drawnChatLines @@ -200,14 +206,14 @@ object Chatting { Minecraft.getMinecraft().gameSettings.chatHeightFocused / 9 ) for (i in scrollPos until drawnLines.size.coerceAtMost(scrollPos + chatHeight)) { - chatLines.add(drawnLines[i].chatComponent.formattedText) + chatLines[drawnLines[i].chatComponent.formattedText] = drawnLines[i] } screenshot(chatLines)?.copyToClipboard() } } - private fun screenshot(messages: List<String>): BufferedImage? { + private fun screenshot(messages: HashMap<String, ChatLine>): BufferedImage? { if (messages.isEmpty()) { Notifications.INSTANCE.send("Chatting", "Chat window is empty.") return null @@ -221,15 +227,15 @@ object Chatting { } val fr: FontRenderer = ModCompatHooks.fontRenderer - val width = messages.maxOf { fr.getStringWidth(it) } + 4 + val width = messages.maxOf { fr.getStringWidth(it.key) + (if (ChattingConfig.showChatHeads && ((it.value as ChatLineHook).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())) GlStateManager.scale(2f, 2f, 1f) val scale = Minecraft.getMinecraft().gameSettings.chatScale GlStateManager.scale(scale, scale, 1f) - for (i in messages.indices) { - ModCompatHooks.redirectDrawString(messages[i], 0f, (messages.size - 1 - i) * 9f, 0xffffff) + messages.entries.forEachIndexed { i: Int, entry: MutableMap.MutableEntry<String, ChatLine> -> + ModCompatHooks.redirectDrawString(entry.key, 0f, (messages.size - 1 - i) * 9f, 0xffffff, entry.value) } val image = fb.screenshot(file) diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt index de69bab..8bc05bb 100644 --- a/src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt +++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt @@ -1,8 +1,8 @@ package cc.woverflow.chatting.gui.components +import cc.polyfrost.oneconfig.renderer.TextRenderer import cc.woverflow.chatting.Chatting import cc.woverflow.chatting.hook.GuiNewChatHook -import cc.woverflow.chatting.utils.ModCompatHooks.drawBorderedString import club.sk1er.patcher.config.PatcherConfig import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiButton @@ -85,10 +85,10 @@ open class CleanButton( } RenderType.FULL -> { - fontrenderer.drawBorderedString( + TextRenderer.drawBorderedText( displayString, - (xPosition + width / 2) - (fontrenderer.getStringWidth(displayString) / 2), - yPosition + (height - 8) / 2, + ((xPosition + width / 2) - (fontrenderer.getStringWidth(displayString) / 2)).toFloat(), + (yPosition + (height - 8) / 2).toFloat(), j, (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity ) diff --git a/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt b/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt index fd337de..0d1d512 100644 --- a/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt +++ b/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt @@ -1,13 +1,22 @@ package cc.woverflow.chatting.utils +import cc.polyfrost.oneconfig.renderer.TextRenderer +import cc.polyfrost.oneconfig.utils.dsl.getAlpha +import cc.polyfrost.oneconfig.utils.dsl.mc import cc.woverflow.chatting.Chatting.isBetterChat import cc.woverflow.chatting.Chatting.isPatcher +import cc.woverflow.chatting.config.ChattingConfig.offsetNonPlayerMessages +import cc.woverflow.chatting.config.ChattingConfig.showChatHeads import cc.woverflow.chatting.config.ChattingConfig.textRenderType +import cc.woverflow.chatting.hook.ChatLineHook import cc.woverflow.chatting.hook.GuiNewChatHook import club.sk1er.patcher.config.PatcherConfig import com.llamalad7.betterchat.BetterChat import net.minecraft.client.Minecraft +import net.minecraft.client.gui.ChatLine import net.minecraft.client.gui.FontRenderer +import net.minecraft.client.gui.Gui +import net.minecraft.client.renderer.GlStateManager // This exists because mixin doesn't like dummy classes object ModCompatHooks { @@ -32,48 +41,56 @@ object ModCompatHooks { get() = Minecraft.getMinecraft().fontRendererObj @JvmStatic - fun redirectDrawString(text: String, x: Float, y: Float, color: Int): Int { + fun redirectDrawString(text: String, x: Float, y: Float, color: Int, chatLine: ChatLine): Int { + var actualX = x + if (showChatHeads) { + val hook = chatLine as ChatLineHook + if (hook.hasDetected() || offsetNonPlayerMessages) { + actualX += 10f + } + val networkPlayerInfo = hook.playerInfo + if (networkPlayerInfo != null) { + GlStateManager.enableBlend() + GlStateManager.enableAlpha() + GlStateManager.enableTexture2D() + mc.textureManager.bindTexture(networkPlayerInfo.locationSkin) + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) + GlStateManager.color(1.0f, 1.0f, 1.0f, color.getAlpha() / 255f) + Gui.drawScaledCustomSizeModalRect( + (x).toInt(), + (y - 1f).toInt(), + 8.0f, + 8.0f, + 8, + 8, + 8, + 8, + 64.0f, + 64.0f + ) + Gui.drawScaledCustomSizeModalRect( + (x).toInt(), + (y - 1f).toInt(), + 40.0f, + 8.0f, + 8, + 8, + 8, + 8, + 64.0f, + 64.0f + ) + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f) + } + } return when (textRenderType) { - 0 -> fontRenderer.drawString(text, x, y, color, false) - 2 -> fontRenderer.drawBorderedString( - text, - x.toInt(), - y.toInt(), + 0 -> fontRenderer.drawString(text, actualX, y, color, false) + 2 -> TextRenderer.drawBorderedText(text, + actualX, + y, color, - (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity - ) - - else -> fontRenderer.drawString(text, x, y, color, true) + (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity) + else -> fontRenderer.drawString(text, actualX, y, color, true) } } - - - private val regex = Regex("(?i)\\u00A7[0-9a-f]") - private var bypassNameHighlight = false - fun FontRenderer.drawBorderedString( - text: String, x: Int, y: Int, color: Int, opacity: Int - ): Int { - val noColors = text.replace(regex, "\u00A7r") - var yes = 0 - if (opacity > 3) { - bypassNameHighlight = true - for (xOff in -2..2) { - for (yOff in -2..2) { - if (xOff * xOff != yOff * yOff) { - yes += - drawString( - noColors, (xOff / 2f) + x, (yOff / 2f) + y, (opacity) shl 24, false - ) - - } - } - } - bypassNameHighlight = false - } - yes += - //#if MODERN==0 - drawString(text, x, y, color) - - return yes - } } |