|
@@ -36,15 +36,14 @@ import java.nio.file.Files;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-@SuppressWarnings("unchecked")
|
|
|
|
public class ClothConfigInitializer implements ClientModInitializer {
|
|
public class ClothConfigInitializer implements ClientModInitializer {
|
|
-
|
|
|
|
|
|
+
|
|
public static final Logger LOGGER = LogManager.getFormatterLogger("ClothConfig");
|
|
public static final Logger LOGGER = LogManager.getFormatterLogger("ClothConfig");
|
|
private static EasingMethod easingMethod = EasingMethodImpl.LINEAR;
|
|
private static EasingMethod easingMethod = EasingMethodImpl.LINEAR;
|
|
private static long scrollDuration = 600;
|
|
private static long scrollDuration = 600;
|
|
private static double scrollStep = 19;
|
|
private static double scrollStep = 19;
|
|
private static double bounceBackMultiplier = .24;
|
|
private static double bounceBackMultiplier = .24;
|
|
-
|
|
|
|
|
|
+
|
|
public static double handleScrollingPosition(double[] target, double scroll, double maxScroll, float delta, double start, double duration) {
|
|
public static double handleScrollingPosition(double[] target, double scroll, double maxScroll, float delta, double start, double duration) {
|
|
if (getBounceBackMultiplier() >= 0) {
|
|
if (getBounceBackMultiplier() >= 0) {
|
|
target[0] = clamp(target[0], maxScroll);
|
|
target[0] = clamp(target[0], maxScroll);
|
|
@@ -60,51 +59,39 @@ public class ClothConfigInitializer implements ClientModInitializer {
|
|
else
|
|
else
|
|
return target[0];
|
|
return target[0];
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static double expoEase(double start, double end, double amount) {
|
|
public static double expoEase(double start, double end, double amount) {
|
|
return start + (end - start) * getEasingMethod().apply(amount);
|
|
return start + (end - start) * getEasingMethod().apply(amount);
|
|
}
|
|
}
|
|
-
|
|
|
|
- public static class Precision {
|
|
|
|
- public static final float FLOAT_EPSILON = 1e-3f;
|
|
|
|
- public static final double DOUBLE_EPSILON = 1e-7;
|
|
|
|
-
|
|
|
|
- public static boolean almostEquals(float value1, float value2, float acceptableDifference) {
|
|
|
|
- return Math.abs(value1 - value2) <= acceptableDifference;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static boolean almostEquals(double value1, double value2, double acceptableDifference) {
|
|
|
|
- return Math.abs(value1 - value2) <= acceptableDifference;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+
|
|
public static double clamp(double v, double maxScroll) {
|
|
public static double clamp(double v, double maxScroll) {
|
|
return clamp(v, maxScroll, DynamicEntryListWidget.SmoothScrollingSettings.CLAMP_EXTENSION);
|
|
return clamp(v, maxScroll, DynamicEntryListWidget.SmoothScrollingSettings.CLAMP_EXTENSION);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static double clamp(double v, double maxScroll, double clampExtension) {
|
|
public static double clamp(double v, double maxScroll, double clampExtension) {
|
|
return MathHelper.clamp(v, -clampExtension, maxScroll + clampExtension);
|
|
return MathHelper.clamp(v, -clampExtension, maxScroll + clampExtension);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static EasingMethod getEasingMethod() {
|
|
public static EasingMethod getEasingMethod() {
|
|
return easingMethod;
|
|
return easingMethod;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static long getScrollDuration() {
|
|
public static long getScrollDuration() {
|
|
return scrollDuration;
|
|
return scrollDuration;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static double getScrollStep() {
|
|
public static double getScrollStep() {
|
|
return scrollStep;
|
|
return scrollStep;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static double getBounceBackMultiplier() {
|
|
public static double getBounceBackMultiplier() {
|
|
return bounceBackMultiplier;
|
|
return bounceBackMultiplier;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private static void loadConfig() {
|
|
private static void loadConfig() {
|
|
File file = new File(FabricLoader.getInstance().getConfigDirectory(), "cloth-config2/config.properties");
|
|
File file = new File(FabricLoader.getInstance().getConfigDirectory(), "cloth-config2/config.properties");
|
|
try {
|
|
try {
|
|
|
|
+ //noinspection ResultOfMethodCallIgnored
|
|
file.getParentFile().mkdirs();
|
|
file.getParentFile().mkdirs();
|
|
easingMethod = EasingMethodImpl.LINEAR;
|
|
easingMethod = EasingMethodImpl.LINEAR;
|
|
scrollDuration = 600;
|
|
scrollDuration = 600;
|
|
@@ -138,7 +125,7 @@ public class ClothConfigInitializer implements ClientModInitializer {
|
|
}
|
|
}
|
|
saveConfig();
|
|
saveConfig();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private static void saveConfig() {
|
|
private static void saveConfig() {
|
|
File file = new File(FabricLoader.getInstance().getConfigDirectory(), "cloth-config2/config.properties");
|
|
File file = new File(FabricLoader.getInstance().getConfigDirectory(), "cloth-config2/config.properties");
|
|
try {
|
|
try {
|
|
@@ -158,7 +145,7 @@ public class ClothConfigInitializer implements ClientModInitializer {
|
|
bounceBackMultiplier = .24;
|
|
bounceBackMultiplier = .24;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void onInitializeClient() {
|
|
public void onInitializeClient() {
|
|
loadConfig();
|
|
loadConfig();
|
|
@@ -177,11 +164,11 @@ public class ClothConfigInitializer implements ClientModInitializer {
|
|
if (m.toString().equals(str))
|
|
if (m.toString().equals(str))
|
|
return m;
|
|
return m;
|
|
return null;
|
|
return null;
|
|
- })).setDefaultValue(EasingMethodImpl.LINEAR).setSaveConsumer(o -> easingMethod = (EasingMethod) o).setSelections(EasingMethods.getMethods()).build();
|
|
|
|
|
|
+ })).setDefaultValue(EasingMethodImpl.LINEAR).setSaveConsumer(o -> easingMethod = o).setSelections(EasingMethods.getMethods()).build();
|
|
LongSliderEntry scrollDurationEntry = entryBuilder.startLongSlider("option.cloth-config.scrollDuration", scrollDuration, 0, 5000).setTextGetter(integer -> integer <= 0 ? "Value: Disabled" : (integer > 1500 ? String.format("Value: %.1fs", integer / 1000f) : "Value: " + integer + "ms")).setDefaultValue(600).setSaveConsumer(i -> scrollDuration = i).build();
|
|
LongSliderEntry scrollDurationEntry = entryBuilder.startLongSlider("option.cloth-config.scrollDuration", scrollDuration, 0, 5000).setTextGetter(integer -> integer <= 0 ? "Value: Disabled" : (integer > 1500 ? String.format("Value: %.1fs", integer / 1000f) : "Value: " + integer + "ms")).setDefaultValue(600).setSaveConsumer(i -> scrollDuration = i).build();
|
|
DoubleListEntry scrollStepEntry = entryBuilder.startDoubleField("option.cloth-config.scrollStep", scrollStep).setDefaultValue(19).setSaveConsumer(i -> scrollStep = i).build();
|
|
DoubleListEntry scrollStepEntry = entryBuilder.startDoubleField("option.cloth-config.scrollStep", scrollStep).setDefaultValue(19).setSaveConsumer(i -> scrollStep = i).build();
|
|
LongSliderEntry bounceMultiplierEntry = entryBuilder.startLongSlider("option.cloth-config.bounceBackMultiplier", (long) (bounceBackMultiplier * 1000), -10, 750).setTextGetter(integer -> integer < 0 ? "Value: Disabled" : String.format("Value: %s", integer / 1000d)).setDefaultValue(240).setSaveConsumer(i -> bounceBackMultiplier = i / 1000d).build();
|
|
LongSliderEntry bounceMultiplierEntry = entryBuilder.startLongSlider("option.cloth-config.bounceBackMultiplier", (long) (bounceBackMultiplier * 1000), -10, 750).setTextGetter(integer -> integer < 0 ? "Value: Disabled" : String.format("Value: %s", integer / 1000d)).setDefaultValue(240).setSaveConsumer(i -> bounceBackMultiplier = i / 1000d).build();
|
|
-
|
|
|
|
|
|
+
|
|
scrolling.addEntry(new TooltipListEntry<Object>(I18n.translate("option.cloth-config.setDefaultSmoothScroll"), null) {
|
|
scrolling.addEntry(new TooltipListEntry<Object>(I18n.translate("option.cloth-config.setDefaultSmoothScroll"), null) {
|
|
int width = 220;
|
|
int width = 220;
|
|
private AbstractButtonWidget buttonWidget = new AbstractPressableButtonWidget(0, 0, 0, 20, getFieldName()) {
|
|
private AbstractButtonWidget buttonWidget = new AbstractPressableButtonWidget(0, 0, 0, 20, getFieldName()) {
|
|
@@ -195,26 +182,26 @@ public class ClothConfigInitializer implements ClientModInitializer {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
private List<AbstractButtonWidget> children = ImmutableList.of(buttonWidget);
|
|
private List<AbstractButtonWidget> children = ImmutableList.of(buttonWidget);
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Object getValue() {
|
|
public Object getValue() {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Optional<Object> getDefaultValue() {
|
|
public Optional<Object> getDefaultValue() {
|
|
return Optional.empty();
|
|
return Optional.empty();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void save() {
|
|
public void save() {
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<? extends Element> children() {
|
|
public List<? extends Element> children() {
|
|
return children;
|
|
return children;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void render(int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) {
|
|
public void render(int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) {
|
|
super.render(index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta);
|
|
super.render(index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta);
|
|
@@ -226,7 +213,7 @@ public class ClothConfigInitializer implements ClientModInitializer {
|
|
this.buttonWidget.render(mouseX, mouseY, delta);
|
|
this.buttonWidget.render(mouseX, mouseY, delta);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
scrolling.addEntry(new TooltipListEntry<Object>(I18n.translate("option.cloth-config.disableSmoothScroll"), null) {
|
|
scrolling.addEntry(new TooltipListEntry<Object>(I18n.translate("option.cloth-config.disableSmoothScroll"), null) {
|
|
int width = 220;
|
|
int width = 220;
|
|
private AbstractButtonWidget buttonWidget = new AbstractPressableButtonWidget(0, 0, 0, 20, getFieldName()) {
|
|
private AbstractButtonWidget buttonWidget = new AbstractPressableButtonWidget(0, 0, 0, 20, getFieldName()) {
|
|
@@ -240,26 +227,26 @@ public class ClothConfigInitializer implements ClientModInitializer {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
private List<AbstractButtonWidget> children = ImmutableList.of(buttonWidget);
|
|
private List<AbstractButtonWidget> children = ImmutableList.of(buttonWidget);
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Object getValue() {
|
|
public Object getValue() {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Optional<Object> getDefaultValue() {
|
|
public Optional<Object> getDefaultValue() {
|
|
return Optional.empty();
|
|
return Optional.empty();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void save() {
|
|
public void save() {
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<? extends Element> children() {
|
|
public List<? extends Element> children() {
|
|
return children;
|
|
return children;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void render(int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) {
|
|
public void render(int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) {
|
|
super.render(index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta);
|
|
super.render(index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta);
|
|
@@ -279,6 +266,11 @@ public class ClothConfigInitializer implements ClientModInitializer {
|
|
testing.addEntry(entryBuilder.startDropdownMenu("lol apple", DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(Items.APPLE), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).setDefaultValue(Items.APPLE).setSelections(Registry.ITEM.stream().sorted(Comparator.comparing(Item::toString)).collect(Collectors.toCollection(LinkedHashSet::new))).setSaveConsumer(item -> System.out.println("save this " + item)).build());
|
|
testing.addEntry(entryBuilder.startDropdownMenu("lol apple", DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(Items.APPLE), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).setDefaultValue(Items.APPLE).setSelections(Registry.ITEM.stream().sorted(Comparator.comparing(Item::toString)).collect(Collectors.toCollection(LinkedHashSet::new))).setSaveConsumer(item -> System.out.println("save this " + item)).build());
|
|
testing.addEntry(entryBuilder.startKeyCodeField("Cool Key", InputUtil.UNKNOWN_KEYCODE).setDefaultValue(InputUtil.UNKNOWN_KEYCODE).build());
|
|
testing.addEntry(entryBuilder.startKeyCodeField("Cool Key", InputUtil.UNKNOWN_KEYCODE).setDefaultValue(InputUtil.UNKNOWN_KEYCODE).build());
|
|
testing.addEntry(entryBuilder.startModifierKeyCodeField("Cool Modifier Key", ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(79), Modifier.of(false, true, false))).setDefaultValue(ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(79), Modifier.of(false, true, false))).build());
|
|
testing.addEntry(entryBuilder.startModifierKeyCodeField("Cool Modifier Key", ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(79), Modifier.of(false, true, false))).setDefaultValue(ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(79), Modifier.of(false, true, false))).build());
|
|
|
|
+ testing.addEntry(
|
|
|
|
+ entryBuilder.startDoubleList("A list of Doubles", new ArrayList<>())
|
|
|
|
+ .setDefaultValue(Arrays.asList(1.0, 2.0))
|
|
|
|
+ .build()
|
|
|
|
+ );
|
|
builder.setSavingRunnable(ClothConfigInitializer::saveConfig);
|
|
builder.setSavingRunnable(ClothConfigInitializer::saveConfig);
|
|
builder.transparentBackground();
|
|
builder.transparentBackground();
|
|
MinecraftClient.getInstance().openScreen(builder.build());
|
|
MinecraftClient.getInstance().openScreen(builder.build());
|
|
@@ -295,5 +287,18 @@ public class ClothConfigInitializer implements ClientModInitializer {
|
|
// });
|
|
// });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ public static class Precision {
|
|
|
|
+ public static final float FLOAT_EPSILON = 1e-3f;
|
|
|
|
+ public static final double DOUBLE_EPSILON = 1e-7;
|
|
|
|
+
|
|
|
|
+ public static boolean almostEquals(float value1, float value2, float acceptableDifference) {
|
|
|
|
+ return Math.abs(value1 - value2) <= acceptableDifference;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static boolean almostEquals(double value1, double value2, double acceptableDifference) {
|
|
|
|
+ return Math.abs(value1 - value2) <= acceptableDifference;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|