diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-03-12 14:53:23 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-03-12 14:53:23 +0700 |
commit | dd0d2d6d5c0191861cab0611d9fc28d7f4edb088 (patch) | |
tree | 96d8b3e88821e42b9b0357ddda1c5170992a57e5 /src/main/kotlin | |
parent | eef8bab78435d86107d95951cc1da04317520d33 (diff) | |
download | Chatting-dd0d2d6d5c0191861cab0611d9fc28d7f4edb088.tar.gz Chatting-dd0d2d6d5c0191861cab0611d9fc28d7f4edb088.tar.bz2 Chatting-dd0d2d6d5c0191861cab0611d9fc28d7f4edb088.zip |
chat tabs documentation
Diffstat (limited to 'src/main/kotlin')
7 files changed, 112 insertions, 86 deletions
diff --git a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt index 1f7c47d..fa24065 100644 --- a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt +++ b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt @@ -10,10 +10,7 @@ import cc.woverflow.chatting.utils.ModCompatHooks import cc.woverflow.chatting.utils.copyToClipboard import cc.woverflow.chatting.utils.createBindFramebuffer import cc.woverflow.chatting.utils.screenshot -import cc.woverflow.wcore.utils.Updater -import cc.woverflow.wcore.utils.command -import cc.woverflow.wcore.utils.openGUI -import gg.essential.api.EssentialAPI +import cc.woverflow.onecore.utils.* import gg.essential.universal.UDesktop import gg.essential.universal.UResolution import net.minecraft.client.Minecraft @@ -78,7 +75,7 @@ object Chatting { ChattingConfig.preload() command("chatting", aliases = arrayListOf("stratus")) { main { - ChattingConfig.openGUI() + ChattingConfig.openScreen() } } ClientRegistry.registerKeyBinding(keybind) @@ -99,11 +96,13 @@ object Chatting { fun onForgeLoad(event: FMLLoadCompleteEvent) { if (ChattingConfig.informForAlternatives) { if (isHychat) { - EssentialAPI.getNotifications().push(NAME, "Hychat can be removed at it is replaced by Chatting.") + sendBrandedNotification(NAME, "Hychat can be removed at it is replaced by Chatting. Click here for more information.", action = { + UDesktop.browseURL("https://github.com/MicrocontrollersDev/Alternatives/blob/main/Hychat.md") + }) } if (isSkytils) { if (Config.chatTabs) { - EssentialAPI.getNotifications().push(NAME, "Skytils' chat tabs can be disabled as it is replace by Chatting.\nClick here to automatically do this.", 6F, action = { + sendBrandedNotification(NAME, "Skytils' chat tabs can be disabled as it is replace by Chatting.\nClick here to automatically do this.", 6F, action = { Config.chatTabs = false ChattingConfig.chatTabs = true ChattingConfig.hypixelOnlyChatTabs = true @@ -112,7 +111,7 @@ object Chatting { }) } if (Config.copyChat) { - EssentialAPI.getNotifications().push(NAME, "Skytils' copy chat messages can be disabled as it is replace by Chatting.\nClick here to automatically do this.", 6F, action = { + sendBrandedNotification(NAME, "Skytils' copy chat messages can be disabled as it is replace by Chatting.\nClick here to automatically do this.", 6F, action = { Config.copyChat = false Config.markDirty() Config.writeData() @@ -169,11 +168,11 @@ object Chatting { private fun screenshot(messages: List<String>): BufferedImage? { if (messages.isEmpty()) { - EssentialAPI.getNotifications().push("Chatting", "Chat window is empty.") + sendBrandedNotification("Chatting", "Chat window is empty.") return null } if (!OpenGlHelper.isFramebufferEnabled()) { - EssentialAPI.getNotifications().push("Chatting", "Screenshot failed, please disable “Fast Render” in OptiFine’s “Performance” tab.") + sendBrandedNotification("Chatting", "Screenshot failed, please disable “Fast Render” in OptiFine’s “Performance” tab.") return null } @@ -192,10 +191,9 @@ object Chatting { val image = fb.screenshot(file) Minecraft.getMinecraft().entityRenderer.setupOverlayRendering() Minecraft.getMinecraft().framebuffer.bindFramebuffer(true) - EssentialAPI.getNotifications() - .push("Chatting", "Chat screenshotted successfully." + (if (ChattingConfig.copyMode != 1) "\nClick to open." else ""), action = { + sendBrandedNotification("Chatting", "Chat screenshotted successfully." + (if (ChattingConfig.copyMode != 1) "\nClick to open." else ""), action = { if (!UDesktop.open(file)) { - EssentialAPI.getNotifications().push("Chatting", "Could not browse!") + sendBrandedNotification("Chatting", "Could not browse!") } }) return image diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt index 236ccf6..1e20b01 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt @@ -2,7 +2,6 @@ package cc.woverflow.chatting.chat import cc.woverflow.chatting.gui.components.TabButton import com.google.gson.annotations.SerializedName -import kotlinx.coroutines.runBlocking import net.minecraft.client.Minecraft import net.minecraft.util.EnumChatFormatting import net.minecraft.util.IChatComponent @@ -16,28 +15,60 @@ data class ChatTab( @SerializedName("ends") val endsWith: List<String>?, val equals: List<String>?, @SerializedName("regex") val uncompiledRegex: List<String>?, - val prefix: String + @SerializedName("ignore_starts") val ignoreStartsWith: List<String>?, + @SerializedName("ignore_contains") val ignoreContains: List<String>?, + @SerializedName("ignore_ends") val ignoreEndsWith: List<String>?, + @SerializedName("ignore_equals") val ignoreEquals: List<String>?, + @SerializedName("ignore_regex") val uncompiledIgnoreRegex: List<String>?, + val prefix: String, ) { lateinit var button: TabButton lateinit var compiledRegex: ChatRegexes + lateinit var compiledIgnoreRegex: ChatRegexes //Ugly hack to make GSON not make button / regex null fun initialize() { compiledRegex = ChatRegexes(uncompiledRegex) + compiledIgnoreRegex = ChatRegexes(uncompiledIgnoreRegex) val width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(name) - button = TabButton(653452, runBlocking { + button = TabButton(653452, run { val returnValue = x - 2 x += 6 + width - return@runBlocking returnValue + return@run returnValue }, width + 4, 12, this) } fun shouldRender(chatComponent: IChatComponent): Boolean { - if (startsWith == null && equals == null && endsWith == null && contains == null && uncompiledRegex == null) { - return true - } val message = if (unformatted) EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.unformattedText) else chatComponent.formattedText + ignoreStartsWith?.forEach { + if (message.startsWith(it)) { + return false + } + } + ignoreEquals?.forEach { + if (message == it) { + return false + } + } + ignoreEndsWith?.forEach { + if (message.endsWith(it)) { + return false + } + } + ignoreContains?.forEach { + if (message.contains(it)) { + return false + } + } + compiledIgnoreRegex.compiledRegexList.forEach { + if (it.matches(message)) { + return false + } + } + if (startsWith.isNullOrEmpty() && equals.isNullOrEmpty() && endsWith.isNullOrEmpty() && contains.isNullOrEmpty() && uncompiledRegex.isNullOrEmpty()) { + return true + } equals?.forEach { if (message == it) { return true @@ -66,22 +97,6 @@ data class ChatTab( return false } - override fun equals(other: Any?): Boolean { - return other is ChatTab && name == other.name && startsWith == other.startsWith && contains == other.contains && endsWith == other.endsWith && equals == other.equals && compiledRegex == other.compiledRegex - } - - override fun hashCode(): Int { - var result = name.hashCode() - result = 31 * result + (startsWith?.hashCode() ?: 0) - result = 31 * result + (contains?.hashCode() ?: 0) - result = 31 * result + (endsWith?.hashCode() ?: 0) - result = 31 * result + (equals?.hashCode() ?: 0) - result = 31 * result + (uncompiledRegex?.hashCode() ?: 0) - result = 31 * result + prefix.hashCode() - result = 31 * result + button.hashCode() - return result - } - companion object { private var x = 4 } diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt index 5525a51..ec9dfc8 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt @@ -37,13 +37,24 @@ object ChatTabs { } else { try { val chatTabJson = GSON.fromJson(tabFile.readText(), ChatTabsJson::class.java) - if (chatTabJson.version == 1) { - // ver 2 adds `enabled` - chatTabJson.tabs.forEach { - it.asJsonObject.addProperty("enabled", true) + when (chatTabJson.version) { + 1 -> { + // ver 2 adds `enabled` + chatTabJson.tabs.forEach { + applyVersion2Changes(it.asJsonObject) + applyVersion3Changes(it.asJsonObject) + } + chatTabJson.version = 3 + tabFile.writeText(chatTabJson.toString()) + } + 2 -> { + // ver 2 adds `enabled` + chatTabJson.tabs.forEach { + applyVersion3Changes(it.asJsonObject) + } + chatTabJson.version = 3 + tabFile.writeText(chatTabJson.toString()) } - chatTabJson.version = 2 - tabFile.writeText(chatTabJson.toString()) } chatTabJson.tabs.forEach { val chatTab = GSON.fromJson(it.toString(), ChatTab::class.java) @@ -63,6 +74,18 @@ object ChatTabs { currentTab = tabs[0] } + private fun applyVersion2Changes(json: JsonObject) { + json.addProperty("enabled", true) + } + + private fun applyVersion3Changes(json: JsonObject) { + json.add("ignore_starts", JsonArray()) + json.add("ignore_contains", JsonArray()) + json.add("ignore_ends", JsonArray()) + json.add("ignore_equals", JsonArray()) + json.add("ignore_regex", JsonArray()) + } + fun shouldRender(message: IChatComponent): Boolean { return currentTab?.shouldRender(message) ?: true } @@ -72,12 +95,12 @@ object ChatTabs { val jsonObject = JsonObject() val defaultTabs = generateDefaultTabs() jsonObject.add("tabs", defaultTabs) - jsonObject.addProperty("version", 1) + jsonObject.addProperty("version", 3) tabFile.writeText(jsonObject.toString()) } private fun generateDefaultTabs(): JsonArray { - val all = ChatTab(true, "ALL", false, null, null, null, null, null, "") + val all = ChatTab(true, "ALL", false, null, null, null, null, null, null, null, null, null, null, "") val party = ChatTab( true, "PARTY", @@ -136,6 +159,11 @@ object ChatTabs { "§cThis party is currently muted\\.§r", "(§r)*(§9P §8\u003e)+(.*)" ), + null, + null, + null, + null, + null, "/pc " ) val guild = ChatTab( @@ -147,6 +175,11 @@ object ChatTabs { null, null, null, + null, + null, + null, + null, + null, "/gc " ) val pm = ChatTab( @@ -158,6 +191,11 @@ object ChatTabs { null, null, null, + null, + null, + null, + null, + null, "/r " ) tabs.add(all) diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt index 67db660..6c09731 100644 --- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt +++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt @@ -45,10 +45,17 @@ object ChattingConfig : Vigilant(File(Chatting.modDir, "${Chatting.ID}.toml"), C type = PropertyType.COLOR, name = "Chat Background Color", description = "Change the color of the chat background.", - category = "General", - allowAlpha = false + category = "General" + ) + var chatBackgroundColor = Color(0, 0, 0, 128) + + @Property( + type = PropertyType.COLOR, + name = "Copy Chat Message Background Color", + description = "Change the color of chat messages that are ready to copy.", + category = "General" ) - var chatBackgroundColor = Color(0, 0, 0, 50) + var hoveredChatBackgroundColor = Color(80, 80, 80, 128) @Property( type = PropertyType.SWITCH, @@ -179,7 +186,7 @@ object ChattingConfig : Vigilant(File(Chatting.modDir, "${Chatting.ID}.toml"), C chatTabs = funny ChatTabs.initialize() if (!funny) { - val dummy = ChatTab(true, "ALL", false, null, null, null, null, null, "") + val dummy = ChatTab(true, "ALL", false, null, null, null, null, null, null, null, null, null, null, "") dummy.initialize() ChatTabs.currentTab = dummy } else { 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 f761a9a..9863936 100644 --- a/src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt +++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt @@ -1,7 +1,8 @@ package cc.woverflow.chatting.gui.components import cc.woverflow.chatting.Chatting -import cc.woverflow.chatting.utils.drawBorderedString +import cc.woverflow.chatting.hook.GuiNewChatHook +import cc.woverflow.onecore.utils.drawBorderedString import club.sk1er.patcher.config.PatcherConfig import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiButton @@ -65,7 +66,7 @@ open class CleanButton(buttonId: Int, private val x: () -> Int, private val y: ( drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, j) } RenderType.FULL -> { - fontrenderer.drawBorderedString(displayString, (xPosition + width / 2) - (fontrenderer.getStringWidth(displayString) / 2), yPosition + (height - 8) / 2, j) + fontrenderer.drawBorderedString(displayString, (xPosition + width / 2) - (fontrenderer.getStringWidth(displayString) / 2), yPosition + (height - 8) / 2, 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 2f21429..8f73f2c 100644 --- a/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt +++ b/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt @@ -5,6 +5,8 @@ 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 net.minecraft.client.Minecraft import net.minecraft.client.gui.FontRenderer @@ -37,7 +39,7 @@ object ModCompatHooks { fontRenderer.drawString(text, x, y, color, false) } 2 -> { - fontRenderer.drawBorderedString(text, x.toInt(), y.toInt(), color) + 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 07fa2d3..393cc74 100644 --- a/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt +++ b/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt @@ -3,9 +3,6 @@ package cc.woverflow.chatting.utils import cc.woverflow.chatting.config.ChattingConfig -import cc.woverflow.chatting.hook.GuiNewChatHook -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.FontRenderer import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.texture.TextureUtil import net.minecraft.client.shader.Framebuffer @@ -24,11 +21,6 @@ import java.nio.ByteBuffer import java.nio.ByteOrder import javax.imageio.ImageIO -var bypassNameHighlight = false - private set - -private val regex = Regex("(?i)\\u00A7[0-9a-f]") - /** * Taken from https://github.com/Moulberry/HyChat */ @@ -214,31 +206,4 @@ fun Framebuffer.screenshot(file: File): BufferedImage { } } return bufferedimage -} - -/** - * Taken from https://github.com/Moulberry/HyChat - */ -fun FontRenderer.drawBorderedString(text: String, - x: Int, - y: Int, - color: Int): Int { - val noColors = text.replace(regex, "\u00A7r") - var yes = 0 - if (((Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity / 4) > 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, ((Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity / 4) shl 24, false - ) - } - } - } - bypassNameHighlight = false - } - yes += drawString(text, x, y, color) - return yes }
\ No newline at end of file |