aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authorMoo2meenn <67310794+Moo2meenn@users.noreply.github.com>2022-05-06 18:50:33 +0300
committerGitHub <noreply@github.com>2022-05-06 18:50:33 +0300
commitb96de6230299c751d0d3953c6546992efccb1111 (patch)
treed9db5ea005b8084b08c639096b42d3e5f6cc517e /src/main/kotlin
parent1046d78d70f074074dcf5c4ce522c8dc83654242 (diff)
parentdae58987b89bc01fa2828b5f4840a594f416f592 (diff)
downloadChatting-b96de6230299c751d0d3953c6546992efccb1111.tar.gz
Chatting-b96de6230299c751d0d3953c6546992efccb1111.tar.bz2
Chatting-b96de6230299c751d0d3953c6546992efccb1111.zip
Merge branch 'main' into fix-buttons-height
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt10
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt27
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt2
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt9
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/gui/components/ClearButton.kt27
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt2
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt12
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt47
8 files changed, 120 insertions, 16 deletions
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt
index 2cd4418..50de1f4 100644
--- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt
@@ -5,11 +5,13 @@ import com.google.gson.annotations.SerializedName
import net.minecraft.client.Minecraft
import net.minecraft.util.EnumChatFormatting
import net.minecraft.util.IChatComponent
+import java.util.*
data class ChatTab(
val enabled: Boolean,
val name: String,
val unformatted: Boolean,
+ val lowercase: Boolean?,
@SerializedName("starts") val startsWith: List<String>?,
val contains: List<String>?,
@SerializedName("ends") val endsWith: List<String>?,
@@ -23,7 +25,7 @@ data class ChatTab(
val color: Int?,
@SerializedName("hovered_color") val hoveredColor: Int?,
@SerializedName("selected_color") val selectedColor: Int?,
- val prefix: String,
+ val prefix: String?,
) {
lateinit var button: TabButton
lateinit var compiledRegex: ChatRegexes
@@ -43,7 +45,11 @@ data class ChatTab(
fun shouldRender(chatComponent: IChatComponent): Boolean {
val message =
- if (unformatted) EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.unformattedText) else chatComponent.formattedText
+ (if (unformatted) EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.unformattedText) else chatComponent.formattedText).let {
+ if (lowercase == true) it.lowercase(
+ Locale.ENGLISH
+ ) else it
+ }
ignoreStartsWith?.forEach {
if (message.startsWith(it)) {
return false
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
index 99a8999..cdec672 100644
--- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
@@ -45,26 +45,37 @@ object ChatTabs {
applyVersion2Changes(it.asJsonObject)
applyVersion3Changes(it.asJsonObject)
applyVersion4Changes(it.asJsonObject)
+ applyVersion5Changes(it.asJsonObject)
}
chatTabJson.version = ChatTabsJson.VERSION
- tabFile.writeText(chatTabJson.toString())
+ tabFile.writeText(GSON.toJson(chatTabJson))
}
2 -> {
// ver 3 adds ignore_
chatTabJson.tabs.forEach {
applyVersion3Changes(it.asJsonObject)
applyVersion4Changes(it.asJsonObject)
+ applyVersion5Changes(it.asJsonObject)
}
chatTabJson.version = ChatTabsJson.VERSION
- tabFile.writeText(chatTabJson.toString())
+ tabFile.writeText(GSON.toJson(chatTabJson))
}
3 -> {
// ver 4 adds color options
chatTabJson.tabs.forEach {
applyVersion4Changes(it.asJsonObject)
+ applyVersion5Changes(it.asJsonObject)
}
chatTabJson.version = ChatTabsJson.VERSION
- tabFile.writeText(chatTabJson.toString())
+ tabFile.writeText(GSON.toJson(chatTabJson))
+ }
+ 4 -> {
+ // ver 5 adds lowercase
+ chatTabJson.tabs.forEach {
+ applyVersion5Changes(it.asJsonObject)
+ }
+ chatTabJson.version = ChatTabsJson.VERSION
+ tabFile.writeText(GSON.toJson(chatTabJson))
}
}
chatTabJson.tabs.forEach {
@@ -103,6 +114,10 @@ object ChatTabs {
json.addProperty("selected_color", TabButton.selectedColor)
}
+ private fun applyVersion5Changes(json: JsonObject) {
+ json.addProperty("lowercase", false)
+ }
+
fun shouldRender(message: IChatComponent): Boolean {
return currentTab?.shouldRender(message) ?: true
}
@@ -113,7 +128,7 @@ object ChatTabs {
val defaultTabs = generateDefaultTabs()
jsonObject.add("tabs", defaultTabs)
jsonObject.addProperty("version", ChatTabsJson.VERSION)
- tabFile.writeText(jsonObject.toString())
+ tabFile.writeText(GSON.toJson(jsonObject))
}
private fun generateDefaultTabs(): JsonArray {
@@ -121,6 +136,7 @@ object ChatTabs {
true,
"ALL",
false,
+ false,
null,
null,
null,
@@ -140,6 +156,7 @@ object ChatTabs {
true,
"PARTY",
false,
+ false,
listOf("§r§9Party §8> ", "§r§9P §8> ", "§eThe party was transferred to §r", "§eKicked §r"),
null,
listOf(
@@ -208,6 +225,7 @@ object ChatTabs {
true,
"GUILD",
true,
+ false,
listOf("Guild >", "G >"),
null,
null,
@@ -227,6 +245,7 @@ object ChatTabs {
true,
"PM",
true,
+ false,
listOf("To ", "From "),
null,
null,
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt
index 6954b8e..b239bbd 100644
--- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt
@@ -10,6 +10,6 @@ data class ChatTabsJson(@SerializedName("tabs") val tabs: JsonArray, var version
}
companion object {
- const val VERSION = 4
+ const val VERSION = 5
}
} \ No newline at end of file
diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
index ae2187f..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"
@@ -183,6 +191,7 @@ object ChattingConfig :
true,
"ALL",
false,
+ false,
null,
null,
null,
diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/ClearButton.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/ClearButton.kt
new file mode 100644
index 0000000..3035a98
--- /dev/null
+++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/ClearButton.kt
@@ -0,0 +1,27 @@
+package cc.woverflow.chatting.gui.components
+
+import cc.woverflow.chatting.Chatting
+import gg.essential.universal.UResolution
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.Gui
+import net.minecraft.client.renderer.GlStateManager
+import net.minecraft.util.ResourceLocation
+
+class ClearButton :
+ CleanButton(13379014, { UResolution.scaledWidth - 28 }, { UResolution.scaledHeight - 27 }, 12, 12, "",
+ { RenderType.NONE }) {
+
+ override fun onMousePress() {
+ Minecraft.getMinecraft().ingameGUI.chatGUI.clearChatMessages()
+ }
+
+ override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) {
+ super.drawButton(mc, mouseX, mouseY)
+ if (visible) {
+ if (hovered) GlStateManager.color(1f, 1f, 160f / 255f)
+ else GlStateManager.color(1f, 1f, 1f)
+ mc.textureManager.bindTexture(ResourceLocation(Chatting.ID, "delete.png"))
+ Gui.drawModalRectWithCustomSizedTexture(xPosition + 1, yPosition + 1, 0f, 0f, 10, 10, 10f, 10f)
+ }
+ }
+} \ No newline at end of file
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 e72dbe1..b22673b 100644
--- a/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt
@@ -33,4 +33,4 @@ class ScreenshotButton :
Gui.drawModalRectWithCustomSizedTexture(xPosition + 1, yPosition + 1, 0f, 0f, 10, 10, 10f, 10f)
}
}
-}
+} \ No newline at end of file
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..dc6a1e6 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.getTrueX().roundToInt(), UMouse.getTrueY().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