2022-01-22 13:16:28 +09:00
|
|
|
package codechicken.nei.recipe;
|
|
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
|
|
import codechicken.lib.gui.GuiDraw;
|
2025-10-21 15:28:14 +03:00
|
|
|
import codechicken.nei.NEIClientConfig;
|
2025-10-12 19:39:21 +03:00
|
|
|
import codechicken.nei.NEIClientUtils;
|
|
|
|
|
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;
|
2025-10-21 15:28:14 +03:00
|
|
|
import codechicken.nei.scroll.ScrollBar;
|
|
|
|
|
import codechicken.nei.scroll.ScrollContainer;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2025-10-12 19:39:21 +03:00
|
|
|
|
2025-10-21 15:28:14 +03:00
|
|
|
@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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-12 19:39:21 +03:00
|
|
|
|
|
|
|
|
private static final int SLOT_SIZE = 16;
|
|
|
|
|
private static final int BORDER_PADDING = 6;
|
2025-12-28 15:40:21 +01:00
|
|
|
private static final int TRANSPARENCY_BORDER = 4;
|
2025-10-12 19:39:21 +03:00
|
|
|
private static final DrawableResource BG_TEXTURE = new DrawableBuilder(
|
|
|
|
|
"nei:textures/catalyst_tab.png",
|
|
|
|
|
0,
|
|
|
|
|
0,
|
2025-12-28 15:40:21 +01:00
|
|
|
28 + TRANSPARENCY_BORDER * 2,
|
|
|
|
|
28 + TRANSPARENCY_BORDER * 2).setTextureSize(28 + TRANSPARENCY_BORDER * 2, 28 + TRANSPARENCY_BORDER * 2)
|
|
|
|
|
.build();
|
2025-10-12 19:39:21 +03:00
|
|
|
|
|
|
|
|
private static final DrawableResource FG_TEXTURE = new DrawableBuilder("nei:textures/slot.png", 0, 0, 18, 18)
|
|
|
|
|
.setTextureSize(18, 18).build();
|
|
|
|
|
|
2025-10-21 15:28:14 +03:00
|
|
|
private static final ScrollBar VERTICAL_SCROLLBAR = ScrollBar.defaultVerticalBar()
|
2025-11-05 19:00:09 +02:00
|
|
|
.setOverflowType(ScrollBar.OverflowType.AUTO).setTrackPadding(0, BORDER_PADDING, -13, BORDER_PADDING)
|
|
|
|
|
.setScrollPlace(ScrollBar.ScrollPlace.START);
|
2025-10-21 15:28:14 +03:00
|
|
|
|
2025-11-05 19:00:09 +02:00
|
|
|
private PositionedStack[] items = new PositionedStack[0];
|
2025-10-12 19:39:21 +03:00
|
|
|
private boolean showWidget = false;
|
2025-10-21 15:28:14 +03:00
|
|
|
private int availableHeight = 0;
|
|
|
|
|
|
|
|
|
|
public GuiRecipeCatalyst() {
|
|
|
|
|
setPaddingBlock(BORDER_PADDING + 1, BORDER_PADDING + 1);
|
|
|
|
|
}
|
2025-10-12 19:39:21 +03:00
|
|
|
|
|
|
|
|
public void setCatalysts(List<PositionedStack> items) {
|
2025-11-05 19:00:09 +02:00
|
|
|
this.items = items.toArray(new PositionedStack[0]);
|
2025-10-21 15:28:14 +03:00
|
|
|
createWidgets();
|
2025-10-12 19:39:21 +03:00
|
|
|
}
|
2023-09-25 00:35:24 +02:00
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
public void setAvailableHeight(int height) {
|
2025-10-21 15:28:14 +03:00
|
|
|
if (this.availableHeight != height) {
|
|
|
|
|
this.availableHeight = height;
|
|
|
|
|
createWidgets();
|
|
|
|
|
}
|
2025-10-12 19:39:21 +03:00
|
|
|
}
|
2022-01-22 13:16:28 +09:00
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
public int getAvailableHeight() {
|
|
|
|
|
return this.availableHeight;
|
|
|
|
|
}
|
2023-09-25 00:35:24 +02:00
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
public boolean isShowWidget() {
|
|
|
|
|
return this.showWidget;
|
|
|
|
|
}
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
public int getColumnCount() {
|
2025-10-21 15:28:14 +03:00
|
|
|
if (NEIClientConfig.getJEIStyleRecipeCatalysts() == 1) {
|
|
|
|
|
final int maxItemsPerColumn = Math.max(0, this.availableHeight - 2 - BORDER_PADDING * 2) / SLOT_SIZE;
|
2025-11-05 19:00:09 +02:00
|
|
|
return maxItemsPerColumn > 0 ? NEIServerUtils.divideCeil(this.items.length, maxItemsPerColumn) : 0;
|
2025-10-21 15:28:14 +03:00
|
|
|
}
|
|
|
|
|
return 1;
|
2025-10-12 19:39:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getRowCount() {
|
|
|
|
|
final int columnCount = getColumnCount();
|
2025-11-05 19:00:09 +02:00
|
|
|
return columnCount > 0 ? NEIServerUtils.divideCeil(this.items.length, columnCount) : 0;
|
2025-10-12 19:39:21 +03:00
|
|
|
}
|
|
|
|
|
|
2025-10-21 15:28:14 +03:00
|
|
|
protected void createWidgets() {
|
2025-10-12 19:39:21 +03:00
|
|
|
final int columns = getColumnCount();
|
|
|
|
|
final int rows = getRowCount();
|
|
|
|
|
|
2025-10-21 15:28:14 +03:00
|
|
|
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);
|
2025-11-05 19:00:09 +02:00
|
|
|
this.w += VERTICAL_SCROLLBAR.getTrackWidth();
|
2025-10-21 15:28:14 +03:00
|
|
|
|
|
|
|
|
setVerticalScroll(VERTICAL_SCROLLBAR);
|
2025-11-05 19:00:09 +02:00
|
|
|
setPaddingInline(BORDER_PADDING + 1 + VERTICAL_SCROLLBAR.getTrackWidth(), this.paddingInlineEnd);
|
2025-10-21 15:28:14 +03:00
|
|
|
}
|
|
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
this.showWidget = rows * columns > 0;
|
|
|
|
|
|
|
|
|
|
if (rows == 0 || columns == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-21 15:28:14 +03:00
|
|
|
final int visibleWidth = getVisibleWidth();
|
|
|
|
|
final List<Widget> widgets = new ArrayList<>();
|
2025-10-12 19:39:21 +03:00
|
|
|
int index = 0;
|
2025-10-21 15:28:14 +03:00
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
for (PositionedStack pStack : this.items) {
|
2025-10-21 15:28:14 +03:00
|
|
|
pStack.relx = visibleWidth - SLOT_SIZE - (index / rows) * SLOT_SIZE;
|
|
|
|
|
pStack.rely = (index % rows) * SLOT_SIZE;
|
2025-10-12 19:39:21 +03:00
|
|
|
index++;
|
2025-10-21 15:28:14 +03:00
|
|
|
|
|
|
|
|
widgets.add(new ItemStackWidget(pStack));
|
2025-10-12 19:39:21 +03:00
|
|
|
}
|
|
|
|
|
|
2025-10-21 15:28:14 +03:00
|
|
|
setWidgets(widgets);
|
2025-10-12 19:39:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void draw(int mx, int my) {
|
|
|
|
|
if (!this.showWidget) return;
|
|
|
|
|
|
|
|
|
|
GL11.glColor4f(1, 1, 1, 1);
|
2025-12-28 15:40:21 +01:00
|
|
|
BG_TEXTURE.draw(
|
|
|
|
|
this.x - TRANSPARENCY_BORDER,
|
|
|
|
|
this.y - TRANSPARENCY_BORDER,
|
|
|
|
|
this.w + TRANSPARENCY_BORDER * 2,
|
|
|
|
|
this.h + TRANSPARENCY_BORDER * 2,
|
|
|
|
|
BORDER_PADDING + TRANSPARENCY_BORDER,
|
|
|
|
|
BORDER_PADDING + TRANSPARENCY_BORDER,
|
|
|
|
|
BORDER_PADDING + TRANSPARENCY_BORDER,
|
|
|
|
|
BORDER_PADDING + TRANSPARENCY_BORDER);
|
2025-10-12 19:39:21 +03:00
|
|
|
FG_TEXTURE.draw(
|
2025-10-21 15:28:14 +03:00
|
|
|
this.x + this.paddingInlineStart - 1,
|
|
|
|
|
this.y + this.paddingBlockStart - 1,
|
|
|
|
|
this.w - this.paddingInlineStart - this.paddingInlineEnd + 2,
|
|
|
|
|
this.h - this.paddingBlockStart - this.paddingBlockEnd + 2,
|
2025-10-12 19:39:21 +03:00
|
|
|
1,
|
|
|
|
|
1,
|
|
|
|
|
1,
|
|
|
|
|
1);
|
|
|
|
|
|
2025-10-21 15:28:14 +03:00
|
|
|
super.draw(mx, my);
|
2022-01-22 13:16:28 +09:00
|
|
|
}
|
|
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
public PositionedStack getPositionedStackMouseOver(int mx, int my) {
|
2025-10-21 15:28:14 +03:00
|
|
|
final Widget widget = getWidgetUnderMouse(mx, my);
|
2025-10-12 19:39:21 +03:00
|
|
|
|
2025-10-21 15:28:14 +03:00
|
|
|
if (widget instanceof ItemStackWidget stackWidget) {
|
|
|
|
|
return stackWidget.pStack;
|
2025-10-12 19:39:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2022-01-22 13:16:28 +09:00
|
|
|
}
|
|
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
@Deprecated
|
|
|
|
|
public static final int ingredientSize = 16;
|
|
|
|
|
@Deprecated
|
|
|
|
|
public static final int ingredientBorder = 1;
|
|
|
|
|
@Deprecated
|
|
|
|
|
public static final int tabBorder = 5;
|
|
|
|
|
@Deprecated
|
|
|
|
|
public static final int fullBorder = ingredientBorder + tabBorder;
|
|
|
|
|
|
2022-01-22 13:16:28 +09:00
|
|
|
}
|