diff options
author | nea <nea@nea.moe> | 2023-06-11 04:00:29 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-06-11 04:00:51 +0200 |
commit | 99fcad8360c3ac7755d70e581c6e2d63e8c49282 (patch) | |
tree | 1318d2a54a32d5f7b71442fa37bf788800119237 /src | |
parent | db8e3640e8f9c14b7027c9e92b810ed127391ced (diff) | |
download | Firmament-99fcad8360c3ac7755d70e581c6e2d63e8c49282.tar.gz Firmament-99fcad8360c3ac7755d70e581c6e2d63e8c49282.tar.bz2 Firmament-99fcad8360c3ac7755d70e581c6e2d63e8c49282.zip |
Add more info to the pets page
Diffstat (limited to 'src')
4 files changed, 95 insertions, 21 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/gui/WTitledItem.kt b/src/main/kotlin/moe/nea/firmament/gui/WTitledItem.kt index ff9e894..07850fc 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/WTitledItem.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/WTitledItem.kt @@ -1,22 +1,32 @@ 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.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.item.TooltipContext import net.minecraft.item.ItemStack import net.minecraft.text.Text 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) { - BackgroundPainter.SLOT.paintBackground(context, x, y, this) - super.paint(context, x, y, mouseX, mouseY) + backgroundPainter.paintBackground(context, x, y, this) 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.drawText(MC.font, countString, x + 19 - 2 - MC.font.getWidth(countString), y + 6 + 3, 0xFFFFFF, true) - context.matrices.push() + context.drawText(MC.font, countString, 19 - 2 - MC.font.getWidth(countString), 6 + 3, 0xFFFFFF, true) + context.matrices.pop() } override fun addTooltip(tooltip: TooltipBuilder) { diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt index 20e11e7..9909418 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt @@ -1,42 +1,104 @@ package moe.nea.firmament.gui.profileviewer 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.WItem import io.github.cottonmc.cotton.gui.widget.WText 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.VerticalAlignment import io.github.cottonmc.cotton.gui.widget.icon.Icon import io.github.cottonmc.cotton.gui.widget.icon.ItemIcon -import net.minecraft.client.gui.DrawContext -import net.minecraft.client.item.TooltipContext +import io.github.moulberry.repo.data.Rarity +import net.minecraft.item.ItemStack import net.minecraft.item.Items import net.minecraft.text.Text +import net.minecraft.util.Formatting import moe.nea.firmament.gui.WTightScrollPanel import moe.nea.firmament.gui.WTitledItem import moe.nea.firmament.rei.PetData import moe.nea.firmament.rei.SBItemStack import moe.nea.firmament.repo.RepoManager +import moe.nea.firmament.util.FirmFormatters 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 { - return WGridPanel().also { + return WBox(Axis.HORIZONTAL).also { it.insets = Insets.ROOT_PANEL - it.add(WText(Text.literal(profileViewer.account.getDisplayName())), 0, 0, 6, 1) - it.add((WTightScrollPanel(WGridPanel().also { - it.setGaps(8, 8) - for ((i, pet) in profileViewer.member.pets.withIndex()) { - val stack = SBItemStack(pet.itemId, PetData(pet.tier, pet.type.name, pet.exp)).asItemStack() - it.add(WTitledItem(stack), i % 5, i / 5, 1, 1) - } - it.layout() - })), 0, 1, 8, 8) + val item = WTitledItem(ItemStack.EMPTY) + item.backgroundPainter = BackgroundPainter.VANILLA + it.add(WBox(Axis.VERTICAL).also { box -> + box.add(petOverview(profileViewer) { item.stack = it }) + }) + val b = WBox(Axis.VERTICAL).also { box -> + box.verticalAlignment = VerticalAlignment.CENTER + box.horizontalAlignment = HorizontalAlignment.CENTER + box.add(item, 128, 128) + } + it.add(b) + it.layout() + b.setSize(b.width + 20, it.height) } } override val icon: Icon get() = ItemIcon(Items.BONE) override val text: Text - get() = Text.translatable("firmament.pv.skills") + get() = Text.translatable("firmament.pv.pets") } diff --git a/src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt b/src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt index 73ef121..ba77b04 100644 --- a/src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt +++ b/src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt @@ -4,6 +4,7 @@ import com.google.common.math.IntMath.pow import kotlin.math.absoluteValue object FirmFormatters { + fun toString(float: Float, fractionalDigits: Int): String = toString(float.toDouble(), fractionalDigits) fun toString(double: Double, fractionalDigits: Int): String { val long = double.toLong() val δ = (double - long).absoluteValue diff --git a/src/main/resources/assets/firmament/lang/en_us.json b/src/main/resources/assets/firmament/lang/en_us.json index 2641173..79b1503 100644 --- a/src/main/resources/assets/firmament/lang/en_us.json +++ b/src/main/resources/assets/firmament/lang/en_us.json @@ -8,6 +8,7 @@ "firmament.price.bazaar.productid": "Stock id: %s", "firmament.price.bazaar.buy.price": "Buy Price: %s", "firmament.price.bazaar.buy.order": "Buy orders: %d", + "firmament.pv.pets": "Pets", "firmament.price.bazaar.sell.price": "Sell Price: %s", "firmament.price.bazaar.sell.order": "Sell orders: %d", "firmament.price.lowestbin": "Lowest BIN: %s", |