diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index 5c952ba2..03122b16 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -263,6 +263,10 @@ public class NEIClientConfig { .setComment("Require holding shift to move items when overlaying recipe").getBooleanValue(true); API.addOption(new OptionToggleButton("inventory.guirecipe.shiftOverlayRecipe", true)); + tag.getTag("inventory.guirecipe.scrollPages").setComment("Disable page scroll when overlaying recipe") + .getBooleanValue(true); + API.addOption(new OptionToggleButton("inventory.guirecipe.scrollPages", true)); + tag.getTag("inventory.guirecipe.profile").getBooleanValue(false); API.addOption(new OptionToggleButton("inventory.guirecipe.profile", true)); diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index 24b782ba..64aa3dda 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -92,6 +92,9 @@ public abstract class GuiRecipe extends GuiContainer i private GuiButton prevtype; private GuiButton nexttype; + private Rectangle typeArea = new Rectangle(); + private Rectangle pageArea = new Rectangle(); + private int lastPage = -1; private final GuiRecipeTabs recipeTabs; private final GuiRecipeCatalyst recipeCatalyst; @@ -358,8 +361,18 @@ public abstract class GuiRecipe extends GuiContainer i GuiRecipe.searchField.w = this.xSize - (BORDER_PADDING + BUTTON_WIDTH) * 2 + 1 - GuiRecipe.toggleSearch.w - 45; GuiRecipe.searchField.h = 14; - this.buttonList.addAll(Arrays.asList(this.prevtype, this.nexttype, this.prevpage, this.nextpage)); + this.typeArea.setBounds( + this.prevtype.xPosition + BUTTON_WIDTH, + this.prevtype.yPosition, + this.nexttype.xPosition - this.prevtype.xPosition - BUTTON_WIDTH - 1, + BUTTON_HEIGHT); + this.pageArea.setBounds( + GuiRecipe.toggleSearch.x + BUTTON_WIDTH, + this.prevpage.yPosition, + this.nextpage.xPosition - GuiRecipe.toggleSearch.x - BUTTON_WIDTH - 1, + BUTTON_HEIGHT); + this.buttonList.addAll(Arrays.asList(this.prevtype, this.nexttype, this.prevpage, this.nextpage)); if (this.currenthandlers.size() == 1) { this.prevtype.visible = false; this.nexttype.visible = false; @@ -377,8 +390,10 @@ public abstract class GuiRecipe extends GuiContainer i this.container.setWidgets(this.handlerPages.getCurrentPageWidgets()); if (!this.handlerInfo.isAllowOverflowX() && this.handlerInfo.getWidth() > this.xSize - 6) { + this.container.setPaddingInline(0, 2); this.container.setHorizontalScroll(ScrollBar.defaultHorizontalBar().setTrackPadding(1, 0, 1, 0)); } else { + this.container.setPaddingInline(0, 0); this.container.setHorizontalScroll(null); } @@ -691,7 +706,7 @@ public abstract class GuiRecipe extends GuiContainer i // If shift is held, try switching to the next recipe handler. Replicates the // GuiRecipeTabs.mouseScrolled() // without the checking for the cursor being inside the tabbar. - if (NEIClientUtils.shiftKey()) { + if (NEIClientUtils.shiftKey() || this.typeArea.contains(mouse)) { if (scroll < 0) { nextType(); } else { @@ -703,7 +718,11 @@ public abstract class GuiRecipe extends GuiContainer i // Finally, if nothing else has handled scrolling, try changing to the next // recipe page. - if (new Rectangle(this.guiLeft, this.guiTop, this.xSize, this.ySize).contains(mouse)) { + if (NEIClientConfig.getBooleanSetting("inventory.guirecipe.scrollPages") + && this.container.boundsInside().contains(mouse.x, mouse.y) + || this.pageArea.contains(mouse) + && (!GuiRecipe.searchField.isVisible() || !GuiRecipe.searchField.contains(mouse.x, mouse.y))) { + if (scroll > 0) { prevPage(); } else { @@ -845,16 +864,16 @@ public abstract class GuiRecipe extends GuiContainer i final int textMiddle = (BUTTON_WIDTH - this.fontRendererObj.FONT_HEIGHT) / 2; drawRect( - this.prevtype.xPosition + BUTTON_WIDTH - 1, - this.prevtype.yPosition, - this.nexttype.xPosition, - this.prevtype.yPosition + BUTTON_HEIGHT, + this.typeArea.x, + this.typeArea.y, + this.typeArea.x + this.typeArea.width, + this.typeArea.y + this.typeArea.height, 0x30000000); drawRect( - this.prevpage.xPosition + BUTTON_WIDTH - 1, - this.prevpage.yPosition, - this.nextpage.xPosition, - this.prevpage.yPosition + BUTTON_HEIGHT, + this.pageArea.x, + this.pageArea.y, + this.pageArea.x + this.pageArea.width, + this.pageArea.y + this.pageArea.height, 0x30000000); final String handlerTitle = this.handler.original.getRecipeName().trim(); @@ -863,7 +882,7 @@ public abstract class GuiRecipe extends GuiContainer i this.fontRendererObj, titleColorCode + handlerTitle + EnumChatFormatting.RESET, this.guiLeft + this.xSize / 2, - this.prevtype.yPosition + textMiddle, + this.typeArea.y + textMiddle, 0xffffff); if (this.handler.searchingAvailable()) { @@ -886,7 +905,7 @@ public abstract class GuiRecipe extends GuiContainer i this.fontRendererObj, recipePage, GuiRecipe.searchField.x + GuiRecipe.searchField.w + 22, - this.prevpage.yPosition + textMiddle, + this.pageArea.y + textMiddle, 0xffffff); } else { final String recipePage = NEIClientUtils.translate( @@ -897,7 +916,7 @@ public abstract class GuiRecipe extends GuiContainer i this.fontRendererObj, recipePage, this.guiLeft + this.xSize / 2, - this.prevpage.yPosition + textMiddle, + this.pageArea.y + textMiddle, 0xffffff); } diff --git a/src/main/java/codechicken/nei/recipe/debug/DebugHandlerWidget.java b/src/main/java/codechicken/nei/recipe/debug/DebugHandlerWidget.java index ce11958f..2cb59866 100644 --- a/src/main/java/codechicken/nei/recipe/debug/DebugHandlerWidget.java +++ b/src/main/java/codechicken/nei/recipe/debug/DebugHandlerWidget.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Consumer; +import java.util.function.IntPredicate; import java.util.regex.Matcher; import java.util.stream.Collectors; @@ -187,12 +188,12 @@ public class DebugHandlerWidget extends Widget { y = addTextFieldWidget("Order", 0, (field, oldText) -> { record.order = field.getInteger(); saveHandlerInfoPatch(); - }, y); + }, null, y); y = addTextFieldWidget("yShift", 0, (field, oldText) -> { record.yShift = field.getInteger(); saveHandlerInfoPatch(); - }, y); + }, null, y); y = addCheckboxWidget("MultiWidgets", button -> { record.multiWidgets = button.value; @@ -209,12 +210,12 @@ public class DebugHandlerWidget extends Widget { y = addTextFieldWidget("Height", HandlerInfo.DEFAULT_HEIGHT, (field, oldText) -> { record.height = field.getInteger(); saveHandlerInfoPatch(); - }, y); + }, newValue -> newValue > 0, y); y = addTextFieldWidget("Width", HandlerInfo.DEFAULT_WIDTH, (field, oldText) -> { record.width = field.getInteger(); saveHandlerInfoPatch(); - }, y); + }, newValue -> newValue >= HandlerInfo.DEFAULT_WIDTH, y); y = addCheckboxWidget("AllowOverflowX", button -> { record.allowOverflowX = button.value; @@ -263,9 +264,10 @@ public class DebugHandlerWidget extends Widget { return y + value.h + 1; } - private int addTextFieldWidget(String key, int defaultValue, BiConsumer onChange, int y) { + private int addTextFieldWidget(String key, int defaultValue, BiConsumer onChange, + IntPredicate validator, int y) { final LabelWidget label = new LabelWidget(0x888888, false); - final IntegerField value = new IntegerField(key, onChange, defaultValue); + final IntegerField value = new IntegerField(key, onChange, validator, defaultValue); label.y = value.y = y; value.w = 60; diff --git a/src/main/java/codechicken/nei/recipe/debug/IntegerField.java b/src/main/java/codechicken/nei/recipe/debug/IntegerField.java index 0ab1492d..9535516d 100644 --- a/src/main/java/codechicken/nei/recipe/debug/IntegerField.java +++ b/src/main/java/codechicken/nei/recipe/debug/IntegerField.java @@ -1,6 +1,7 @@ package codechicken.nei.recipe.debug; import java.util.function.BiConsumer; +import java.util.function.IntPredicate; import net.minecraft.client.Minecraft; @@ -13,10 +14,13 @@ public class IntegerField extends TextField implements IUpdatableWidget { protected int defaultValue = 0; protected BiConsumer onChange; + protected IntPredicate validator; - public IntegerField(String ident, BiConsumer onChange, int defaultValue) { + public IntegerField(String ident, BiConsumer onChange, IntPredicate validator, + int defaultValue) { super(ident); this.onChange = onChange; + this.validator = validator; this.defaultValue = defaultValue; this.h = 16; this.z = 2; @@ -68,8 +72,12 @@ public class IntegerField extends TextField implements IUpdatableWidget { } protected int getInteger() { + return getInteger(text()); + } + + protected int getInteger(String text) { try { - return Integer.parseInt(text()); + return Integer.parseInt(text); } catch (NumberFormatException nfe) { return this.defaultValue; } @@ -82,6 +90,13 @@ public class IntegerField extends TextField implements IUpdatableWidget { return true; } + @Override + public void setText(String newValue) { + if (validator == null || validator.test(getInteger(newValue))) { + super.setText(newValue); + } + } + public void updateValue(String newValue) { setText(newValue); } diff --git a/src/main/resources/assets/nei/lang/en_US.lang b/src/main/resources/assets/nei/lang/en_US.lang index 2d3f8971..d806e5c4 100644 --- a/src/main/resources/assets/nei/lang/en_US.lang +++ b/src/main/resources/assets/nei/lang/en_US.lang @@ -301,6 +301,11 @@ nei.options.inventory.guirecipe.handlerInfo=Handler Info Widget nei.options.inventory.guirecipe.handlerInfo.tip=Use shift+d while in the Recipes GUI nei.options.inventory.guirecipe.handlerInfo.true=Enabled nei.options.inventory.guirecipe.handlerInfo.false=Disabled + +nei.options.inventory.guirecipe.scrollPages=Scroll Pages +nei.options.inventory.guirecipe.scrollPages.true=Enabled +nei.options.inventory.guirecipe.scrollPages.false=Disabled + nei.options.inventory.guirecipe.maxHeight=Max Height nei.options.inventory.showItemQuantityWidget=Show Item Quantity Widget nei.options.inventory.showItemQuantityWidget.true=Yes