aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-04-08 18:45:11 +0200
committerGitHub <noreply@github.com>2024-04-08 18:45:11 +0200
commit878f8ee718c43d66e068f40e1c2ef7d30abb7ac4 (patch)
treea81a5d1496c2bf4f654e2874c572730fb0b1e9cd /src/main/java/at/hannibal2
parentff6dd291a0f89644508171e6b984295de20466ce (diff)
downloadskyhanni-878f8ee718c43d66e068f40e1c2ef7d30abb7ac4.tar.gz
skyhanni-878f8ee718c43d66e068f40e1c2ef7d30abb7ac4.tar.bz2
skyhanni-878f8ee718c43d66e068f40e1c2ef7d30abb7ac4.zip
Add hud element config links. (#1383)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt29
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java29
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt34
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/garden/composter/ComposterConfig.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt2
7 files changed, 90 insertions, 16 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
index 3fbf41541..65c252bae 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<IdentityCharacteristics<Any>>) {
+ 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 670ea573c..26b0a1e7d 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 class Position {
}
return deltaY;
}
+
+ public boolean canJumpToConfigOptions() {
+ return linkField != null && ConfigGuiManager.INSTANCE.getEditorInstance().getProcessedConfig().getOptionFromField(linkField) != null;
+ }
+
+ public void jumpToConfigOptions() {
+ MoulConfigEditor<Features> 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 88264e994..20491ce3e 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<Position>, 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<Position>, 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<Position>, 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 3b0f7c767..653a3a243 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.Accordion;
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 class ComposterConfig {
}
@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 class ComposterConfig {
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 584676ac1..b2360e0ca 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.FeatureToggle;
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 31b4cfc98..2d97da6b0 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 77c776043..40f6a9c94 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<T>().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.")