package fun.demure.ui.display.impl;
import com.mojang.blaze3d.matrix.MatrixStack;
import fun.demure.Demure;
import fun.demure.events.EventDisplay;
import fun.demure.functions.api.Function;
import fun.demure.ui.display.ElementRenderer;
import fun.demure.ui.styles.Style;
import fun.demure.utils.client.KeyStorage;
import fun.demure.utils.drag.Dragging;
import fun.demure.utils.math.MathUtil;
import fun.demure.utils.math.Vector4i;
import fun.demure.utils.render.ColorUtils;
import fun.demure.utils.render.DisplayUtils;
import fun.demure.utils.render.KawaseBlur;
import fun.demure.utils.render.Scissor;
import fun.demure.utils.render.font.Fonts;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import net.minecraft.util.math.vector.Vector4f;
import java.util.Locale;
@FieldDefaults(level = AccessLevel.PRIVATE)
@RequiredArgsConstructor
public class KeyBindRenderer implements ElementRenderer {
final Dragging dragging;
float width;
float height;
@Override
public void render(EventDisplay eventDisplay) {
MatrixStack ms = eventDisplay.getMatrixStack();
KawaseBlur.blur.updateBlur(1, 1);
final float posX = dragging.getX();
final float posY = dragging.getY();
final float currentWidth = width;
final float currentHeight = height-2.5f;
float fontSize = 7f;
float padding = 5;
Style style = Demure.getInstance().getStyleManager().getCurrentStyle();
String name = "Keybinds";
KawaseBlur.blur.render(() -> {
DisplayUtils.drawRoundedRect(posX-1.5f, posY-0.5f, currentWidth+2, currentHeight, 6, ColorUtils.rgba(25,25,25,120));
});
DisplayUtils.drawGradientRound(posX-1.5f-1+1, posY-1.5f, currentWidth+2, currentHeight+2, 6.5f,ColorUtils.setAlpha(style.getFirstColor().getRGB(), 195),style.getFirstColor().getRGB(),style.getFirstColor().getRGB(),style.getFirstColor().getRGB());
DisplayUtils.drawGradientRound(posX-1.5f-1+1, posY-1.5f, currentWidth+2, currentHeight+2, 6.5f,ColorUtils.setAlpha(ColorUtils.rgb(0,0,0), 105),ColorUtils.rgb(0,0,0),ColorUtils.rgb(0,0,0),ColorUtils.rgb(0,0,0));
DisplayUtils.drawGradientRound(posX-1.5f+1, posY-0.5f, currentWidth, currentHeight, 6,ColorUtils.rgba(5,5,5,170),ColorUtils.rgba(5,5,5,170),ColorUtils.rgba(5,5,5,170),ColorUtils.rgba(5,5,5,170));
float fixYs = posY+16;
DisplayUtils.drawRoundedRect(posX-1f, fixYs - 1.5f, currentWidth+1,currentHeight-14.5f,new Vector4f(0,6,0,6), ColorUtils.rgba(0,0,0,55));
Scissor.push();
Scissor.setFromComponentCoordinates(posX, posY-0.5f, currentWidth, currentHeight);
Fonts.relbold.drawText(ms, name, posX+4, posY-1 +4.5f, ColorUtils.rgb(255,255,255), 7.5f, .08f);
fun.demure.utils.font.Fonts.icons1[16].drawString(ms, "C", posX+currentWidth/1.2f, posY-1 + 7, style.getFirstColor().getRGB());
float renderPosY = posY + fontSize + padding * 2;
float maxWidth = Fonts.sflight.getWidth(name, fontSize) + padding * 2;
float localHeight = fontSize + padding * 2;
renderPosY += 3f;
for (Function f : Demure.getInstance().getFunctionRegistry().getFunctions()) {
f.getAnimation().update();
if (!(f.getAnimation().getValue() > 0) || f.getBind() == 0) continue;
String nameText = f.getName();
float nameWidth = Fonts.sflight.getWidth(nameText, fontSize);
String bindText = "[" + KeyStorage.getKey(f.getBind()) + "]";
float bindWidth = Fonts.sflight.getWidth(bindText, fontSize);
float localWidth = nameWidth + bindWidth + padding * 3;
Fonts.sflight.drawText(ms, nameText, posX-1 + padding, renderPosY - 1.5f,
ColorUtils.rgba(255,255,255, (int) (190 * f.getAnimation().getValue())), 7f, .17f);
Fonts.sflight.drawText(ms, bindText, posX-2 + currentWidth - padding - bindWidth+2, renderPosY - 1.5f,
style.getFirstColor().getRGB(), 7f, .13f);
if (localWidth > maxWidth) {
maxWidth = localWidth;
}
renderPosY += (float) ((fontSize + padding) * f.getAnimation().getValue());
localHeight += (float) ((fontSize + padding) * f.getAnimation().getValue());
}
Scissor.unset();
Scissor.pop();
this.width = Math.max(maxWidth, 80);
this.height = localHeight + 2.5f;
dragging.setWidth(this.width);
dragging.setHeight(this.height);
}
}