Skip to content

Commit e8bc2c9

Browse files
committed
rework mostly done
1 parent 7595eb3 commit e8bc2c9

File tree

2 files changed

+204
-23
lines changed

2 files changed

+204
-23
lines changed

src/main/java/gregtech/api/metatileentity/SimpleMachineMetaTileEntity.java

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package gregtech.api.metatileentity;
22

3+
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
4+
5+
import com.cleanroommc.modularui.widgets.layout.Flow;
6+
37
import gregtech.api.GTValues;
48
import gregtech.api.capability.GregtechTileCapabilities;
59
import gregtech.api.capability.IActiveOutputSide;
@@ -501,33 +505,41 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager)
501505
yOffset = FONT_HEIGHT;
502506
}
503507

504-
ModularPanel panel = GTGuis.createPanel(this, 176, 166 + yOffset);
508+
ModularPanel panel = GTGuis.createPanel(this, 176 + 20, 166 + yOffset);
509+
Flow col = Flow.column()
510+
.debugName("special.buttons")
511+
.right(7).bottom(7)
512+
.height(18 * 4 + 4)
513+
.width(18);
505514

506515
BooleanSyncValue hasEnergy = new BooleanSyncValue(workable::isHasNotEnoughEnergy);
507516
guiSyncManager.syncValue("has_energy", hasEnergy);
508517

509518
workableRecipeMap.getRecipeMapUI().constructPanel(panel, workable::getProgressPercent,
510519
importItems, exportItems, importFluids, exportFluids, yOffset, guiSyncManager)
511520
.child(IKey.lang(getMetaFullName()).asWidget().pos(5, 5))
512-
.child(new ItemSlot()
513-
.slot(SyncHandlers.itemSlot(chargerInventory, 0))
514-
.pos(79, 62 + yOffset)
515-
.background(GTGuiTextures.SLOT, GTGuiTextures.CHARGER_OVERLAY)
516-
.addTooltipLine(IKey.lang("gregtech.gui.charger_slot.tooltip",
517-
GTValues.VNF[getTier()], GTValues.VNF[getTier()])))
518521
.child(new Widget<>()
522+
.debugName("energy.indicator")
519523
.size(18, 18)
520524
.pos(79, 42 + yOffset)
521525
.background(GTGuiTextures.INDICATOR_NO_ENERGY)
522526
.setEnabledIf($ -> hasEnergy.getBoolValue()))
523-
.bindPlayerInventory();
527+
.child(col)
528+
.child(SlotGroupWidget.playerInventory().left(7));
529+
530+
col.child(new ItemSlot()
531+
.debugName("charger.slot")
532+
.slot(SyncHandlers.itemSlot(chargerInventory, 0))
533+
// .pos(79, 62 + yOffset)
534+
.background(GTGuiTextures.SLOT, GTGuiTextures.CHARGER_OVERLAY)
535+
.addTooltipLine(IKey.lang("gregtech.gui.charger_slot.tooltip",
536+
GTValues.VNF[getTier()], GTValues.VNF[getTier()])));
524537

525538
int leftButtonStartX = 7;
526539

527540
if (exportItems.getSlots() > 0) {
528-
529-
panel.child(new ToggleButton()
530-
.pos(leftButtonStartX, 62 + yOffset)
541+
col.child(new ToggleButton()
542+
// .pos(leftButtonStartX, 62 + yOffset)
531543
.overlay(GTGuiTextures.BUTTON_ITEM_OUTPUT)
532544
.value(new BooleanSyncValue(() -> autoOutputItems, val -> autoOutputItems = val))
533545
.addTooltip(true, IKey.lang("gregtech.gui.item_auto_output.tooltip.enabled"))
@@ -538,23 +550,25 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager)
538550

539551
if (exportFluids.getTanks() > 0) {
540552

541-
panel.child(new ToggleButton()
542-
.pos(leftButtonStartX, 62 + yOffset)
553+
col.child(new ToggleButton()
554+
// .pos(leftButtonStartX, 62 + yOffset)
543555
.overlay(GTGuiTextures.BUTTON_FLUID_OUTPUT)
544556
.value(new BooleanSyncValue(() -> autoOutputFluids, val -> autoOutputFluids = val))
545557
.addTooltip(true, IKey.lang("gregtech.gui.fluid_auto_output.tooltip.enabled"))
546558
.addTooltip(false, IKey.lang("gregtech.gui.fluid_auto_output.tooltip.disabled")));
547559
}
548560

549561
if (exportItems.getSlots() + exportFluids.getTanks() <= 9) {
550-
panel.child(new Widget<>()
562+
col.child(new Widget<>()
551563
.size(17)
552-
.pos(152, 63 + yOffset)
564+
.marginTop(1).marginRight(1)
565+
.bottom(0)
566+
// .pos(152, 63 + yOffset)
553567
.background(GTGuiTextures.getLogo(getUITheme())));
554568

555569
if (hasGhostCircuitInventory() && circuitInventory != null) {
556-
panel.child(new GhostCircuitSlotWidget()
557-
.pos(124, 62 + yOffset)
570+
col.child(new GhostCircuitSlotWidget()
571+
// .pos(124, 62 + yOffset)
558572
.slot(SyncHandlers.itemSlot(circuitInventory, 0))
559573
.background(GTGuiTextures.SLOT, GTGuiTextures.INT_CIRCUIT_OVERLAY));
560574
}

src/main/java/gregtech/api/recipes/ui/RecipeMapUI.java

Lines changed: 173 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@
1515
import net.minecraftforge.items.IItemHandlerModifiable;
1616

1717
import com.cleanroommc.modularui.api.drawable.IDrawable;
18+
import com.cleanroommc.modularui.api.widget.IWidget;
1819
import com.cleanroommc.modularui.drawable.UITexture;
1920
import com.cleanroommc.modularui.screen.ModularPanel;
21+
import com.cleanroommc.modularui.utils.Alignment;
2022
import com.cleanroommc.modularui.value.sync.DoubleSyncValue;
2123
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
2224
import com.cleanroommc.modularui.value.sync.SyncHandlers;
2325
import com.cleanroommc.modularui.widget.ParentWidget;
26+
import com.cleanroommc.modularui.widget.Widget;
2427
import com.cleanroommc.modularui.widget.sizer.Area;
2528
import com.cleanroommc.modularui.widgets.ItemSlot;
2629
import com.cleanroommc.modularui.widgets.ProgressWidget;
30+
import com.cleanroommc.modularui.widgets.layout.Flow;
2731
import com.cleanroommc.modularui.widgets.layout.Grid;
2832
import com.cleanroommc.modularui.widgets.slot.SlotGroup;
2933
import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap;
@@ -35,6 +39,8 @@
3539
import org.jetbrains.annotations.NotNull;
3640
import org.jetbrains.annotations.Nullable;
3741

42+
import java.util.ArrayList;
43+
import java.util.List;
3844
import java.util.function.Consumer;
3945
import java.util.function.DoubleSupplier;
4046

@@ -547,19 +553,30 @@ public ModularPanel constructPanel(ModularPanel panel, DoubleSupplier progressSu
547553
FluidTankList exportFluids, int yOffset, PanelSyncManager syncManager) {
548554
DoubleSyncValue progressValue = new DoubleSyncValue(progressSupplier);
549555

550-
panel.debugName("recipemapui.parent");
556+
Flow row = Flow.row()
557+
.height(3 * 18 + 9)
558+
.debugName("recipemapui.parent")
559+
.crossAxisAlignment(Alignment.CrossAxis.CENTER)
560+
.top(23 - 7);
551561

552-
panel.child(new RecipeProgressWidget()
562+
int m = calculateCenter(importItems.getSlots(), importFluids.getTanks(), 176 + 20);
563+
564+
row.child(makeInventorySlotGroup(importItems, importFluids, false)
565+
.marginLeft(m - 4));
566+
row.child(new RecipeProgressWidget()
553567
.recipeMap(recipeMap)
554568
.debugName("recipe.progress")
555569
.size(20)
556-
.alignX(0.5f)
557-
.top(23 + yOffset)
570+
.margin(4, 0)
571+
// .alignX(0.5f)
572+
// .top(23 + yOffset)
558573
.value(progressValue)
559574
.texture(progressTexture, 20)
560575
.direction(progressDirection));
561-
addInventorySlotGroup(panel, importItems, importFluids, false, yOffset);
562-
addInventorySlotGroup(panel, exportItems, exportFluids, true, yOffset);
576+
row.child(makeInventorySlotGroup(exportItems, exportFluids, true));
577+
// addInventorySlotGroup(panel, importItems, importFluids, false, yOffset);
578+
// addInventorySlotGroup(panel, exportItems, exportFluids, true, yOffset);
579+
panel.child(row);
563580
if (specialDrawableTexture != null) {
564581
panel.child(specialDrawableTexture.asWidget()
565582
.debugName("special_texture")
@@ -569,6 +586,154 @@ public ModularPanel constructPanel(ModularPanel panel, DoubleSupplier progressSu
569586
return panel;
570587
}
571588

589+
private int calculateCenter(int inputItems, int inputFluids, int panelSize) {
590+
int[] ints = determineSlotsGrid(inputItems, inputFluids);
591+
int leftSize = ints[1] >= inputFluids && ints[0] < 3 ?
592+
(ints[0] + ints[2]) * 18 :
593+
Math.max(ints[0] * 18, ints[2] * 18);
594+
int p = panelSize / 2;
595+
p -= 10;
596+
p -= leftSize;
597+
return p;
598+
}
599+
600+
private Widget<?> makeItemGroup(int width, IItemHandlerModifiable handler, boolean isOutputs) {
601+
Flow col = Flow.column().mainAxisAlignment(Alignment.MainAxis.END)
602+
.coverChildren().debugName("item.col");
603+
int c = handler.getSlots();
604+
int h = (int) Math.ceil((double) c / width);
605+
SlotGroup slotGroup = new SlotGroup(isOutputs ? "output_items" : "input_items",
606+
width, 1, !isOutputs);
607+
for (int i = 0; i < h; i++) {
608+
Flow row = Flow.row().mainAxisAlignment(isOutputs ? Alignment.MainAxis.START : Alignment.MainAxis.END)
609+
.coverChildren().debugName("item.row." + i);
610+
for (int j = 0; j < width; j++) {
611+
row.child(makeItemSlot(slotGroup, (i * h) + j, handler, isOutputs));
612+
}
613+
col.child(row);
614+
}
615+
return col;
616+
}
617+
618+
private Widget<?> makeFluidGroup(int width, FluidTankList handler, boolean isOutputs) {
619+
Flow col = Flow.column().mainAxisAlignment(Alignment.MainAxis.START)
620+
.coverChildren().debugName("fluid.col");
621+
int c = handler.getTanks();
622+
int h = (int) Math.ceil((double) c / width);
623+
for (int i = 0; i < h; i++) {
624+
Flow row = Flow.row().mainAxisAlignment(isOutputs ? Alignment.MainAxis.START : Alignment.MainAxis.END)
625+
.coverChildren().debugName("fluid.row");
626+
for (int j = 0; j < width; j++) {
627+
row.child(makeFluidSlot((i * h) + j, handler, isOutputs));
628+
}
629+
col.child(row);
630+
}
631+
return col;
632+
}
633+
634+
protected Widget<?> makeInventorySlotGroup(@NotNull IItemHandlerModifiable itemHandler,
635+
@NotNull FluidTankList fluidHandler, boolean isOutputs) {
636+
final int itemInputsCount = itemHandler.getSlots();
637+
boolean onlyFluids = itemInputsCount == 0;
638+
final int fluidInputsCount = fluidHandler.getTanks();
639+
if (fluidInputsCount == 0 && onlyFluids)
640+
return null; // nothing to do here
641+
642+
int[] slotGridSizes = determineSlotsGrid(itemInputsCount, fluidInputsCount);
643+
int itemGridWidth = slotGridSizes[onlyFluids ? 2 : 0];
644+
int itemGridHeight = slotGridSizes[onlyFluids ? 3 : 1];
645+
646+
int fluidGridWidth = slotGridSizes[2];
647+
int fluidGridHeight = slotGridSizes[3];
648+
boolean singleRow = itemGridHeight >= fluidInputsCount && itemGridWidth < 3;
649+
650+
Flow flow = (singleRow ? Flow.row() : Flow.column()).coverChildren()
651+
.debugName(singleRow ? "parent.row" : "parent.col");
652+
flow.crossAxisAlignment(isOutputs ? Alignment.CrossAxis.START : Alignment.CrossAxis.END);
653+
654+
if (!onlyFluids && fluidGridHeight > 1) {
655+
// 1 should be 18, 2 should be 0, 3 should be -18, 4 should be -36
656+
// this is to make the first item row align with progress widget
657+
flow.top((2 - itemGridHeight) * 18);
658+
}
659+
660+
if (itemInputsCount > 6) {
661+
flow.top(0);
662+
}
663+
664+
if (onlyFluids) {
665+
flow.childIf(fluidInputsCount > 0, () -> makeFluidGroup(fluidGridWidth, fluidHandler, isOutputs));
666+
} else {
667+
flow.childIf(!singleRow || isOutputs, () -> makeItemGroup(itemGridWidth, itemHandler, isOutputs));
668+
flow.childIf(fluidInputsCount > 0, () -> makeFluidGroup(fluidGridWidth, fluidHandler, isOutputs));
669+
flow.childIf(singleRow && !isOutputs, () -> makeItemGroup(itemGridWidth, itemHandler, isOutputs));
670+
}
671+
672+
if (true) {
673+
return flow;
674+
}
675+
676+
Grid grid = new Grid()
677+
.debugName(isOutputs ? "output.grid" : "input.grid");
678+
679+
SlotGroup slotGroup = new SlotGroup(isOutputs ? "output_items" : "input_items", itemGridWidth, 1,
680+
!isOutputs);
681+
int tHeight = singleRow ? itemGridHeight : itemGridHeight + fluidGridHeight;
682+
int tWidth = itemGridWidth + fluidGridWidth;
683+
int total = tWidth * tHeight;
684+
grid.size(tWidth * 18, tHeight * 18);
685+
686+
List<IWidget> list = new ArrayList<>();
687+
int diff = (itemGridHeight * itemGridWidth) - itemInputsCount;
688+
int fluidDiff = Math.max(tWidth - fluidInputsCount, 0);
689+
int fluidIndex = 0, itemIndex = 0, emptyIndex = 0;
690+
691+
for (int i = 0; i < total; i++) {
692+
IWidget widget = IDrawable.EMPTY.asWidget().size(18)
693+
.debugName("empty.slot." + emptyIndex++);
694+
if (!isOutputs) {
695+
if (singleRow) {
696+
// fluid slot, then item slots
697+
if (i == 0 && fluidIndex < fluidInputsCount) {
698+
widget = makeFluidSlot(fluidIndex++, fluidHandler, false);
699+
} else if (itemIndex < itemInputsCount) {
700+
widget = makeItemSlot(slotGroup, itemIndex++, itemHandler, false);
701+
}
702+
} else {
703+
if (i > diff && i < itemGridWidth * itemGridHeight) {
704+
// top left should be empty
705+
widget = makeItemSlot(slotGroup, itemIndex++, itemHandler, false);
706+
} else if (i >= itemGridWidth * itemGridHeight && i < total - fluidDiff) {
707+
// bottom left should be empty
708+
widget = makeFluidSlot(fluidIndex++, fluidHandler, false);
709+
}
710+
}
711+
} else {
712+
if (singleRow) {
713+
// item slots, then fluid slots
714+
if (i == total - 1 && fluidIndex < fluidInputsCount) {
715+
widget = makeFluidSlot(fluidIndex++, fluidHandler, false);
716+
} else if (itemIndex < itemInputsCount) {
717+
widget = makeItemSlot(slotGroup, itemIndex++, itemHandler, false);
718+
}
719+
} else {
720+
if (i < (tWidth - diff) || i >= tWidth) {
721+
// top right should be empty
722+
widget = makeItemSlot(slotGroup, itemIndex++, itemHandler, false);
723+
} else if (i >= itemGridWidth * itemGridHeight && i < total - fluidDiff) {
724+
// bottom right should be empty
725+
widget = makeFluidSlot(fluidIndex++, fluidHandler, false);
726+
}
727+
}
728+
}
729+
list.add(widget);
730+
}
731+
732+
grid.mapTo(Math.max(itemGridWidth, fluidGridWidth), list);
733+
734+
return grid;
735+
}
736+
572737
protected void addInventorySlotGroup(@NotNull ParentWidget<?> group,
573738
@NotNull IItemHandlerModifiable itemHandler,
574739
@NotNull FluidTankList fluidHandler, boolean isOutputs, int yOffset) {
@@ -653,6 +818,7 @@ protected void addInventorySlotGroup(@NotNull ParentWidget<?> group,
653818
protected ItemSlot makeItemSlot(SlotGroup group, int slotIndex, IItemHandlerModifiable itemHandler,
654819
boolean isOutputs) {
655820
return new ItemSlot()
821+
.debugName("item.slot." + slotIndex + ":" + group.getName())
656822
.slot(SyncHandlers.itemSlot(itemHandler, slotIndex)
657823
.slotGroup(group)
658824
.accessibility(!isOutputs, true))
@@ -661,6 +827,7 @@ protected ItemSlot makeItemSlot(SlotGroup group, int slotIndex, IItemHandlerModi
661827

662828
protected GTFluidSlot makeFluidSlot(int slotIndex, FluidTankList fluidHandler, boolean isOutputs) {
663829
return new GTFluidSlot()
830+
.debugName("fluid.slot." + slotIndex)
664831
.syncHandler(GTFluidSlot.sync(fluidHandler.getTankAt(slotIndex))
665832
.accessibility(true, !isOutputs)
666833
.drawAlwaysFull(true))

0 commit comments

Comments
 (0)