reset button

This commit is contained in:
2025-04-03 23:30:32 +02:00
parent 6b67b7bf8e
commit 7e04120fa2
9 changed files with 74 additions and 25 deletions
@@ -17,10 +17,13 @@ public class Property<T> {
}
public T value;
public boolean isReset = false;
private T defaultValue;
private PropertyType type;
public Property(T value) {
this.value = value;
this.defaultValue = value;
if (value instanceof Boolean) {
type = PropertyType.BOOLEAN;
} else if (value instanceof Integer) {
@@ -36,6 +39,7 @@ public class Property<T> {
public Property(T value, PropertyType type) {
this.value = value;
this.defaultValue = value;
this.type = type;
}
@@ -67,6 +71,11 @@ public class Property<T> {
throw new IllegalStateException("Property does not contain a string");
}
public void reset() {
value = defaultValue;
isReset = true;
}
public int getHexString() {
if (value instanceof String) {
String str = (String) value;
@@ -6,6 +6,7 @@ import org.saturnclient.saturnclient.SaturnClient;
import org.saturnclient.saturnclient.config.ConfigManager;
import org.saturnclient.saturnclient.config.Property;
import org.saturnclient.ui.SaturnUi;
import org.saturnclient.ui.SaturnWidget;
import org.saturnclient.ui.Textures;
import org.saturnclient.ui.components.SaturnFloat;
import org.saturnclient.ui.components.SaturnHex;
@@ -116,6 +117,8 @@ public class ConfigEditor extends SaturnUi {
(rectWidth / 2) - 17,
modY,
70));
configScroll.draw(resetButton(prop, modX, modY));
break;
case FLOAT:
configScroll.draw(
@@ -132,6 +135,8 @@ public class ConfigEditor extends SaturnUi {
(rectWidth / 2) - 17,
modY,
70));
configScroll.draw(resetButton(prop, modX, modY));
break;
case STRING:
configScroll.draw(
@@ -148,6 +153,8 @@ public class ConfigEditor extends SaturnUi {
(rectWidth / 2) - 17,
modY,
70));
configScroll.draw(resetButton(prop, modX, modY));
break;
case HEX:
configScroll.draw(
@@ -164,6 +171,8 @@ public class ConfigEditor extends SaturnUi {
(rectWidth / 2) - 17,
modY,
70));
configScroll.draw(resetButton(prop, modX, modY));
break;
case NAMESPACE:
configScroll.draw(
@@ -207,4 +216,19 @@ public class ConfigEditor extends SaturnUi {
ConfigManager.save();
super.close();
}
public SaturnWidget resetButton(Property<?> prop, int modX, int modY) {
int size = textRenderer.fontHeight - 1;
return new SaturnImageButton(
Textures.RESET,
size,
size,
() -> {
prop.reset();
})
.setX(modX + 209)
.setY(modY)
.setWidth(size + 3)
.setHeight(size + 3);
}
}
@@ -18,7 +18,7 @@ public class HudEditor extends Screen {
private HudMod draggingMod = null;
private boolean resizing = false;
private int offsetX, offsetY;
private static final int RESIZE_MARGIN = 6;
private static final int RESIZE_MARGIN = 3;
public HudEditor() {
super(Text.literal("HUD Editor"));
@@ -17,16 +17,19 @@ public class Coordinates implements SaturnMod, HudMod {
private static ConfigManager config = new ConfigManager("coords");
public static Property<Boolean> enabled = config.property(
"Enabled",
new Property<>(false)
);
new Property<>(false));
private static ModDimensions dimensions = new ModDimensions(config);
public static Property<Integer> fgColor = config.property(
"Foreground color",
new Property<>(SaturnClient.WHITE, Property.PropertyType.HEX)
);
new Property<>(SaturnClient.WHITE, Property.PropertyType.HEX));
public Coordinates() {}
public Coordinates() {
// Ensure fgColor has a value
if (fgColor.value == null) {
fgColor.value = SaturnClient.WHITE;
}
}
public void renderDummy(DrawContext context) {
int playerX = 124;
@@ -39,12 +42,10 @@ public class Coordinates implements SaturnMod, HudMod {
0,
0,
fgColor.value,
false
);
false);
dimensions.width = SaturnClient.textRenderer.getWidth(
playerX + " " + playerY + " " + playerZ
);
playerX + " " + playerY + " " + playerZ);
dimensions.height = SaturnClient.textRenderer.fontHeight;
}
@@ -60,8 +61,7 @@ public class Coordinates implements SaturnMod, HudMod {
0,
0,
fgColor.value,
false
);
false);
}
public String getName() {
@@ -11,6 +11,7 @@ public class Textures {
public static final Identifier SETTINGS = Identifier.of("saturnclient", "textures/gui/components/settings.png");
public static final Identifier CLOAK = Identifier.of("saturnclient", "textures/gui/components/cloak.png");
public static final Identifier HAT = Identifier.of("saturnclient", "textures/gui/components/hat.png");
public static final Identifier RESET = Identifier.of("saturnclient", "textures/gui/components/reset.png");
public static final Identifier TOGGLE_INDICATOR = Identifier.of("saturnclient",
"textures/gui/components/toggle_indicator.png");
public static final Identifier TOGGLE_BG = Identifier.of("saturnclient", "textures/gui/components/toggle_bg.png");
@@ -97,6 +97,11 @@ public class SaturnFloat extends SaturnWidget {
boolean hovering,
int mouseX,
int mouseY) {
if (prop.isReset) {
this.text = String.valueOf(prop.value);
this.cursorPosition = 0;
prop.isReset = false;
}
SaturnUi.drawHighResGuiTexture(
context,
Textures.BUTTON_BORDER,
@@ -22,7 +22,7 @@ public class SaturnHex extends SaturnWidget {
this.y = y;
this.width = width;
this.prop = prop;
this.text = intToHex(prop.value); // Convert stored int to hex
this.text = intToHex(prop.value);
this.height = textRenderer.fontHeight + 4;
this.scale = 0.8f;
}
@@ -76,6 +76,11 @@ public class SaturnHex extends SaturnWidget {
boolean hovering,
int mouseX,
int mouseY) {
if (prop.isReset) {
this.text = intToHex(prop.value);
this.cursorPosition = 0;
prop.isReset = false;
}
SaturnUi.drawHighResGuiTexture(
context,
Textures.BUTTON_BORDER,
@@ -97,6 +97,11 @@ public class SaturnInteger extends SaturnWidget {
boolean hovering,
int mouseX,
int mouseY) {
if (prop.isReset) {
this.text = String.valueOf(prop.value);
this.cursorPosition = 0;
prop.isReset = false;
}
SaturnUi.drawHighResGuiTexture(
context,
Textures.BUTTON_BORDER,
Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B