reset button
This commit is contained in:
@@ -17,10 +17,13 @@ public class Property<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public T value;
|
public T value;
|
||||||
|
public boolean isReset = false;
|
||||||
|
private T defaultValue;
|
||||||
private PropertyType type;
|
private PropertyType type;
|
||||||
|
|
||||||
public Property(T value) {
|
public Property(T value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
this.defaultValue = value;
|
||||||
if (value instanceof Boolean) {
|
if (value instanceof Boolean) {
|
||||||
type = PropertyType.BOOLEAN;
|
type = PropertyType.BOOLEAN;
|
||||||
} else if (value instanceof Integer) {
|
} else if (value instanceof Integer) {
|
||||||
@@ -36,6 +39,7 @@ public class Property<T> {
|
|||||||
|
|
||||||
public Property(T value, PropertyType type) {
|
public Property(T value, PropertyType type) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
this.defaultValue = value;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +71,11 @@ public class Property<T> {
|
|||||||
throw new IllegalStateException("Property does not contain a string");
|
throw new IllegalStateException("Property does not contain a string");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
value = defaultValue;
|
||||||
|
isReset = true;
|
||||||
|
}
|
||||||
|
|
||||||
public int getHexString() {
|
public int getHexString() {
|
||||||
if (value instanceof String) {
|
if (value instanceof String) {
|
||||||
String str = (String) value;
|
String str = (String) value;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.saturnclient.saturnclient.SaturnClient;
|
|||||||
import org.saturnclient.saturnclient.config.ConfigManager;
|
import org.saturnclient.saturnclient.config.ConfigManager;
|
||||||
import org.saturnclient.saturnclient.config.Property;
|
import org.saturnclient.saturnclient.config.Property;
|
||||||
import org.saturnclient.ui.SaturnUi;
|
import org.saturnclient.ui.SaturnUi;
|
||||||
|
import org.saturnclient.ui.SaturnWidget;
|
||||||
import org.saturnclient.ui.Textures;
|
import org.saturnclient.ui.Textures;
|
||||||
import org.saturnclient.ui.components.SaturnFloat;
|
import org.saturnclient.ui.components.SaturnFloat;
|
||||||
import org.saturnclient.ui.components.SaturnHex;
|
import org.saturnclient.ui.components.SaturnHex;
|
||||||
@@ -116,6 +117,8 @@ public class ConfigEditor extends SaturnUi {
|
|||||||
(rectWidth / 2) - 17,
|
(rectWidth / 2) - 17,
|
||||||
modY,
|
modY,
|
||||||
70));
|
70));
|
||||||
|
|
||||||
|
configScroll.draw(resetButton(prop, modX, modY));
|
||||||
break;
|
break;
|
||||||
case FLOAT:
|
case FLOAT:
|
||||||
configScroll.draw(
|
configScroll.draw(
|
||||||
@@ -132,6 +135,8 @@ public class ConfigEditor extends SaturnUi {
|
|||||||
(rectWidth / 2) - 17,
|
(rectWidth / 2) - 17,
|
||||||
modY,
|
modY,
|
||||||
70));
|
70));
|
||||||
|
|
||||||
|
configScroll.draw(resetButton(prop, modX, modY));
|
||||||
break;
|
break;
|
||||||
case STRING:
|
case STRING:
|
||||||
configScroll.draw(
|
configScroll.draw(
|
||||||
@@ -148,6 +153,8 @@ public class ConfigEditor extends SaturnUi {
|
|||||||
(rectWidth / 2) - 17,
|
(rectWidth / 2) - 17,
|
||||||
modY,
|
modY,
|
||||||
70));
|
70));
|
||||||
|
|
||||||
|
configScroll.draw(resetButton(prop, modX, modY));
|
||||||
break;
|
break;
|
||||||
case HEX:
|
case HEX:
|
||||||
configScroll.draw(
|
configScroll.draw(
|
||||||
@@ -164,6 +171,8 @@ public class ConfigEditor extends SaturnUi {
|
|||||||
(rectWidth / 2) - 17,
|
(rectWidth / 2) - 17,
|
||||||
modY,
|
modY,
|
||||||
70));
|
70));
|
||||||
|
|
||||||
|
configScroll.draw(resetButton(prop, modX, modY));
|
||||||
break;
|
break;
|
||||||
case NAMESPACE:
|
case NAMESPACE:
|
||||||
configScroll.draw(
|
configScroll.draw(
|
||||||
@@ -207,4 +216,19 @@ public class ConfigEditor extends SaturnUi {
|
|||||||
ConfigManager.save();
|
ConfigManager.save();
|
||||||
super.close();
|
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 HudMod draggingMod = null;
|
||||||
private boolean resizing = false;
|
private boolean resizing = false;
|
||||||
private int offsetX, offsetY;
|
private int offsetX, offsetY;
|
||||||
private static final int RESIZE_MARGIN = 6;
|
private static final int RESIZE_MARGIN = 3;
|
||||||
|
|
||||||
public HudEditor() {
|
public HudEditor() {
|
||||||
super(Text.literal("HUD Editor"));
|
super(Text.literal("HUD Editor"));
|
||||||
|
|||||||
@@ -16,17 +16,20 @@ public class Coordinates implements SaturnMod, HudMod {
|
|||||||
|
|
||||||
private static ConfigManager config = new ConfigManager("coords");
|
private static ConfigManager config = new ConfigManager("coords");
|
||||||
public static Property<Boolean> enabled = config.property(
|
public static Property<Boolean> enabled = config.property(
|
||||||
"Enabled",
|
"Enabled",
|
||||||
new Property<>(false)
|
new Property<>(false));
|
||||||
);
|
|
||||||
private static ModDimensions dimensions = new ModDimensions(config);
|
private static ModDimensions dimensions = new ModDimensions(config);
|
||||||
|
|
||||||
public static Property<Integer> fgColor = config.property(
|
public static Property<Integer> fgColor = config.property(
|
||||||
"Foreground color",
|
"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) {
|
public void renderDummy(DrawContext context) {
|
||||||
int playerX = 124;
|
int playerX = 124;
|
||||||
@@ -34,17 +37,15 @@ public class Coordinates implements SaturnMod, HudMod {
|
|||||||
int playerZ = 83;
|
int playerZ = 83;
|
||||||
|
|
||||||
context.drawText(
|
context.drawText(
|
||||||
SaturnClient.textRenderer,
|
SaturnClient.textRenderer,
|
||||||
playerX + " " + playerY + " " + playerZ,
|
playerX + " " + playerY + " " + playerZ,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
fgColor.value,
|
fgColor.value,
|
||||||
false
|
false);
|
||||||
);
|
|
||||||
|
|
||||||
dimensions.width = SaturnClient.textRenderer.getWidth(
|
dimensions.width = SaturnClient.textRenderer.getWidth(
|
||||||
playerX + " " + playerY + " " + playerZ
|
playerX + " " + playerY + " " + playerZ);
|
||||||
);
|
|
||||||
dimensions.height = SaturnClient.textRenderer.fontHeight;
|
dimensions.height = SaturnClient.textRenderer.fontHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,13 +56,12 @@ public class Coordinates implements SaturnMod, HudMod {
|
|||||||
int playerZ = (int) player.getZ();
|
int playerZ = (int) player.getZ();
|
||||||
|
|
||||||
context.drawText(
|
context.drawText(
|
||||||
SaturnClient.textRenderer,
|
SaturnClient.textRenderer,
|
||||||
playerX + " " + playerY + " " + playerZ,
|
playerX + " " + playerY + " " + playerZ,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
fgColor.value,
|
fgColor.value,
|
||||||
false
|
false);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
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 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 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 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",
|
public static final Identifier TOGGLE_INDICATOR = Identifier.of("saturnclient",
|
||||||
"textures/gui/components/toggle_indicator.png");
|
"textures/gui/components/toggle_indicator.png");
|
||||||
public static final Identifier TOGGLE_BG = Identifier.of("saturnclient", "textures/gui/components/toggle_bg.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,
|
boolean hovering,
|
||||||
int mouseX,
|
int mouseX,
|
||||||
int mouseY) {
|
int mouseY) {
|
||||||
|
if (prop.isReset) {
|
||||||
|
this.text = String.valueOf(prop.value);
|
||||||
|
this.cursorPosition = 0;
|
||||||
|
prop.isReset = false;
|
||||||
|
}
|
||||||
SaturnUi.drawHighResGuiTexture(
|
SaturnUi.drawHighResGuiTexture(
|
||||||
context,
|
context,
|
||||||
Textures.BUTTON_BORDER,
|
Textures.BUTTON_BORDER,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class SaturnHex extends SaturnWidget {
|
|||||||
this.y = y;
|
this.y = y;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.prop = prop;
|
this.prop = prop;
|
||||||
this.text = intToHex(prop.value); // Convert stored int to hex
|
this.text = intToHex(prop.value);
|
||||||
this.height = textRenderer.fontHeight + 4;
|
this.height = textRenderer.fontHeight + 4;
|
||||||
this.scale = 0.8f;
|
this.scale = 0.8f;
|
||||||
}
|
}
|
||||||
@@ -76,6 +76,11 @@ public class SaturnHex extends SaturnWidget {
|
|||||||
boolean hovering,
|
boolean hovering,
|
||||||
int mouseX,
|
int mouseX,
|
||||||
int mouseY) {
|
int mouseY) {
|
||||||
|
if (prop.isReset) {
|
||||||
|
this.text = intToHex(prop.value);
|
||||||
|
this.cursorPosition = 0;
|
||||||
|
prop.isReset = false;
|
||||||
|
}
|
||||||
SaturnUi.drawHighResGuiTexture(
|
SaturnUi.drawHighResGuiTexture(
|
||||||
context,
|
context,
|
||||||
Textures.BUTTON_BORDER,
|
Textures.BUTTON_BORDER,
|
||||||
|
|||||||
@@ -97,6 +97,11 @@ public class SaturnInteger extends SaturnWidget {
|
|||||||
boolean hovering,
|
boolean hovering,
|
||||||
int mouseX,
|
int mouseX,
|
||||||
int mouseY) {
|
int mouseY) {
|
||||||
|
if (prop.isReset) {
|
||||||
|
this.text = String.valueOf(prop.value);
|
||||||
|
this.cursorPosition = 0;
|
||||||
|
prop.isReset = false;
|
||||||
|
}
|
||||||
SaturnUi.drawHighResGuiTexture(
|
SaturnUi.drawHighResGuiTexture(
|
||||||
context,
|
context,
|
||||||
Textures.BUTTON_BORDER,
|
Textures.BUTTON_BORDER,
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 771 B |
Reference in New Issue
Block a user