From 2f795bd9b4776c1777990e43436d139746bac0fb Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 9 Dec 2023 01:20:00 +0100 Subject: Show a chat message with the positive or negative progress in the community goal percentage after opening the bingo card inventory. --- .../config/features/event/bingo/BingoCardConfig.java | 7 +++++++ .../at/hannibal2/skyhanni/features/bingo/BingoAPI.kt | 10 ++++++++++ .../skyhanni/features/bingo/card/BingoCardDisplay.kt | 17 ++++------------- .../skyhanni/features/bingo/card/BingoCardReader.kt | 19 +++++++++++++++++-- 4 files changed, 38 insertions(+), 15 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/bingo/BingoCardConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/event/bingo/BingoCardConfig.java index ae382d25d..9150f06e4 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/event/bingo/BingoCardConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/event/bingo/BingoCardConfig.java @@ -13,6 +13,7 @@ public class BingoCardConfig { @ConfigEditorBoolean @FeatureToggle public boolean enabled = true; + @Expose @ConfigOption(name = "Quick Toggle", desc = "Quickly toggle the Bingo Card or the step helper by sneaking with SkyBlock Menu in hand.") @ConfigEditorBoolean @@ -52,4 +53,10 @@ public class BingoCardConfig { @ConfigOption(name = "Hide Difficulty When Done", desc = "Remove the background difficulty color in the bingo card inventory when the goal is done.") @ConfigEditorBoolean public boolean hideDoneDifficulty = true; + + @Expose + @ConfigOption(name = "Community Goal Progress", desc = "Show a chat message with the positive or negative progress in the community goal percentage after opening the bingo card inventory.") + @ConfigEditorBoolean + @FeatureToggle + public boolean communityGoalProgress = true; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt index 3f45df300..8b352578a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoRanksJson import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.features.bingo.card.goals.BingoGoal import at.hannibal2.skyhanni.features.bingo.card.goals.GoalType +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.time.LocalDate @@ -53,4 +54,13 @@ object BingoAPI { LocalDate.now(ZoneId.of("UTC")).plusDays(5).withDayOfMonth(1), LocalTime.MIDNIGHT, ZoneOffset.UTC ).toEpochSecond() + + fun getCommunityPercentageColor(percentage: Double): String = when { + percentage < 0.01 -> "§a" + percentage < 0.05 -> "§e" + percentage < 0.1 -> "§6" + percentage < 0.25 -> "§6" + + else -> "§c" + } + LorenzUtils.formatPercentage(percentage) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt index ab4c2c3df..520e93b27 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt @@ -127,19 +127,9 @@ class BingoCardDisplay { add(Renderable.string(" ")) } - private fun percentageFormat(it: BingoGoal): String { - val percentage = it.communtyGoalPercentage ?: return "" - - val percentageColor = when { - percentage < 0.01 -> "§a" - percentage < 0.05 -> "§e" - percentage < 0.1 -> "§6" - percentage < 0.25 -> "§6" - - else -> "§c" - } - return " " + percentageColor + LorenzUtils.formatPercentage(percentage) - } + private fun percentageFormat(it: BingoGoal) = it.communtyGoalPercentage?.let { + " " + BingoAPI.getCommunityPercentageColor(it) + } ?: "" private fun MutableList.addPersonalGoals() { val todo = BingoAPI.personalGoals.filter { !it.done }.toMutableList() @@ -262,6 +252,7 @@ class BingoCardDisplay { @SubscribeEvent fun onBingoCardUpdate(event: BingoCardUpdateEvent) { if (!config.enabled) return + if (!LorenzUtils.isBingoProfile) return update() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt index a0fdd2134..0c94a0d15 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt @@ -32,7 +32,6 @@ class BingoCardReader { @SubscribeEvent fun onInventoryOpen(event: InventoryUpdatedEvent) { - if (!LorenzUtils.isBingoProfile) return if (!config.enabled) return if (event.inventoryName != "Bingo Card") return @@ -69,13 +68,17 @@ class BingoCardReader { val visualDescription = hiddenGoalData.tipNote val bingoGoal = BingoAPI.bingoGoals.getOrPut(slot) { BingoGoal() } + with(bingoGoal) { this.type = goalType this.displayName = name this.description = visualDescription this.done = done this.hiddenGoalData = hiddenGoalData - this.communtyGoalPercentage = communtyGoalPercentage + } + communtyGoalPercentage?.let { + bingoGoalDifference(bingoGoal, it) + bingoGoal.communtyGoalPercentage = it } } BingoAPI.lastBingoCardOpenTime = SimpleTimeMark.now() @@ -83,6 +86,18 @@ class BingoCardReader { BingoCardUpdateEvent().postAndCatch() } + private fun bingoGoalDifference(bingoGoal: BingoGoal, new: Double) { + val old = bingoGoal.communtyGoalPercentage ?: 1.0 + + if (!config.communityGoalProgress) return + if (new == old) return + + val oldFormat = BingoAPI.getCommunityPercentageColor(old) + val newFormat = BingoAPI.getCommunityPercentageColor(new) + val color = if (new > old) "§c" else "§a" + LorenzUtils.chat("$color${bingoGoal.displayName}: $oldFormat §b->" + " $newFormat") + } + private fun readCommuntyGoalPercentage(lore: List): Double? { for (line in lore) { percentagePattern.matchMatcher(line) { -- cgit