Skip to content

Commit

Permalink
UI stuff & mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Jun 25, 2024
1 parent 7cde619 commit 835357d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 41 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ owo_version=0.11.2+1.20

gadget_version=0.2.2+1.20

endec_version=0.1.0-pre.7
endec_version=0.1.0-pre.1
endec_version_2=0.1.0-pre.1

mixinextras_version=0.4.0-beta.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ abstract class EntityAttributeInstanceMixin implements MutableAttributeInstance,
@Shadow
private Set<EntityAttributeModifier> persistentModifiers;

@Shadow
private double baseValue;

@Shadow
private Collection<EntityAttributeModifier> getModifiersByOperation(EntityAttributeModifier.Operation operation) {
return Collections.emptySet();
Expand All @@ -69,7 +66,7 @@ private Collection<EntityAttributeModifier> getModifiersByOperation(EntityAttrib
@Shadow
protected void onUpdate() {}

@Shadow private double value;
@Shadow public abstract double getBaseValue();

@Inject(method = "<init>", at = @At("TAIL"))
private void data_init(EntityAttribute type, Consumer<EntityAttributeInstance> updateCallback, CallbackInfo ci) {
Expand All @@ -91,12 +88,12 @@ private double data_computeValue(Operation<Double> original) {

double k = 0.0D, v = 0.0D, k2 = 0.0D, v2 = 0.0D;

if (this.baseValue > 0.0D) {
k = formula.stack(k, this.baseValue);
k2 = formula.max(k2, this.baseValue);
if (this.getBaseValue() > 0.0D) {
k = formula.stack(k, this.getBaseValue());
k2 = formula.max(k2, this.getBaseValue());
} else {
v = formula.stack(v, this.baseValue);
v2 = formula.max(v2, this.baseValue);
v = formula.stack(v, this.getBaseValue());
v2 = formula.max(v2, this.getBaseValue());
}

for (EntityAttributeModifier modifier : this.getModifiersByOperation(EntityAttributeModifier.Operation.ADDITION)) {
Expand Down Expand Up @@ -164,13 +161,14 @@ private double data_computeValue(Operation<Double> original) {
}
}

double value = ((EntityAttribute) attribute).clamp(e);

if (formula == StackingFormula.Diminished) {
value = value * (attribute.data_attributes$max() - attribute.data_attributes$min());
value += attribute.data_attributes$min();
e = e * (attribute.data_attributes$max() - attribute.data_attributes$min());
e += attribute.data_attributes$min();
}

double value = ((EntityAttribute) attribute).clamp(e);

return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import com.bibireden.data_attributes.config.OverridesConfigModel.AttributeOverri
import com.bibireden.data_attributes.data.AttributeFunctionConfigData
import com.bibireden.data_attributes.data.EntityTypeData
import com.bibireden.data_attributes.mutable.MutableEntityAttribute
import com.bibireden.data_attributes.ui.ColorCodes
import com.bibireden.data_attributes.ui.components.ButtonComponents
import com.bibireden.data_attributes.ui.colors.ColorCodes
import com.bibireden.data_attributes.ui.renderers.ButtonRenderers
import com.bibireden.data_attributes.utils.round
import com.google.common.base.Predicate
import io.wispforest.owo.config.Option
import io.wispforest.owo.config.ui.OptionComponentFactory
import io.wispforest.owo.config.ui.component.ConfigToggleButton
import io.wispforest.owo.config.ui.component.OptionValueProvider
import io.wispforest.owo.ui.component.Components
import io.wispforest.owo.ui.component.TextBoxComponent
import io.wispforest.owo.ui.container.Containers
import io.wispforest.owo.ui.container.FlowLayout
import io.wispforest.owo.ui.core.*
import net.minecraft.client.resource.language.I18n
import net.minecraft.entity.attribute.ClampedEntityAttribute
import net.minecraft.registry.Registries
import net.minecraft.text.MutableText
Expand Down Expand Up @@ -87,22 +87,26 @@ object DataAttributesConfigProviders {
it.tooltip(Text.translatable("text.config.data_attributes.data_entry.invalid"))
}

it.gap(15)
it.child(Containers.horizontalFlow(Sizing.fill(100), Sizing.fixed(15)).also { hf ->
hf.verticalAlignment(VerticalAlignment.BOTTOM)

it.child(Containers.horizontalFlow(Sizing.fill(100), Sizing.fixed(20)).also { hf ->
hf.verticalAlignment(VerticalAlignment.CENTER)
hf.gap(10)

hf.child(Components.label(Text.translatable("text.config.data_attributes.data_entry.overrides.enabled"))
.sizing(Sizing.content(), Sizing.fixed(20)))
hf.child(ConfigToggleButton().apply {
enabled(override.enabled)
onPress { backing.replace(id, override.copy(enabled = !override.enabled)) }
renderer(ButtonRenderers.STANDARD)
})

hf.child(ConfigToggleButton().also { b ->
b.enabled(override.enabled).positioning(Positioning.relative(100, 0))
b.onPress {
this.backing.remove(id)
this.backing.put(id, override.copy(enabled = !override.enabled))
hf.child(Components.button(Text.translatable("text.config.data_attributes.data_entry.reset"))
{
override = override.copy(min = override.min_fallback, max = override.max_fallback)
this.childById(TextBoxComponent::class.java, "inputs.min")!!.write(override.min.toString())
this.childById(TextBoxComponent::class.java, "inputs.max")!!.write(override.max.toString())
this.backing.replace(id, override)
}
})
.renderer(ButtonRenderers.STANDARD)
)
})

it.child(textBoxComponent(
Expand All @@ -111,10 +115,10 @@ object DataAttributesConfigProviders {
::isNumeric,
onChange = {
it.toDoubleOrNull()?.let { v ->
this.backing.remove(id)
this.backing.put(id, override.copy(min = v))
this.backing.replace(id, override.copy(min = v))
}
}
},
"inputs.min"
))

it.child(textBoxComponent(
Expand All @@ -123,10 +127,10 @@ object DataAttributesConfigProviders {
::isNumeric,
onChange = {
it.toDoubleOrNull()?.let { v ->
this.backing.remove(id)
this.backing.put(id, override.copy(max = v))
this.backing.replace(id, override.copy(max = v))
}
}
},
"inputs.max"
))

it.child(textBoxComponent(
Expand Down Expand Up @@ -174,7 +178,7 @@ object DataAttributesConfigProviders {
it.message = Text.translatable("text.config.data_attributes.enum.stackingFormula.${override.formula.name.lowercase()}")
this.backing.replace(id, override.copy(formula = override.formula))
})
.renderer(ButtonComponents.STANDARD)
.renderer(ButtonRenderers.STANDARD)
.positioning(Positioning.relative(100, 0)).horizontalSizing(Sizing.fixed(65))
)
})
Expand Down Expand Up @@ -250,7 +254,7 @@ object DataAttributesConfigProviders {
popped[index] = function.copy(behavior = function.behavior)
this.backing.put(topID, popped)
})
.renderer(ButtonComponents.STANDARD)
.renderer(ButtonRenderers.STANDARD)
.positioning(Positioning.relative(100, 0)).horizontalSizing(Sizing.fixed(65))
)
})
Expand Down Expand Up @@ -302,7 +306,7 @@ object DataAttributesConfigProviders {
override fun parsedValue() = backing
}

fun textBoxComponent(txt: Text, obj: Any, predicate: Predicate<String>? = null, onChange: ((String) -> Unit)? = null): FlowLayout {
fun textBoxComponent(txt: Text, obj: Any, predicate: Predicate<String>? = null, onChange: ((String) -> Unit)? = null, textBoxID: String? = null): FlowLayout {
val isUnchangeable = onChange == null
return Containers.horizontalFlow(Sizing.fill(100), Sizing.fixed(20)).also { hf ->
hf.verticalAlignment(VerticalAlignment.CENTER)
Expand Down Expand Up @@ -332,7 +336,7 @@ object DataAttributesConfigProviders {
true
}
}
}.positioning(Positioning.relative(100, 50))
}.positioning(Positioning.relative(100, 50)).id(textBoxID)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bibireden.data_attributes.ui
package com.bibireden.data_attributes.ui.colors

object ColorCodes {
val BEE_YELLOW = 0xE7C14B
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bibireden.data_attributes.ui.components
package com.bibireden.data_attributes.ui.renderers

import io.wispforest.owo.ui.component.ButtonComponent

object ButtonComponents {
object ButtonRenderers {
val STANDARD = ButtonComponent.Renderer.flat(0x3C3C3C, 0x6F98B0, 0x904C57)
}
6 changes: 5 additions & 1 deletion src/main/resources/assets/data_attributes/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
"text.config.data_attributes.category.overrides": "Overrides",
"text.config.data_attributes.category.functions": "Functions",

"text.config.data_attributes.data_entry.overrides.enabled": "Enabled",
"text.config.data_attributes.data_entry.reset": [
{"text": "", "color": "#6FD392"},
{"text": "Reset", "color": "white"}
],

"text.config.data_attributes.data_entry.overrides.min_fallback": [
{"text": "", "color": "#979797"},
{"text": "Min Fallback", "color": "white"}
Expand Down

0 comments on commit 835357d

Please sign in to comment.