diff options
Diffstat (limited to 'src/main/kotlin')
-rw-r--r-- | src/main/kotlin/AllModules.kt | 2 | ||||
-rw-r--r-- | src/main/kotlin/datamodel/ChatType.kt | 52 | ||||
-rw-r--r-- | src/main/kotlin/event/VisibleChatMessageAddedEvent.kt | 8 | ||||
-rw-r--r-- | src/main/kotlin/gui/ChatUi.kt | 18 | ||||
-rw-r--r-- | src/main/kotlin/util/minecrat/infer.kt | 4 |
5 files changed, 69 insertions, 15 deletions
diff --git a/src/main/kotlin/AllModules.kt b/src/main/kotlin/AllModules.kt index 0e10687..01cfb36 100644 --- a/src/main/kotlin/AllModules.kt +++ b/src/main/kotlin/AllModules.kt @@ -1,6 +1,7 @@ package moe.nea.ultranotifier import moe.nea.ultranotifier.commands.Commands +import moe.nea.ultranotifier.datamodel.ChatCategoryArbiter import moe.nea.ultranotifier.event.SubscriptionTarget import moe.nea.ultranotifier.event.TickEvent import moe.nea.ultranotifier.gui.ScreenUtil @@ -11,5 +12,6 @@ object AllModules { Commands, ScreenUtil, TickEvent, + ChatCategoryArbiter, ) } diff --git a/src/main/kotlin/datamodel/ChatType.kt b/src/main/kotlin/datamodel/ChatType.kt index db3311b..31ec2e7 100644 --- a/src/main/kotlin/datamodel/ChatType.kt +++ b/src/main/kotlin/datamodel/ChatType.kt @@ -1,6 +1,12 @@ package moe.nea.ultranotifier.datamodel -import moe.nea.ultranotifier.util.minecrat.getDirectlyContainedText +import jdk.jfr.Category +import moe.nea.ultranotifier.event.SubscriptionTarget +import moe.nea.ultranotifier.event.TickEvent +import moe.nea.ultranotifier.event.UltraSubscribe +import moe.nea.ultranotifier.event.VisibleChatMessageAddedEvent +import moe.nea.ultranotifier.util.minecrat.MC +import moe.nea.ultranotifier.util.minecrat.category import moe.nea.ultranotifier.util.minecrat.getFormattedTextCompat import moe.nea.ultranotifier.util.minecrat.removeFormattingCodes import net.minecraft.text.Text @@ -29,7 +35,9 @@ data class ChatPattern( //#endif } +data class CategoryId(val id: String) data class ChatCategory( + val id: CategoryId, val label: String, val chatTypes: Set<ChatTypeId>, ) @@ -71,7 +79,8 @@ interface HasCategorizedChatLine { val categorizedChatLine_ultraNotifier: CategorizedChatLine } -object ChatCategoryArbiter { +object ChatCategoryArbiter : SubscriptionTarget { + val specialAll = CategoryId("special-all") val universe = ChatUniverse( "Hypixel SkyBlock", listOf( @@ -92,19 +101,50 @@ object ChatCategoryArbiter { ), listOf( ChatCategory( + specialAll, + "All", + setOf() + ), + ChatCategory( + CategoryId("economy"), "Economy", setOf(ChatTypeId("bazaar"), ChatTypeId("auction-house")) ) ) ) - fun categorize(content: Text): CategorizedChatLine { - val stringContent = content.getFormattedTextCompat().removeFormattingCodes() - return universe.categorize(stringContent) + val categories get() = universe.categories + var selectedCategoryId = specialAll + set(value) { + field = value + selectedCategory = findCategory(value) + } + var lastSelectedId = selectedCategoryId + + @UltraSubscribe + fun onTick(event: TickEvent) { + if (lastSelectedId != selectedCategoryId) { + MC.chatHud.reset() + lastSelectedId = selectedCategoryId + } } -} + var selectedCategory: ChatCategory = findCategory(selectedCategoryId) + private set + @UltraSubscribe + fun onVisibleChatMessage(event: VisibleChatMessageAddedEvent) { + val cl = event.chatLine.category + if (selectedCategory.id == specialAll)return + if (selectedCategory !in cl.categories) + event.cancel() + } + fun findCategory(id: CategoryId) = categories.find { it.id == id }!! + fun categorize(content: Text): CategorizedChatLine { + val stringContent = content.getFormattedTextCompat().removeFormattingCodes() + return universe.categorize(stringContent) + } +} diff --git a/src/main/kotlin/event/VisibleChatMessageAddedEvent.kt b/src/main/kotlin/event/VisibleChatMessageAddedEvent.kt new file mode 100644 index 0000000..5d37451 --- /dev/null +++ b/src/main/kotlin/event/VisibleChatMessageAddedEvent.kt @@ -0,0 +1,8 @@ +package moe.nea.ultranotifier.event + +import net.minecraft.client.gui.hud.ChatHudLine + + +data class VisibleChatMessageAddedEvent( + val chatLine: ChatHudLine, +) : UltraEvent() diff --git a/src/main/kotlin/gui/ChatUi.kt b/src/main/kotlin/gui/ChatUi.kt index e88c375..b812b73 100644 --- a/src/main/kotlin/gui/ChatUi.kt +++ b/src/main/kotlin/gui/ChatUi.kt @@ -2,6 +2,8 @@ package moe.nea.ultranotifier.gui import gg.essential.universal.UGraphics import gg.essential.universal.UMatrixStack +import moe.nea.ultranotifier.datamodel.ChatCategory +import moe.nea.ultranotifier.datamodel.ChatCategoryArbiter import moe.nea.ultranotifier.util.minecrat.MC import moe.nea.ultranotifier.util.minecrat.accessor import moe.nea.ultranotifier.util.render.ScreenRenderUtils @@ -26,10 +28,9 @@ class ChatUi(val chatScreen: ChatScreen) { return chatTop.toDouble() } - var selectedTab = "Bazaar" fun iterateButtons( onEach: ( - label: String, + label: ChatCategory, isSelected: Boolean, pos: Rect, ) -> Unit @@ -37,9 +38,9 @@ class ChatUi(val chatScreen: ChatScreen) { val chatTop = calculateChatTop() var xOffset = 5 val top = chatTop - 16.0 - for (button in listOf("Socials", "Bazaar", "Slayer", "Guild", "Party", "Dungeon", "Fishing","Socials", "Bazaar", "Slayer", "Guild", "Party", "Dungeon", "Fishing")) { - val w = ScreenRenderUtils.getTextWidth(button) + 3 - val isSelected = button == selectedTab + for (button in ChatCategoryArbiter.categories) { + val w = ScreenRenderUtils.getTextWidth(button.label) + 3 + val isSelected = button == ChatCategoryArbiter.selectedCategory onEach(button, isSelected, Rect(xOffset.toDouble(), top, w.toDouble(), 16.0)) xOffset += w + 5 } @@ -65,8 +66,7 @@ class ChatUi(val chatScreen: ChatScreen) { matrixStack: UMatrixStack, mouseX: Double, mouseY: Double, ) { - iterateButtons { text, isSelected, pos -> - val w = ScreenRenderUtils.getTextWidth(text) + iterateButtons { button, isSelected, pos -> UGraphics.enableBlend() ScreenRenderUtils.fillRect(matrixStack, pos.l, pos.t, pos.r, pos.b, @@ -74,7 +74,7 @@ class ChatUi(val chatScreen: ChatScreen) { UGraphics.disableBlend() ScreenRenderUtils.renderText(matrixStack, pos.l + 2, pos.cy - 9 / 2, - if (isSelected) "§a$text" else "§f$text") + if (isSelected) "§a${button.label}" else "§f${button.label}") } } @@ -82,7 +82,7 @@ class ChatUi(val chatScreen: ChatScreen) { iterateButtons { label, isSelected, pos -> if (pos.contains(mouseX, mouseY)) { if (button == 0) { - selectedTab = label + ChatCategoryArbiter.selectedCategoryId = label.id } // TODO: right click options or something } diff --git a/src/main/kotlin/util/minecrat/infer.kt b/src/main/kotlin/util/minecrat/infer.kt index 79973b9..479b186 100644 --- a/src/main/kotlin/util/minecrat/infer.kt +++ b/src/main/kotlin/util/minecrat/infer.kt @@ -2,7 +2,9 @@ package moe.nea.ultranotifier.util.minecrat +import moe.nea.ultranotifier.datamodel.HasCategorizedChatLine import net.minecraft.client.gui.hud.ChatHud +import net.minecraft.client.gui.hud.ChatHudLine import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract @@ -16,3 +18,5 @@ fun ChatHud.accessor(): AccessorChatHud { } return this as AccessorChatHud } + +val ChatHudLine.category get() = (this as HasCategorizedChatLine).categorizedChatLine_ultraNotifier |