Skip to content

Commit

Permalink
[change] AttributeButtonComponentType -> ButtonType
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Aug 13, 2024
1 parent fa4240f commit 3675168
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class PlayerEXScreen : BaseUIModelScreen<FlowLayout>(FlowLayout::class.java, Dat
return super.keyPressed(keyCode, scanCode, modifiers)
}

enum class AttributeButtonComponentType {
enum class ButtonType {
Add,
Remove;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.bibireden.data_attributes.api.attribute.StackingBehavior
import com.bibireden.data_attributes.api.attribute.StackingFormula
import com.bibireden.playerex.components.player.IPlayerDataComponent
import com.bibireden.playerex.ext.id
import com.bibireden.playerex.ui.PlayerEXScreen.AttributeButtonComponentType
import com.bibireden.playerex.ui.PlayerEXScreen.ButtonType
import com.bibireden.playerex.ui.components.buttons.AttributeButtonComponent
import com.bibireden.playerex.ui.components.labels.AttributeLabelComponent
import com.bibireden.playerex.ui.util.Colors
Expand Down Expand Up @@ -65,12 +65,12 @@ class AttributeComponent(private val attribute: Attribute, private val player: P
.id("${attribute.id}:label")
)

child(AttributeButtonComponent(attribute, player, component, AttributeButtonComponentType.Remove))
child(AttributeButtonComponent(attribute, player, component, ButtonType.Remove))
child(
AttributeLabelComponent(attribute, player).also { label = it }
.horizontalSizing(Sizing.fill(34))
)
child(AttributeButtonComponent(attribute, player, component, AttributeButtonComponentType.Add))
child(AttributeButtonComponent(attribute, player, component, ButtonType.Add))

horizontalAlignment(HorizontalAlignment.RIGHT)
verticalAlignment(VerticalAlignment.CENTER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import net.minecraft.world.entity.ai.attributes.Attribute
import net.minecraft.world.entity.player.Player
import net.minecraft.network.chat.Component

class AttributeButtonComponent(val attribute: Attribute, private val player: Player, private val component: IPlayerDataComponent, val type: PlayerEXScreen.AttributeButtonComponentType) : ButtonComponent(
class AttributeButtonComponent(val attribute: Attribute, private val player: Player, private val component: IPlayerDataComponent, val type: PlayerEXScreen.ButtonType) : ButtonComponent(
Component.literal(type.symbol),
{
// reference text-box to get the necessary value to send to server
Expand All @@ -41,8 +41,8 @@ class AttributeButtonComponent(val attribute: Attribute, private val player: Pla
DataAttributesAPI.getValue(attribute, player).ifPresent { value ->
val max = (attribute as IEntityAttribute).`data_attributes$max`();
this.active(when (type) {
PlayerEXScreen.AttributeButtonComponentType.Add -> component.skillPoints > 0 && max > value
PlayerEXScreen.AttributeButtonComponentType.Remove -> component.refundablePoints > 0 && value > 0
PlayerEXScreen.ButtonType.Add -> component.skillPoints > 0 && max > value
PlayerEXScreen.ButtonType.Remove -> component.refundablePoints > 0 && value > 0
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.bibireden.data_attributes.api.attribute.EntityAttributeSupplier
import com.bibireden.playerex.api.attribute.PlayerEXAttributes
import com.bibireden.playerex.components.player.IPlayerDataComponent
import com.bibireden.playerex.ext.id
import com.bibireden.playerex.ext.level
import com.bibireden.playerex.ui.PlayerEXScreen
import com.bibireden.playerex.ui.childById
import com.bibireden.playerex.ui.components.*
Expand Down Expand Up @@ -84,8 +83,8 @@ class PlayerEXAttributesMenu : MenuComponent(algorithm = Algorithm.HORIZONTAL) {
val max = descendant.attribute.`data_attributes$max`()
val current = DataAttributesAPI.getValue(descendant.attribute, player).orElse(0.0)
when (descendant.type) {
PlayerEXScreen.AttributeButtonComponentType.Add -> descendant.active(result > 0 && component.skillPoints >= result && (current + result) <= max)
PlayerEXScreen.AttributeButtonComponentType.Remove -> descendant.active(result > 0 && component.refundablePoints > 0 && (current - result >= 0))
PlayerEXScreen.ButtonType.Add -> descendant.active(result > 0 && component.skillPoints >= result && (current + result) <= max)
PlayerEXScreen.ButtonType.Remove -> descendant.active(result > 0 && component.refundablePoints > 0 && (current - result >= 0))
}
}
}
Expand Down

0 comments on commit 3675168

Please sign in to comment.