-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement UI elements for skill info & temp menu
- Loading branch information
1 parent
efec623
commit a88c7d5
Showing
11 changed files
with
254 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/client/kotlin/com/bibireden/playerex/ui/components/AttributeListComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.bibireden.playerex.ui.components | ||
|
||
import com.bibireden.data_attributes.api.attribute.EntityAttributeSupplier | ||
import com.bibireden.playerex.ui.util.FormattingPredicates | ||
import io.wispforest.owo.ui.component.Components | ||
import io.wispforest.owo.ui.container.Containers | ||
import io.wispforest.owo.ui.container.FlowLayout | ||
import io.wispforest.owo.ui.core.Positioning | ||
import io.wispforest.owo.ui.core.Sizing | ||
import net.minecraft.entity.attribute.EntityAttribute | ||
import net.minecraft.entity.player.PlayerEntity | ||
import net.minecraft.text.Text | ||
|
||
private fun transform(array: List<Pair<EntityAttributeSupplier, FormattingPredicates>>): List<Pair<EntityAttribute, FormattingPredicate>> { | ||
val filtered = mutableListOf<Pair<EntityAttribute, FormattingPredicate>>() | ||
for ((attribute, pred) in array) { | ||
if (attribute.get().isPresent) filtered.add(Pair(attribute.get().get(), pred.predicate)) | ||
} | ||
return filtered | ||
} | ||
|
||
class AttributeListComponent(translationKey: String, private val player: PlayerEntity, private val gimmie: List<Pair<EntityAttributeSupplier, FormattingPredicates>>) : FlowLayout(Sizing.fill(45), Sizing.content(), Algorithm.VERTICAL) { | ||
val entriesSection: FlowLayout | ||
|
||
init { | ||
child( | ||
Components.label(Text.translatable(translationKey)) | ||
.horizontalSizing(Sizing.fill(100)) | ||
) | ||
entriesSection = Containers.verticalFlow(Sizing.fill(100), Sizing.content()) | ||
.apply { | ||
gap(4) | ||
}.also(::child) | ||
|
||
gap(4) | ||
refresh() | ||
} | ||
|
||
fun refresh() { | ||
entriesSection.children().filterIsInstance<AttributeListEntryComponent>().forEach(::removeChild) | ||
entriesSection.children(transform(gimmie).map { AttributeListEntryComponent(it.first, player, it.second) }) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/client/kotlin/com/bibireden/playerex/ui/components/AttributeListEntryComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.bibireden.playerex.ui.components | ||
|
||
import com.bibireden.data_attributes.api.DataAttributesAPI | ||
import com.bibireden.playerex.ext.id | ||
import com.bibireden.playerex.ui.util.Colors | ||
import io.wispforest.owo.ui.component.LabelComponent | ||
import io.wispforest.owo.ui.core.HorizontalAlignment | ||
import io.wispforest.owo.ui.core.VerticalAlignment | ||
import net.minecraft.entity.attribute.EntityAttribute | ||
import net.minecraft.entity.player.PlayerEntity | ||
import net.minecraft.text.Text | ||
import net.minecraft.util.Formatting | ||
|
||
typealias FormattingPredicate = (Double) -> String | ||
|
||
class AttributeListEntryComponent( | ||
val attribute: EntityAttribute, | ||
val player: PlayerEntity, | ||
private val formattingPredicate: FormattingPredicate | ||
) : LabelComponent(Text.empty()) { | ||
init { | ||
horizontalTextAlignment(HorizontalAlignment.CENTER) | ||
verticalTextAlignment(VerticalAlignment.CENTER) | ||
|
||
refresh() | ||
} | ||
|
||
fun refresh() { | ||
text( | ||
Text.translatable(attribute.translationKey) | ||
.append(": ") | ||
.append(Text.literal( | ||
DataAttributesAPI.getValue(attribute, player).map { formattingPredicate(it) } | ||
.orElse("N/A")).styled { it.withColor(Colors.GOLD) } | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/client/kotlin/com/bibireden/playerex/ui/menus/PlayerEXStatsMenu.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.bibireden.playerex.ui.menus | ||
|
||
import com.bibireden.data_attributes.api.attribute.EntityAttributeSupplier | ||
import com.bibireden.playerex.api.attribute.ModdedAttributes | ||
import com.bibireden.playerex.api.attribute.PlayerEXAttributes | ||
import com.bibireden.playerex.components.player.IPlayerDataComponent | ||
import com.bibireden.playerex.ext.id | ||
import com.bibireden.playerex.ui.components.AttributeListComponent | ||
import com.bibireden.playerex.ui.components.AttributeListEntryComponent | ||
import com.bibireden.playerex.ui.components.MenuComponent | ||
import com.bibireden.playerex.ui.util.FormattingPredicates | ||
import de.dafuqs.additionalentityattributes.AdditionalEntityAttributes | ||
import io.wispforest.owo.ui.component.Components | ||
import io.wispforest.owo.ui.container.Containers | ||
import io.wispforest.owo.ui.container.FlowLayout | ||
import io.wispforest.owo.ui.core.Insets | ||
import io.wispforest.owo.ui.core.OwoUIAdapter | ||
import io.wispforest.owo.ui.core.Positioning | ||
import io.wispforest.owo.ui.core.Sizing | ||
import net.fabric_extras.ranged_weapon.api.EntityAttributes_RangedWeapon | ||
import net.minecraft.client.network.ClientPlayerEntity | ||
import net.minecraft.entity.attribute.EntityAttributes | ||
import net.minecraft.text.Text | ||
import org.jetbrains.annotations.ApiStatus | ||
|
||
@ApiStatus.Internal | ||
class PlayerEXStatsMenu : MenuComponent(algorithm = Algorithm.VERTICAL) { | ||
val MELEE_COMBAT_STATS: List<Pair<EntityAttributeSupplier, FormattingPredicates>> = listOf( | ||
EntityAttributeSupplier(EntityAttributes.GENERIC_ATTACK_DAMAGE.id) to FormattingPredicates.Normal, | ||
EntityAttributeSupplier(EntityAttributes.GENERIC_ATTACK_SPEED.id) to FormattingPredicates.Normal, | ||
ModdedAttributes.ATTACK_RANGE to FormattingPredicates.Normal, | ||
EntityAttributeSupplier(PlayerEXAttributes.MELEE_CRIT_DAMAGE.id) to FormattingPredicates.PercentageDiv, | ||
EntityAttributeSupplier(PlayerEXAttributes.MELEE_CRIT_CHANCE.id) to FormattingPredicates.PercentageDiv | ||
) | ||
|
||
val RANGED_COMBAT_STATS: List<Pair<EntityAttributeSupplier, FormattingPredicates>> = listOf( | ||
EntityAttributeSupplier(PlayerEXAttributes.RANGED_DAMAGE.id) to FormattingPredicates.Normal, | ||
EntityAttributeSupplier(PlayerEXAttributes.RANGED_CRITICAL_DAMAGE.id) to FormattingPredicates.PercentageDiv, | ||
EntityAttributeSupplier(PlayerEXAttributes.RANGED_CRITICAL_CHANCE.id) to FormattingPredicates.PercentageDiv, | ||
EntityAttributeSupplier(EntityAttributes_RangedWeapon.HASTE.id) to FormattingPredicates.Percent, | ||
) | ||
|
||
val DEFENSE_COMBAT_STATS: List<Pair<EntityAttributeSupplier, FormattingPredicates>> = listOf( | ||
EntityAttributeSupplier(EntityAttributes.GENERIC_ARMOR.id) to FormattingPredicates.Normal, | ||
EntityAttributeSupplier(AdditionalEntityAttributes.MAGIC_PROTECTION.id) to FormattingPredicates.Normal, | ||
EntityAttributeSupplier(EntityAttributes.GENERIC_ARMOR_TOUGHNESS.id) to FormattingPredicates.Normal, | ||
EntityAttributeSupplier(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE.id) to FormattingPredicates.PercentageDiv, | ||
EntityAttributeSupplier(PlayerEXAttributes.EVASION.id) to FormattingPredicates.PercentageDiv, | ||
) | ||
|
||
override fun build(player: ClientPlayerEntity, adapter: OwoUIAdapter<FlowLayout>, component: IPlayerDataComponent) { | ||
child( | ||
Containers.verticalScroll( | ||
Sizing.fill(100), | ||
Sizing.fill(100), | ||
Containers.verticalFlow(Sizing.fill(100), Sizing.content()).apply { | ||
child(AttributeListComponent("playerex.ui.main.categories.melee_combat", player, MELEE_COMBAT_STATS)) | ||
child(AttributeListComponent("playerex.ui.main.categories.ranged_combat", player, RANGED_COMBAT_STATS)) | ||
child(AttributeListComponent("playerex.ui.main.categories.defense_combat", player, DEFENSE_COMBAT_STATS)) | ||
gap(10) | ||
}.id("combat_stats") | ||
) | ||
) | ||
|
||
this.onAttributeUpdated.subscribe { _, _ -> | ||
this.forEachDescendant { | ||
if (it is AttributeListEntryComponent) it.refresh() | ||
} | ||
} | ||
|
||
padding(Insets.both(8, 12)) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/client/kotlin/com/bibireden/playerex/ui/util/FormattingPredicates.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.bibireden.playerex.ui.util | ||
|
||
import com.bibireden.playerex.ui.components.FormattingPredicate | ||
|
||
enum class FormattingPredicates(val predicate: FormattingPredicate) { | ||
Normal({ "%.2f".format(it) }), | ||
Percent({ "${it.toInt()}%" }), | ||
PercentageMul({ "${(it * 100.0).toInt()}%" }), | ||
PercentageDiv({ "${(it / 100.0).toInt()}%" }), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.