From 83efbb3341edc3266bc2a4b89b3570c1a303ccba Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Fri, 18 Oct 2024 18:01:39 +0200 Subject: Improvement: Custom Scoreboard Refactor (#2162) Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Co-authored-by: Empa <42304516+ItsEmpa@users.noreply.github.com> Co-authored-by: Cal Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: ItsEmpa --- .../java/at/hannibal2/skyhanni/api/SkillAPI.kt | 2 +- .../skyhanni/config/ConfigUpdaterMigrator.kt | 2 +- .../gui/customscoreboard/ChunkedStatsConfig.java | 4 +- .../customscoreboard/CustomScoreboardConfig.java | 20 +- .../gui/customscoreboard/DisplayConfig.java | 14 +- .../gui/customscoreboard/EventsConfig.java | 11 +- .../features/gui/customscoreboard/PartyConfig.java | 7 +- .../gui/customscoreboard/TitleAndFooterConfig.java | 26 +- .../java/at/hannibal2/skyhanni/data/HypixelData.kt | 18 +- .../java/at/hannibal2/skyhanni/data/MaxwellAPI.kt | 15 +- .../java/at/hannibal2/skyhanni/data/MiningAPI.kt | 17 +- .../java/at/hannibal2/skyhanni/data/WinterAPI.kt | 3 + .../at/hannibal2/skyhanni/data/model/TabWidget.kt | 2 +- .../skyhanni/features/combat/SpidersDenAPI.kt | 21 +- .../features/gui/customscoreboard/ChunkedStat.kt | 81 -- .../gui/customscoreboard/ChunkedStatsLine.kt | 112 +++ .../gui/customscoreboard/CustomScoreboard.kt | 248 ++---- .../customscoreboard/CustomScoreboardConfigFix.kt | 119 +++ .../gui/customscoreboard/CustomScoreboardUtils.kt | 76 +- .../customscoreboard/ScoreboardConfigElement.kt | 125 +++ .../ScoreboardConfigEventElement.kt | 98 +++ .../gui/customscoreboard/ScoreboardElements.kt | 863 --------------------- .../gui/customscoreboard/ScoreboardEvent.kt | 576 -------------- .../gui/customscoreboard/ScoreboardLine.kt | 18 + .../gui/customscoreboard/ScoreboardPattern.kt | 205 +++-- .../gui/customscoreboard/UnknownLinesHandler.kt | 23 +- .../customscoreboard/elements/ScoreboardElement.kt | 33 + .../elements/ScoreboardElementBank.kt | 26 + .../elements/ScoreboardElementBits.kt | 32 + .../elements/ScoreboardElementChunkedStats.kt | 19 + .../elements/ScoreboardElementCold.kt | 25 + .../elements/ScoreboardElementCookie.kt | 24 + .../elements/ScoreboardElementCopper.kt | 27 + .../elements/ScoreboardElementDate.kt | 12 + .../elements/ScoreboardElementEmptyLine.kt | 9 + .../elements/ScoreboardElementEvents.kt | 19 + .../elements/ScoreboardElementFooter.kt | 18 + .../elements/ScoreboardElementGems.kt | 25 + .../elements/ScoreboardElementHeat.kt | 24 + .../elements/ScoreboardElementIsland.kt | 13 + .../elements/ScoreboardElementLobbyCode.kt | 16 + .../elements/ScoreboardElementLocation.kt | 17 + .../elements/ScoreboardElementMayor.kt | 59 ++ .../elements/ScoreboardElementMotes.kt | 25 + .../elements/ScoreboardElementNorthStars.kt | 25 + .../elements/ScoreboardElementObjective.kt | 29 + .../elements/ScoreboardElementParty.kt | 40 + .../elements/ScoreboardElementPlayerAmount.kt | 20 + .../elements/ScoreboardElementPowder.kt | 50 ++ .../elements/ScoreboardElementPower.kt | 24 + .../elements/ScoreboardElementProfile.kt | 15 + .../elements/ScoreboardElementPurse.kt | 30 + .../elements/ScoreboardElementQuiver.kt | 48 ++ .../elements/ScoreboardElementSlayer.kt | 19 + .../elements/ScoreboardElementSoulflow.kt | 23 + .../elements/ScoreboardElementTime.kt | 23 + .../elements/ScoreboardElementTitle.kt | 31 + .../elements/ScoreboardElementTuning.kt | 42 + .../elements/ScoreboardElementUnknown.kt | 16 + .../elements/ScoreboardElementVisiting.kt | 20 + .../gui/customscoreboard/events/ScoreboardEvent.kt | 5 + .../events/ScoreboardEventActiveTablist.kt | 31 + .../events/ScoreboardEventAnniversary.kt | 13 + .../events/ScoreboardEventBroodmother.kt | 15 + .../events/ScoreboardEventCarnival.kt | 35 + .../events/ScoreboardEventDamage.kt | 23 + .../events/ScoreboardEventDarkAuction.kt | 27 + .../customscoreboard/events/ScoreboardEventDojo.kt | 28 + .../events/ScoreboardEventDungeons.kt | 29 + .../events/ScoreboardEventEssence.kt | 13 + .../events/ScoreboardEventFlightDuration.kt | 22 + .../events/ScoreboardEventGarden.kt | 19 + .../events/ScoreboardEventJacobContest.kt | 25 + .../events/ScoreboardEventJacobMedals.kt | 17 + .../events/ScoreboardEventKuudra.kt | 27 + .../events/ScoreboardEventMagmaBoss.kt | 32 + .../events/ScoreboardEventMining.kt | 74 ++ .../events/ScoreboardEventNewYear.kt | 13 + .../events/ScoreboardEventQueue.kt | 20 + .../events/ScoreboardEventRedstone.kt | 17 + .../customscoreboard/events/ScoreboardEventRift.kt | 30 + .../events/ScoreboardEventServerClose.kt | 14 + .../events/ScoreboardEventSpooky.kt | 29 + .../events/ScoreboardEventStartingSoonTablist.kt | 25 + .../events/ScoreboardEventTrapper.kt | 25 + .../events/ScoreboardEventVoting.kt | 26 + .../events/ScoreboardEventWinter.kt | 26 + .../features/inventory/AuctionOutbidWarning.kt | 2 +- .../at/hannibal2/skyhanni/utils/CollectionUtils.kt | 23 +- .../at/hannibal2/skyhanni/utils/LorenzUtils.kt | 5 +- .../hannibal2/skyhanni/utils/SizeLimitedCache.kt | 37 + .../at/hannibal2/skyhanni/utils/SizeLimitedSet.kt | 35 + .../at/hannibal2/skyhanni/utils/StringUtils.kt | 53 +- .../hannibal2/skyhanni/utils/TimeLimitedCache.kt | 10 +- .../at/hannibal2/skyhanni/utils/TimeLimitedSet.kt | 5 +- 95 files changed, 2467 insertions(+), 1947 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ChunkedStat.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ChunkedStatsLine.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboardConfigFix.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardConfigElement.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardConfigEventElement.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardEvent.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardLine.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElement.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementBank.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementBits.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementChunkedStats.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementCold.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementCookie.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementCopper.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementDate.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementEmptyLine.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementEvents.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementFooter.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementGems.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementHeat.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementIsland.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementLobbyCode.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementLocation.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementMayor.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementMotes.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementNorthStars.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementObjective.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementParty.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementPlayerAmount.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementPowder.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementPower.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementProfile.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementPurse.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementQuiver.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementSlayer.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementSoulflow.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementTime.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementTitle.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementTuning.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementUnknown.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/elements/ScoreboardElementVisiting.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEvent.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventActiveTablist.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventAnniversary.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventBroodmother.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventCarnival.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventDamage.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventDarkAuction.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventDojo.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventDungeons.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventEssence.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventFlightDuration.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventGarden.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventJacobContest.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventJacobMedals.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventKuudra.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventMagmaBoss.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventMining.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventNewYear.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventQueue.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventRedstone.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventRift.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventServerClose.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventSpooky.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventStartingSoonTablist.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventTrapper.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventVoting.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/events/ScoreboardEventWinter.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/SizeLimitedCache.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/SizeLimitedSet.kt diff --git a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt index 95e39d1f7..aa930adb1 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt @@ -28,8 +28,8 @@ import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.NumberUtil.formatLongOrUserError import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary +import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.SimpleTimeMark -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index 8228ae025..93c7d3407 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive object ConfigUpdaterMigrator { val logger = LorenzLogger("ConfigMigration") - const val CONFIG_VERSION = 62 + const val CONFIG_VERSION = 63 fun JsonElement.at(chain: List, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/ChunkedStatsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/ChunkedStatsConfig.java index 4293dd168..8e0941d30 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/ChunkedStatsConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/ChunkedStatsConfig.java @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.config.features.gui.customscoreboard; -import at.hannibal2.skyhanni.features.gui.customscoreboard.ChunkedStat; +import at.hannibal2.skyhanni.features.gui.customscoreboard.ChunkedStatsLine; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider; @@ -17,7 +17,7 @@ public class ChunkedStatsConfig { desc = "Select the stats you want to display chunked on the scoreboard." ) @ConfigEditorDraggableList - public List chunkedStats = new ArrayList<>(ChunkedStat.getEntries()); + public List chunkedStats = new ArrayList<>(ChunkedStatsLine.getEntries()); @Expose @ConfigOption( diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/CustomScoreboardConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/CustomScoreboardConfig.java index 38a749f35..944b44cd4 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/CustomScoreboardConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/CustomScoreboardConfig.java @@ -2,7 +2,8 @@ package at.hannibal2.skyhanni.config.features.gui.customscoreboard; import at.hannibal2.skyhanni.config.FeatureToggle; import at.hannibal2.skyhanni.config.core.config.Position; -import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardElement; +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboard; +import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardConfigElement; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.Accordion; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; @@ -28,17 +29,14 @@ public class CustomScoreboardConfig { @Expose @ConfigOption( name = "Appearance", - desc = "Drag text to change the appearance of the advanced scoreboard." // supporting both custom & advanced search + desc = "Drag text to change the appearance of the advanced scoreboard." ) - @ConfigEditorDraggableList() - public List scoreboardEntries = new ArrayList<>(ScoreboardElement.defaultOption); + @ConfigEditorDraggableList + public Property> scoreboardEntries = Property.of(new ArrayList<>(ScoreboardConfigElement.defaultOptions)); @ConfigOption(name = "Reset Appearance", desc = "Reset the appearance of the advanced scoreboard.") @ConfigEditorButton(buttonText = "Reset") - public Runnable reset = () -> { - scoreboardEntries.clear(); - scoreboardEntries.addAll(ScoreboardElement.defaultOption); - }; + public Runnable reset = CustomScoreboard::resetAppearance; @Expose @ConfigOption(name = "Display Options", desc = "") @@ -56,7 +54,11 @@ public class CustomScoreboardConfig { public InformationFilteringConfig informationFiltering = new InformationFilteringConfig(); @Expose - @ConfigOption(name = "Unknown Lines warning", desc = "Give a chat warning when unknown lines are found in the scoreboard.") + @ConfigOption( + name = "Unknown Lines warning", + desc = "Give a chat warning when unknown lines are found in the scoreboard." + + "\n§cReporting these in the Discord Server are very important, so we can know what lines are missing." + ) @ConfigEditorBoolean public boolean unknownLinesWarning = true; diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/DisplayConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/DisplayConfig.java index 2f0eb502e..39d8c09bf 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/DisplayConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/DisplayConfig.java @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.config.features.gui.customscoreboard; import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.utils.RenderUtils; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.Accordion; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; @@ -51,7 +52,6 @@ public class DisplayConfig { @Accordion public TitleAndFooterConfig titleAndFooter = new TitleAndFooterConfig(); - @Expose @ConfigOption(name = "Hide Vanilla Scoreboard", desc = "Hide the vanilla scoreboard.\n" + "§cMods that add their own scoreboard will not be affected by this setting!") @@ -145,8 +145,16 @@ public class DisplayConfig { public int lineSpacing = 10; @Expose - @ConfigOption(name = "Cache Scoreboard on Island Switch", - desc = "Will stop the Scoreboard from updating while switching islands.\nRemoves the shaking when loading data.") + @ConfigOption(name = "Text Alignment", desc = "Will align the text to the left, center or right, while not overriding certain lines, like title or footer.") + @ConfigEditorDropdown + public RenderUtils.HorizontalAlignment textAlignment = RenderUtils.HorizontalAlignment.LEFT; + + @Expose + @ConfigOption( + name = "Cache Scoreboard on Island Switch", + desc = "Will stop the Scoreboard from updating while switching islands.\n" + + "Removes the shaking when loading data." + ) @ConfigEditorBoolean public boolean cacheScoreboardOnIslandSwitch = false; } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/EventsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/EventsConfig.java index e2663bf55..b091c8e90 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/EventsConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/EventsConfig.java @@ -1,11 +1,12 @@ package at.hannibal2.skyhanni.config.features.gui.customscoreboard; -import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardEvent; +import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardConfigEventElement; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorButton; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; +import io.github.notenoughupdates.moulconfig.observer.Property; import java.util.ArrayList; import java.util.List; @@ -18,13 +19,15 @@ public class EventsConfig { desc = "Drag your list to select the priority of each event." ) @ConfigEditorDraggableList() - public List eventEntries = new ArrayList<>(ScoreboardEvent.defaultOption); + public Property> eventEntries = Property.of(new ArrayList<>(ScoreboardConfigEventElement.defaultOption)); @ConfigOption(name = "Reset Events Priority", desc = "Reset the priority of all events.") @ConfigEditorButton(buttonText = "Reset") + // TODO move into kotlin public Runnable reset = () -> { - eventEntries.clear(); - eventEntries.addAll(ScoreboardEvent.defaultOption); + eventEntries.get().clear(); + eventEntries.get().addAll(ScoreboardConfigEventElement.defaultOption); + eventEntries.notifyObservers(); }; @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/PartyConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/PartyConfig.java index 670e9b16b..5a553369f 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/PartyConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/PartyConfig.java @@ -11,7 +11,7 @@ public class PartyConfig { @ConfigOption(name = "Max Party List", desc = "Max number of party members to show in the party list (you are not included).") @ConfigEditorSlider( minValue = 1, - maxValue = 25, // why do I even set it so high + maxValue = 25, minStep = 1 ) public Property maxPartyList = Property.of(4); @@ -21,4 +21,9 @@ public class PartyConfig { "If disabled, it will only show in Dungeon Hub, Crimson Isle & Kuudra.") @ConfigEditorBoolean public boolean showPartyEverywhere = false; + + @Expose + @ConfigOption(name = "Show Party Leader", desc = "Show the party leader in the party list.") + @ConfigEditorBoolean + public boolean showPartyLeader = true; } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/TitleAndFooterConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/TitleAndFooterConfig.java index 1c3bb4304..aae9fe026 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/TitleAndFooterConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/TitleAndFooterConfig.java @@ -6,21 +6,19 @@ import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorText; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; -import io.github.notenoughupdates.moulconfig.observer.Property; public class TitleAndFooterConfig { @Expose - @ConfigOption(name = "Title and Footer Alignment", desc = "Align the title and footer in the scoreboard.") + @ConfigOption(name = "Title Alignment", desc = "Align the title in the scoreboard.") @ConfigEditorDropdown - // TODO rename to "horizontalAlignment" or "alignment" - public RenderUtils.HorizontalAlignment alignTitleAndFooter = RenderUtils.HorizontalAlignment.CENTER; + public RenderUtils.HorizontalAlignment alignTitle = RenderUtils.HorizontalAlignment.CENTER; @Expose @ConfigOption(name = "Custom Title", desc = "What should be displayed as the title of the scoreboard." + - "\nUse & for colors." + + "\nUse && for colors." + "\nUse \"\\n\" for new line.") @ConfigEditorText - public Property customTitle = Property.of("&6&lSKYBLOCK"); + public String customTitle = "&&6&&lSKYBLOCK"; @Expose @ConfigOption(name = "Use Custom Title", desc = "Use a custom title instead of the default Hypixel title.") @@ -32,10 +30,22 @@ public class TitleAndFooterConfig { @ConfigEditorBoolean public boolean useCustomTitleOutsideSkyBlock = false; + @Expose + @ConfigOption(name = "Footer Alignment", desc = "Align the footer in the scoreboard.") + @ConfigEditorDropdown + public RenderUtils.HorizontalAlignment alignFooter = RenderUtils.HorizontalAlignment.LEFT; + @Expose @ConfigOption(name = "Custom Footer", desc = "What should be displayed as the footer of the scoreboard." + - "\nUse & for colors." + + "\nUse && for colors." + + "\nUse \"\\n\" for new line.") + @ConfigEditorText + public String customFooter = "&&ewww.hypixel.net"; + + @Expose + @ConfigOption(name = "Custom Alpha Footer", desc = "What should be displayed as the footer of the scoreboard when on the Alpha Server." + + "\nUse && for colors." + "\nUse \"\\n\" for new line.") @ConfigEditorText - public Property customFooter = Property.of("&ewww.hypixel.net"); + public String customAlphaFooter = "&&ealpha.hypixel.net"; } diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index 3707d10af..20ed57276 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -485,12 +485,12 @@ object HypixelData { } private fun checkIsland(event: WidgetUpdateEvent) { - val islandType: IslandType + val newIsland: IslandType val foundIsland: String if (event.isClear()) { TabListData.fullyLoaded = false - islandType = IslandType.NONE + newIsland = IslandType.NONE foundIsland = "" } else { @@ -498,19 +498,21 @@ object HypixelData { // Can not use color coding, because of the color effect (§f§lSKYB§6§lL§e§lOCK§A§L GUEST) val guesting = guestPattern.matches(ScoreboardData.objectiveTitle.removeColor()) foundIsland = TabWidget.AREA.matchMatcherFirstLine { group("island").removeColor() } ?: "" - islandType = getIslandType(foundIsland, guesting) + newIsland = getIslandType(foundIsland, guesting) } // TODO don't send events when one of the arguments is none, at least when not on sb anymore - if (skyBlockIsland != islandType) { - IslandChangeEvent(islandType, skyBlockIsland).postAndCatch() - if (islandType == IslandType.UNKNOWN) { + if (skyBlockIsland != newIsland) { + val oldIsland = skyBlockIsland + skyBlockIsland = newIsland + IslandChangeEvent(newIsland, oldIsland).postAndCatch() + + if (newIsland == IslandType.UNKNOWN) { ChatUtils.debug("Unknown island detected: '$foundIsland'") loggerIslandChange.log("Unknown: '$foundIsland'") } else { - loggerIslandChange.log(islandType.name) + loggerIslandChange.log(newIsland.name) } - skyBlockIsland = islandType if (TabListData.fullyLoaded) { TabWidget.reSendEvents() } diff --git a/src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt index 776a7c808..5fd644818 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt @@ -6,7 +6,7 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.features.dungeon.DungeonAPI import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboard -import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardElement +import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardConfigElement import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils @@ -135,14 +135,11 @@ object MaxwellAPI { chatPowerPattern.tryReadPower(message) chatPowerUnlockedPattern.tryReadPower(message) - tuningAutoAssignedPattern.matchMatcher(event.message) { - if (tunings.isNullOrEmpty()) return - val tuningsInScoreboard = ScoreboardElement.TUNING in CustomScoreboard.config.scoreboardEntries - if (tuningsInScoreboard) { - ChatUtils.chat( - "Talk to Maxwell and open the Tuning Page again to update the tuning data in scoreboard.", - ) - } + if (!tuningAutoAssignedPattern.matches(event.message)) return + if (tunings.isNullOrEmpty()) return + with(CustomScoreboard.config) { + if (!enabled.get() || ScoreboardConfigElement.TUNING !in scoreboardEntries.get()) return + ChatUtils.chat("Talk to Maxwell and open the Tuning Page again to update the tuning data in scoreboard.") } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt index 54d186ae5..fbe304098 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt @@ -14,7 +14,6 @@ import at.hannibal2.skyhanni.events.ServerBlockChangeEvent import at.hannibal2.skyhanni.events.mining.OreMinedEvent import at.hannibal2.skyhanni.events.player.PlayerDeathEvent import at.hannibal2.skyhanni.events.skyblock.ScoreboardAreaChangeEvent -import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern import at.hannibal2.skyhanni.features.mining.OreBlock import at.hannibal2.skyhanni.features.mining.isTitanium import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule @@ -46,12 +45,20 @@ object MiningAPI { private val glaciteAreaPattern by group.pattern("area.glacite", "Glacite Tunnels|Great Glacite Lake") private val dwarvenBaseCampPattern by group.pattern("area.basecamp", "Dwarven Base Camp") - // TODO add regex test + // TODO add regex tests private val coldResetPattern by group.pattern( "cold.reset", "§6The warmth of the campfire reduced your §r§b❄ Cold §r§6to §r§a0§r§6!|§c ☠ §r§7You froze to death§r§7\\.", ) + /** + * REGEX-TEST: Cold: §b-1❄ + */ + val coldPattern by group.pattern( + "cold", + "(?:§.)*Cold: §.(?-?\\d+)❄", + ) + private val pickbobulusGroup = group.group("pickobulus") /** @@ -150,11 +157,15 @@ object MiningAPI { IslandType.SPIDER_DEN, ) + fun inAdvancedMiningIsland() = inAnyIsland(IslandType.DWARVEN_MINES, IslandType.CRYSTAL_HOLLOWS, IslandType.MINESHAFT) + + fun inMiningIsland() = inAdvancedMiningIsland() || inAnyIsland(IslandType.GOLD_MINES, IslandType.DEEP_CAVERNS) + fun inColdIsland() = inAnyIsland(IslandType.DWARVEN_MINES, IslandType.MINESHAFT) @SubscribeEvent fun onScoreboardChange(event: ScoreboardUpdateEvent) { - val newCold = ScoreboardPattern.coldPattern.firstMatcher(event.scoreboard) { + val newCold = coldPattern.firstMatcher(event.scoreboard) { group("cold").toInt().absoluteValue } ?: return diff --git a/src/main/java/at/hannibal2/skyhanni/data/WinterAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/WinterAPI.kt index 9e3a7a9e6..4b430b9c5 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/WinterAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/WinterAPI.kt @@ -1,9 +1,12 @@ package at.hannibal2.skyhanni.data +import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.TimeUtils import java.time.Month object WinterAPI { + fun inWorkshop() = IslandType.WINTER.isInIsland() + fun isDecember() = TimeUtils.getCurrentLocalDate().month == Month.DECEMBER } 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 e5939c3f7..7a57de667 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/model/TabWidget.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/model/TabWidget.kt @@ -95,7 +95,7 @@ enum class TabWidget( ), EVENT( // language=RegExp - "(?:§.)*Event: (?:§.)*(?.*)", + "(?:§.)*Event: (?(?:§.)*)(?.*)", ), SKILLS( // language=RegExp diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/SpidersDenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/SpidersDenAPI.kt index af1dd8430..8b9ff035e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/SpidersDenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/SpidersDenAPI.kt @@ -1,11 +1,26 @@ package at.hannibal2.skyhanni.features.combat +import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.ScoreboardData -import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule -import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.RegexUtils.anyMatches +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @SkyHanniModule object SpidersDenAPI { - fun isAtTopOfNest(): Boolean = ScoreboardData.sidebarLinesFormatted.any { ScoreboardPattern.broodmotherPattern.matches(it) } + + private val repoGroup = RepoPattern.group("combat.spidersden") + + /** + * REGEX-TEST: §4Broodmother§7: §6Soon + */ + val broodmotherPattern by repoGroup.pattern( + "broodmother", + "§4Broodmother§7: §[e64](?:Slain|Dormant|Soon|Awakening|Imminent|Alive!)", + ) + + fun inSpidersDen() = IslandType.SPIDER_DEN.isInIsland() + + fun isAtTopOfNest() = inSpidersDen() && broodmotherPattern.anyMatches(ScoreboardData.sidebarLinesFormatted) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ChunkedStat.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ChunkedStat.kt deleted file mode 100644 index 4acfcb81d..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ChunkedStat.kt +++ /dev/null @@ -1,81 +0,0 @@ -package at.hannibal2.skyhanni.features.gui.customscoreboard - -import at.hannibal2.skyhanni.data.MiningAPI -import at.hannibal2.skyhanni.data.PurseAPI -import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboard.chunkedConfig -import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboard.informationFilteringConfig -import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.formatNum -import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getBank -import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getBits -import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getBitsLine -import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getBitsToClaim -import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getCopper -import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getGems -import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getHeat -import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getMotes -import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getNorthStars - -private val hideEmptyLines get() = informationFilteringConfig.hideEmptyLines - -enum class ChunkedStat( - private val displayPair: () -> String, - val showWhen: () -> Boolean, - private val configLine: String, -) { - PURSE( - displayPair = { "§6${PurseAPI.currentPurse.formatNum()}" }, - showWhen = { !(hideEmptyLines && PurseAPI.currentPurse.toInt() == 0) && ScoreboardElement.PURSE.showWhen() }, - configLine = "§6Purse", - ), - MOTES( - displayPair = { "§b${getMotes()}" }, - showWhen = { !(hideEmptyLines && getMotes() == "0") && ScoreboardElement.MOTES.showWhen() }, - configLine = "§dMotes", - ), - BANK( - displayPair = { "§6${getBank()}" }, - showWhen = { !(hideEmptyLines && (getBank() == "0" || getBank() == "0§7 / §60")) && ScoreboardElement.BANK.showWhen() }, - configLine = "§6Bank", - ), - BITS( - displayPair = { getBitsLine() }, - showWhen = { !(hideEmptyLines && getBits() == "0" && getBitsToClaim() == "0") && ScoreboardElement.BITS.showWhen() }, - configLine = "§bBits", - ), - COPPER( - displayPair = { "§c${getCopper()}" }, - showWhen = { !(hideEmptyLines && getCopper() == "0") && ScoreboardElement.COPPER.showWhen() }, - configLine = "§cCopper", - ), - GEMS( - displayPair = { "§a${getGems()}" }, - showWhen = { !(hideEmptyLines && getGems() == "0") && ScoreboardElement.GEMS.showWhen() }, - configLine = "§aGems", - ), - HEAT( - displayPair = { "§c${getHeat()}" }, - showWhen = { !(hideEmptyLines && getHeat() == "§c♨ 0") && ScoreboardElement.HEAT.showWhen() }, - configLine = "§cHeat", - ), - COLD( - displayPair = { "§b${MiningAPI.cold}❄" }, - showWhen = { !(hideEmptyLines && MiningAPI.cold == 0) && ScoreboardElement.COLD.showWhen() }, - configLine = "§bCold", - ), - NORTH_STARS( - displayPair = { "§d${getNorthStars()}" }, - showWhen = { !(hideEmptyLines && getNorthStars() == "0") && ScoreboardElement.NORTH_STARS.showWhen() }, - configLine = "§dNorth Stars", - ), - ; - - override fun toString() = configLine - - companion object { - fun getChunkedStats() = chunkedConfig.chunkedStats.mapNotNull { - it.takeIf { it.showWhen() }?.displayPair?.invoke() - } - - fun shouldShowChunkedStats() = chunkedConfig.chunkedStats.any { it.showWhen() } - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ChunkedStatsLine.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ChunkedStatsLine.kt new file mode 100644 index 000000000..57000be68 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ChunkedStatsLine.kt @@ -0,0 +1,112 @@ +package at.hannibal2.skyhanni.features.gui.customscoreboard + +import at.hannibal2.skyhanni.data.MiningAPI +import at.hannibal2.skyhanni.data.PurseAPI +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboard.chunkedConfig +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboard.informationFilteringConfig +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.formatNumber +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getBank +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getBits +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getBitsAvailable +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getBitsLine +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getCopper +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getGems +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getHeat +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getMotes +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils.getNorthStars +import at.hannibal2.skyhanni.features.gui.customscoreboard.elements.ScoreboardElementBank +import at.hannibal2.skyhanni.features.gui.customscoreboard.elements.ScoreboardElementBits +import at.hannibal2.skyhanni.features.gui.customscoreboard.elements.ScoreboardElementCold +import at.hannibal2.skyhanni.features.gui.customscoreboard.elements.ScoreboardElementCopper +import at.hannibal2.skyhanni.features.gui.customscoreboard.elements.ScoreboardElementGems +import at.hannibal2.skyhanni.features.gui.customscoreboard.elements.ScoreboardElementHeat +import at.hannibal2.skyhanni.features.gui.customscoreboard.elements.ScoreboardElementMotes +import at.hannibal2.skyhanni.features.gui.customscoreboard.elements.ScoreboardElementNorthStars +import at.hannibal2.skyhanni.features.gui.customscoreboard.elements.ScoreboardElementPurse + +private val hideEmptyLines get() = informationFilteringConfig.hideEmptyLines + +enum class ChunkedStatsLine( + private val displayPair: () -> String, + private val showWhen: () -> Boolean, + private val showIsland: () -> Boolean, + private val configLine: String, +) { + PURSE( + displayPair = { "§6${formatNumber(PurseAPI.currentPurse)}" }, + showWhen = { !(hideEmptyLines && PurseAPI.currentPurse.toInt() == 0) && ScoreboardElementPurse.showWhen() }, + showIsland = { ScoreboardElementPurse.showIsland() }, + configLine = "§6Purse", + ), + MOTES( + displayPair = { "§b${getMotes()}" }, + showWhen = { !(hideEmptyLines && getMotes() == "0") && ScoreboardElementMotes.showWhen() }, + showIsland = { ScoreboardElementMotes.showIsland() }, + configLine = "§dMotes", + ), + BANK( + displayPair = { "§6${getBank()}" }, + showWhen = { !(hideEmptyLines && (getBank() == "0" || getBank() == "0§7 / §60")) && ScoreboardElementBank.showWhen() }, + showIsland = { ScoreboardElementBank.showIsland() }, + configLine = "§6Bank", + ), + BITS( + displayPair = { getBitsLine() }, + showWhen = { !(hideEmptyLines && getBits() == "0" && getBitsAvailable() == "0") && ScoreboardElementBits.showWhen() }, + showIsland = { ScoreboardElementBits.showIsland() }, + configLine = "§bBits", + ), + COPPER( + displayPair = { "§c${getCopper()}" }, + showWhen = { !(hideEmptyLines && getCopper() == "0") && ScoreboardElementCopper.showWhen() }, + showIsland = { ScoreboardElementCopper.showIsland() }, + configLine = "§cCopper", + ), + GEMS( + displayPair = { "§a${getGems()}" }, + showWhen = { !(hideEmptyLines && getGems() == "0") && ScoreboardElementGems.showWhen() }, + showIsland = { ScoreboardElementGems.showIsland() }, + configLine = "§aGems", + ), + HEAT( + displayPair = { "§c${getHeat()}" }, + showWhen = { !(hideEmptyLines && getHeat() == "§c♨ 0") && ScoreboardElementHeat.showWhen() }, + showIsland = { ScoreboardElementHeat.showIsland() }, + configLine = "§cHeat", + ), + COLD( + displayPair = { "§b${MiningAPI.cold}❄" }, + showWhen = { !(hideEmptyLines && MiningAPI.cold == 0) && ScoreboardElementCold.showWhen() }, + showIsland = { ScoreboardElementCold.showIsland() }, + configLine = "§bCold", + ), + NORTH_STARS( + displayPair = { "§d${getNorthStars()}" }, + showWhen = { !(hideEmptyLines && getNorthStars() == "0") && ScoreboardElementNorthStars.showWhen() }, + showIsland = { ScoreboardElementNorthStars.showIsland() }, + configLine = "§dNorth Stars", + ), + ; + + override fun toString() = configLine + + companion object { + + private var currentIslandStats = listOf() + + fun getChunkedStats() = buildList { + currentIslandStats.forEach { stat -> + if (stat.showWhen()) { + add(stat.displayPair.invoke()) + } + } + } + + fun shouldShowChunkedStats() = currentIslandStats.any { it.showWhen() } + + fun showChunkedStatsIsland(): Boolean { + currentIslandStats = chunkedConfig.chunkedStats.filter { it.showIsland() } + return currentIslandStats.isNotEmpty() + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt index 4a86519c3..14f311aad 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt @@ -1,28 +1,33 @@ -// -// TODO LIST -// V2 RELEASE -// - Bank API (actually maybe not, I like the current design) -// - countdown events like fishing festival + fiesta when its not on tablist -// - improve hide coin difference to also work with bits, motes, etc -// - color options in the purse etc lines -// - choose the amount of decimal places in shorten nums -// +/** + * TODO LIST + * - Bank API (actually maybe not, I like the current design) + * - countdown events like fishing festival + fiesta when its not on tablist + * - improve hide coin difference to also work with bits, motes, etc + * - color options in the purse etc lines + * - choose the amount of decimal places in shorten nums + * - heavily optimize elements and events by only updating them when absolutely needed + */ package at.hannibal2.skyhanni.features.gui.customscoreboard import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.config.enums.OutsideSbFeature import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.GuiPositionMovedEvent import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.IslandChangeEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.ScoreboardUpdateEvent +import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardLine.Companion.align +import at.hannibal2.skyhanni.features.gui.customscoreboard.elements.ScoreboardElement +import at.hannibal2.skyhanni.features.gui.customscoreboard.elements.ScoreboardElementTitle +import at.hannibal2.skyhanni.features.gui.customscoreboard.events.ScoreboardEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.CollectionUtils.takeIfNotEmpty import at.hannibal2.skyhanni.utils.ConditionalUtils import at.hannibal2.skyhanni.utils.DelayedRun.runDelayed import at.hannibal2.skyhanni.utils.LorenzUtils @@ -34,21 +39,22 @@ import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.fromNow import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.renderables.Renderable -import com.google.gson.JsonArray -import com.google.gson.JsonPrimitive import net.minecraftforge.client.GuiIngameForge import net.minecraftforge.client.event.RenderGameOverlayEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds -typealias ScoreboardElementType = Pair - @SkyHanniModule object CustomScoreboard { - private var display = emptyList() - private var cache = emptyList() + private var display: Renderable? = null + private var cache: Renderable? = null + + private var currentIslandEntries = listOf() + var currentIslandEvents = listOf() + private set + private const val GUI_NAME = "Custom Scoreboard" private var nextScoreboardUpdate = SimpleTimeMark.farFuture() @@ -56,25 +62,16 @@ object CustomScoreboard { @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { if (!isEnabled()) return - if (display.isEmpty()) return + display ?: return val render = - if (LorenzUtils.inSkyBlock && !TabListData.fullyLoaded && displayConfig.cacheScoreboardOnIslandSwitch && cache.isNotEmpty()) { - cache - } else { - display - } - - val textRenderable = Renderable.verticalContainer( - render.map { Renderable.string(it.first, horizontalAlign = it.second) }, - displayConfig.lineSpacing - 10, - horizontalAlign = HorizontalAlignment.CENTER, - verticalAlign = VerticalAlignment.CENTER, - ) + if (LorenzUtils.inSkyBlock && !TabListData.fullyLoaded && displayConfig.cacheScoreboardOnIslandSwitch && cache != null) cache + else display - val finalRenderable = RenderBackground.addBackground(textRenderable) + render ?: return - RenderBackground.updatePosition(finalRenderable) + // We want to update the background every time, so we can have a smooth transition when using chroma as the color + val finalRenderable = RenderBackground.addBackground(render) config.position.renderRenderable(finalRenderable, posLabel = GUI_NAME) } @@ -110,9 +107,9 @@ object CustomScoreboard { if (dirty || nextScoreboardUpdate.isInPast()) { nextScoreboardUpdate = 250.milliseconds.fromNow() dirty = false - display = createLines().removeEmptyLinesFromEdges() + display = createLines().removeEmptyLinesFromEdges().createRenderable() if (TabListData.fullyLoaded) { - cache = display.toList() + cache = display } } @@ -144,53 +141,47 @@ object CustomScoreboard { } private fun addAllNonSkyBlockLines() = buildList { - addAll(ScoreboardElement.TITLE.getVisiblePair()) - addAll(ScoreboardData.sidebarLinesFormatted.map { it to HorizontalAlignment.LEFT }) + addAll(ScoreboardElementTitle.getLines()) + addAll(ScoreboardData.sidebarLinesFormatted.map { it.align() }) } private fun addDefaultSkyBlockLines() = buildList { - add(ScoreboardData.objectiveTitle to displayConfig.titleAndFooter.alignTitleAndFooter) - addAll(ScoreboardData.sidebarLinesFormatted.map { it to HorizontalAlignment.LEFT }) + add(ScoreboardData.objectiveTitle align displayConfig.titleAndFooter.alignTitle) + addAll(ScoreboardData.sidebarLinesFormatted.map { it.align() }) } - private fun addCustomSkyBlockLines() = buildList { - for (element in config.scoreboardEntries) { - val lines = element.getVisiblePair() + private fun addCustomSkyBlockLines() = buildList { + for (element in currentIslandEntries) { + val lines = element.getLines() if (lines.isEmpty()) continue if ( informationFilteringConfig.hideConsecutiveEmptyLines && - lines.first().first == "" && - lastOrNull()?.first?.isEmpty() == true + lines.first().display.isEmpty() && + lastOrNull()?.display?.isEmpty() == true ) { continue } - if (lines.first().first == "") { - add("" to HorizontalAlignment.LEFT) - continue - } - - if (lines.any { it.first == "" }) { - continue - } - addAll(lines) } } - private fun List.removeEmptyLinesFromEdges(): List { - if (config.informationFiltering.hideEmptyLinesAtTopAndBottom) { - return this - .dropWhile { it.first.isEmpty() } - .dropLastWhile { it.first.isEmpty() } - } - return this - } + private fun List.createRenderable() = Renderable.verticalContainer( + map { Renderable.string(it.display, horizontalAlign = it.alignment) }, + displayConfig.lineSpacing - 10, + horizontalAlign = HorizontalAlignment.CENTER, + verticalAlign = VerticalAlignment.CENTER, + ) + + private fun List.removeEmptyLinesFromEdges(): List = + takeIf { !informationFilteringConfig.hideEmptyLinesAtTopAndBottom } + ?: dropWhile { it.display.isBlank() }.dropLastWhile { it.display.isBlank() } private var dirty = false - // Thank you Apec for showing that the ElementType of the stupid scoreboard is FUCKING HELMET WTF + // The ElementType for the Vanilla Scoreboard is called HELMET + // Thanks to APEC for showing this @SubscribeEvent fun onRenderScoreboard(event: RenderGameOverlayEvent.Post) { if (event.type == RenderGameOverlayEvent.ElementType.HELMET) { @@ -213,6 +204,12 @@ object CustomScoreboard { ) { if (!isHideVanillaScoreboardEnabled()) dirty = true } + ConditionalUtils.onToggle( + config.scoreboardEntries, + eventsConfig.eventEntries, + ) { + updateIslandEntries() + } } @SubscribeEvent @@ -222,6 +219,16 @@ object CustomScoreboard { } } + @SubscribeEvent + fun onIslandChange(event: IslandChangeEvent) { + updateIslandEntries() + } + + private fun updateIslandEntries() { + currentIslandEntries = config.scoreboardEntries.get().map { it.element }.filter { it.showIsland() } + currentIslandEvents = eventsConfig.eventEntries.get().map { it.event }.filter { it.showIsland() } + } + @SubscribeEvent fun onDebugDataCollect(event: DebugDataCollectEvent) { event.title("Custom Scoreboard") @@ -229,117 +236,34 @@ object CustomScoreboard { if (!config.enabled.get()) { add("Custom Scoreboard disabled.") } else { - ScoreboardElement.entries.map { element -> + add("Custom Scoreboard Lines:") + ScoreboardConfigElement.entries.forEach { entry -> add( - "${element.name.firstLetterUppercase()} - " + - "${element.showWhen.invoke()} - " + - "${element.getVisiblePair().map { it.first }}", + " ${entry.name.firstLetterUppercase()} - " + + "island: ${entry.element.showIsland()} - " + + "show: ${entry.element.showWhen()} - " + + "${entry.element.getLines().map { it.display }}", ) } + allUnknownLines.takeIfNotEmpty()?.let { set -> + add("Recent Unknown Lines:") + set.forEach { add(" ${it.line}") } + } } } } + @JvmStatic + fun resetAppearance() { + with(config.scoreboardEntries) { + get().clear() + get().addAll(ScoreboardConfigElement.defaultOptions) + notifyObservers() + } + } + private fun isEnabled() = (LorenzUtils.inSkyBlock || (OutsideSbFeature.CUSTOM_SCOREBOARD.isSelected() && LorenzUtils.onHypixel)) && config.enabled.get() private fun isHideVanillaScoreboardEnabled() = isEnabled() && displayConfig.hideVanillaScoreboard.get() - - @SubscribeEvent - fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - val prefix = "gui.customScoreboard" - val displayConfigPrefix = "$prefix.displayConfig" - val displayPrefix = "$prefix.display" - - event.move( - 28, - "$prefix.displayConfig.showAllActiveEvents", - "$prefix.displayConfig.eventsConfig.showAllActiveEvents", - ) - - event.move(31, "$displayConfigPrefix.arrowAmountDisplay", "$displayPrefix.arrow.amountDisplay") - event.move(31, "$displayConfigPrefix.colorArrowAmount", "$displayPrefix.arrow.colorArrowAmount") - event.move(31, "$displayConfigPrefix.showMagicalPower", "$displayPrefix.maxwell.showMagicalPower") - event.move(31, "$displayConfigPrefix.compactTuning", "$displayPrefix.maxwell.compactTuning") - event.move(31, "$displayConfigPrefix.tuningAmount", "$displayPrefix.maxwell.tuningAmount") - event.move(31, "$displayConfigPrefix.hideVanillaScoreboard", "$displayPrefix.hideVanillaScoreboard") - event.move(31, "$displayConfigPrefix.displayNumbersFirst", "$displayPrefix.displayNumbersFirst") - event.move(31, "$displayConfigPrefix.showUnclaimedBits", "$displayPrefix.showUnclaimedBits") - event.move(31, "$displayConfigPrefix.showMaxIslandPlayers", "$displayPrefix.showMaxIslandPlayers") - event.move(31, "$displayConfigPrefix.numberFormat", "$displayPrefix.numberFormat") - event.move(31, "$displayConfigPrefix.lineSpacing", "$displayPrefix.lineSpacing") - event.move( - 31, - "$displayConfigPrefix.cacheScoreboardOnIslandSwitch", - "$displayPrefix.cacheScoreboardOnIslandSwitch", - ) - // Categories - event.move(31, "$displayConfigPrefix.alignment", "$displayPrefix.alignment") - event.move(31, "$displayConfigPrefix.titleAndFooter", "$displayPrefix.titleAndFooter") - event.move(31, "$prefix.backgroundConfig", "$prefix.background") - event.move(31, "$prefix.informationFilteringConfig", "$prefix.informationFiltering") - event.move(31, "$displayConfigPrefix.eventsConfig", "$displayPrefix.events") - event.move(31, "$prefix.mayorConfig", "$displayPrefix.mayor") - event.move(31, "$prefix.partyConfig", "$displayPrefix.party") - - event.transform(37, "$displayPrefix.events.eventEntries") { element -> - val array = element.asJsonArray - array.add(JsonPrimitive(ScoreboardEvent.QUEUE.name)) - array - } - event.transform(40, "$displayPrefix.events.eventEntries") { element -> - val jsonArray = element.asJsonArray - val newArray = JsonArray() - - for (jsonElement in jsonArray) { - val stringValue = jsonElement.asString - if (stringValue !in listOf("HOT_DOG_CONTEST", "EFFIGIES")) { - newArray.add(jsonElement) - } - } - - if (jsonArray.any { it.asString in listOf("HOT_DOG_CONTEST", "EFFIGIES") }) { - newArray.add(JsonPrimitive(ScoreboardEvent.RIFT.name)) - } - - newArray - } - - event.move(43, "$displayPrefix.alignment.alignRight", "$displayPrefix.alignment.horizontalAlignment") { - JsonPrimitive( - if (it.asBoolean) { - HorizontalAlignment.RIGHT.name - } else { - HorizontalAlignment.DONT_ALIGN.name - }, - ) - } - event.move(43, "$displayPrefix.alignment.alignCenterVertically", "$displayPrefix.alignment.verticalAlignment") { - JsonPrimitive( - if (it.asBoolean) { - VerticalAlignment.CENTER.name - } else { - VerticalAlignment.DONT_ALIGN.name - }, - ) - } - event.transform(50, "$displayPrefix.events.eventEntries") { element -> - val array = element.asJsonArray - array.add(JsonPrimitive(ScoreboardEvent.ANNIVERSARY.name)) - array.add(JsonPrimitive(ScoreboardEvent.CARNIVAL.name)) - array - } - event.transform(51, "$displayPrefix.events.eventEntries") { element -> - val array = element.asJsonArray - array.add(JsonPrimitive(ScoreboardEvent.NEW_YEAR.name)) - array - } - event.move( - 57, - "$displayPrefix.titleAndFooter.useHypixelTitleAnimation", - "$displayPrefix.titleAndFooter.useCustomTitle", - ) { - JsonPrimitive(!it.asBoolean) - } - } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboardConfigFix.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboardConfigFix.kt new file mode 100644 index 000000000..44dac8127 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboardConfigFix.kt @@ -0,0 +1,119 @@ +package at.hannibal2.skyhanni.features.gui.customscoreboard + +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment +import at.hannibal2.skyhanni.utils.RenderUtils.VerticalAlignment +import com.google.gson.JsonArray +import com.google.gson.JsonElement +import com.google.gson.JsonPrimitive +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object CustomScoreboardConfigFix { + + private const val PREFIX = "gui.customScoreboard" + private const val DISPLAY_PREFIX = "$PREFIX.display" + private const val DISPLAY_CONFIG_PREFIX = "$PREFIX.di