aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/gui/profileviewer
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/gui/profileviewer')
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt110
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfilePage.kt17
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt77
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt71
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt146
5 files changed, 0 insertions, 421 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt
deleted file mode 100644
index 6daeca4..0000000
--- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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")
-}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfilePage.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfilePage.kt
deleted file mode 100644
index 3d599ee..0000000
--- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfilePage.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * 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.widget.WWidget
-import io.github.cottonmc.cotton.gui.widget.icon.Icon
-import net.minecraft.text.Text
-
-interface ProfilePage {
- fun getElements(profileViewer: ProfileViewer): WWidget
- val icon: Icon
- val text: Text
-}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt
deleted file mode 100644
index ada7603..0000000
--- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.CottonClientScreen
-import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription
-import io.github.cottonmc.cotton.gui.widget.WTabPanel
-import moe.nea.firmament.Firmament
-import moe.nea.firmament.apis.Member
-import moe.nea.firmament.apis.PlayerData
-import moe.nea.firmament.apis.Profile
-import moe.nea.firmament.apis.Routes
-import moe.nea.firmament.util.ScreenUtil
-import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
-import net.minecraft.text.Text
-import java.util.*
-
-class ProfileViewer(
- val primaryPlayer: UUID,
- val playerNames: Map<UUID, String>,
- val accountData: Map<UUID, PlayerData>,
- val profile: Profile,
-) : LightweightGuiDescription() {
-
- val member: Member = profile.members[primaryPlayer] ?: error("Primary player not in profile")
- val primaryName: String = playerNames[primaryPlayer] ?: error("Primary player has no name")
- val account: PlayerData = accountData[primaryPlayer] ?: error("Primary player has no data")
-
- init {
- val panel = WTabPanel().also { rootPanel = it }
- panel.backgroundPainter
- listOf<ProfilePage>(SkillPage, PetsPage)
- .forEach { page ->
- panel.add(page.getElements(this)) {
- it.icon(page.icon)
- it.tooltip(page.text)
- }
- }
- }
-
- companion object {
- suspend fun onCommand(source: FabricClientCommandSource, name: String) {
- source.sendFeedback(Text.stringifiedTranslatable("firmament.pv.lookingup", name))
- try {
- val uuid = Routes.getUUIDForPlayerName(name)
- if (uuid == null) {
- source.sendError(Text.stringifiedTranslatable("firmament.pv.noplayer", name))
- return
- }
- val name = Routes.getPlayerNameForUUID(uuid) ?: name
- val names = mapOf(uuid to (name))
- val data = Routes.getAccountData(uuid)
- if (data == null) {
- source.sendError(Text.stringifiedTranslatable("firmament.pv.noprofile", name))
- return
- }
- val accountData = mapOf(data.uuid to data)
- val profiles = Routes.getProfiles(uuid)
- val profile = profiles?.profiles?.find { it.selected }
- if (profile == null) {
- source.sendFeedback(Text.stringifiedTranslatable("firmament.pv.noprofile", name))
- return
- }
- ScreenUtil.setScreenLater(CottonClientScreen(ProfileViewer(uuid, names, accountData, profile)))
- } catch (e: Exception) {
- Firmament.logger.error("Error loading profile data for $name", e)
- source.sendError(Text.stringifiedTranslatable("firmament.pv.badprofile", name, e.message))
- }
- }
- }
-}
-
-
diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt
deleted file mode 100644
index 0c99f67..0000000
--- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
- * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-package moe.nea.firmament.gui.profileviewer
-
-import com.mojang.brigadier.StringReader
-import io.github.cottonmc.cotton.gui.client.CottonClientScreen
-import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription
-import io.github.cottonmc.cotton.gui.widget.WGridPanel
-import io.github.cottonmc.cotton.gui.widget.WText
-import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment
-import moe.nea.lisp.LispData
-import moe.nea.lisp.LispExecutionContext
-import moe.nea.lisp.LispParser
-import moe.nea.lisp.bind.AutoBinder
-import moe.nea.lisp.bind.LispBinding
-import moe.nea.lisp.bind.UnmapForeignObject
-import net.minecraft.command.argument.ItemStringReader
-import net.minecraft.item.ItemStack
-import net.minecraft.text.Text
-import moe.nea.firmament.gui.WTitledItem
-import moe.nea.firmament.util.MC
-import moe.nea.firmament.util.ScreenUtil
-import moe.nea.firmament.util.item.setCustomName
-import moe.nea.firmament.util.modifyLore
-
-class ProfileViewerLibrary {
-
- @LispBinding("mk-item")
- fun makeItem(itemType: String, title: String, vararg lore: String): LispData.ForeignObject<ItemStack> {
- val item = ItemStringReader(MC.defaultRegistries).consume(StringReader(itemType))
- val itemStack = ItemStack(item.item.value())
- itemStack.applyComponentsFrom(item.components)
- itemStack.modifyLore { lore.map { Text.literal(it) } }
- itemStack.setCustomName(Text.literal(title))
- return LispData.ForeignObject(itemStack)
- }
-
- @LispBinding("def-page")
- fun defPage(name: String, @UnmapForeignObject icon: ItemStack) {
- pages.add(Pair(name, icon))
- }
-
- val pages = mutableListOf<Pair<String, ItemStack>>()
- val coreEnvironment = LispExecutionContext()
-
- fun run() {
- val t = coreEnvironment.genBindings()
- val ab = AutoBinder()
- ab.bindTo(this, t)
- val prog = LispParser.parse(
- "testfile.lisp", """
- (def-page "Test" (mk-item "minecraft:tnt" "§aThis is a test page" "§aMore text"))
- (def-page "Skills" (mk-item "minecraft:diamond_sword" "§aThis is a test page" "§aMore text"))
- """.trimIndent()
- )
- coreEnvironment.executeProgram(t, prog)
- val light = LightweightGuiDescription()
- val root = light.rootPanel as WGridPanel
- root.setGaps(8, 8)
- pages.forEachIndexed { i, (name, item) ->
- root.add(WTitledItem(item), 0, i)
- root.add(WText(Text.literal(name)).also { it.verticalAlignment = VerticalAlignment.CENTER }, 1, i, 6, 1)
- }
- ScreenUtil.setScreenLater(CottonClientScreen(light))
- }
-}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt
deleted file mode 100644
index 64f4f2c..0000000
--- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
- * SPDX-FileCopyrightText: 2024 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.widget.*
-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.Insets
-import io.github.cottonmc.cotton.gui.widget.icon.Icon
-import io.github.cottonmc.cotton.gui.widget.icon.ItemIcon
-import moe.nea.firmament.apis.*
-import moe.nea.firmament.gui.WBar
-import moe.nea.firmament.gui.WFixedPanel
-import moe.nea.firmament.gui.WTitledItem
-import moe.nea.firmament.hud.horizontal
-import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry
-import moe.nea.firmament.rei.SBItemEntryDefinition
-import moe.nea.firmament.repo.HypixelStaticData
-import moe.nea.firmament.repo.ItemCache.asItemStack
-import moe.nea.firmament.repo.RepoManager
-import moe.nea.firmament.util.FirmFormatters
-import moe.nea.firmament.util.modifyLore
-import moe.nea.firmament.util.toShedaniel
-import moe.nea.firmament.util.toTextColor
-import net.minecraft.item.ItemStack
-import net.minecraft.item.Items
-import net.minecraft.text.Style
-import net.minecraft.text.Text
-import net.minecraft.util.DyeColor
-import net.minecraft.util.Formatting
-import moe.nea.firmament.util.item.setCustomName
-
-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.stringifiedTranslatable("firmament.pv.skills.total", FirmFormatters.formatCurrency(exp, 1)))
- }
- }
- }
-
- private fun collectionItem(type: CollectionType, info: CollectionInfo, color: DyeColor, profile: Profile): WWidget {
- val collectionCount = profile.members.values.sumOf { it.collection[type] ?: 0 }
- val unlockedTiers = info.tiers.count { it.amountRequired <= collectionCount }
- return WTitledItem(
- SBItemEntryDefinition.getEntry(type.skyblockId).asItemEntry().value.copy()
- .also {
- it.setCustomName(
- Text.literal(info.name).fillStyle(
- Style.EMPTY.withItalic(false).withBold(true)
- .withColor(color.toTextColor())
- )
- )
- it.modifyLore { old ->
- listOf(
- Text.literal("${info.name} Collection: $collectionCount / ${info.tiers.last().amountRequired}"),
- Text.literal("Tiers unlocked: $unlockedTiers / ${info.tiers.size}")
- ).map {
- it.fillStyle(
- Style.EMPTY.withItalic(false).withColor(Formatting.GRAY)
- )
- }
- }
- }, countString = Text.literal("$unlockedTiers").styled {
- if (unlockedTiers == info.maxTiers)
- it.withColor(Formatting.YELLOW)
- else it
- }
- )
- }
-
- private fun collectionPanel(profileViewer: ProfileViewer): WTabPanel {
- return WTabPanel().also {
- val data = HypixelStaticData.collectionData
- val panels = mutableListOf<WPanel>()
- for ((collectionKind, collections) in data.entries) {
- val skillT = CollectionCategory.values().find { it.name == collectionKind }
- val color = skillT?.color ?: DyeColor.WHITE
- val icon = skillT?.icon?.let { RepoManager.getNEUItem(it).asItemStack() } ?: ItemStack(Items.ITEM_FRAME)
- val panel = WBox(Axis.HORIZONTAL).also {
- it.horizontalAlignment = HorizontalAlignment.CENTER
- it.add(WFixedPanel(WGridPanel().also {
- it.insets = Insets.ROOT_PANEL
- it.setGaps(2, 2)
- var x = 0
- var y = 0
- for (item in collections.items) {
- it.add(collectionItem(item.key, item.value, color, profileViewer.profile), x, y, 1, 1)
- x++
- if (x == 5) {
- x = 0
- y++
- }
- }
- }))
- }
- panels.add(panel)
- it.add(panel) {
- it.tooltip(
- Text.translatable("firmament.pv.skills.${collectionKind.lowercase()}")
- .styled { it.withColor(color.toTextColor()) })
- it.icon(ItemIcon(icon))
- }
- }
- it.layout()
- val tabWidth = it.width
- panels.forEach { it.setSize(tabWidth - Insets.ROOT_PANEL.horizontal, it.height) }
- }
- }
-
- override fun getElements(profileViewer: ProfileViewer): WWidget {
- return WBox(Axis.HORIZONTAL).also {
- it.insets = Insets.ROOT_PANEL
- it.add(WGridPanel().also {
- it.add(WText(Text.literal(profileViewer.account.getDisplayName(profileViewer.primaryName))), 0, 0, 8, 1)
- for ((i, skill) in Skill.values().withIndex()) {
- it.add(WText(Text.translatable("firmament.pv.skills.${skill.name.lowercase()}")), 0, i + 1, 4, 1)
- it.add(skillBar(profileViewer, skill), 4, i + 1, 4, 1)
- }
- })
- it.add(collectionPanel(profileViewer))
- }
- }
-
- override val icon: Icon
- get() = ItemIcon(ItemStack(Items.IRON_SWORD))
- override val text: Text
- get() = Text.translatable("firmament.pv.skills")
-}