From 233b5d9b79afce09b830df22b89bc99180b5b991 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 12 May 2023 15:22:34 +0200 Subject: Time Format and Maxed Milestone options for Best Crop Time and Crop Milestones --- .../features/garden/farming/GardenBestCropTime.kt | 14 +++++--- .../garden/farming/GardenCropMilestoneDisplay.kt | 39 ++++++++++++++++------ 2 files changed, 38 insertions(+), 15 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden') diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBestCropTime.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBestCropTime.kt index 10726fc44..360819e30 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBestCropTime.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBestCropTime.kt @@ -9,13 +9,14 @@ import at.hannibal2.skyhanni.features.garden.GardenNextJacobContest import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.getSpeed import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.sorted +import at.hannibal2.skyhanni.utils.TimeUnit import at.hannibal2.skyhanni.utils.TimeUtils class GardenBestCropTime { var display = listOf>() - private val config get() = SkyHanniMod.feature.garden companion object { + private val config get() = SkyHanniMod.feature.garden val timeTillNextCrop = mutableMapOf() fun reset() { @@ -32,7 +33,7 @@ class GardenBestCropTime { val currentTier = GardenCropMilestones.getTierForCrops(counter) val cropsForCurrentTier = GardenCropMilestones.getCropsForTier(currentTier) - val nextTier = currentTier + 1 + val nextTier = if (config.cropMilestoneBestShowMaxedNeeded.get()) 46 else currentTier + 1 val cropsForNextTier = GardenCropMilestones.getCropsForTier(nextTier) val have = counter - cropsForCurrentTier @@ -89,7 +90,8 @@ class GardenBestCropTime { var number = 0 for (crop in sorted.keys) { val millis = timeTillNextCrop[crop]!! - val duration = TimeUtils.formatDuration(millis, maxUnits = 2) + val biggestUnit = TimeUnit.values()[config.cropMilestoneHighestTimeFormat.get()] + val duration = TimeUtils.formatDuration(millis, biggestUnit, maxUnits = 2) val isCurrent = crop == currentCrop number++ if (number > config.cropMilestoneShowOnlyBest && (!config.cropMilestoneShowCurrent || !isCurrent)) continue @@ -102,10 +104,12 @@ class GardenBestCropTime { val color = if (isCurrent) "§e" else "§7" val contestFormat = if (GardenNextJacobContest.isNextCrop(crop)) "§n" else "" - val nextTier = GardenCropMilestones.getTierForCrops(crop.getCounter()) + 1 + val currentTier = GardenCropMilestones.getTierForCrops(crop.getCounter()) + val nextTier = if (config.cropMilestoneBestShowMaxedNeeded.get()) 46 else currentTier + 1 + val cropName = if (!config.cropMilestoneBestCompact) crop.cropName + " " else "" - val cropNameDisplay = "$color$contestFormat$cropName$nextTier§r" + val cropNameDisplay = "$color$contestFormat$cropName$currentTier->$nextTier§r" list.add("$cropNameDisplay §b$duration") if (gardenExp && !config.cropMilestoneBestCompact) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt index b2e63c497..de8d299fd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt @@ -18,6 +18,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.TimeUnit import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -42,6 +43,17 @@ object GardenCropMilestoneDisplay { } } + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + LorenzUtils.onToggle( + config.cropMilestoneBestShowMaxedNeeded, + config.cropMilestoneHighestTimeFormat, + ) { + GardenBestCropTime.updateTimeTillNextCrop() + update() + } + } + @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { if (!isEnabled()) return @@ -126,7 +138,7 @@ object GardenCropMilestoneDisplay { return } currentCrop?.let { - progressDisplay = drawProgressDisplay(it, it.getCounter()) + progressDisplay = drawProgressDisplay(it) } if (config.cropMilestoneBestDisplay) { @@ -136,23 +148,28 @@ object GardenCropMilestoneDisplay { } } - private fun drawProgressDisplay(crop: CropType, counter: Long): MutableList> { + private fun drawProgressDisplay(crop: CropType): MutableList> { + val counter = crop.getCounter() val lineMap = HashMap>() lineMap[0] = Collections.singletonList("§6Crop Milestones") val currentTier = GardenCropMilestones.getTierForCrops(counter) - val nextTier = currentTier + 1 + val nextTier = if (config.cropMilestoneBestShowMaxedNeeded.get()) 46 else currentTier + 1 val list = mutableListOf() list.addCropIcon(crop) - list.add("§7" + crop.cropName + " Tier $nextTier") + list.add("§7" + crop.cropName + " $currentTier->$nextTier") lineMap[1] = list - val cropsForCurrentTier = GardenCropMilestones.getCropsForTier(currentTier) val cropsForNextTier = GardenCropMilestones.getCropsForTier(nextTier) - - val have = counter - cropsForCurrentTier - val need = cropsForNextTier - cropsForCurrentTier + val (have, need) = if (config.cropMilestoneBestShowMaxedNeeded.get()) { + Pair(counter, cropsForNextTier) + } else { + val cropsForCurrentTier = GardenCropMilestones.getCropsForTier(currentTier) + val have = counter - cropsForCurrentTier + val need = cropsForNextTier - cropsForCurrentTier + Pair(have, need) + } val haveFormat = LorenzUtils.formatInteger(have) val needFormat = LorenzUtils.formatInteger(need) @@ -168,7 +185,8 @@ object GardenCropMilestoneDisplay { val missingTimeSeconds = missing / farmingFortuneSpeed val millis = missingTimeSeconds * 1000 GardenBestCropTime.timeTillNextCrop[crop] = millis - val duration = TimeUtils.formatDuration(millis) + val biggestUnit = TimeUnit.values()[config.cropMilestoneHighestTimeFormat.get()] + val duration = TimeUtils.formatDuration(millis, biggestUnit) if (config.cropMilestoneWarnClose) { if (millis < 5_900) { if (System.currentTimeMillis() > lastPlaySoundTime + 1_000) { @@ -252,7 +270,8 @@ object GardenCropMilestoneDisplay { val missingTimeSeconds = missing / blocksPerSecond val millis = missingTimeSeconds * 1000 - val duration = TimeUtils.formatDuration(millis.toLong()) + val biggestUnit = TimeUnit.values()[config.cropMilestoneHighestTimeFormat.get()] + val duration = TimeUtils.formatDuration(millis.toLong(), biggestUnit) lineMap[3] = Collections.singletonList("§7In §b$duration") } -- cgit