shedaniel 5 年之前
父節點
當前提交
db3e0ba46a

+ 3 - 3
gradle.properties

@@ -1,6 +1,6 @@
-minecraft_version=1.15-pre6
-yarn_version=1.15-pre6+build.1
+minecraft_version=1.15
+yarn_version=1.15+build.1
 fabric_loader_version=0.7.2+build.174
 fabric_version=0.4.20+build.273-1.15
-mod_version=2.5.1
+mod_version=2.5.2
 modmenu_version=1.7.14-unstable.19w42a+build.10

+ 5 - 2
src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigScreen.java

@@ -477,7 +477,10 @@ public abstract class ClothConfigScreen extends Screen {
     @Override
     public boolean mouseClicked(double double_1, double double_2, int int_1) {
         if (this.focusedBinding != null) {
-            focusedBinding.setValue(InputUtil.Type.MOUSE.createFromCode(int_1));
+            if (focusedBinding.isAllowMouse())
+                focusedBinding.setValue(InputUtil.Type.MOUSE.createFromCode(int_1));
+            else
+                focusedBinding.setValue(InputUtil.UNKNOWN_KEYCODE);
             this.focusedBinding = null;
             return true;
         } else {
@@ -488,7 +491,7 @@ public abstract class ClothConfigScreen extends Screen {
     @Override
     public boolean keyPressed(int int_1, int int_2, int int_3) {
         if (this.focusedBinding != null) {
-            if (int_1 == 256) {
+            if (int_1 == 256 || !focusedBinding.isAllowKey()) {
                 focusedBinding.setValue(InputUtil.UNKNOWN_KEYCODE);
             } else {
                 focusedBinding.setValue(InputUtil.getKeyCode(int_1, int_2));

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

@@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.mojang.blaze3d.systems.RenderSystem;
 import me.shedaniel.clothconfig2.ClothConfigInitializer;
-import me.shedaniel.clothconfig2.api.RunSixtyTimesEverySec;
 import me.shedaniel.clothconfig2.api.ScissorsHandler;
 import me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget.SmoothScrollingSettings;
 import me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWidget.Interpolation;
@@ -32,8 +31,6 @@ import java.util.function.Consumer;
 import java.util.function.Function;
 import java.util.function.Supplier;
 
-import static me.shedaniel.clothconfig2.ClothConfigInitializer.getBounceBackMultiplier;
-
 @SuppressWarnings("deprecation")
 public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
     
@@ -238,15 +235,6 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
         protected double scroll, target;
         protected long start;
         protected long duration;
-        protected RunSixtyTimesEverySec clamper = () -> {
-            target = clamp(target);
-            if (target < 0) {
-                target = target * getBounceBackMultiplier();
-            } else if (target > getMaxScrollPosition()) {
-                target = (target - getMaxScrollPosition()) * getBounceBackMultiplier() + getMaxScrollPosition();
-            } else
-                unregisterClamper();
-        };
         
         public DefaultDropdownMenuElement(@Nonnull ImmutableList<R> selections) {
             this.selections = selections;
@@ -254,10 +242,6 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
             this.currentElements = Lists.newArrayList();
         }
         
-        protected void unregisterClamper() {
-            clamper.unregisterTick();
-        }
-        
         public final double clamp(double v) {
             return MathHelper.clamp(v, -SmoothScrollingSettings.CLAMP_EXTENSION, getMaxScrollPosition() + SmoothScrollingSettings.CLAMP_EXTENSION);
         }
@@ -354,8 +338,11 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
         
         private void updatePosition(float delta) {
             target = clamp(target);
-            if ((target < 0 || target > getMaxScrollPosition()) && !clamper.isRegistered())
-                clamper.registerTick();
+            if (target < 0) {
+                target -= target * (1 - ClothConfigInitializer.getBounceBackMultiplier()) * delta / 3;
+            } else if (target > getMaxScrollPosition()) {
+                target = (target - getMaxScrollPosition()) * (1 - (1 - ClothConfigInitializer.getBounceBackMultiplier()) * delta / 3) + getMaxScrollPosition();
+            }
             if (!Precision.almostEquals(scroll, target, Precision.FLOAT_EPSILON))
                 scroll = (float) Interpolation.expoEase(scroll, target, Math.min((System.currentTimeMillis() - start) / ((double) duration), 1));
             else
@@ -369,6 +356,7 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
             fill(lastRectangle.x, lastRectangle.y + lastRectangle.height, lastRectangle.x + cWidth, lastRectangle.y + lastRectangle.height + last10Height + 1, -6250336);
             fill(lastRectangle.x + 1, lastRectangle.y + lastRectangle.height + 1, lastRectangle.x + cWidth - 1, lastRectangle.y + lastRectangle.height + last10Height, -16777216);
             RenderSystem.pushMatrix();
+            RenderSystem.translatef(0, 0, 300f);
             
             ScissorsHandler.INSTANCE.scissor(new Rectangle(lastRectangle.x, lastRectangle.y + lastRectangle.height + 1, cWidth - 6, last10Height - 1));
             double yy = lastRectangle.y + lastRectangle.height - scroll;
@@ -420,6 +408,7 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
                 tessellator.draw();
                 RenderSystem.enableTexture();
             }
+            RenderSystem.translatef(0, 0, -300f);
             RenderSystem.popMatrix();
         }
         

+ 2 - 5
src/main/java/me/shedaniel/clothconfig2/impl/ScissorsHandlerImpl.java

@@ -49,12 +49,9 @@ public final class ScissorsHandlerImpl implements ScissorsHandler {
             Rectangle r = scissorsAreas.get(0).clone();
             scissorsAreas.stream().skip(1L).forEach(rectangle -> r.setBounds(r.intersects(rectangle) ? r.intersection(rectangle) : new Rectangle()));
             Window window = MinecraftClient.getInstance().getWindow();
-            int x = Math.round(window.getWidth() * (r.x / (float) window.getScaledWidth()));
-            int y = Math.round(window.getHeight() * (r.y / (float) window.getScaledHeight()));
-            int ww = Math.round(window.getWidth() * (r.width / (float) window.getScaledWidth()));
-            int hh = Math.round(window.getHeight() * ((r.height) / (float) window.getScaledHeight()));
+            double scaleFactor = window.getScaleFactor();
             GL11.glEnable(GL11.GL_SCISSOR_TEST);
-            GL11.glScissor(x, window.getHeight() - hh - y, ww, hh);
+            GL11.glScissor((int) (r.x * scaleFactor), (int) ((window.getScaledHeight() - r.height - r.y) * scaleFactor), (int) (r.width * scaleFactor), (int) (r.height * scaleFactor));
         } else
             GL11.glDisable(GL11.GL_SCISSOR_TEST);
     }

+ 17 - 0
src/main/java/me/shedaniel/clothconfig2/impl/builders/KeyCodeBuilder.java

@@ -15,12 +15,27 @@ public class KeyCodeBuilder extends FieldBuilder<InputUtil.KeyCode, KeyCodeEntry
     @Nullable private Consumer<InputUtil.KeyCode> saveConsumer = null;
     @Nonnull private Function<InputUtil.KeyCode, Optional<String[]>> tooltipSupplier = bool -> Optional.empty();
     private InputUtil.KeyCode value;
+    private boolean allowKey = true, allowMouse = true;
     
     public KeyCodeBuilder(String resetButtonKey, String fieldNameKey, InputUtil.KeyCode value) {
         super(resetButtonKey, fieldNameKey);
         this.value = value;
     }
     
+    public KeyCodeBuilder setAllowKey(boolean allowKey) {
+        if (!allowMouse && !allowKey)
+            throw new IllegalArgumentException();
+        this.allowKey = allowKey;
+        return this;
+    }
+    
+    public KeyCodeBuilder setAllowMouse(boolean allowMouse) {
+        if (!allowKey && !allowMouse)
+            throw new IllegalArgumentException();
+        this.allowMouse = allowMouse;
+        return this;
+    }
+    
     public KeyCodeBuilder setErrorSupplier(@Nullable Function<InputUtil.KeyCode, Optional<String>> errorSupplier) {
         this.errorSupplier = errorSupplier;
         return this;
@@ -72,6 +87,8 @@ public class KeyCodeBuilder extends FieldBuilder<InputUtil.KeyCode, KeyCodeEntry
         entry.setTooltipSupplier(() -> tooltipSupplier.apply(entry.getValue()));
         if (errorSupplier != null)
             entry.setErrorSupplier(() -> errorSupplier.apply(entry.getValue()));
+        entry.setAllowKey(allowKey);
+        entry.setAllowMouse(allowMouse);
         return entry;
     }