diff options
| author | ILike2WatchMemes <ilike2watchmemes@gmail.com> | 2024-03-23 18:59:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-23 18:59:01 +0100 |
| commit | f307d45a23a319fb48c3af8c7fbd657e07df78b4 (patch) | |
| tree | e0de59a0633e49858dbb37394e60cc5d855da8a1 /src/main/java/at/hannibal2/skyhanni/features | |
| parent | aa78d9de37d964de3334c6af18a3ba9ece426dde (diff) | |
| download | skyhanni-f307d45a23a319fb48c3af8c7fbd657e07df78b4.tar.gz skyhanni-f307d45a23a319fb48c3af8c7fbd657e07df78b4.tar.bz2 skyhanni-f307d45a23a319fb48c3af8c7fbd657e07df78b4.zip | |
Feature: Plot Menu Highlighting (#1181)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenNextPlotPrice.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt) | 2 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotIcon.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenPlotIcon.kt) | 2 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotMenuHighlighting.kt | 81 |
3 files changed, 83 insertions, 2 deletions
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 index 54414d211..1391f5706 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 index 6b7389079..32a75c425 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 000000000..165980a9f --- /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<GardenPlotAPI.Plot, PlotStatusType>() + + @SubscribeEvent + fun onInventoryOpen(event: InventoryOpenEvent) { + if (!isEnabled()) return + + for (slot in InventoryUtils.getItemsInOpenChest()) { + val list = mutableListOf<PlotStatusType>() + 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<PlotStatusType>): 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 +} |
