Skip to content

Commit ebfa8a2

Browse files
authored
[MUI] - Singleblock RecipeType UIs (#4309)
1 parent c3ab309 commit ebfa8a2

File tree

13 files changed

+652
-358
lines changed

13 files changed

+652
-358
lines changed

src/main/java/com/gregtechceu/gtceu/api/mui/widgets/slot/FluidSlot.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public FluidSlot() {
7373
protected void addTooltip(RichTooltip tooltip) {
7474
IFluidTank fluidTank = getFluidTank();
7575
FluidStack fluid = this.syncHandler.getValue();
76-
if (fluid != null) {
76+
if (fluid != null && !fluid.isEmpty()) {
7777
tooltip.addLine(IKey.lang(fluid.getDisplayName())).spaceLine(2);
7878
}
7979
if (this.syncHandler.phantom()) {
@@ -83,33 +83,34 @@ protected void addTooltip(RichTooltip tooltip) {
8383
formatFluidTooltipAmount(fluid.getAmount()), getUnit()));
8484
}
8585
} else {
86-
tooltip.addLine(IKey.lang("modularui.fluid.empty"));
87-
tooltip.addLine(IKey.lang("modularui.fluid.capacity", formatFluidTooltipAmount(fluidTank.getCapacity()),
88-
getUnit()));
86+
tooltip.addLine(IKey.lang("gtceu.fluid.empty"));
87+
tooltip.addLine(
88+
IKey.lang("gtceu.fluid_pipe.capacity", formatFluidTooltipAmount(fluidTank.getCapacity()),
89+
getUnit()));
8990
}
9091
if (this.syncHandler.controlsAmount()) {
9192
tooltip.addLine(IKey.lang("modularui.fluid.phantom.control"));
9293
}
9394
} else {
9495
if (fluid != null) {
95-
tooltip.addLine(IKey.lang("modularui.fluid.amount", formatFluidTooltipAmount(fluid.getAmount()),
96+
tooltip.addLine(IKey.lang("gtceu.fluid.amount", formatFluidTooltipAmount(fluid.getAmount()),
9697
formatFluidTooltipAmount(fluidTank.getCapacity()), getUnit()));
9798
addAdditionalFluidInfo(tooltip, fluid);
9899
} else {
99-
tooltip.addLine(IKey.lang("modularui.fluid.empty"));
100+
tooltip.addLine(IKey.lang("gtceu.fluid.empty"));
100101
}
101102
if (this.syncHandler.canFillSlot() || this.syncHandler.canDrainSlot()) {
102103
tooltip.addLine(IKey.EMPTY); // Add an empty line to separate from the bottom material tooltips
103104
if (Interactable.hasShiftDown()) {
104105
if (this.syncHandler.canFillSlot() && this.syncHandler.canDrainSlot()) {
105-
tooltip.addLine(IKey.lang("modularui.fluid.click_combined"));
106+
tooltip.addLine(IKey.lang("gtceu.fluid.click_combined"));
106107
} else if (this.syncHandler.canDrainSlot()) {
107-
tooltip.addLine(IKey.lang("modularui.fluid.click_to_fill"));
108+
tooltip.addLine(IKey.lang("gtceu.fluid.click_to_fill"));
108109
} else if (this.syncHandler.canFillSlot()) {
109-
tooltip.addLine(IKey.lang("modularui.fluid.click_to_empty"));
110+
tooltip.addLine(IKey.lang("gtceu.fluid.click_to_empty"));
110111
}
111112
} else {
112-
tooltip.addLine(IKey.lang("modularui.tooltip.shift"));
113+
tooltip.addLine(IKey.lang("gtceu.tooltip.hold_shift"));
113114
}
114115
}
115116
}
@@ -188,7 +189,8 @@ public void draw(ModularGuiContext context, WidgetThemeEntry<?> widgetTheme) {
188189
if (this.overlayTexture != null) {
189190
this.overlayTexture.drawAtZeroPadded(context, getArea(), getActiveWidgetTheme(widgetTheme, isHovering()));
190191
}
191-
if (content != null && this.syncHandler.controlsAmount()) {
192+
if (content != null && !content.isEmpty() && this.syncHandler.controlsAmount()) {
193+
192194
String s = FormattingUtil.formatNumberReadable2F(getBaseUnitAmount(content.getAmount()), false) +
193195
getBaseUnit();
194196
this.textRenderer.setAlignment(Alignment.CenterRight, getArea().width - this.contentOffsetX - 1f);

src/main/java/com/gregtechceu/gtceu/api/recipe/gui/GTRecipeTypeUILayout.java

Lines changed: 192 additions & 74 deletions
Large diffs are not rendered by default.

src/main/java/com/gregtechceu/gtceu/api/recipe/gui/GTRecipeTypeUIXEI.java

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package com.gregtechceu.gtceu.api.recipe.gui;
2+
3+
import com.gregtechceu.gtceu.api.GTValues;
4+
import com.gregtechceu.gtceu.api.capability.recipe.IO;
5+
import com.gregtechceu.gtceu.api.capability.recipe.ItemRecipeCapability;
6+
import com.gregtechceu.gtceu.api.mui.base.drawable.IDrawable;
7+
import com.gregtechceu.gtceu.api.mui.utils.Alignment;
8+
import com.gregtechceu.gtceu.api.mui.widget.ParentWidget;
9+
import com.gregtechceu.gtceu.api.mui.widgets.ProgressWidget;
10+
import com.gregtechceu.gtceu.api.mui.widgets.SlotGroupWidget;
11+
import com.gregtechceu.gtceu.api.mui.widgets.layout.Column;
12+
import com.gregtechceu.gtceu.api.mui.widgets.layout.Row;
13+
import com.gregtechceu.gtceu.common.mui.GTGuiTextures;
14+
15+
import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap;
16+
17+
import java.util.ArrayList;
18+
import java.util.Map;
19+
20+
public class GTRecipeViewerUILayout {
21+
22+
public final GTRecipeTypeUILayout layout;
23+
24+
private ParentWidget<? extends ParentWidget<?>> overrideWidget;
25+
26+
public GTRecipeViewerUILayout(GTRecipeTypeUILayout layout) {
27+
this.layout = layout;
28+
}
29+
30+
public GTRecipeViewerUILayout overrideWidget(ParentWidget<? extends ParentWidget<?>> overrideWidget) {
31+
this.overrideWidget = overrideWidget;
32+
return this;
33+
}
34+
35+
public ParentWidget<?> getRecipeWidget() {
36+
if (layout.getRecipeType() != null) {
37+
var parentWidget = new ParentWidget<>();
38+
parentWidget.coverChildren();
39+
var slotsRow = new Row();
40+
slotsRow.coverChildrenHeight();
41+
42+
int rowWidthPx = 0;
43+
44+
Map<IO, ParentWidget<?>> colWidgetGroups = new Object2ReferenceOpenHashMap<>();
45+
46+
int slotLeftShiftPx = 0;
47+
for (var io : layout.getIOs()) {
48+
boolean in = io == IO.IN;
49+
50+
var caps = (in ? layout.getRecipeType().maxInputs : layout.getRecipeType().maxOutputs);
51+
int slotGroupHeightPx = 0;
52+
53+
Column ioColumn = new Column();
54+
// ioColumn.coverChildrenWidth();
55+
int slotGroupWidthPx = 0;
56+
57+
var widgetGroups = new ArrayList<ParentWidget<?>>();
58+
59+
for (var recipeCap : caps.keySet()) {
60+
int maxRecipeTypeSlots = caps.get(recipeCap);
61+
62+
var grid = layout.createGrid(io, recipeCap, 's', GTValues.MAX, Integer.MAX_VALUE);
63+
64+
slotGroupHeightPx += 18 * grid.length;
65+
66+
IDrawable defaultSlotBackground = (recipeCap == ItemRecipeCapability.CAP ?
67+
GTGuiTextures.SLOT : GTGuiTextures.FLUID_SLOT);
68+
69+
SlotGroupWidget.Builder slotWidgetBuilder = SlotGroupWidget.builder()
70+
.matrix(grid);
71+
var overlays = layout.getOverlays();
72+
slotWidgetBuilder.key('s', i -> {
73+
var widget = new IDrawable.DrawableWidget(defaultSlotBackground);
74+
if (overlays.containsKey(io) && overlays.get(io).containsKey(recipeCap)) {
75+
widget.overlay(overlays.get(io).get(recipeCap).get(i));
76+
}
77+
return widget;
78+
});
79+
80+
// calculate full width of each column
81+
slotGroupWidthPx = Math.max(slotGroupWidthPx, Math.min(maxRecipeTypeSlots, grid[0].length()) * 18);
82+
83+
widgetGroups.add(slotWidgetBuilder.build()
84+
.name(recipeCap.name + "_" + io.name())
85+
.alignX(io == IO.IN ? Alignment.TopLeft : Alignment.TopRight));
86+
}
87+
88+
ioColumn.size(slotGroupWidthPx, slotGroupHeightPx);
89+
for (var g : widgetGroups) {
90+
ioColumn.child(g);
91+
}
92+
slotLeftShiftPx += (slotGroupWidthPx / 2) * ((io == io.IN) ? -1 : 1);
93+
94+
rowWidthPx += slotGroupWidthPx;
95+
colWidgetGroups.put(io, ioColumn);
96+
}
97+
// 2 px padding plus each half of the progress bar (1)
98+
slotsRow.childPadding((layout.getProgressSize() / 2) + 2);
99+
for (var ioColumn : colWidgetGroups.entrySet()) {
100+
var col = ioColumn.getValue();
101+
var io = ioColumn.getKey();
102+
slotsRow.child(col.align(io == IO.IN ? Alignment.CenterLeft : Alignment.CenterRight));
103+
}
104+
105+
// same padding as (1) + half a slot on each side
106+
rowWidthPx += layout.getProgressSize() + 4 + 18;
107+
slotsRow.width(rowWidthPx);
108+
109+
parentWidget.child(slotsRow.left(slotLeftShiftPx));
110+
111+
parentWidget.child(new ProgressWidget()
112+
.center()
113+
.progress(() -> 0.5f)
114+
.name("progressBar")
115+
.texture(layout.getProgressBar(), layout.getProgressSize())
116+
.size(layout.getProgressSize())
117+
.direction(layout.getProgressDirection()));
118+
return parentWidget;
119+
}
120+
return new ParentWidget<>();
121+
}
122+
}

src/main/java/com/gregtechceu/gtceu/common/data/GTMachines.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ public class GTMachines {
179179
(holder, tier) -> new SimpleTieredMachine(holder, tier, defaultTankSizeFunction), (tier, builder) -> builder
180180
.langValue("%s Arc Furnace %s".formatted(VLVH[tier], VLVT[tier]))
181181
.UI(GTSingleblockMachinePanels.ARC_FURNACE)
182-
.editableUI(SimpleTieredMachine.EDITABLE_UI_CREATOR.apply(GTCEu.id("arc_furnace"),
183-
GTRecipeTypes.ARC_FURNACE_RECIPES))
182+
// .editableUI(SimpleTieredMachine.EDITABLE_UI_CREATOR.apply(GTCEu.id("arc_furnace"),
183+
// GTRecipeTypes.ARC_FURNACE_RECIPES))
184184
.rotationState(RotationState.NON_Y_AXIS)
185185
.recipeType(GTRecipeTypes.ARC_FURNACE_RECIPES)
186186
.recipeModifier(GTRecipeModifiers.OC_NON_PERFECT)
@@ -281,8 +281,8 @@ public class GTMachines {
281281
(holder, tier) -> new SimpleTieredMachine(holder, tier, defaultTankSizeFunction), (tier, builder) -> builder
282282
.langValue("%s Macerator %s".formatted(VLVH[tier], VLVT[tier]))
283283
.UI(GTSingleblockMachinePanels.MACERATOR)
284-
.editableUI(SimpleTieredMachine.EDITABLE_UI_CREATOR.apply(GTCEu.id("macerator"),
285-
GTRecipeTypes.MACERATOR_RECIPES))
284+
// .editableUI(SimpleTieredMachine.EDITABLE_UI_CREATOR.apply(GTCEu.id("macerator"),
285+
// GTRecipeTypes.MACERATOR_RECIPES))
286286
.rotationState(RotationState.NON_Y_AXIS)
287287
.recipeType(GTRecipeTypes.MACERATOR_RECIPES)
288288
.addOutputLimit(ItemRecipeCapability.CAP, switch (tier) {

0 commit comments

Comments
 (0)