tesing new ui scope
This commit is contained in:
@@ -1,77 +1,15 @@
|
||||
package org.saturnclient.saturnclient.menus;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.Text;
|
||||
import org.saturnclient.ui2.SaturnScreen;
|
||||
import org.saturnclient.ui2.elements.Text;
|
||||
|
||||
import org.saturnclient.saturnclient.SaturnClientConfig;
|
||||
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 class SaturnMenu extends SaturnScreen {
|
||||
public SaturnMenu() {
|
||||
super(Text.literal("Saturn Client"));
|
||||
super("Saturn Client");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
SaturnClientConfig.textRenderer = MinecraftClient.getInstance().textRenderer;
|
||||
|
||||
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();
|
||||
public void ui() {
|
||||
draw(new Text("Saturn Client"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
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 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.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
@@ -22,82 +25,94 @@ public class RenderScope {
|
||||
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
|
||||
|
||||
int x1 = x;
|
||||
int x2 = x+width;
|
||||
int x2 = x + width;
|
||||
int y1 = y;
|
||||
int y2 = y+height;
|
||||
int y2 = y + height;
|
||||
|
||||
int i;
|
||||
if (x1 < x2) {
|
||||
i = x1;
|
||||
x1 = x2;
|
||||
x2 = i;
|
||||
}
|
||||
int i;
|
||||
if (x1 < x2) {
|
||||
i = x1;
|
||||
x1 = x2;
|
||||
x2 = i;
|
||||
}
|
||||
|
||||
if (y1 < y2) {
|
||||
i = y1;
|
||||
y1 = y2;
|
||||
y2 = i;
|
||||
}
|
||||
if (y1 < y2) {
|
||||
i = y1;
|
||||
y1 = y2;
|
||||
y2 = i;
|
||||
}
|
||||
|
||||
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer);
|
||||
vertexConsumer.vertex(matrix4f, (float)x1, (float)y1, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, (float)x1, (float)y2, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, (float)x2, (float)y2, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, (float)x2, (float)y1, 0).color(color);
|
||||
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer);
|
||||
vertexConsumer.vertex(matrix4f, (float) x1, (float) y1, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, (float) x1, (float) y2, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, (float) x2, (float) y2, 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) {
|
||||
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
|
||||
|
||||
int x1 = x;
|
||||
int x2 = x+width;
|
||||
int x2 = x + width;
|
||||
int y1 = y;
|
||||
int y2 = y+height;
|
||||
int y2 = y + height;
|
||||
|
||||
int i;
|
||||
if (x1 < x2) {
|
||||
i = x1;
|
||||
x1 = x2;
|
||||
x2 = i;
|
||||
}
|
||||
int i;
|
||||
if (x1 < x2) {
|
||||
i = x1;
|
||||
x1 = x2;
|
||||
x2 = i;
|
||||
}
|
||||
|
||||
if (y1 < y2) {
|
||||
i = y1;
|
||||
y1 = y2;
|
||||
y2 = i;
|
||||
}
|
||||
if (y1 < y2) {
|
||||
i = y1;
|
||||
y1 = y2;
|
||||
y2 = i;
|
||||
}
|
||||
|
||||
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer);
|
||||
vertexConsumer.vertex(matrix4f, (float)x1, (float)y1, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, (float)x1, (float)y2, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, (float)x2, (float)y2, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, (float)x2, (float)y1, 0).color(color);
|
||||
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer);
|
||||
vertexConsumer.vertex(matrix4f, (float) x1, (float) y1, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, (float) x1, (float) y2, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, (float) x2, (float) y2, 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
RenderLayer renderLayer = RenderLayer.getGuiTextured(sprite);
|
||||
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
|
||||
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer);
|
||||
vertexConsumer.vertex(matrix4f, (float)x1, (float)y1, 0.0F).texture(u1, v1).color(color);
|
||||
vertexConsumer.vertex(matrix4f, (float)x1, (float)y2, 0.0F).texture(u1, 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) x1, (float) y1, 0.0F).texture(u1, v1).color(color);
|
||||
vertexConsumer.vertex(matrix4f, (float) x1, (float) y2, 0.0F).texture(u1, 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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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.text.Text;
|
||||
|
||||
public class SaturnScreen extends Screen {
|
||||
SaturnScreen(String title) {
|
||||
protected List<Element> elements = new ArrayList<>();
|
||||
|
||||
public SaturnScreen(String 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);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,8 @@
|
||||
"TotemParticleMixin",
|
||||
"Crosshair",
|
||||
"EntityMixin",
|
||||
"CameraMixin"
|
||||
"CameraMixin",
|
||||
"DrawContextAccessor"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
Reference in New Issue
Block a user