Skip to content

Commit

Permalink
Added option to Hide Cheap Items in Slayer, Fishing and Diana Item Pr…
Browse files Browse the repository at this point in the history
…ofit Trackers.
  • Loading branch information
hannibal002 committed Dec 20, 2023
1 parent 060d521 commit 1279308
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import at.hannibal2.skyhanni.data.SlayerAPI
import at.hannibal2.skyhanni.data.TitleData
import at.hannibal2.skyhanni.data.TitleManager
import at.hannibal2.skyhanni.data.ToolTipData
import at.hannibal2.skyhanni.data.TrackerManager
import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson
import at.hannibal2.skyhanni.data.jsonobjects.local.JacobContestsJson
import at.hannibal2.skyhanni.data.jsonobjects.local.KnownFeaturesJson
Expand Down Expand Up @@ -415,6 +416,7 @@ class SkyHanniMod {
loadModule(AdvancedPlayerList)
loadModule(ItemAddManager())
loadModule(BingoCardReader())
loadModule(TrackerManager)

// APIs
loadModule(BazaarApi())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,28 @@ public static class TrackerItemWarningsConfig {
@ConfigEditorSlider(minValue = 1, maxValue = 50_000_000, minStep = 1)
public int minimumTitle = 5_000_000;
}

@Expose
@ConfigOption(name = "Hide Cheap Items", desc = "Hide cheap items.")
@Accordion
public HideCheapItemsConfig hideCheapItems = new HideCheapItemsConfig();

public static class HideCheapItemsConfig {

@Expose
@ConfigOption(name = "Enabled", desc = "Limit how many items should be shown.")
@ConfigEditorBoolean
public Property<Boolean> enabled = Property.of(true);

@Expose
@ConfigOption(name = "Show Expensive #", desc = "Always show the # most expensive items.")
@ConfigEditorSlider(minValue = 1, maxValue = 40, minStep = 1)
public Property<Integer> alwaysShowBest = Property.of(8);

@Expose
@ConfigOption(name = "Still Show Above", desc = "Always show items above this §6price in 1k §7even when not in the top # of items.")
@ConfigEditorSlider(minValue = 5, maxValue = 500, minStep = 5)
public Property<Integer> minPrice = Property.of(100);

}
}
37 changes: 37 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/data/TrackerManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

object TrackerManager {

private var hasChanged = false
var dirty = false

@SubscribeEvent
fun onConfigLoad(event: ConfigLoadEvent) {
val config = SkyHanniMod.feature.misc.tracker.hideCheapItems
LorenzUtils.onToggle(config.alwaysShowBest, config.minPrice, config.enabled) {
hasChanged = true
}
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
fun onRenderOverlayFirst(event: GuiRenderEvent) {
if (hasChanged) {
dirty = true
}
}

@SubscribeEvent(priority = EventPriority.LOWEST)
fun onRenderOverlayLast(event: GuiRenderEvent) {
if (hasChanged) {
dirty = false
hasChanged = false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,25 @@ class SkyHanniItemTracker<Data : ItemTrackerData>(
}
}

for (text in items.sortedDesc().keys) {
val limitList = config.hideCheapItems
var pos = 0
var hiddenItems = 0
for ((text, pricePer) in items.sortedDesc()) {
pos++
if (limitList.enabled.get()) {
if (pos > limitList.alwaysShowBest.get()) {
if (pricePer < limitList.minPrice.get() * 1000) {
hiddenItems++
continue
}
}
}
lists.addAsSingletonList(text)
}
if (hiddenItems > 0) {
lists.addAsSingletonList(" §7$hiddenItems cheap items are hidden.")
}

return profit
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.config.Storage
import at.hannibal2.skyhanni.config.core.config.Position
import at.hannibal2.skyhanni.config.features.misc.TrackerConfig.PriceFromEntry
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.TrackerManager
import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData
import at.hannibal2.skyhanni.features.misc.items.EstimatedItemValue
import at.hannibal2.skyhanni.utils.ConfigUtils
Expand Down Expand Up @@ -87,7 +88,7 @@ open class SkyHanniTracker<Data : TrackerData>(
update()
}

if (dirty) {
if (dirty || TrackerManager.dirty) {
display = getSharedTracker()?.let {
buildFinalDisplay(drawDisplay(it.get(getDisplayMode())))
} ?: emptyList()
Expand Down

0 comments on commit 1279308

Please sign in to comment.