diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2021-12-25 14:13:27 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2021-12-25 14:13:27 +0700 |
commit | 4927d585ec72cb045a70718423228fa2cf55d071 (patch) | |
tree | 32714efb0c1a3a3aa3a01cadfc7a8ba5a9c784f1 /src/main/kotlin | |
parent | f720ca0a074411be7cbbdc1b9629b14d06e3b26c (diff) | |
download | Chatting-4927d585ec72cb045a70718423228fa2cf55d071.tar.gz Chatting-4927d585ec72cb045a70718423228fa2cf55d071.tar.bz2 Chatting-4927d585ec72cb045a70718423228fa2cf55d071.zip |
new: rewrite chat searching
fix: fix chat tabs / shortcuts not initializing when turning on
Diffstat (limited to 'src/main/kotlin')
10 files changed, 142 insertions, 41 deletions
diff --git a/src/main/kotlin/com/raeids/stratus/Stratus.kt b/src/main/kotlin/com/raeids/stratus/Stratus.kt index eafff31..d771915 100644 --- a/src/main/kotlin/com/raeids/stratus/Stratus.kt +++ b/src/main/kotlin/com/raeids/stratus/Stratus.kt @@ -12,6 +12,7 @@ import gg.essential.universal.UDesktop import net.minecraft.client.Minecraft import net.minecraft.client.gui.FontRenderer import net.minecraft.client.gui.GuiChat +import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.settings.KeyBinding import net.minecraft.client.shader.Framebuffer import net.minecraftforge.common.MinecraftForge.EVENT_BUS @@ -108,6 +109,8 @@ object Stratus { w = fr.getStringWidth(chatLines.stream().max(Comparator.comparingInt { obj: String -> obj.length }).get()) } val fb: Framebuffer = RenderHelper.createBindFramebuffer(w, h) + GlStateManager.translate(-2f, (160 - (180 - h)).toFloat(), 0f) + chat.drawChat(hud.updateCounter) val file = File(Minecraft.getMinecraft().mcDataDir, "screenshots/chat/" + fileFormatter.format(Date())) RenderHelper.screenshotFramebuffer(fb, file) Minecraft.getMinecraft().entityRenderer.setupOverlayRendering() diff --git a/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt b/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt index 8841700..e9d2401 100644 --- a/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt +++ b/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt @@ -2,6 +2,7 @@ package com.raeids.stratus.config import com.raeids.stratus.Stratus import com.raeids.stratus.gui.ChatShortcutViewGui +import com.raeids.stratus.hook.ChatShortcuts import com.raeids.stratus.hook.ChatTab import com.raeids.stratus.hook.ChatTabs import com.raeids.stratus.updater.DownloadGui @@ -107,7 +108,18 @@ object StratusConfig : Vigilant(File(Stratus.modDir, "${Stratus.ID}.toml"), Stra initialize() registerListener("chatTabs") { funny: Boolean -> chatTabs = funny - ChatTabs.currentTab = ChatTab("ALL", false, null, null, null, null, null, "") + ChatTabs.initialize() + if (!funny) { + val dummy = ChatTab("ALL", false, null, null, null, null, null, "") + dummy.initialize() + ChatTabs.currentTab = dummy + } else { + ChatTabs.currentTab = ChatTabs.tabs[0] + } + } + registerListener("chatShortcuts") { funny: Boolean -> + chatShortcuts = funny + ChatShortcuts.initialize() } } }
\ No newline at end of file diff --git a/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutEditGui.kt b/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutEditGui.kt index ef7baf5..ce64c6a 100644 --- a/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutEditGui.kt +++ b/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutEditGui.kt @@ -49,6 +49,8 @@ class ChatShortcutEditGui(private var alias: String, private var command: String } childOf window } ButtonComponent("Save") { + alias = alias.substringAfter("/") + command = alias.substringAfter("/") if (editing) { ChatShortcuts.removeShortcut(initialAlias) } @@ -67,7 +69,7 @@ class ChatShortcutEditGui(private var alias: String, private var command: String } childOf window } - inner class ChatShortcutConfirmGui(var alias: String, var command: String): WindowScreen(restoreCurrentGuiOnClose = true) { + inner class ChatShortcutConfirmGui(private var alias: String, private var command: String): WindowScreen(restoreCurrentGuiOnClose = true) { override fun initScreen(width: Int, height: Int) { super.initScreen(width, height) EssentialAPI.getEssentialComponentFactory().buildConfirmationModal { diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt index c056161..57cfc93 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt +++ b/src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt @@ -1,41 +1,41 @@ package com.raeids.stratus.hook +import gg.essential.lib.caffeine.cache.Cache +import gg.essential.lib.caffeine.cache.Caffeine import gg.essential.universal.wrappers.message.UTextComponent import net.minecraft.client.Minecraft import net.minecraft.client.gui.ChatLine -import net.minecraft.client.gui.GuiTextField -import net.minecraft.client.gui.ScaledResolution +import java.util.concurrent.LinkedBlockingQueue +import java.util.concurrent.ThreadPoolExecutor +import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicInteger -var inputField: GuiTextField? = null -var sr: ScaledResolution? = null -var prevText = "" - -fun initGui() { - sr = ScaledResolution(Minecraft.getMinecraft()) - inputField = GuiTextField( - 694209000, - Minecraft.getMinecraft().fontRendererObj, - sr!!.scaledWidth * 4 / 5 - 1, - sr!!.scaledHeight - 13, - sr!!.scaledWidth / 5, - 12 +private var counter: AtomicInteger = AtomicInteger(0) +private var POOL: ThreadPoolExecutor = ThreadPoolExecutor( + 50, 50, + 0L, TimeUnit.SECONDS, + LinkedBlockingQueue() +) { r -> + Thread( + r, + "Chat Filter Cache Thread ${counter.incrementAndGet()}" ) - inputField!!.maxStringLength = 100 - inputField!!.enableBackgroundDrawing = true - inputField!!.isFocused = false - inputField!!.text = "" - inputField!!.setCanLoseFocus(true) - prevText = "" } -fun updateScreen() { - inputField?.updateCursorCounter() -} +val cache: Cache<String, List<ChatLine?>> = Caffeine.newBuilder().executor(POOL).maximumSize(5000).build() -fun filterMessages(list: List<ChatLine?>?): List<ChatLine?>? { - if (inputField == null || list == null || inputField?.text.isNullOrBlank()) return list - return list.filter { - it != null && UTextComponent.stripFormatting(it.chatComponent.unformattedText).lowercase() - .contains(inputField!!.text!!.lowercase()) +fun filterMessages(text: String, list: List<ChatLine?>?): List<ChatLine?>? { + if (list.isNullOrEmpty() || text.isBlank()) return list + val cached = cache.getIfPresent(text) + return cached ?: run { + cache.put(text, list.filter { + it != null && UTextComponent.stripFormatting(it.chatComponent.unformattedText).lowercase() + .contains(text.lowercase()) + }) + cache.getIfPresent(text) } +} + +fun setPrevText(text: String) { + (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).prevText = text }
\ No newline at end of file diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatShortcuts.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatShortcuts.kt index dfea873..10a2af9 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatShortcuts.kt +++ b/src/main/kotlin/com/raeids/stratus/hook/ChatShortcuts.kt @@ -9,10 +9,17 @@ object ChatShortcuts { private val shortcutsFile = File(Stratus.modDir, "chatshortcuts.json") private val PARSER = JsonParser() + private var initialized = false + val shortcuts = mutableSetOf<Pair<String, String>>() fun initialize() { + if (initialized) { + return + } else { + initialized = true + } if (!shortcutsFile.exists()) { shortcutsFile.createNewFile() shortcutsFile.writeText( diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt index 3609fdc..2f3a729 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt +++ b/src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt @@ -16,18 +16,18 @@ data class ChatTab( @SerializedName("regex") val uncompiledRegex: List<String>?, val prefix: String ) { - lateinit var button: CleanButton + lateinit var button: CleanTabButton lateinit var compiledRegex: ChatRegexes //Ugly hack to make GSON not make button / regex null fun initialize() { compiledRegex = ChatRegexes(uncompiledRegex) val width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(name) - button = CleanButton(653452, runBlocking { + button = CleanTabButton(653452, runBlocking { val returnValue = x - 2 x += 6 + width return@runBlocking returnValue - }, 0, width + 4, 12, this) + }, width + 4, 12, this) } fun shouldRender(chatComponent: IChatComponent): Boolean { diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt index 0c371d1..a994f3d 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt +++ b/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt @@ -19,10 +19,16 @@ object ChatTabs { } } } + private var initialized = false private val tabFile = File(Stratus.modDir, "chattabs.json") fun initialize() { + if (initialized) { + return + } else { + initialized = true + } if (!tabFile.exists()) { generateNewFile() } else { diff --git a/src/main/kotlin/com/raeids/stratus/hook/CleanButton.kt b/src/main/kotlin/com/raeids/stratus/hook/CleanButton.kt index 38e44ad..bc4db34 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/CleanButton.kt +++ b/src/main/kotlin/com/raeids/stratus/hook/CleanButton.kt @@ -2,7 +2,6 @@ package com.raeids.stratus.hook import club.sk1er.patcher.config.PatcherConfig import com.raeids.stratus.Stratus -import gg.essential.universal.UResolution import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiButton import net.minecraft.client.renderer.GlStateManager @@ -13,21 +12,30 @@ import java.awt.Color * https://github.com/P0keDev/ChatShortcuts/blob/master/LICENSE * @author P0keDev */ -class CleanButton(buttonId: Int, x: Int, y: Int, widthIn: Int, heightIn: Int, private val chatTab: ChatTab) : - GuiButton(buttonId, x, y, widthIn, heightIn, chatTab.name) { +open class CleanButton(buttonId: Int, private val x: () -> Int, private val y: () -> Int, widthIn: Int, heightIn: Int, name: String) : + GuiButton(buttonId, x.invoke(), 0, widthIn, heightIn, name) { + + open fun isEnabled(): Boolean { + return false + } + + open fun onMousePress() { + + } override fun mousePressed(mc: Minecraft, mouseX: Int, mouseY: Int): Boolean { val isPressed = - enabled && visible && mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height + visible && mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height if (isPressed) { - ChatTabs.currentTab = chatTab + onMousePress() } return isPressed } override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) { - enabled = chatTab != ChatTabs.currentTab - yPosition = UResolution.scaledHeight - 26 + enabled = isEnabled() + xPosition = x.invoke() + yPosition = y.invoke() if (visible) { val fontrenderer = mc.fontRendererObj GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f) diff --git a/src/main/kotlin/com/raeids/stratus/hook/CleanSearchButton.kt b/src/main/kotlin/com/raeids/stratus/hook/CleanSearchButton.kt new file mode 100644 index 0000000..4b7ba5a --- /dev/null +++ b/src/main/kotlin/com/raeids/stratus/hook/CleanSearchButton.kt @@ -0,0 +1,46 @@ +package com.raeids.stratus.hook + +import gg.essential.universal.UResolution +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.GuiTextField + +class CleanSearchButton: CleanButton(3993935, {UResolution.scaledWidth - 42}, {UResolution.scaledHeight - 27}, 40, 12, "Search") { + val inputField = SearchTextField() + private var chatBox = false + + override fun isEnabled(): Boolean { + return chatBox + } + + override fun onMousePress() { + println("hi") + chatBox = !chatBox + inputField.setEnabled(chatBox) + inputField.isFocused = chatBox + (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).prevText = "" + inputField.text = "" + } + + override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) { + inputField.drawTextBox() + super.drawButton(mc, mouseX, mouseY) + } + + inner class SearchTextField: GuiTextField(69420, Minecraft.getMinecraft().fontRendererObj, UResolution.scaledWidth * 4 / 5 - 60, UResolution.scaledHeight - 27, UResolution.scaledWidth / 5, 12) { + + init { + maxStringLength = 100 + enableBackgroundDrawing = true + isFocused = false + text = "" + setCanLoseFocus(true) + } + + override fun drawTextBox() { + if (isEnabled()) { + if (!isFocused) isFocused = true + super.drawTextBox() + } + } + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/raeids/stratus/hook/CleanTabButton.kt b/src/main/kotlin/com/raeids/stratus/hook/CleanTabButton.kt new file mode 100644 index 0000000..0277dd8 --- /dev/null +++ b/src/main/kotlin/com/raeids/stratus/hook/CleanTabButton.kt @@ -0,0 +1,17 @@ +package com.raeids.stratus.hook + +import gg.essential.universal.UResolution + +class CleanTabButton(buttonId: Int, x: Int, widthIn: Int, heightIn: Int, private val chatTab: ChatTab) : + CleanButton(buttonId, { x }, { + UResolution.scaledHeight - 26 + }, widthIn, heightIn, chatTab.name) { + + override fun onMousePress() { + ChatTabs.currentTab = chatTab + } + + override fun isEnabled(): Boolean { + return chatTab != ChatTabs.currentTab + } +}
\ No newline at end of file |