diff options
author | ThatGravyBoat <thatgravyboat@gmail.com> | 2021-12-26 01:31:48 -0330 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-26 12:01:48 +0700 |
commit | 8f8d8e2dbe795309b69162bc3760dd4789fc6b73 (patch) | |
tree | 27f0df9ea4b3f793e4ad23e105330db97c2125b9 /src/main/kotlin/com/raeids/stratus/hook | |
parent | 4927d585ec72cb045a70718423228fa2cf55d071 (diff) | |
download | Chatting-8f8d8e2dbe795309b69162bc3760dd4789fc6b73.tar.gz Chatting-8f8d8e2dbe795309b69162bc3760dd4789fc6b73.tar.bz2 Chatting-8f8d8e2dbe795309b69162bc3760dd4789fc6b73.zip |
improve search button display and screenshotting, and fix tooltips (#2)
Diffstat (limited to 'src/main/kotlin/com/raeids/stratus/hook')
3 files changed, 54 insertions, 6 deletions
diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt index 57cfc93..6dd4904 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt +++ b/src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt @@ -22,14 +22,14 @@ private var POOL: ThreadPoolExecutor = ThreadPoolExecutor( ) } -val cache: Cache<String, List<ChatLine?>> = Caffeine.newBuilder().executor(POOL).maximumSize(5000).build() +val cache: Cache<String, List<ChatLine>> = Caffeine.newBuilder().executor(POOL).maximumSize(5000).build() -fun filterMessages(text: String, list: List<ChatLine?>?): List<ChatLine?>? { - if (list.isNullOrEmpty() || text.isBlank()) return list +fun filterMessages(text: String, list: List<ChatLine>): List<ChatLine>? { + if (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() + UTextComponent.stripFormatting(it.chatComponent.unformattedText).lowercase() .contains(text.lowercase()) }) cache.getIfPresent(text) diff --git a/src/main/kotlin/com/raeids/stratus/hook/CleanSearchButton.kt b/src/main/kotlin/com/raeids/stratus/hook/CleanSearchButton.kt index 4b7ba5a..7a68c75 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/CleanSearchButton.kt +++ b/src/main/kotlin/com/raeids/stratus/hook/CleanSearchButton.kt @@ -1,10 +1,14 @@ package com.raeids.stratus.hook +import com.raeids.stratus.Stratus import gg.essential.universal.UResolution import net.minecraft.client.Minecraft +import net.minecraft.client.gui.Gui import net.minecraft.client.gui.GuiTextField +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.util.ResourceLocation -class CleanSearchButton: CleanButton(3993935, {UResolution.scaledWidth - 42}, {UResolution.scaledHeight - 27}, 40, 12, "Search") { +class CleanSearchButton: CleanButton(3993935, {UResolution.scaledWidth - 14}, {UResolution.scaledHeight - 27}, 12, 12, "") { val inputField = SearchTextField() private var chatBox = false @@ -13,7 +17,6 @@ class CleanSearchButton: CleanButton(3993935, {UResolution.scaledWidth - 42}, {U } override fun onMousePress() { - println("hi") chatBox = !chatBox inputField.setEnabled(chatBox) inputField.isFocused = chatBox @@ -24,6 +27,17 @@ class CleanSearchButton: CleanButton(3993935, {UResolution.scaledWidth - 42}, {U override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) { inputField.drawTextBox() super.drawButton(mc, mouseX, mouseY) + if (visible) { + mc.textureManager.bindTexture(ResourceLocation(Stratus.ID, "search.png")) + if (isEnabled()) { + GlStateManager.color(224f/255f, 224f/255f, 224f/255f) + } else if (mouseX >= xPosition && mouseX <= xPosition + 10 && mouseY >= yPosition && mouseY <= yPosition + 10) { + GlStateManager.color(1f, 1f, 160f/255f) + } else { + GlStateManager.color(1f, 1f, 1f) + } + Gui.drawModalRectWithCustomSizedTexture(xPosition+1, yPosition+1, 0f, 0f, 10, 10, 10f, 10f) + } } inner class SearchTextField: GuiTextField(69420, Minecraft.getMinecraft().fontRendererObj, UResolution.scaledWidth * 4 / 5 - 60, UResolution.scaledHeight - 27, UResolution.scaledWidth / 5, 12) { diff --git a/src/main/kotlin/com/raeids/stratus/hook/ScreenshotButton.kt b/src/main/kotlin/com/raeids/stratus/hook/ScreenshotButton.kt new file mode 100644 index 0000000..70c64c2 --- /dev/null +++ b/src/main/kotlin/com/raeids/stratus/hook/ScreenshotButton.kt @@ -0,0 +1,34 @@ +package com.raeids.stratus.hook + +import com.raeids.stratus.Stratus +import com.raeids.stratus.mixin.GuiNewChatAccessor +import gg.essential.api.utils.GuiUtil +import gg.essential.universal.UResolution +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.Gui +import net.minecraft.client.gui.GuiChat +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.util.ResourceLocation + +class ScreenshotButton: CleanButton(448318, { UResolution.scaledWidth - 28}, { UResolution.scaledHeight - 27}, 12, 12, "") { + + override fun onMousePress() { + val chat = Minecraft.getMinecraft().ingameGUI.chatGUI + if (GuiUtil.getOpenedScreen() is GuiChat) { + Stratus.screenshotChat((chat as GuiNewChatAccessor).scrollPos) + } + } + + 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(Stratus.ID, "screenshot.png")) + Gui.drawModalRectWithCustomSizedTexture(xPosition + 1, yPosition + 1, 0f, 0f, 10, 10, 10f, 10f) + } + } +}
\ No newline at end of file |