Browse Source

Disable dynamically adjust recipe screen height and width

Signed-off-by: shedaniel <daniel@shedaniel.me>
shedaniel 5 years ago
parent
commit
aa372c8c5c

+ 1 - 1
build.gradle

@@ -3,7 +3,7 @@ import net.fabricmc.loom.task.RemapJarTask
 import java.text.SimpleDateFormat
 import java.text.SimpleDateFormat
 
 
 plugins {
 plugins {
-    id 'fabric-loom' version '0.2.7-SNAPSHOT'
+    id 'fabric-loom' version '0.4.3'
     id 'maven-publish'
     id 'maven-publish'
     id 'net.minecrell.licenser' version '0.4.1'
     id 'net.minecrell.licenser' version '0.4.1'
     id 'com.matthewprenger.cursegradle' version '1.4.0'
     id 'com.matthewprenger.cursegradle' version '1.4.0'

+ 1 - 1
gradle.properties

@@ -1,4 +1,4 @@
-mod_version=4.2.1-unstable
+mod_version=4.2.2-unstable
 supported_version=20w17a
 supported_version=20w17a
 minecraft_version=20w17a
 minecraft_version=20w17a
 yarn_version=20w17a+build.2
 yarn_version=20w17a+build.2

+ 2 - 0
src/main/java/me/shedaniel/rei/api/ConfigObject.java

@@ -155,4 +155,6 @@ public interface ConfigObject {
     
     
     @ApiStatus.Experimental
     @ApiStatus.Experimental
     boolean isSubsetsEnabled();
     boolean isSubsetsEnabled();
+    
+    boolean shouldResizeDynamically();
 }
 }

+ 9 - 8
src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java

@@ -223,17 +223,18 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen {
         this.preWidgets.clear();
         this.preWidgets.clear();
         this.widgets.clear();
         this.widgets.clear();
         this.largestWidth = width - 100;
         this.largestWidth = width - 100;
-        this.largestHeight = Math.max(height - 36, 100);
+        this.largestHeight = Math.max(height - 34 - 30, 100);
         int maxWidthDisplay = CollectionUtils.mapAndMax(getCurrentDisplayed(), selectedCategory::getDisplayWidth, Comparator.naturalOrder()).orElse(150);
         int maxWidthDisplay = CollectionUtils.mapAndMax(getCurrentDisplayed(), selectedCategory::getDisplayWidth, Comparator.naturalOrder()).orElse(150);
-        this.guiWidth = maxWidthDisplay + 20;
+        this.guiWidth = Math.max(maxWidthDisplay + 40, 0);
         this.guiHeight = MathHelper.floor(MathHelper.clamp((double) (selectedCategory.getDisplayHeight() + 4) * (getRecipesPerPage() + 1) + 36, 100, largestHeight));
         this.guiHeight = MathHelper.floor(MathHelper.clamp((double) (selectedCategory.getDisplayHeight() + 4) * (getRecipesPerPage() + 1) + 36, 100, largestHeight));
+        if (!ConfigObject.getInstance().shouldResizeDynamically()) this.guiHeight = largestHeight;
         this.tabsPerPage = Math.max(5, MathHelper.floor((guiWidth - 20d) / tabSize));
         this.tabsPerPage = Math.max(5, MathHelper.floor((guiWidth - 20d) / tabSize));
         if (this.categoryPages == -1) {
         if (this.categoryPages == -1) {
             this.categoryPages = Math.max(0, categories.indexOf(selectedCategory) / tabsPerPage);
             this.categoryPages = Math.max(0, categories.indexOf(selectedCategory) / tabsPerPage);
         }
         }
         this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - guiHeight / 2, guiWidth, guiHeight);
         this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - guiHeight / 2, guiWidth, guiHeight);
         this.page = MathHelper.clamp(page, 0, getTotalPages(selectedCategory) - 1);
         this.page = MathHelper.clamp(page, 0, getTotalPages(selectedCategory) - 1);
-        this.widgets.add(Widgets.createButton(new Rectangle(bounds.x + 2, bounds.y - 16, 10, 10), new TranslatableText("text.rei.left_arrow"))
+        this.widgets.add(Widgets.createButton(new Rectangle(bounds.x, bounds.y - 16, 10, 10), new TranslatableText("text.rei.left_arrow"))
                 .onClick(button -> {
                 .onClick(button -> {
                     categoryPages--;
                     categoryPages--;
                     if (categoryPages < 0)
                     if (categoryPages < 0)
@@ -241,7 +242,7 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen {
                     RecipeViewingScreen.this.init();
                     RecipeViewingScreen.this.init();
                 })
                 })
                 .enabled(categories.size() > tabsPerPage));
                 .enabled(categories.size() > tabsPerPage));
-        this.widgets.add(Widgets.createButton(new Rectangle(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10), new TranslatableText("text.rei.right_arrow"))
+        this.widgets.add(Widgets.createButton(new Rectangle(bounds.x + bounds.width - 10, bounds.y - 16, 10, 10), new TranslatableText("text.rei.right_arrow"))
                 .onClick(button -> {
                 .onClick(button -> {
                     categoryPages++;
                     categoryPages++;
                     if (categoryPages > MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1)
                     if (categoryPages > MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1)
@@ -283,7 +284,7 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen {
             RecipeViewingScreen.this.init();
             RecipeViewingScreen.this.init();
         }).onRender((matrices, label) -> {
         }).onRender((matrices, label) -> {
             label.setText(new LiteralText(String.format("%d/%d", page + 1, getTotalPages(selectedCategory))));
             label.setText(new LiteralText(String.format("%d/%d", page + 1, getTotalPages(selectedCategory))));
-            label.setClickable(categoriesMap.get(selectedCategory).size() > getRecipesPerPageByHeight());
+            label.setClickable(getTotalPages(selectedCategory) > 1);
         }).tooltipSupplier(label -> label.isClickable() ? I18n.translate("text.rei.choose_page") : null));
         }).tooltipSupplier(label -> label.isClickable() ? I18n.translate("text.rei.choose_page") : null));
         widgets.add(recipeNext = Widgets.createButton(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 19, 12, 12), new TranslatableText("text.rei.right_arrow"))
         widgets.add(recipeNext = Widgets.createButton(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 19, 12, 12), new TranslatableText("text.rei.right_arrow"))
                 .onClick(button -> {
                 .onClick(button -> {
@@ -292,8 +293,8 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen {
                         page = 0;
                         page = 0;
                     RecipeViewingScreen.this.init();
                     RecipeViewingScreen.this.init();
                 }).tooltipLine(I18n.translate("text.rei.next_page")));
                 }).tooltipLine(I18n.translate("text.rei.next_page")));
-        recipeBack.setEnabled(categoriesMap.get(selectedCategory).size() > getRecipesPerPageByHeight());
-        recipeNext.setEnabled(categoriesMap.get(selectedCategory).size() > getRecipesPerPageByHeight());
+        recipeBack.setEnabled(getTotalPages(selectedCategory) > 1);
+        recipeNext.setEnabled(getTotalPages(selectedCategory) > 1);
         int tabV = isCompactTabs ? 166 : 192;
         int tabV = isCompactTabs ? 166 : 192;
         for (int i = 0; i < tabsPerPage; i++) {
         for (int i = 0; i < tabsPerPage; i++) {
             int j = i + categoryPages * tabsPerPage;
             int j = i + categoryPages * tabsPerPage;
@@ -316,7 +317,7 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen {
             final RecipeDisplay display = currentDisplayed.get(i);
             final RecipeDisplay display = currentDisplayed.get(i);
             final Supplier<RecipeDisplay> displaySupplier = () -> display;
             final Supplier<RecipeDisplay> displaySupplier = () -> display;
             int displayWidth = selectedCategory.getDisplayWidth(displaySupplier.get());
             int displayWidth = selectedCategory.getDisplayWidth(displaySupplier.get());
-            final Rectangle displayBounds = new Rectangle(getBounds().getCenterX() - displayWidth / 2, getBounds().y - 2 + 36 + recipeHeight * i + 4 * i, displayWidth, recipeHeight);
+            final Rectangle displayBounds = new Rectangle(getBounds().getCenterX() - displayWidth / 2, getBounds().getCenterY() + 16 - recipeHeight * (getRecipesPerPage() + 1) / 2 - 2 * (getRecipesPerPage() + 1) + recipeHeight * i + 4 * i, displayWidth, recipeHeight);
             List<Widget> setupDisplay = selectedCategory.setupDisplay(display, displayBounds);
             List<Widget> setupDisplay = selectedCategory.setupDisplay(display, displayBounds);
             transformIngredientNotice(setupDisplay, ingredientStackToNotice);
             transformIngredientNotice(setupDisplay, ingredientStackToNotice);
             transformResultNotice(setupDisplay, resultStackToNotice);
             transformResultNotice(setupDisplay, resultStackToNotice);

+ 9 - 2
src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java

@@ -163,7 +163,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
     
     
     @Override
     @Override
     public int getMaxRecipePerPage() {
     public int getMaxRecipePerPage() {
-        return appearance.maxRecipePerPage;
+        return appearance.maxRecipesPerPage;
     }
     }
     
     
     @Override
     @Override
@@ -336,6 +336,11 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
         return experimental.isSubsetsEnabled;
         return experimental.isSubsetsEnabled;
     }
     }
     
     
+    @Override
+    public boolean shouldResizeDynamically() {
+        return appearance.resizeDynamically;
+    }
+    
     @Retention(RetentionPolicy.RUNTIME)
     @Retention(RetentionPolicy.RUNTIME)
     @Target({ElementType.FIELD})
     @Target({ElementType.FIELD})
     @interface DontApplyFieldName {}
     @interface DontApplyFieldName {}
@@ -381,7 +386,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
         private SearchFieldLocation searchFieldLocation = SearchFieldLocation.CENTER;
         private SearchFieldLocation searchFieldLocation = SearchFieldLocation.CENTER;
         @Comment("Declares the position of the item list panel.") private boolean mirrorItemPanel = false;
         @Comment("Declares the position of the item list panel.") private boolean mirrorItemPanel = false;
         @Comment("Declares the maximum amount of recipes displayed in a page if possible.") @ConfigEntry.BoundedDiscrete(min = 2, max = 99)
         @Comment("Declares the maximum amount of recipes displayed in a page if possible.") @ConfigEntry.BoundedDiscrete(min = 2, max = 99)
-        private int maxRecipePerPage = 3;
+        private int maxRecipesPerPage = 15;
         private boolean clickableRecipeArrows = true;
         private boolean clickableRecipeArrows = true;
         @Comment("Declares the appearance of recipe's border.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
         @Comment("Declares the appearance of recipe's border.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
         private RecipeBorderType recipeBorder = RecipeBorderType.DEFAULT;
         private RecipeBorderType recipeBorder = RecipeBorderType.DEFAULT;
@@ -395,6 +400,8 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
         @UsePercentage(min = 0.25, max = 4.0) private double entrySize = 1.0;
         @UsePercentage(min = 0.25, max = 4.0) private double entrySize = 1.0;
         private boolean useCompactTabs = true;
         private boolean useCompactTabs = true;
         private boolean lowerConfigButton = false;
         private boolean lowerConfigButton = false;
+        @Comment("Declares whether REI should resize its recipe window dynamically")
+        private boolean resizeDynamically = false;
     }
     }
     
     
     public static class Technical {
     public static class Technical {