Jelajahi Sumber

Fix dropdown scrolling and fix restart needed

Signed-off-by: shedaniel <daniel@shedaniel.me>
shedaniel 5 tahun lalu
induk
melakukan
8daa0c3f99

+ 1 - 1
gradle.properties

@@ -3,6 +3,6 @@ minecraft_version=20w18a
 yarn_mappings=20w18a+build.1
 loader_version=0.8.2+build.194
 fabric_version=0.7.1+build.331-1.16
-mod_version=4.3.1-unstable
+mod_version=4.3.2-unstable
 modmenu_version=1.11.2+build.6
 nec_version=1.2.3+1.15.1

+ 25 - 7
src/main/java/me/shedaniel/clothconfig2/ClothConfigInitializer.java

@@ -289,31 +289,31 @@ public class ClothConfigInitializer implements ClientModInitializer {
         class Pair<T, R> {
             T t;
             R r;
-        
+            
             public Pair(T t, R r) {
                 this.t = t;
                 this.r = r;
             }
-        
+            
             public T getLeft() {
                 return t;
             }
-        
+            
             public R getRight() {
                 return r;
             }
-        
+            
             @Override
             public boolean equals(Object o) {
                 if (this == o) return true;
                 if (o == null || getClass() != o.getClass()) return false;
-            
+                
                 Pair<?, ?> pair = (Pair<?, ?>) o;
-            
+                
                 if (!Objects.equals(t, pair.t)) return false;
                 return Objects.equals(r, pair.r);
             }
-        
+            
             @Override
             public int hashCode() {
                 int result = t != null ? t.hashCode() : 0;
@@ -340,6 +340,24 @@ public class ClothConfigInitializer implements ClientModInitializer {
         colors.add(entryBuilder.startDropdownMenu(new LiteralText("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());
         colors.add(entryBuilder.startDropdownMenu(new LiteralText("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(colors.build());
+        testing.addEntry(entryBuilder.startDropdownMenu(new LiteralText("Suggestion Random Int"), DropdownMenuBuilder.TopCellElementBuilder.of(10,
+                s -> {
+                    try {
+                        return Integer.parseInt(s);
+                    } catch (NumberFormatException ignored) {
+                        
+                    }
+                    return null;
+                })).setDefaultValue(10).setSelections(Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)).build());
+        testing.addEntry(entryBuilder.startDropdownMenu(new LiteralText("Selection Random Int"), DropdownMenuBuilder.TopCellElementBuilder.of(10,
+                s -> {
+                    try {
+                        return Integer.parseInt(s);
+                    } catch (NumberFormatException ignored) {
+                        
+                    }
+                    return null;
+                })).setDefaultValue(5).setSuggestionMode(false).setSelections(Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)).build());
         testing.addEntry(new NestedListListEntry<Pair<Integer, Integer>, MultiElementListEntry<Pair<Integer, Integer>>>(
                 new LiteralText("Nice"),
                 Lists.newArrayList(new Pair<>(10, 10), new Pair<>(20, 40)),

+ 1 - 1
src/main/java/me/shedaniel/clothconfig2/gui/AbstractConfigScreen.java

@@ -29,7 +29,7 @@ public abstract class AbstractConfigScreen extends Screen implements ConfigScree
         if (legacyRequiresRestart) return true;
         for (List<AbstractConfigEntry<?>> entries : getCategorizedEntries().values()) {
             for (AbstractConfigEntry<?> entry : entries) {
-                if (entry.isRequiresRestart()) {
+                if (!entry.getConfigError().isPresent() && entry.isEdited() && entry.isRequiresRestart()) {
                     return true;
                 }
             }

+ 0 - 3
src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigScreen.java

@@ -198,9 +198,6 @@ public abstract class ClothConfigScreen extends AbstractTabbedConfigScreen {
         this.children.clear();
         this.tabButtons.clear();
         
-        // Put already created list back to entries
-        if (listWidget != null)
-            categorizedEntries.put(tabs.get(selectedTabIndex).getLeft(), (List) listWidget.children());
         selectedTabIndex = nextTabIndex;
         children.add(listWidget = new ListWidget(client, width, height, isShowingTabs() ? 70 : 30, height - 32, getBackgroundLocation()));
         if (categorizedEntries.size() > selectedTabIndex) {

+ 1 - 1
src/main/java/me/shedaniel/clothconfig2/gui/entries/DropdownBoxEntry.java

@@ -377,7 +377,7 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
         
         private void updatePosition(float delta) {
             double[] target = {this.target};
-            scroll = handleScrollingPosition(target, scroll, getMaxScroll(), delta, start, duration);
+            scroll = handleScrollingPosition(target, scroll, getMaxScrollPosition(), delta, start, duration);
             this.target = target[0];
         }