From 8bcdd9b6de9f7fc53cfed31ab84187092ea4dc6e Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sun, 30 Jun 2024 11:54:52 +0200 Subject: Feature: Scrolling pages (#2164) --- .../config/features/inventory/InventoryConfig.java | 11 +++- .../features/inventory/PageScrollingConfig.java | 30 +++++++++ .../skyhanni/features/inventory/PageScrolling.kt | 75 ++++++++++++++++++++++ .../java/at/hannibal2/skyhanni/utils/RegexUtils.kt | 6 ++ .../utils/repopatterns/RepoPatternManager.kt | 5 ++ 5 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/inventory/PageScrollingConfig.java create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/PageScrolling.kt (limited to 'src/main/java/at/hannibal2') 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 fcdccfab7..45c0a9e98 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 @@ -57,12 +57,12 @@ public class InventoryConfig { @Expose @Category(name = "Chocolate Factory", desc = "Features to help you master the Chocolate Factory idle game.") public ChocolateFactoryConfig chocolateFactory = new ChocolateFactoryConfig(); - + @Expose @Category(name = "Craftable Item List", desc = "") @Accordion public CraftableItemListConfig craftableItemList = new CraftableItemListConfig(); - + @Expose @ConfigOption(name = "Not Clickable Items", desc = "Better not click that item.") @Accordion @@ -108,6 +108,11 @@ public class InventoryConfig { @Accordion public PocketSackInASackConfig pocketSackInASack = new PocketSackInASackConfig(); + @Expose + @ConfigOption(name = "Page Scrolling", desc = "") + @Accordion + public PageScrollingConfig pageScrolling = new PageScrollingConfig(); + @Expose @ConfigOption(name = "Item Number", desc = "Showing the item number as a stack size for these items.") @ConfigEditorDraggableList @@ -177,7 +182,7 @@ public class InventoryConfig { @Expose @ConfigOption(name = "Quick Craft Confirmation", desc = "Require Ctrl+Click to craft items that aren't often quick crafted " + - "(e.g. armor, weapons, accessories). " + + "(e.g. armor, weapons, accessories). " + "Sack items can be crafted normally." ) @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/PageScrollingConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/PageScrollingConfig.java new file mode 100644 index 000000000..098de295d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/PageScrollingConfig.java @@ -0,0 +1,30 @@ +package at.hannibal2.skyhanni.config.features.inventory; + +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; +import org.lwjgl.input.Keyboard; + +public class PageScrollingConfig { + + @Expose + @ConfigOption(name = "Enable", desc = "Enables you to scroll in any inventory with multiple pages.") + @ConfigEditorBoolean + public boolean enable = false; + + @Expose + @ConfigOption(name = "Bypass Key", desc = "When the key is held allows you to scroll even though you are over an item.") + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_LSHIFT) + public int bypassKey = Keyboard.KEY_LSHIFT; + + @Expose + @ConfigOption(name = "Invert Bypass", desc = "Inverts the behaviour of the bypass key. With this option the bypass key blocks scrolling over items instead of allowing it.") + @ConfigEditorBoolean + public boolean invertBypass = false; + + @Expose + @ConfigOption(name = "Invert Scroll", desc = "Inverts the direction of the scrolling.") + @ConfigEditorBoolean + public boolean invertScroll = false; +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/PageScrolling.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/PageScrolling.kt new file mode 100644 index 000000000..f9855d0d4 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/PageScrolling.kt @@ -0,0 +1,75 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.ToolTipData +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.fromNow +import at.hannibal2.skyhanni.utils.renderables.ScrollValue +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.input.Mouse +import kotlin.time.Duration.Companion.seconds + +@SkyHanniModule +object PageScrolling { + + private val config get() = SkyHanniMod.feature.inventory.pageScrolling + + private val repoGroup = RepoPattern.group("inventory.pagescrolling") + + private val illegalInventory by repoGroup.list( + "illegal", + "Large Chest", + "Chest", + ) + + private val forwardPattern by repoGroup.list( + "forward", + "§aNext Page", + "§aScroll Up", + "§aLevels 26 - 50", + "§aNext Page →", + ) + + private val backwardPattern by repoGroup.list( + "backward", + "§aPrevious Page", + "§aScroll Down", + "§aLevels 1 - 25", + "§a← Previous Page", + ) + + private val scroll = ScrollValue() + + private var cooldown = SimpleTimeMark.farPast() + + @SubscribeEvent + fun onLorenzTick(event: LorenzTickEvent) { + if (!isEnabled()) return + if (cooldown.isInFuture()) return + if (!scroll.isMouseEventValid()) return + + val inventoryName = InventoryUtils.openInventoryName() + if (inventoryName.isEmpty()) return + if (illegalInventory.matches(inventoryName)) return + + if (((ToolTipData.lastSlot != null) xor config.invertBypass xor config.bypassKey.isKeyHeld())) return + + val dWheel = Mouse.getEventDWheel() + if (dWheel == 0) return + val patterns = if ((dWheel > 0) xor config.invertScroll) forwardPattern else backwardPattern + val slot = InventoryUtils.getItemsInOpenChest().firstOrNull { + patterns.matches(it.stack?.displayName) + } ?: return + InventoryUtils.clickSlot(slot.slotNumber) + cooldown = 1.0.seconds.fromNow() // 1 second is not specific it is just a reasonable cooldown + } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.enable && InventoryUtils.inInventory() +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt index 927b08d54..57c6c69e5 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt @@ -56,4 +56,10 @@ object RegexUtils { } return null } + + fun Iterable.matches(string: String?): Boolean { + if (string == null) return false + return this.any { it.matches(string) } + } + } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt b/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt index 2ec62fd3f..8f55a8b1f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt @@ -213,6 +213,11 @@ object RepoPatternManager { arrayPattern.wasOverridden = false } + if (localLoading) { + setDefaultPatterns() + return + } + if (patternMap.mapTo(mutableSetOf()) { it.first } != patternMap.indices.toSet()) { logger.error("Incorrect index set for $arrayPattern") setDefaultPatterns() -- cgit