tesing new ui scope

This commit is contained in:
2025-04-20 17:24:53 +02:00
parent 5c15af0590
commit 9f0d5ef78b
7 changed files with 152 additions and 128 deletions
@@ -1,77 +1,15 @@
package org.saturnclient.saturnclient.menus; package org.saturnclient.saturnclient.menus;
import net.minecraft.client.MinecraftClient; import org.saturnclient.ui2.SaturnScreen;
import net.minecraft.text.Text; import org.saturnclient.ui2.elements.Text;
import org.saturnclient.saturnclient.SaturnClientConfig; public class SaturnMenu extends SaturnScreen {
import org.saturnclient.ui.SaturnUi;
import org.saturnclient.ui.Textures;
import org.saturnclient.ui.animations.FadeIn;
import org.saturnclient.ui.animations.Slide;
import org.saturnclient.ui.widgets.SaturnButton;
import org.saturnclient.ui.widgets.SaturnImage;
import org.saturnclient.ui.widgets.SaturnImageButton;
public class SaturnMenu extends SaturnUi {
public SaturnMenu() { public SaturnMenu() {
super(Text.literal("Saturn Client")); super("Saturn Client");
} }
@Override @Override
protected void init() { public void ui() {
SaturnClientConfig.textRenderer = MinecraftClient.getInstance().textRenderer; draw(new Text("Saturn Client"));
int buttonWidth = 96;
int buttonHeight = 25;
draw(
new SaturnButton("Mods", () -> {
client.setScreen(new ModMenu());
})
.setX((width - buttonWidth) / 2)
.setY((height - buttonHeight) / 2)
.setWidth(buttonWidth)
.setHeight(buttonHeight)
.setAnimations(new FadeIn(2)));
draw(
new SaturnImageButton(Textures.HUD_ICON, 14, 14, () -> {
client.setScreen(new HudEditor());
})
.setX((width - buttonWidth - (buttonHeight * 2) - 6) / 2)
.setY((height - buttonHeight) / 2)
.setWidth(buttonHeight)
.setHeight(buttonHeight)
.setAnimations(new FadeIn(2)));
draw(
new SaturnImageButton(Textures.COSMETICS, 14, 14, () -> {
client.setScreen(new CloaksMenu());
})
.setX((width / 2) + (buttonWidth / 2) + 3)
.setY((height - buttonHeight) / 2)
.setWidth(buttonHeight)
.setHeight(buttonHeight)
.setAnimations(new FadeIn(2)));
int logoSize = 49;
draw(
new SaturnImage(Textures.LOGO_TEXT)
.setX((width - logoSize) / 2)
.setY((height - 8) / 2 - 23)
.setWidth(logoSize)
.setHeight(8)
.setAnimations(new FadeIn(2)));
draw(
new SaturnImage(SaturnClientConfig.getLogo())
.setX((width - logoSize) / 2)
.setY(height / 2 - logoSize - 24)
.setWidth(logoSize)
.setHeight(logoSize)
.setAnimations(new Slide(2, 14)));
super.init();
} }
} }
@@ -0,0 +1,12 @@
package org.saturnclient.saturnclient.mixin;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.VertexConsumerProvider;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(DrawContext.class)
public interface DrawContextAccessor {
@Accessor("vertexConsumers")
VertexConsumerProvider.Immediate getVertexConsumers();
}
@@ -1,5 +1,12 @@
package org.saturnclient.ui2; package org.saturnclient.ui2;
public class Element { public class Element {
protected int x;
protected int y;
protected int width;
protected int height;
protected int color;
public void render(RenderScope renderScope) {
}
} }
@@ -2,6 +2,9 @@ package org.saturnclient.ui2;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.font.TextRenderer.TextLayerType;
import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexConsumerProvider;
@@ -46,7 +49,6 @@ public class RenderScope {
vertexConsumer.vertex(matrix4f, (float) x2, (float) y1, 0).color(color); vertexConsumer.vertex(matrix4f, (float) x2, (float) y1, 0).color(color);
} }
public void drawTexture(int x, int y, int width, int height, int color) { public void drawTexture(int x, int y, int width, int height, int color) {
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix(); Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
@@ -75,23 +77,30 @@ public class RenderScope {
vertexConsumer.vertex(matrix4f, (float) x2, (float) y1, 0).color(color); vertexConsumer.vertex(matrix4f, (float) x2, (float) y1, 0).color(color);
} }
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight, int color) { public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth,
int textureHeight, int color) {
this.drawTexture(sprite, x, y, u, v, width, height, width, height, textureWidth, textureHeight, color); this.drawTexture(sprite, x, y, u, v, width, height, width, height, textureWidth, textureHeight, color);
} }
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) { public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth,
int textureHeight) {
this.drawTexture(sprite, x, y, u, v, width, height, width, height, textureWidth, textureHeight); this.drawTexture(sprite, x, y, u, v, width, height, width, height, textureWidth, textureHeight);
} }
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWith, int regionHeight, int textureWidth, int textureHeight) { public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWith,
int regionHeight, int textureWidth, int textureHeight) {
this.drawTexture(sprite, x, y, u, v, width, height, regionWith, regionHeight, textureWidth, textureHeight, -1); this.drawTexture(sprite, x, y, u, v, width, height, regionWith, regionHeight, textureWidth, textureHeight, -1);
} }
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWidth, int regionHeight, int textureWidth, int textureHeight, int color) { public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWidth,
this.drawTexturedQuad(sprite, x, x + width, y, y + height, (u + 0.0F) / (float)textureWidth, (u + (float)regionWidth) / (float)textureWidth, (v + 0.0F) / (float)textureHeight, (v + (float)regionHeight) / (float)textureHeight, color); int regionHeight, int textureWidth, int textureHeight, int color) {
this.drawTexturedQuad(sprite, x, x + width, y, y + height, (u + 0.0F) / (float) textureWidth,
(u + (float) regionWidth) / (float) textureWidth, (v + 0.0F) / (float) textureHeight,
(v + (float) regionHeight) / (float) textureHeight, color);
} }
private void drawTexturedQuad(Identifier sprite, int x1, int x2, int y1, int y2, float u1, float u2, float v1, float v2, int color) { private void drawTexturedQuad(Identifier sprite, int x1, int x2, int y1, int y2, float u1, float u2, float v1,
float v2, int color) {
RenderLayer renderLayer = RenderLayer.getGuiTextured(sprite); RenderLayer renderLayer = RenderLayer.getGuiTextured(sprite);
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix(); Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer); VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer);
@@ -100,4 +109,10 @@ public class RenderScope {
vertexConsumer.vertex(matrix4f, (float) x2, (float) y2, 0.0F).texture(u2, v2).color(color); vertexConsumer.vertex(matrix4f, (float) x2, (float) y2, 0.0F).texture(u2, v2).color(color);
vertexConsumer.vertex(matrix4f, (float) x2, (float) y1, 0.0F).texture(u2, v1).color(color); vertexConsumer.vertex(matrix4f, (float) x2, (float) y1, 0.0F).texture(u2, v1).color(color);
} }
public void drawText(String text, int x, int y, int color) {
TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
textRenderer.draw(text, (float) x, (float) y, color, false, this.matrices.peek().getPositionMatrix(),
this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
}
} }
@@ -1,12 +1,46 @@
package org.saturnclient.ui2; package org.saturnclient.ui2;
import java.util.ArrayList;
import java.util.List;
import org.saturnclient.saturnclient.mixin.DrawContextAccessor;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text; import net.minecraft.text.Text;
public class SaturnScreen extends Screen { public class SaturnScreen extends Screen {
SaturnScreen(String title) { protected List<Element> elements = new ArrayList<>();
public SaturnScreen(String title) {
super(Text.literal(title)); super(Text.literal(title));
} }
public void draw(Element element) {
synchronized (elements) {
elements.add(element);
}
}
@Override
protected void init() {
ui();
// Do stuff
}
public void ui() {
}
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
// We are using a Abstracted RenderScope because older minecraft versions don't
// use DrawContext
RenderScope renderScope = new RenderScope(context.getMatrices(),
((DrawContextAccessor) context).getVertexConsumers());
for (Element element : elements) {
element.render(renderScope);
}
}
} }
@@ -0,0 +1,17 @@
package org.saturnclient.ui2.elements;
import org.saturnclient.ui2.Element;
import org.saturnclient.ui2.RenderScope;
public class Text extends Element {
private String text;
public Text(String text) {
this.text = text;
}
@Override
public void render(RenderScope renderScope) {
renderScope.drawText(this.text, this.x, this.y, this.color);
}
}
+2 -1
View File
@@ -12,7 +12,8 @@
"TotemParticleMixin", "TotemParticleMixin",
"Crosshair", "Crosshair",
"EntityMixin", "EntityMixin",
"CameraMixin" "CameraMixin",
"DrawContextAccessor"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1