diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index 3fbf41541621..65c252baee34 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -1,15 +1,18 @@ package at.hannibal2.skyhanni.config import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.core.config.Position import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson import at.hannibal2.skyhanni.data.jsonobjects.local.JacobContestsJson import at.hannibal2.skyhanni.data.jsonobjects.local.KnownFeaturesJson import at.hannibal2.skyhanni.data.jsonobjects.local.VisualWordsJson import at.hannibal2.skyhanni.data.jsonobjects.other.HypixelApiTrophyFish +import at.hannibal2.skyhanni.events.LorenzEvent import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity import at.hannibal2.skyhanni.features.misc.update.UpdateManager import at.hannibal2.skyhanni.utils.FeatureTogglesByDefaultAdapter +import at.hannibal2.skyhanni.utils.IdentityCharacteristics import at.hannibal2.skyhanni.utils.KotlinTypeAdapterFactory import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzRarity @@ -29,6 +32,7 @@ import com.google.gson.TypeAdapterFactory import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonToken import com.google.gson.stream.JsonWriter +import io.github.notenoughupdates.moulconfig.annotations.ConfigLink import io.github.notenoughupdates.moulconfig.observer.PropertyTypeAdapterFactory import io.github.notenoughupdates.moulconfig.processor.BuiltinMoulConfigGuis import io.github.notenoughupdates.moulconfig.processor.ConfigProcessorDriver @@ -214,6 +218,31 @@ class ConfigManager { BuiltinMoulConfigGuis.addProcessors(processor) UpdateManager.injectConfigProcessor(processor) ConfigProcessorDriver(processor).processConfig(features) + + try { + findPositionLinks(features, mutableSetOf()) + } catch (e: Exception) { + if (LorenzEvent.isInGuardedEventHandler) + throw e + } + } + + private fun findPositionLinks(obj: Any?, slog: MutableSet>) { + if (obj == null) return + if (!obj.javaClass.name.startsWith("at.hannibal2.skyhanni.")) return + val ic = IdentityCharacteristics(obj) + if (ic in slog) return + slog.add(ic) + for (field in obj.javaClass.fields) { + field.isAccessible = true + if (field.type != Position::class.java) { + findPositionLinks(field.get(obj), slog) + continue + } + val configLink = field.getAnnotation(ConfigLink::class.java) ?: continue + val position = field.get(obj) as Position + position.setLink(configLink) + } } private fun firstLoadFile(file: File?, fileType: ConfigFileType, defaultValue: Any): Any { diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java index 670ea573c636..26b0a1e7da97 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java @@ -20,9 +20,18 @@ package at.hannibal2.skyhanni.config.core.config; import at.hannibal2.skyhanni.SkyHanniMod; +import at.hannibal2.skyhanni.config.ConfigGuiManager; +import at.hannibal2.skyhanni.config.Features; import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; +import io.github.notenoughupdates.moulconfig.gui.GuiScreenElementWrapper; +import io.github.notenoughupdates.moulconfig.gui.MoulConfigEditor; +import io.github.notenoughupdates.moulconfig.processor.ProcessedOption; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Field; public class Position { @Expose @@ -39,6 +48,8 @@ public class Position { @Expose private boolean centerY; + public transient Field linkField; + private boolean clicked = false; public String internalName = null; @@ -203,4 +214,22 @@ public int moveY(int deltaY, int objHeight) { } return deltaY; } + + public boolean canJumpToConfigOptions() { + return linkField != null && ConfigGuiManager.INSTANCE.getEditorInstance().getProcessedConfig().getOptionFromField(linkField) != null; + } + + public void jumpToConfigOptions() { + MoulConfigEditor editor = ConfigGuiManager.INSTANCE.getEditorInstance(); + if (linkField == null) return; + ProcessedOption option = editor.getProcessedConfig().getOptionFromField(linkField); + if (option == null) return; + editor.search(""); + if (!editor.goToOption(option)) return; + SkyHanniMod.Companion.setScreenToOpen(new GuiScreenElementWrapper(editor)); + } + + public void setLink(@NotNull ConfigLink configLink) throws NoSuchFieldException { + linkField = configLink.owner().getField(configLink.field()); + } } diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt index 88264e994e1d..20491ce3ea99 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt @@ -93,6 +93,12 @@ class GuiPositionEditor(private val positions: List, private val borde val location = "§7x: §e${pos.rawX}§7, y: §e${pos.rawY}§7, scale: §e${pos.scale.round(2)}" GuiRenderUtils.drawStringCentered("§b" + pos.internalName, getScaledWidth() / 2, 18) GuiRenderUtils.drawStringCentered(location, getScaledWidth() / 2, 28) + if (pos.canJumpToConfigOptions()) + GuiRenderUtils.drawStringCentered( + "§aRight-Click to open associated config options", + getScaledWidth() / 2, + 38 + ) } private fun renderRectangles(): Int { @@ -142,7 +148,6 @@ class GuiPositionEditor(private val positions: List, private val borde override fun mouseClicked(originalX: Int, priginalY: Int, mouseButton: Int) { super.mouseClicked(originalX, priginalY, mouseButton) - if (mouseButton != 0) return val mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth val mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1 @@ -152,19 +157,20 @@ class GuiPositionEditor(private val positions: List, private val borde val elementHeight = position.getDummySize().y val x = position.getAbsX() val y = position.getAbsY() - if (!position.clicked && - GuiRenderUtils.isPointInRect( - - mouseX, - mouseY, - x - border, - y - border, - elementWidth + border * 2, - elementHeight + border * 2 - - ) - - ) { + val isHovered = GuiRenderUtils.isPointInRect( + mouseX, + mouseY, + x - border, + y - border, + elementWidth + border * 2, + elementHeight + border * 2 + ) + if (!isHovered) continue + if (mouseButton == 1) { + position.jumpToConfigOptions() + break + } + if (!position.clicked && mouseButton == 0) { clickedPos = i position.clicked = true grabbedX = mouseX diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/composter/ComposterConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/composter/ComposterConfig.java index 3b0f7c767239..653a3a243459 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/composter/ComposterConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/composter/ComposterConfig.java @@ -8,6 +8,7 @@ import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; +import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; public class ComposterConfig { @Expose @@ -86,9 +87,11 @@ public String toString() { } @Expose + @ConfigLink(owner = ComposterConfig.class, field = "overlay") public Position overlayOrganicMatterPos = new Position(140, 152, false, true); @Expose + @ConfigLink(owner = ComposterConfig.class, field = "overlay") public Position overlayFuelExtrasPos = new Position(-320, 152, false, true); @Expose @@ -158,8 +161,10 @@ public String toString() { public NotifyLowConfig notifyLow = new NotifyLowConfig(); @Expose + @ConfigLink(owner = ComposterConfig.class, field = "displayEnabled") public Position displayPos = new Position(-390, 10, false, true); @Expose + @ConfigLink(owner = ComposterConfig.class, field = "displayEnabled") public Position outsideGardenPos = new Position(-363, 13, false, true); } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java index 584676ac1419..b2360e0caf0e 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.config.core.config.Position; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; public class SprayConfig { @@ -24,6 +25,7 @@ public class SprayConfig { public boolean drawPlotsBorderWhenInHands = true; @Expose + @ConfigLink(owner = SprayConfig.class, field = "pestWhenSelector") public Position position = new Position(315, -200, 2.3f); @Expose @@ -54,5 +56,6 @@ public class SprayConfig { public boolean expiryNotification = true; @Expose + @ConfigLink(owner = SprayConfig.class, field = "displayEnabled") public Position displayPosition = new Position(390, 75, false, true); } diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt index 31b4cfc98901..2d97da6b0e66 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt @@ -6,6 +6,8 @@ import at.hannibal2.skyhanni.mixins.hooks.setValue import at.hannibal2.skyhanni.mixins.transformers.AccessorEventBus import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.launchwrapper.Launch import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.eventhandler.Event import net.minecraftforge.fml.common.eventhandler.IEventListener @@ -25,7 +27,7 @@ abstract class LorenzEvent : Event() { return 0 } } - val isInGuardedEventHandler get() = eventHandlerDepth > 0 + val isInGuardedEventHandler get() = eventHandlerDepth > 0 || LorenzUtils.isInDevEnvironment() } fun postAndCatchAndBlock( diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 77c776043ffe..40f6a9c94932 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -333,7 +333,7 @@ object LorenzUtils { enumValues().joinToString("|", transform = transform) // TODO move to val by lazy - fun isInDevEnvironment() = Launch.blackboard["fml.deobfuscatedEnvironment"] as Boolean + fun isInDevEnvironment() = ((Launch.blackboard ?: mapOf())["fml.deobfuscatedEnvironment"] as Boolean?) ?: true fun shutdownMinecraft(reason: String? = null) { System.err.println("SkyHanni-${SkyHanniMod.version} forced the game to shutdown.")