Răsfoiți Sursa

Scrollbar is a very important element of a list

Danielshe 5 ani în urmă
părinte
comite
b9332c4097

+ 2 - 2
gradle.properties

@@ -1,9 +1,9 @@
-mod_version=3.1.1
+mod_version=3.1.2
 minecraft_version=1.14.4
 yarn_version=1.14.4+build.1
 fabricloader_version=0.6.1+build.164
 jankson_version=1.1.0
-cloth_events_version=0.5.1
+cloth_events_version=0.6.0
 cloth_config_version=1.1.1
 modmenu_version=1.7.9+build.118
 fabric_api=0.3.2+build.218-1.14

+ 6 - 0
src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java

@@ -242,6 +242,12 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
             if (screen instanceof AbstractContainerScreen)
                 ScreenHelper.getLastOverlay().render(i, i1, v);
         });
+        ClothClientHooks.SCREEN_MOUSE_DRAGGED.register((minecraftClient, screen, v, v1, i, v2, v3) -> {
+            if (screen instanceof AbstractContainerScreen)
+                if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseDragged(v, v1, i, v2, v3))
+                    return ActionResult.SUCCESS;
+            return ActionResult.PASS;
+        });
         ClothClientHooks.SCREEN_MOUSE_CLICKED.register((minecraftClient, screen, v, v1, i) -> {
             if (screen instanceof CreativeInventoryScreen)
                 if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseClicked(v, v1, i)) {

+ 7 - 0
src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java

@@ -572,6 +572,13 @@ public class ContainerScreenOverlay extends Widget {
         return false;
     }
     
+    @Override
+    public boolean mouseDragged(double double_1, double double_2, int int_1, double double_3, double double_4) {
+        if (!ScreenHelper.isOverlayVisible())
+            return false;
+        return this.getFocused() != null && this.isDragging() && int_1 == 0 ? this.getFocused().mouseDragged(double_1, double_2, int_1, double_3, double_4) : false;
+    }
+    
     public boolean isInside(double mouseX, double mouseY) {
         if (!rectangle.contains(mouseX, mouseY))
             return false;

+ 7 - 1
src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java

@@ -103,7 +103,13 @@ public class AutoCraftingButtonWidget extends ButtonWidget {
         if (isHovered(mouseX, mouseY) && category instanceof TransferRecipeCategory && redSlots != null) {
             ((TransferRecipeCategory<RecipeDisplay>) category).renderRedSlots(setupDisplay, displayBounds, displaySupplier.get(), redSlots);
         }
-        errorTooltip = error == null || error.isEmpty() ? null : error;
+        errorTooltip = error == null || error.isEmpty() ? null : Lists.newArrayList();
+        if (errorTooltip != null) {
+            for (String s : error) {
+                if (!errorTooltip.stream().anyMatch(ss -> ss.equalsIgnoreCase(s)))
+                    errorTooltip.add(s);
+            }
+        }
         int x = getBounds().x, y = getBounds().y, width = getBounds().width, height = getBounds().height;
         minecraft.getTextureManager().bindTexture(ScreenHelper.isDarkModeEnabled() ? BUTTON_LOCATION_DARK : BUTTON_LOCATION);
         RenderHelper.color4f(1.0F, 1.0F, 1.0F, 1.0F);

+ 99 - 1
src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java

@@ -20,7 +20,10 @@ import me.shedaniel.rei.impl.SearchArgument;
 import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.item.TooltipContext;
 import net.minecraft.client.network.ClientPlayerEntity;
+import net.minecraft.client.render.BufferBuilder;
 import net.minecraft.client.render.GuiLighting;
+import net.minecraft.client.render.Tessellator;
+import net.minecraft.client.render.VertexFormats;
 import net.minecraft.client.resource.language.I18n;
 import net.minecraft.fluid.Fluid;
 import net.minecraft.item.Item;
@@ -76,6 +79,10 @@ public class EntryListWidget extends Widget {
             e.printStackTrace();
         }
     };
+    private static float scrollBarAlpha = 0;
+    private static float scrollBarAlphaFuture = 0;
+    private static long scrollBarAlphaFutureTime = -1;
+    private static boolean draggingScrollBar = false;
     
     static {
         ASCENDING_COMPARATOR = (entry, entry1) -> {
@@ -238,6 +245,10 @@ public class EntryListWidget extends Widget {
                 scrollVelocity -= 24;
             else if (this.scroll <= this.getMaxScroll() && double_3 < 0)
                 scrollVelocity += 24;
+            if (scrollBarAlphaFuture == 0)
+                scrollBarAlphaFuture = 1f;
+            if (System.currentTimeMillis() - scrollBarAlphaFutureTime > 300f)
+                scrollBarAlphaFutureTime = System.currentTimeMillis();
             return true;
         }
         return super.mouseScrolled(double_1, double_2, double_3);
@@ -245,6 +256,29 @@ public class EntryListWidget extends Widget {
     
     @Override
     public void render(int int_1, int int_2, float float_1) {
+        if (RoughlyEnoughItemsCore.getConfigManager().getConfig().doesVillagerScreenHavePermanentScrollBar()) {
+            scrollBarAlphaFutureTime = System.currentTimeMillis();
+            scrollBarAlphaFuture = 0;
+            scrollBarAlpha = 1;
+        } else if (scrollBarAlphaFutureTime > 0) {
+            long l = System.currentTimeMillis() - scrollBarAlphaFutureTime;
+            if (l > 300f) {
+                if (scrollBarAlphaFutureTime == 0) {
+                    scrollBarAlpha = scrollBarAlphaFuture;
+                    scrollBarAlphaFutureTime = -1;
+                } else if (l > 2000f && scrollBarAlphaFuture == 1) {
+                    scrollBarAlphaFuture = 0;
+                    scrollBarAlphaFutureTime = System.currentTimeMillis();
+                } else
+                    scrollBarAlpha = scrollBarAlphaFuture;
+            } else {
+                if (scrollBarAlphaFuture == 0)
+                    scrollBarAlpha = Math.min(scrollBarAlpha, 1 - Math.min(1f, l / 300f));
+                else if (scrollBarAlphaFuture == 1)
+                    scrollBarAlpha = Math.max(Math.min(1f, l / 300f), scrollBarAlpha);
+            }
+        }
+        
         GuiLighting.disable();
         RenderHelper.pushMatrix();
         boolean widgetScrolled = RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled();
@@ -265,8 +299,44 @@ public class EntryListWidget extends Widget {
                 widget.render(int_1, int_2, float_1);
             }
         });
-        if (widgetScrolled)
+        if (widgetScrolled) {
+            double height = getMaxScroll();
+            if (height > rectangle.height) {
+                Tessellator tessellator = Tessellator.getInstance();
+                BufferBuilder buffer = tessellator.getBufferBuilder();
+                double maxScroll = height;
+                //                int scrollBarHeight = MathHelper.floor((rectangle.height) * (rectangle.height) / maxScroll);
+                //                scrollBarHeight = MathHelper.clamp(scrollBarHeight, 32, rectangle.height - 8);
+                //                int minY = (int) (scroll * (rectangle.height - scrollBarHeight) / maxScroll) + rectangle.y + 1;
+                //                if (minY < this.rectangle.y + 1)
+                //                    minY = this.rectangle.y;
+                //                if (minY + scrollBarHeight >= rectangle.getMaxY())
+                //                    minY = rectangle.getMaxY() - scrollBarHeight;
+                int scrollBarHeight = MathHelper.floor((rectangle.height) * (rectangle.height) / maxScroll);
+                scrollBarHeight = MathHelper.clamp(scrollBarHeight, 32, rectangle.height - 8);
+                scrollBarHeight = (int) ((double) scrollBarHeight - Math.min((double) (this.scroll < 0.0D ? (int) (-this.scroll) : (this.scroll > (double) this.getMaxScroll() ? (int) this.scroll - this.getMaxScroll() : 0)), (double) scrollBarHeight * 0.75D));
+                int minY = (int) Math.min(Math.max((int) this.getScroll() * (rectangle.height - scrollBarHeight) / maxScroll + rectangle.y, rectangle.y), rectangle.getMaxY() - scrollBarHeight);
+                double scrollbarPositionMinX = rectangle.getMaxX() - 6, scrollbarPositionMaxX = rectangle.getMaxX() - 1;
+                GuiLighting.disable();
+                RenderHelper.disableTexture();
+                RenderHelper.enableBlend();
+                RenderHelper.disableAlphaTest();
+                RenderHelper.blendFuncSeparate(770, 771, 1, 0);
+                RenderHelper.shadeModel(7425);
+                buffer.begin(7, VertexFormats.POSITION_COLOR);
+                float b = ScreenHelper.isDarkModeEnabled() ? 0.8f : 1f;
+                buffer.vertex(scrollbarPositionMinX, minY + scrollBarHeight, 1000D).color(b, b, b, scrollBarAlpha).next();
+                buffer.vertex(scrollbarPositionMaxX, minY + scrollBarHeight, 1000D).color(b, b, b, scrollBarAlpha).next();
+                buffer.vertex(scrollbarPositionMaxX, minY, 1000D).color(b, b, b, scrollBarAlpha).next();
+                buffer.vertex(scrollbarPositionMinX, minY, 1000D).color(b, b, b, scrollBarAlpha).next();
+                tessellator.draw();
+                RenderHelper.shadeModel(7424);
+                RenderHelper.disableBlend();
+                RenderHelper.enableAlphaTest();
+                RenderHelper.enableTexture();
+            }
             Scissors.end();
+        }
         RenderHelper.popMatrix();
         ClientPlayerEntity player = minecraft.player;
         if (rectangle.contains(PointHelper.fromMouse()) && ClientHelper.getInstance().isCheating() && !player.inventory.getCursorStack().isEmpty() && RoughlyEnoughItemsCore.hasPermissionToUsePackets())
@@ -373,6 +443,22 @@ public class EntryListWidget extends Widget {
         return true;
     }
     
+    @Override
+    public boolean mouseDragged(double mouseX, double mouseY, int int_1, double double_3, double double_4) {
+        if (int_1 == 0 && scrollBarAlpha > 0 && draggingScrollBar) {
+            float height = maxScroll;
+            int actualHeight = rectangle.height;
+            if (height > actualHeight && mouseY >= rectangle.y && mouseY <= rectangle.getMaxY()) {
+                double double_5 = (double) Math.max(1, this.getMaxScroll());
+                int int_2 = rectangle.height;
+                int int_3 = MathHelper.clamp((int) ((float) (int_2 * int_2) / (float) maxScroll), 32, int_2 - 8);
+                double double_6 = Math.max(1.0D, double_5 / (double) (int_2 - int_3));
+                scroll = MathHelper.clamp((float) (scroll + double_4 * double_6), 0, height - rectangle.height);
+            }
+        }
+        return super.mouseDragged(mouseX, mouseY, int_1, double_3, double_4);
+    }
+    
     @Override
     public boolean keyPressed(int int_1, int int_2, int int_3) {
         if (rectangle.contains(PointHelper.fromMouse()))
@@ -458,6 +544,18 @@ public class EntryListWidget extends Widget {
     
     @Override
     public boolean mouseClicked(double double_1, double double_2, int int_1) {
+        double height = getMaxScroll();
+        int actualHeight = rectangle.height;
+        if (height > actualHeight && scrollBarAlpha > 0 && double_2 >= rectangle.y && double_2 <= rectangle.getMaxY()) {
+            double scrollbarPositionMinX = rectangle.getMaxX() - 6;
+            if (double_1 >= scrollbarPositionMinX - 2 & double_1 <= scrollbarPositionMinX + 8) {
+                this.draggingScrollBar = true;
+                scrollBarAlpha = 1;
+                return true;
+            }
+        }
+        this.draggingScrollBar = false;
+        
         if (rectangle.contains(double_1, double_2)) {
             ClientPlayerEntity player = minecraft.player;
             if (ClientHelper.getInstance().isCheating() && !player.inventory.getCursorStack().isEmpty() && RoughlyEnoughItemsCore.hasPermissionToUsePackets()) {

+ 3 - 3
src/main/resources/assets/roughlyenoughitems/lang/en_us.json

@@ -102,9 +102,9 @@
   "config.roughlyenoughitems.searchFieldLocation.bottom_side": "Bottom Left / Right",
   "config.roughlyenoughitems.searchFieldLocation.top_side": "Top Left / Right",
   "config.roughlyenoughitems.searchFieldLocation.center": "Middle",
-  "config.roughlyenoughitems.villagerScreenPermanentScrollBar": "Villager Recipe Screen Scrollbar:",
-  "config.roughlyenoughitems.villagerScreenPermanentScrollBar.boolean.true": "Permanent",
-  "config.roughlyenoughitems.villagerScreenPermanentScrollBar.boolean.false": "Auto Fade Out",
+  "config.roughlyenoughitems.villagerScreenPermanentScrollBar": "Scrollbar Fade:",
+  "config.roughlyenoughitems.villagerScreenPermanentScrollBar.boolean.true": "Never",
+  "config.roughlyenoughitems.villagerScreenPermanentScrollBar.boolean.false": "When Inactive",
   "config.roughlyenoughitems.disableRecipeBook": "Vanilla Recipe Book:",
   "config.roughlyenoughitems.disableRecipeBook.boolean.true": "Disabled",
   "config.roughlyenoughitems.disableRecipeBook.boolean.false": "Enabled",