Refactor skill page
This commit is contained in:
@@ -11,6 +11,7 @@ import kotlinx.serialization.Serializable
|
|||||||
import kotlinx.serialization.UseSerializers
|
import kotlinx.serialization.UseSerializers
|
||||||
import kotlin.reflect.KProperty1
|
import kotlin.reflect.KProperty1
|
||||||
import net.minecraft.util.DyeColor
|
import net.minecraft.util.DyeColor
|
||||||
|
import net.minecraft.util.Formatting
|
||||||
import moe.nea.firmament.repo.RepoManager
|
import moe.nea.firmament.repo.RepoManager
|
||||||
import moe.nea.firmament.util.LegacyFormattingCode
|
import moe.nea.firmament.util.LegacyFormattingCode
|
||||||
import moe.nea.firmament.util.json.DashlessUUIDSerializer
|
import moe.nea.firmament.util.json.DashlessUUIDSerializer
|
||||||
@@ -130,6 +131,12 @@ data class PlayerData(
|
|||||||
) {
|
) {
|
||||||
val rankPlusDyeColor = LegacyFormattingCode.values().find { it.name == rankPlusColor } ?: LegacyFormattingCode.GOLD
|
val rankPlusDyeColor = LegacyFormattingCode.values().find { it.name == rankPlusColor } ?: LegacyFormattingCode.GOLD
|
||||||
val rankData get() = RepoManager.neuRepo.constants.misc.ranks[if (monthlyPackageRank == "NONE" || monthlyPackageRank == null) packageRank else monthlyPackageRank]
|
val rankData get() = RepoManager.neuRepo.constants.misc.ranks[if (monthlyPackageRank == "NONE" || monthlyPackageRank == null) packageRank else monthlyPackageRank]
|
||||||
|
fun getDisplayName() = rankData?.let {
|
||||||
|
("§${it.color}[${it.tag}${rankPlusDyeColor.modern}" +
|
||||||
|
"${it.plus ?: ""}§${it.color}] $playerName")
|
||||||
|
} ?: "${Formatting.GRAY}${playerName}"
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import io.github.cottonmc.cotton.gui.widget.icon.ItemIcon
|
|||||||
import net.minecraft.item.ItemStack
|
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.apis.Skill
|
import moe.nea.firmament.apis.Skill
|
||||||
import moe.nea.firmament.gui.WBar
|
import moe.nea.firmament.gui.WBar
|
||||||
import moe.nea.firmament.repo.RepoManager
|
import moe.nea.firmament.repo.RepoManager
|
||||||
@@ -18,37 +17,33 @@ import moe.nea.firmament.util.FirmFormatters
|
|||||||
import moe.nea.firmament.util.toShedaniel
|
import moe.nea.firmament.util.toShedaniel
|
||||||
|
|
||||||
object SkillPage : ProfilePage {
|
object SkillPage : ProfilePage {
|
||||||
|
|
||||||
|
private fun skillBar(profileViewer: ProfileViewer, skill: Skill): WBar {
|
||||||
|
val leveling = RepoManager.neuRepo.constants.leveling
|
||||||
|
val exp = skill.accessor.get(profileViewer.member)
|
||||||
|
val maxLevel = skill.getMaximumLevel(leveling)
|
||||||
|
val level = skill.getLadder(leveling)
|
||||||
|
.runningFold(0.0) { a, b -> a + b }
|
||||||
|
.filter { it <= exp }.size
|
||||||
|
.coerceAtMost(maxLevel)
|
||||||
|
return object : WBar(
|
||||||
|
level.toDouble(), maxLevel.toDouble(),
|
||||||
|
skill.color.toShedaniel(), skill.color.toShedaniel().darker(2.0)
|
||||||
|
) {
|
||||||
|
override fun addTooltip(tooltip: TooltipBuilder) {
|
||||||
|
tooltip.add(Text.literal("$level/$maxLevel"))
|
||||||
|
tooltip.add(Text.translatable("firmament.pv.skills.total", FirmFormatters.toString(exp, 1)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun getElements(profileViewer: ProfileViewer): WWidget {
|
override fun getElements(profileViewer: ProfileViewer): WWidget {
|
||||||
return WGridPanel().also {
|
return WGridPanel().also {
|
||||||
it.insets = Insets.ROOT_PANEL
|
it.insets = Insets.ROOT_PANEL
|
||||||
it.add(
|
it.add(WText(Text.literal(profileViewer.account.getDisplayName())), 0, 0, 6, 1)
|
||||||
WText(
|
|
||||||
Text.literal(
|
|
||||||
profileViewer.account.rankData?.let {
|
|
||||||
("§${it.color}[${it.tag}${profileViewer.account.rankPlusDyeColor.modern}" +
|
|
||||||
"${it.plus ?: ""}§${it.color}] ${profileViewer.primaryName}")
|
|
||||||
} ?: "${Formatting.GRAY}${profileViewer.primaryName}"
|
|
||||||
)
|
|
||||||
), 0, 0, 6, 1
|
|
||||||
)
|
|
||||||
for ((i, skill) in Skill.values().withIndex()) {
|
for ((i, skill) in Skill.values().withIndex()) {
|
||||||
val leveling = RepoManager.neuRepo.constants.leveling
|
|
||||||
val exp = skill.accessor.get(profileViewer.member)
|
|
||||||
val maxLevel = skill.getMaximumLevel(leveling)
|
|
||||||
val level = skill.getLadder(leveling)
|
|
||||||
.runningFold(0.0) { a, b -> a + b }
|
|
||||||
.filter { it <= exp }.size
|
|
||||||
.coerceAtMost(maxLevel)
|
|
||||||
it.add(WText(Text.translatable("firmament.pv.skills.${skill.name.lowercase()}")), 0, i + 1, 4, 1)
|
it.add(WText(Text.translatable("firmament.pv.skills.${skill.name.lowercase()}")), 0, i + 1, 4, 1)
|
||||||
it.add(object : WBar(
|
it.add(skillBar(profileViewer, skill), 4, i + 1, 4, 1)
|
||||||
level.toDouble(), maxLevel.toDouble(),
|
|
||||||
skill.color.toShedaniel(), skill.color.toShedaniel().darker(2.0)
|
|
||||||
) {
|
|
||||||
override fun addTooltip(tooltip: TooltipBuilder) {
|
|
||||||
tooltip.add(Text.literal("$level/$maxLevel"))
|
|
||||||
tooltip.add(Text.translatable("firmament.pv.skills.total", FirmFormatters.toString(exp, 1)))
|
|
||||||
}
|
|
||||||
}, 4, i + 1, 4, 1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user