diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index c55aa910d6f2..125f3f0a74c5 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -197,8 +197,9 @@ import at.hannibal2.skyhanni.features.garden.fortuneguide.CaptureFarmingGear import at.hannibal2.skyhanni.features.garden.inventory.AnitaExtraFarmingFortune import at.hannibal2.skyhanni.features.garden.inventory.GardenCropMilestoneInventory import at.hannibal2.skyhanni.features.garden.inventory.GardenInventoryNumbers -import at.hannibal2.skyhanni.features.garden.inventory.GardenNextPlotPrice -import at.hannibal2.skyhanni.features.garden.inventory.GardenPlotIcon +import at.hannibal2.skyhanni.features.garden.inventory.plots.GardenNextPlotPrice +import at.hannibal2.skyhanni.features.garden.inventory.plots.GardenPlotIcon +import at.hannibal2.skyhanni.features.garden.inventory.plots.GardenPlotMenuHighlighting import at.hannibal2.skyhanni.features.garden.inventory.SkyMartCopperPrice import at.hannibal2.skyhanni.features.garden.pests.PestAPI import at.hannibal2.skyhanni.features.garden.pests.PestFinder @@ -621,6 +622,7 @@ class SkyHanniMod { loadModule(TpsCounter()) loadModule(ParticleHider()) loadModule(MiscFeatures()) + loadModule(GardenPlotMenuHighlighting()) loadModule(SkyMartCopperPrice()) loadModule(GardenVisitorFeatures()) loadModule(NPCVisitorFix) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java index 2f9191d17452..84bb8d5be0f1 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java @@ -119,6 +119,11 @@ public class GardenConfig { @Accordion public CropStartLocationConfig cropStartLocation = new CropStartLocationConfig(); + @Expose + @ConfigOption(name = "Plot Menu Highlighting", desc = "") + @Accordion + public PlotMenuHighlightingConfig plotMenuHighlighting = new PlotMenuHighlightingConfig(); + @Expose @ConfigOption(name = "Garden Plot Icon", desc = "") @Accordion diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/PlotIconConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/PlotIconConfig.java index 2801d2bf6066..aca099417374 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/PlotIconConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/PlotIconConfig.java @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.config.features.garden; import at.hannibal2.skyhanni.config.FeatureToggle; -import at.hannibal2.skyhanni.features.garden.inventory.GardenPlotIcon; +import at.hannibal2.skyhanni.features.garden.inventory.plots.GardenPlotIcon; import at.hannibal2.skyhanni.utils.ChatUtils; import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/PlotMenuHighlightingConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/PlotMenuHighlightingConfig.java new file mode 100644 index 000000000000..acf10ec5dbb4 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/PlotMenuHighlightingConfig.java @@ -0,0 +1,45 @@ +package at.hannibal2.skyhanni.config.features.garden; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.utils.LorenzColor; +import com.google.gson.annotations.Expose; +import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigEditorDraggableList; +import io.github.moulberry.moulconfig.annotations.ConfigOption; + +import java.util.ArrayList; +import java.util.List; + +public class PlotMenuHighlightingConfig { + @Expose + @ConfigOption(name = "Enabled", desc = "Highlights plots based on their status.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = false; + + @Expose + @ConfigOption(name = "Statuses", desc = "Change which statuses are enabled, and the hierarchy of them.") + @ConfigEditorDraggableList + public List deskPlotStatusTypes = new ArrayList<>(); + + public enum PlotStatusType { + PESTS("§cPests", LorenzColor.RED), + SPRAYS("§eSprays", LorenzColor.YELLOW), + LOCKED("§7Locked", LorenzColor.DARK_GRAY), + CURRENT("§aCurrent plot", LorenzColor.GREEN) + ; + + public final String name; + public final LorenzColor highlightColor; + + PlotStatusType(String name, LorenzColor highlightColor) { + this.name = name; + this.highlightColor = highlightColor; + } + + @Override + public String toString() { + return name; + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenNextPlotPrice.kt similarity index 96% rename from src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt rename to src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenNextPlotPrice.kt index 54414d2116f9..1391f5706174 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenNextPlotPrice.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.features.garden.inventory +package at.hannibal2.skyhanni.features.garden.inventory.plots import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.features.garden.GardenAPI diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenPlotIcon.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotIcon.kt similarity index 98% rename from src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenPlotIcon.kt rename to src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotIcon.kt index 6b73890791ef..32a75c42592a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenPlotIcon.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotIcon.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.features.garden.inventory +package at.hannibal2.skyhanni.features.garden.inventory.plots import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotMenuHighlighting.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotMenuHighlighting.kt new file mode 100644 index 000000000000..165980a9f947 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotMenuHighlighting.kt @@ -0,0 +1,81 @@ +package at.hannibal2.skyhanni.features.garden.inventory.plots + +import at.hannibal2.skyhanni.config.features.garden.PlotMenuHighlightingConfig.PlotStatusType +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.features.garden.GardenAPI +import at.hannibal2.skyhanni.features.garden.GardenPlotAPI +import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.currentSpray +import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.pests +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.RenderUtils.highlight +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class GardenPlotMenuHighlighting { + + private val config get() = GardenAPI.config.plotMenuHighlighting + + private var highlightedPlots = mutableMapOf() + + @SubscribeEvent + fun onInventoryOpen(event: InventoryOpenEvent) { + if (!isEnabled()) return + + for (slot in InventoryUtils.getItemsInOpenChest()) { + val list = mutableListOf() + val plot = GardenPlotAPI.plots.find { it.inventorySlot == slot.slotIndex } ?: continue + + val (pestsEnabled, spraysEnabled, locksEnabled, currentEnabled) = PlotStatusType.entries.map { it in config.deskPlotStatusTypes } + + if (plot.pests >= 1 && pestsEnabled) list.add(PlotStatusType.PESTS) + if (plot.currentSpray != null && spraysEnabled) list.add(PlotStatusType.SPRAYS) + if (!plot.unlocked && locksEnabled) list.add(PlotStatusType.LOCKED) + if (plot == GardenPlotAPI.getCurrentPlot() && currentEnabled) list.add(PlotStatusType.CURRENT) + + getLowestIndexItem(list)?.let { index -> + val status = config.deskPlotStatusTypes[index] + handleCurrent(plot, status) + } ?: highlightedPlots.remove(plot) + } + } + + @SubscribeEvent + fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (!isEnabled() || highlightedPlots.isEmpty()) return + + for (plot in highlightedPlots) { + val items = InventoryUtils.getItemsInOpenChest() + if (plot.key.inventorySlot in items.indices) { + val slot = items[plot.key.inventorySlot] + slot.stack.stackSize = handleStackSize(plot.key, plot.value) + slot highlight plot.value.highlightColor + } + } + } + + private fun handleStackSize(plot: GardenPlotAPI.Plot, status: PlotStatusType): Int { + return when (status.name) { + "§cPests" -> return plot.pests + "§eSprays" -> return plot.currentSpray?.expiry?.timeUntil()?.inWholeMinutes?.toInt() ?: 1 + else -> 1 + } + } + + private fun handleCurrent(plot: GardenPlotAPI.Plot, status: PlotStatusType) { + val isHighlighted = highlightedPlots.containsKey(plot) + val isCurrent = highlightedPlots[plot] == status + if (!isHighlighted || isCurrent) { + if (!isHighlighted) highlightedPlots[plot] = status + } else { + highlightedPlots[plot] = status + } + } + + private fun getLowestIndexItem(array: MutableList): Int? { + return array.mapNotNull { status -> config.deskPlotStatusTypes.find { it == status } } + .minOfOrNull { config.deskPlotStatusTypes.indexOf(it) } + } + + private fun isEnabled() = + GardenAPI.inGarden() && InventoryUtils.openInventoryName() == "Configure Plots" && config.enabled +}