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

Backend: Remove deprecated method renderStringsAndItems #3069

Draft
wants to merge 4 commits into
base: beta
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
92 changes: 40 additions & 52 deletions src/main/java/at/hannibal2/skyhanni/features/combat/BestiaryData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.CollectionUtils.addButton
import at.hannibal2.skyhanni.utils.ConfigUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addButton
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary
Expand All @@ -27,7 +26,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.toRoman
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
Expand Down Expand Up @@ -78,7 +77,7 @@ object BestiaryData {
"^(?:\\(\\d+\\/\\d+\\) )?(?<title>Bestiary|.+) ➜ .+\$"
)

private var display = emptyList<List<Any>>()
private var display: Renderable? = null
private val mobList = mutableListOf<BestiaryMob>()
private val stackList = mutableMapOf<Int, ItemStack>()
private val catList = mutableListOf<Category>()
Expand All @@ -96,9 +95,7 @@ object BestiaryData {
fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) {
if (!isEnabled()) return
if (inInventory) {
config.position.renderStringsAndItems(
display, extraSpace = -1, itemScale = 0.7, posLabel = "Bestiary Data"
)
config.position.renderRenderable(display, posLabel = "Bestiary Data")
}
}

Expand Down Expand Up @@ -243,27 +240,23 @@ object BestiaryData {
}
}

private fun drawDisplay(): List<List<Any>> {
val newDisplay = mutableListOf<List<Any>>()
private fun drawDisplay(): Renderable {
val display = mutableListOf<Renderable>()

if (!overallProgressEnabled) {
newDisplay.addAsSingletonList("§7Bestiary Data")
newDisplay.addAsSingletonList(" §cPlease enable Overall Progress")
newDisplay.addAsSingletonList(" §cUsing the Eye of Ender highlighted in red.")
return newDisplay
display.add(Renderable.string("§7Bestiary Data"))
display.add(Renderable.string(" §cPlease enable Overall Progress"))
display.add(Renderable.string(" §cUsing the Eye of Ender highlighted in red."))
} else {
init()
addCategories(display)
if (mobList.isNotEmpty()) {
addList(display)
addButtons(display)
}
}

init()

addCategories(newDisplay)

if (mobList.isEmpty()) return newDisplay

addList(newDisplay)

addButtons(newDisplay)

return newDisplay
return Renderable.verticalContainer(display)
}

private fun sortMobList(): MutableList<BestiaryMob> {
Expand All @@ -281,26 +274,21 @@ object BestiaryData {
return sortedMobList
}

private fun addList(newDisplay: MutableList<List<Any>>) {
private fun addList(newDisplay: MutableList<Renderable>) {
val sortedMobList = sortMobList()

newDisplay.addAsSingletonList("§7Bestiary Data")
newDisplay.add(Renderable.string("§7Bestiary Data"))
for (mob in sortedMobList) {
val isUnlocked = mob.actualRealTotalKill != 0.toLong()
val isMaxed = mob.percentToMax() >= 1
if (!isUnlocked) {
newDisplay.add(
buildList {
add(" §7- ")
add("${mob.name}: §cNot unlocked!")
}
)
newDisplay.add(Renderable.string(" §7- ${mob.name}: §cNot unlocked!"))
continue
}
if (isMaxed && config.hideMaxed) continue
val text = getMobLine(mob, isMaxed)
val tips = getMobHover(mob)
newDisplay.addAsSingletonList(Renderable.hoverTips(text, tips) { true })
newDisplay.add(Renderable.hoverTips(text, tips) { true })
}
}

Expand Down Expand Up @@ -362,7 +350,7 @@ object BestiaryData {
return text
}

private fun addButtons(newDisplay: MutableList<List<Any>>) {
private fun addButtons(newDisplay: MutableList<Renderable>) {
newDisplay.addButton(
prefix = "§7Number Format: ",
getName = FormatType.entries[config.numberFormat.ordinal].type, // todo: avoid ordinal
Expand Down Expand Up @@ -402,27 +390,27 @@ object BestiaryData {
)
}

private fun addCategories(newDisplay: MutableList<List<Any>>) {
private fun addCategories(newDisplay: MutableList<Renderable>) {
if (catList.isNotEmpty()) {
newDisplay.addAsSingletonList("§7Category")
for (cat in catList) {
newDisplay.add(
buildList {
add(" §7- ${cat.name}§7: ")
val element = when {
cat.familiesCompleted == cat.totalFamilies -> "§c§lCompleted!"
cat.familiesFound == cat.totalFamilies -> "§b${cat.familiesCompleted}§7/§b${cat.totalFamilies} §7completed"
cat.familiesFound < cat.totalFamilies ->
"§b${cat.familiesFound}§7/§b${cat.totalFamilies} §7found, " +
"§b${cat.familiesCompleted}§7/§b${cat.totalFamilies} §7completed"

else -> continue
}
add(element)
}
)
newDisplay.add(Renderable.string("§7Category"))
newDisplay += catList.mapNotNull { buildCategoryLine(it) }
}
}

private fun buildCategoryLine(cat: Category): Renderable? {
val list = buildList {
add(Renderable.string(" §7- ${cat.name}§7: "))
val element = when {
cat.familiesCompleted == cat.totalFamilies -> "§c§lCompleted!"
cat.familiesFound == cat.totalFamilies -> "§b${cat.familiesCompleted}§7/§b${cat.totalFamilies} §7completed"
cat.familiesFound < cat.totalFamilies ->
"§b${cat.familiesFound}§7/§b${cat.totalFamilies} §7found, " +
"§b${cat.familiesCompleted}§7/§b${cat.totalFamilies} §7completed"
else -> return null
}
add(Renderable.string(element))
}
return Renderable.horizontalContainer(list)
}

private fun isOverallProgressEnabled(inventoryItems: Map<Int, ItemStack>): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.InventoryUtils.getUpperItems
import at.hannibal2.skyhanni.utils.ItemPriceUtils.getPrice
Expand All @@ -34,7 +33,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
import at.hannibal2.skyhanni.utils.RegexUtils.firstMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.TimeUtils
import at.hannibal2.skyhanni.utils.renderables.Renderable
Expand All @@ -52,7 +51,7 @@ object CityProjectFeatures {

private val config get() = SkyHanniMod.feature.event.cityProject

private var display = emptyList<List<Any>>()
private var display: Renderable? = null
private var inInventory = false
private var lastReminderSend = SimpleTimeMark.farPast()

Expand Down Expand Up @@ -152,22 +151,23 @@ object CityProjectFeatures {
return true
}

private fun buildList(materials: MutableMap<NEUInternalName, Int>) = buildList<List<Any>> {
addAsSingletonList("§7City Project Materials")
private fun buildList(materials: MutableMap<NEUInternalName, Int>): Renderable? {
val lines = mutableListOf<Renderable>()
lines.add(Renderable.string("§7City Project Materials"))

if (materials.isEmpty()) {
addAsSingletonList("§cNo Materials to contribute.")
return@buildList
lines.add(Renderable.string("§cNo Materials to contribute."))
return Renderable.verticalContainer(lines)
}

for ((internalName, amount) in materials) {
val stack = internalName.getItemStack()
val name = internalName.itemName
val list = mutableListOf<Any>()
list.add(" §7- ")
list.add(stack)
val line = mutableListOf<Renderable>()
line.add(Renderable.string(" §7- "))
line.add(Renderable.itemStack(stack))

list.add(
line.add(
Renderable.optionalLink(
"$name §ex${amount.addSeparators()}",
{
Expand All @@ -182,9 +182,11 @@ object CityProjectFeatures {

val price = internalName.getPrice() * amount
val format = price.shortFormat()
list.add(" §7(§6$format§7)")
add(list)
line.add(Renderable.string(" §7(§6$format§7)"))
lines.add(Renderable.horizontalContainer(line))
}

return Renderable.verticalContainer(lines)
}

private fun fetchMaterials(item: ItemStack, materials: MutableMap<NEUInternalName, Int>) {
Expand Down Expand Up @@ -215,7 +217,7 @@ object CityProjectFeatures {
if (!config.showMaterials) return
if (!inInventory) return

config.pos.renderStringsAndItems(display, posLabel = "City Project Materials")
config.pos.renderRenderable(display, posLabel = "City Project Materials")
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import at.hannibal2.skyhanni.features.fame.ReminderUtils
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.fromNow
import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.renderables.Renderable
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.Collections
import kotlin.time.Duration
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
Expand All @@ -33,7 +33,7 @@ object ComposterDisplay {

private val config get() = GardenAPI.config.composters
private val storage get() = GardenAPI.storage
private var display = emptyList<List<Any>>()
private var display: Renderable? = null
private var composterEmptyTime: Duration? = null

private val bucket by lazy { "BUCKET".toInternalName().getItemStack() }
Expand All @@ -49,9 +49,8 @@ object ComposterDisplay {

val pattern by lazy { rawPattern.toPattern() }

fun addToList(map: Map<DataType, String>): List<Any> {
return map[this]?.let { listOf(displayItem, it) }.orEmpty()
}
fun renderableLine(map: Map<DataType, String>): Renderable? =
map[this]?.let { labeledItemStack(it, displayItem) }
}

@HandleEvent
Expand All @@ -63,37 +62,42 @@ object ComposterDisplay {

if (tabListData.isNotEmpty()) {
composterEmptyTime = ComposterAPI.estimateEmptyTimeFromTab()
updateDisplay()
display = updateDisplay()
sendNotify()
}
}

private fun updateDisplay() {
if (!config.displayEnabled) return
val newDisplay = mutableListOf<List<Any>>()
newDisplay.addAsSingletonList("§bComposter")
private fun updateDisplay(): Renderable? {
if (!config.displayEnabled) return null

val lines = mutableListOf<Renderable>()
lines.add(Renderable.string("§bComposter"))

DataType.TIME_LEFT.renderableLine(tabListData)?.let { lines.add(it) }

newDisplay.add(DataType.TIME_LEFT.addToList(tabListData))
val ingredientLine = Renderable.horizontalContainer(
listOfNotNull(
DataType.ORGANIC_MATTER.renderableLine(tabListData),
Renderable.string(" "),
DataType.FUEL.renderableLine(tabListData),
)
)

val list = mutableListOf<Any>()
list.addAll(DataType.ORGANIC_MATTER.addToList(tabListData))
list.add(" ")
list.addAll(DataType.FUEL.addToList(tabListData))
newDisplay.add(list)
lines.add(ingredientLine)

newDisplay.add(DataType.STORED_COMPOST.addToList(tabListData))
newDisplay.add(addComposterEmptyTime(composterEmptyTime))
DataType.STORED_COMPOST.renderableLine(tabListData)?.let { lines.add(it) }
lines.add(addComposterEmptyTime(composterEmptyTime))

display = newDisplay
return Renderable.verticalContainer(lines, spacing = 1)
}

private fun addComposterEmptyTime(emptyTime: Duration?): List<Any> {
private fun addComposterEmptyTime(emptyTime: Duration?): Renderable {
return if (emptyTime != null) {
GardenAPI.storage?.composterEmptyTime = emptyTime.fromNow()
val format = emptyTime.format()
listOf(bucket, "§b$format")
labeledItemStack("§b$format", bucket)
} else {
listOf("§cOpen Composter Upgrades!")
Renderable.string("§cOpen Composter Upgrades!")
}
}

Expand Down Expand Up @@ -154,7 +158,7 @@ object ComposterDisplay {
if (!LorenzUtils.inSkyBlock && !OutsideSbFeature.COMPOSTER_TIME.isSelected()) return

if (GardenAPI.inGarden() && config.displayEnabled) {
config.displayPos.renderStringsAndItems(display, posLabel = "Composter Display")
config.displayPos.renderRenderable(display, posLabel = "Composter Display")
}

checkWarningsAndOutsideGarden()
Expand All @@ -179,11 +183,17 @@ object ComposterDisplay {
val inSb = LorenzUtils.inSkyBlock && config.displayOutsideGarden
val outsideSb = !LorenzUtils.inSkyBlock && OutsideSbFeature.COMPOSTER_TIME.isSelected()
if (!GardenAPI.inGarden() && (inSb || outsideSb)) {
val list = Collections.singletonList(listOf(bucket, "§b$format"))
config.outsideGardenPos.renderStringsAndItems(list, posLabel = "Composter Outside Garden")
val outsideGardenDisplay = labeledItemStack("§b$format", bucket)
config.outsideGardenPos.renderRenderable(outsideGardenDisplay, posLabel = "Composter Outside Garden")
}
}

private fun labeledItemStack(label: String, itemStack: ItemStack): Renderable {
return Renderable.horizontalContainer(
listOf(Renderable.itemStack(itemStack), Renderable.string(label))
)
}

private fun warn(warningMessage: String) {
if (!config.warnAlmostClose) return
val storage = GardenAPI.storage ?: return
Expand Down
Loading
Loading