this time it should be good (aside from colors)
This commit is contained in:
@@ -16,7 +16,7 @@ public class Element {
|
||||
public float scale = 1.0f;
|
||||
public Function<Double, Double> curve = Curve::easeInOutCubic;
|
||||
|
||||
public void render(RenderScope renderScope, RenderContext ctx) {
|
||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||
}
|
||||
|
||||
public void click(int mouseX, int mouseY) {
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package org.saturnclient.ui2;
|
||||
|
||||
public class RenderContext {
|
||||
public class ElementContext {
|
||||
public int mouseX, mouseY;
|
||||
public int elementWidth, elementHeight;
|
||||
public float elementScale;
|
||||
|
||||
public RenderContext(int mouseX, int mouseY, Element e) {
|
||||
public ElementContext(int mouseX, int mouseY, Element e) {
|
||||
this.mouseX = mouseX - e.x;
|
||||
this.mouseY = mouseY - e.y;
|
||||
this.elementWidth = e.width;
|
||||
@@ -80,13 +80,17 @@ public class RenderScope {
|
||||
}
|
||||
|
||||
public void drawText(String text, int x, int y, boolean bold, int color) {
|
||||
drawText(1.0f, text, x, y, bold, color);
|
||||
}
|
||||
|
||||
public void drawText(float scale, String text, int x, int y, boolean bold, int color) {
|
||||
int i = 0;
|
||||
for (String line : text.split("\n")) {
|
||||
color = getColor(color);
|
||||
Identifier font = bold ? Fonts.INTER_BOLD : Fonts.INTER;
|
||||
matrices.push();
|
||||
matrices.translate(x, y + (i * Fonts.getHeight()), 0);
|
||||
matrices.scale(1.0f, 1.0f, 1.0f);
|
||||
matrices.scale(scale, scale, 1.0f);
|
||||
TextRenderer textRenderer = SaturnClient.client.textRenderer;
|
||||
textRenderer.draw(Fonts.setFont(line, font), 0, 7, color, false, this.matrices.peek().getPositionMatrix(),
|
||||
this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
|
||||
@@ -95,7 +99,7 @@ public class RenderScope {
|
||||
}
|
||||
}
|
||||
|
||||
public void drawRoundedCorner(int width, int height, int radius, int color) {
|
||||
private void drawRoundedCorner(int width, int height, int radius, int color) {
|
||||
int w = width * 20;
|
||||
int h = height * 20;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.saturnclient.ui2.Element;
|
||||
import org.saturnclient.ui2.RenderContext;
|
||||
import org.saturnclient.ui2.ElementContext;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.Utils;
|
||||
import org.saturnclient.ui2.anim.Animation;
|
||||
@@ -30,7 +30,7 @@ public class ElementRenderer {
|
||||
renderScope.setOpacity(element.opacity);
|
||||
renderScope.matrices.translate(element.x, element.y, 0);
|
||||
renderScope.matrices.scale(element.scale, element.scale, 1.0f);
|
||||
element.render(renderScope, new RenderContext(mouseX, mouseY, element));
|
||||
element.render(renderScope, new ElementContext(mouseX, mouseY, element));
|
||||
renderScope.matrices.pop();
|
||||
renderScope.setRenderLayer(null);
|
||||
}
|
||||
|
||||
@@ -7,133 +7,80 @@ import org.saturnclient.saturnclient.config.ThemeManager;
|
||||
import org.saturnclient.saturnclient.menus.ConfigEditor;
|
||||
import org.saturnclient.ui.Textures;
|
||||
import org.saturnclient.ui2.Element;
|
||||
import org.saturnclient.ui2.RenderContext;
|
||||
import org.saturnclient.ui2.ElementContext;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.Utils;
|
||||
import org.saturnclient.ui2.resources.Fonts;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
|
||||
public class SaturnModule extends Element {
|
||||
private static ThemeManager theme = new ThemeManager("SaturnModule", "enabled", "hovering");
|
||||
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(-16777216));
|
||||
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(-1));
|
||||
private static Property<Integer> iconBgColor = theme.property("icon-bg-color", new Property<Integer>(-16777216));
|
||||
private static Property<Integer> iconColor = theme.property("icon-fg-color", new Property<Integer>(-1));
|
||||
|
||||
private static Property<Integer> cornerRadius = theme.property("corner-radius", new Property<Integer>(10));
|
||||
private static Property<Integer> padding = theme.property("padding", new Property<Integer>(10));
|
||||
private static Property<Integer> iconMargin = theme.property("icon-margin", new Property<Integer>(10));
|
||||
private static Property<Integer> iconPadding = theme.property("icon-padding", new Property<Integer>(4));
|
||||
private static Property<Integer> tagGap = theme.property("tag-gap", new Property<Integer>(4));
|
||||
|
||||
private static ThemeManager settingsTheme = new ThemeManager("SaturnModule$Settings", "hovering");
|
||||
private static Property<Integer> settingsBg = settingsTheme.property("bg-color", new Property<Integer>(-16777216));
|
||||
private static Property<Integer> settingsFg = settingsTheme.property("fg-color", new Property<Integer>(-1));
|
||||
private static Property<Integer> settingsRadius = settingsTheme.property("corner-radius", new Property<Integer>(10));
|
||||
private static ThemeManager theme = new ThemeManager("Module", "enabled", "hovering");
|
||||
private static Property<Integer> bgColor = theme.property("bg", new Property<>(0xFF581c1c));
|
||||
private static Property<Integer> fgColor = theme.property("fg", new Property<>(0xFFA1A2B8));
|
||||
private static Property<Integer> iconBg = theme.property("icon-bg", new Property<>(0xFF802222));
|
||||
private static Property<Integer> iconRadius = theme.property("icon-radius", new Property<>(10));
|
||||
private static Property<Integer> radius = theme.property("radius", new Property<>(10));
|
||||
|
||||
static {
|
||||
theme.propertyStateDefault("enabled", "icon-bg-color", -7643914);
|
||||
theme.propertyStateDefault("hovering", "fg-color", -7643914);
|
||||
settingsTheme.propertyStateDefault("hovering", "bg-color", -7643914);
|
||||
theme.propertyStateDefault("enabled", "bg", 0xFF14532d);
|
||||
theme.propertyStateDefault("enabled", "icon-bg", 0xFF1e6f3f);
|
||||
theme.propertyStateDefault("hovering", "fg", 0xFFbfc0cf);
|
||||
}
|
||||
|
||||
private Module mod;
|
||||
|
||||
public SaturnModule(Module mod) {
|
||||
this.mod = mod;
|
||||
this.width = 180;
|
||||
this.height = 113;
|
||||
this.width = 160;
|
||||
this.height = 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderScope renderScope, RenderContext ctx) {
|
||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||
int p = 10;
|
||||
int s = 14;
|
||||
boolean settingsHover = false;
|
||||
|
||||
renderScope.setRenderLayer(RenderLayer::getGuiTextured);
|
||||
|
||||
if (mod.isEnabled()) {
|
||||
theme.setState("enabled");
|
||||
}
|
||||
|
||||
if (ctx.isHovering(0, (height-40), width, 30)) {
|
||||
settingsTheme.setState("hovering");
|
||||
if (ctx.isHovering(width - s - p, height - s - p, s, s)) {
|
||||
settingsHover = true;
|
||||
} else if (ctx.isHovering()) {
|
||||
theme.applyState("hovering");
|
||||
}
|
||||
|
||||
renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, bgColor.value);
|
||||
renderScope.drawRoundedRectangle(0, 0, width, height, radius.value, bgColor.value);
|
||||
|
||||
renderScope.matrices.push();
|
||||
int h = height-(p * 2);
|
||||
|
||||
renderScope.matrices.translate(padding.value, padding.value, 0);
|
||||
renderScope.drawRoundedRectangle(p, p, h, h, iconRadius.value, iconBg.value);
|
||||
|
||||
// Top part
|
||||
renderScope.drawRoundedRectangle(0, 0, 20, 20, 10, iconBgColor.value);
|
||||
renderScope.drawTexture(mod.getIconTexture(), iconPadding.value, iconPadding.value, 0, 0, 20 - (iconPadding.value * 2), 20 - (iconPadding.value * 2), iconColor.value);
|
||||
renderScope.drawText(mod.getName(), 20 + iconMargin.value, (22 - Fonts.getHeight()) / 2, false, fgColor.value);
|
||||
renderScope.drawTexture(mod.getIconTexture(), p + (p / 2), p + (p / 2), 0, 0, h - p, h - p, fgColor.value);
|
||||
|
||||
renderScope.matrices.push();
|
||||
renderScope.matrices.translate(20 + iconMargin.value, ((22 - Fonts.getHeight()) / 2) + Fonts.getHeight(), 0);
|
||||
renderScope.drawText(0.6f, mod.getName(), p+h+4, p + 1, true, fgColor.value);
|
||||
|
||||
renderScope.matrices.scale(0.5f, 0.5f, 1);
|
||||
renderScope.drawText(formatText(mod.getDescription(), (int) ((width - iconMargin.value) * 1.5f)), 0, 0, false, -20);
|
||||
renderScope.matrices.pop();
|
||||
renderScope.matrices.pop();
|
||||
|
||||
// Mid part
|
||||
int i = padding.value;
|
||||
for (String tag : mod.getTags()) {
|
||||
renderScope.matrices.push();
|
||||
renderScope.matrices.translate(i, height - 40 - Fonts.getHeight(), 0);
|
||||
renderScope.matrices.scale(0.5f, 0.5f, 1);
|
||||
renderScope.drawText(tag, 0, 0, false, -20);
|
||||
renderScope.matrices.pop();
|
||||
i += (Fonts.getWidth(tag, false) * 0.5f) + tagGap.value;
|
||||
if (settingsHover) {
|
||||
theme.setState("hovering");
|
||||
}
|
||||
|
||||
// Settings button
|
||||
renderScope.matrices.push();
|
||||
renderScope.matrices.translate(padding.value, height - 30 - padding.value, 0);
|
||||
|
||||
int w = width - (padding.value * 2);
|
||||
|
||||
renderScope.drawRoundedRectangle(0, 0, w, 30, settingsRadius.value, settingsBg.value);
|
||||
renderScope.drawTexture(Textures.SETTINGS, ((w - Fonts.getWidth("Settings", false)) / 2) - 20, (16) / 2, 0, 0, 15, 15, settingsFg.value);
|
||||
renderScope.drawText("Settings", Fonts.centerX(w, "Settings", false), Fonts.centerY(32), false, settingsFg.value);
|
||||
renderScope.matrices.pop();
|
||||
renderScope.drawTexture(Textures.SETTINGS, width - s - p, height - s - p, 0, 0, s, s, fgColor.value);
|
||||
|
||||
theme.setState(null);
|
||||
settingsTheme.setState(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(int mouseX, int mouseY) {
|
||||
if (Utils.isHovering(mouseX, mouseY - (height-40), width, 30, scale)) {
|
||||
int p = 10;
|
||||
int s = 14;
|
||||
|
||||
if (Utils.isHovering(mouseX - (width - s - p), mouseY - (height - s - p), s, s, 1.0f)) {
|
||||
SaturnClient.client.setScreen(new ConfigEditor(mod.getConfig()));
|
||||
} else {
|
||||
mod.setEnabled(!mod.isEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatText(String text, int width) {
|
||||
StringBuilder formatted = new StringBuilder();
|
||||
StringBuilder currentLine = new StringBuilder();
|
||||
|
||||
for (char c : text.toCharArray()) {
|
||||
currentLine.append(c);
|
||||
if (Fonts.getWidth(currentLine.toString(), false) > width) {
|
||||
// Line is too wide; backtrack the last character
|
||||
currentLine.deleteCharAt(currentLine.length() - 1);
|
||||
formatted.append(currentLine).append('\n');
|
||||
currentLine.setLength(0); // clear currentLine
|
||||
currentLine.append(c); // start new line with the character that overflowed
|
||||
}
|
||||
}
|
||||
|
||||
// Append any remaining characters in the currentLine
|
||||
if (currentLine.length() > 0) {
|
||||
formatted.append(currentLine);
|
||||
}
|
||||
|
||||
return formatted.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.saturnclient.ui2.components;
|
||||
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.ElementContext;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.Utils;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Sidebar extends Element {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderScope renderScope, RenderContext ctx) {
|
||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||
int topRow = 0;
|
||||
int bottomRow = 0;
|
||||
|
||||
|
||||
@@ -3,7 +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.ElementContext;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.resources.Fonts;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Button extends Element {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderScope renderScope, RenderContext ctx) {
|
||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||
if (ctx.isHovering()) {
|
||||
theme.setState("hovering");
|
||||
} else {
|
||||
|
||||
@@ -3,7 +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.ElementContext;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
@@ -22,7 +22,7 @@ public class ClickableTexture extends Element {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderScope renderScope, RenderContext ctx) {
|
||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||
if (ctx.isHovering()) {
|
||||
theme.setState("hovering");
|
||||
} else {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.saturnclient.ui2.elements;
|
||||
|
||||
import org.saturnclient.ui2.Element;
|
||||
import org.saturnclient.ui2.RenderContext;
|
||||
import org.saturnclient.ui2.ElementContext;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
@@ -15,7 +15,7 @@ public class ImageTexture extends Element {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderScope renderScope, RenderContext ctx) {
|
||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||
renderScope.setRenderLayer(RenderLayer::getGuiTextured);
|
||||
renderScope.drawTexture(sprite, 0, 0, 0, 0, width, height);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.List;
|
||||
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.ElementContext;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.components.ElementRenderer;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Scroll extends Element {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderScope renderScope, RenderContext ctx) {
|
||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||
renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, bgColor.value);
|
||||
|
||||
renderScope.enableScissor(padding, padding, width - padding, height - padding);
|
||||
|
||||
@@ -3,7 +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.ElementContext;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
|
||||
public class Text extends Element {
|
||||
@@ -17,7 +17,7 @@ public class Text extends Element {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderScope renderScope, RenderContext ctx) {
|
||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||
renderScope.drawText(this.text, this.x, this.y, false, fgColor.value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +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.ElementContext;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
@@ -30,7 +30,7 @@ public class TextureButton extends Element {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderScope renderScope, RenderContext ctx) {
|
||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||
if (ctx.isHovering()) {
|
||||
theme.setState("hovering");
|
||||
} else {
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.saturnclient.ui2.screens;
|
||||
import org.saturnclient.modules.ModManager;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.Property;
|
||||
import org.saturnclient.saturnclient.config.ThemeManager;
|
||||
import org.saturnclient.saturnclient.menus.CloaksMenu;
|
||||
import org.saturnclient.saturnclient.menus.SaturnConfigEditor;
|
||||
import org.saturnclient.ui.Textures;
|
||||
@@ -14,23 +12,22 @@ import org.saturnclient.ui2.components.Sidebar;
|
||||
import org.saturnclient.ui2.elements.Scroll;
|
||||
|
||||
public class ModMenu extends SaturnScreen {
|
||||
private static ThemeManager theme = new ThemeManager("ModMenu");
|
||||
private static Property<Integer> padding = theme.property("padding", new Property<Integer>(25));
|
||||
private static Property<Integer> gap = theme.property("gap", new Property<Integer>(10));
|
||||
|
||||
public ModMenu() {
|
||||
super("Mod Menu");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ui() {
|
||||
Scroll scroll = new Scroll(padding.value);
|
||||
int p = 10;
|
||||
int g = 10;
|
||||
|
||||
Scroll scroll = new Scroll(p);
|
||||
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
|
||||
for (Module mod : ModManager.MODS) {
|
||||
scroll.draw(new SaturnModule(mod).position((180 + gap.value) * col, (140 + gap.value) * row));
|
||||
scroll.draw(new SaturnModule(mod).position((160 + g) * col, (50 + g) * row));
|
||||
|
||||
if (col == 2) {
|
||||
col = 0;
|
||||
@@ -40,7 +37,7 @@ public class ModMenu extends SaturnScreen {
|
||||
}
|
||||
}
|
||||
|
||||
int scrollWidth = 540 + (gap.value * 2) + (padding.value * 2);
|
||||
int scrollWidth = 480 + 10 + (g * 2) + (p * 2);
|
||||
|
||||
draw(scroll.dimensions(scrollWidth, 350).center(width, height));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user