diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index 19284ce1..fd33eaeb 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -229,9 +229,9 @@ public class NEIClientConfig { .getBooleanValue(true); API.addOption(new OptionToggleButtonBoubs("inventory.guirecipe.jeiStyleTabs", true)); - tag.getTag("inventory.guirecipe.jeiStyleRecipeCatalyst").setComment("Enable/disable JEI Style Recipe Catalysts") - .getBooleanValue(true); - API.addOption(new OptionToggleButton("inventory.guirecipe.jeiStyleRecipeCatalyst", true)); + tag.getTag("inventory.guirecipe.jeiStyleRecipeCatalyst") + .setComment("JEI Style Recipe Catalysts (0 - none, 1 - grid, 2 - scroll)").getIntValue(1); + API.addOption(new OptionCycled("inventory.guirecipe.jeiStyleRecipeCatalyst", 3, true)); tag.getTag("inventory.guirecipe.cycledIngredientsTooltip").setComment("Show cycled ingredients tooltip") .getBooleanValue(true); @@ -1105,8 +1105,8 @@ public class NEIClientConfig { return getBooleanSetting("inventory.guirecipe.slotHighlightPresent"); } - public static boolean areJEIStyleRecipeCatalystsVisible() { - return getBooleanSetting("inventory.guirecipe.jeiStyleRecipeCatalyst"); + public static int getJEIStyleRecipeCatalysts() { + return getIntSetting("inventory.guirecipe.jeiStyleRecipeCatalyst"); } public static boolean useCreativeTabStyle() { diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index b61ffb13..49f68a6a 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -65,8 +65,8 @@ public abstract class GuiRecipe extends GuiContainer i private static final int BUTTON_WIDTH = 13; private static final int BUTTON_HEIGHT = 12; - protected static final ScrollBar VERTICAL_SCROLLBAR = new ScrollBar().setScrollbarSize(14) - .setOverflowType(OverflowType.AUTO).setScrollPlace(ScrollPlace.OUTSIDE) + protected static final ScrollBar VERTICAL_SCROLLBAR = new ScrollBar().setScrollbarSize(14).setMarginStart(-6) + .setOverflowType(OverflowType.AUTO).setScrollPlace(ScrollPlace.END) .setTrackTexture(new DrawableBuilder("nei:textures/nei_sprites.png", 42, 90, 13, 21).build(), 9, 9) .setThumbTexture(new DrawableBuilder("nei:textures/nei_sprites.png", 21, 96, 8, 9).build(), 3, 2) .setThumbPadding(6); @@ -379,7 +379,7 @@ public abstract class GuiRecipe extends GuiContainer i } else { this.container.setVerticalScroll( ScrollBar.defaultVerticalBar().setOverflowType(OverflowType.OVERLAY) - .setScrollPlace(ScrollPlace.OUTSIDE)); + .setScrollPlace(ScrollPlace.END)); } } @@ -422,7 +422,6 @@ public abstract class GuiRecipe extends GuiContainer i GuiRecipe.toggleSearch.state = 0; this.container.setVerticalScrollOffset(0); - this.container.setHorizontalScrollOffset(0); this.page = Math.min(Math.max(0, refIndex), this.numRecipes() - 1) / getRecipesPerPage(); changePage(0); @@ -709,10 +708,10 @@ public abstract class GuiRecipe extends GuiContainer i refreshPage(); this.container.update(); - this.recipeCatalyst.setAvailableHeight(this.container.h); - this.recipeCatalyst.update(); + this.recipeCatalyst.setAvailableHeight(this.ySize - 5); this.recipeCatalyst.y = this.guiTop; - this.recipeCatalyst.x = this.guiLeft - this.recipeCatalyst.w + 6; + this.recipeCatalyst.x = this.guiLeft - this.recipeCatalyst.w + 4; + this.recipeCatalyst.update(); } @Override @@ -832,7 +831,6 @@ public abstract class GuiRecipe extends GuiContainer i if (this.page != oldPage) { this.container.setVerticalScrollOffset(0); - this.container.setHorizontalScrollOffset(0); } } @@ -864,6 +862,11 @@ public abstract class GuiRecipe extends GuiContainer i public void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { GL11.glTranslatef(-guiLeft, -guiTop, 0); this.container.draw(mouseX, mouseY); + + if (NEIClientConfig.getJEIStyleRecipeCatalysts() != 0 && this.recipeCatalyst.isShowWidget()) { + this.recipeCatalyst.draw(mouseX, mouseY); + } + GL11.glTranslatef(guiLeft, guiTop, 0); } @@ -940,11 +943,6 @@ public abstract class GuiRecipe extends GuiContainer i RenderHelper.enableGUIStandardItemLighting(); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f); this.recipeTabs.draw(mouseX, mouseY); - - if (NEIClientConfig.areJEIStyleRecipeCatalystsVisible()) { - this.recipeCatalyst.draw(mouseX, mouseY); - } - RenderHelper.disableStandardItemLighting(); } } @@ -1027,7 +1025,7 @@ public abstract class GuiRecipe extends GuiContainer i final Rectangle4i rect = new Rectangle4i(x, y, w, h); // Because some of the handlers *cough avaritia* are oversized - if (this.recipeCatalyst.isShowWidget() && this.recipeCatalyst.bounds().intersects(rect)) { + if (this.recipeCatalyst.isShowWidget() && this.recipeCatalyst.boundsOutside().intersects(rect)) { return true; } diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipeCatalyst.java b/src/main/java/codechicken/nei/recipe/GuiRecipeCatalyst.java index bc6fc09e..e129239c 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipeCatalyst.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipeCatalyst.java @@ -3,13 +3,10 @@ package codechicken.nei.recipe; import java.util.ArrayList; import java.util.List; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.item.ItemStack; - import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; import codechicken.lib.gui.GuiDraw; +import codechicken.nei.NEIClientConfig; import codechicken.nei.NEIClientUtils; import codechicken.nei.NEIServerUtils; import codechicken.nei.PositionedStack; @@ -18,8 +15,37 @@ import codechicken.nei.api.ShortcutInputHandler; import codechicken.nei.drawable.DrawableBuilder; import codechicken.nei.drawable.DrawableResource; import codechicken.nei.guihook.GuiContainerManager; +import codechicken.nei.scroll.ScrollBar; +import codechicken.nei.scroll.ScrollContainer; -public class GuiRecipeCatalyst extends Widget { +public class GuiRecipeCatalyst extends ScrollContainer { + + protected static class ItemStackWidget extends Widget { + + private final PositionedStack pStack; + + public ItemStackWidget(PositionedStack pStack) { + this.pStack = pStack; + this.x = pStack.relx; + this.y = pStack.rely; + this.w = SLOT_SIZE; + this.h = SLOT_SIZE; + } + + @Override + public void draw(int mx, int my) { + GuiContainerManager.drawItem(this.x, this.y, this.pStack.item); + + if (contains(mx, my)) { + NEIClientUtils.gl2DRenderContext(() -> GuiDraw.drawRect(this.x, this.y, this.w, this.h, 0x80FFFFFF)); + } + } + + @Override + public boolean handleClick(int mx, int my, int button) { + return ShortcutInputHandler.handleMouseClick(this.pStack.item); + } + } private static final int SLOT_SIZE = 16; private static final int BORDER_PADDING = 6; @@ -33,17 +59,29 @@ public class GuiRecipeCatalyst extends Widget { private static final DrawableResource FG_TEXTURE = new DrawableBuilder("nei:textures/slot.png", 0, 0, 18, 18) .setTextureSize(18, 18).build(); + private static final ScrollBar VERTICAL_SCROLLBAR = ScrollBar.defaultVerticalBar() + .setOverflowType(ScrollBar.OverflowType.AUTO).setMarginStart(BORDER_PADDING).setMarginEnd(BORDER_PADDING) + .setPadding(-13).setScrollPlace(ScrollBar.ScrollPlace.START); + private final List items = new ArrayList<>(); - private int availableHeight = 0; private boolean showWidget = false; + private int availableHeight = 0; + + public GuiRecipeCatalyst() { + setPaddingBlock(BORDER_PADDING + 1, BORDER_PADDING + 1); + } public void setCatalysts(List items) { this.items.clear(); this.items.addAll(items); + createWidgets(); } public void setAvailableHeight(int height) { - this.availableHeight = height; + if (this.availableHeight != height) { + this.availableHeight = height; + createWidgets(); + } } public int getAvailableHeight() { @@ -55,8 +93,11 @@ public class GuiRecipeCatalyst extends Widget { } public int getColumnCount() { - final int maxItemsPerColumn = Math.max(0, this.availableHeight - 2 - BORDER_PADDING * 2) / SLOT_SIZE; - return maxItemsPerColumn > 0 ? NEIServerUtils.divideCeil(this.items.size(), maxItemsPerColumn) : 0; + if (NEIClientConfig.getJEIStyleRecipeCatalysts() == 1) { + final int maxItemsPerColumn = Math.max(0, this.availableHeight - 2 - BORDER_PADDING * 2) / SLOT_SIZE; + return maxItemsPerColumn > 0 ? NEIServerUtils.divideCeil(this.items.size(), maxItemsPerColumn) : 0; + } + return 1; } public int getRowCount() { @@ -64,20 +105,35 @@ public class GuiRecipeCatalyst extends Widget { return columnCount > 0 ? NEIServerUtils.divideCeil(this.items.size(), columnCount) : 0; } - @Override - public void update() { + protected void createWidgets() { final int columns = getColumnCount(); final int rows = getRowCount(); + setVerticalScroll(null); + setPaddingInline(BORDER_PADDING + 1, BORDER_PADDING - 3); + + this.h = rows * SLOT_SIZE + this.paddingBlockStart + this.paddingBlockEnd; + this.w = columns * SLOT_SIZE + this.paddingInlineStart + this.paddingInlineEnd; + + if (NEIClientConfig.getJEIStyleRecipeCatalysts() == 2 + && rows * SLOT_SIZE + this.paddingBlockStart + this.paddingBlockEnd > this.availableHeight) { + this.h = Math.min(this.h, this.availableHeight); + this.w += VERTICAL_SCROLLBAR.getScrollbarSize(); + + setVerticalScroll(VERTICAL_SCROLLBAR); + setPaddingInline(BORDER_PADDING + 1 + VERTICAL_SCROLLBAR.getScrollbarSize(), this.paddingInlineEnd); + } + this.showWidget = rows * columns > 0; - this.w = columns * SLOT_SIZE + 2 + BORDER_PADDING * 2; - this.h = rows * SLOT_SIZE + 2 + BORDER_PADDING * 2; if (rows == 0 || columns == 0) { return; } + final int visibleWidth = getVisibleWidth(); + final List widgets = new ArrayList<>(); int index = 0; + for (PositionedStack pStack : this.items) { if (pStack.items.length > 1) { @@ -86,75 +142,45 @@ public class GuiRecipeCatalyst extends Widget { pStack.setPermutationToRender(stackIndex); } - pStack.relx = this.w - BORDER_PADDING - 1 - SLOT_SIZE - (index / rows) * SLOT_SIZE; - pStack.rely = BORDER_PADDING + 1 + (index % rows) * SLOT_SIZE; + pStack.relx = visibleWidth - SLOT_SIZE - (index / rows) * SLOT_SIZE; + pStack.rely = (index % rows) * SLOT_SIZE; index++; + + widgets.add(new ItemStackWidget(pStack)); } + setWidgets(widgets); } @Override public void draw(int mx, int my) { if (!this.showWidget) return; - GL11.glTranslatef(this.x, this.y, 0); GL11.glColor4f(1, 1, 1, 1); - - BG_TEXTURE.draw(0, 0, this.w, this.h, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING); + BG_TEXTURE.draw(this.x, this.y, this.w, this.h, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING); FG_TEXTURE.draw( - BORDER_PADDING, - BORDER_PADDING, - this.w - BORDER_PADDING * 2, - this.h - BORDER_PADDING * 2, + this.x + this.paddingInlineStart - 1, + this.y + this.paddingBlockStart - 1, + this.w - this.paddingInlineStart - this.paddingInlineEnd + 2, + this.h - this.paddingBlockStart - this.paddingBlockEnd + 2, 1, 1, 1, 1); - GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_LIGHTING_BIT); - RenderHelper.enableGUIStandardItemLighting(); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - - for (PositionedStack pStack : this.items) { - GuiContainerManager.drawItem(pStack.relx, pStack.rely, pStack.item); - - if (pStack.contains(mx - this.x, my - this.y)) { - NEIClientUtils.gl2DRenderContext( - () -> GuiDraw.drawRect(pStack.relx, pStack.rely, SLOT_SIZE, SLOT_SIZE, -2130706433)); - } - } - - GL11.glPopAttrib(); - GL11.glTranslatef(-this.x, -this.y, 0); + super.draw(mx, my); } public PositionedStack getPositionedStackMouseOver(int mx, int my) { + final Widget widget = getWidgetUnderMouse(mx, my); - for (PositionedStack pStack : this.items) { - if (pStack.contains(mx - this.x, my - this.y)) { - return pStack; - } + if (widget instanceof ItemStackWidget stackWidget) { + return stackWidget.pStack; } return null; } - @Override - public ItemStack getStackMouseOver(int mx, int my) { - final PositionedStack pStack = getPositionedStackMouseOver(mx, my); - - if (pStack != null) { - return pStack.item; - } - - return null; - } - - @Override - public boolean handleClick(int mx, int my, int button) { - return ShortcutInputHandler.handleMouseClick(getStackMouseOver(mx, my)); - } - @Deprecated public static final int ingredientSize = 16; @Deprecated diff --git a/src/main/java/codechicken/nei/recipe/GuiUsageRecipe.java b/src/main/java/codechicken/nei/recipe/GuiUsageRecipe.java index de27c077..0e00ddce 100644 --- a/src/main/java/codechicken/nei/recipe/GuiUsageRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiUsageRecipe.java @@ -99,7 +99,7 @@ public class GuiUsageRecipe extends GuiRecipe { private static IUsageHandler getUsageOrCatalystHandler(IUsageHandler handler, String inputId, Object... ingredients) { boolean skipCatalyst = NEIClientUtils.controlKey(); - if (NEIClientConfig.areJEIStyleRecipeCatalystsVisible() && !skipCatalyst) { + if (NEIClientConfig.getJEIStyleRecipeCatalysts() != 0 && !skipCatalyst) { return handler.getUsageAndCatalystHandler(inputId, ingredients); } else { return handler.getUsageHandler(inputId, ingredients); diff --git a/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java b/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java index d8a783c4..e08dc6b7 100644 --- a/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java +++ b/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java @@ -182,7 +182,7 @@ public class NEIRecipeWidget extends Widget { GuiContainerManager.drawItem(pStack.relx, pStack.rely, pStack.item); if (pStack.contains(mouseX - this.x, mouseY - this.y - yShift)) { - NEIClientUtils.gl2DRenderContext(() -> GuiDraw.drawRect(pStack.relx, pStack.rely, 16, 16, -2130706433)); + NEIClientUtils.gl2DRenderContext(() -> GuiDraw.drawRect(pStack.relx, pStack.rely, 16, 16, 0x80FFFFFF)); } } @@ -190,7 +190,7 @@ public class NEIRecipeWidget extends Widget { GuiContainerManager.drawItem(pStack.relx, pStack.rely, pStack.item); if (pStack.contains(mouseX - this.x, mouseY - this.y - yShift)) { - NEIClientUtils.gl2DRenderContext(() -> GuiDraw.drawRect(pStack.relx, pStack.rely, 16, 16, -2130706433)); + NEIClientUtils.gl2DRenderContext(() -> GuiDraw.drawRect(pStack.relx, pStack.rely, 16, 16, 0x80FFFFFF)); } } @@ -199,7 +199,7 @@ public class NEIRecipeWidget extends Widget { GuiContainerManager.drawItem(pStackResult.relx, pStackResult.rely, pStackResult.item); if (pStackResult.contains(mouseX - this.x, mouseY - this.y - yShift)) { NEIClientUtils.gl2DRenderContext( - () -> GuiDraw.drawRect(pStackResult.relx, pStackResult.rely, 16, 16, -2130706433)); + () -> GuiDraw.drawRect(pStackResult.relx, pStackResult.rely, 16, 16, 0x80FFFFFF)); } } diff --git a/src/main/java/codechicken/nei/scroll/ScrollBar.java b/src/main/java/codechicken/nei/scroll/ScrollBar.java index 06ef7bc4..4f18d754 100644 --- a/src/main/java/codechicken/nei/scroll/ScrollBar.java +++ b/src/main/java/codechicken/nei/scroll/ScrollBar.java @@ -31,18 +31,21 @@ public class ScrollBar { } public enum ScrollPlace { - INSIDE, - OUTSIDE + START, + END } private ScrollType scrollType = ScrollType.VERTICAL; private OverflowType overflowType = OverflowType.SCROLL; - private ScrollPlace scrollPlace = ScrollPlace.INSIDE; + private ScrollPlace scrollPlace = ScrollPlace.END; private float handleClickOffset = -1; private int scrollbarSize = 6; private int thumbPadding = 0; - private int margin = 0; + + private int padding = 0; + private int marginStart = 0; + private int marginEnd = 0; private DrawableResource thumbTexture; private int thumbSliceStart; @@ -58,14 +61,13 @@ public class ScrollBar { public static ScrollBar defaultVerticalBar() { return new ScrollBar().setScrollbarSize(8) - .setTrackTexture(new DrawableBuilder("nei:textures/nei_sprites.png", 29, 95, 12, 11).build(), 3, 4) - .setThumbTexture(new DrawableBuilder("nei:textures/nei_sprites.png", 21, 96, 8, 9).build(), 3, 2) + .setTrackTexture(new DrawableBuilder("nei:textures/nei_sprites.png", 28, 95, 11, 11).build(), 3, 4) + .setThumbTexture(new DrawableBuilder("nei:textures/nei_sprites.png", 21, 96, 7, 9).build(), 3, 2) .setThumbPadding(1); } public static ScrollBar defaultHorizontalBar() { - return new ScrollBar().setScrollbarSize(8).setOverflowType(OverflowType.SCROLL) - .setScrollPlace(ScrollPlace.INSIDE) + return new ScrollBar().setScrollbarSize(8).setOverflowType(OverflowType.SCROLL).setScrollPlace(ScrollPlace.END) .setTrackTexture(new DrawableBuilder("nei:textures/nei_sprites.png", 0, 97, 11, 8).build(), 3, 4) .setThumbTexture(new DrawableBuilder("nei:textures/nei_sprites.png", 12, 97, 9, 7).build(), 3, 2) .setThumbPadding(1); @@ -81,13 +83,31 @@ public class ScrollBar { return this; } - public ScrollBar setMargin(int margin) { - this.margin = margin; + public ScrollBar setPadding(int padding) { + this.padding = padding; return this; } - public int getMargin() { - return this.margin; + public int getPadding() { + return this.padding; + } + + public ScrollBar setMarginStart(int start) { + this.marginStart = start; + return this; + } + + public int getMarginStart() { + return this.marginStart; + } + + public ScrollBar setMarginEnd(int end) { + this.marginEnd = end; + return this; + } + + public int getMarginEnd() { + return this.marginEnd; } public int getScrollbarSize() { @@ -153,22 +173,9 @@ public class ScrollBar { private int getMaxTrackSize(ScrollContainer container) { if (this.scrollType == ScrollType.HORIZONTAL) { - int visibleSize = container.w; - - if (container.canScrollVertical() && container.getVerticalScroll().getScrollPlace() == ScrollPlace.INSIDE) { - visibleSize -= container.getVerticalScroll().getScrollbarSize(); - } - - return visibleSize; + return container.w - this.marginStart - this.marginEnd; } else { - int visibleSize = container.h; - - if (container.canScrollHorizontal() - && container.getHorizontalScroll().getScrollPlace() == ScrollPlace.INSIDE) { - visibleSize -= container.getHorizontalScroll().getScrollbarSize(); - } - - return visibleSize; + return container.h - this.marginStart - this.marginEnd; } } @@ -205,23 +212,41 @@ public class ScrollBar { } public Rectangle4i trackBounds(ScrollContainer container) { + if (this.scrollType == ScrollType.HORIZONTAL) { - return new Rectangle4i( - container.x, - container.y + container.h - + this.margin - - (this.scrollPlace == ScrollPlace.INSIDE ? scrollbarSize : 0), - getMaxTrackSize(container), - scrollbarSize); + + if (this.scrollPlace == ScrollPlace.START) { + return new Rectangle4i( + container.x + this.marginStart, + container.y - this.padding - this.scrollbarSize, + getMaxTrackSize(container), + this.scrollbarSize); + } else { + return new Rectangle4i( + container.x + this.marginStart, + container.y + container.h + this.padding, + getMaxTrackSize(container), + this.scrollbarSize); + } + } else { - return new Rectangle4i( - container.x + container.w - + this.margin - - (this.scrollPlace == ScrollPlace.INSIDE ? scrollbarSize : 0), - container.y, - scrollbarSize, - getMaxTrackSize(container)); + + if (this.scrollPlace == ScrollPlace.START) { + return new Rectangle4i( + container.x - this.padding - this.scrollbarSize, + container.y + this.marginStart, + this.scrollbarSize, + getMaxTrackSize(container)); + } else { + return new Rectangle4i( + container.x + container.w + this.padding, + container.y + this.marginStart, + this.scrollbarSize, + getMaxTrackSize(container)); + } + } + } public Rectangle4i thumbBounds(ScrollContainer container) { @@ -388,9 +413,36 @@ public class ScrollBar { GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); if (this.scrollType == ScrollType.HORIZONTAL) { - texture.draw(bounds.x, bounds.y, bounds.w, texture.getHeight(), sliceStart, sliceEnd, 0, 0); + + if (this.scrollPlace == ScrollPlace.START) { + texture.draw( + bounds.x, + bounds.y + (bounds.h - texture.getHeight()) / 2, + bounds.w, + texture.getHeight(), + sliceStart, + sliceEnd, + 0, + 0); + } else { + texture.draw(bounds.x, bounds.y, bounds.w, texture.getHeight(), sliceStart, sliceEnd, 0, 0); + } + } else { - texture.draw(bounds.x, bounds.y, texture.getWidth(), bounds.h, 0, 0, sliceStart, sliceEnd); + + if (this.scrollPlace == ScrollPlace.START) { + texture.draw( + bounds.x + (bounds.w - texture.getWidth()) / 2, + bounds.y, + texture.getWidth(), + bounds.h, + 0, + 0, + sliceStart, + sliceEnd); + } else { + texture.draw(bounds.x, bounds.y, texture.getWidth(), bounds.h, 0, 0, sliceStart, sliceEnd); + } } } diff --git a/src/main/java/codechicken/nei/scroll/ScrollContainer.java b/src/main/java/codechicken/nei/scroll/ScrollContainer.java index 5c6ad1cc..28143d21 100644 --- a/src/main/java/codechicken/nei/scroll/ScrollContainer.java +++ b/src/main/java/codechicken/nei/scroll/ScrollContainer.java @@ -14,7 +14,6 @@ import codechicken.nei.NEIClientUtils; import codechicken.nei.Widget; import codechicken.nei.WidgetContainer; import codechicken.nei.scroll.ScrollBar.OverflowType; -import codechicken.nei.scroll.ScrollBar.ScrollPlace; import codechicken.nei.scroll.ScrollBar.ScrollType; public class ScrollContainer extends WidgetContainer { @@ -34,8 +33,10 @@ public class ScrollContainer extends WidgetContainer { protected int actualWidth = 0; protected int actualHeight = 0; - protected int marginInline = 0; - protected int marginBlock = 0; + protected int paddingInlineStart = 0; + protected int paddingInlineEnd = 0; + protected int paddingBlockStart = 0; + protected int paddingBlockEnd = 0; protected final Map relativePostion = new HashMap<>(); protected ScrollBar horizontalScrollBar; @@ -45,30 +46,36 @@ public class ScrollContainer extends WidgetContainer { public Rectangle4i boundsOutside() { int width = this.w; int height = this.h; + int x = this.x; + int y = this.y; if (canScrollVertical() && (this.verticalScrollBar.getOverflowType() == OverflowType.SCROLL || this.verticalScrollBar.getOverflowType() == OverflowType.AUTO)) { - width += this.verticalScrollBar.getMargin(); - - if (this.verticalScrollBar.getScrollPlace() == ScrollPlace.OUTSIDE) { - width += this.verticalScrollBar.getScrollbarSize(); - } + final Rectangle4i trackBounds = this.verticalScrollBar.trackBounds(this); + x = Math.min(x, trackBounds.x); + y = Math.min(y, trackBounds.y); + height = Math.max(this.y + height, trackBounds.y + trackBounds.h) - y; + width = Math.max(this.x + width, trackBounds.x + trackBounds.w) - x; } if (canScrollHorizontal() && (this.horizontalScrollBar.getOverflowType() == OverflowType.SCROLL || this.horizontalScrollBar.getOverflowType() == OverflowType.AUTO)) { - height += this.horizontalScrollBar.getMargin(); - - if (this.horizontalScrollBar.getScrollPlace() == ScrollPlace.OUTSIDE) { - height += this.horizontalScrollBar.getScrollbarSize(); - } + final Rectangle4i trackBounds = this.horizontalScrollBar.trackBounds(this); + x = Math.min(x, trackBounds.x); + y = Math.min(y, trackBounds.y); + height = Math.max(this.y + height, trackBounds.y + trackBounds.h) - y; + width = Math.max(this.x + width, trackBounds.x + trackBounds.w) - x; } return new Rectangle4i(x, y, width, height); } public Rectangle4i boundsInside() { - return new Rectangle4i(x, y, getVisibleWidth(), getVisibleHeight()); + return new Rectangle4i( + x + this.paddingInlineStart, + y + this.paddingBlockStart, + getVisibleWidth(), + getVisibleHeight()); } @Override @@ -92,31 +99,18 @@ public class ScrollContainer extends WidgetContainer { return this.relativePostion.get(widget); } - public void setMarginInline(int marginInline) { - this.marginInline = marginInline; + public void setPaddingInline(int start, int end) { + this.paddingInlineStart = start; + this.paddingInlineEnd = end; } - public void setMarginBlock(int marginBlock) { - this.marginBlock = marginBlock; - } - - public int getMarginInline() { - return this.marginInline; - } - - public int getMarginBlock() { - return this.marginBlock; + public void setPaddingBlock(int start, int end) { + this.paddingBlockStart = start; + this.paddingBlockEnd = end; } public int getVisibleWidth() { - - if (canScrollVertical() && this.verticalScrollBar.getScrollPlace() == ScrollPlace.INSIDE - && (this.verticalScrollBar.getOverflowType() == OverflowType.SCROLL - || this.verticalScrollBar.getOverflowType() == OverflowType.AUTO)) { - return this.w - this.verticalScrollBar.getScrollbarSize(); - } - - return this.w; + return this.w - this.paddingInlineStart - this.paddingInlineEnd; } public int getActualWidth() { @@ -125,7 +119,7 @@ public class ScrollContainer extends WidgetContainer { public boolean setHorizontalScrollOffset(int offset) { - if (!canScrollHorizontal() && this.w < getActualWidth()) { + if (!canScrollHorizontal() && getVisibleWidth() < getActualWidth()) { offset = 0; } @@ -150,9 +144,9 @@ public class ScrollContainer extends WidgetContainer { } public boolean canScrollHorizontal() { - return this.horizontalScrollBar != null - && (this.horizontalScrollBar.getOverflowType() != OverflowType.NONE && this.w < getActualWidth() - || this.horizontalScrollBar.getOverflowType() == OverflowType.SCROLL); + return this.horizontalScrollBar != null && (this.horizontalScrollBar.getOverflowType() != OverflowType.NONE + && getVisibleWidth() < getActualWidth() + || this.horizontalScrollBar.getOverflowType() == OverflowType.SCROLL); } public ScrollBar getHorizontalScroll() { @@ -174,14 +168,7 @@ public class ScrollContainer extends WidgetContainer { } public int getVisibleHeight() { - - if (canScrollHorizontal() && this.horizontalScrollBar.getScrollPlace() == ScrollPlace.INSIDE - && (this.horizontalScrollBar.getOverflowType() == OverflowType.SCROLL - || this.horizontalScrollBar.getOverflowType() == OverflowType.AUTO)) { - return this.h - this.horizontalScrollBar.getScrollbarSize(); - } - - return this.h; + return this.h - this.paddingBlockStart - this.paddingBlockEnd; } public int getActualHeight() { @@ -190,7 +177,7 @@ public class ScrollContainer extends WidgetContainer { public boolean setVerticalScrollOffset(int offset) { - if (!canScrollVertical() && this.h < getActualHeight()) { + if (!canScrollVertical() && getVisibleHeight() < getActualHeight()) { offset = 0; } @@ -215,9 +202,9 @@ public class ScrollContainer extends WidgetContainer { } public boolean canScrollVertical() { - return this.verticalScrollBar != null - && (this.verticalScrollBar.getOverflowType() != OverflowType.NONE && this.h < getActualHeight() - || this.verticalScrollBar.getOverflowType() == OverflowType.SCROLL); + return this.verticalScrollBar != null && (this.verticalScrollBar.getOverflowType() != OverflowType.NONE + && getVisibleHeight() < getActualHeight() + || this.verticalScrollBar.getOverflowType() == OverflowType.SCROLL); } public ScrollBar getVerticalScroll() { @@ -245,10 +232,10 @@ public class ScrollContainer extends WidgetContainer { if (canScrollVertical || canScrollHorizontal) { GuiHelper.useScissor( - this.x, - this.y, - getVisibleWidth(), - getVisibleHeight(), + this.x + this.paddingInlineStart, + this.y + this.paddingBlockStart, + this.w - this.paddingInlineStart - this.paddingInlineEnd, + this.h - this.paddingBlockStart - this.paddingBlockEnd, () -> drawContent(mousex, mousey)); GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_LIGHTING_BIT); @@ -295,12 +282,15 @@ public class ScrollContainer extends WidgetContainer { super.update(); - for (Widget widget : this.widgets) { - this.actualWidth = Math.max(this.actualWidth, widget.x + widget.w + this.marginInline * 2); - this.actualHeight = Math.max(this.actualHeight, widget.y + widget.h + this.marginBlock * 2); + final int x = this.x + this.paddingInlineStart - this.xScroll; + final int y = this.y + this.paddingBlockStart - this.yScroll; - widget.x += this.marginInline + this.x - this.xScroll; - widget.y += this.marginBlock + this.y - this.yScroll; + for (Widget widget : this.widgets) { + this.actualWidth = Math.max(this.actualWidth, widget.x + widget.w); + this.actualHeight = Math.max(this.actualHeight, widget.y + widget.h); + + widget.x += x; + widget.y += y; } if (this.fade > 0) { diff --git a/src/main/resources/assets/nei/lang/en_US.lang b/src/main/resources/assets/nei/lang/en_US.lang index fdedadcf..3da46163 100644 --- a/src/main/resources/assets/nei/lang/en_US.lang +++ b/src/main/resources/assets/nei/lang/en_US.lang @@ -282,8 +282,9 @@ nei.options.inventory.guirecipe.infiniteScroll=Use Infinite Scroll nei.options.inventory.guirecipe.infiniteScroll.true=Yes nei.options.inventory.guirecipe.infiniteScroll.false=No nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst=JEI Style Recipe Catalysts -nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.true=Yes -nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.false=No +nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.0=None +nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.1=Grid +nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.2=Scroll nei.options.inventory.guirecipe.cycledIngredientsTooltip=Cycled Ingredients Tooltip nei.options.inventory.guirecipe.cycledIngredientsTooltip.true=Show nei.options.inventory.guirecipe.cycledIngredientsTooltip.false=Hide diff --git a/src/main/resources/assets/nei/lang/ru_RU.lang b/src/main/resources/assets/nei/lang/ru_RU.lang index 0d6eb26b..4e950acb 100644 --- a/src/main/resources/assets/nei/lang/ru_RU.lang +++ b/src/main/resources/assets/nei/lang/ru_RU.lang @@ -199,8 +199,9 @@ nei.options.inventory.guirecipe.slotHighlightPresent=Подсвечивать п nei.options.inventory.guirecipe.slotHighlightPresent.true=Да nei.options.inventory.guirecipe.slotHighlightPresent.false=Нет nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst=Катализаторы рецептов в стиле JEI -nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.true=Да -nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.false=Нет +nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.0=Нет +nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.1=Грид +nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.2=Скролл nei.options.inventory.guirecipe.cycledIngredientsTooltip=Подсказка циклических ингредиентов nei.options.inventory.guirecipe.cycledIngredientsTooltip.true=Показывать nei.options.inventory.guirecipe.cycledIngredientsTooltip.false=Скрыть diff --git a/src/main/resources/assets/nei/lang/zh_CN.lang b/src/main/resources/assets/nei/lang/zh_CN.lang index d8c1a357..858e8c37 100644 --- a/src/main/resources/assets/nei/lang/zh_CN.lang +++ b/src/main/resources/assets/nei/lang/zh_CN.lang @@ -136,8 +136,6 @@ nei.options.inventory.guirecipe.jeiStyleTabs=JEI标签页 nei.options.inventory.guirecipe.jeiStyleTabs.true=是 nei.options.inventory.guirecipe.jeiStyleTabs.false=否 [不会吧] nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst=JEI风格可执行合成表机器显示[测试中] -nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.true=是 -nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.false=否 nei.options.inventory.bookmarks.animation=REI风格书签动画 nei.options.inventory.bookmarks.animation.true=是 nei.options.inventory.bookmarks.animation.false=否 diff --git a/src/main/resources/assets/nei/textures/catalyst_tab.png b/src/main/resources/assets/nei/textures/catalyst_tab.png index e7ccbe87..ef3cf064 100644 Binary files a/src/main/resources/assets/nei/textures/catalyst_tab.png and b/src/main/resources/assets/nei/textures/catalyst_tab.png differ