diff options
author | Cephetir <silyichev@gmail.com> | 2022-05-07 15:58:07 +0300 |
---|---|---|
committer | Cephetir <silyichev@gmail.com> | 2022-05-07 15:58:07 +0300 |
commit | 5a7c1803dfeeda9a88dc4c290d60e907a43aeebd (patch) | |
tree | 62c69c0bfedc453db258c59d85fcc471b871459f /src/main/kotlin | |
parent | 8dcd0270b25df0437fd583b8221f59943cfe4372 (diff) | |
download | Chatting-5a7c1803dfeeda9a88dc4c290d60e907a43aeebd.tar.gz Chatting-5a7c1803dfeeda9a88dc4c290d60e907a43aeebd.tar.bz2 Chatting-5a7c1803dfeeda9a88dc4c290d60e907a43aeebd.zip |
FINALLY fixed timestamps
Diffstat (limited to 'src/main/kotlin')
3 files changed, 36 insertions, 18 deletions
diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt index d1a6ae9..2b163c5 100644 --- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt +++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt @@ -107,13 +107,21 @@ object ChattingConfig : @Property( type = PropertyType.SWITCH, name = "Show Timestamp", - description = "Show message timestamp on hover.", + description = "Show message timestamp.", category = "General" ) var showTimestamp = false @Property( type = PropertyType.SWITCH, + name = "Timestamp Only On Hover", + description = "Show timestamp only on mouse hover.", + category = "General" + ) + var showTimestampHover = true + + @Property( + type = PropertyType.SWITCH, name = "Custom Chat Height", description = "Allows you to change the height of chat to heights greater than before.", category = "Chat Window" @@ -243,6 +251,7 @@ object ChattingConfig : chatShortcuts = funny ChatShortcuts.initialize() } + addDependency("showTimestampHover", "showTimestamp") } private object ConfigSorting : SortingBehavior() { diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt index b22673b..61f1ea1 100644 --- a/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt +++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt @@ -11,7 +11,7 @@ import net.minecraft.client.renderer.GlStateManager import net.minecraft.util.ResourceLocation class ScreenshotButton : - CleanButton(448318, { UResolution.scaledWidth - 28 }, { UResolution.scaledHeight - 26 }, 12, 12, "", + CleanButton(448318, { UResolution.scaledWidth - 42 }, { UResolution.scaledHeight - 26 }, 12, 12, "", { RenderType.NONE }) { override fun onMousePress() { diff --git a/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt b/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt index dc6a1e6..7a5f5d4 100644 --- a/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt +++ b/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt @@ -5,6 +5,7 @@ package cc.woverflow.chatting.utils import cc.woverflow.chatting.config.ChattingConfig import cc.woverflow.chatting.mixin.GuiNewChatAccessor import cc.woverflow.chatting.utils.ModCompatHooks.fontRenderer +import gg.essential.universal.ChatColor import gg.essential.universal.UMouse import net.minecraft.client.Minecraft import net.minecraft.client.gui.ChatLine @@ -12,7 +13,6 @@ import net.minecraft.client.gui.ScaledResolution import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.texture.TextureUtil import net.minecraft.client.shader.Framebuffer -import net.minecraft.util.ChatComponentText import net.minecraft.util.MathHelper import org.apache.commons.lang3.SystemUtils import org.lwjgl.BufferUtils @@ -27,8 +27,6 @@ import java.lang.reflect.Field import java.lang.reflect.Method import java.nio.ByteBuffer import java.nio.ByteOrder -import java.text.SimpleDateFormat -import java.util.* import javax.imageio.ImageIO import kotlin.math.roundToInt @@ -219,21 +217,32 @@ fun Framebuffer.screenshot(file: File): BufferedImage { return bufferedimage } -private val sdf: SimpleDateFormat = SimpleDateFormat("HH:mm:ss") - -@JvmField -val messages: Map<ChatLine, Long> = mutableMapOf() -var lastMessage: ChatLine? = null -fun showTimestamp() { - if (!ChattingConfig.showTimestamp) return +private val timePattern = Regex("\\[\\d+:\\d+:\\d+]") +private var lastLines = mutableListOf<ChatLine>() +fun timestampPre() { + if (!ChattingConfig.showTimestampHover) return + val drawnChatLines = (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatAccessor).drawnChatLines val chatLine = getChatLineOverMouse(UMouse.getTrueX().roundToInt(), UMouse.getTrueY().roundToInt()) - if (chatLine != null) { - val long = messages[chatLine] - if (long != null) chatLine.chatComponent.appendText(" §7[${sdf.format(Date(long))}]§r") + + lastLines.clear() + for (line in drawnChatLines) { + val chatComponent = line.chatComponent.createCopy() + val newline = ChatLine(line.updatedCounter, chatComponent, line.chatLineID) + lastLines.add(newline) } - val long = messages[lastMessage] - if (long != null) lastMessage?.chatComponent?.siblings?.remove(ChatComponentText(" §7[${sdf.format(Date(long))}]§r")) - lastMessage = chatLine + + drawnChatLines.map { + if (it != chatLine) it.chatComponent.siblings.removeAll { itt -> + timePattern.find(ChatColor.stripControlCodes(itt.unformattedText)!!) != null + } + } +} + +fun timestampPost() { + if (!ChattingConfig.showTimestampHover) return + val drawnChatLines = (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatAccessor).drawnChatLines + drawnChatLines.clear() + drawnChatLines.addAll(lastLines) } private fun getChatLineOverMouse(mouseX: Int, mouseY: Int): ChatLine? { |