better font management
This commit is contained in:
@@ -12,6 +12,7 @@ public class ModDimensions {
|
|||||||
public Property<Integer> bgColor = new Property<>(0xFF000000, Property.PropertyType.HEX);
|
public Property<Integer> bgColor = new Property<>(0xFF000000, Property.PropertyType.HEX);
|
||||||
public Property<Integer> fgColor = new Property<>(0xFFffffff, Property.PropertyType.HEX);
|
public Property<Integer> fgColor = new Property<>(0xFFffffff, Property.PropertyType.HEX);
|
||||||
public Property<Integer> radius = new Property<>(0);
|
public Property<Integer> radius = new Property<>(0);
|
||||||
|
public Property<Integer> font = Property.font(0);
|
||||||
|
|
||||||
public int width = 0;
|
public int width = 0;
|
||||||
public int height = 0;
|
public int height = 0;
|
||||||
@@ -23,7 +24,8 @@ public class ModDimensions {
|
|||||||
"Scale", scale,
|
"Scale", scale,
|
||||||
"Background Color", bgColor,
|
"Background Color", bgColor,
|
||||||
"Foreground Color", fgColor,
|
"Foreground Color", fgColor,
|
||||||
"Corner Radius", radius
|
"Corner Radius", radius,
|
||||||
|
"Font", font
|
||||||
)).named("In-Game Display");
|
)).named("In-Game Display");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class ArmorDisplay extends Module implements HudMod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void renderHealth(RenderScope scope, int i, int max, int current) {
|
public void renderHealth(RenderScope scope, int i, int max, int current) {
|
||||||
scope.drawText(0.5f, String.valueOf(((double) current / max) * 100) + "%", 17, (15 * i) + 3, false, dimensions.fgColor.value);
|
scope.drawText(0.5f, String.valueOf(((double) current / max) * 100) + "%", 17, (15 * i) + 3, dimensions.font.value, dimensions.fgColor.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -26,15 +26,15 @@ public class Fps extends Module implements HudMod {
|
|||||||
@Override
|
@Override
|
||||||
public void renderHud(RenderScope scope) {
|
public void renderHud(RenderScope scope) {
|
||||||
String text = String.valueOf(SaturnClient.client.getCurrentFps()) + " FPS";
|
String text = String.valueOf(SaturnClient.client.getCurrentFps()) + " FPS";
|
||||||
scope.drawText(text, 0, 0, false, fgColor.value);
|
scope.drawText(text, 0, 0, dimensions.font.value, fgColor.value);
|
||||||
dimensions.width = Fonts.getWidth(text, isEnabled());
|
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderDummy(RenderScope scope) {
|
public void renderDummy(RenderScope scope) {
|
||||||
String text = "369 FPS";
|
String text = "369 FPS";
|
||||||
scope.drawText(text, 0, 0, false, fgColor.value);
|
scope.drawText(text, 0, 0, dimensions.font.value, fgColor.value);
|
||||||
dimensions.width = Fonts.getWidth(text, isEnabled());
|
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -13,12 +13,14 @@ public class Property<T> {
|
|||||||
FLOAT,
|
FLOAT,
|
||||||
STRING,
|
STRING,
|
||||||
HEX,
|
HEX,
|
||||||
NAMESPACE
|
NAMESPACE,
|
||||||
|
SELECT,
|
||||||
}
|
}
|
||||||
|
|
||||||
public T value;
|
public T value;
|
||||||
public boolean isReset = false;
|
public boolean isReset = false;
|
||||||
private T defaultValue;
|
private T defaultValue;
|
||||||
|
private String[] availableValues;
|
||||||
private PropertyType type;
|
private PropertyType type;
|
||||||
|
|
||||||
public Property(T value) {
|
public Property(T value) {
|
||||||
@@ -43,32 +45,45 @@ public class Property<T> {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getBool() {
|
public static Property<Integer> select(Integer value, String... availableValues) {
|
||||||
if (value instanceof Boolean) {
|
Property<Integer> property = new Property<>(value, PropertyType.SELECT);
|
||||||
return (boolean) value;
|
property.availableValues = availableValues;
|
||||||
}
|
return property;
|
||||||
throw new IllegalStateException("Property does not contain a boolean");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInt() {
|
public static Property<Integer> font(int value) {
|
||||||
if (value instanceof Integer) {
|
return select(value, "Default", "Inter", "Inter bold");
|
||||||
return (int) value;
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Property does not contain an int");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getFloat() {
|
@SuppressWarnings("unchecked")
|
||||||
if (value instanceof Float) {
|
public static <T> Property<T> namespace(Map<String, Property<?>> value) {
|
||||||
return (float) value;
|
Property<T> property = new Property<>((T) value, PropertyType.NAMESPACE);
|
||||||
}
|
property.type = PropertyType.NAMESPACE;
|
||||||
throw new IllegalStateException("Property does not contain a float");
|
return property;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getString() {
|
public void next() {
|
||||||
if (value instanceof String) {
|
if ((Integer) value < availableValues.length-1) setValue((Integer)value+1);
|
||||||
return (String) value;
|
else setValue(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void prev() {
|
||||||
|
if ((Integer) value > 0) setValue((Integer)value-1);
|
||||||
|
else setValue(availableValues.length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelection(int selection) {
|
||||||
|
if (selection >= 0 && selection < availableValues.length && type == PropertyType.SELECT) {
|
||||||
|
setValue(selection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelection() {
|
||||||
|
if (type == PropertyType.SELECT) {
|
||||||
|
return availableValues[(Integer) value];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Property does not contain a string");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ public class ThemeManager {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (Map.Entry<String, Property<?>> tProp : properties.get(namespace).entrySet()) {
|
for (Map.Entry<String, Property<?>> tProp : properties.get(namespace).entrySet()) {
|
||||||
currentStyling.get(tProp.getKey()).setValue(tProp.getValue().value);
|
Property<?> p = currentStyling.get(tProp.getKey());
|
||||||
|
if (p != null) p.setValue(tProp.getValue().value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,7 +62,7 @@ public class ThemeManager {
|
|||||||
for (Map.Entry<String, Property<?>> tProp : properties.get(namespace+"@"+state).entrySet()) {
|
for (Map.Entry<String, Property<?>> tProp : properties.get(namespace+"@"+state).entrySet()) {
|
||||||
Property<?> p = currentStyling.get(tProp.getKey());
|
Property<?> p = currentStyling.get(tProp.getKey());
|
||||||
Property<?> currProp = properties.get(namespace).get(tProp.getKey());
|
Property<?> currProp = properties.get(namespace).get(tProp.getKey());
|
||||||
if (p.value.equals(currProp.value)) {
|
if (currProp != null && p.value.equals(currProp.value)) {
|
||||||
p.setValue(tProp.getValue().value);
|
p.setValue(tProp.getValue().value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,20 +92,22 @@ 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 drawText(String text, int x, int y, boolean bold, int color) {
|
public void drawText(String text, int x, int y, int font, int color) {
|
||||||
drawText(1.0f, text, x, y, bold, color);
|
drawText(1.0f, text, x, y, font, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawText(float scale, String text, int x, int y, boolean bold, int color) {
|
public void drawText(float scale, String text, int x, int y, int font, int color) {
|
||||||
|
if (font == 0) {
|
||||||
|
scale *= 2;
|
||||||
|
}
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String line : text.split("\n")) {
|
for (String line : text.split("\n")) {
|
||||||
color = getColor(color);
|
color = getColor(color);
|
||||||
Identifier font = bold ? Fonts.INTER_BOLD : Fonts.INTER;
|
|
||||||
matrices.push();
|
matrices.push();
|
||||||
matrices.translate(x, y + (i * Fonts.getHeight()), 0);
|
matrices.translate(x, y + (i * Fonts.getHeight()), 0);
|
||||||
matrices.scale(scale, scale, 1.0f);
|
matrices.scale(scale, scale, 1.0f);
|
||||||
TextRenderer textRenderer = SaturnClient.client.textRenderer;
|
TextRenderer textRenderer = SaturnClient.client.textRenderer;
|
||||||
textRenderer.draw(Fonts.setFont(line, font), 0, 7, color, false, this.matrices.peek().getPositionMatrix(),
|
textRenderer.draw(Fonts.setFont(line, Fonts.getFont(font)), 0, font == 0 ? 1: 7, color, false, this.matrices.peek().getPositionMatrix(),
|
||||||
this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
|
this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
i++;
|
i++;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.saturnclient.ui2;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.config.ThemeManager;
|
||||||
import org.saturnclient.saturnclient.mixin.DrawContextAccessor;
|
import org.saturnclient.saturnclient.mixin.DrawContextAccessor;
|
||||||
import org.saturnclient.ui2.anim.Animation;
|
import org.saturnclient.ui2.anim.Animation;
|
||||||
import org.saturnclient.ui2.components.ElementRenderer;
|
import org.saturnclient.ui2.components.ElementRenderer;
|
||||||
@@ -62,6 +63,8 @@ public abstract class SaturnScreen extends Screen {
|
|||||||
Animation.execute((Float progress) -> {
|
Animation.execute((Float progress) -> {
|
||||||
blurProgress = progress;
|
blurProgress = progress;
|
||||||
}, blurDuration);
|
}, blurDuration);
|
||||||
|
|
||||||
|
ThemeManager.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void ui();
|
public abstract void ui();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public class SaturnModule extends Element {
|
|||||||
private static Property<Integer> iconBg = theme.property("icon-bg", new Property<>(0xFF2e3248));
|
private static Property<Integer> iconBg = theme.property("icon-bg", new Property<>(0xFF2e3248));
|
||||||
private static Property<Integer> tagBg = theme.property("tag-bg", new Property<>(0xFF2e3248));
|
private static Property<Integer> tagBg = theme.property("tag-bg", new Property<>(0xFF2e3248));
|
||||||
private static Property<Integer> iconRadius = theme.property("icon-radius", new Property<>(10));
|
private static Property<Integer> iconRadius = theme.property("icon-radius", new Property<>(10));
|
||||||
|
private static Property<Integer> font = theme.property("font", Property.font(1));
|
||||||
private static Property<Integer> radius = theme.property("radius", new Property<>(10));
|
private static Property<Integer> radius = theme.property("radius", new Property<>(10));
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -64,15 +65,15 @@ public class SaturnModule extends Element {
|
|||||||
|
|
||||||
renderScope.drawTexture(mod.getIconTexture(), p + (p / 2), p + (p / 2), 0, 0, h - p, h - p, iconFg.value);
|
renderScope.drawTexture(mod.getIconTexture(), p + (p / 2), p + (p / 2), 0, 0, h - p, h - p, iconFg.value);
|
||||||
|
|
||||||
renderScope.drawText(0.6f, mod.getName(), p+h+4, p + 1, true, fgColor.value);
|
renderScope.drawText(0.6f, mod.getName(), p+h+4, p + 1, font.value, fgColor.value);
|
||||||
|
|
||||||
renderScope.drawText(0.35f, mod.getVersion(), width - p - (int) (Fonts.getWidth(mod.getVersion(), false) * 0.35f), p + 1, false, fgColor.value);
|
renderScope.drawText(0.35f, mod.getVersion(), width - p - (int) (Fonts.getWidth(mod.getVersion(), font.value) * 0.35f), p + 1, font.value, fgColor.value);
|
||||||
|
|
||||||
int xt = p + h + 4;
|
int xt = p + h + 4;
|
||||||
for (String tag : mod.getTags()) {
|
for (String tag : mod.getTags()) {
|
||||||
int xtb = (int) (Fonts.getWidth(tag, false) * 0.4f);
|
int xtb = (int) (Fonts.getWidth(tag, font.value) * 0.4f);
|
||||||
renderScope.drawRoundedRectangle(xt, p + (h/2), xtb + 6, 12, 5, tagBg.value);
|
renderScope.drawRoundedRectangle(xt, p + (h/2), xtb + 6, 12, 5, tagBg.value);
|
||||||
renderScope.drawText(0.4f, tag, xt+2, p + (h/2) + 3, false, fgColor.value);
|
renderScope.drawText(0.4f, tag, xt+2, p + (h/2) + 3, font.value, fgColor.value);
|
||||||
xt += xtb + 9;
|
xt += xtb + 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,17 @@ package org.saturnclient.ui2.components.inputs;
|
|||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
import org.saturnclient.saturnclient.config.Property;
|
||||||
|
import org.saturnclient.saturnclient.config.ThemeManager;
|
||||||
import org.saturnclient.ui2.Element;
|
import org.saturnclient.ui2.Element;
|
||||||
import org.saturnclient.ui2.ElementContext;
|
import org.saturnclient.ui2.ElementContext;
|
||||||
import org.saturnclient.ui2.RenderScope;
|
import org.saturnclient.ui2.RenderScope;
|
||||||
import org.saturnclient.ui2.resources.Fonts;
|
import org.saturnclient.ui2.resources.Fonts;
|
||||||
|
|
||||||
public abstract class Input extends Element {
|
public abstract class Input extends Element {
|
||||||
|
private static ThemeManager theme = new ThemeManager("Input");
|
||||||
|
private static Property<Integer> font = theme.property("font", Property.font(1));
|
||||||
|
|
||||||
String text = "";
|
String text = "";
|
||||||
public int cursorPosition = 0;
|
public int cursorPosition = 0;
|
||||||
public abstract void checkReset();
|
public abstract void checkReset();
|
||||||
@@ -66,12 +71,11 @@ public abstract class Input extends Element {
|
|||||||
int scrollOffset = getScrollOffset();
|
int scrollOffset = getScrollOffset();
|
||||||
String visibleText = getVisibleText(scrollOffset);
|
String visibleText = getVisibleText(scrollOffset);
|
||||||
int textColor = focused ? 0xFFFFFF : 0xAAAAAA;
|
int textColor = focused ? 0xFFFFFF : 0xAAAAAA;
|
||||||
renderScope.drawText(0.6f, visibleText, 4, 4, false, textColor);
|
renderScope.drawText(0.6f, visibleText, 4, 4, font.value, textColor);
|
||||||
|
|
||||||
if (focused) {
|
if (focused) {
|
||||||
int cursorX = 4 +
|
int cursorX = 4 +
|
||||||
(int) (SaturnClient.client.textRenderer.getWidth(
|
(int) (Fonts.getWidth(visibleText.substring(0, cursorPosition - scrollOffset), font.value) * 0.6f);
|
||||||
Fonts.setFont(visibleText.substring(0, cursorPosition - scrollOffset))) * 0.6f);
|
|
||||||
|
|
||||||
renderScope.drawRect(cursorX, 2, 1, height - 4, 0xFFFFFFFF);
|
renderScope.drawRect(cursorX, 2, 1, height - 4, 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
@@ -86,7 +90,7 @@ public abstract class Input extends Element {
|
|||||||
int maxWidth = width - 4; // Available width for text
|
int maxWidth = width - 4; // Available width for text
|
||||||
while (offset < cursorPosition) { // Ensure cursor remains visible
|
while (offset < cursorPosition) { // Ensure cursor remains visible
|
||||||
String visibleText = text.substring(offset, cursorPosition);
|
String visibleText = text.substring(offset, cursorPosition);
|
||||||
if (SaturnClient.client.textRenderer.getWidth(Fonts.setFont(visibleText)) > maxWidth) {
|
if (Fonts.getWidth(visibleText, font.value) > maxWidth) {
|
||||||
offset++;
|
offset++;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@@ -100,8 +104,7 @@ public abstract class Input extends Element {
|
|||||||
|
|
||||||
// Ensure text does not overflow past the available width
|
// Ensure text does not overflow past the available width
|
||||||
for (int i = 1; i <= visibleText.length(); i++) {
|
for (int i = 1; i <= visibleText.length(); i++) {
|
||||||
if (SaturnClient.client.textRenderer.getWidth(
|
if (Fonts.getWidth(visibleText.substring(0, i), font.value) > width - 4) {
|
||||||
Fonts.setFont(visibleText.substring(0, i))) > width - 4) {
|
|
||||||
return visibleText.substring(0, i - 1); // Trim overflow
|
return visibleText.substring(0, i - 1); // Trim overflow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package org.saturnclient.ui2.components.inputs;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.config.Property;
|
||||||
|
import org.saturnclient.saturnclient.config.ThemeManager;
|
||||||
|
import org.saturnclient.ui2.Element;
|
||||||
|
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 Select extends Element {
|
||||||
|
private static ThemeManager theme = new ThemeManager("Toggle");
|
||||||
|
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xAAAAAA));
|
||||||
|
private static Property<Integer> arrowColor = theme.property("arrow-color", new Property<Integer>(0xff8B5CF6));
|
||||||
|
private static Property<Integer> font = theme.property("font", Property.font(1));
|
||||||
|
|
||||||
|
private Property<Integer> prop;
|
||||||
|
|
||||||
|
public Select(Property<Integer> prop) {
|
||||||
|
this.prop = prop;
|
||||||
|
this.width = 150;
|
||||||
|
this.height = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||||
|
renderScope.setRenderLayer(RenderLayer::getGuiTextured);
|
||||||
|
|
||||||
|
renderScope.drawText(0.8f, "<", 0, 0, font.value, arrowColor.value);
|
||||||
|
|
||||||
|
String text = prop.getSelection();
|
||||||
|
|
||||||
|
renderScope.drawText(0.6f, text, (int) (width - ((float) Fonts.getWidth(text, font.value) * 0.6f)) / 2, 1, font.value, fgColor.value);
|
||||||
|
|
||||||
|
renderScope.drawText(0.8f, ">", width - 10, 0, font.value, arrowColor.value);
|
||||||
|
|
||||||
|
theme.setState(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void click(int mouseX, int mouseY) {
|
||||||
|
if (Utils.isHovering(mouseX - (width - 10), mouseY, 10, height, 1.0f)) {
|
||||||
|
prop.next();
|
||||||
|
} else if (Utils.isHovering(mouseX, mouseY, 10, height, 1.0f)) {
|
||||||
|
prop.prev();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ public class Button extends Element {
|
|||||||
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0xFF000000));
|
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0xFF000000));
|
||||||
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFFFFFFFF));
|
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFFFFFFFF));
|
||||||
private static Property<Integer> cornerRadius = theme.property("corner-radius", new Property<Integer>(10));
|
private static Property<Integer> cornerRadius = theme.property("corner-radius", new Property<Integer>(10));
|
||||||
private static Property<Boolean> bold = theme.property("fg-bold", new Property<Boolean>(false));
|
private static Property<Integer> font = theme.property("font", Property.font(1));
|
||||||
|
|
||||||
static {
|
static {
|
||||||
theme.propertyStateDefault("hovering", "fg-color", 0xFF845eee);
|
theme.propertyStateDefault("hovering", "fg-color", 0xFF845eee);
|
||||||
@@ -24,7 +24,7 @@ public class Button extends Element {
|
|||||||
public Button(String text, Runnable onClick) {
|
public Button(String text, Runnable onClick) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.onClick = onClick;
|
this.onClick = onClick;
|
||||||
this.dimensions(Fonts.getWidth(text, bold.value) + 50, 38);
|
this.dimensions(Fonts.getWidth(text, font.value) + 50, 38);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -37,7 +37,7 @@ public class Button extends Element {
|
|||||||
renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, bgColor.value);
|
renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, bgColor.value);
|
||||||
|
|
||||||
// renderScope.drawText(text, (width - Fonts.getWidth(text, font)) / 2, (height - Fonts.getHeight()) / 2, bold.value, fgColor.value);
|
// renderScope.drawText(text, (width - Fonts.getWidth(text, font)) / 2, (height - Fonts.getHeight()) / 2, bold.value, fgColor.value);
|
||||||
renderScope.drawText(text, Fonts.centerX(width, text, bold.value), Fonts.centerY(height), bold.value, fgColor.value);
|
renderScope.drawText(text, Fonts.centerX(width, text, font.value), Fonts.centerY(height), font.value, fgColor.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.saturnclient.ui2.RenderScope;
|
|||||||
public class Text extends Element {
|
public class Text extends Element {
|
||||||
private static ThemeManager theme = new ThemeManager("Text");
|
private static ThemeManager theme = new ThemeManager("Text");
|
||||||
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFFFFFFFF));
|
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFFFFFFFF));
|
||||||
|
public static Property<Integer> font = theme.property("font", Property.font(1));
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
@@ -18,6 +19,6 @@ public class Text extends Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||||
renderScope.drawText(this.text, 0, 0, false, fgColor.value);
|
renderScope.drawText(this.text, 0, 0, font.value, fgColor.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,16 @@ import net.minecraft.util.Identifier;
|
|||||||
public class Fonts {
|
public class Fonts {
|
||||||
public static final Identifier INTER = Identifier.of("saturnclient", "inter");
|
public static final Identifier INTER = Identifier.of("saturnclient", "inter");
|
||||||
public static final Identifier INTER_BOLD = Identifier.of("saturnclient", "inter_bold");
|
public static final Identifier INTER_BOLD = Identifier.of("saturnclient", "inter_bold");
|
||||||
|
public static final Identifier DEFAULT = Identifier.ofVanilla("default");
|
||||||
|
|
||||||
public static Identifier getFont(boolean bold) {
|
public static Identifier getFont(int font) {
|
||||||
if (bold) {
|
switch (font) {
|
||||||
return INTER_BOLD;
|
case 0:
|
||||||
} else {
|
return DEFAULT;
|
||||||
|
case 1:
|
||||||
return INTER;
|
return INTER;
|
||||||
|
default:
|
||||||
|
return INTER_BOLD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,35 +26,24 @@ public class Fonts {
|
|||||||
Style.EMPTY.withFont(font));
|
Style.EMPTY.withFont(font));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Text setFont(String text, boolean bold) {
|
public static int getWidth(String text, int font) {
|
||||||
return Text.literal(text).setStyle(
|
if (font == 0) {
|
||||||
Style.EMPTY.withFont(bold ? INTER_BOLD : INTER));
|
return getWidth(text, getFont(font)) * 2;
|
||||||
|
} else {
|
||||||
|
return getWidth(text, getFont(font));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Text setFont(String text) {
|
private static int getWidth(String text, Identifier font) {
|
||||||
return Text.literal(text).setStyle(
|
return SaturnClient.client.textRenderer.getWidth(setFont(text, font));
|
||||||
Style.EMPTY.withFont(INTER));
|
|
||||||
}
|
|
||||||
|
|
||||||
// public static int getWidth(String text, Identifier font) {
|
|
||||||
// return SaturnClient.client.textRenderer.getWidth(Text.literal(text).setStyle(
|
|
||||||
// Style.EMPTY.withFont(font)));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public static int getHeight() {
|
|
||||||
// return SaturnClient.client.textRenderer.fontHeight;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static int getWidth(String text, boolean bold) {
|
|
||||||
return SaturnClient.client.textRenderer.getWidth(setFont(text, getFont(bold)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getHeight() {
|
public static int getHeight() {
|
||||||
return 18;
|
return 18;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int centerX(int w, String text, boolean bold) {
|
public static int centerX(int w, String text, int font) {
|
||||||
return (w - Fonts.getWidth(text, bold)) / 2;
|
return (w - Fonts.getWidth(text, font)) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int centerY(int h) {
|
public static int centerY(int h) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.saturnclient.ui2.components.Sidebar;
|
|||||||
import org.saturnclient.ui2.components.inputs.FloatInput;
|
import org.saturnclient.ui2.components.inputs.FloatInput;
|
||||||
import org.saturnclient.ui2.components.inputs.HexInput;
|
import org.saturnclient.ui2.components.inputs.HexInput;
|
||||||
import org.saturnclient.ui2.components.inputs.IntInput;
|
import org.saturnclient.ui2.components.inputs.IntInput;
|
||||||
|
import org.saturnclient.ui2.components.inputs.Select;
|
||||||
import org.saturnclient.ui2.components.inputs.Toggle;
|
import org.saturnclient.ui2.components.inputs.Toggle;
|
||||||
import org.saturnclient.ui2.elements.Scroll;
|
import org.saturnclient.ui2.elements.Scroll;
|
||||||
import org.saturnclient.ui2.elements.Text;
|
import org.saturnclient.ui2.elements.Text;
|
||||||
@@ -59,7 +60,7 @@ public class ConfigEditor extends SaturnScreen {
|
|||||||
configScroll.draw(
|
configScroll.draw(
|
||||||
new Text(
|
new Text(
|
||||||
propName
|
propName
|
||||||
).position(Fonts.centerX(520, propName, false), modY + 1).scale(0.7f));
|
).position(Fonts.centerX(520, propName, Text.font.value), modY + 1).scale(0.7f));
|
||||||
} else {
|
} else {
|
||||||
configScroll.draw(
|
configScroll.draw(
|
||||||
new Text(
|
new Text(
|
||||||
@@ -91,6 +92,11 @@ public class ConfigEditor extends SaturnScreen {
|
|||||||
Map<String, Property<?>> nestedProperties = (Map<String, Property<?>>) prop.value;
|
Map<String, Property<?>> nestedProperties = (Map<String, Property<?>>) prop.value;
|
||||||
row = drawProperties(configScroll, nestedProperties, row + 1, col, w);
|
row = drawProperties(configScroll, nestedProperties, row + 1, col, w);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SELECT:
|
||||||
|
configScroll.draw(new Select((Property<Integer>) prop).position(w / 2, modY));
|
||||||
|
break;
|
||||||
|
|
||||||
case STRING:
|
case STRING:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.saturnclient.ui2.components.Sidebar;
|
|||||||
import org.saturnclient.ui2.components.inputs.FloatInput;
|
import org.saturnclient.ui2.components.inputs.FloatInput;
|
||||||
import org.saturnclient.ui2.components.inputs.HexInput;
|
import org.saturnclient.ui2.components.inputs.HexInput;
|
||||||
import org.saturnclient.ui2.components.inputs.IntInput;
|
import org.saturnclient.ui2.components.inputs.IntInput;
|
||||||
|
import org.saturnclient.ui2.components.inputs.Select;
|
||||||
import org.saturnclient.ui2.components.inputs.Toggle;
|
import org.saturnclient.ui2.components.inputs.Toggle;
|
||||||
import org.saturnclient.ui2.elements.Scroll;
|
import org.saturnclient.ui2.elements.Scroll;
|
||||||
import org.saturnclient.ui2.elements.Text;
|
import org.saturnclient.ui2.elements.Text;
|
||||||
@@ -55,7 +56,7 @@ public class SaturnConfigEditor extends SaturnScreen {
|
|||||||
configScroll.draw(
|
configScroll.draw(
|
||||||
new Text(
|
new Text(
|
||||||
propName
|
propName
|
||||||
).position(Fonts.centerX(520, propName, false), modY + 1).scale(0.7f));
|
).position(Fonts.centerX(520, propName, Text.font.value), modY + 1).scale(0.7f));
|
||||||
} else {
|
} else {
|
||||||
configScroll.draw(
|
configScroll.draw(
|
||||||
new Text(
|
new Text(
|
||||||
@@ -88,6 +89,9 @@ public class SaturnConfigEditor extends SaturnScreen {
|
|||||||
row = drawProperties(configScroll, nestedProperties, row + 1, col, w);
|
row = drawProperties(configScroll, nestedProperties, row + 1, col, w);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SELECT:
|
||||||
|
configScroll.draw(new Select((Property<Integer>) prop).position(w / 2, modY));
|
||||||
|
|
||||||
case STRING:
|
case STRING:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user