mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-08 12:34:46 +00:00
GuiRecipe: Add scrollPages Option (#929)
This commit is contained in:
1 parent
41554f4c5b
commit
4ffd614017
5 files changed
+67
-22
No files matched your search
@@ -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));
|
||||
|
||||
|
||||
@@ -92,6 +92,9 @@ public abstract class GuiRecipe<H extends IRecipeHandler> 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<H extends IRecipeHandler> 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<H extends IRecipeHandler> 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<H extends IRecipeHandler> 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<H extends IRecipeHandler> 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<H extends IRecipeHandler> 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<H extends IRecipeHandler> 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<H extends IRecipeHandler> 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<H extends IRecipeHandler> extends GuiContainer i
|
||||
this.fontRendererObj,
|
||||
recipePage,
|
||||
this.guiLeft + this.xSize / 2,
|
||||
this.prevpage.yPosition + textMiddle,
|
||||
this.pageArea.y + textMiddle,
|
||||
0xffffff);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<IntegerField, String> onChange, int y) {
|
||||
private int addTextFieldWidget(String key, int defaultValue, BiConsumer<IntegerField, String> 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;
|
||||
|
||||
@@ -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<IntegerField, String> onChange;
|
||||
protected IntPredicate validator;
|
||||
|
||||
public IntegerField(String ident, BiConsumer<IntegerField, String> onChange, int defaultValue) {
|
||||
public IntegerField(String ident, BiConsumer<IntegerField, String> 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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user