Skip to content

Commit

Permalink
Add coins to itempickup list, add option for formatting, add option f…
Browse files Browse the repository at this point in the history
…or display alignment
  • Loading branch information
catgirlseraid committed Jul 19, 2024
1 parent 940bf5a commit f143f2f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import at.hannibal2.skyhanni.config.FeatureToggle;
import at.hannibal2.skyhanni.config.core.config.Position;
import at.hannibal2.skyhanni.utils.RenderUtils;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider;
import io.github.notenoughupdates.moulconfig.annotations.ConfigLink;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
Expand All @@ -22,15 +24,33 @@ public class ItemPickupLogConfig {
public boolean compactLines = true;

@Expose
@ConfigOption(name = "Show Item Icon", desc = "Show the item icon next to the item name")
@ConfigOption(name = "Compact Numbers", desc = "Compact the amounts added and removed.")
@ConfigEditorBoolean
public boolean shorten = false;

@Expose
@ConfigOption(name = "Show Item Icon", desc = "Show the item icon next to the item name.")
@ConfigEditorBoolean
public boolean showItemIcon = true;

@Expose
@ConfigOption(name = "Sacks", desc = "Also show items added and removed from stacks")
@ConfigOption(name = "Sacks", desc = "Show items added and removed from stacks.")
@ConfigEditorBoolean
public boolean sack = true;

@Expose
@ConfigOption(name = "Coins", desc = "Show coins added and removed from purse.")
@ConfigEditorBoolean
public boolean coins = false;

@Expose
@ConfigOption(
name = "Alignment",
desc = "How the item pickup log should be aligned. §d:3"
)
@ConfigEditorDropdown
public RenderUtils.VerticalAlignment alignment = RenderUtils.VerticalAlignment.TOP;

@Expose
@ConfigOption(
name = "Expire After",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.PurseChangeEvent
import at.hannibal2.skyhanni.events.SackChangeEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.CollectionUtils.addItemStack
Expand All @@ -12,14 +13,18 @@ import at.hannibal2.skyhanni.utils.ItemNameResolver
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrNull
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
import at.hannibal2.skyhanni.utils.RenderUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getExtraAttributes
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXYAligned
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraft.item.ItemStack
Expand All @@ -32,10 +37,12 @@ import kotlin.time.Duration.Companion.seconds
object ItemPickupLog {
private val config get() = SkyHanniMod.feature.inventory.itemPickupLogConfig

private val coinIcon = "COIN_TALISMAN".asInternalName()

private var itemList = mutableMapOf<Int, Pair<ItemStack, Int>>()
private var itemsAddedToInventory = mutableMapOf<Int, UpdatedItem>()
private var itemsRemovedFromInventory = mutableMapOf<Int, UpdatedItem>()
private val display = mutableListOf<Renderable>()
private var display: Renderable = Renderable.string("")

private val patternGroup = RepoPattern.group("itempickuplog")
private val shopPattern by patternGroup.pattern(
Expand All @@ -46,7 +53,7 @@ object ItemPickupLog {
@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent) {
if (!isEnabled()) return
config.pos.renderRenderables(display, posLabel = "Item Pickup Log Display")
config.pos.renderRenderable(display, posLabel = "Item Pickup Log Display")
}

@SubscribeEvent
Expand All @@ -58,17 +65,24 @@ object ItemPickupLog {
}

@SubscribeEvent
fun onStackChange(event: SackChangeEvent) {
if (!isEnabled() && !config.sack) return
fun onSackChange(event: SackChangeEvent) {
if (!isEnabled() || !config.sack) return

event.sackChanges.forEach {
val itemStack = (it.internalName.getItemStack())
val item = UpdatedItem(itemStack.displayName, it.delta.absoluteValue)
val item = UpdatedItem(itemStack.displayName, it.delta.absoluteValue.toLong(), it.internalName)

updateItem(itemStack.hash(), item, itemStack, it.delta < 0)
}
}

@SubscribeEvent
fun onPurseChange(event: PurseChangeEvent) {
if (!isEnabled() || !config.coins || !worldChangeCooldown()) return

updateItem(0, UpdatedItem("§6Coins", event.coins.absoluteValue.toLong(), coinIcon), coinIcon.getItemStack(), event.coins < 0)
}

@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!isEnabled()) return
Expand Down Expand Up @@ -102,26 +116,26 @@ object ItemPickupLog {
}
}

if (LorenzUtils.lastWorldSwitch.passedSince() < 2.seconds) return
if (!worldChangeCooldown()) return

oldItemList.forEach {
if (!itemList.containsKey(it.key)) {
val item = UpdatedItem(it.value.first.displayName, it.value.second)
val item = UpdatedItem(it.value.first.displayName, it.value.second.toLong(), it.value.first.getInternalNameOrNull())
updateItem(it.key, item, it.value.first, true)
} else if (it.value.second > itemList[it.key]!!.second) {
val amount = (it.value.second - itemList[it.key]?.second!!)
val item = UpdatedItem(it.value.first.displayName, amount)
val item = UpdatedItem(it.value.first.displayName, amount.toLong(), it.value.first.getInternalNameOrNull())
updateItem(it.key, item, it.value.first, true)
}
}

itemList.forEach {
if (!oldItemList.containsKey(it.key)) {
val item = UpdatedItem(it.value.first.displayName, it.value.second)
val item = UpdatedItem(it.value.first.displayName, it.value.second.toLong(), it.value.first.getInternalNameOrNull())
updateItem(it.key, item, it.value.first, false)
} else if (it.value.second > oldItemList[it.key]!!.second) {
val amount = (it.value.second - oldItemList[it.key]?.second!!)
val item = UpdatedItem(it.value.first.displayName, amount)
val item = UpdatedItem(it.value.first.displayName, amount.toLong(), it.value.first.getInternalNameOrNull())
updateItem(it.key, item, it.value.first, false)
}
}
Expand Down Expand Up @@ -185,10 +199,10 @@ object ItemPickupLog {
}
}

private data class UpdatedItem(val name: String, var amount: Int) {
private data class UpdatedItem(val name: String, var amount: Long, val neuInternalName: NEUInternalName?) {
var time = SimpleTimeMark.now()

fun updateAmount(change: Int) {
fun updateAmount(change: Long) {
amount += change
time = SimpleTimeMark.now()
}
Expand All @@ -198,15 +212,16 @@ object ItemPickupLog {

private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled

private fun renderList(prefix: String, amount: Int, name: String): Renderable {
private fun renderList(prefix: String, amount: Long, name: String, itemIcon: NEUInternalName?): Renderable {
return if (config.showItemIcon) {
Renderable.horizontalContainer(
buildList {
add(Renderable.string("${prefix}${amount.addSeparators()}"))
ItemNameResolver.getInternalNameOrNull(name)?.let {
addItemStack(
it,
)
val formattedAmount = if (config.shorten) amount.shortFormat() else amount.addSeparators()
add(Renderable.string("${prefix}${formattedAmount}"))
if (itemIcon != null) {
addItemStack(itemIcon)
} else {
ItemNameResolver.getInternalNameOrNull(name)?.let { addItemStack(it) }
}
add(Renderable.string(name))
},
Expand All @@ -216,10 +231,14 @@ object ItemPickupLog {
}
}

private fun worldChangeCooldown(): Boolean {
return LorenzUtils.lastWorldSwitch.passedSince() > 2.seconds
}

private fun updateDisplay() {
if (!isEnabled()) return

display.clear()
val display = mutableListOf<Renderable>()

itemsAddedToInventory.values.removeIf { it.isExpired() }
itemsRemovedFromInventory.values.removeIf { it.isExpired() }
Expand All @@ -238,9 +257,9 @@ object ItemPickupLog {
val currentTotalValue = item.value.amount - it.amount

if (currentTotalValue > 0) {
display.add(renderList("§a+", currentTotalValue, item.value.name))
display.add(renderList("§a+", currentTotalValue, item.value.name, item.value.neuInternalName))
} else if (currentTotalValue < 0) {
display.add(renderList("§c", currentTotalValue, item.value.name))
display.add(renderList("§c", currentTotalValue, item.value.name, item.value.neuInternalName))
} else {
itemsAddedToInventory.remove(item.key)
itemsRemovedFromInventory.remove(item.key)
Expand All @@ -249,21 +268,33 @@ object ItemPickupLog {
iterator.remove()
}
} else {
display.add(renderList("§a+", item.value.amount, item.value.name))
display.add(renderList("§a+", item.value.amount, item.value.name, item.value.neuInternalName))
}
}
} else {
for (item in addedItemsToNoLongerShow) {

display.add(renderList("§a+", item.value.amount, item.value.name))
display.add(renderList("§a+", item.value.amount, item.value.name, item.value.neuInternalName))
removedItemsToNoLongerShow[item.key]?.let {
display.add(renderList("§c-", it.amount, it.name))
display.add(renderList("§c-", it.amount, it.name, it.neuInternalName))
removedItemsToNoLongerShow.remove(item.key)
}
}
}
for (item in removedItemsToNoLongerShow) {
display.add(renderList("§c-", item.value.amount, item.value.name))
display.add(renderList("§c-", item.value.amount, item.value.name, item.value.neuInternalName))
}
val renderable = Renderable.verticalContainer(display, verticalAlign = config.alignment)
this.display = object : Renderable {
override val width: Int = renderable.width
override val height: Int = renderable.height
override val horizontalAlign: RenderUtils.HorizontalAlignment = renderable.horizontalAlign
override val verticalAlign: RenderUtils.VerticalAlignment = renderable.verticalAlign

override fun render(posX: Int, posY: Int) {
renderable.renderXYAligned(posX, posY, 0, 0)
}

}
}
}
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ object RenderUtils {
renderable.render(0, 0)
}
GlStateManager.popMatrix()
if (addToGuiManager) GuiEditManager.add(this, posLabel, renderable.width, 0)
if (addToGuiManager) GuiEditManager.add(this, posLabel, renderable.width, renderable.height)
}

/**
Expand Down

0 comments on commit f143f2f

Please sign in to comment.