summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java1
-rw-r--r--src/main/java/moe/nea/ultranotifier/mixin/FilterVisibleMessagePatch.java24
-rw-r--r--src/main/kotlin/AllModules.kt2
-rw-r--r--src/main/kotlin/datamodel/ChatType.kt52
-rw-r--r--src/main/kotlin/event/VisibleChatMessageAddedEvent.kt8
-rw-r--r--src/main/kotlin/gui/ChatUi.kt18
-rw-r--r--src/main/kotlin/util/minecrat/infer.kt4
7 files changed, 94 insertions, 15 deletions
diff --git a/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java b/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java
index bcccfe4..d7ed298 100644
--- a/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java
+++ b/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java
@@ -37,6 +37,7 @@ public class ChatHudMessageAdded {
//#endif
CallbackInfo ci
) {
+ // TODO: in this method prevent messages from being flushed (to preserve more history)
if (UltraNotifierEvents.post(new ChatGuiLineEvent(message)).isCancelled()) {
ci.cancel();
}
diff --git a/src/main/java/moe/nea/ultranotifier/mixin/FilterVisibleMessagePatch.java b/src/main/java/moe/nea/ultranotifier/mixin/FilterVisibleMessagePatch.java
new file mode 100644
index 0000000..13ef7cc
--- /dev/null
+++ b/src/main/java/moe/nea/ultranotifier/mixin/FilterVisibleMessagePatch.java
@@ -0,0 +1,24 @@
+package moe.nea.ultranotifier.mixin;
+
+import moe.nea.ultranotifier.event.UltraNotifierEvents;
+import moe.nea.ultranotifier.event.VisibleChatMessageAddedEvent;
+import net.minecraft.client.gui.hud.ChatHud;
+import net.minecraft.client.gui.hud.ChatHudLine;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+@Mixin(ChatHud.class)
+public class FilterVisibleMessagePatch {
+ @Inject(
+ method = "addVisibleMessage",
+ at = @At("HEAD"),
+ cancellable = true
+ )
+ private void onAddVisibleMessage(ChatHudLine message, CallbackInfo ci) {
+ if (UltraNotifierEvents.post(new VisibleChatMessageAddedEvent(message)).isCancelled()) {
+ ci.cancel();
+ }
+ }
+}
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