From e574e54a53b87ef4bbb33404b6fdb6b97c72dd81 Mon Sep 17 00:00:00 2001 From: Wyvest <45589059+Wyvest@users.noreply.github.com> Date: Sat, 14 Jan 2023 13:45:51 -0500 Subject: allow selecting multiple chat tabs at the same time --- .../kotlin/cc/woverflow/chatting/chat/ChatTabs.kt | 26 ++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/main/kotlin/cc/woverflow/chatting/chat') diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt index cb95c53..c2329b4 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt @@ -16,15 +16,16 @@ object ChatTabs { private val GSON = GsonBuilder().setPrettyPrinting().create() private val PARSER = JsonParser() val tabs = arrayListOf() - var currentTab: ChatTab? = null - set(value) { - if (value != null) { - field = value - if (Minecraft.getMinecraft().theWorld != null) { - Minecraft.getMinecraft().ingameGUI.chatGUI.refreshChat() - } + var currentTabs: ArrayList = object : ArrayList() { + override fun add(element: ChatTab?): Boolean { + if (element == null) return false + val returnValue = super.add(element) + if (Minecraft.getMinecraft().theWorld != null && returnValue) { + Minecraft.getMinecraft().ingameGUI.chatGUI.refreshChat() } + return returnValue } + } private var initialized = false private val tabFile = ConfigUtils.getProfileFile("chattabs.json") @@ -49,7 +50,8 @@ object ChatTabs { tabs.forEach { it.initialize() } - currentTab = tabs[0] + currentTabs.clear() + currentTabs.add(tabs[0]) } private fun handleFile() { @@ -171,7 +173,13 @@ object ChatTabs { } fun shouldRender(message: IChatComponent): Boolean { - return currentTab?.shouldRender(message) ?: true + if (currentTabs.isEmpty()) return true + for (tab in currentTabs) { + if (tab?.shouldRender(message) == true) { + return true + } + } + return false } private fun generateNewFile() { -- cgit