瀏覽代碼

Add test list in example config

Mitchell Skaggs 5 年之前
父節點
當前提交
e6d95c4e40
共有 1 個文件被更改,包括 45 次插入40 次删除
  1. 45 40
      src/main/java/me/shedaniel/clothconfig2/ClothConfigInitializer.java

+ 45 - 40
src/main/java/me/shedaniel/clothconfig2/ClothConfigInitializer.java

@@ -36,15 +36,14 @@ import java.nio.file.Files;
 import java.util.*;
 import java.util.stream.Collectors;
 
-@SuppressWarnings("unchecked")
 public class ClothConfigInitializer implements ClientModInitializer {
-    
+
     public static final Logger LOGGER = LogManager.getFormatterLogger("ClothConfig");
     private static EasingMethod easingMethod = EasingMethodImpl.LINEAR;
     private static long scrollDuration = 600;
     private static double scrollStep = 19;
     private static double bounceBackMultiplier = .24;
-    
+
     public static double handleScrollingPosition(double[] target, double scroll, double maxScroll, float delta, double start, double duration) {
         if (getBounceBackMultiplier() >= 0) {
             target[0] = clamp(target[0], maxScroll);
@@ -60,51 +59,39 @@ public class ClothConfigInitializer implements ClientModInitializer {
         else
             return target[0];
     }
-    
+
     public static double expoEase(double start, double end, double 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) {
         return clamp(v, maxScroll, DynamicEntryListWidget.SmoothScrollingSettings.CLAMP_EXTENSION);
     }
-    
+
     public static double clamp(double v, double maxScroll, double clampExtension) {
         return MathHelper.clamp(v, -clampExtension, maxScroll + clampExtension);
     }
-    
+
     public static EasingMethod getEasingMethod() {
         return easingMethod;
     }
-    
+
     public static long getScrollDuration() {
         return scrollDuration;
     }
-    
+
     public static double getScrollStep() {
         return scrollStep;
     }
-    
+
     public static double getBounceBackMultiplier() {
         return bounceBackMultiplier;
     }
-    
+
     private static void loadConfig() {
         File file = new File(FabricLoader.getInstance().getConfigDirectory(), "cloth-config2/config.properties");
         try {
+            //noinspection ResultOfMethodCallIgnored
             file.getParentFile().mkdirs();
             easingMethod = EasingMethodImpl.LINEAR;
             scrollDuration = 600;
@@ -138,7 +125,7 @@ public class ClothConfigInitializer implements ClientModInitializer {
         }
         saveConfig();
     }
-    
+
     private static void saveConfig() {
         File file = new File(FabricLoader.getInstance().getConfigDirectory(), "cloth-config2/config.properties");
         try {
@@ -158,7 +145,7 @@ public class ClothConfigInitializer implements ClientModInitializer {
             bounceBackMultiplier = .24;
         }
     }
-    
+
     @Override
     public void onInitializeClient() {
         loadConfig();
@@ -177,11 +164,11 @@ public class ClothConfigInitializer implements ClientModInitializer {
                                 if (m.toString().equals(str))
                                     return m;
                             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();
                         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();
-                        
+
                         scrolling.addEntry(new TooltipListEntry<Object>(I18n.translate("option.cloth-config.setDefaultSmoothScroll"), null) {
                             int width = 220;
                             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);
-                            
+
                             @Override
                             public Object getValue() {
                                 return null;
                             }
-                            
+
                             @Override
                             public Optional<Object> getDefaultValue() {
                                 return Optional.empty();
                             }
-                            
+
                             @Override
                             public void save() {
                             }
-                            
+
                             @Override
                             public List<? extends Element> children() {
                                 return children;
                             }
-                            
+
                             @Override
                             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);
@@ -226,7 +213,7 @@ public class ClothConfigInitializer implements ClientModInitializer {
                                 this.buttonWidget.render(mouseX, mouseY, delta);
                             }
                         });
-                        
+
                         scrolling.addEntry(new TooltipListEntry<Object>(I18n.translate("option.cloth-config.disableSmoothScroll"), null) {
                             int width = 220;
                             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);
-                            
+
                             @Override
                             public Object getValue() {
                                 return null;
                             }
-                            
+
                             @Override
                             public Optional<Object> getDefaultValue() {
                                 return Optional.empty();
                             }
-                            
+
                             @Override
                             public void save() {
                             }
-                            
+
                             @Override
                             public List<? extends Element> children() {
                                 return children;
                             }
-                            
+
                             @Override
                             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);
@@ -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.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.startDoubleList("A list of Doubles", new ArrayList<>())
+                                        .setDefaultValue(Arrays.asList(1.0, 2.0))
+                                        .build()
+                        );
                         builder.setSavingRunnable(ClothConfigInitializer::saveConfig);
                         builder.transparentBackground();
                         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;
+        }
+    }
+
 }