Add more info to the pets page

This commit is contained in:
nea
2023-06-11 04:00:29 +02:00
parent db8e3640e8
commit 99fcad8360
5 changed files with 95 additions and 25 deletions

View File

@@ -1,11 +1,7 @@
== TO BE DONE BEFORE RELEASE == == TO BE DONE BEFORE RELEASE ==
- PV: - PV:
- Add Collection stats
- Add Inventory (prio -1) - Add Inventory (prio -1)
- Fix the layout
- More wider
- Pet level stat
- Item List: - Item List:
- Add other recipe types (prio -1) - Add other recipe types (prio -1)
- Fix banner data fixer (prio -1) - Fix banner data fixer (prio -1)

View File

@@ -1,22 +1,32 @@
package moe.nea.firmament.gui package moe.nea.firmament.gui
import com.mojang.blaze3d.systems.RenderSystem
import io.github.cottonmc.cotton.gui.client.BackgroundPainter import io.github.cottonmc.cotton.gui.client.BackgroundPainter
import io.github.cottonmc.cotton.gui.widget.TooltipBuilder import io.github.cottonmc.cotton.gui.widget.TooltipBuilder
import io.github.cottonmc.cotton.gui.widget.WItem import io.github.cottonmc.cotton.gui.widget.WWidget
import org.joml.AxisAngle4d
import org.joml.Quaternionf
import org.joml.Vector3f
import kotlin.math.PI
import net.minecraft.client.gui.DrawContext import net.minecraft.client.gui.DrawContext
import net.minecraft.client.item.TooltipContext import net.minecraft.client.item.TooltipContext
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
import net.minecraft.text.Text import net.minecraft.text.Text
import moe.nea.firmament.util.MC import moe.nea.firmament.util.MC
class WTitledItem(val stack: ItemStack, val countString: Text = Text.empty()) : WItem(stack) { open class WTitledItem(var stack: ItemStack, val countString: Text = Text.empty()) : WWidget() {
var backgroundPainter:BackgroundPainter = BackgroundPainter.SLOT
override fun canResize(): Boolean = true
override fun paint(context: DrawContext, x: Int, y: Int, mouseX: Int, mouseY: Int) { override fun paint(context: DrawContext, x: Int, y: Int, mouseX: Int, mouseY: Int) {
BackgroundPainter.SLOT.paintBackground(context, x, y, this) backgroundPainter.paintBackground(context, x, y, this)
super.paint(context, x, y, mouseX, mouseY)
context.matrices.push() context.matrices.push()
context.matrices.translate(x.toFloat(), y.toFloat(), 0F)
context.matrices.scale(width / 18F, height / 18F, 1F)
RenderSystem.enableDepthTest()
context.drawItemWithoutEntity(stack, 18 / 2 - 8, 18 / 2 - 8)
context.matrices.translate(0F, 0F, 200F) context.matrices.translate(0F, 0F, 200F)
context.drawText(MC.font, countString, x + 19 - 2 - MC.font.getWidth(countString), y + 6 + 3, 0xFFFFFF, true) context.drawText(MC.font, countString, 19 - 2 - MC.font.getWidth(countString), 6 + 3, 0xFFFFFF, true)
context.matrices.push() context.matrices.pop()
} }
override fun addTooltip(tooltip: TooltipBuilder) { override fun addTooltip(tooltip: TooltipBuilder) {

View File

@@ -1,42 +1,104 @@
package moe.nea.firmament.gui.profileviewer package moe.nea.firmament.gui.profileviewer
import io.github.cottonmc.cotton.gui.client.BackgroundPainter import io.github.cottonmc.cotton.gui.client.BackgroundPainter
import io.github.cottonmc.cotton.gui.widget.TooltipBuilder import io.github.cottonmc.cotton.gui.widget.WBox
import io.github.cottonmc.cotton.gui.widget.WGridPanel import io.github.cottonmc.cotton.gui.widget.WGridPanel
import io.github.cottonmc.cotton.gui.widget.WItem
import io.github.cottonmc.cotton.gui.widget.WText import io.github.cottonmc.cotton.gui.widget.WText
import io.github.cottonmc.cotton.gui.widget.WWidget import io.github.cottonmc.cotton.gui.widget.WWidget
import io.github.cottonmc.cotton.gui.widget.data.Axis
import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment
import io.github.cottonmc.cotton.gui.widget.data.InputResult
import io.github.cottonmc.cotton.gui.widget.data.Insets import io.github.cottonmc.cotton.gui.widget.data.Insets
import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment
import io.github.cottonmc.cotton.gui.widget.icon.Icon import io.github.cottonmc.cotton.gui.widget.icon.Icon
import io.github.cottonmc.cotton.gui.widget.icon.ItemIcon import io.github.cottonmc.cotton.gui.widget.icon.ItemIcon
import net.minecraft.client.gui.DrawContext import io.github.moulberry.repo.data.Rarity
import net.minecraft.client.item.TooltipContext import net.minecraft.item.ItemStack
import net.minecraft.item.Items import net.minecraft.item.Items
import net.minecraft.text.Text import net.minecraft.text.Text
import net.minecraft.util.Formatting
import moe.nea.firmament.gui.WTightScrollPanel import moe.nea.firmament.gui.WTightScrollPanel
import moe.nea.firmament.gui.WTitledItem import moe.nea.firmament.gui.WTitledItem
import moe.nea.firmament.rei.PetData import moe.nea.firmament.rei.PetData
import moe.nea.firmament.rei.SBItemStack import moe.nea.firmament.rei.SBItemStack
import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.util.FirmFormatters
object PetsPage : ProfilePage { object PetsPage : ProfilePage {
private fun petOverview(profileViewer: ProfileViewer, choosePet: (ItemStack) -> Unit) = WGridPanel().also { panel ->
panel.insets = Insets.ROOT_PANEL
panel.add(WText(Text.literal(profileViewer.account.getDisplayName(profileViewer.primaryName))), 0, 0, 6, 1)
panel.add((WTightScrollPanel(WGridPanel().also { it ->
it.setGaps(8, 8)
for ((i, pet) in profileViewer.member.pets.map {
SBItemStack(it.itemId, PetData(it.tier, it.type.name, it.exp))
}.sortedWith(
Comparator.comparing<SBItemStack?, Rarity?> { it.petData!!.rarity }.reversed()
.thenDescending(Comparator.comparing { it.petData!!.levelData.currentLevel })
.thenDescending(Comparator.comparing { it.petData!!.petId })
).withIndex()) {
val stack = pet.asItemStack()
it.add(object : WTitledItem(stack) {
override fun onClick(x: Int, y: Int, button: Int): InputResult {
choosePet(stack)
return InputResult.PROCESSED
}
}, i % 9, i / 9, 1, 1)
}
it.layout()
})), 0, 1, 12, 8)
petStats(profileViewer).withIndex().forEach { (i, it) ->
panel.add(it, 0, 10 + i, 8, 1)
}
}
private fun petStats(profileViewer: ProfileViewer): List<WWidget> {
val petScore = profileViewer.member.pets.groupBy { it.type }
.map { it.value.maxBy { it.tier } }
.sumOf { RepoManager.neuRepo.constants.bonuses.getPetValue(it.tier) }
return listOf(
WText(
Text.literal("Pet Score: ").styled { it.withColor(Formatting.AQUA) }
.append(Text.literal("$petScore").styled { it.withColor(Formatting.GOLD) })
),
WText(
Text.literal("Magic Find: ").styled { it.withColor(Formatting.AQUA) }
.append(
Text.literal(
FirmFormatters.toString(
RepoManager.neuRepo.constants.bonuses.getPetRewards(
petScore
)["magic_find"] ?: 0.0F, 1
)
)
.styled { it.withColor(Formatting.GOLD) })
)
)
}
override fun getElements(profileViewer: ProfileViewer): WWidget { override fun getElements(profileViewer: ProfileViewer): WWidget {
return WGridPanel().also { return WBox(Axis.HORIZONTAL).also {
it.insets = Insets.ROOT_PANEL it.insets = Insets.ROOT_PANEL
it.add(WText(Text.literal(profileViewer.account.getDisplayName())), 0, 0, 6, 1) val item = WTitledItem(ItemStack.EMPTY)
it.add((WTightScrollPanel(WGridPanel().also { item.backgroundPainter = BackgroundPainter.VANILLA
it.setGaps(8, 8) it.add(WBox(Axis.VERTICAL).also { box ->
for ((i, pet) in profileViewer.member.pets.withIndex()) { box.add(petOverview(profileViewer) { item.stack = it })
val stack = SBItemStack(pet.itemId, PetData(pet.tier, pet.type.name, pet.exp)).asItemStack() })
it.add(WTitledItem(stack), i % 5, i / 5, 1, 1) val b = WBox(Axis.VERTICAL).also { box ->
} box.verticalAlignment = VerticalAlignment.CENTER
it.layout() box.horizontalAlignment = HorizontalAlignment.CENTER
})), 0, 1, 8, 8) box.add(item, 128, 128)
}
it.add(b)
it.layout()
b.setSize(b.width + 20, it.height)
} }
} }
override val icon: Icon override val icon: Icon
get() = ItemIcon(Items.BONE) get() = ItemIcon(Items.BONE)
override val text: Text override val text: Text
get() = Text.translatable("firmament.pv.skills") get() = Text.translatable("firmament.pv.pets")
} }

View File

@@ -4,6 +4,7 @@ import com.google.common.math.IntMath.pow
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
object FirmFormatters { object FirmFormatters {
fun toString(float: Float, fractionalDigits: Int): String = toString(float.toDouble(), fractionalDigits)
fun toString(double: Double, fractionalDigits: Int): String { fun toString(double: Double, fractionalDigits: Int): String {
val long = double.toLong() val long = double.toLong()
val δ = (double - long).absoluteValue val δ = (double - long).absoluteValue

View File

@@ -8,6 +8,7 @@
"firmament.price.bazaar.productid": "Stock id: %s", "firmament.price.bazaar.productid": "Stock id: %s",
"firmament.price.bazaar.buy.price": "Buy Price: %s", "firmament.price.bazaar.buy.price": "Buy Price: %s",
"firmament.price.bazaar.buy.order": "Buy orders: %d", "firmament.price.bazaar.buy.order": "Buy orders: %d",
"firmament.pv.pets": "Pets",
"firmament.price.bazaar.sell.price": "Sell Price: %s", "firmament.price.bazaar.sell.price": "Sell Price: %s",
"firmament.price.bazaar.sell.order": "Sell orders: %d", "firmament.price.bazaar.sell.order": "Sell orders: %d",
"firmament.price.lowestbin": "Lowest BIN: %s", "firmament.price.lowestbin": "Lowest BIN: %s",