22
33import com .gregtechceu .gtceu .api .blockentity .IPaintable ;
44import com .gregtechceu .gtceu .api .capability .recipe .IO ;
5- import com .gregtechceu .gtceu .api .gui .widget .TankWidget ;
65import com .gregtechceu .gtceu .api .machine .IMachineBlockEntity ;
76import com .gregtechceu .gtceu .api .machine .MachineDefinition ;
87import com .gregtechceu .gtceu .api .machine .TickableSubscription ;
1211import com .gregtechceu .gtceu .api .machine .multiblock .part .TieredIOPartMachine ;
1312import com .gregtechceu .gtceu .api .machine .trait .NotifiableFluidTank ;
1413import com .gregtechceu .gtceu .api .machine .trait .NotifiableItemStackHandler ;
14+ import com .gregtechceu .gtceu .api .mui .base .drawable .IKey ;
15+ import com .gregtechceu .gtceu .api .mui .factory .PosGuiData ;
16+ import com .gregtechceu .gtceu .api .mui .utils .Alignment ;
17+ import com .gregtechceu .gtceu .api .mui .value .sync .BooleanSyncValue ;
18+ import com .gregtechceu .gtceu .api .mui .value .sync .FluidSlotSyncHandler ;
19+ import com .gregtechceu .gtceu .api .mui .value .sync .PanelSyncManager ;
20+ import com .gregtechceu .gtceu .api .mui .widgets .SlotGroupWidget ;
21+ import com .gregtechceu .gtceu .api .mui .widgets .TextWidget ;
22+ import com .gregtechceu .gtceu .api .mui .widgets .ToggleButton ;
23+ import com .gregtechceu .gtceu .api .mui .widgets .layout .Column ;
24+ import com .gregtechceu .gtceu .api .mui .widgets .layout .Flow ;
25+ import com .gregtechceu .gtceu .api .mui .widgets .slot .FluidSlot ;
26+ import com .gregtechceu .gtceu .client .mui .screen .ModularPanel ;
27+ import com .gregtechceu .gtceu .client .mui .screen .UISettings ;
1528import com .gregtechceu .gtceu .common .data .GTMachines ;
29+ import com .gregtechceu .gtceu .common .data .mui .GTMuiMachineUtil ;
30+ import com .gregtechceu .gtceu .common .data .mui .GTMuiWidgets ;
1631import com .gregtechceu .gtceu .common .item .IntCircuitBehaviour ;
32+ import com .gregtechceu .gtceu .common .mui .GTGuiTextures ;
1733import com .gregtechceu .gtceu .config .ConfigHolder ;
1834import com .gregtechceu .gtceu .utils .GTTransferUtils ;
1935
@@ -266,85 +282,20 @@ public boolean swapIO() {
266282 return true ;
267283 }
268284
269- //////////////////////////////////////
270- // ********** GUI ***********//
271- //////////////////////////////////////
272-
273- /*
274- * @Override
275- * public void attachConfigurators(ConfiguratorPanel configuratorPanel) {
276- * super.attachConfigurators(configuratorPanel);
277- * if (isCircuitSlotEnabled() && this.io == IO.IN) {
278- * configuratorPanel.attachConfigurators(new CircuitFancyConfigurator(circuitInventory.storage));
279- * }
280- * }
281- *
282- * @Override
283- * public Widget createUIWidget() {
284- * if (slots == 1) {
285- * return createSingleSlotGUI();
286- * } else {
287- * return createMultiSlotGUI();
288- * }
289- * }
290- *
291- * protected Widget createSingleSlotGUI() {
292- * var group = new WidgetGroup(0, 0, 89, 63);
293- * group.addWidget(new ImageWidget(4, 4, 81, 55, GuiTextures.DISPLAY));
294- * TankWidget tankWidget;
295- *
296- * // Add input/output-specific widgets
297- * if (this.io == IO.OUT) {
298- * // if this is an output hatch, assign tankWidget to the phantom widget displaying the locked fluid...
299- * group.addWidget(tankWidget = new PhantomFluidWidget(this.tank.getLockedFluid(), 0, 67, 40, 18, 18,
300- * () -> this.tank.getLockedFluid().getFluid(), f -> {
301- * if (!this.tank.getFluidInTank(0).isEmpty()) {
302- * return;
303- * }
304- * if (f == null || f.isEmpty()) {
305- * this.tank.setLocked(false);
306- * } else {
307- * FluidStack newFluid = f.copy();
308- * newFluid.setAmount(1);
309- * this.tank.setLocked(true, newFluid);
310- * }
311- * }).setShowAmount(false).setDrawHoverTips(true).setBackground(GuiTextures.FLUID_SLOT));
312- *
313- * group.addWidget(new ToggleButtonWidget(7, 40, 18, 18,
314- * GuiTextures.BUTTON_LOCK, this.tank::isLocked, this.tank::setLocked)
315- * .setTooltipText("gtceu.gui.fluid_lock.tooltip")
316- * .setShouldUseBaseBackground())
317- * // ...and add the actual tank widget separately.
318- * .addWidget(new TankWidget(tank.getStorages()[0], 67, 22, 18, 18, true, io.support(IO.IN))
319- * .setShowAmount(true).setDrawHoverTips(true).setBackground(GuiTextures.FLUID_SLOT));
320- * } else {
321- * group.addWidget(tankWidget = new TankWidget(tank.getStorages()[0], 67, 22, 18, 18, true, io.support(IO.IN))
322- * .setShowAmount(true).setDrawHoverTips(true).setBackground(GuiTextures.FLUID_SLOT));
323- * }
324- *
325- * group.addWidget(new LabelWidget(8, 8, "gtceu.gui.fluid_amount"))
326- * .addWidget(new LabelWidget(8, 18, () -> getFluidAmountText(tankWidget)))
327- * .addWidget(new LabelWidget(8, 28, () -> getFluidNameText(tankWidget).getString()));
328- *
329- * group.setBackground(GuiTextures.BACKGROUND_INVERSE);
330- * return group;
331- * }
332- */
333-
334- private Component getFluidNameText (TankWidget tankWidget ) {
285+ private Component getFluidNameText () {
335286 Component translation ;
336- if (!tank .getFluidInTank (tankWidget . getTank () ).isEmpty ()) {
337- translation = tank .getFluidInTank (tankWidget . getTank () ).getDisplayName ();
287+ if (!this . tank .getFluidInTank (0 ).isEmpty ()) {
288+ translation = this . tank .getFluidInTank (0 ).getDisplayName ();
338289 } else {
339290 translation = this .tank .getLockedFluid ().getFluid ().getDisplayName ();
340291 }
341292 return translation ;
342293 }
343294
344- private String getFluidAmountText (TankWidget tankWidget ) {
295+ private String getFluidAmountText () {
345296 String fluidAmount = "" ;
346- if (!tank .getFluidInTank (tankWidget . getTank () ).isEmpty ()) {
347- fluidAmount = getFormattedFluidAmount (tank .getFluidInTank (tankWidget . getTank () ));
297+ if (!tank .getFluidInTank (0 ).isEmpty ()) {
298+ fluidAmount = getFormattedFluidAmount (tank .getFluidInTank (0 ));
348299 } else {
349300 // Display Zero to show information about the locked fluid
350301 if (!this .tank .getLockedFluid ().getFluid ().isEmpty ()) {
@@ -354,35 +305,68 @@ private String getFluidAmountText(TankWidget tankWidget) {
354305 return fluidAmount ;
355306 }
356307
308+ private Component getFluidText () {
309+ return getFluidNameText ().copy ().append ("\n " ).append (getFluidAmountText ());
310+ }
311+
357312 public String getFormattedFluidAmount (FluidStack fluidStack ) {
358313 return String .format ("%,d" , fluidStack .isEmpty () ? 0 : fluidStack .getAmount ());
359314 }
360315
361- /*
362- * protected Widget createMultiSlotGUI() {
363- * int rowSize = (int) Math.sqrt(slots);
364- * int colSize = rowSize;
365- * if (slots == 8) {
366- * rowSize = 4;
367- * colSize = 2;
368- * }
369- *
370- * var group = new WidgetGroup(0, 0, 18 * rowSize + 16, 18 * colSize + 16);
371- * var container = new WidgetGroup(4, 4, 18 * rowSize + 8, 18 * colSize + 8);
372- *
373- * int index = 0;
374- * for (int y = 0; y < colSize; y++) {
375- * for (int x = 0; x < rowSize; x++) {
376- * container.addWidget(
377- * new TankWidget(tank.getStorages()[index++], 4 + x * 18, 4 + y * 18, true, io.support(IO.IN))
378- * .setBackground(GuiTextures.FLUID_SLOT));
379- * }
380- * }
381- *
382- * container.setBackground(GuiTextures.BACKGROUND_INVERSE);
383- * group.addWidget(container);
384- *
385- * return group;
386- * }
387- */
316+ @ Override
317+ public ModularPanel buildUI (PosGuiData data , PanelSyncManager syncManager , UISettings settings ) {
318+ return new ModularPanel (getDefinition ().getName ())
319+ .child (GTMuiWidgets .createTitleBar (getDefinition (), 174 ))
320+ .bindPlayerInventory ()
321+ .child ((slots == 1 ? createSingleSlotUI (syncManager ) : createMultiSlotUI (syncManager ))
322+ .marginBottom (91 )
323+ .center ())
324+ .child (new Column ()
325+ .coverChildren ()
326+ .leftRel (1.0f )
327+ .reverseLayout (true )
328+ .bottom (16 )
329+ .padding (0 , 8 , 4 , 4 )
330+ .childPadding (2 )
331+ .excludeAreaInXei ()
332+ .background (GTGuiTextures .BACKGROUND .getSubArea (0.25f , 0f , 1.0f , 1.0f ))
333+ .child (GTMuiWidgets .createPowerButton (this ::isWorkingEnabled , this ::setWorkingEnabled ,
334+ syncManager )));
335+ }
336+
337+ protected Flow createSingleSlotUI (PanelSyncManager syncManager ) {
338+ return Flow .row ()
339+ .coverChildrenHeight ()
340+ .widthRel (.6f )
341+ .background (GTGuiTextures .DISPLAY )
342+ .padding (5 )
343+ .childPadding (5 )
344+ .crossAxisAlignment (Alignment .CrossAxis .START )
345+ .child (new TextWidget <>(IKey .dynamic (this ::getFluidText )))
346+ .child (Flow .column ()
347+ .alignX (1f )
348+ .childPadding (2 )
349+ .coverChildren ()
350+ .childIf (io .support (IO .OUT ), new FluidSlot ()
351+ .syncHandler (new FluidSlotSyncHandler (tank .getLockedFluid ())
352+ .phantom (true )
353+ .controlsAmount (false )))
354+ .childIf (io .support (IO .OUT ), new ToggleButton ()
355+ .value (new BooleanSyncValue (tank ::isLocked , tank ::setLocked ))
356+ .background (GTGuiTextures .MC_BUTTON , GTGuiTextures .BUTTON_LOCK )
357+ .hoverBackground (GTGuiTextures .MC_BUTTON_HOVERED , GTGuiTextures .BUTTON_LOCK )
358+ .selectedBackground (GTGuiTextures .MC_BUTTON_PRESSED , GTGuiTextures .BUTTON_LOCK )
359+ .selectedHoverBackground (GTGuiTextures .MC_BUTTON_HOVERED_PRESSED ,
360+ GTGuiTextures .BUTTON_LOCK ))
361+ .child (new FluidSlot ()
362+ .syncHandler (new FluidSlotSyncHandler (tank .getStorages ()[0 ])
363+ .canFillSlot (io .support (IO .IN )))));
364+ }
365+
366+ protected SlotGroupWidget createMultiSlotUI (PanelSyncManager syncManager ) {
367+ return GTMuiMachineUtil .createSlotGroupFromInventory (
368+ syncManager ,
369+ tank , "fluid_inv" ,
370+ slots , 'F' , GTMuiMachineUtil .createSquareMatrix (slots , 'F' ));
371+ }
388372}
0 commit comments