first commit
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package de.fullrisk.citrusDev;
|
||||
|
||||
import io.wispforest.owo.ui.base.BaseOwoScreen;
|
||||
import io.wispforest.owo.ui.component.UIComponents;
|
||||
import io.wispforest.owo.ui.container.FlowLayout;
|
||||
import io.wispforest.owo.ui.container.UIContainers;
|
||||
import io.wispforest.owo.ui.core.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import de.fullrisk.citrusDev.ScalableLabel;
|
||||
import de.fullrisk.citrusDev.ScalableButton;
|
||||
import de.fullrisk.citrusDev.ScaleValue;
|
||||
|
||||
public class MyScreen extends BaseOwoScreen<FlowLayout> {
|
||||
|
||||
public MyScreen() {
|
||||
super(Component.literal("Citrus Dev"));
|
||||
Minecraft.getInstance().getSoundManager().play(
|
||||
SimpleSoundInstance.forUI(SoundEvents.UI_TOAST_IN, 1.5F, 2)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OwoUIAdapter<FlowLayout> createAdapter() {
|
||||
return OwoUIAdapter.create(this, UIContainers::verticalFlow);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void build(FlowLayout rootComponent) {
|
||||
rootComponent
|
||||
.horizontalAlignment(HorizontalAlignment.CENTER)
|
||||
.verticalAlignment(VerticalAlignment.CENTER);
|
||||
|
||||
FlowLayout panel = UIContainers.verticalFlow(Sizing.content(), Sizing.content());
|
||||
panel.gap(6);
|
||||
panel.padding(Insets.of(12));
|
||||
|
||||
panel.horizontalAlignment(HorizontalAlignment.CENTER);
|
||||
panel.verticalAlignment(VerticalAlignment.CENTER);
|
||||
panel.horizontalSizing(Sizing.fixed(0));
|
||||
panel.verticalSizing(Sizing.fixed(0));
|
||||
panel.horizontalSizing().animate(300, Easing.CUBIC, Sizing.fixed(250)).forwards();
|
||||
panel.verticalSizing().animate(300, Easing.CUBIC, Sizing.fixed(150)).forwards();
|
||||
|
||||
var header = new ScalableLabel(Component.literal("Citrus Dev"));
|
||||
panel.child(header);
|
||||
|
||||
var header_button = new ScalableButton(Component.literal("Click me"), btn -> {
|
||||
btn.setMessage(Component.literal("Clicked!"));
|
||||
Minecraft.getInstance().getSoundManager().play(
|
||||
SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK.value(), 2.0F, 2)
|
||||
);
|
||||
});
|
||||
|
||||
header_button.scale().animate(300, Easing.CUBIC, new ScaleValue(1f)).forwards();
|
||||
panel.child(header_button);
|
||||
header.scale().animate(300, Easing.CUBIC, new ScaleValue(2f)).forwards();
|
||||
|
||||
|
||||
Surface glassPanel = Surface.blur(5f, 15f)
|
||||
.and(Surface.flat(0x40FFFFFF))
|
||||
.and(Surface.outline(0xFFFFFFFF));
|
||||
|
||||
panel.surface(glassPanel);
|
||||
|
||||
var version = new ScalableLabel(Component.literal("Citrus-Dev v2.0"))
|
||||
.horizontalTextAlignment(HorizontalAlignment.RIGHT)
|
||||
.verticalTextAlignment(VerticalAlignment.BOTTOM);
|
||||
|
||||
panel.child(version);
|
||||
rootComponent.child(panel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isPauseScreen() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package de.fullrisk.citrusDev;
|
||||
|
||||
import io.wispforest.owo.ui.component.ButtonComponent;
|
||||
import io.wispforest.owo.ui.core.AnimatableProperty;
|
||||
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));
|
||||
|
||||
public ScalableButton(Component message, Consumer<ButtonComponent> onPress) {
|
||||
super(message, onPress);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user