ui and module improvements
This commit is contained in:
@@ -17,10 +17,10 @@ public class ModManager {
|
||||
};
|
||||
|
||||
public static void init() {
|
||||
ClientTickEvents.START_CLIENT_TICK.register(client -> {
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
for (Module m : MODS) {
|
||||
if (m instanceof TickModule && m.isEnabled()) {
|
||||
((TickModule) m).tick();
|
||||
if (m.isEnabled()) {
|
||||
m.tick();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -48,7 +48,7 @@ public class ModManager {
|
||||
|
||||
matrices.pop();
|
||||
} else {
|
||||
m.render(context);
|
||||
m.render(renderScope);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package org.saturnclient.modules;
|
||||
import org.saturnclient.saturnclient.config.ConfigManager;
|
||||
import org.saturnclient.saturnclient.config.NamedProperty;
|
||||
import org.saturnclient.ui.Textures;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public abstract class Module {
|
||||
@@ -30,7 +30,8 @@ public abstract class Module {
|
||||
configManager = config;
|
||||
}
|
||||
|
||||
public void render(DrawContext scope) {}
|
||||
public void render(RenderScope scope) {}
|
||||
public void tick() {}
|
||||
|
||||
public abstract boolean isEnabled();
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package org.saturnclient.modules;
|
||||
|
||||
public interface TickModule {
|
||||
public void tick();
|
||||
}
|
||||
@@ -2,49 +2,43 @@ package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.NamedProperty;
|
||||
import org.saturnclient.saturnclient.config.Property;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.resources.Textures;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class Crosshair extends Module {
|
||||
Identifier textureLocation = Identifier.of("saturnclient", "textures/gui/hud/crosshair_range.png");
|
||||
|
||||
public static NamedProperty<Boolean> enabled = new Property<>(false).named("Enabled");
|
||||
public static NamedProperty<Boolean> range_indicator = new Property<>(false).named("Range Indicator");
|
||||
public static Property<Boolean> enabled = new Property<>(false);
|
||||
public static Property<Boolean> range_indicator = new Property<>(false);
|
||||
|
||||
public Crosshair() {
|
||||
super("Crosshair", "crosshair", enabled, range_indicator);
|
||||
super("Crosshair", "crosshair", enabled.named("Enabled"), range_indicator.named("Range Indicator"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context) {
|
||||
if (enabled.prop.value
|
||||
&& range_indicator.prop.value
|
||||
public void render(RenderScope scope) {
|
||||
if (enabled.value
|
||||
&& range_indicator.value
|
||||
&& SaturnClient.client.targetedEntity != null
|
||||
&& SaturnClient.client.targetedEntity.isAlive()) {
|
||||
RenderSystem.setShaderTexture(0, textureLocation);
|
||||
int scaledWidth = 15;
|
||||
int scaledHeight = 15;
|
||||
|
||||
context.drawTexture(RenderLayer::getCrosshair, textureLocation,
|
||||
(context.getScaledWindowWidth() - scaledWidth) / 2,
|
||||
(context.getScaledWindowHeight() - scaledHeight) / 2, 0.0F, 0.0F, scaledWidth, scaledHeight,
|
||||
scope.drawTexture(RenderLayer::getCrosshair, Textures.CROSSHAIR_RANGE,
|
||||
(scope.getScaledWindowWidth() - scaledWidth) / 2,
|
||||
(scope.getScaledWindowHeight() - scaledHeight) / 2, 0.0F, 0.0F, scaledWidth, scaledHeight,
|
||||
scaledWidth, scaledHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.prop.value;
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean e) {
|
||||
enabled.prop.value = e;
|
||||
enabled.value = e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.saturnclient.saturnclient.menus;
|
||||
|
||||
import org.saturnclient.ui2.SaturnScreen;
|
||||
import org.saturnclient.ui2.elements.Button;
|
||||
|
||||
public class SaturnMenu extends SaturnScreen {
|
||||
public SaturnMenu() {
|
||||
@@ -10,6 +9,5 @@ public class SaturnMenu extends SaturnScreen {
|
||||
|
||||
@Override
|
||||
public void ui() {
|
||||
draw(new Button("Settings").center(width, height));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ 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.ui2.screens.ShiftMenu;
|
||||
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
||||
import net.minecraft.client.gui.screen.option.OptionsScreen;
|
||||
@@ -69,7 +70,7 @@ public class SaturnTitleScreen extends SaturnUi {
|
||||
bY += 20;
|
||||
|
||||
draw(new SaturnButton("SATURN OPTIONS", () -> {
|
||||
client.setScreen(new SaturnMenu());
|
||||
client.setScreen(new ShiftMenu());
|
||||
}).setBold(true).setWidth(210).setHeight(26).setX(bX).setY(bY).setScale(0.69f));
|
||||
|
||||
super.init();
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package org.saturnclient.saturnclient.mod_utils;
|
||||
|
||||
public interface CameraOverriddenEntity {
|
||||
float freelook$getCameraPitch();
|
||||
float freelook$getCameraYaw();
|
||||
|
||||
void freelook$setCameraPitch(float pitch);
|
||||
void freelook$setCameraYaw(float yaw);
|
||||
}
|
||||
@@ -5,8 +5,12 @@ public class Element {
|
||||
protected int y;
|
||||
protected int width;
|
||||
protected int height;
|
||||
public boolean focused;
|
||||
|
||||
public void render(RenderScope renderScope, boolean hovering) {
|
||||
public void render(RenderScope renderScope, RenderContext ctx) {
|
||||
}
|
||||
|
||||
public void click(int mouseX, int mouseY) {
|
||||
}
|
||||
|
||||
public final void dimensions(int width, int height) {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.saturnclient.ui2;
|
||||
|
||||
public class RenderContext {
|
||||
public int mouseX, mouseY;
|
||||
public int elementX, elementY;
|
||||
public int elementWidth, elementHeight;
|
||||
|
||||
public RenderContext(int mouseX, int mouseY, Element e) {
|
||||
this.mouseX = mouseX;
|
||||
this.mouseY = mouseY;
|
||||
this.elementX = e.x;
|
||||
this.elementY = e.y;
|
||||
this.elementWidth = e.width;
|
||||
this.elementHeight = e.height;
|
||||
}
|
||||
|
||||
public boolean isHovering() {
|
||||
return mouseX >= elementX &&
|
||||
mouseX <= elementX + elementWidth &&
|
||||
mouseY >= elementY &&
|
||||
mouseY <= elementY + elementHeight;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package org.saturnclient.ui2;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
import org.saturnclient.ui2.resources.Fonts;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
@@ -133,4 +136,40 @@ public class RenderScope {
|
||||
|
||||
this.matrices.pop();
|
||||
}
|
||||
|
||||
public int getScaledWindowWidth() {
|
||||
return SaturnClient.client.getWindow().getScaledWidth();
|
||||
}
|
||||
|
||||
public int getScaledWindowHeight() {
|
||||
return SaturnClient.client.getWindow().getScaledHeight();
|
||||
}
|
||||
|
||||
public void drawTexture(Function<Identifier, RenderLayer> renderLayers, Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight, int color) {
|
||||
this.drawTexture(renderLayers, sprite, x, y, u, v, width, height, width, height, textureWidth, textureHeight, color);
|
||||
}
|
||||
|
||||
public void drawTexture(Function<Identifier, RenderLayer> renderLayers, Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) {
|
||||
this.drawTexture(renderLayers, sprite, x, y, u, v, width, height, width, height, textureWidth, textureHeight);
|
||||
}
|
||||
|
||||
public void drawTexture(Function<Identifier, RenderLayer> renderLayers, Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWith, int regionHeight, int textureWidth, int textureHeight) {
|
||||
this.drawTexture(renderLayers, sprite, x, y, u, v, width, height, regionWith, regionHeight, textureWidth, textureHeight, -1);
|
||||
}
|
||||
|
||||
public void drawTexture(Function<Identifier, RenderLayer> renderLayers, 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(renderLayers, 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(Function<Identifier, RenderLayer> renderLayers, Identifier sprite, int x1, int x2, int y1, int y2, float u1, float u2, float v1, float v2, int color) {
|
||||
RenderSystem.setShaderTexture(0, sprite);
|
||||
|
||||
RenderLayer renderLayer = (RenderLayer)renderLayers.apply(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,7 @@ public class SaturnScreen extends Screen {
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
ui();
|
||||
|
||||
// Do stuff
|
||||
ui(); // abstraction to render the saturn ui and also render extra stuff here
|
||||
}
|
||||
|
||||
public void ui() {
|
||||
@@ -43,22 +41,32 @@ public class SaturnScreen extends Screen {
|
||||
|
||||
renderScope.matrices.push();
|
||||
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
Element element = elements.get(i);
|
||||
|
||||
for (Element element : elements) {
|
||||
renderScope.matrices.push();
|
||||
renderScope.matrices.translate(element.x, element.y, 0);
|
||||
element.render(renderScope, isMouseInside(mouseX, mouseY, element));
|
||||
element.render(renderScope, new RenderContext(mouseX, mouseY, element));
|
||||
renderScope.matrices.pop();
|
||||
}
|
||||
|
||||
renderScope.matrices.pop();
|
||||
}
|
||||
|
||||
public static boolean isMouseInside(int mouseX, int mouseY, Element element) {
|
||||
return mouseX >= element.x &&
|
||||
mouseX <= (element.x + element.width) &&
|
||||
mouseY >= element.y &&
|
||||
mouseY <= (element.y + element.height);
|
||||
}
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (button == 0) {
|
||||
for (Element element : new ArrayList<>(elements)) {
|
||||
element.focused = false;
|
||||
|
||||
int adjustedMouseX = (int) mouseX - element.x;
|
||||
int adjustedMouseY = (int) mouseY - element.y;
|
||||
|
||||
if (Utils.isHovering(adjustedMouseX, adjustedMouseY, element.width, element.height)) {
|
||||
element.focused = true;
|
||||
element.click(adjustedMouseX, adjustedMouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.saturnclient.ui2;
|
||||
|
||||
public class Utils {
|
||||
public static boolean isHovering(int mouseX, int mouseY, int elementWidth, int elementHeight) {
|
||||
return mouseX >= 0 &&
|
||||
mouseX <= elementWidth &&
|
||||
mouseY >= 0 &&
|
||||
mouseY <= elementHeight;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package org.saturnclient.ui2.elements;
|
||||
import org.saturnclient.saturnclient.config.Property;
|
||||
import org.saturnclient.saturnclient.config.ThemeManager;
|
||||
import org.saturnclient.ui2.Element;
|
||||
import org.saturnclient.ui2.RenderContext;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.resources.Fonts;
|
||||
|
||||
@@ -20,16 +21,18 @@ public class Button extends Element {
|
||||
|
||||
private String text;
|
||||
private Identifier font;
|
||||
private Runnable onClick;
|
||||
|
||||
public Button(String text) {
|
||||
public Button(String text, Runnable onClick) {
|
||||
this.text = text;
|
||||
this.font = Fonts.getFont(bold.value);
|
||||
this.onClick = onClick;
|
||||
this.dimensions(Fonts.getWidth(text, font)+ 25 , Fonts.getHeight() + 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderScope renderScope, boolean hovering) {
|
||||
if (hovering) {
|
||||
public void render(RenderScope renderScope, RenderContext ctx) {
|
||||
if (ctx.isHovering()) {
|
||||
theme.setState("hovering");
|
||||
} else {
|
||||
theme.setState(null);
|
||||
@@ -38,4 +41,11 @@ public class Button extends Element {
|
||||
|
||||
renderScope.drawText(text, width / 2 - Fonts.getWidth(text, font) / 2, height / 2 - Fonts.getHeight() / 2, bold.value, fgColor.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(int mouseX, int mouseY) {
|
||||
if (onClick != null) {
|
||||
onClick.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.saturnclient.ui2.elements;
|
||||
|
||||
import org.saturnclient.ui2.Element;
|
||||
import org.saturnclient.ui2.RenderContext;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
|
||||
public class Text extends Element {
|
||||
@@ -11,7 +12,7 @@ public class Text extends Element {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderScope renderScope, boolean hovering) {
|
||||
public void render(RenderScope renderScope, RenderContext ctx) {
|
||||
renderScope.drawText(this.text, this.x, this.y, false, 0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.saturnclient.ui2.resources;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class Textures {
|
||||
public static final Identifier CROSSHAIR_RANGE = Identifier.of("saturnclient", "textures/gui/hud/crosshair_range.png");
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.saturnclient.ui2.screens;
|
||||
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.ui2.SaturnScreen;
|
||||
import org.saturnclient.ui2.elements.Button;
|
||||
|
||||
public class ShiftMenu extends SaturnScreen {
|
||||
public ShiftMenu() {
|
||||
super("Shift Menu");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ui() {
|
||||
draw(new Button("Click Me!", () -> {
|
||||
SaturnClient.LOGGER.info("Clicked!");
|
||||
}).center(width, height));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user