1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package moe.nea.firmament.gui.profileviewer
import io.github.cottonmc.cotton.gui.client.BackgroundPainter
import io.github.cottonmc.cotton.gui.widget.WBox
import io.github.cottonmc.cotton.gui.widget.WGridPanel
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 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.formatCurrency(
RepoManager.neuRepo.constants.bonuses.getPetRewards(
petScore
)["magic_find"] ?: 0.0F, 1
)
)
.styled { it.withColor(Formatting.GOLD) })
)
)
}
override fun getElements(profileViewer: ProfileViewer): WWidget {
return WBox(Axis.HORIZONTAL).also {
it.insets = Insets.ROOT_PANEL
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.pets")
}
|