62 lines
2.3 KiB
Java
62 lines
2.3 KiB
Java
package de.fullrisk.citrusDev.UI;
|
|
|
|
import io.wispforest.owo.ui.component.LabelComponent;
|
|
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 io.wispforest.owo.ui.hud.Hud;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.resources.Identifier;
|
|
|
|
public class Module_FPS {
|
|
|
|
private static LabelComponent fpsLabel;
|
|
private static FlowLayout fpsContainer;
|
|
static boolean toggle = true;
|
|
private static boolean shown = false; // tracks current visible/built state
|
|
|
|
private static final Surface GLASS_PANEL = Surface.blur(5f, 15f)
|
|
.and(Surface.flat(0x40FFFFFF));
|
|
|
|
public static void register() {
|
|
Hud.add(Identifier.fromNamespaceAndPath("citrus-dev", "fps_display"), () -> {
|
|
if (fpsContainer == null) {
|
|
fpsLabel = UIComponents.label(Component.literal(""));
|
|
|
|
fpsContainer = UIContainers.horizontalFlow(Sizing.content(), Sizing.content());
|
|
fpsContainer.gap(4);
|
|
fpsContainer.verticalAlignment(VerticalAlignment.CENTER);
|
|
fpsContainer.horizontalAlignment(HorizontalAlignment.CENTER);
|
|
fpsContainer.positioning(Positioning.absolute(10, 10));
|
|
// start hidden; tick()/first update will populate it
|
|
fpsContainer.padding(Insets.of(0));
|
|
}
|
|
return fpsContainer;
|
|
});
|
|
}
|
|
|
|
public static void tick() {
|
|
if (fpsContainer == null) return;
|
|
|
|
if (toggle && !shown) {
|
|
// turning on: restore the panel chrome and label
|
|
fpsContainer.surface(GLASS_PANEL);
|
|
fpsContainer.padding(Insets.of(6));
|
|
fpsContainer.child(fpsLabel);
|
|
shown = true;
|
|
} else if (!toggle && shown) {
|
|
// turning off: strip everything so it collapses to nothing
|
|
fpsContainer.clearChildren();
|
|
fpsContainer.surface(Surface.flat(0));
|
|
fpsContainer.padding(Insets.of(0));
|
|
shown = false;
|
|
}
|
|
|
|
if (!toggle) return;
|
|
|
|
Minecraft client = Minecraft.getInstance();
|
|
fpsLabel.text(Component.literal(client.getFps() + " FPS"));
|
|
}
|
|
} |