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 | |
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')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 6 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java | 5 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/garden/PlotIconConfig.java | 2 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/garden/PlotMenuHighlightingConfig.java | 45 | ||||
-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 |
7 files changed, 138 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index c55aa910d..125f3f0a7 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 9fa7e2bcc..9d941c095 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 @@ -120,6 +120,11 @@ public class GardenConfig { 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 public PlotIconConfig plotIcon = new PlotIconConfig(); 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 2801d2bf6..aca099417 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 000000000..acf10ec5d --- /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<PlotStatusType> 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 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 +} |