diff --git a/src/main/java/codechicken/nei/ColorUtils.java b/src/main/java/codechicken/nei/ColorUtils.java index ec5012e9..a45bf843 100644 --- a/src/main/java/codechicken/nei/ColorUtils.java +++ b/src/main/java/codechicken/nei/ColorUtils.java @@ -11,9 +11,11 @@ public class ColorUtils { textGray = color.rgb("textGray", "0x404040"), textLightGray = color.rgb("textLightGray", "0x606060"), recipeTitle = color.rgb("recipeTitle", "0xFFFFFF"), + recipeTitleBG = color.argb("recipeTitleBG", "0x30000000"), recipeTitleHover = color.rgb("recipeTitleHover", "0xFFFF55"), - subsetWidget = color.rgb("subsetWidget", "0xAA00AA"), recipeBadge = color.rgb("recipeBadge", "0xFDD835"), + + subsetWidget = color.rgb("subsetWidget", "0xAA00AA"), buttonLabelNormal = color.rgb("buttonLabelNormal", "0xE0E0E0"), buttonLabelHover = color.rgb("buttonLabelHover", "0xFFFFA0"), buttonLabelDisabled = color.rgb("buttonLabelDisabled", "0x601010"), diff --git a/src/main/java/codechicken/nei/LayoutStyleMinecraft.java b/src/main/java/codechicken/nei/LayoutStyleMinecraft.java index 14cc9cf8..a4c0f1f5 100644 --- a/src/main/java/codechicken/nei/LayoutStyleMinecraft.java +++ b/src/main/java/codechicken/nei/LayoutStyleMinecraft.java @@ -11,8 +11,9 @@ import codechicken.nei.api.LayoutStyle; public class LayoutStyleMinecraft extends LayoutStyle { - protected static final int BUTTON_SIZE = 20; - protected static final int MARGIN = 2; + public static final int BUTTON_SIZE = 20; + public static final int MARGIN = 2; + public static final int SUBSET_BAR_HEIGHT = 16; public int buttonCount; public int leftSize; @@ -147,7 +148,7 @@ public class LayoutStyleMinecraft extends LayoutStyle { LayoutManager.searchField.x += BUTTON_SIZE; LayoutManager.searchField.w -= BUTTON_SIZE; } else { - LayoutManager.dropDown.h = 16; + LayoutManager.dropDown.h = SUBSET_BAR_HEIGHT; LayoutManager.dropDown.w = 150; LayoutManager.dropDown.y = MARGIN; LayoutManager.dropDown.x = (gui.width - LayoutManager.dropDown.w) / 2; diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index 527edd70..6ece571c 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -59,6 +59,7 @@ import codechicken.nei.config.preset.GuiPresetList; import codechicken.nei.event.NEIConfigsLoadedEvent; import codechicken.nei.moboverlay.MobOverlayScan; import codechicken.nei.moboverlay.MobOverlayStyle; +import codechicken.nei.recipe.HandlerInfo; import codechicken.nei.recipe.IRecipeHandler; import codechicken.nei.recipe.InformationHandler; import codechicken.nei.recipe.RecipeCatalysts; @@ -270,9 +271,20 @@ public class NEIClientConfig { .getBooleanValue(false); API.addOption(new OptionToggleButton("inventory.guirecipe.infiniteScroll", true)); + tag.getTag("inventory.guirecipe.evenRecipeSpacing").setComment("Spread recipes evenly across the page height") + .getBooleanValue(true); + API.addOption(new OptionToggleButton("inventory.guirecipe.evenRecipeSpacing", true)); + + tag.getTag("inventory.guirecipe.topMargin").setComment("Recipe GUI Top Margin").getIntValue(0); + API.addOption(new OptionIntegerField("inventory.guirecipe.topMargin", 0, 200)); + tag.getTag("inventory.guirecipe.maxHeight").setComment("Recipe GUI Max Height").getIntValue(370); API.addOption(new OptionIntegerField("inventory.guirecipe.maxHeight", 166, 4000)); + tag.getTag("inventory.guirecipe.minWidth").setComment("Recipe GUI Min Width") + .getIntValue(HandlerInfo.DEFAULT_WIDTH); + API.addOption(new OptionIntegerField("inventory.guirecipe.minWidth", HandlerInfo.DEFAULT_WIDTH, 4000)); + tag.getTag("inventory.guirecipe.shiftOverlayRecipe") .setComment("Require holding shift to move items when overlaying recipe").getBooleanValue(true); API.addOption(new OptionToggleButton("inventory.guirecipe.shiftOverlayRecipe", true)); diff --git a/src/main/java/codechicken/nei/bookmark/tree/TreeOverlayButton.java b/src/main/java/codechicken/nei/bookmark/tree/TreeOverlayButton.java index 5becebf2..22df7f85 100644 --- a/src/main/java/codechicken/nei/bookmark/tree/TreeOverlayButton.java +++ b/src/main/java/codechicken/nei/bookmark/tree/TreeOverlayButton.java @@ -3,25 +3,15 @@ package codechicken.nei.bookmark.tree; import java.util.List; import java.util.Map; -import net.minecraft.client.Minecraft; - -import org.lwjgl.opengl.GL11; - import codechicken.nei.NEIClientUtils; -import codechicken.nei.drawable.DrawableBuilder; import codechicken.nei.drawable.DrawableResource; import codechicken.nei.recipe.GuiRecipeButton; import codechicken.nei.recipe.Recipe; import codechicken.nei.recipe.RecipeHandlerRef; +import codechicken.nei.theme.UIRecipeTexture; public class TreeOverlayButton extends GuiRecipeButton { - protected static final DrawableResource ICON_FILL = new DrawableBuilder( - "nei:textures/nei_sprites.png", - 28, - 76, - 9, - 10).build(); protected static final int BUTTON_ID_SHIFT = 4; public final GuiCraftingTree treeGui; @@ -50,16 +40,8 @@ public class TreeOverlayButton extends GuiRecipeButton { } @Override - protected void drawContent(Minecraft minecraft, int y, int x, boolean mouseOver) { - final int iconX = this.xPosition + (this.width - ICON_FILL.width - 1) / 2; - final int iconY = this.yPosition + (this.height - ICON_FILL.height) / 2; - - GL11.glColor4f(1, 1, 1, this.enabled ? 1 : 0.5f); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - ICON_FILL.draw(iconX, iconY); - GL11.glDisable(GL11.GL_BLEND); - GL11.glColor4f(1, 1, 1, 1); + protected DrawableResource getIcon() { + return UIRecipeTexture.ICON_OVERLAY_FILL; } @Override diff --git a/src/main/java/codechicken/nei/config/IMCHandler.java b/src/main/java/codechicken/nei/config/IMCHandler.java index d4eee409..16327f21 100644 --- a/src/main/java/codechicken/nei/config/IMCHandler.java +++ b/src/main/java/codechicken/nei/config/IMCHandler.java @@ -109,6 +109,8 @@ public class IMCHandler { info.setShowFavoritesButton(!tag.hasKey("showFavoritesButton") || tag.getBoolean("showFavoritesButton")); info.setShowOverlayButton(!tag.hasKey("showOverlayButton") || tag.getBoolean("showOverlayButton")); info.setShowBadge(tag.hasKey("showBadge") && tag.getBoolean("showBadge")); + info.setWindowWidth(tag.getInteger("windowWidth")); + info.setRecipeSpacing(tag.getBoolean("recipeSpacing")); GuiRecipeTab.handlerAdderFromIMC.remove(handler); GuiRecipeTab.handlerAdderFromIMC.put(handler, info); diff --git a/src/main/java/codechicken/nei/drawable/Drawable.java b/src/main/java/codechicken/nei/drawable/Drawable.java new file mode 100644 index 00000000..dc3f200d --- /dev/null +++ b/src/main/java/codechicken/nei/drawable/Drawable.java @@ -0,0 +1,57 @@ +package codechicken.nei.drawable; + +public interface Drawable { + + @FunctionalInterface + public interface Painter { + + public void draw(int x, int y, int width, int height); + } + + public int getWidth(); + + public int getHeight(); + + public void draw(int x, int y, int width, int height); + + default void draw(int x, int y) { + draw(x, y, getWidth(), getHeight()); + } + + public static Drawable of(int width, int height, Painter painter) { + return new Drawable() { + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + + @Override + public void draw(int x, int y, int w, int h) { + painter.draw(x, y, w, h); + } + }; + } + + // every layer is drawn into the whole rectangle, the first one at the bottom + public static Drawable stack(Drawable... layers) { + int width = 0; + int height = 0; + + for (Drawable layer : layers) { + width = Math.max(width, layer.getWidth()); + height = Math.max(height, layer.getHeight()); + } + + return of(width, height, (x, y, w, h) -> { + for (Drawable layer : layers) { + layer.draw(x, y, w, h); + } + }); + } +} diff --git a/src/main/java/codechicken/nei/drawable/DrawableResource.java b/src/main/java/codechicken/nei/drawable/DrawableResource.java index f48db978..ee1ca68d 100644 --- a/src/main/java/codechicken/nei/drawable/DrawableResource.java +++ b/src/main/java/codechicken/nei/drawable/DrawableResource.java @@ -8,7 +8,7 @@ import org.lwjgl.opengl.GL11; import codechicken.nei.Image; -public class DrawableResource extends Image { +public class DrawableResource extends Image implements Drawable { private final ResourceLocation resourceLocation; private final int textureWidth; diff --git a/src/main/java/codechicken/nei/recipe/GuiFavoriteButton.java b/src/main/java/codechicken/nei/recipe/GuiFavoriteButton.java index bdb71249..c2a3591e 100644 --- a/src/main/java/codechicken/nei/recipe/GuiFavoriteButton.java +++ b/src/main/java/codechicken/nei/recipe/GuiFavoriteButton.java @@ -11,8 +11,6 @@ import java.util.Set; import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; -import org.lwjgl.opengl.GL11; - import codechicken.lib.gui.GuiDraw; import codechicken.nei.BookmarkPanel.BookmarkViewMode; import codechicken.nei.FavoriteRecipes; @@ -24,28 +22,18 @@ import codechicken.nei.LayoutManager; import codechicken.nei.NEIClientConfig; import codechicken.nei.NEIClientUtils; import codechicken.nei.bookmark.tree.GuiCraftingTree; -import codechicken.nei.drawable.DrawableBuilder; import codechicken.nei.drawable.DrawableResource; import codechicken.nei.recipe.Recipe.RecipeId; import codechicken.nei.recipe.Recipe.RecipeIngredient; +import codechicken.nei.theme.UIRecipeTexture; import codechicken.nei.util.NEIMouseUtils; public class GuiFavoriteButton extends GuiRecipeButton { private static final int BUTTON_ID_START = 14; - protected static final DrawableResource ICON_STATE_OFF = new DrawableBuilder( - "nei:textures/nei_sprites.png", - 10, - 76, - 9, - 10).build(); - protected static final DrawableResource ICON_STATE_ON = new DrawableBuilder( - "nei:textures/nei_sprites.png", - 19, - 76, - 9, - 10).build(); + protected static final DrawableResource ICON_STATE_OFF = UIRecipeTexture.ICON_FAVORITE_OFF; + protected static final DrawableResource ICON_STATE_ON = UIRecipeTexture.ICON_FAVORITE_ON; protected final Recipe recipe; protected boolean favorite = false; @@ -94,17 +82,13 @@ public class GuiFavoriteButton extends GuiRecipeButton { } @Override - protected void drawContent(Minecraft minecraft, int y, int x, boolean mouseOver) { - final DrawableResource icon = isFavorite() ? ICON_STATE_ON : ICON_STATE_OFF; - final int iconX = this.xPosition + (this.width - icon.width - 1) / 2; - final int iconY = this.yPosition + (this.height - icon.height) / 2; + protected DrawableResource getIcon() { + return isFavorite() ? ICON_STATE_ON : ICON_STATE_OFF; + } - GL11.glColor4f(1, 1, 1, this.enabled ? 1 : 0.5f); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - icon.draw(iconX, iconY); - GL11.glDisable(GL11.GL_BLEND); - GL11.glColor4f(1, 1, 1, 1); + @Override + protected void drawContent(Minecraft minecraft, int mouseX, int mouseY, boolean mouseOver) { + super.drawContent(minecraft, mouseX, mouseY, mouseOver); if (!mouseOver) { this.selectedResult = null; diff --git a/src/main/java/codechicken/nei/recipe/GuiOverlayButton.java b/src/main/java/codechicken/nei/recipe/GuiOverlayButton.java index b9f2bc6b..5468c025 100644 --- a/src/main/java/codechicken/nei/recipe/GuiOverlayButton.java +++ b/src/main/java/codechicken/nei/recipe/GuiOverlayButton.java @@ -5,13 +5,10 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; -import org.lwjgl.opengl.GL11; - import codechicken.lib.gui.GuiDraw; import codechicken.nei.ItemPanels; import codechicken.nei.ItemsTooltipLineHandler; @@ -23,20 +20,14 @@ import codechicken.nei.PositionedStack; import codechicken.nei.api.IOverlayHandler; import codechicken.nei.bookmark.BookmarkGrid; import codechicken.nei.bookmark.BookmarkPayload; -import codechicken.nei.drawable.DrawableBuilder; import codechicken.nei.drawable.DrawableResource; +import codechicken.nei.theme.UIRecipeTexture; import codechicken.nei.util.NEIMouseUtils; public class GuiOverlayButton extends GuiRecipeButton { - protected static DrawableResource notPresent = new DrawableBuilder( - "nei:textures/nei_tabbed_sprites.png", - 0, - 40, - 8, - 8).build(); - protected static DrawableResource present = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 8, 40, 8, 8) - .build(); + protected static DrawableResource notPresent = UIRecipeTexture.ITEM_MISSING; + protected static DrawableResource present = UIRecipeTexture.ITEM_PRESENT; public enum ItemOverlayFormat { @@ -87,24 +78,9 @@ public class GuiOverlayButton extends GuiRecipeButton { } } - protected static final DrawableResource ICON_FILL = new DrawableBuilder( - "nei:textures/nei_sprites.png", - 28, - 76, - 9, - 10).build(); - protected static final DrawableResource ICON_FILL_ERROR = new DrawableBuilder( - "nei:textures/nei_sprites.png", - 37, - 76, - 9, - 10).build(); - protected static final DrawableResource ICON_OVERLAY = new DrawableBuilder( - "nei:textures/nei_sprites.png", - 46, - 76, - 9, - 10).build(); + protected static final DrawableResource ICON_FILL = UIRecipeTexture.ICON_OVERLAY_FILL; + protected static final DrawableResource ICON_FILL_ERROR = UIRecipeTexture.ICON_OVERLAY_FILL_ERROR; + protected static final DrawableResource ICON_OVERLAY = UIRecipeTexture.ICON_OVERLAY; protected static final int BUTTON_ID_SHIFT = 4; public final GuiContainer firstGui; @@ -217,22 +193,12 @@ public class GuiOverlayButton extends GuiRecipeButton { } @Override - protected void drawContent(Minecraft minecraft, int y, int x, boolean mouseOver) { - DrawableResource icon = ICON_OVERLAY; - + protected DrawableResource getIcon() { if (this.canFillCraftingGrid && (!requireShiftForOverlayRecipe() || NEIClientUtils.shiftKey())) { - icon = this.missedMaterialsTooltipLineHandler == null ? ICON_FILL : ICON_FILL_ERROR; + return this.missedMaterialsTooltipLineHandler == null ? ICON_FILL : ICON_FILL_ERROR; } - final int iconX = this.xPosition + (this.width - icon.width - 1) / 2; - final int iconY = this.yPosition + (this.height - icon.height) / 2; - - GL11.glColor4f(1, 1, 1, this.enabled ? 1 : 0.5f); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - icon.draw(iconX, iconY); - GL11.glDisable(GL11.GL_BLEND); - GL11.glColor4f(1, 1, 1, 1); + return ICON_OVERLAY; } @Override diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index c4b106ed..f9ede33d 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -1,14 +1,15 @@ package codechicken.nei.recipe; import java.awt.Point; -import java.awt.Rectangle; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.IdentityHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.WeakHashMap; +import java.util.function.Consumer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; @@ -23,29 +24,23 @@ import org.lwjgl.opengl.GL11; import codechicken.lib.gui.GuiDraw; import codechicken.lib.vec.Rectangle4i; -import codechicken.nei.Button; import codechicken.nei.ColorUtils; -import codechicken.nei.GuiNEIButton; import codechicken.nei.KeyManager; +import codechicken.nei.LayoutStyleMinecraft; import codechicken.nei.NEICPH; import codechicken.nei.NEIClientConfig; import codechicken.nei.NEIClientUtils; import codechicken.nei.PositionedStack; import codechicken.nei.RecipeSearchField; -import codechicken.nei.RestartableTask; -import codechicken.nei.SearchField; -import codechicken.nei.SearchTokenParser.ISearchParserProvider; -import codechicken.nei.SearchTokenParser.SearchMode; import codechicken.nei.VisiblityData; import codechicken.nei.Widget; +import codechicken.nei.WidgetContainer; import codechicken.nei.api.IGuiContainerOverlay; import codechicken.nei.api.INEIGuiHandler; import codechicken.nei.api.IRecipeFilter; import codechicken.nei.api.IRecipeFilter.IRecipeFilterProvider; import codechicken.nei.api.ItemFilter; import codechicken.nei.api.TaggedInventoryArea; -import codechicken.nei.drawable.DrawableBuilder; -import codechicken.nei.drawable.DrawableResource; import codechicken.nei.filter.AllMultiRecipeFilter; import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.guihook.IContainerTooltipHandler; @@ -54,11 +49,9 @@ import codechicken.nei.guihook.IGuiHandleMouseWheel; import codechicken.nei.guihook.IGuiHotkeyListener; import codechicken.nei.recipe.Recipe.RecipeId; import codechicken.nei.recipe.widget.RecipeWidget; -import codechicken.nei.scroll.ScrollBar; -import codechicken.nei.scroll.ScrollBar.OverflowType; -import codechicken.nei.scroll.ScrollBar.ScrollPlace; +import codechicken.nei.recipe.widget.ViewStates; import codechicken.nei.scroll.ScrollContainer; -import codechicken.nei.search.SearchExpressionUtils; +import codechicken.nei.theme.UIRecipeTexture; import codechicken.nei.theme.UIWidgetTexture; import codechicken.nei.util.EmptyContainer; import codechicken.nei.util.SlotInaccessible; @@ -67,30 +60,10 @@ public abstract class GuiRecipe extends GuiContainer i IGuiClientSide, IGuiHandleMouseWheel, IGuiHotkeyListener, IContainerTooltipHandler, INEIGuiHandler { private static final int BORDER_PADDING = 5; - private static final int TRANSPARENCY_BORDER = 4; - private final DrawableResource BG_TEXTURE = new DrawableBuilder( - "nei:textures/gui/recipebg.png", - 0, - 0, - 176 + TRANSPARENCY_BORDER * 2, - 166 + TRANSPARENCY_BORDER * 2) - .setSlices( - BORDER_PADDING + TRANSPARENCY_BORDER, - BORDER_PADDING + TRANSPARENCY_BORDER, - BORDER_PADDING + TRANSPARENCY_BORDER, - BORDER_PADDING + TRANSPARENCY_BORDER) - .build(); - - private static final int BUTTON_WIDTH = 13; - private static final int BUTTON_HEIGHT = 12; - - protected static final ScrollBar VERTICAL_SCROLLBAR = new ScrollBar().setTrackWidth(14) - .setOverflowType(OverflowType.AUTO).setScrollPlace(ScrollPlace.END) - .setTrackTexture( - new DrawableBuilder("nei:textures/nei_sprites.png", 42, 90, 13, 21).setSlices(0, 0, 9, 9).build()) - .setThumbTexture( - new DrawableBuilder("nei:textures/nei_sprites.png", 22, 96, 6, 9).setSlices(0, 0, 3, 2).build()) - .setThumbPadding(1, 6, 0, 6); + private static final int SCROLL_CONTENT_GAP = 2; + private static final int SCROLL_BORDER_SHIFT = 1; + private static final int HEADER_HEIGHT = 33; + private static final int MIN_HEIGHT = 166; public static final List recipeFilterers = new LinkedList<>(); @@ -103,173 +76,24 @@ public abstract class GuiRecipe extends GuiContainer i public GuiContainer firstGui; public GuiScreen firstGuiGeneral; public GuiScreen prevGui; - private GuiButton nextpage; - private GuiButton prevpage; - private GuiButton prevtype; - private GuiButton nexttype; + private static final NavigationBar typeBar = new NavigationBar( + () -> GuiRecipe.onCurrentScreen(GuiRecipe::openAllHandlers), + () -> GuiRecipe.onCurrentScreen(GuiRecipe::prevType), + () -> GuiRecipe.onCurrentScreen(GuiRecipe::nextType)); - private Rectangle typeArea = new Rectangle(); - private Rectangle pageArea = new Rectangle(); + private static final RecipeSearchBar search = new RecipeSearchBar( + () -> GuiRecipe.onCurrentScreen(GuiRecipe::prevPage), + () -> GuiRecipe.onCurrentScreen(GuiRecipe::nextPage)); private int lastPage = -1; private int catalystsVersion = -1; + private int scrollInset; private final GuiRecipeTabs recipeTabs; private final GuiRecipeCatalyst recipeCatalyst; private SearchRecipeHandler handler; private HandlerInfo handlerInfo; private RecipePageManager handlerPages; - - protected static final RestartableTask updateFilter = new RestartableTask("NEI Recipe Filtering") { - - @Override - public void execute() { - final GuiScreen currentScreen = NEIClientUtils.mc().currentScreen; - - if (currentScreen instanceof GuiRecipeguiRecipe) { - final SearchRecipeHandler searchHandler = guiRecipe.handler; - - if (searchHandler != null && searchHandler.searchingAvailable()) { - - if (GuiRecipe.searchField.text().isEmpty()) { - searchHandler.setSearchIndices(null); - } else { - final IRecipeFilter filter = GuiRecipe.searchField.getRecipeFilter(); - final List filtered = searchHandler.getSearchResult(filter); - - if (filtered == null) { - stop(); - } - - if (interrupted()) return; - searchHandler.setSearchIndices(filtered); - } - - } - - } - - } - - }; - - protected static final RecipeSearchField searchField = new RecipeSearchField("") { - - @Override - protected boolean noResults() { - final GuiScreen currentScreen = NEIClientUtils.mc().currentScreen; - return !(currentScreen instanceof GuiRecipe) - || ((GuiRecipe) currentScreen).handlerPages.getNumRecipes() > 0; - } - - @Override - public void onTextChange(String oldText) { - updateFilter.restart(); - } - - }; - - protected static final Button toggleSearch = new Button() { - - @Override - public boolean onButtonPress(boolean rightclick) { - if (rightclick) return false; - - if (GuiRecipe.searchField.isVisible()) { - GuiRecipe.searchField.setText(""); - GuiRecipe.searchField.setFocus(false); - GuiRecipe.searchField.setVisible(false); - state = 0; - } else { - GuiRecipe.searchField.setVisible(true); - GuiRecipe.searchField.setFocus(true); - state = 2; - } - - return true; - } - - @Override - public void addTooltips(List tooltip) { - tooltip.add(NEIClientUtils.translate("recipe.search.tooltip.name") + GuiDraw.TOOLTIP_LINESPACE); - - if (NEIClientUtils.shiftKey()) { - tooltip.add( - NEIClientUtils.translate( - "recipe.search.tooltip.input", - SearchExpressionUtils.HIGHLIGHTS.RECIPE + "<")); - tooltip.add( - NEIClientUtils.translate( - "recipe.search.tooltip.output", - SearchExpressionUtils.HIGHLIGHTS.RECIPE + ">")); - tooltip.add( - NEIClientUtils.translate( - "recipe.search.tooltip.text", - SearchExpressionUtils.HIGHLIGHTS.RECIPE + "~")); - - final int patternMode = NEIClientConfig.getIntSetting("inventory.search.patternMode"); - - if (patternMode != 2) { - tooltip.add( - NEIClientUtils.translate( - "recipe.search.tooltip.auxiliary", - SearchExpressionUtils.HIGHLIGHTS.RECIPE + "^")); - } - - if (patternMode == 3) { - tooltip.add( - NEIClientUtils.translate( - "recipe.search.tooltip.all", - SearchExpressionUtils.HIGHLIGHTS.RECIPE + "<&")); - } - - for (ISearchParserProvider provider : SearchField.searchParser.getProviders()) { - if (provider.getSearchMode() == SearchMode.PREFIX) { - addPrefixTooltip(tooltip, provider); - } - } - - tooltip.add( - NEIClientUtils.translate( - "recipe.search.tooltip.exclude", - SearchExpressionUtils.HIGHLIGHTS.NEGATE + "-")); - tooltip.add( - NEIClientUtils.translate( - "recipe.search.tooltip.exclude_recipe", - SearchExpressionUtils.HIGHLIGHTS.NEGATE + "!")); - tooltip.add( - NEIClientUtils - .translate("recipe.search.tooltip.or", SearchExpressionUtils.HIGHLIGHTS.OR.f + "|")); - tooltip.add( - NEIClientUtils.translate( - "recipe.search.tooltip.exact", - SearchExpressionUtils.HIGHLIGHTS.QUOTED + "\"", - SearchExpressionUtils.HIGHLIGHTS.QUOTED + "\"")); - - if (patternMode == 1 || patternMode == 3) { - tooltip.add( - NEIClientUtils.translate( - "recipe.search.tooltip.regex", - SearchExpressionUtils.HIGHLIGHTS.REGEX + "r/", - SearchExpressionUtils.HIGHLIGHTS.REGEX + "/")); - } - } else { - tooltip.add(NEIClientUtils.translate("recipe.search.tooltip.shift")); - } - - } - - private void addPrefixTooltip(List tooltip, ISearchParserProvider provider) { - final char prefix = SearchField.searchParser.getRedefinedPrefix(provider.getPrefix()); - final String modeName = NEIClientUtils.translate("recipe.search.tooltip.prefix." + provider.getName()); - - tooltip.add( - NEIClientUtils.translate( - "recipe.search.tooltip.prefix", - provider.getHighlightedColor() + String.valueOf(prefix), - modeName)); - } - - }; + private final Map viewStates = new IdentityHashMap<>(); /** * This will only be true iff height hacking has been configured for the current recipe handler AND we are currently @@ -283,11 +107,21 @@ public abstract class GuiRecipe extends GuiContainer i @Override protected void setRecipePage(int recipetype) { - GuiRecipe.this.setRecipePage(recipetype); + final int size = GuiRecipe.this.currenthandlers.size(); + if ((size + recipetype) % size != GuiRecipe.this.recipetype) { + GuiRecipe.this.setRecipePage(recipetype); + } } }; this.recipeCatalyst = new GuiRecipeCatalyst(); + + this.screen.addWidget(this.recipeCatalyst); + this.screen.addWidget(this.container); + // oversized recipes must not cover the navigation + this.screen.addWidget(GuiRecipe.typeBar); + this.screen.addWidget(GuiRecipe.search); + this.slotcontainer = (EmptyContainer) this.inventorySlots; this.prevGui = prevgui; @@ -301,36 +135,6 @@ public abstract class GuiRecipe extends GuiContainer i this.firstGui = gui.getFirstScreen(); this.firstGuiGeneral = gui.getFirstScreenGeneral(); } - - this.prevtype = new GuiNEIButton(0, 0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, "<") { - - @Override - public void mouseReleased(int mouseX, int mouseY) { - prevType(); - } - }; - this.nexttype = new GuiNEIButton(1, 0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, ">") { - - @Override - public void mouseReleased(int mouseX, int mouseY) { - nextType(); - } - }; - - this.prevpage = new GuiNEIButton(2, 0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, "<") { - - @Override - public void mouseReleased(int mouseX, int mouseY) { - prevPage(); - } - }; - this.nextpage = new GuiNEIButton(3, 0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, ">") { - - @Override - public void mouseReleased(int mouseX, int mouseY) { - nextPage(); - } - }; } /** @@ -361,10 +165,9 @@ public abstract class GuiRecipe extends GuiContainer i private static final int LEGACY_BOX_WIDTH = 176; private static final int LEGACY_BOX_HEIGHT = 166; - // layoutWindow() places the recipe container at (guiLeft + 3, guiTop + 32); RecipePageManager then places - // each left-aligned recipe widget another 2px to the right of that. This is the inverse of both, undoing the - // container's own inset so a legacy handler sees its recipe flush with guiLeft as it expects. - private static final int CONTAINER_LEFT_INSET = 3 + 2; + // Legacy handlers draw their recipe 5px from the left edge of the 176 wide box, and that is where the widget + // is centered in the default window, so this is the inverse of that offset. + private static final int CONTAINER_LEFT_INSET = 5; private final GuiRecipe gui; private final int trueWidth; @@ -451,6 +254,12 @@ public abstract class GuiRecipe extends GuiContainer i private ScrollContainer container = new ScrollContainer() { + // the scrollbar track lies outside the container + @Override + public boolean contains(int px, int py) { + return boundsOutside().contains(px, py); + } + @Override public Widget getWidgetUnderMouse(int mousex, int mousey) { @@ -463,99 +272,158 @@ public abstract class GuiRecipe extends GuiContainer i }; + // all widgets of the screen, later ones are drawn over and get the mouse first + private final WidgetContainer screen = new WidgetContainer() { + + @Override + public Widget getWidgetUnderMouse(int mousex, int mousey) { + final Widget widget = super.getWidgetUnderMouse(mousex, mousey); + + // recipes that overflow the container still get the mouse outside of it + if (widget == null && GuiRecipe.this.handlerInfo.isAllowOverflowY()) { + return GuiRecipe.this.container; + } + + return widget; + } + + }; + @Override public void initGui() { final int tabHeight = GuiRecipeTabs.getTabHeight(); - this.xSize = 176; - this.ySize = Math - .min(this.height - 22 - 22 - tabHeight, NEIClientConfig.getIntSetting("inventory.guirecipe.maxHeight")); + final int bottomInset = NEIClientConfig.isSearchWidgetCentered() ? LayoutStyleMinecraft.BUTTON_SIZE : 0; + int topInset = 0; + if (NEIClientConfig.showSubsetWidget() && NEIClientConfig.subsetWidgetOnTop()) { + topInset += LayoutStyleMinecraft.MARGIN + LayoutStyleMinecraft.SUBSET_BAR_HEIGHT; + } + + final int freeHeight = this.height - topInset - bottomInset - tabHeight; + topInset += Math.min( + NEIClientConfig.getIntSetting("inventory.guirecipe.topMargin"), + Math.max(0, freeHeight - MIN_HEIGHT)); + + final int availableHeight = this.height - topInset - bottomInset - tabHeight; + this.ySize = Math.min(availableHeight, NEIClientConfig.getIntSetting("inventory.guirecipe.maxHeight")); + this.xSize = fitWindowContentWidth(this.scrollInset) + windowChrome(); super.initGui(); - this.guiTop = Math.max(22 - 3 + tabHeight, (this.height - this.ySize) / 2); + this.guiTop = topInset + tabHeight - 3 + (availableHeight - this.ySize) / 2; if (this.handler == null) { setRecipePage(this.recipetype); + } else { + GuiRecipe.search.updateFilter(); } - final int rightButtonX = this.guiLeft + this.xSize - BORDER_PADDING - BUTTON_WIDTH + 1; - final int leftButtonX = this.guiLeft + BORDER_PADDING; + layoutWindow(); + fitWindow(); + this.lastPage = -1; - this.prevtype.xPosition = leftButtonX; - this.prevtype.yPosition = guiTop + 3; - this.nexttype.xPosition = rightButtonX; - this.nexttype.yPosition = guiTop + 3; - this.prevpage.xPosition = leftButtonX; - this.prevpage.yPosition = guiTop + 17; - this.nextpage.xPosition = rightButtonX; - this.nextpage.yPosition = guiTop + 17; + GuiRecipe.typeBar.enabled = this.currenthandlers.size() > 1; + GuiRecipe.typeBar.labelTooltip = NEIClientUtils.translate("recipe.tab.view_all.tooltip"); + GuiRecipe.typeBar.color = ColorUtils.recipeTitle.getColor(); + GuiRecipe.typeBar.hoverColor = ColorUtils.recipeTitleHover.getColor(); + updateNavigation(); + } - this.container.x = this.guiLeft + 3; - this.container.y = this.guiTop + 32; - this.container.h = this.ySize - 32 - 4; + private void updateNavigation() { + GuiRecipe.typeBar.label = this.handler.original.getRecipeName().trim(); + GuiRecipe.search.setAvailable(this.handler.searchingAvailable()); + GuiRecipe.search.enabled = this.handlerPages.getNumPages() > 1; + GuiRecipe.search.setPages(this.handlerPages.getCurrentPageIndex() + 1, this.handlerPages.getNumPages()); + } - GuiRecipe.toggleSearch.icon = new DrawableBuilder("nei:textures/nei_sprites.png", 0, 76, 10, 10).build(); - GuiRecipe.toggleSearch.w = GuiRecipe.toggleSearch.h = 12; - GuiRecipe.toggleSearch.x = this.guiLeft + BORDER_PADDING + BUTTON_WIDTH; - GuiRecipe.toggleSearch.y = this.guiTop + 17; + private void layoutWindow() { + this.guiLeft = (this.width - this.xSize) / 2; - GuiRecipe.searchField.y = this.guiTop + 16; - GuiRecipe.searchField.x = this.guiLeft + BORDER_PADDING + BUTTON_WIDTH + GuiRecipe.toggleSearch.w; - GuiRecipe.searchField.w = this.xSize - (BORDER_PADDING + BUTTON_WIDTH) * 2 + 1 - GuiRecipe.toggleSearch.w - 45; - GuiRecipe.searchField.h = 14; + this.screen.w = this.width; + this.screen.h = this.height; - 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( - this.prevpage.xPosition + BUTTON_WIDTH, - this.prevpage.yPosition, - this.nextpage.xPosition - this.prevpage.xPosition - BUTTON_WIDTH - 1, - BUTTON_HEIGHT); + this.container.x = this.guiLeft + BORDER_PADDING; + this.container.y = this.guiTop + HEADER_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; + placeNavigation(); + placeSidePanels(); + } + + private int fitWindowContentWidth(int scrollInset) { + final int minWidth = NEIClientConfig.getIntSetting("inventory.guirecipe.minWidth"); + final int maxWidth = this.width - BORDER_PADDING * 2 - scrollInset; + + if (this.handlerInfo == null) { + return Math.min(minWidth, maxWidth); } - this.recipeTabs.update(this); + this.recipeCatalyst.setAvailableHeight(this.ySize); + + final int desiredWidth = this.handlerInfo.isAllowOverflowX() + ? Math.max(this.handlerInfo.getWindowWidth(), this.handlerPages.getMaxRecipeWidth()) + : this.handlerInfo.getWindowWidth(); + final int sideWidth = this.recipeCatalyst.isVisible() ? this.recipeCatalyst.w - 5 : 0; + + return Math.min(maxWidth - sideWidth * 2, Math.max(minWidth - scrollInset, desiredWidth)); + } + + private int windowChrome() { + return BORDER_PADDING * 2 + this.scrollInset; + } + + private void fitWindow() { + final int trackInset = UIWidgetTexture.SCROLL_TRACK_WIDTH + SCROLL_CONTENT_GAP - SCROLL_BORDER_SHIFT; + // the height splits recipes into pages, so it must not depend on the current page's scroll track + final boolean horizontalScroll = this.handlerPages.getMaxRecipeWidth() + > fitWindowContentWidth(this.handlerPages.needsVerticalScroll() ? trackInset : 0); + + this.scrollInset = this.handlerPages.currentPageNeedsVerticalScroll() ? trackInset : 0; + final int windowWidth = fitWindowContentWidth(this.scrollInset) + windowChrome(); + + if (windowWidth != this.xSize) { + this.xSize = windowWidth; + layoutWindow(); + } + + updateContainerSize(horizontalScroll); } protected void refreshContainer() { + if (this.catalystsVersion != RecipeCatalysts.getVersion()) { + this.catalystsVersion = RecipeCatalysts.getVersion(); + this.recipeCatalyst.setCatalysts(RecipeCatalysts.getRecipeCatalysts(this.handler.original)); + // the catalyst width changes the window width, so the page has to be placed again + this.lastPage = -1; + } + if (this.handlerPages.rebuildPages() || this.lastPage != this.handlerPages.getCurrentPageIndex()) { this.lastPage = this.handlerPages.getCurrentPageIndex(); - updateContainerSize(); + updateNavigation(); + fitWindow(); this.container.setWidgets(this.handlerPages.getCurrentPageWidgets()); - if (!this.handlerInfo.isAllowOverflowX() && this.handlerInfo.getWidth() > this.xSize - 6) { - this.container.setPaddingInline(0, 2); - this.container.setHorizontalScroll(UIWidgetTexture.horizontalScrollBar().setTrackPadding(1, 0, 1, 0)); + final boolean verticalScroll = !this.handlerInfo.isAllowOverflowY() + && this.handlerPages.currentPageNeedsVerticalScroll(); + + if (isWiderThanWindow(this.handlerPages.getCurrentPageWidth())) { + this.container.setHorizontalScroll( + UIWidgetTexture.horizontalScrollBar() + .setTrackPadding(0, 0, verticalScroll ? -SCROLL_CONTENT_GAP : 0, 0)); } else { this.container.setPaddingInline(0, 0); this.container.setHorizontalScroll(null); } - if (this.handlerInfo.isAllowOverflowY()) { + if (!verticalScroll) { + this.container.setPaddingBlock(0, 0); this.container.setVerticalScroll(null); - } else if (this.container.w == this.xSize - 6) { - this.container.setVerticalScroll(VERTICAL_SCROLLBAR); } else { this.container.setVerticalScroll( - UIWidgetTexture.verticalScrollBar().setOverflowType(OverflowType.OVERLAY) - .setTrackPadding(-8, 0, 0, 0)); + UIWidgetTexture.verticalScrollBar().setTrackPadding(SCROLL_CONTENT_GAP, 0, 0, 0)); } } - if (this.catalystsVersion != RecipeCatalysts.getVersion()) { - this.catalystsVersion = RecipeCatalysts.getVersion(); - this.recipeCatalyst.setCatalysts(RecipeCatalysts.getRecipeCatalysts(this.handler.original)); - } - this.container.update(); } @@ -578,41 +446,72 @@ public abstract class GuiRecipe extends GuiContainer i return recipeFilter.filters.size() == 1 ? recipeFilter.filters.get(0) : recipeFilter; } + private static void onCurrentScreen(Consumer> action) { + if (NEIClientUtils.mc().currentScreen instanceof GuiRecipeguiRecipe) { + action.accept(guiRecipe); + } + } + public static ItemFilter getSearchItemFilter() { - return GuiRecipe.searchField.getFilter(); + return GuiRecipe.search.getFilter(); } protected void setRecipePage(int idx) { this.recipetype = (this.currenthandlers.size() + idx) % this.currenthandlers.size(); - this.handler = new SearchRecipeHandler<>(this.currenthandlers.get(this.recipetype)); + this.handler = new SearchRecipeHandler<>( + this.currenthandlers.get(this.recipetype), + GuiRecipe.getRecipeListFilter()); this.handlerInfo = GuiRecipeTab.getHandlerInfo(this.handler.original); this.catalystsVersion = RecipeCatalysts.getVersion(); this.recipeCatalyst.setCatalysts(RecipeCatalysts.getRecipeCatalysts(this.handler.original)); - updateContainerSize(); - this.handlerPages = new RecipePageManager(this.handler, this.handlerInfo, this.container); - this.prevpage.enabled = this.nextpage.enabled = this.handlerPages.getNumPages() > 1; + GuiRecipe.search.reset(); + this.handlerPages = new RecipePageManager( + this.handler, + this.handlerInfo, + this.container, + this.viewStates.computeIfAbsent(this.handler.original, k -> new ViewStates())); + fitWindow(); + this.handlerPages.rebuildPages(); + // the pages decide whether the window needs room for the scroll track + fitWindow(); + this.handlerPages.rebuildPages(); this.lastPage = -1; - GuiRecipe.searchField.setText(""); - GuiRecipe.searchField.setVisible(false); - GuiRecipe.toggleSearch.state = 0; + updateNavigation(); this.container.setVerticalScrollOffset(0); this.container.setHorizontalScrollOffset(0); - this.recipeTabs.update(this); + this.recipeTabs.update(this.currenthandlers, this.recipetype); } - private void updateContainerSize() { - final int width = this.xSize - 6; - this.container.w = Math.max(width, this.handlerInfo.getWidth()); - this.container.h = this.ySize - 32 - 4; + private void placeNavigation() { + final int navWidth = Math + .min(this.xSize, NEIClientConfig.getIntSetting("inventory.guirecipe.minWidth") + BORDER_PADDING * 2); + final int navLeft = this.guiLeft + (this.xSize - navWidth) / 2; - if (!this.handlerInfo.isAllowOverflowX() && this.handlerInfo.getWidth() > width) { - this.container.w = width; - this.container.h -= 8; + GuiRecipe.typeBar.place(navLeft + BORDER_PADDING, this.guiTop + 5, navWidth - BORDER_PADDING * 2); + + GuiRecipe.search.place( + GuiRecipe.typeBar.x, + GuiRecipe.typeBar.y + GuiRecipe.typeBar.h + NavigationBar.GAP, + GuiRecipe.typeBar.w); + + this.recipeTabs.place(navLeft, navWidth, this.guiTop); + } + + private void updateContainerSize(boolean horizontalScroll) { + this.container.w = this.xSize - windowChrome(); + this.container.h = this.ySize - HEADER_HEIGHT - BORDER_PADDING; + + if (horizontalScroll) { + this.container.h -= UIWidgetTexture.SCROLL_TRACK_WIDTH - SCROLL_BORDER_SHIFT; } } + private boolean isWiderThanWindow(int recipesWidth) { + return recipesWidth > this.xSize - windowChrome(); + } + public int openTargetRecipe(RecipeId recipeId) { return openTargetRecipe(recipeId, null); } @@ -696,7 +595,9 @@ public abstract class GuiRecipe extends GuiContainer i } } - final PositionedStack activeStack = this.recipeCatalyst.getPositionedStackMouseOver(mousex, mousey); + final PositionedStack activeStack = this.recipeCatalyst.isVisible() + ? this.recipeCatalyst.getPositionedStackMouseOver(mousex, mousey) + : null; if (activeStack != null) { slotcontainer.setActiveStack(activeStack.item); @@ -714,6 +615,14 @@ public abstract class GuiRecipe extends GuiContainer i return this.handler.original; } + SearchRecipeHandler getSearchHandler() { + return this.handler; + } + + int getNumRecipes() { + return this.handlerPages.getNumRecipes(); + } + public List getRecipeIndices() { return this.handlerPages.getRecipeIndices(); } @@ -725,8 +634,7 @@ public abstract class GuiRecipe extends GuiContainer i @Override public void keyTyped(char c, int i) { - if (GuiRecipe.searchField.isVisible() && GuiRecipe.searchField.focused() - && GuiRecipe.searchField.handleKeyPress(i, c)) { + if (GuiRecipe.search.handleKeyPress(i, c)) { return; } @@ -736,25 +644,17 @@ public abstract class GuiRecipe extends GuiContainer i return; } - if (GuiRecipe.searchField.isVisible() && GuiRecipe.searchField.focused()) { - GuiRecipe.searchField.lastKeyTyped(i, c); - GuiRecipe.searchField.onHotkeyPressed(); + if (GuiRecipe.search.isFocused()) { + GuiRecipe.search.lastKeyTyped(i, c); + GuiRecipe.search.onHotkeyPressed(); return; } - if (this.recipeCatalyst.isShowWidget()) { - if (this.recipeCatalyst.handleKeyPress(i, c)) { - return; - } - - this.recipeCatalyst.lastKeyTyped(i, c); - } - - if (this.container.handleKeyPress(i, c)) { + if (this.screen.handleKeyPress(i, c)) { return; } - this.container.lastKeyTyped(i, c); + this.screen.lastKeyTyped(i, c); if (GuiContainerManager.getManager(this).lastKeyTyped(i, c)) { return; @@ -768,8 +668,8 @@ public abstract class GuiRecipe extends GuiContainer i @Override public boolean onHotkeyPressed() { - if (GuiRecipe.searchField.isVisible() && GuiRecipe.searchField.onHotkeyPressed() - || this.recipeCatalyst.isShowWidget() && this.recipeCatalyst.onHotkeyPressed() + if (GuiRecipe.search.onHotkeyPressed() + || this.recipeCatalyst.isVisible() && this.recipeCatalyst.onHotkeyPressed() || this.container.onHotkeyPressed()) { return true; } @@ -799,22 +699,7 @@ public abstract class GuiRecipe extends GuiContainer i @Override protected void mouseClicked(int mousex, int mousey, int button) { - - if (this.handler != null && this.handler.searchingAvailable()) { - if (GuiRecipe.toggleSearch.contains(mousex, mousey)) { - GuiRecipe.toggleSearch.handleClick(mousex, mousey, button); - } else if (GuiRecipe.searchField.contains(mousex, mousey)) { - GuiRecipe.searchField.handleClick(mousex, mousey, button); - } else { - GuiRecipe.searchField.onGuiClick(mousex, mousey); - } - } - - if (this.recipeCatalyst.isShowWidget() && this.recipeCatalyst.handleClick(mousex, mousey, button)) { - return; - } - - if (this.container.handleClick(mousex, mousey, button)) { + if (this.screen.handleClick(mousex, mousey, button)) { return; } @@ -822,25 +707,12 @@ public abstract class GuiRecipe extends GuiContainer i return; } - if (button == 0 && isHandlerTitleHovered(mousex, mousey)) { - if (this instanceof GuiCraftingRecipe) { - GuiCraftingRecipe.openRecipeGui("all"); - } else if (this instanceof GuiUsageRecipe) { - GuiUsageRecipe.openRecipeGui("all"); - } - return; - } - super.mouseClicked(mousex, mousey, button); } @Override protected void mouseClickMove(int mousex, int mousey, int button, long heldTime) { - if (this.recipeCatalyst.isShowWidget()) { - this.recipeCatalyst.mouseDragged(mousex, mousey, button, heldTime); - } - - this.container.mouseDragged(mousex, mousey, button, heldTime); + this.screen.mouseDragged(mousex, mousey, button, heldTime); super.mouseClickMove(mousex, mousey, button, heldTime); } @@ -848,12 +720,7 @@ public abstract class GuiRecipe extends GuiContainer i protected void mouseMovedOrUp(int mousex, int mousey, int state) { if (state != -1) { - - if (this.recipeCatalyst.isShowWidget()) { - this.recipeCatalyst.mouseUp(mousex, mousey, state); - } - - this.container.mouseUp(mousex, mousey, state); + this.screen.mouseUp(mousex, mousey, state); } super.mouseMovedOrUp(mousex, mousey, state); @@ -872,18 +739,14 @@ public abstract class GuiRecipe extends GuiContainer i final Point mouse = GuiDraw.getMousePosition(); - if (this.recipeCatalyst.isShowWidget() && this.recipeCatalyst.onMouseWheel(scroll, mouse.x, mouse.y)) { - return; - } - - if (this.container.onMouseWheel(scroll, mouse.x, mouse.y)) { + if (this.screen.onMouseWheel(scroll, mouse.x, mouse.y)) { return; } // 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() || this.typeArea.contains(mouse)) { + if (NEIClientUtils.shiftKey() || GuiRecipe.typeBar.contains(mouse.x, mouse.y)) { if (scroll < 0) { nextType(); } else { @@ -897,9 +760,7 @@ public abstract class GuiRecipe extends GuiContainer i // recipe page. if (NEIClientConfig.getBooleanSetting("inventory.guirecipe.scrollPages") && this.container.boundsInside().contains(mouse.x, mouse.y) - || this.pageArea.contains(mouse) - && (!this.handler.searchingAvailable() || !GuiRecipe.toggleSearch.contains(mouse.x, mouse.y)) - && (!GuiRecipe.searchField.isVisible() || !GuiRecipe.searchField.contains(mouse.x, mouse.y))) { + || GuiRecipe.search.contains(mouse.x, mouse.y) && !GuiRecipe.search.overSearch(mouse.x, mouse.y)) { if (scroll > 0) { prevPage(); @@ -915,44 +776,22 @@ public abstract class GuiRecipe extends GuiContainer i this.handler.original.onUpdate(); refreshContainer(); - - this.recipeCatalyst.setAvailableHeight(this.ySize - 5); - this.recipeCatalyst.y = this.guiTop; - this.recipeCatalyst.x = this.guiLeft - this.recipeCatalyst.w + 4; + placeSidePanels(); this.recipeCatalyst.update(); } + private void placeSidePanels() { + this.recipeCatalyst.y = this.guiTop; + this.recipeCatalyst.x = this.guiLeft - this.recipeCatalyst.w + 5; + } + @Override public List handleTooltip(GuiContainer gui, int mousex, int mousey, List currenttip) { - if (this.recipeCatalyst.isShowWidget()) { - currenttip = this.recipeCatalyst.handleTooltip(mousex, mousey, currenttip); - } - - currenttip = this.container.handleTooltip(mousex, mousey, currenttip); + currenttip = this.screen.handleTooltip(mousex, mousey, currenttip); this.recipeTabs.handleTooltip(mousex, mousey, currenttip); - if (this.handler != null && this.handler.searchingAvailable()) { - currenttip = GuiRecipe.toggleSearch.handleTooltip(mousex, mousey, currenttip); - } - - if (currenttip.isEmpty() && isHandlerTitleHovered(mousex, mousey)) { - currenttip.add(NEIClientUtils.translate("recipe.tab.view_all.tooltip")); - } - - if (currenttip.isEmpty() && GuiRecipe.searchField.isVisible() - && new Rectangle(GuiRecipe.searchField.x + GuiRecipe.searchField.w, 15, 44, 16) - .contains(mousex - this.guiLeft, mousey - this.guiTop)) { - - final String pageInfo = String - .format("%d/%d", this.handlerPages.getCurrentPageIndex() + 1, this.handlerPages.getNumPages()); - - if (this.fontRendererObj.getStringWidth(pageInfo) >= 45) { - currenttip.add(pageInfo); - } - } - return currenttip; } @@ -970,30 +809,25 @@ public abstract class GuiRecipe extends GuiContainer i @Override public Map handleHotkeys(GuiContainer gui, int mousex, int mousey, Map hotkeys) { - - if (this.recipeCatalyst.isShowWidget()) { - hotkeys = this.recipeCatalyst.handleHotkeys(mousex, mousey, hotkeys); - } - - hotkeys = this.container.handleHotkeys(mousex, mousey, hotkeys); - - return hotkeys; + return this.screen.handleHotkeys(mousex, mousey, hotkeys); } - private void nextPage() { + void nextPage() { this.handlerPages.changePage(1); } - private void prevPage() { + void prevPage() { this.handlerPages.changePage(-1); } protected void nextType() { - setRecipePage(++recipetype); + if (this.currenthandlers.size() <= 1) return; + setRecipePage(++this.recipetype); } protected void prevType() { - setRecipePage(--recipetype); + if (this.currenthandlers.size() <= 1) return; + setRecipePage(--this.recipetype); } public GuiRecipeCatalyst getRecipeCatalystWidget() { @@ -1014,86 +848,18 @@ public abstract class GuiRecipe extends GuiContainer i @Override 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); - } - + this.screen.draw(mouseX, mouseY); GL11.glTranslatef(guiLeft, guiTop, 0); } @Override public void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { - BG_TEXTURE.draw( - this.guiLeft - TRANSPARENCY_BORDER, - this.guiTop - TRANSPARENCY_BORDER, - this.xSize + TRANSPARENCY_BORDER * 2, - this.ySize + TRANSPARENCY_BORDER * 2); - + GL11.glColor4f(1, 1, 1, 1); + UIRecipeTexture.WINDOW.draw(this.guiLeft, this.guiTop, this.xSize, this.ySize); drawJEITabs(mouseX, mouseY); } private void drawJEITabs(int mouseX, int mouseY) { - final int textMiddle = (BUTTON_WIDTH - this.fontRendererObj.FONT_HEIGHT) / 2; - - drawRect( - this.typeArea.x, - this.typeArea.y, - this.typeArea.x + this.typeArea.width, - this.typeArea.y + this.typeArea.height, - 0x30000000); - drawRect( - 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(); - final int titleColor = getHandlerTitleColor(isHandlerTitleHovered(mouseX, mouseY)); - drawCenteredString( - this.fontRendererObj, - handlerTitle, - this.guiLeft + this.xSize / 2, - this.typeArea.y + textMiddle, - titleColor); - - if (this.handler.searchingAvailable()) { - GuiRecipe.toggleSearch.draw(mouseX, mouseY); - } - - if (GuiRecipe.searchField.isVisible()) { - GuiRecipe.searchField.draw(mouseX, mouseY); - } - - if (GuiRecipe.searchField.isVisible()) { - final String recipePage = NEIClientUtils.cropText( - this.fontRendererObj, - String.format( - "%d/%d", - this.handlerPages.getCurrentPageIndex() + 1, - this.handlerPages.getNumPages()), - 45); - drawCenteredString( - this.fontRendererObj, - recipePage, - GuiRecipe.searchField.x + GuiRecipe.searchField.w + 22, - this.pageArea.y + textMiddle, - 0xffffff); - } else { - final String recipePage = NEIClientUtils.translate( - "recipe.page", - this.handlerPages.getCurrentPageIndex() + 1, - this.handlerPages.getNumPages()); - drawCenteredString( - this.fontRendererObj, - recipePage, - this.guiLeft + this.xSize / 2, - this.pageArea.y + textMiddle, - 0xffffff); - } - if (NEIClientConfig.areJEIStyleTabsVisible()) { RenderHelper.enableGUIStandardItemLighting(); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f); @@ -1102,17 +868,12 @@ public abstract class GuiRecipe extends GuiContainer i } } - private boolean isHandlerTitleHovered(int mousex, int mousey) { - final String handlerTitle = this.handler.original.getRecipeName().trim(); - final int titleWidth = this.fontRendererObj.getStringWidth(handlerTitle); - final int textMiddle = (BUTTON_WIDTH - this.fontRendererObj.FONT_HEIGHT) / 2; - final int titleX = this.guiLeft + (this.xSize - titleWidth) / 2; - final int titleY = this.prevtype.yPosition + textMiddle; - return new Rectangle(titleX, titleY, titleWidth, this.fontRendererObj.FONT_HEIGHT).contains(mousex, mousey); - } - - private int getHandlerTitleColor(boolean hovered) { - return hovered ? ColorUtils.recipeTitleHover.getColor() : ColorUtils.recipeTitle.getColor(); + private void openAllHandlers() { + if (this instanceof GuiCraftingRecipe) { + GuiCraftingRecipe.openRecipeGui("all"); + } else if (this instanceof GuiUsageRecipe) { + GuiUsageRecipe.openRecipeGui("all"); + } } @Override @@ -1181,13 +942,7 @@ public abstract class GuiRecipe extends GuiContainer i @Override public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button) { - - if (GuiRecipe.searchField.isVisible() && GuiRecipe.searchField.contains(mousex, mousey)) { - GuiRecipe.searchField.setText(SearchField.getEscapedSearchText(draggedStack)); - return true; - } - - return false; + return GuiRecipe.search.handleDragNDrop(mousex, mousey, draggedStack); } @Override @@ -1195,7 +950,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.boundsOutside().intersects(rect)) { + if (this.recipeCatalyst.isVisible() && this.recipeCatalyst.boundsOutside().intersects(rect)) { return true; } @@ -1219,6 +974,9 @@ public abstract class GuiRecipe extends GuiContainer i @Deprecated private GuiOverlayButton[] overlayButtons = new GuiOverlayButton[0]; + @Deprecated + protected static final RecipeSearchField searchField = search.getSearchField(); + @Deprecated public EmptyContainer slotcontainer; diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipeCatalyst.java b/src/main/java/codechicken/nei/recipe/GuiRecipeCatalyst.java index fa198501..ba742865 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipeCatalyst.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipeCatalyst.java @@ -13,11 +13,10 @@ import codechicken.nei.NEIServerUtils; import codechicken.nei.PositionedStack; import codechicken.nei.Widget; 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; +import codechicken.nei.theme.UIRecipeTexture; import codechicken.nei.theme.UIWidgetTexture; public class GuiRecipeCatalyst extends ScrollContainer { @@ -51,26 +50,11 @@ public class GuiRecipeCatalyst extends ScrollContainer { private static final int SLOT_SIZE = 16; private static final int BORDER_PADDING = 6; - private static final int TRANSPARENCY_BORDER = 4; - private static final DrawableResource BG_TEXTURE = new DrawableBuilder( - "nei:textures/catalyst_tab.png", - 0, - 0, - 28 + TRANSPARENCY_BORDER * 2, - 28 + TRANSPARENCY_BORDER * 2) - .setTextureSize(28 + TRANSPARENCY_BORDER * 2, 28 + TRANSPARENCY_BORDER * 2) - .setSlices( - BORDER_PADDING + TRANSPARENCY_BORDER, - BORDER_PADDING + TRANSPARENCY_BORDER, - BORDER_PADDING + TRANSPARENCY_BORDER, - BORDER_PADDING + TRANSPARENCY_BORDER) - .build(); - - private static final DrawableResource FG_TEXTURE = new DrawableBuilder("nei:textures/slot.png", 0, 0, 18, 18) - .setTextureSize(18, 18).setSlices(1, 1, 1, 1).build(); + private static final int COLUMNS_BOTTOM_INSET = 5; private static final ScrollBar VERTICAL_SCROLLBAR = UIWidgetTexture.verticalScrollBar() - .setOverflowType(ScrollBar.OverflowType.AUTO).setTrackPadding(0, BORDER_PADDING, -13, BORDER_PADDING) + .setOverflowType(ScrollBar.OverflowType.AUTO) + .setTrackPadding(0, BORDER_PADDING - 1, -13, BORDER_PADDING - 1) .setScrollPlace(ScrollBar.ScrollPlace.START); private List items = Collections.emptyList(); @@ -79,7 +63,7 @@ public class GuiRecipeCatalyst extends ScrollContainer { private int style = -1; public GuiRecipeCatalyst() { - setPaddingBlock(BORDER_PADDING + 1, BORDER_PADDING + 1); + setPaddingBlock(BORDER_PADDING, BORDER_PADDING); } public void setCatalysts(List items) { @@ -98,13 +82,15 @@ public class GuiRecipeCatalyst extends ScrollContainer { return this.availableHeight; } - public boolean isShowWidget() { - return this.showWidget; + @Override + public boolean isVisible() { + return this.showWidget && NEIClientConfig.getJEIStyleRecipeCatalysts() != 0; } public int getColumnCount() { if (NEIClientConfig.getJEIStyleRecipeCatalysts() == 1) { - final int maxItemsPerColumn = Math.max(0, this.availableHeight - 2 - BORDER_PADDING * 2) / SLOT_SIZE; + final int maxItemsPerColumn = Math + .max(0, this.availableHeight - COLUMNS_BOTTOM_INSET - 2 - BORDER_PADDING * 2) / SLOT_SIZE; return maxItemsPerColumn > 0 ? NEIServerUtils.divideCeil(this.items.size(), maxItemsPerColumn) : 0; } return 1; @@ -120,7 +106,7 @@ public class GuiRecipeCatalyst extends ScrollContainer { final int rows = getRowCount(); setVerticalScroll(null); - setPaddingInline(BORDER_PADDING + 1, BORDER_PADDING - 3); + setPaddingInline(BORDER_PADDING, BORDER_PADDING - 3); this.style = NEIClientConfig.getJEIStyleRecipeCatalysts(); this.h = rows * SLOT_SIZE + this.paddingBlockStart + this.paddingBlockEnd; @@ -132,7 +118,7 @@ public class GuiRecipeCatalyst extends ScrollContainer { this.w += VERTICAL_SCROLLBAR.getTrackWidth(); setVerticalScroll(VERTICAL_SCROLLBAR); - setPaddingInline(BORDER_PADDING + 1 + VERTICAL_SCROLLBAR.getTrackWidth(), this.paddingInlineEnd); + setPaddingInline(this.paddingInlineStart + VERTICAL_SCROLLBAR.getTrackWidth(), this.paddingInlineEnd); } this.showWidget = rows * columns > 0; @@ -162,12 +148,14 @@ public class GuiRecipeCatalyst extends ScrollContainer { if (!this.showWidget) return; GL11.glColor4f(1, 1, 1, 1); - BG_TEXTURE.draw( - this.x - TRANSPARENCY_BORDER, - this.y - TRANSPARENCY_BORDER, - this.w + TRANSPARENCY_BORDER * 2, - this.h + TRANSPARENCY_BORDER * 2); - FG_TEXTURE.draw( + + if (this.h < this.availableHeight) { + UIRecipeTexture.CATALYST_TAB_JOINED.draw(this.x, this.y, this.w, this.h); + } else { + UIRecipeTexture.CATALYST_TAB.draw(this.x, this.y, this.w, this.h); + } + + UIRecipeTexture.CATALYST_SLOT.draw( this.x + this.paddingInlineStart - 1, this.y + this.paddingBlockStart - 1, this.w - this.paddingInlineStart - this.paddingInlineEnd + 2, diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipeTab.java b/src/main/java/codechicken/nei/recipe/GuiRecipeTab.java index 521a6f68..57f861b5 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipeTab.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipeTab.java @@ -10,7 +10,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.MinecraftForge; @@ -26,11 +25,11 @@ import codechicken.nei.ColorUtils; import codechicken.nei.NEIClientConfig; import codechicken.nei.NEIClientUtils; import codechicken.nei.Widget; -import codechicken.nei.drawable.DrawableBuilder; import codechicken.nei.drawable.DrawableResource; import codechicken.nei.event.NEIRegisterHandlerInfosEvent; import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.recipe.debug.DebugHandlerWidget; +import codechicken.nei.theme.UIRecipeTexture; import cpw.mods.fml.common.Loader; public abstract class GuiRecipeTab extends Widget { @@ -44,29 +43,14 @@ public abstract class GuiRecipeTab extends Widget { protected final String handlerName; protected final String handlerID; - public static final int TAB_WIDTH = 24; - public static final int TAB_HEIGHT = 24; - private static final DrawableResource selectedTabImage = new DrawableBuilder( - "nei:textures/nei_tabbed_sprites.png", - 0, - 16, - 24, - 24).build(); - private static final DrawableResource unselectedTabImage = new DrawableBuilder( - "nei:textures/nei_tabbed_sprites.png", - 24, - 16, - 24, - 24).build(); - private boolean selected; public GuiRecipeTab(IRecipeHandler handler, int x, int y) { super(); this.x = x; this.y = y; - this.w = TAB_WIDTH; - this.h = TAB_HEIGHT; + this.w = UIRecipeTexture.TAB_UNSELECTED.getWidth(); + this.h = UIRecipeTexture.TAB_UNSELECTED.getHeight(); this.handler = handler; this.handlerName = handler.getHandlerId(); this.selected = false; @@ -84,21 +68,20 @@ public abstract class GuiRecipeTab extends Widget { drawForeground(mouseX, mouseY); } - public void drawBackground(int mouseX, int mouseY) { + private void drawBackground(int mouseX, int mouseY) { + final DrawableResource image = this.selected ? UIRecipeTexture.TAB_SELECTED : UIRecipeTexture.TAB_UNSELECTED; + GL11.glDisable(GL11.GL_LIGHTING); GL11.glColor4f(1, 1, 1, 1); - final DrawableResource image = this.selected ? selectedTabImage : unselectedTabImage; - image.draw(this.x, this.y); + image.draw(this.x, this.y, this.w, this.h); } - public void drawForeground(int mouseX, int mouseY) { - final int iconX = this.x + 4; - final int iconY = this.y + 4; - - final FontRenderer fontRenderer = GuiDraw.fontRenderer; + private void drawForeground(int mouseX, int mouseY) { final HandlerInfo handlerInfo = getHandlerInfo(this.handlerName, this.handlerID); final DrawableResource icon = handlerInfo != null ? handlerInfo.getImage() : null; final ItemStack itemStack = handlerInfo != null ? handlerInfo.getItemStack() : null; + final int iconX = this.x + (this.w - 16) / 2; + final int iconY = this.y + this.h - 16 - 6; if (icon != null) { icon.draw(iconX + 1, iconY + 1); @@ -111,24 +94,17 @@ public abstract class GuiRecipeTab extends Widget { if (!isEnabled) GL11.glDisable(GL12.GL_RESCALE_NORMAL); } else { // Text fallback + final int color = this.selected ? ColorUtils.buttonLabelHover.getColor() + : ColorUtils.buttonLabelNormal.getColor(); String text = this.handler.getRecipeName(); - if (text != null && text.length() > 0) { - if (text.length() > 2) { - text = text.substring(0, 2); - } - } else { + + if (text == null || text.length() == 0) { text = "??"; + } else if (text.length() > 2) { + text = text.substring(0, 2); } - int textCenterX = this.x + (int) (this.w / 2f); - int textCenterY = this.y + (int) (this.h / 2f) - 3; - int color = this.selected ? ColorUtils.buttonLabelHover.getColor() - : ColorUtils.buttonLabelNormal.getColor(); - fontRenderer.drawStringWithShadow( - text, - textCenterX - (int) (fontRenderer.getStringWidth(text) / 2f), - textCenterY, - color); + GuiDraw.drawStringC(text, iconX + 8, iconY + 4, color); GL11.glColor4f(1, 1, 1, 1); } } diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipeTabs.java b/src/main/java/codechicken/nei/recipe/GuiRecipeTabs.java index d3f4c641..0d58d707 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipeTabs.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipeTabs.java @@ -2,19 +2,23 @@ package codechicken.nei.recipe; import java.awt.Rectangle; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.function.BooleanSupplier; import codechicken.lib.gui.GuiDraw; import codechicken.nei.Button; import codechicken.nei.NEIClientConfig; -import codechicken.nei.NEIClientUtils; +import codechicken.nei.drawable.DrawableResource; +import codechicken.nei.theme.UIRecipeTexture; +import codechicken.nei.theme.UIWidgetTexture; public class GuiRecipeTabs { private final List tabs = new ArrayList<>(); private final List