aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/cc/woverflow/chatting
diff options
context:
space:
mode:
authorCephetir <silyichev@gmail.com>2022-05-06 12:41:54 +0300
committerCephetir <silyichev@gmail.com>2022-05-06 12:41:54 +0300
commitb5002d403246d91b8276791c1d16847abbbadab9 (patch)
treec011350cd8b1e29252edf672c68bbcb7cbc2a28d /src/main/kotlin/cc/woverflow/chatting
parentd3b3d5273d6754c991d6ba9a69884071a8e56c91 (diff)
downloadChatting-b5002d403246d91b8276791c1d16847abbbadab9.tar.gz
Chatting-b5002d403246d91b8276791c1d16847abbbadab9.tar.bz2
Chatting-b5002d403246d91b8276791c1d16847abbbadab9.zip
Timestamp on hover
Diffstat (limited to 'src/main/kotlin/cc/woverflow/chatting')
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt8
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt12
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt47
3 files changed, 59 insertions, 8 deletions
diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
index 93a8723..e80fa94 100644
--- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
@@ -80,6 +80,14 @@ object ChattingConfig :
@Property(
type = PropertyType.SWITCH,
+ name = "Show Timestamp",
+ description = "Show message timestamp on hover.",
+ category = "General"
+ )
+ var showTimestamp = false
+
+ @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"
diff --git a/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt b/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt
index 8f73f2c..39455ae 100644
--- a/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt
@@ -1,12 +1,12 @@
package cc.woverflow.chatting.utils
-import club.sk1er.patcher.config.PatcherConfig
-import com.llamalad7.betterchat.BetterChat
import cc.woverflow.chatting.Chatting.isBetterChat
import cc.woverflow.chatting.Chatting.isPatcher
import cc.woverflow.chatting.config.ChattingConfig.textRenderType
import cc.woverflow.chatting.hook.GuiNewChatHook
import cc.woverflow.onecore.utils.drawBorderedString
+import club.sk1er.patcher.config.PatcherConfig
+import com.llamalad7.betterchat.BetterChat
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.FontRenderer
@@ -35,12 +35,8 @@ object ModCompatHooks {
@JvmStatic
fun redirectDrawString(text: String, x: Float, y: Float, color: Int): Int {
return when (textRenderType) {
- 0 -> {
- fontRenderer.drawString(text, x, y, color, false)
- }
- 2 -> {
- fontRenderer.drawBorderedString(text, x.toInt(), y.toInt(), color, (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity)
- }
+ 0 -> fontRenderer.drawString(text, x, y, color, false)
+ 2 -> fontRenderer.drawBorderedString(text, x.toInt(), y.toInt(), color, (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity)
else -> fontRenderer.drawString(text, x, y, color, true)
}
}
diff --git a/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt b/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt
index 393cc74..bf11c3b 100644
--- a/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt
@@ -3,9 +3,17 @@
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.UMouse
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.ChatLine
+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
import org.lwjgl.opengl.GL11
@@ -19,7 +27,10 @@ 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
/**
* Taken from https://github.com/Moulberry/HyChat
@@ -206,4 +217,40 @@ 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
+ val chatLine = getChatLineOverMouse(UMouse.Raw.x.roundToInt(), UMouse.Raw.y.roundToInt())
+ if (chatLine != null) {
+ val long = messages[chatLine]
+ if (long != null) chatLine.chatComponent.appendText(" §7[${sdf.format(Date(long))}]§r")
+ }
+ val long = messages[lastMessage]
+ if (long != null) lastMessage?.chatComponent?.siblings?.remove(ChatComponentText(" §7[${sdf.format(Date(long))}]§r"))
+ lastMessage = chatLine
+}
+
+private fun getChatLineOverMouse(mouseX: Int, mouseY: Int): ChatLine? {
+ val chat = Minecraft.getMinecraft().ingameGUI.chatGUI
+ if (!chat.chatOpen) return null
+ val scaledResolution = ScaledResolution(Minecraft.getMinecraft())
+ val i = scaledResolution.scaleFactor
+ val f = chat.chatScale
+ val j = MathHelper.floor_float((mouseX / i - 3).toFloat() / f)
+ val k = MathHelper.floor_float((mouseY / i - 27).toFloat() / f)
+ if (j < 0 || k < 0) return null
+ val drawnChatLines = (chat as GuiNewChatAccessor).drawnChatLines
+ val l = chat.lineCount.coerceAtMost(drawnChatLines.size)
+ if (j <= MathHelper.floor_float(chat.chatWidth.toFloat() / f) && k < fontRenderer.FONT_HEIGHT * l + l) {
+ val m = k / Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT + chat.scrollPos
+ if (m >= 0 && m < drawnChatLines.size)
+ return drawnChatLines[m]
+ }
+ return null
} \ No newline at end of file