From 35a83932ea69cf3ae4ab56b5f15a41aa67f36776 Mon Sep 17 00:00:00 2001 From: Bibi Reden Date: Thu, 25 Jul 2024 13:26:21 -0500 Subject: [PATCH] Realignment of component(s), left side needs some work still --- .../ui/components/labels/AttributeComponent.kt | 18 +++++++++++++----- .../labels/AttributeLabelComponent.kt | 6 +++++- .../playerex/ui/menus/AttributeMenu.kt | 4 ++-- .../assets/playerex/owo_ui/main_ui_model.xml | 13 +++++++------ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/client/kotlin/com/bibireden/playerex/ui/components/labels/AttributeComponent.kt b/src/client/kotlin/com/bibireden/playerex/ui/components/labels/AttributeComponent.kt index 9db8d09e..3c0f9af1 100644 --- a/src/client/kotlin/com/bibireden/playerex/ui/components/labels/AttributeComponent.kt +++ b/src/client/kotlin/com/bibireden/playerex/ui/components/labels/AttributeComponent.kt @@ -12,6 +12,7 @@ import io.wispforest.owo.ui.component.Components import io.wispforest.owo.ui.component.LabelComponent import io.wispforest.owo.ui.container.Containers import io.wispforest.owo.ui.container.FlowLayout +import io.wispforest.owo.ui.core.HorizontalAlignment import io.wispforest.owo.ui.core.Positioning import io.wispforest.owo.ui.core.Sizing import io.wispforest.owo.ui.core.VerticalAlignment @@ -23,7 +24,7 @@ import net.minecraft.util.Formatting private val StackingBehavior.symbol: String get() = if (this == StackingBehavior.Add) "+" else "×" -class AttributeComponent(val attribute: EntityAttribute, val player: PlayerEntity, component: IPlayerDataComponent) : FlowLayout(Sizing.fill(100), Sizing.fixed(18), Algorithm.HORIZONTAL) { +class AttributeComponent(val attribute: EntityAttribute, val player: PlayerEntity, component: IPlayerDataComponent) : FlowLayout(Sizing.fill(35), Sizing.fixed(18), Algorithm.HORIZONTAL) { fun updateTooltip() { // todo: allow data_attributes to have API funcs for obtaining this data. val entries = DataAttributes.FUNCTIONS_CONFIG.functions.data[attribute.id] @@ -54,18 +55,25 @@ class AttributeComponent(val attribute: EntityAttribute, val player: PlayerEntit init { this.child( - Components.label(Text.translatable(attribute.translationKey)).sizing(Sizing.content(), Sizing.fill(100)) - .also { this.updateTooltip() }.id("${attribute.id}:label") + Components.label(Text.translatable(attribute.translationKey)) + .verticalTextAlignment(VerticalAlignment.CENTER) + .sizing(Sizing.content(), Sizing.fill(100)) + .also { this.updateTooltip() } + .id("${attribute.id}:label") ) this.child(AttributeLabelComponent(attribute, player)) this.child( - Containers.horizontalFlow(Sizing.fill(50), Sizing.fill(100)).also { + Containers.horizontalFlow(Sizing.content(), Sizing.fill(100)).also { it.child(AttributeButtonComponent(attribute, player, component, AttributeButtonComponentType.Remove)) it.child(AttributeButtonComponent(attribute, player, component, AttributeButtonComponentType.Add)) it.child(Components.textBox(Sizing.fixed(27)).text("1").verticalSizing(Sizing.fixed(12)).id("entry:${attribute.id}")) it.gap(4) - }.positioning(Positioning.relative(100, 0)).verticalAlignment(VerticalAlignment.CENTER) + } + .horizontalAlignment(HorizontalAlignment.RIGHT) + .verticalAlignment(VerticalAlignment.CENTER) + .positioning(Positioning.relative(100, 0)) ) this.gap(3) + this.verticalAlignment(VerticalAlignment.CENTER) } } \ No newline at end of file diff --git a/src/client/kotlin/com/bibireden/playerex/ui/components/labels/AttributeLabelComponent.kt b/src/client/kotlin/com/bibireden/playerex/ui/components/labels/AttributeLabelComponent.kt index 770b35f3..b7f9e247 100644 --- a/src/client/kotlin/com/bibireden/playerex/ui/components/labels/AttributeLabelComponent.kt +++ b/src/client/kotlin/com/bibireden/playerex/ui/components/labels/AttributeLabelComponent.kt @@ -4,6 +4,8 @@ import com.bibireden.data_attributes.api.DataAttributesAPI import com.bibireden.data_attributes.api.attribute.IEntityAttribute import com.bibireden.playerex.ext.id import io.wispforest.owo.ui.component.LabelComponent +import io.wispforest.owo.ui.core.Sizing +import io.wispforest.owo.ui.core.VerticalAlignment import net.minecraft.entity.attribute.EntityAttribute import net.minecraft.entity.player.PlayerEntity import net.minecraft.text.Text @@ -15,7 +17,9 @@ private fun createTextFromAttribute(attribute: EntityAttribute, player: PlayerEn class AttributeLabelComponent(private val attribute: EntityAttribute, private val player: PlayerEntity) : LabelComponent(createTextFromAttribute(attribute, player)) { init { - this.id("${attribute.id}:current_level") + id("${attribute.id}:current_level") + verticalSizing(Sizing.fill(100)) + verticalTextAlignment(VerticalAlignment.CENTER) } fun update(): LabelComponent = text(createTextFromAttribute(attribute, player)) diff --git a/src/client/kotlin/com/bibireden/playerex/ui/menus/AttributeMenu.kt b/src/client/kotlin/com/bibireden/playerex/ui/menus/AttributeMenu.kt index 9a9e21cc..2ef442d7 100644 --- a/src/client/kotlin/com/bibireden/playerex/ui/menus/AttributeMenu.kt +++ b/src/client/kotlin/com/bibireden/playerex/ui/menus/AttributeMenu.kt @@ -15,7 +15,7 @@ import net.minecraft.client.network.ClientPlayerEntity import net.minecraft.registry.Registries import net.minecraft.text.Text -class AttributeMenu : MenuComponent(Sizing.fill(75), Sizing.content(), Algorithm.VERTICAL) { +class AttributeMenu : MenuComponent(Sizing.fill(100), Sizing.fill(100), Algorithm.VERTICAL) { private fun onLevelUpdate(level: Int) {} /** Whenever ANY attribute gets updated. */ @@ -28,7 +28,7 @@ class AttributeMenu : MenuComponent(Sizing.fill(75), Sizing.content(), Algorithm override fun build(player: ClientPlayerEntity, adapter: OwoUIAdapter, component: IPlayerDataComponent) { child(Components.label(Text.translatable("playerex.ui.category.primary_attributes"))) - child(Components.box(Sizing.fill(60), Sizing.fixed(2))) + child(Components.box(Sizing.fill(35), Sizing.fixed(2))) gap(5) children(PlayerEXAttributes.PRIMARY_ATTRIBUTE_IDS.mapNotNull(Registries.ATTRIBUTE::get).map { AttributeComponent(it, player, component) }) positioning(Positioning.relative(10, 25)) diff --git a/src/client/resources/assets/playerex/owo_ui/main_ui_model.xml b/src/client/resources/assets/playerex/owo_ui/main_ui_model.xml index 9e52e045..3ccecc8d 100644 --- a/src/client/resources/assets/playerex/owo_ui/main_ui_model.xml +++ b/src/client/resources/assets/playerex/owo_ui/main_ui_model.xml @@ -14,7 +14,7 @@ playerex.ui.main.title center - 25 + 30 25 0,50 @@ -44,7 +44,7 @@ @@ -65,7 +64,7 @@ playerex.ui.main.exit playerex.ui.main.exit.tooltip - 604 + 1004 @@ -99,7 +98,9 @@ -