aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-06-03 14:24:48 +0200
committernea <nea@nea.moe>2023-06-03 14:24:48 +0200
commit9477a32ad577fc242fd83059826706fcea8c6f31 (patch)
tree900481bf5c9bc390b4101f946f6221b9995eccba /src/main
parent06a8ace53c3c1fcce02e9a9d085b82acb8cecb71 (diff)
downloadFirmament-9477a32ad577fc242fd83059826706fcea8c6f31.tar.gz
Firmament-9477a32ad577fc242fd83059826706fcea8c6f31.tar.bz2
Firmament-9477a32ad577fc242fd83059826706fcea8c6f31.zip
Bad pets menu
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/moe/nea/firmament/apis/Profiles.kt5
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/WTightScrollPanel.kt12
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt50
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt2
-rw-r--r--src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt8
5 files changed, 74 insertions, 3 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/apis/Profiles.kt b/src/main/kotlin/moe/nea/firmament/apis/Profiles.kt
index 7132147..4d4f370 100644
--- a/src/main/kotlin/moe/nea/firmament/apis/Profiles.kt
+++ b/src/main/kotlin/moe/nea/firmament/apis/Profiles.kt
@@ -14,6 +14,7 @@ import net.minecraft.util.DyeColor
import net.minecraft.util.Formatting
import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.util.LegacyFormattingCode
+import moe.nea.firmament.util.SkyblockId
import moe.nea.firmament.util.json.DashlessUUIDSerializer
import moe.nea.firmament.util.json.InstantAsLongSerializer
@@ -108,7 +109,9 @@ data class Pet(
val candyUsed: Int,
val heldItem: String?,
val skin: String?,
-)
+) {
+ val itemId get() = SkyblockId("${type.name};${tier.ordinal}")
+}
@Serializable
data class PlayerResponse(
diff --git a/src/main/kotlin/moe/nea/firmament/gui/WTightScrollPanel.kt b/src/main/kotlin/moe/nea/firmament/gui/WTightScrollPanel.kt
new file mode 100644
index 0000000..e9905d8
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/gui/WTightScrollPanel.kt
@@ -0,0 +1,12 @@
+package moe.nea.firmament.gui
+
+import io.github.cottonmc.cotton.gui.widget.WPanel
+import io.github.cottonmc.cotton.gui.widget.WScrollPanel
+import io.github.cottonmc.cotton.gui.widget.WWidget
+
+class WTightScrollPanel(val widget: WWidget, val margin: Int = 3) : WScrollPanel(widget) {
+ override fun setSize(x: Int, y: Int) {
+ (widget as? WPanel)?.layout()
+ super.setSize(widget.width + 8 + margin, y)
+ }
+}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt
new file mode 100644
index 0000000..0c3e5c8
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt
@@ -0,0 +1,50 @@
+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.WGridPanel
+import io.github.cottonmc.cotton.gui.widget.WItem
+import io.github.cottonmc.cotton.gui.widget.WScrollPanel
+import io.github.cottonmc.cotton.gui.widget.WText
+import io.github.cottonmc.cotton.gui.widget.WWidget
+import io.github.cottonmc.cotton.gui.widget.data.Insets
+import io.github.cottonmc.cotton.gui.widget.icon.Icon
+import io.github.cottonmc.cotton.gui.widget.icon.ItemIcon
+import net.minecraft.client.item.TooltipContext
+import net.minecraft.client.util.math.MatrixStack
+import net.minecraft.item.Items
+import net.minecraft.text.Text
+import moe.nea.firmament.gui.WFixedPanel
+import moe.nea.firmament.gui.WTightScrollPanel
+import moe.nea.firmament.rei.SBItemStack
+
+object PetsPage : ProfilePage {
+ override fun getElements(profileViewer: ProfileViewer): WWidget {
+ return WGridPanel().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, 1).asItemStack()
+ it.add(object : WItem(stack) {
+ override fun paint(matrices: MatrixStack?, x: Int, y: Int, mouseX: Int, mouseY: Int) {
+ BackgroundPainter.SLOT.paintBackground(matrices, x, y, this)
+ super.paint(matrices, x, y, mouseX, mouseY)
+ }
+
+ override fun addTooltip(tooltip: TooltipBuilder) {
+ tooltip.add(*stack.getTooltip(null, TooltipContext.BASIC).toTypedArray())
+ }
+ }, i % 5, i / 5, 1, 1)
+ }
+ it.layout()
+ })), 0, 1, 8, 8)
+ }
+ }
+
+ override val icon: Icon
+ get() = ItemIcon(Items.BONE)
+ override val text: Text
+ get() = Text.translatable("firmament.pv.skills")
+}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt
index 6b70e6c..c22fd39 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt
@@ -28,7 +28,7 @@ class ProfileViewer(
init {
val panel = WTabPanel().also { rootPanel = it }
panel.backgroundPainter
- listOf<ProfilePage>(SkillPage)
+ listOf<ProfilePage>(SkillPage, PetsPage)
.forEach { page ->
panel.add(page.getElements(this)) {
it.icon(page.icon)
diff --git a/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt b/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt
index ee6b673..c38f350 100644
--- a/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt
+++ b/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt
@@ -45,7 +45,13 @@ data class SBItemStack(
val neuItem: NEUItem?,
val stackSize: Int,
) {
- fun asItemStack(): ItemStack? {
+ constructor(skyblockId: SkyblockId, stackSize: Int = 1) : this(
+ skyblockId,
+ RepoManager.getNEUItem(skyblockId),
+ stackSize
+ )
+
+ fun asItemStack(): ItemStack {
if (skyblockId == SkyblockId.COINS)
return ItemCache.coinItem(stackSize)
return neuItem.asItemStack(idHint = skyblockId).copyWithCount(stackSize)