Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Plot Menu Highlighting #1181

Merged
merged 13 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,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.PestFinder
import at.hannibal2.skyhanni.features.garden.pests.PestSpawn
Expand Down Expand Up @@ -618,6 +619,7 @@ class SkyHanniMod {
loadModule(TpsCounter())
loadModule(ParticleHider())
loadModule(MiscFeatures())
loadModule(GardenPlotMenuHighlighting())
loadModule(SkyMartCopperPrice())
loadModule(GardenVisitorFeatures())
loadModule(NPCVisitorFix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
ILike2WatchMemes marked this conversation as resolved.
Show resolved Hide resolved

@Expose
@ConfigOption(name = "Garden Plot Icon", desc = "")
@Accordion
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 the hierarchy of the different plot statuses.")
@ConfigEditorDraggableList
public List<PlotStatusTypes> deskPlotStatusTypes = new ArrayList<>();

public enum PlotStatusTypes {
ILike2WatchMemes marked this conversation as resolved.
Show resolved Hide resolved
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;

PlotStatusTypes(String name, LorenzColor highlightColor) {
this.name = name;
this.highlightColor = highlightColor;
}

@Override
public String toString() {
return name;
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.hannibal2.skyhanni.features.garden.inventory
package at.hannibal2.skyhanni.features.garden.inventory.plots

import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package at.hannibal2.skyhanni.features.garden.inventory.plots

import at.hannibal2.skyhanni.config.features.garden.PlotMenuHighlightingConfig.PlotStatusTypes
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
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.features.garden.GardenPlotAPI.plots
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 = mutableListOf<Pair<GardenPlotAPI.Plot, PlotStatusTypes>>()

private fun isHighlighted(plot: GardenPlotAPI.Plot) = highlightedPlots.any { it.first == plot }
ILike2WatchMemes marked this conversation as resolved.
Show resolved Hide resolved
private fun isCurrentHighlight(plot: GardenPlotAPI.Plot, current: PlotStatusTypes) =
highlightedPlots.any { it.first == plot && it.second == current }

private fun handleStackSize(plot: GardenPlotAPI.Plot, status: PlotStatusTypes): 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: PlotStatusTypes) {
val isHighlighted = isHighlighted(plot)
val isCurrent = isCurrentHighlight(plot, status)
ILike2WatchMemes marked this conversation as resolved.
Show resolved Hide resolved
if (!isHighlighted || isCurrent) {
if (!isHighlighted) highlightedPlots.add(plot to status)
} else {
highlightedPlots.replaceAll { if (it.first == plot) plot to status else it }
}
}

private fun getLowestIndexItem(array: MutableList<PlotStatusTypes>): Int? {
var lowest = 999
array.forEach { status ->
val foundStatus = config.deskPlotStatusTypes.find { it == status }
if (foundStatus != null) {
val index = config.deskPlotStatusTypes.indexOf(foundStatus)
if (index < lowest) lowest = index
}
}
return if(lowest == 999) null else lowest
ILike2WatchMemes marked this conversation as resolved.
Show resolved Hide resolved
ILike2WatchMemes marked this conversation as resolved.
Show resolved Hide resolved
}

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
for (slot in InventoryUtils.getItemsInOpenChest()) {
ILike2WatchMemes marked this conversation as resolved.
Show resolved Hide resolved
val list = mutableListOf<PlotStatusTypes>()
val plot = plots.find { it.inventorySlot == slot.slotIndex } ?: continue
ILike2WatchMemes marked this conversation as resolved.
Show resolved Hide resolved
if (plot.pests >= 1) list.add(PlotStatusTypes.PESTS)
if (plot.currentSpray != null) list.add(PlotStatusTypes.SPRAYS)
if (!plot.unlocked) list.add(PlotStatusTypes.LOCKED)
if (plot == GardenPlotAPI.getCurrentPlot()) list.add(PlotStatusTypes.CURRENT)

getLowestIndexItem(list)?.let { index ->
val status = config.deskPlotStatusTypes[index]
handleCurrent(plot, status)
} ?: highlightedPlots.removeIf { it.first == plot }
}
}

@SubscribeEvent
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (!isEnabled() || highlightedPlots.size <= 0) return

for (plot in highlightedPlots) {
val slot = InventoryUtils.getItemsInOpenChest()[plot.first.inventorySlot] ?: continue
slot.stack.stackSize = handleStackSize(plot.first, plot.second)
slot highlight plot.second.highlightColor
}
}

private fun isEnabled() =
GardenAPI.inGarden() && InventoryUtils.openInventoryName() == "Configure Plots" && config.enabled
}
Loading