This commit is contained in:
2026-07-05 21:14:50 +02:00
parent eaeb467db9
commit 999b51ce66
8 changed files with 251 additions and 129 deletions
@@ -0,0 +1,19 @@
package de.fullrisk.citrusDev.UIHelper;
import io.wispforest.owo.ui.core.Animatable;
import net.minecraft.util.Mth;
public record ColorValue(int argb) implements Animatable<ColorValue> {
@Override
public ColorValue interpolate(ColorValue next, float delta) {
int a1 = (this.argb >> 24) & 0xFF, r1 = (this.argb >> 16) & 0xFF, g1 = (this.argb >> 8) & 0xFF, b1 = this.argb & 0xFF;
int a2 = (next.argb >> 24) & 0xFF, r2 = (next.argb >> 16) & 0xFF, g2 = (next.argb >> 8) & 0xFF, b2 = next.argb & 0xFF;
int a = Mth.floor(Mth.lerp(delta, a1, a2));
int r = Mth.floor(Mth.lerp(delta, r1, r2));
int g = Mth.floor(Mth.lerp(delta, g1, g2));
int b = Mth.floor(Mth.lerp(delta, b1, b2));
return new ColorValue((a << 24) | (r << 16) | (g << 8) | b);
}
}
@@ -0,0 +1,91 @@
package de.fullrisk.citrusDev.UIHelper;
import io.wispforest.owo.ui.component.ButtonComponent;
import io.wispforest.owo.ui.core.AnimatableProperty;
import io.wispforest.owo.ui.core.Easing;
import io.wispforest.owo.ui.core.OwoUIGraphics;
import net.minecraft.network.chat.Component;
import java.util.function.Consumer;
public class ScalableButton extends ButtonComponent {
protected final AnimatableProperty<ScaleValue> scale = AnimatableProperty.of(new ScaleValue(0f));
protected final AnimatableProperty<ColorValue> fillColor;
protected final AnimatableProperty<ColorValue> outlineColor;
private final int baseFill;
private final int hoveredFill;
private final int baseOutline;
private final int hoveredOutline;
private final int outlineWidth;
private boolean wasHovered = false;
public ScalableButton(Component message, Consumer<ButtonComponent> onPress,
int baseFill, int hoveredFill,
int baseOutline, int hoveredOutline,
int outlineWidth) {
super(message, onPress);
this.baseFill = baseFill;
this.hoveredFill = hoveredFill;
this.baseOutline = baseOutline;
this.hoveredOutline = hoveredOutline;
this.outlineWidth = outlineWidth;
this.fillColor = AnimatableProperty.of(new ColorValue(baseFill));
this.outlineColor = AnimatableProperty.of(new ColorValue(baseOutline));
this.renderer((context, button, delta) -> {
int x = button.getX();
int y = button.getY();
int w = button.getWidth();
int h = button.getHeight();
int fill = this.fillColor.get().argb();
int outline = this.outlineColor.get().argb();
context.fill(x, y, x + w, y + h, fill);
context.fill(x, y, x + w, y + this.outlineWidth, outline); // top
context.fill(x, y + h - this.outlineWidth, x + w, y + h, outline); // bottom
context.fill(x, y, x + this.outlineWidth, y + h, outline); // left
context.fill(x + w - this.outlineWidth, y, x + w, y + h, outline); // right
});
}
public AnimatableProperty<ScaleValue> scale() {
return this.scale;
}
@Override
public void update(float delta, int mouseX, int mouseY) {
super.update(delta, mouseX, mouseY);
this.scale.update(delta);
this.fillColor.update(delta);
this.outlineColor.update(delta);
boolean hovered = this.isHovered();
if (hovered != this.wasHovered) {
this.fillColor.animate(150, Easing.CUBIC, new ColorValue(hovered ? hoveredFill : baseFill)).forwards();
this.outlineColor.animate(150, Easing.CUBIC, new ColorValue(hovered ? hoveredOutline : baseOutline)).forwards();
this.wasHovered = hovered;
}
}
@Override
public void draw(OwoUIGraphics graphics, int mouseX, int mouseY, float partialTicks, float delta) {
float s = this.scale.get().value();
float centerX = this.x() + this.width() / 2f;
float centerY = this.y() + this.height() / 2f;
graphics.pose().pushMatrix();
graphics.pose().translate(centerX, centerY);
graphics.pose().scale(s, s);
graphics.pose().translate(-centerX, -centerY);
super.draw(graphics, mouseX, mouseY, partialTicks, delta);
graphics.pose().popMatrix();
}
}
@@ -0,0 +1,42 @@
package de.fullrisk.citrusDev.UIHelper;
import io.wispforest.owo.ui.component.LabelComponent;
import io.wispforest.owo.ui.core.AnimatableProperty;
import io.wispforest.owo.ui.core.OwoUIGraphics;
import net.minecraft.network.chat.Component;
public class ScalableLabel extends LabelComponent {
protected final AnimatableProperty<ScaleValue> scale = AnimatableProperty.of(new ScaleValue(0f));
public ScalableLabel(Component text) {
super(text);
}
public AnimatableProperty<ScaleValue> scale() {
return this.scale;
}
@Override
public void update(float delta, int mouseX, int mouseY) {
super.update(delta, mouseX, mouseY);
this.scale.update(delta);
}
@Override
public void draw(OwoUIGraphics graphics, int mouseX, int mouseY, float partialTicks, float delta) {
float s = this.scale.get().value();
float centerX = this.x() + this.width() / 2f;
float centerY = this.y() + this.height() / 2f;
graphics.pose().pushMatrix();
graphics.pose().translate(centerX, centerY);
graphics.pose().scale(s, s);
graphics.pose().translate(-centerX, -centerY);
super.draw(graphics, mouseX, mouseY, partialTicks, delta);
graphics.pose().popMatrix();
}
}
@@ -0,0 +1,11 @@
package de.fullrisk.citrusDev.UIHelper;
import io.wispforest.owo.ui.core.Animatable;
import net.minecraft.util.Mth;
public record ScaleValue(float value) implements Animatable<ScaleValue> {
@Override
public ScaleValue interpolate(ScaleValue next, float delta) {
return new ScaleValue(Mth.lerp(delta, this.value, next.value));
}
}