forked from hannibal002/SkyHanni
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Plot Menu Highlighting (hannibal002#1181)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
138 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/at/hannibal2/skyhanni/config/features/garden/PlotIconConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/at/hannibal2/skyhanni/config/features/garden/PlotMenuHighlightingConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...s/garden/inventory/GardenNextPlotPrice.kt → ...en/inventory/plots/GardenNextPlotPrice.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...atures/garden/inventory/GardenPlotIcon.kt → .../garden/inventory/plots/GardenPlotIcon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
.../java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotMenuHighlighting.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |