some ui stuff
This commit is contained in:
@@ -24,7 +24,7 @@ public class ModDimensions {
|
|||||||
"Background Color", bgColor,
|
"Background Color", bgColor,
|
||||||
"Foreground Color", fgColor,
|
"Foreground Color", fgColor,
|
||||||
"Corner Radius", radius
|
"Corner Radius", radius
|
||||||
)).named("Hud Position");
|
)).named("In-Game Display");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModDimensions(int width, int height) {
|
public ModDimensions(int width, int height) {
|
||||||
|
|||||||
@@ -25,15 +25,30 @@ public class ArmorDisplay extends Module implements HudMod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void renderArmor(RenderScope scope, ItemStack helmet, ItemStack chestplate, ItemStack leggings, ItemStack boots) {
|
public void renderArmor(RenderScope scope, ItemStack helmet, ItemStack chestplate, ItemStack leggings, ItemStack boots) {
|
||||||
scope.drawItem(helmet, 0, 0);
|
int row = 0;
|
||||||
scope.drawItem(chestplate, 0, 15);
|
|
||||||
scope.drawItem(leggings, 0, 30);
|
|
||||||
scope.drawItem(boots, 0, 45);
|
|
||||||
|
|
||||||
renderHealth(scope, 0, helmet.getMaxDamage(), helmet.getDamage());
|
if (!helmet.isEmpty()) {
|
||||||
renderHealth(scope, 1, chestplate.getMaxDamage(), chestplate.getDamage());
|
scope.drawItem(helmet, 0, 0);
|
||||||
renderHealth(scope, 2, leggings.getMaxDamage(), leggings.getDamage());
|
renderHealth(scope, row, helmet.getMaxDamage(), helmet.getDamage());
|
||||||
renderHealth(scope, 3, boots.getMaxDamage(), boots.getDamage());
|
row++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chestplate.isEmpty()) {
|
||||||
|
scope.drawItem(chestplate, 0, 15 * row);
|
||||||
|
renderHealth(scope, row, chestplate.getMaxDamage(), chestplate.getDamage());
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
if (!leggings.isEmpty()) {
|
||||||
|
scope.drawItem(leggings, 0, 15 * row);
|
||||||
|
renderHealth(scope, row, leggings.getMaxDamage(), leggings.getDamage());
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!boots.isEmpty()) {
|
||||||
|
scope.drawItem(boots, 0, 15 * row);
|
||||||
|
renderHealth(scope, row, boots.getMaxDamage(), boots.getDamage());
|
||||||
|
row++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderHealth(RenderScope scope, int i, int max, int current) {
|
public void renderHealth(RenderScope scope, int i, int max, int current) {
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ public class ColorDialog extends SaturnScreen {
|
|||||||
private static final int PICKER_HEIGHT = 200;
|
private static final int PICKER_HEIGHT = 200;
|
||||||
private static final int SLIDER_WIDTH = 200;
|
private static final int SLIDER_WIDTH = 200;
|
||||||
private static final int SLIDER_HEIGHT = 10;
|
private static final int SLIDER_HEIGHT = 10;
|
||||||
|
private static final int HUE_SLIDER_HEIGHT = 10;
|
||||||
|
private float hue = 0.0f;
|
||||||
|
|
||||||
private int selectedX = 0;
|
private int selectedX = 0;
|
||||||
private int selectedY = 0;
|
private int selectedY = 0;
|
||||||
@@ -32,6 +34,7 @@ public class ColorDialog extends SaturnScreen {
|
|||||||
int alpha = (prop.value >> 24) & 0xFF;
|
int alpha = (prop.value >> 24) & 0xFF;
|
||||||
if (alpha == 0) alpha = 255; // fallback if no alpha specified
|
if (alpha == 0) alpha = 255; // fallback if no alpha specified
|
||||||
this.opacity = alpha / 255.0f;
|
this.opacity = alpha / 255.0f;
|
||||||
|
syncFromColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -55,12 +58,12 @@ public class ColorDialog extends SaturnScreen {
|
|||||||
int xStart = (width - PICKER_WIDTH) / 2;
|
int xStart = (width - PICKER_WIDTH) / 2;
|
||||||
int yStart = (height - PICKER_HEIGHT) / 2;
|
int yStart = (height - PICKER_HEIGHT) / 2;
|
||||||
|
|
||||||
// Draw the HSV hue/saturation square (brightness fixed at 1)
|
// Draw the HSV saturation/value square (with current hue)
|
||||||
for (int x = 0; x < PICKER_WIDTH; x++) {
|
for (int x = 0; x < PICKER_WIDTH; x++) {
|
||||||
for (int y = 0; y < PICKER_HEIGHT; y++) {
|
for (int y = 0; y < PICKER_HEIGHT; y++) {
|
||||||
float hue = x / (float) PICKER_WIDTH;
|
float saturation = x / (float) PICKER_WIDTH;
|
||||||
float saturation = y / (float) PICKER_HEIGHT;
|
float value = 1.0f - y / (float) PICKER_HEIGHT;
|
||||||
int color = Color.HSBtoRGB(hue, saturation, 1.0f);
|
int color = Color.HSBtoRGB(hue, saturation, value);
|
||||||
context.fill(xStart + x, yStart + y, xStart + x + 1, yStart + y + 1, 0xFF000000 | color);
|
context.fill(xStart + x, yStart + y, xStart + x + 1, yStart + y + 1, 0xFF000000 | color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,6 +74,7 @@ public class ColorDialog extends SaturnScreen {
|
|||||||
context.drawBorder(x, y, 8, 8, 0xFFffffff);
|
context.drawBorder(x, y, 8, 8, 0xFFffffff);
|
||||||
|
|
||||||
renderSlider(context, mouseX, mouseY, delta);
|
renderSlider(context, mouseX, mouseY, delta);
|
||||||
|
renderHueSlider(context);
|
||||||
|
|
||||||
renderScope.matrices.pop();
|
renderScope.matrices.pop();
|
||||||
}
|
}
|
||||||
@@ -95,6 +99,20 @@ public class ColorDialog extends SaturnScreen {
|
|||||||
// context.drawText(textRenderer, String.format("Opacity: %.2f", opacity), xStart, yStart - 15, 0xFFFFFF, false);
|
// context.drawText(textRenderer, String.format("Opacity: %.2f", opacity), xStart, yStart - 15, 0xFFFFFF, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void renderHueSlider(DrawContext context) {
|
||||||
|
int xStart = (width - SLIDER_WIDTH) / 2;
|
||||||
|
int yStart = (height + PICKER_HEIGHT) / 2 + 10;
|
||||||
|
|
||||||
|
for (int x = 0; x < SLIDER_WIDTH; x++) {
|
||||||
|
float localHue = x / (float) SLIDER_WIDTH;
|
||||||
|
int color = Color.HSBtoRGB(localHue, 1.0f, 1.0f);
|
||||||
|
context.fill(xStart + x, yStart, xStart + x + 1, yStart + HUE_SLIDER_HEIGHT, 0xFF000000 | color);
|
||||||
|
}
|
||||||
|
|
||||||
|
int knobX = xStart + (int)(hue * SLIDER_WIDTH);
|
||||||
|
context.fill(knobX - 1, yStart - 2, knobX + 1, yStart + HUE_SLIDER_HEIGHT + 2, 0xFF000000);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||||
mouseX *= 2;
|
mouseX *= 2;
|
||||||
@@ -107,9 +125,9 @@ public class ColorDialog extends SaturnScreen {
|
|||||||
int relY = (int) mouseY - yStart;
|
int relY = (int) mouseY - yStart;
|
||||||
|
|
||||||
if (relX >= 0 && relX < PICKER_WIDTH && relY >= 0 && relY < PICKER_HEIGHT) {
|
if (relX >= 0 && relX < PICKER_WIDTH && relY >= 0 && relY < PICKER_HEIGHT) {
|
||||||
float hue = relX / (float) PICKER_WIDTH;
|
float saturation = relX / (float) PICKER_WIDTH;
|
||||||
float saturation = relY / (float) PICKER_HEIGHT;
|
float value = 1.0f - relY / (float) PICKER_HEIGHT;
|
||||||
prop.value = Color.HSBtoRGB(hue, saturation, 1.0f);
|
prop.value = Color.HSBtoRGB(hue, saturation, value);
|
||||||
|
|
||||||
int alpha = (int)(opacity * 255) & 0xFF;
|
int alpha = (int)(opacity * 255) & 0xFF;
|
||||||
prop.value = (alpha << 24) | (prop.value & 0xFFFFFF);
|
prop.value = (alpha << 24) | (prop.value & 0xFFFFFF);
|
||||||
@@ -122,6 +140,9 @@ public class ColorDialog extends SaturnScreen {
|
|||||||
updateOpacity(mouseX);
|
updateOpacity(mouseX);
|
||||||
dragging = true;
|
dragging = true;
|
||||||
return true;
|
return true;
|
||||||
|
} else if (isInHueSlider(mouseX, mouseY)) {
|
||||||
|
updateHue(mouseX);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.mouseClicked(mouseX, mouseY, button);
|
return super.mouseClicked(mouseX, mouseY, button);
|
||||||
@@ -138,7 +159,10 @@ public class ColorDialog extends SaturnScreen {
|
|||||||
mouseX *= 2;
|
mouseX *= 2;
|
||||||
mouseY *= 2;
|
mouseY *= 2;
|
||||||
|
|
||||||
if (dragging) {
|
if (isInHueSlider(mouseX, mouseY)) {
|
||||||
|
updateHue(mouseX);
|
||||||
|
return true;
|
||||||
|
} else if (dragging) {
|
||||||
updateOpacity(mouseX);
|
updateOpacity(mouseX);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -149,9 +173,9 @@ public class ColorDialog extends SaturnScreen {
|
|||||||
int relY = (int) mouseY - yStart;
|
int relY = (int) mouseY - yStart;
|
||||||
|
|
||||||
if (relX >= 0 && relX < PICKER_WIDTH && relY >= 0 && relY < PICKER_HEIGHT) {
|
if (relX >= 0 && relX < PICKER_WIDTH && relY >= 0 && relY < PICKER_HEIGHT) {
|
||||||
float hue = relX / (float) PICKER_WIDTH;
|
float saturation = relX / (float) PICKER_WIDTH;
|
||||||
float saturation = relY / (float) PICKER_HEIGHT;
|
float value = 1.0f - relY / (float) PICKER_HEIGHT;
|
||||||
prop.value = Color.HSBtoRGB(hue, saturation, 1.0f);
|
prop.value = Color.HSBtoRGB(hue, saturation, value);
|
||||||
|
|
||||||
int alpha = (int)(opacity * 255) & 0xFF;
|
int alpha = (int)(opacity * 255) & 0xFF;
|
||||||
prop.value = (alpha << 24) | (prop.value & 0xFFFFFF);
|
prop.value = (alpha << 24) | (prop.value & 0xFFFFFF);
|
||||||
@@ -173,6 +197,13 @@ public class ColorDialog extends SaturnScreen {
|
|||||||
mouseY >= yStart && mouseY <= yStart + SLIDER_HEIGHT;
|
mouseY >= yStart && mouseY <= yStart + SLIDER_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isInHueSlider(double mouseX, double mouseY) {
|
||||||
|
int xStart = (width - SLIDER_WIDTH) / 2;
|
||||||
|
int yStart = (height + PICKER_HEIGHT) / 2 + 10;
|
||||||
|
return mouseX >= xStart && mouseX <= xStart + SLIDER_WIDTH &&
|
||||||
|
mouseY >= yStart && mouseY <= yStart + HUE_SLIDER_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
private void updateOpacity(double mouseX) {
|
private void updateOpacity(double mouseX) {
|
||||||
int xStart = (width - SLIDER_WIDTH) / 2;
|
int xStart = (width - SLIDER_WIDTH) / 2;
|
||||||
float newOpacity = (float)((mouseX - xStart) / SLIDER_WIDTH);
|
float newOpacity = (float)((mouseX - xStart) / SLIDER_WIDTH);
|
||||||
@@ -181,4 +212,35 @@ public class ColorDialog extends SaturnScreen {
|
|||||||
int alpha = (int)(opacity * 255) & 0xFF;
|
int alpha = (int)(opacity * 255) & 0xFF;
|
||||||
prop.value = (alpha << 24) | (prop.value & 0xFFFFFF);
|
prop.value = (alpha << 24) | (prop.value & 0xFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateHue(double mouseX) {
|
||||||
|
int xStart = (width - SLIDER_WIDTH) / 2;
|
||||||
|
float newHue = (float)((mouseX - xStart) / SLIDER_WIDTH);
|
||||||
|
hue = Math.max(0.0f, Math.min(1.0f, newHue));
|
||||||
|
|
||||||
|
float saturation = selectedX / (float) PICKER_WIDTH;
|
||||||
|
float value = 1.0f - selectedY / (float) PICKER_HEIGHT;
|
||||||
|
prop.value = Color.HSBtoRGB(hue, saturation, value);
|
||||||
|
|
||||||
|
int alpha = (int)(opacity * 255) & 0xFF;
|
||||||
|
prop.value = (alpha << 24) | (prop.value & 0xFFFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncFromColor() {
|
||||||
|
int rgb = prop.value & 0xFFFFFF;
|
||||||
|
float[] hsb = Color.RGBtoHSB((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF, null);
|
||||||
|
|
||||||
|
this.hue = hsb[0];
|
||||||
|
|
||||||
|
float saturation = hsb[1];
|
||||||
|
float value = hsb[2];
|
||||||
|
|
||||||
|
this.selectedX = (int)(saturation * PICKER_WIDTH);
|
||||||
|
this.selectedY = (int)((1.0f - value) * PICKER_HEIGHT);
|
||||||
|
|
||||||
|
// Extract alpha and convert to opacity float
|
||||||
|
int alpha = (prop.value >> 24) & 0xFF;
|
||||||
|
if (alpha == 0) alpha = 255;
|
||||||
|
this.opacity = alpha / 255.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class HexInput extends Element {
|
|||||||
|
|
||||||
public HexInput(Property<Integer> prop, SaturnScreen screen) {
|
public HexInput(Property<Integer> prop, SaturnScreen screen) {
|
||||||
this.width = 58;
|
this.width = 58;
|
||||||
this.height = 18;
|
this.height = 20;
|
||||||
this.prop = prop;
|
this.prop = prop;
|
||||||
this.scale = 0.8f;
|
this.scale = 0.8f;
|
||||||
this.screen = screen;
|
this.screen = screen;
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ public abstract class Input extends Element {
|
|||||||
String visibleText = text.substring(scrollOffset);
|
String visibleText = text.substring(scrollOffset);
|
||||||
|
|
||||||
int newCursorPos = scrollOffset;
|
int newCursorPos = scrollOffset;
|
||||||
int textWidth = 0;
|
float textWidth = 0;
|
||||||
|
|
||||||
for (int i = 0; i < visibleText.length(); i++) {
|
for (int i = 0; i < visibleText.length(); i++) {
|
||||||
textWidth = SaturnClient.client.textRenderer.getWidth(visibleText.substring(0, i + 1));
|
textWidth = SaturnClient.client.textRenderer.getWidth(visibleText.substring(0, i + 1)) * 0.6f;
|
||||||
|
|
||||||
if (textWidth > mouseX) {
|
if (textWidth > mouseX) {
|
||||||
break;
|
break;
|
||||||
@@ -66,14 +66,14 @@ 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, 2, 2, false, textColor);
|
renderScope.drawText(0.6f, visibleText, 4, 4, false, textColor);
|
||||||
|
|
||||||
if (focused) {
|
if (focused) {
|
||||||
int cursorX = 2 +
|
int cursorX = 4 +
|
||||||
SaturnClient.client.textRenderer.getWidth(
|
(int) (SaturnClient.client.textRenderer.getWidth(
|
||||||
Fonts.setFont(visibleText.substring(0, cursorPosition - scrollOffset)));
|
Fonts.setFont(visibleText.substring(0, cursorPosition - scrollOffset))) * 0.6f);
|
||||||
|
|
||||||
renderScope.drawRect(cursorX, 2, 1, height - 1, 0xFFFFFFFF);
|
renderScope.drawRect(cursorX, 2, 1, height - 4, 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.saturnclient.ui2.components.inputs.IntInput;
|
|||||||
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;
|
||||||
|
import org.saturnclient.ui2.resources.Fonts;
|
||||||
|
|
||||||
public class ConfigEditor extends SaturnScreen {
|
public class ConfigEditor extends SaturnScreen {
|
||||||
private ConfigManager config;
|
private ConfigManager config;
|
||||||
@@ -54,10 +55,17 @@ public class ConfigEditor extends SaturnScreen {
|
|||||||
int modX = (w / 2) * col; // two-column layout
|
int modX = (w / 2) * col; // two-column layout
|
||||||
int modY = 25 * row;
|
int modY = 25 * row;
|
||||||
|
|
||||||
configScroll.draw(
|
if (prop.getType() == Property.PropertyType.NAMESPACE) {
|
||||||
|
configScroll.draw(
|
||||||
new Text(
|
new Text(
|
||||||
propName.substring(0, 1).toUpperCase() + propName.substring(1)
|
propName
|
||||||
).position(modX, modY + 1).scale(0.7f));
|
).position(Fonts.centerX(520, propName, false), modY + 1).scale(0.7f));
|
||||||
|
} else {
|
||||||
|
configScroll.draw(
|
||||||
|
new Text(
|
||||||
|
propName
|
||||||
|
).position(modX, modY + 1).scale(0.7f));
|
||||||
|
}
|
||||||
|
|
||||||
switch (prop.getType()) {
|
switch (prop.getType()) {
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
@@ -83,6 +91,7 @@ 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 STRING:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (full) {
|
if (full) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.saturnclient.ui2.components.inputs.IntInput;
|
|||||||
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;
|
||||||
|
import org.saturnclient.ui2.resources.Fonts;
|
||||||
|
|
||||||
public class SaturnConfigEditor extends SaturnScreen {
|
public class SaturnConfigEditor extends SaturnScreen {
|
||||||
public SaturnConfigEditor() {
|
public SaturnConfigEditor() {
|
||||||
@@ -50,10 +51,17 @@ public class SaturnConfigEditor extends SaturnScreen {
|
|||||||
int modX = (w / 2) * col; // two-column layout
|
int modX = (w / 2) * col; // two-column layout
|
||||||
int modY = 25 * row;
|
int modY = 25 * row;
|
||||||
|
|
||||||
configScroll.draw(
|
if (prop.getType() == Property.PropertyType.NAMESPACE) {
|
||||||
|
configScroll.draw(
|
||||||
new Text(
|
new Text(
|
||||||
propName.substring(0, 1).toUpperCase() + propName.substring(1)
|
propName
|
||||||
).position(modX, modY + 1).scale(0.7f));
|
).position(Fonts.centerX(520, propName, false), modY + 1).scale(0.7f));
|
||||||
|
} else {
|
||||||
|
configScroll.draw(
|
||||||
|
new Text(
|
||||||
|
propName
|
||||||
|
).position(modX, modY + 1).scale(0.7f));
|
||||||
|
}
|
||||||
|
|
||||||
switch (prop.getType()) {
|
switch (prop.getType()) {
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
@@ -79,6 +87,8 @@ public class SaturnConfigEditor 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 STRING:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (full) {
|
if (full) {
|
||||||
|
|||||||
Reference in New Issue
Block a user