mirror of
https://github.com/Shiewk/Widgets.git
synced 2026-04-28 11:34:17 +02:00
Widget settings refactoring changes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package de.shiewk.widgets;
|
||||
|
||||
import de.shiewk.widgets.widgets.settings.WidgetSettingOption;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.text.Text;
|
||||
@@ -13,7 +14,7 @@ public abstract class ModWidget {
|
||||
private final Identifier id;
|
||||
private final WidgetSettings settings;
|
||||
|
||||
protected ModWidget(Identifier id, List<WidgetSettingOption> customSettings) {
|
||||
protected ModWidget(Identifier id, List<WidgetSettingOption<?>> customSettings) {
|
||||
Objects.requireNonNull(id, "id");
|
||||
this.id = id;
|
||||
this.settings = WidgetSettings.ofId(id, customSettings);
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import de.shiewk.widgets.client.WidgetManager;
|
||||
import de.shiewk.widgets.widgets.settings.WidgetSettingOption;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
@@ -18,9 +19,9 @@ public class WidgetSettings {
|
||||
public int offsetX = 0;
|
||||
public int offsetY = 0;
|
||||
private boolean enabled = false;
|
||||
private final ObjectArrayList<WidgetSettingOption> customSettings;
|
||||
private final ObjectArrayList<WidgetSettingOption<?>> customSettings;
|
||||
|
||||
private WidgetSettings(JsonObject data, List<WidgetSettingOption> settings){
|
||||
private WidgetSettings(JsonObject data, List<WidgetSettingOption<?>> settings){
|
||||
customSettings = new ObjectArrayList<>(settings);
|
||||
if (data != null){
|
||||
try {
|
||||
@@ -39,7 +40,7 @@ public class WidgetSettings {
|
||||
final JsonElement s = data.get("settings");
|
||||
if (s != null && s.isJsonObject()){
|
||||
final JsonObject savedSettings = s.getAsJsonObject();
|
||||
for (WidgetSettingOption setting : this.customSettings) {
|
||||
for (WidgetSettingOption<?> setting : this.customSettings) {
|
||||
final String settingId = setting.getId();
|
||||
if (savedSettings.has(settingId)){
|
||||
try {
|
||||
@@ -56,7 +57,7 @@ public class WidgetSettings {
|
||||
}
|
||||
}
|
||||
}
|
||||
public static WidgetSettings ofId(Identifier id, List<WidgetSettingOption> customSettings){
|
||||
public static WidgetSettings ofId(Identifier id, List<WidgetSettingOption<?>> customSettings){
|
||||
final JsonObject data = WidgetManager.loadWidget(id);
|
||||
return new WidgetSettings(data, customSettings);
|
||||
}
|
||||
@@ -92,7 +93,7 @@ public class WidgetSettings {
|
||||
object.add("oy", gson.toJsonTree(this.offsetY));
|
||||
|
||||
JsonObject customSettings = new JsonObject();
|
||||
for (WidgetSettingOption customSetting : this.customSettings) {
|
||||
for (WidgetSettingOption<?> customSetting : this.customSettings) {
|
||||
customSettings.add(customSetting.getId(), customSetting.saveState());
|
||||
}
|
||||
object.add("settings", customSettings);
|
||||
@@ -100,8 +101,8 @@ public class WidgetSettings {
|
||||
return object;
|
||||
}
|
||||
|
||||
public WidgetSettingOption optionById(String id){
|
||||
for (WidgetSettingOption customSetting : customSettings) {
|
||||
public WidgetSettingOption<?> optionById(String id){
|
||||
for (WidgetSettingOption<?> customSetting : customSettings) {
|
||||
if (customSetting.getId().equals(id)){
|
||||
return customSetting;
|
||||
}
|
||||
@@ -109,7 +110,7 @@ public class WidgetSettings {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ObjectArrayList<WidgetSettingOption> getCustomSettings() {
|
||||
public ObjectArrayList<WidgetSettingOption<?>> getCustomSettings() {
|
||||
return customSettings.clone();
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,7 +1,7 @@
|
||||
package de.shiewk.widgets.client.screen.components;
|
||||
|
||||
import de.shiewk.widgets.ModWidget;
|
||||
import de.shiewk.widgets.WidgetSettingOption;
|
||||
import de.shiewk.widgets.widgets.settings.WidgetSettingOption;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
@@ -19,7 +19,7 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
||||
private final TextRenderer textRenderer;
|
||||
private final ModWidget widget;
|
||||
private final Runnable onChange;
|
||||
private WidgetSettingOption focus = null;
|
||||
private WidgetSettingOption<?> focus = null;
|
||||
private int contentsHeight = 10;
|
||||
|
||||
public WidgetSettingsEditWidget(int x, int y, int width, int height, TextRenderer textRenderer, ModWidget widget, Runnable onChange) {
|
||||
@@ -27,7 +27,7 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
||||
this.widget = widget;
|
||||
this.textRenderer = textRenderer;
|
||||
this.onChange = onChange;
|
||||
for (WidgetSettingOption customSetting : widget.getSettings().getCustomSettings()) {
|
||||
for (WidgetSettingOption<?> customSetting : widget.getSettings().getCustomSettings()) {
|
||||
customSetting.setFocused(false);
|
||||
}
|
||||
setWidth(width);
|
||||
@@ -36,7 +36,7 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
||||
|
||||
@Override
|
||||
public void setWidth(int width) {
|
||||
for (WidgetSettingOption setting : widget.getSettings().getCustomSettings()) {
|
||||
for (WidgetSettingOption<?> setting : widget.getSettings().getCustomSettings()) {
|
||||
setting.setMaxRenderWidth(width - 10);
|
||||
}
|
||||
super.setWidth(width);
|
||||
@@ -63,7 +63,7 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
||||
context.drawText(textRenderer, widget.getName(), this.width / 4 - textRenderer.getWidth(widget.getName()) / 2, this.height / 100, COLOR_FG, true);
|
||||
matrices.popMatrix();
|
||||
int y = textRenderer.fontHeight * 2 + this.height / 50 + 5;
|
||||
for (WidgetSettingOption setting : widget.getSettings().getCustomSettings()) {
|
||||
for (WidgetSettingOption<?> setting : widget.getSettings().getCustomSettings()) {
|
||||
if (!setting.shouldShow()) continue;
|
||||
if (this.width - setting.getWidth() > textRenderer.getWidth(setting.getName()) + 20){
|
||||
setting.setX(this.getX() + this.width - setting.getWidth() - 5);
|
||||
@@ -88,7 +88,7 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
||||
double mouseY = click.y();
|
||||
double mouseX = click.x();
|
||||
mouseY += getScrollY();
|
||||
for (WidgetSettingOption customSetting : widget.getSettings().getCustomSettings()) {
|
||||
for (WidgetSettingOption<?> customSetting : widget.getSettings().getCustomSettings()) {
|
||||
if (!customSetting.shouldShow()) continue;
|
||||
if (customSetting.isHovered(mouseX, mouseY)){
|
||||
focus = customSetting;
|
||||
@@ -106,7 +106,7 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(Click click) {
|
||||
for (WidgetSettingOption customSetting : widget.getSettings().getCustomSettings()) {
|
||||
for (WidgetSettingOption<?> customSetting : widget.getSettings().getCustomSettings()) {
|
||||
if (!customSetting.shouldShow()) continue;
|
||||
if (customSetting.mouseReleased(new Click(click.x(), click.y() + getScrollY(), click.buttonInfo()))){
|
||||
onChange.run();
|
||||
|
||||
@@ -153,14 +153,14 @@ public class ArmorHudWidget extends ResizableWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.padding = ((IntSliderWidgetSetting) settings.optionById("padding")).getValue();
|
||||
this.showDurability = ((ToggleWidgetSetting) settings.optionById("show_durability")).getValue();
|
||||
this.durabilityStyle = (DurabilityStyle) ((EnumWidgetSetting<?>) settings.optionById("durability_style")).getValue();
|
||||
this.rainbow = ((ToggleWidgetSetting) settings.optionById("rainbow")).getValue();
|
||||
this.rainbowSpeed = ((IntSliderWidgetSetting) settings.optionById("rainbow_speed")).getValue();
|
||||
this.textColor = ((RGBAColorWidgetSetting) settings.optionById("textcolor")).getColor();
|
||||
this.backgroundColor = ((RGBAColorWidgetSetting) settings.optionById("backgroundcolor")).getColor();
|
||||
this.preferredWidth = ((IntSliderWidgetSetting) settings.optionById("width")).getValue();
|
||||
this.textAlignment = (BasicTextWidget.TextAlignment) ((EnumWidgetSetting<?>) settings.optionById("alignment")).getValue();
|
||||
this.padding = (int) settings.optionById("padding").getValue();
|
||||
this.showDurability = (boolean) settings.optionById("show_durability").getValue();
|
||||
this.durabilityStyle = (DurabilityStyle) settings.optionById("durability_style").getValue();
|
||||
this.rainbow = (boolean) settings.optionById("rainbow").getValue();
|
||||
this.rainbowSpeed = (int) settings.optionById("rainbow_speed").getValue();
|
||||
this.textColor = (int) settings.optionById("textcolor").getValue();
|
||||
this.backgroundColor = (int) settings.optionById("backgroundcolor").getValue();
|
||||
this.preferredWidth = (int) settings.optionById("width").getValue();
|
||||
this.textAlignment = (BasicTextWidget.TextAlignment) settings.optionById("alignment").getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,10 +100,10 @@ public class BandwidthWidget extends BasicTextWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.dynamicColor = ((ToggleWidgetSetting) settings.optionById("dynamic_color")).getValue();
|
||||
this.hideInSingleplayer = ((ToggleWidgetSetting) settings.optionById("hide_in_singleplayer")).getValue();
|
||||
this.unit = (Unit) ((EnumWidgetSetting<?>) settings.optionById("unit")).getValue();
|
||||
this.fastUpdate = ((ToggleWidgetSetting) settings.optionById("fastupdate")).getValue();
|
||||
this.dynamicColor = (boolean) settings.optionById("dynamic_color").getValue();
|
||||
this.hideInSingleplayer = (boolean) settings.optionById("hide_in_singleplayer").getValue();
|
||||
this.unit = (Unit) settings.optionById("unit").getValue();
|
||||
this.fastUpdate = (boolean) settings.optionById("fastupdate").getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package de.shiewk.widgets.widgets;
|
||||
|
||||
import de.shiewk.widgets.WidgetSettingOption;
|
||||
import de.shiewk.widgets.widgets.settings.WidgetSettingOption;
|
||||
import de.shiewk.widgets.WidgetSettings;
|
||||
import de.shiewk.widgets.client.WidgetRenderer;
|
||||
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
||||
@@ -70,8 +70,8 @@ public abstract class BasicTextWidget extends ResizableWidget {
|
||||
protected boolean rainbow = false;
|
||||
private int rainbowSpeed = 3;
|
||||
|
||||
private static ObjectArrayList<WidgetSettingOption> getCustomSettings(List<WidgetSettingOption> otherCustomOptions) {
|
||||
final ObjectArrayList<WidgetSettingOption> list = new ObjectArrayList<>(otherCustomOptions);
|
||||
private static ObjectArrayList<WidgetSettingOption<?>> getCustomSettings(List<WidgetSettingOption<?>> otherCustomOptions) {
|
||||
final ObjectArrayList<WidgetSettingOption<?>> list = new ObjectArrayList<>(otherCustomOptions);
|
||||
list.add(new RGBAColorWidgetSetting("backgroundcolor", translatable("widgets.widgets.basictext.background"), 0, 0, 0, 80));
|
||||
list.add(new ToggleWidgetSetting("rainbow", translatable("widgets.widgets.common.rainbow"), false));
|
||||
list.add(new RGBAColorWidgetSetting("textcolor", translatable("widgets.widgets.basictext.textcolor"), 255, 255, 255, 255));
|
||||
@@ -84,7 +84,7 @@ public abstract class BasicTextWidget extends ResizableWidget {
|
||||
list.add(new EnumWidgetSetting<>("text_style", translatable("widgets.widgets.basictext.textstyle"), TextStyle.class, TextStyle.PLAIN, TextStyle::displayText));
|
||||
return list;
|
||||
}
|
||||
protected BasicTextWidget(Identifier id, List<WidgetSettingOption> otherCustomOptions) {
|
||||
protected BasicTextWidget(Identifier id, List<WidgetSettingOption<?>> otherCustomOptions) {
|
||||
super(id, getCustomSettings(otherCustomOptions));
|
||||
getSettings().optionById("padding").setShowCondition(() -> this.textAlignment != TextAlignment.CENTER);
|
||||
getSettings().optionById("textcolor").setShowCondition(() -> !this.rainbow);
|
||||
@@ -165,15 +165,15 @@ public abstract class BasicTextWidget extends ResizableWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.backgroundColor = ((RGBAColorWidgetSetting) settings.optionById("backgroundcolor")).getColor();
|
||||
this.textColor = ((RGBAColorWidgetSetting) settings.optionById("textcolor")).getColor();
|
||||
this.width = ((IntSliderWidgetSetting) settings.optionById("width")).getValue();
|
||||
this.height = ((IntSliderWidgetSetting) settings.optionById("height")).getValue();
|
||||
this.textAlignment = (TextAlignment) ((EnumWidgetSetting<?>) settings.optionById("alignment")).getValue();
|
||||
this.padding = ((IntSliderWidgetSetting) settings.optionById("padding")).getValue();
|
||||
this.textShadow = ((ToggleWidgetSetting) settings.optionById("shadow")).getValue();
|
||||
this.textStyle = (TextStyle) ((EnumWidgetSetting<?>) settings.optionById("text_style")).getValue();
|
||||
this.rainbow = ((ToggleWidgetSetting) settings.optionById("rainbow")).getValue();
|
||||
this.rainbowSpeed = ((IntSliderWidgetSetting) settings.optionById("rainbow_speed")).getValue();
|
||||
this.backgroundColor = (int) settings.optionById("backgroundcolor").getValue();
|
||||
this.textColor = (int) settings.optionById("textcolor").getValue();
|
||||
this.width = (int) settings.optionById("width").getValue();
|
||||
this.height = (int) settings.optionById("height").getValue();
|
||||
this.textAlignment = (TextAlignment) settings.optionById("alignment").getValue();
|
||||
this.padding = (int) settings.optionById("padding").getValue();
|
||||
this.textShadow = (boolean) settings.optionById("shadow").getValue();
|
||||
this.textStyle = (TextStyle) settings.optionById("text_style").getValue();
|
||||
this.rainbow = (boolean) settings.optionById("rainbow").getValue();
|
||||
this.rainbowSpeed = (int) settings.optionById("rainbow_speed").getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,6 @@ public class BiomeWidget extends BasicTextWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.showLabel = ((ToggleWidgetSetting) settings.optionById("show_label")).getValue();
|
||||
this.showLabel = (boolean) settings.optionById("show_label").getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,17 +141,17 @@ public class CPSWidget extends BasicTextWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
countLeftClicks = ((ToggleWidgetSetting) settings.optionById("left")).getValue();
|
||||
countMiddleClicks = ((ToggleWidgetSetting) settings.optionById("middle")).getValue();
|
||||
countRightClicks = ((ToggleWidgetSetting) settings.optionById("right")).getValue();
|
||||
appearance = (Appearance) ((EnumWidgetSetting<?>) settings.optionById("appearance")).getValue();
|
||||
showLabel = ((ToggleWidgetSetting) settings.optionById("show_label")).getValue();
|
||||
countLeftClicks = (boolean) settings.optionById("left").getValue();
|
||||
countMiddleClicks = (boolean) settings.optionById("middle").getValue();
|
||||
countRightClicks = (boolean) settings.optionById("right").getValue();
|
||||
appearance = (Appearance) settings.optionById("appearance").getValue();
|
||||
showLabel = (boolean) settings.optionById("show_label").getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getName() {
|
||||
return translatable("widgets.widgets.cps");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDescription() {
|
||||
|
||||
@@ -104,10 +104,10 @@ public class ClockWidget extends BasicTextWidget {
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
String datePattern = "HH:mm:ss";
|
||||
TimeOption timeOption = (TimeOption) ((EnumWidgetSetting<?>) settings.optionById("hour_format")).getValue();
|
||||
DateOption dateOption = (DateOption) ((EnumWidgetSetting<?>) settings.optionById("date_format")).getValue();
|
||||
WeekOption weekOption = (WeekOption) ((EnumWidgetSetting<?>) settings.optionById("week_format")).getValue();
|
||||
boolean showSeconds = ((ToggleWidgetSetting) settings.optionById("show_seconds")).getValue();
|
||||
TimeOption timeOption = (TimeOption) settings.optionById("hour_format").getValue();
|
||||
DateOption dateOption = (DateOption) settings.optionById("date_format").getValue();
|
||||
WeekOption weekOption = (WeekOption) settings.optionById("week_format").getValue();
|
||||
boolean showSeconds = (boolean) settings.optionById("show_seconds").getValue();
|
||||
if (timeOption == TimeOption.HOUR_24){
|
||||
datePattern = showSeconds ? "HH:mm:ss" : "HH:mm";
|
||||
} else if (timeOption == TimeOption.AM_PM){
|
||||
|
||||
@@ -106,8 +106,8 @@ public class ComboWidget extends BasicTextWidget implements AttackEntityCallback
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.displayThreshold = ((IntSliderWidgetSetting) settings.optionById("display_threshold")).getValue();
|
||||
this.showLabel = ((ToggleWidgetSetting) settings.optionById("show_label")).getValue();
|
||||
this.displayThreshold = (int) settings.optionById("display_threshold").getValue();
|
||||
this.showLabel = (boolean) settings.optionById("show_label").getValue();
|
||||
updateComboText();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,17 +107,17 @@ public class CoordinatesWidget extends ResizableWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.backgroundColor = ((RGBAColorWidgetSetting) settings.optionById("backgroundcolor")).getColor();
|
||||
this.textColor = ((RGBAColorWidgetSetting) settings.optionById("textcolor")).getColor();
|
||||
this.showX = ((ToggleWidgetSetting) settings.optionById("x")).getValue();
|
||||
this.showY = ((ToggleWidgetSetting) settings.optionById("y")).getValue();
|
||||
this.showZ = ((ToggleWidgetSetting) settings.optionById("z")).getValue();
|
||||
this.paddingX = ((IntSliderWidgetSetting) settings.optionById("paddingX")).getValue();
|
||||
this.paddingY = ((IntSliderWidgetSetting) settings.optionById("paddingY")).getValue();
|
||||
this.width = ((IntSliderWidgetSetting) settings.optionById("width")).getValue();
|
||||
this.shadow = ((ToggleWidgetSetting) settings.optionById("shadow")).getValue();
|
||||
this.rainbow = ((ToggleWidgetSetting) settings.optionById("rainbow")).getValue();
|
||||
this.rainbowSpeed = ((IntSliderWidgetSetting) settings.optionById("rainbow_speed")).getValue();
|
||||
this.backgroundColor = (int) settings.optionById("backgroundcolor").getValue();
|
||||
this.textColor = (int) settings.optionById("textcolor").getValue();
|
||||
this.showX = (boolean) settings.optionById("x").getValue();
|
||||
this.showY = (boolean) settings.optionById("y").getValue();
|
||||
this.showZ = (boolean) settings.optionById("z").getValue();
|
||||
this.paddingX = (int) settings.optionById("paddingX").getValue();
|
||||
this.paddingY = (int) settings.optionById("paddingY").getValue();
|
||||
this.width = (int) settings.optionById("width").getValue();
|
||||
this.shadow = (boolean) settings.optionById("shadow").getValue();
|
||||
this.rainbow = (boolean) settings.optionById("rainbow").getValue();
|
||||
this.rainbowSpeed = (int) settings.optionById("rainbow_speed").getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -57,7 +57,7 @@ public class FPSWidget extends BasicTextWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.realtime = ((ToggleWidgetSetting) settings.optionById("realtime")).getValue();
|
||||
this.realtime = (boolean) settings.optionById("realtime").getValue();
|
||||
|
||||
timedFrames = this.realtime ? new LinkedList<>() : null;
|
||||
}
|
||||
|
||||
@@ -205,15 +205,15 @@ public class InventoryWidget extends ResizableWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.mode = ((InventoryMode) ((EnumWidgetSetting<?>) settings.optionById("mode")).getValue());
|
||||
this.rainbowGrid = ((ToggleWidgetSetting) settings.optionById("rainbow_grid")).getValue();
|
||||
this.gridRainbowSpeed = ((IntSliderWidgetSetting) settings.optionById("grid_rainbow_speed")).getValue();
|
||||
this.gridColor = ((RGBAColorWidgetSetting) settings.optionById("grid_color")).getColor();
|
||||
this.mode = (InventoryMode) settings.optionById("mode").getValue();
|
||||
this.rainbowGrid = (boolean) settings.optionById("rainbow_grid").getValue();
|
||||
this.gridRainbowSpeed = (int) settings.optionById("grid_rainbow_speed").getValue();
|
||||
this.gridColor = (int) settings.optionById("grid_color").getValue();
|
||||
|
||||
this.rainbowBoxes = ((ToggleWidgetSetting) settings.optionById("rainbow_boxes")).getValue();
|
||||
this.boxRainbowSpeed = ((IntSliderWidgetSetting) settings.optionById("box_rainbow_speed")).getValue();
|
||||
this.boxColor = ((RGBAColorWidgetSetting) settings.optionById("box_color")).getColor();
|
||||
this.rainbowBoxes = (boolean) settings.optionById("rainbow_boxes").getValue();
|
||||
this.boxRainbowSpeed = (int) settings.optionById("box_rainbow_speed").getValue();
|
||||
this.boxColor = (int) settings.optionById("box_color").getValue();
|
||||
|
||||
this.showHotbar = ((ToggleWidgetSetting) settings.optionById("show_hotbar")).getValue() || !mode.canDisableHotbar;
|
||||
this.showHotbar = (boolean) settings.optionById("show_hotbar").getValue() || !mode.canDisableHotbar;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,18 +35,6 @@ public class KeyStrokesWidget extends ResizableWidget {
|
||||
getSettings().optionById("rainbow_speed").setShowCondition(() -> this.rainbow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.showJumpKey = ((ToggleWidgetSetting) settings.optionById("showjump")).getValue();
|
||||
this.colorBackgroundPressed = ((RGBAColorWidgetSetting) settings.optionById("bgpressed")).getColor();
|
||||
this.colorBackgroundUnpressed = ((RGBAColorWidgetSetting) settings.optionById("bgunpressed")).getColor();
|
||||
this.colorKeyPressed = ((RGBAColorWidgetSetting) settings.optionById("keypressed")).getColor();
|
||||
this.colorKeyUnpressed = ((RGBAColorWidgetSetting) settings.optionById("keyunpressed")).getColor();
|
||||
this.rainbow = ((ToggleWidgetSetting) settings.optionById("rainbow")).getValue();
|
||||
this.rainbowSpeed = ((IntSliderWidgetSetting) settings.optionById("rainbow_speed")).getValue();
|
||||
}
|
||||
|
||||
private boolean showJumpKey = true;
|
||||
|
||||
private int colorBackgroundPressed = new Color(255, 255, 255, 80).getRGB(),
|
||||
@@ -175,4 +163,16 @@ public class KeyStrokesWidget extends ResizableWidget {
|
||||
public int height() {
|
||||
return showJumpKey ? 56 : 44;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.showJumpKey = (boolean) settings.optionById("showjump").getValue();
|
||||
this.colorBackgroundPressed = (int) settings.optionById("bgpressed").getValue();
|
||||
this.colorBackgroundUnpressed = (int) settings.optionById("bgunpressed").getValue();
|
||||
this.colorKeyPressed = (int) settings.optionById("keypressed").getValue();
|
||||
this.colorKeyUnpressed = (int) settings.optionById("keyunpressed").getValue();
|
||||
this.rainbow = (boolean) settings.optionById("rainbow").getValue();
|
||||
this.rainbowSpeed = (int) settings.optionById("rainbow_speed").getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,8 +71,8 @@ public class MemoryUsageWidget extends BasicTextWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.showPercentage = ((ToggleWidgetSetting) settings.optionById("percentage")).getValue();
|
||||
this.showLabel = ((ToggleWidgetSetting) settings.optionById("label")).getValue();
|
||||
this.realtime = ((ToggleWidgetSetting) settings.optionById("realtime")).getValue();
|
||||
this.showPercentage = (boolean) settings.optionById("percentage").getValue();
|
||||
this.showLabel = (boolean) settings.optionById("label").getValue();
|
||||
this.realtime = (boolean) settings.optionById("realtime").getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ public class PingWidget extends BasicTextWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.dynamicColor = ((ToggleWidgetSetting) settings.optionById("dynamic_color")).getValue();
|
||||
this.hideInSingleplayer = ((ToggleWidgetSetting) settings.optionById("hide_in_singleplayer")).getValue();
|
||||
this.dynamicColor = (boolean) settings.optionById("dynamic_color").getValue();
|
||||
this.hideInSingleplayer = (boolean) settings.optionById("hide_in_singleplayer").getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,6 +32,6 @@ public class PlainTextWidget extends BasicTextWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
formatAndSetRenderText(literal(((TextFieldWidgetSettingOption) settings.optionById("text")).getValue()));
|
||||
formatAndSetRenderText(literal((String) settings.optionById("text").getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,6 @@ public class PlayTimeWidget extends BasicTextWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.labelStyle = (LabelStyle) ((EnumWidgetSetting<?>) settings.optionById("labelstyle")).getValue();
|
||||
this.labelStyle = (LabelStyle) settings.optionById("labelstyle").getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ public class PlayerCountWidget extends BasicTextWidget{
|
||||
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
showLabel = ((ToggleWidgetSetting) settings.optionById("showlabel")).getValue();
|
||||
hideInSingleplayer = ((ToggleWidgetSetting) settings.optionById("hide_in_singleplayer")).getValue();
|
||||
showLabel = (boolean) settings.optionById("showlabel").getValue();
|
||||
hideInSingleplayer = (boolean) settings.optionById("hide_in_singleplayer").getValue();
|
||||
super.onSettingsChanged(settings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.shiewk.widgets.widgets;
|
||||
|
||||
import de.shiewk.widgets.ModWidget;
|
||||
import de.shiewk.widgets.WidgetSettingOption;
|
||||
import de.shiewk.widgets.widgets.settings.WidgetSettingOption;
|
||||
import de.shiewk.widgets.WidgetSettings;
|
||||
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
@@ -15,12 +15,12 @@ import java.util.List;
|
||||
|
||||
public abstract class ResizableWidget extends ModWidget {
|
||||
|
||||
protected ResizableWidget(Identifier id, List<WidgetSettingOption> customSettings) {
|
||||
protected ResizableWidget(Identifier id, List<WidgetSettingOption<?>> customSettings) {
|
||||
super(id, addScaleSetting(customSettings));
|
||||
}
|
||||
|
||||
private static List<WidgetSettingOption> addScaleSetting(List<WidgetSettingOption> target) {
|
||||
ArrayList<WidgetSettingOption> settings = new ArrayList<>(target);
|
||||
private static List<WidgetSettingOption<?>> addScaleSetting(List<WidgetSettingOption<?>> target) {
|
||||
ArrayList<WidgetSettingOption<?>> settings = new ArrayList<>(target);
|
||||
settings.add(new IntSliderWidgetSetting("size", Text.translatable("widgets.widgets.common.sizePercent"), 25, 100, 400));
|
||||
return settings;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public abstract class ResizableWidget extends ModWidget {
|
||||
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
this.size = 0.01f * ((IntSliderWidgetSetting) settings.optionById("size")).getValue();
|
||||
this.size = 0.01f * (int) settings.optionById("size").getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ServerIPWidget extends BasicTextWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.dynamicWidth = ((ToggleWidgetSetting) settings.optionById("dynamicwidth")).getValue();
|
||||
this.hideInSingleplayer = ((ToggleWidgetSetting) settings.optionById("hide_in_singleplayer")).getValue();
|
||||
this.dynamicWidth = (boolean) settings.optionById("dynamicwidth").getValue();
|
||||
this.hideInSingleplayer = (boolean) settings.optionById("hide_in_singleplayer").getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,12 +104,12 @@ public class SpeedWidget extends BasicTextWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.unit = ((Unit) ((EnumWidgetSetting<?>) settings.optionById("unit")).getValue());
|
||||
this.withXVelocity = ((ToggleWidgetSetting) settings.optionById("with_x")).getValue();
|
||||
this.withYVelocity = ((ToggleWidgetSetting) settings.optionById("with_y")).getValue();
|
||||
this.withZVelocity = ((ToggleWidgetSetting) settings.optionById("with_z")).getValue();
|
||||
this.digitsAfterComma = ((IntSliderWidgetSetting) settings.optionById("digits")).getValue();
|
||||
this.unit = (Unit) settings.optionById("unit").getValue();
|
||||
this.withXVelocity = (boolean) settings.optionById("with_x").getValue();
|
||||
this.withYVelocity = (boolean) settings.optionById("with_y").getValue();
|
||||
this.withZVelocity = (boolean) settings.optionById("with_z").getValue();
|
||||
this.digitsAfterComma = (int) settings.optionById("digits").getValue();
|
||||
this.windowPointer = 0;
|
||||
this.averagingWindow = new double[((IntSliderWidgetSetting) settings.optionById("window_size")).getValue()];
|
||||
this.averagingWindow = new double[(int) settings.optionById("window_size").getValue()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,10 +124,10 @@ public class TPSWidget extends BasicTextWidget {
|
||||
@Override
|
||||
public void onSettingsChanged(WidgetSettings settings) {
|
||||
super.onSettingsChanged(settings);
|
||||
this.dynamicColor = ((ToggleWidgetSetting) settings.optionById("dynamic_color")).getValue();
|
||||
this.showLabel = ((ToggleWidgetSetting) settings.optionById("show_label")).getValue();
|
||||
this.dynamicColor = (boolean) settings.optionById("dynamic_color").getValue();
|
||||
this.showLabel = (boolean) settings.optionById("show_label").getValue();
|
||||
|
||||
int windowSize = ((IntSliderWidgetSetting) settings.optionById("window_size")).getValue();
|
||||
int windowSize = (int) settings.optionById("window_size").getValue();
|
||||
updatePointer = 0;
|
||||
updatesSinceWorldChange = 0;
|
||||
lastUpdates = new long[windowSize];
|
||||
|
||||
@@ -2,7 +2,6 @@ package de.shiewk.widgets.widgets.settings;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import de.shiewk.widgets.WidgetSettingOption;
|
||||
import de.shiewk.widgets.utils.WidgetUtils;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
@@ -15,7 +14,7 @@ import net.minecraft.text.Text;
|
||||
import java.awt.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class EnumWidgetSetting<T extends Enum<T>> extends WidgetSettingOption {
|
||||
public class EnumWidgetSetting<T extends Enum<T>> extends WidgetSettingOption<T> {
|
||||
|
||||
private final Class<T> enumClass;
|
||||
private T value;
|
||||
@@ -31,6 +30,7 @@ public class EnumWidgetSetting<T extends Enum<T>> extends WidgetSettingOption {
|
||||
this.enumNameGetter = enumNameGetter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getValue(){
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package de.shiewk.widgets.widgets.settings;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import de.shiewk.widgets.WidgetSettingOption;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.Click;
|
||||
@@ -11,8 +10,9 @@ import net.minecraft.client.gui.cursor.StandardCursors;
|
||||
import net.minecraft.client.input.KeyInput;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class IntSliderWidgetSetting extends WidgetSettingOption {
|
||||
public class IntSliderWidgetSetting extends WidgetSettingOption<Integer> {
|
||||
|
||||
private int value;
|
||||
private int minValue;
|
||||
@@ -98,7 +98,8 @@ public class IntSliderWidgetSetting extends WidgetSettingOption {
|
||||
return t;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
@Override
|
||||
public @NotNull Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package de.shiewk.widgets.widgets.settings;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import de.shiewk.widgets.WidgetSettingOption;
|
||||
import de.shiewk.widgets.utils.WidgetUtils;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
@@ -16,10 +15,11 @@ import net.minecraft.client.input.KeyInput;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class RGBAColorWidgetSetting extends WidgetSettingOption {
|
||||
public class RGBAColorWidgetSetting extends WidgetSettingOption<Integer> {
|
||||
public RGBAColorWidgetSetting(String id, Text name, int defaultR, int defaultG, int defaultB, int defaultAlpha) {
|
||||
super(id, name);
|
||||
this.r = defaultR;
|
||||
@@ -42,6 +42,11 @@ public class RGBAColorWidgetSetting extends WidgetSettingOption {
|
||||
return a << 24 | r << 16 | g << 8 | b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Integer getValue(){
|
||||
return getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(JsonElement state) {
|
||||
if (state.isJsonPrimitive() && state.getAsJsonPrimitive().isNumber()){
|
||||
|
||||
@@ -2,7 +2,6 @@ package de.shiewk.widgets.widgets.settings;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import de.shiewk.widgets.WidgetSettingOption;
|
||||
import de.shiewk.widgets.WidgetsMod;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
@@ -13,7 +12,7 @@ import net.minecraft.client.input.CharInput;
|
||||
import net.minecraft.client.input.KeyInput;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class TextFieldWidgetSettingOption extends WidgetSettingOption {
|
||||
public class TextFieldWidgetSettingOption extends WidgetSettingOption<String> {
|
||||
|
||||
private TextField textField = null;
|
||||
private final Text initialValue;
|
||||
@@ -55,6 +54,7 @@ public class TextFieldWidgetSettingOption extends WidgetSettingOption {
|
||||
textField.setText(value.isEmpty() ? initialValue.getString() : value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(){
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package de.shiewk.widgets.widgets.settings;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import de.shiewk.widgets.WidgetSettingOption;
|
||||
import de.shiewk.widgets.utils.WidgetUtils;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
@@ -11,10 +10,11 @@ import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ToggleWidgetSetting extends WidgetSettingOption {
|
||||
public class ToggleWidgetSetting extends WidgetSettingOption<Boolean> {
|
||||
|
||||
private boolean value;
|
||||
private long toggleTime = 0;
|
||||
@@ -24,7 +24,8 @@ public class ToggleWidgetSetting extends WidgetSettingOption {
|
||||
this.value = defaultValue;
|
||||
}
|
||||
|
||||
public boolean getValue(){
|
||||
@Override
|
||||
public @NotNull Boolean getValue(){
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -1,4 +1,4 @@
|
||||
package de.shiewk.widgets;
|
||||
package de.shiewk.widgets.widgets.settings;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import de.shiewk.widgets.utils.WidgetUtils;
|
||||
@@ -13,7 +13,7 @@ import net.minecraft.text.Text;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class WidgetSettingOption implements Drawable, Widget {
|
||||
public abstract class WidgetSettingOption<T> implements Drawable, Widget {
|
||||
private final String id;
|
||||
private final Text name;
|
||||
private int x = 0;
|
||||
@@ -45,6 +45,7 @@ public abstract class WidgetSettingOption implements Drawable, Widget {
|
||||
|
||||
public abstract JsonElement saveState();
|
||||
public abstract void loadState(JsonElement state);
|
||||
public abstract T getValue();
|
||||
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
return false;
|
||||
@@ -108,7 +109,7 @@ public abstract class WidgetSettingOption implements Drawable, Widget {
|
||||
return shouldShow.getAsBoolean();
|
||||
}
|
||||
|
||||
public WidgetSettingOption setShowCondition(BooleanSupplier shouldShow){
|
||||
public WidgetSettingOption<?> setShowCondition(BooleanSupplier shouldShow){
|
||||
this.shouldShow = shouldShow;
|
||||
return this;
|
||||
}
|
||||
Reference in New Issue
Block a user