Ver Fonte

Horribly broke API and fix #46

Signed-off-by: shedaniel <daniel@shedaniel.me>
shedaniel há 5 anos atrás
pai
commit
5309c21519

+ 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.1.0-unstable
+mod_version=4.2.0-unstable
 modmenu_version=1.11.2+build.6
 nec_version=1.2.3+1.15.1

+ 0 - 1
src/main/java/me/shedaniel/clothconfig2/ClothConfigInitializer.java

@@ -294,7 +294,6 @@ public class ClothConfigInitializer implements ClientModInitializer {
         ConfigBuilder builder = getConfigBuilder();
         ConfigEntryBuilder entryBuilder = builder.entryBuilder();
         ConfigCategory testing = builder.getOrCreateCategory(new TranslatableText("category.cloth-config.testing"));
-//        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(new LiteralText("Cool Key"), InputUtil.UNKNOWN_KEYCODE).setDefaultValue(InputUtil.UNKNOWN_KEYCODE).build());
         testing.addEntry(entryBuilder.startModifierKeyCodeField(new LiteralText("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(new LiteralText("A list of Doubles"), Arrays.asList(1d, 2d, 3d)).setDefaultValue(Arrays.asList(1d, 2d, 3d)).build());

+ 0 - 25
src/main/java/me/shedaniel/clothconfig2/api/RunSixtyTimesEverySec.java

@@ -1,25 +0,0 @@
-package me.shedaniel.clothconfig2.api;
-
-import me.shedaniel.clothconfig2.impl.RunSixtyTimesEverySecImpl;
-import org.jetbrains.annotations.ApiStatus;
-
-@Deprecated
-@ApiStatus.ScheduledForRemoval
-public interface RunSixtyTimesEverySec {
-    
-    void run();
-    
-    default boolean isRegistered() {
-        return RunSixtyTimesEverySecImpl.TICKS_LIST.contains(this);
-    }
-    
-    default void registerTick() {
-        RunSixtyTimesEverySecImpl.TICKS_LIST.removeIf(runSixtyTimesEverySec -> runSixtyTimesEverySec == this);
-        RunSixtyTimesEverySecImpl.TICKS_LIST.add(this);
-    }
-    
-    default void unregisterTick() {
-        RunSixtyTimesEverySecImpl.TICKS_LIST.remove(this);
-    }
-    
-}

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

@@ -231,14 +231,14 @@ public abstract class ClothConfigScreen extends Screen {
         listWidget.setSmoothScrolling(this.smoothScrollingList);
         if (tabbedEntries.size() > selectedTabIndex)
             Lists.newArrayList(tabbedEntries.values()).get(selectedTabIndex).forEach(entry -> listWidget.children().add(entry));
-        int buttonWidths = (width - 50 - 12) / 3;
-        addButton(quitButton = new ButtonWidget(25, height - 26, buttonWidths, 20, edited ? new TranslatableText("text.cloth-config.cancel_discard") : new TranslatableText("gui.cancel"), widget -> {
+        int buttonWidths = Math.min(200, (width - 50 - 12) / 3);
+        addButton(quitButton = new ButtonWidget(width / 2 - buttonWidths / 2 - buttonWidths - 6, height - 26, buttonWidths, 20, edited ? new TranslatableText("text.cloth-config.cancel_discard") : new TranslatableText("gui.cancel"), widget -> {
             if (confirmSave && edited)
                 client.openScreen(new ConfirmScreen(new QuitSaveConsumer(), new TranslatableText("text.cloth-config.quit_config"), new TranslatableText("text.cloth-config.quit_config_sure"), new TranslatableText("text.cloth-config.quit_discard"), new TranslatableText("gui.cancel")));
             else
                 client.openScreen(parent);
         }));
-        addButton(saveButton = new AbstractPressableButtonWidget(25 + 6 + buttonWidths, height - 26, buttonWidths, 20, NarratorManager.EMPTY) {
+        addButton(saveButton = new AbstractPressableButtonWidget(width / 2 + buttonWidths / 2 + 6, height - 26, buttonWidths, 20, NarratorManager.EMPTY) {
             @Override
             public void onPress() {
                 saveAll(true);
@@ -262,7 +262,7 @@ public abstract class ClothConfigScreen extends Screen {
                 super.render(matrices, mouseX, mouseY, delta);
             }
         });
-        addButton(applyButton = new AbstractPressableButtonWidget(25 + (6 + buttonWidths) * 2, height - 26, buttonWidths, 20, new TranslatableText("text.cloth-config.apply")) {
+        addButton(applyButton = new AbstractPressableButtonWidget(width / 2 - buttonWidths / 2, height - 26, buttonWidths, 20, new TranslatableText("text.cloth-config.apply")) {
             @Override
             public void onPress() {
                 if (requiresRestart)

+ 0 - 167
src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicSmoothScrollingEntryListWidget.java

@@ -1,167 +0,0 @@
-package me.shedaniel.clothconfig2.gui.widget;
-
-import me.shedaniel.clothconfig2.api.RunSixtyTimesEverySec;
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.render.BufferBuilder;
-import net.minecraft.client.render.Tessellator;
-import net.minecraft.client.render.VertexFormats;
-import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.util.Identifier;
-import net.minecraft.util.math.MathHelper;
-import net.minecraft.util.math.Matrix4f;
-
-@Deprecated
-@Environment(EnvType.CLIENT)
-public abstract class DynamicSmoothScrollingEntryListWidget<E extends DynamicEntryListWidget.Entry<E>> extends DynamicEntryListWidget<E> {
-    
-    protected double scrollVelocity;
-    protected boolean smoothScrolling = true;
-    protected RunSixtyTimesEverySec scroller = () -> {
-        if (scrollVelocity == 0 && scroll >= 0 && scroll <= getMaxScroll())
-            scrollerUnregisterTick();
-        else {
-            // Basic scrolling
-            double change = scrollVelocity * 0.3d;
-            if (scrollVelocity != 0) {
-                scroll += change;
-                scrollVelocity -= scrollVelocity * (scroll >= 0 && scroll <= getMaxScroll() ? 0.2d : .4d);
-                if (Math.abs(scrollVelocity) < .1)
-                    scrollVelocity = 0d;
-            }
-            
-            // Scrolling back aka bounce
-            if (scroll < 0d && scrollVelocity == 0d) {
-                scroll = Math.min(scroll + (0 - scroll) * 0.2d, 0);
-                if (scroll > -0.1d && scroll < 0d)
-                    scroll = 0d;
-            } else if (scroll > getMaxScroll() && scrollVelocity == 0d) {
-                scroll = Math.max(scroll - (scroll - getMaxScroll()) * 0.2d, getMaxScroll());
-                if (scroll > getMaxScroll() && scroll < getMaxScroll() + 0.1d)
-                    scroll = getMaxScroll();
-            }
-        }
-    };
-    
-    public DynamicSmoothScrollingEntryListWidget(MinecraftClient client, int width, int height, int top, int bottom, Identifier backgroundLocation) {
-        super(client, width, height, top, bottom, backgroundLocation);
-    }
-    
-    protected void scrollerUnregisterTick() {
-        scroller.unregisterTick();
-    }
-    
-    public double getScrollVelocity() {
-        return scrollVelocity;
-    }
-    
-    public void setScrollVelocity(double scrollVelocity) {
-        this.scrollVelocity = scrollVelocity;
-    }
-    
-    public boolean isSmoothScrolling() {
-        return smoothScrolling;
-    }
-    
-    public void setSmoothScrolling(boolean smoothScrolling) {
-        this.smoothScrolling = smoothScrolling;
-    }
-    
-    @Override
-    public void capYPosition(double double_1) {
-        if (smoothScrolling)
-            this.scroll = double_1;
-        else
-            this.scroll = MathHelper.clamp(double_1, 0.0D, this.getMaxScroll());
-    }
-    
-    @Override
-    public boolean mouseDragged(double double_1, double double_2, int int_1, double double_3, double double_4) {
-        if (!smoothScrolling)
-            return super.mouseDragged(double_1, double_2, int_1, double_3, double_4);
-        if ((this.getFocused() != null && this.isDragging() && int_1 == 0) && this.getFocused().mouseDragged(double_1, double_2, int_1, double_3, double_4)) {
-            return true;
-        } else if (int_1 == 0 && this.scrolling) {
-            if (double_2 < (double) this.top) {
-                this.capYPosition(0.0D);
-            } else if (double_2 > (double) this.bottom) {
-                this.capYPosition(this.getMaxScroll());
-            } else {
-                double double_5 = Math.max(1, this.getMaxScroll());
-                int int_2 = this.bottom - this.top;
-                int int_3 = MathHelper.clamp((int) ((float) (int_2 * int_2) / (float) this.getMaxScrollPosition()), 32, int_2 - 8);
-                double double_6 = Math.max(1.0D, double_5 / (double) (int_2 - int_3));
-                this.capYPosition(MathHelper.clamp(this.getScroll() + double_4 * double_6, 0, getMaxScroll()));
-            }
-            return true;
-        }
-        return false;
-    }
-    
-    @Override
-    protected void scroll(int int_1) {
-        super.scroll(int_1);
-        this.scrollVelocity = 0d;
-    }
-    
-    @Override
-    public boolean mouseScrolled(double double_1, double double_2, double double_3) {
-        for (E entry : children()) {
-            if (entry.mouseScrolled(double_1, double_2, double_3)) {
-                return true;
-            }
-        }
-        if (!smoothScrolling) {
-            this.scrollVelocity = 0d;
-            scroll += 16 * -double_3;
-            this.scroll = MathHelper.clamp(double_1, 0.0D, this.getMaxScroll());
-            return true;
-        }
-        if (scroll <= getMaxScroll() && double_3 < 0)
-            scrollVelocity += 16 * -double_3;
-        if (scroll >= 0 && double_3 > 0)
-            scrollVelocity += 16 * -double_3;
-        if (!scroller.isRegistered())
-            scroller.registerTick();
-        return true;
-    }
-    
-    @Override
-    protected void renderScrollBar(MatrixStack matrices, Tessellator tessellator, BufferBuilder buffer, int maxScroll, int scrollbarPositionMinX, int scrollbarPositionMaxX) {
-        if (!smoothScrolling)
-            super.renderScrollBar(matrices, tessellator, buffer, maxScroll, scrollbarPositionMinX, scrollbarPositionMaxX);
-        else if (maxScroll > 0) {
-            Matrix4f matrix = matrices.peek().getModel();
-            int height = ((this.bottom - this.top) * (this.bottom - this.top)) / this.getMaxScrollPosition();
-            height = MathHelper.clamp(height, 32, this.bottom - this.top - 8);
-            height -= Math.min((scroll < 0 ? (int) -scroll : scroll > getMaxScroll() ? (int) scroll - getMaxScroll() : 0), height * .75);
-            int minY = Math.min(Math.max((int) this.getScroll() * (this.bottom - this.top - height) / maxScroll + this.top, this.top), this.bottom - height);
-            
-            // Black Bar
-            buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
-            buffer.vertex(matrix, scrollbarPositionMinX, this.bottom, 0.0F).texture(0, 1).color(0, 0, 0, 255).next();
-            buffer.vertex(matrix, scrollbarPositionMaxX, this.bottom, 0.0F).texture(1, 1).color(0, 0, 0, 255).next();
-            buffer.vertex(matrix, scrollbarPositionMaxX, this.top, 0.0F).texture(1, 0).color(0, 0, 0, 255).next();
-            buffer.vertex(matrix, scrollbarPositionMinX, this.top, 0.0F).texture(0, 0).color(0, 0, 0, 255).next();
-            tessellator.draw();
-            
-            // Top
-            buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
-            buffer.vertex(matrix, scrollbarPositionMinX, minY + height, 0.0F).texture(0, 1).color(128, 128, 128, 255).next();
-            buffer.vertex(matrix, scrollbarPositionMaxX, minY + height, 0.0F).texture(1, 1).color(128, 128, 128, 255).next();
-            buffer.vertex(matrix, scrollbarPositionMaxX, minY, 0.0F).texture(1, 0).color(128, 128, 128, 255).next();
-            buffer.vertex(matrix, scrollbarPositionMinX, minY, 0.0F).texture(0, 0).color(128, 128, 128, 255).next();
-            tessellator.draw();
-            
-            // Bottom
-            buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
-            buffer.vertex(scrollbarPositionMinX, (minY + height - 1), 0.0D).texture(0, 1).color(192, 192, 192, 255).next();
-            buffer.vertex((scrollbarPositionMaxX - 1), (minY + height - 1), 0.0D).texture(1, 1).color(192, 192, 192, 255).next();
-            buffer.vertex((scrollbarPositionMaxX - 1), minY, 0.0D).texture(1, 0).color(192, 192, 192, 255).next();
-            buffer.vertex(scrollbarPositionMinX, minY, 0.0D).texture(0, 0).color(192, 192, 192, 255).next();
-            tessellator.draw();
-        }
-    }
-    
-}

+ 0 - 34
src/main/java/me/shedaniel/clothconfig2/impl/RunSixtyTimesEverySecImpl.java

@@ -1,34 +0,0 @@
-package me.shedaniel.clothconfig2.impl;
-
-import com.google.common.collect.Lists;
-import me.shedaniel.clothconfig2.api.RunSixtyTimesEverySec;
-import org.jetbrains.annotations.ApiStatus;
-
-import java.util.List;
-import java.util.Objects;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-@ApiStatus.Internal
-@Deprecated
-@ApiStatus.ScheduledForRemoval
-public class RunSixtyTimesEverySecImpl {
-    
-    public static final List<RunSixtyTimesEverySec> TICKS_LIST = Lists.newCopyOnWriteArrayList();
-    private static final ScheduledExecutorService EXECUTOR_SERVICE = Executors.newSingleThreadScheduledExecutor();
-    
-    static {
-        EXECUTOR_SERVICE.scheduleAtFixedRate(() -> {
-            TICKS_LIST.removeIf(Objects::isNull);
-            TICKS_LIST.iterator().forEachRemaining(run -> {
-                try {
-                    run.run();
-                } catch (Throwable throwable) {
-                    throwable.printStackTrace();
-                }
-            });
-        }, 0, 1000 / 60, TimeUnit.MILLISECONDS);
-    }
-    
-}