Added Quests and Real Settings (yay)
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package de.fullrisk.citrusDev.UIHelper;
|
||||
|
||||
import io.wispforest.owo.ui.core.Color;
|
||||
import io.wispforest.owo.ui.core.OwoUIGraphics;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||
import net.minecraft.client.gui.components.toasts.Toast;
|
||||
import net.minecraft.client.gui.components.toasts.ToastManager;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.client.renderer.RenderPipelines;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
public class CitrusToast implements Toast {
|
||||
|
||||
private static final int WIDTH = 180;
|
||||
private static final int HEIGHT = 32;
|
||||
private static final long DEFAULT_DURATION_MS = 3000L;
|
||||
|
||||
private final String title;
|
||||
private final String message;
|
||||
private final long durationMs;
|
||||
|
||||
private Visibility wantedVisibility = Visibility.SHOW;
|
||||
|
||||
private CitrusToast(String title, String message, long durationMs) {
|
||||
this.title = title;
|
||||
this.message = message;
|
||||
this.durationMs = durationMs;
|
||||
}
|
||||
|
||||
public static void show(String title, String message) {
|
||||
show(title, message, DEFAULT_DURATION_MS);
|
||||
}
|
||||
|
||||
public static void show(String title, String message, long durationMs) {
|
||||
Minecraft.getInstance().getToastManager().addToast(new CitrusToast(title, message, durationMs));
|
||||
}
|
||||
@Override
|
||||
public Visibility getWantedVisibility() {
|
||||
return this.wantedVisibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ToastManager manager, long fullyVisibleForMs) {
|
||||
if (fullyVisibleForMs >= this.durationMs) {
|
||||
this.wantedVisibility = Visibility.HIDE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable SoundEvent getSoundEvent() {
|
||||
return SoundEvents.UI_TOAST_IN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int width() {
|
||||
return WIDTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int height() {
|
||||
return HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractRenderState(GuiGraphicsExtractor graphics, Font font, long fullyVisibleForMs) {
|
||||
OwoUIGraphics owo = OwoUIGraphics.of(graphics);
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int w = WIDTH;
|
||||
int h = HEIGHT;
|
||||
|
||||
// glass background, matching GLASS_PANEL style
|
||||
owo.fill(RenderPipelines.GUI, x, y, x + w, y + h, 0x40FFFFFF);
|
||||
owo.drawRectOutline(RenderPipelines.GUI, x, y, w, h, 0x64de4b);
|
||||
|
||||
owo.drawText(Component.literal(this.title), x + 6, y + 6, 1f, 0xFFFFFFFF);
|
||||
owo.drawText(Component.literal(this.message), x + 6, y + 18, 0.8f, 0xFFa3a3ac);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package de.fullrisk.citrusDev.UIHelper;
|
||||
|
||||
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.resources.Identifier;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.DoubleConsumer;
|
||||
import java.util.function.DoubleFunction;
|
||||
|
||||
|
||||
|
||||
public class SettingsControls {
|
||||
|
||||
private static final Surface GLASS_PANEL = Surface.blur(5f, 15f)
|
||||
.and(Surface.flat(0x40FFFFFF))
|
||||
.and(Surface.outline(0x64de4b));
|
||||
|
||||
public record ButtonState(String label, Runnable onSelect) {}
|
||||
|
||||
public static FlowLayout makeSmallButton(Surface baseSurface, Identifier texture, Runnable onClick) {
|
||||
FlowLayout button = UIContainers.verticalFlow(Sizing.fixed(16), Sizing.fixed(16));
|
||||
button.verticalAlignment(VerticalAlignment.CENTER);
|
||||
button.horizontalAlignment(HorizontalAlignment.CENTER);
|
||||
button.surface(baseSurface);
|
||||
button.child(UIComponents.texture(texture, 0, 0, 12, 12, 12, 12))
|
||||
.horizontalAlignment(HorizontalAlignment.CENTER)
|
||||
.verticalAlignment(VerticalAlignment.CENTER);
|
||||
|
||||
button.mouseEnter().subscribe(() -> button.surface(
|
||||
Surface.blur(5f, 15f).and(Surface.flat(0x70FFFFFF)).and(Surface.outline(0xFFFFFFFF))
|
||||
));
|
||||
button.mouseLeave().subscribe(() -> button.surface(baseSurface));
|
||||
|
||||
button.mouseDown().subscribe((click, doubled) -> {
|
||||
Minecraft.getInstance().getSoundManager().play(
|
||||
SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK.value(), 2.0F, 2)
|
||||
);
|
||||
onClick.run();
|
||||
return true;
|
||||
});
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
public static FlowLayout makeTextButton(Surface baseSurface, String text, Runnable onClick) {
|
||||
FlowLayout button = UIContainers.verticalFlow(Sizing.content(), Sizing.content());
|
||||
button.verticalAlignment(VerticalAlignment.CENTER);
|
||||
button.horizontalAlignment(HorizontalAlignment.CENTER);
|
||||
button.padding(Insets.of(2, 2, 4, 4));
|
||||
button.surface(baseSurface);
|
||||
button.child(UIComponents.label(Component.literal(text)).color(Color.ofRgb(0xFFFFFF)));
|
||||
|
||||
button.mouseEnter().subscribe(() -> button.surface(
|
||||
Surface.blur(5f, 15f).and(Surface.flat(0x70FFFFFF)).and(Surface.outline(0xFFFFFFFF))
|
||||
));
|
||||
button.mouseLeave().subscribe(() -> button.surface(baseSurface));
|
||||
|
||||
button.mouseDown().subscribe((click, doubled) -> {
|
||||
Minecraft.getInstance().getSoundManager().play(
|
||||
SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK.value(), 2.0F, 2)
|
||||
);
|
||||
onClick.run();
|
||||
return true;
|
||||
});
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
public static FlowLayout makeCyclingButton(Surface baseSurface, List<ButtonState> states) {
|
||||
int[] currentIndex = {0};
|
||||
|
||||
FlowLayout button = UIContainers.verticalFlow(Sizing.fixed(50), Sizing.fixed(16));
|
||||
button.verticalAlignment(VerticalAlignment.CENTER);
|
||||
button.horizontalAlignment(HorizontalAlignment.CENTER);
|
||||
button.surface(baseSurface);
|
||||
|
||||
var label = UIComponents.label(Component.literal(states.get(0).label()))
|
||||
.color(Color.ofRgb(0xFFFFFF));
|
||||
button.child(label);
|
||||
|
||||
button.mouseDown().subscribe((click, doubled) -> {
|
||||
Minecraft.getInstance().getSoundManager().play(
|
||||
SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK.value(), 2.0F, 2)
|
||||
);
|
||||
|
||||
currentIndex[0] = (currentIndex[0] + 1) % states.size();
|
||||
ButtonState newState = states.get(currentIndex[0]);
|
||||
|
||||
label.text(Component.literal(newState.label()));
|
||||
newState.onSelect().run();
|
||||
|
||||
return true;
|
||||
});
|
||||
button.mouseEnter().subscribe(() -> label.color(Color.ofRgb(0xFFFFFF)));
|
||||
button.mouseLeave().subscribe(() -> label.color(Color.ofRgb(0xCCCCCC)));
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
public static FlowLayout makeSlider(Surface baseSurface, int width, double min, double max, double initial,
|
||||
DoubleFunction<String> labelFormatter, DoubleConsumer onChange) {
|
||||
int labelWidth = 34;
|
||||
int sliderWidth = width - labelWidth - 6;
|
||||
|
||||
FlowLayout wrapper = UIContainers.horizontalFlow(Sizing.fixed(width), Sizing.fixed(16));
|
||||
wrapper.verticalAlignment(VerticalAlignment.CENTER);
|
||||
wrapper.horizontalAlignment(HorizontalAlignment.LEFT);
|
||||
wrapper.padding(Insets.of(2, 2, 4, 0));
|
||||
wrapper.gap(2);
|
||||
|
||||
var valueLabel = UIComponents.label(Component.literal(labelFormatter.apply(initial)));
|
||||
valueLabel.color(Color.ofRgb(0xFFFFFF));
|
||||
valueLabel.horizontalSizing(Sizing.fixed(labelWidth));
|
||||
wrapper.child(valueLabel);
|
||||
|
||||
var slider = UIComponents.discreteSlider(Sizing.fixed(sliderWidth), min, max);
|
||||
slider.horizontalSizing(Sizing.fixed(sliderWidth));
|
||||
slider.verticalSizing(Sizing.fixed(10));
|
||||
slider.setFromDiscreteValue(initial);
|
||||
slider.cursorStyle(CursorStyle.POINTER);
|
||||
slider.mouseDown().subscribe((click, doubled) -> {
|
||||
return doubled;
|
||||
});
|
||||
slider.onChanged().subscribe(value -> {
|
||||
valueLabel.text(Component.literal(labelFormatter.apply(value)));
|
||||
onChange.accept(value);
|
||||
});
|
||||
|
||||
wrapper.child(slider);
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user