aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
authorThunderblade73 <85900443+Thunderblade73@users.noreply.github.com>2024-09-07 19:59:58 +0200
committerGitHub <noreply@github.com>2024-09-07 19:59:58 +0200
commit83d48c6aeee1656c5a6966839a1951e67fccbc53 (patch)
treea2c94427ba09763f36cb495ea91ffc4111ab322b /src/main/java/at/hannibal2
parent4663ebc4c9d5ef6ed890eced49d90dd8e3589fb5 (diff)
downloadskyhanni-83d48c6aeee1656c5a6966839a1951e67fccbc53.tar.gz
skyhanni-83d48c6aeee1656c5a6966839a1951e67fccbc53.tar.bz2
skyhanni-83d48c6aeee1656c5a6966839a1951e67fccbc53.zip
Feature: Display Tab Widgets (#1276)
Co-authored-by: Cal <cwolfson58@gmail.com> 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.kt21
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/core/config/PositionList.kt47
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/gui/GUIConfig.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/gui/TabWidgetConfig.java40
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/model/TabWidget.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/gui/TabWidgetDisplay.kt79
7 files changed, 191 insertions, 9 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
index db70f7e89..4ac3f7925 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
@@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.config
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.core.config.Position
+import at.hannibal2.skyhanni.config.core.config.PositionList
import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson
import at.hannibal2.skyhanni.data.jsonobjects.local.JacobContestsJson
import at.hannibal2.skyhanni.data.jsonobjects.local.KnownFeaturesJson
@@ -39,7 +40,6 @@ import java.nio.file.StandardCopyOption
import java.util.EnumMap
import kotlin.concurrent.fixedRateTimer
import kotlin.reflect.KMutableProperty0
-import kotlin.reflect.KMutableProperty1
private fun GsonBuilder.registerIfBeta(create: TypeAdapterFactory): GsonBuilder {
return if (LorenzUtils.isBetaVersion()) {
@@ -66,8 +66,7 @@ class ConfigManager {
private fun setConfigHolder(type: ConfigFileType, value: Any) {
require(value.javaClass == type.clazz)
- @Suppress("UNCHECKED_CAST")
- (type.property as KMutableProperty0<Any>).set(value)
+ @Suppress("UNCHECKED_CAST") (type.property as KMutableProperty0<Any>).set(value)
(jsonHolder as MutableMap<ConfigFileType, Any>)[type] = value
}
@@ -96,8 +95,7 @@ class ConfigManager {
try {
findPositionLinks(features, mutableSetOf())
} catch (e: Exception) {
- if (LorenzEvent.isInGuardedEventHandler)
- throw e
+ if (LorenzEvent.isInGuardedEventHandler) throw e
}
}
@@ -125,7 +123,7 @@ class ConfigManager {
var missingConfigLink = false
for (field in obj.javaClass.fields) {
field.isAccessible = true
- if (field.type != Position::class.java) {
+ if (field.type != Position::class.java && field.type != PositionList::class.java) {
findPositionLinks(field.get(obj), slog)
continue
}
@@ -141,8 +139,13 @@ class ConfigManager {
}
continue
}
- val position = field.get(obj) as Position
- position.setLink(configLink)
+ if (field.type == Position::class.java) {
+ val position = field.get(obj) as Position
+ position.setLink(configLink)
+ } else if (field.type == PositionList::class.java) {
+ val list = field.get(obj) as PositionList
+ list.setLink(configLink)
+ }
}
if (missingConfigLink) {
println("")
@@ -245,7 +248,7 @@ class ConfigManager {
unit.toPath(),
file.toPath(),
StandardCopyOption.REPLACE_EXISTING,
- StandardCopyOption.ATOMIC_MOVE
+ StandardCopyOption.ATOMIC_MOVE,
)
} catch (e: AccessDeniedException) {
if (loop == 5) {
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 d0112766a..eb37131b1 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
@@ -56,6 +56,10 @@ public class Position {
private boolean clicked = false;
public String internalName = null;
+ public Position() {
+ this(0, 0);
+ }
+
public Position(int x, int y) {
this(x, y, false, false);
}
diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/PositionList.kt b/src/main/java/at/hannibal2/skyhanni/config/core/config/PositionList.kt
new file mode 100644
index 000000000..c33f54293
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/PositionList.kt
@@ -0,0 +1,47 @@
+package at.hannibal2.skyhanni.config.core.config
+
+import io.github.notenoughupdates.moulconfig.annotations.ConfigLink
+
+class PositionList() : ArrayList<Position>(), MutableList<Position> {
+
+ constructor(init: Collection<Position>) : this() {
+ this.addAll(init)
+ }
+
+ constructor(size: Int) : this() {
+ this.addAll((0..<size).map { Position() })
+ }
+
+ @Throws(NoSuchFieldException::class)
+ fun setLink(configLink: ConfigLink) {
+ this.configLink = configLink
+ forEach {
+ it.setLink(configLink)
+ }
+ }
+
+ private var configLink: ConfigLink? = null
+
+ override fun add(element: Position): Boolean {
+ if (configLink != null) {
+ element.setLink(configLink!!)
+ }
+ return super.add(element)
+ }
+
+ override fun addAll(elements: Collection<Position>): Boolean {
+ if (configLink != null) {
+ elements.forEach {
+ it.setLink(configLink!!)
+ }
+ }
+ return super.addAll(elements)
+ }
+
+ override fun set(index: Int, element: Position): Position {
+ if (configLink != null) {
+ element.setLink(configLink!!)
+ }
+ return super.set(index, element)
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/gui/GUIConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/gui/GUIConfig.java
index 6355857f5..74ab755c9 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/gui/GUIConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/gui/GUIConfig.java
@@ -87,6 +87,11 @@ public class GUIConfig {
public TextBoxConfig customTextBox = new TextBoxConfig();
@Expose
+ @ConfigOption(name = "Tab Widget", desc = "")
+ @Accordion
+ public TabWidgetConfig tabWidget = new TabWidgetConfig();
+
+ @Expose
@ConfigOption(name = "In-Game Date", desc = "")
@Accordion
public InGameDateConfig inGameDate = new InGameDateConfig();
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/gui/TabWidgetConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/gui/TabWidgetConfig.java
new file mode 100644
index 000000000..2d4b27cb1
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/gui/TabWidgetConfig.java
@@ -0,0 +1,40 @@
+package at.hannibal2.skyhanni.config.features.gui;
+
+import at.hannibal2.skyhanni.config.FeatureToggle;
+import at.hannibal2.skyhanni.config.core.config.PositionList;
+import at.hannibal2.skyhanni.features.gui.TabWidgetDisplay;
+import com.google.gson.annotations.Expose;
+import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
+import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList;
+import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorInfoText;
+import io.github.notenoughupdates.moulconfig.annotations.ConfigLink;
+import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TabWidgetConfig {
+
+ @Expose
+ @ConfigOption(name = "Enabled", desc = "Enables the gui elements for the selected widgets.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean enabled = false;
+
+ @ConfigOption(name = "Not working Info", desc = "If the information isn't shown in the tablist it won't show anything. Use /widget to turn on the information you need.")
+ @ConfigEditorInfoText
+ public String text1;
+
+ @ConfigOption(name = "Enable Info", desc = "Drag only one new value at time into the list, since the default locations are all the same.")
+ @ConfigEditorInfoText
+ public String text2;
+
+ @Expose
+ @ConfigOption(name = "Widgets", desc = "")
+ @ConfigEditorDraggableList
+ public List<TabWidgetDisplay> display = new ArrayList<>();
+
+ @Expose
+ @ConfigLink(owner = TabWidgetConfig.class, field = "enabled")
+ public PositionList displayPositions = new PositionList(TabWidgetDisplay.getEntries().size());
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/model/TabWidget.kt b/src/main/java/at/hannibal2/skyhanni/data/model/TabWidget.kt
index cd72264f3..523121b37 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/model/TabWidget.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/model/TabWidget.kt
@@ -307,6 +307,10 @@ enum class TabWidget(
// language=RegExp
"Scrap: (?:§.)*(?<amount>\\d)(?:§.)*/(?:§.)*\\d",
),
+ EVENT_TRACKERS(
+ // language=RegExp
+ "§e§lEvent Trackers:",
+ )
;
diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/TabWidgetDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/TabWidgetDisplay.kt
new file mode 100644
index 000000000..2e598923d
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/gui/TabWidgetDisplay.kt
@@ -0,0 +1,79 @@
+package at.hannibal2.skyhanni.features.gui
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.core.config.Position
+import at.hannibal2.skyhanni.data.model.TabWidget
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.ProfileJoinEvent
+import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
+import at.hannibal2.skyhanni.test.command.ErrorManager
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
+import at.hannibal2.skyhanni.utils.StringUtils.allLettersFirstUppercase
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+enum class TabWidgetDisplay(private val configName: String?, vararg val widgets: TabWidget) {
+ SOULFLOW(null, TabWidget.SOULFLOW),
+ COINS("Bank and Interest", TabWidget.BANK, TabWidget.INTEREST),
+ SB_LEVEL("Skyblock Level", TabWidget.SB_LEVEL),
+ PROFILE(null, TabWidget.PROFILE),
+ PLAYER_LIST("Players", TabWidget.PLAYER_LIST),
+ PET(null, TabWidget.PET),
+ PET_TRAINING("Pet Upgrade Info", TabWidget.PET_SITTER, TabWidget.PET_TRAINING),
+ STATS(null, TabWidget.STATS, TabWidget.DUNGEON_SKILLS_AND_STATS),
+ DUNGEON_TEAM("Dungeon Info about every person", TabWidget.DUNGEON_PARTY),
+ DUNGEON_PUZZLE("Dungeon Info about puzzles", TabWidget.DUNGEON_PUZZLE),
+ DUNGEON_OVERALL("Dungeon General Info (very long)", TabWidget.DUNGEON_STATS),
+ BESTIARY(null, TabWidget.BESTIARY),
+ DRAGON("Dragon Fight Info", TabWidget.DRAGON),
+ PROTECTOR("Protector State", TabWidget.PROTECTOR),
+ SHEN_RIFT("Shen's Auction inside the Rift", TabWidget.RIFT_SHEN),
+ MINION("Minion Info", TabWidget.MINION),
+ COLLECTION(null, TabWidget.COLLECTION),
+ TIMERS(null, TabWidget.TIMERS),
+ FIRE_SALE(null, TabWidget.FIRE_SALE),
+ RAIN("Park Rain", TabWidget.RAIN),
+ ;
+
+ val position get() = config.displayPositions[ordinal]
+
+ override fun toString(): String {
+ return configName ?: name.lowercase().allLettersFirstUppercase()
+ }
+
+ @SkyHanniModule
+ companion object {
+
+ private val config get() = SkyHanniMod.feature.gui.tabWidget
+
+ private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
+ if (!isEnabled()) return
+ if (config?.displayPositions == null) return
+ config.display.forEach { widget ->
+ widget.position.renderStrings(
+ widget.widgets.flatMap { it.lines },
+ posLabel = "Display Widget: ${widget.name}",
+ )
+ }
+ }
+
+ @SubscribeEvent
+ fun onJoin(event: ProfileJoinEvent) {
+ // Validation that the displayPositions in the config is correct
+ val sizeDiff = TabWidgetDisplay.entries.size - config.displayPositions.size
+ if (sizeDiff == 0) return
+ if (sizeDiff < 0) {
+ ErrorManager.skyHanniError(
+ "Invalid State of config.displayPositions",
+ "Display" to TabWidgetDisplay.entries,
+ "Positions" to config.displayPositions,
+ )
+ } else {
+ config.displayPositions.addAll(generateSequence { Position() }.take(sizeDiff))
+ }
+ }
+ }
+}