aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorConutik <60240193+Conutik@users.noreply.github.com>2024-03-24 12:49:30 +0300
committerGitHub <noreply@github.com>2024-03-24 10:49:30 +0100
commitd03dce8b859a263de4ec06b3ddc7427b83842aa1 (patch)
tree089776e69932f5c960004ba32270045fe43dd2d1 /src/main/java/at/hannibal2/skyhanni
parent3e7e376578602059e28487419e7b5f69770c7930 (diff)
downloadskyhanni-d03dce8b859a263de4ec06b3ddc7427b83842aa1.tar.gz
skyhanni-d03dce8b859a263de4ec06b3ddc7427b83842aa1.tar.bz2
skyhanni-d03dce8b859a263de4ec06b3ddc7427b83842aa1.zip
Feature: Added Highlighting for tab widgets. (#1175)
Co-authored-by: hannibal2 <24389977+hannibal002@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/TabWidgetSettings.kt99
3 files changed, 107 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index ed35585ad..27dd3c914 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -294,6 +294,7 @@ import at.hannibal2.skyhanni.features.misc.RestorePieceOfWizardPortalLore
import at.hannibal2.skyhanni.features.misc.ServerRestartTitle
import at.hannibal2.skyhanni.features.misc.SkyBlockKickDuration
import at.hannibal2.skyhanni.features.misc.SuperpairsClicksAlert
+import at.hannibal2.skyhanni.features.misc.TabWidgetSettings
import at.hannibal2.skyhanni.features.misc.TimeFeatures
import at.hannibal2.skyhanni.features.misc.TpsCounter
import at.hannibal2.skyhanni.features.misc.compacttablist.AdvancedPlayerList
@@ -772,6 +773,7 @@ class SkyHanniMod {
loadModule(LockMouseLook)
loadModule(SensitivityReducer)
loadModule(DungeonFinderFeatures())
+ loadModule(TabWidgetSettings())
loadModule(PabloHelper())
loadModule(FishingBaitWarnings())
loadModule(CustomScoreboard())
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java
index 874fde7d7..1908b6ef7 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java
@@ -138,6 +138,12 @@ public class InventoryConfig {
}
@Expose
+ @ConfigOption(name = "Highlight Widgets", desc = "Highlight enabled and disabled widgets in /tab.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean highlightWidgets = true;
+
+ @Expose
@ConfigOption(name = " Vacuum Bag Cap", desc = "Cap the Garden Vacuum Bag item number display to 40.")
@ConfigEditorBoolean
public boolean vacuumBagCap = true;
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/TabWidgetSettings.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/TabWidgetSettings.kt
new file mode 100644
index 000000000..c3bc3a38e
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/TabWidgetSettings.kt
@@ -0,0 +1,99 @@
+package at.hannibal2.skyhanni.features.misc
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.GuiContainerEvent
+import at.hannibal2.skyhanni.events.InventoryCloseEvent
+import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.LorenzColor
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.RenderUtils.highlight
+import at.hannibal2.skyhanni.utils.StringUtils.anyMatches
+import at.hannibal2.skyhanni.utils.StringUtils.matches
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class TabWidgetSettings {
+ private val patternGroup = RepoPattern.group("tab.widget.setting")
+ private val mainPageSettingPattern by patternGroup.pattern(
+ "gui",
+ "(Widgets in.*|Widgets on.*)"
+ )
+ private val mainPageWidgetPattern by patternGroup.pattern(
+ "main",
+ "§7Currently:.*"
+ )
+ private val subPageWidgetPattern by patternGroup.pattern(
+ "sub",
+ "§eClick to .*"
+ )
+ private val shownSettingPattern by patternGroup.pattern(
+ "show",
+ "Shown .* Setting.*|.*Widget Settings"
+ )
+ private val clickToDisablePattern by patternGroup.pattern(
+ "click.disable",
+ ".*(disable!)"
+ )
+ private val enabledPattern by patternGroup.pattern(
+ "is.enabled",
+ ".*ENABLED"
+ )
+
+ var inInventory = false
+ var highlights = mutableMapOf<Int, LorenzColor>()
+
+ @SubscribeEvent
+ fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
+ if (!isEnabled()) return
+ highlights.clear()
+
+ val inventoryName = event.inventoryName
+ if (mainPageSettingPattern.matches(inventoryName)) {
+ inInventory = true
+ val items = event.inventoryItems.filter { mainPageWidgetPattern.anyMatches(it.value.getLore()) }
+ for ((slot, stack) in items) {
+ highlights[slot] = if (enabledPattern.anyMatches(stack.getLore())) {
+ LorenzColor.GREEN
+ } else {
+ LorenzColor.RED
+ }
+ }
+ }
+
+ if (shownSettingPattern.matches(inventoryName)) {
+ inInventory = true
+ val items = event.inventoryItems.filter {
+ subPageWidgetPattern.matches(it.value.getLore().lastOrNull())
+ }
+
+ for ((slot, stack) in items) {
+ highlights[slot] = if (clickToDisablePattern.anyMatches(stack.getLore())) {
+ LorenzColor.GREEN
+ } else {
+ LorenzColor.RED
+ }
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ inInventory = false
+ highlights.clear()
+ }
+
+ @SubscribeEvent
+ fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
+ if (!isEnabled()) return
+ if (!inInventory) return
+
+ event.gui.inventorySlots.inventorySlots
+ .associateWith { highlights[it.slotNumber] }
+ .forEach { (slot, color) ->
+ color?.let { slot.highlight(it) }
+ }
+ }
+
+ private fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.inventory.highlightWidgets
+}