aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-01-11 17:48:56 +0100
committerGitHub <noreply@github.com>2024-01-11 17:48:56 +0100
commit0bb2a47bce773ca32d3a367b51dea33490544060 (patch)
tree72667a537985ffe9e387bd7517b7b21931f025ad /src/main
parentaa87cf5201fb53d4c21d297c79a92ddb72971aac (diff)
downloadskyhanni-0bb2a47bce773ca32d3a367b51dea33490544060.tar.gz
skyhanni-0bb2a47bce773ca32d3a367b51dea33490544060.tar.bz2
skyhanni-0bb2a47bce773ca32d3a367b51dea33490544060.zip
Add fire hide tab list (#865)
Add tab list fire sale advertisement hider. #865
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/CompactTabListConfig.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/SkipTabListLineEvent.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/RenderColumn.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListRenderer.kt38
5 files changed, 54 insertions, 10 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/CompactTabListConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/CompactTabListConfig.java
index 2236d886b..4d5530ea3 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/CompactTabListConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/CompactTabListConfig.java
@@ -21,6 +21,11 @@ public class CompactTabListConfig {
public boolean hideAdverts = false;
@Expose
+ @ConfigOption(name = "Hide Fire Sale Adverts", desc = "Hides fire sales from the tablist")
+ @ConfigEditorBoolean
+ public boolean hideFiresales = false;
+
+ @Expose
@ConfigOption(name = "Advanced Player List", desc = "")
@Accordion
public AdvancedPlayerListConfig advancedPlayerList = new AdvancedPlayerListConfig();
diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt
index 767643755..4db163944 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt
@@ -66,4 +66,8 @@ abstract class LorenzEvent : Event() {
}
fun postWithoutCatch() = MinecraftForge.EVENT_BUS.post(this)
+
+ fun cancel() {
+ isCanceled = true
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/SkipTabListLineEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/SkipTabListLineEvent.kt
new file mode 100644
index 000000000..0250b821f
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/SkipTabListLineEvent.kt
@@ -0,0 +1,11 @@
+package at.hannibal2.skyhanni.events
+
+import at.hannibal2.skyhanni.features.misc.compacttablist.TabLine
+import net.minecraftforge.fml.common.eventhandler.Cancelable
+
+@Cancelable
+data class SkipTabListLineEvent(
+ val line: TabLine,
+ val lastSubTitle: TabLine?,
+ val lastTitle: TabLine?,
+) : LorenzEvent()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/RenderColumn.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/RenderColumn.kt
index 2ee1e3442..894dee93b 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/RenderColumn.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/RenderColumn.kt
@@ -1,8 +1,6 @@
package at.hannibal2.skyhanni.features.misc.compacttablist
-class RenderColumn {
-
- val lines = mutableListOf<TabLine>()
+class RenderColumn(val lines: MutableList<TabLine> = mutableListOf()) {
fun size(): Int {
return lines.size
@@ -15,4 +13,4 @@ class RenderColumn {
fun getMaxWidth(): Int {
return lines.maxOfOrNull { it.getWidth() } ?: 0
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListRenderer.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListRenderer.kt
index d5cc7f875..b796b6e79 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListRenderer.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListRenderer.kt
@@ -1,8 +1,11 @@
package at.hannibal2.skyhanni.features.misc.compacttablist
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.SkipTabListLineEvent
import at.hannibal2.skyhanni.mixins.transformers.AccessorGuiPlayerTabOverlay
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matches
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.Gui
import net.minecraft.client.gui.ScaledResolution
@@ -91,18 +94,31 @@ object TabListRenderer {
}
var middleX = x
+ var lastTitle = null as TabLine?
+ var lastSubTitle = null as TabLine?
for (column in columns) {
var middleY = if (config.hideAdverts) headerY else headerY + padding + 2
+ val filteredColumn = column.lines.filterTo(mutableListOf()) { tabLine ->
+ if (tabLine.type == TabStringType.TITLE) {
+ lastSubTitle = null
+ lastTitle = tabLine
+ }
+ if (tabLine.type == TabStringType.SUB_TITLE) {
+ lastSubTitle = tabLine
+ }
+ !SkipTabListLineEvent(tabLine, lastSubTitle, lastTitle).postAndCatch()
+ }.let(::RenderColumn)
+
Gui.drawRect(
middleX - padding + 1,
middleY - padding + 1,
- middleX + column.getMaxWidth() + padding - 2,
- middleY + column.size() * lineHeight + padding - 2,
+ middleX + filteredColumn.getMaxWidth() + padding - 2,
+ middleY + filteredColumn.size() * lineHeight + padding - 2,
0x20AAAAAA
)
- for (tabLine in column.lines) {
+ for (tabLine in filteredColumn.lines) {
val savedX = middleX
val hideIcons = config.advancedPlayerList.hidePlayerIcons && !AdvancedPlayerList.ignoreCustomTabList()
@@ -125,7 +141,7 @@ object TabListRenderer {
if (tabLine.type == TabStringType.TITLE) {
minecraft.fontRendererObj.drawStringWithShadow(
text,
- middleX + column.getMaxWidth() / 2f - tabLine.getWidth() / 2f,
+ middleX + filteredColumn.getMaxWidth() / 2f - tabLine.getWidth() / 2f,
middleY.toFloat(),
0xFFFFFF
)
@@ -140,7 +156,7 @@ object TabListRenderer {
middleY += lineHeight
middleX = savedX
}
- middleX += column.getMaxWidth() + columnSpacing
+ middleX += filteredColumn.getMaxWidth() + columnSpacing
}
if (footer.isNotEmpty()) {
@@ -156,4 +172,14 @@ object TabListRenderer {
}
}
}
-} \ No newline at end of file
+
+ val fireSaleRegex by RepoPattern.pattern("tablist.firesaletitle", "^§b§lFire Sales: §r§f\\([0-9]+\\)$")
+
+ @SubscribeEvent
+ fun hideFireFromTheTabListBecauseWhoWantsThose(event: SkipTabListLineEvent) {
+ if (config.hideFiresales && event.lastSubTitle != null && fireSaleRegex.matches(event.lastSubTitle.text)) {
+ event.cancel()
+ }
+ }
+
+}