Skip to content

Commit 05f15e8

Browse files
committed
make setSize() a builder method
construct panel in map ui adjust height to remove empty space
1 parent 1bb7c67 commit 05f15e8

File tree

4 files changed

+62
-23
lines changed

4 files changed

+62
-23
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import gregtech.api.gui.widgets.LabelWidget;
1212
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
1313
import gregtech.api.mui.GTGuiTextures;
14-
import gregtech.api.mui.GTGuis;
1514
import gregtech.api.recipes.RecipeMap;
1615
import gregtech.client.renderer.ICubeRenderer;
1716
import gregtech.client.renderer.texture.Textures;
@@ -151,9 +150,12 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager)
151150
yOffset = FONT_HEIGHT;
152151
}
153152

154-
ModularPanel panel = GTGuis.createPanel(this, 176, 166 + yOffset);
155-
workableRecipeMap.getRecipeMapUI().constructPanel(panel, workable::getProgressPercent,
156-
importItems, exportItems, importFluids, exportFluids, yOffset, guiSyncManager)
153+
ModularPanel panel = workableRecipeMap.getRecipeMapUI()
154+
.setSize(176, 166 + yOffset)
155+
.constructPanel(this, workable::getProgressPercent,
156+
importItems, exportItems,
157+
importFluids, exportFluids,
158+
yOffset, guiSyncManager)
157159
.child(IKey.lang(getMetaFullName()).asWidget().pos(5, 5))
158160
.bindPlayerInventory();
159161

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import gregtech.api.items.itemhandlers.GTItemStackHandler;
1818
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
1919
import gregtech.api.mui.GTGuiTextures;
20-
import gregtech.api.mui.GTGuis;
2120
import gregtech.api.mui.widget.GhostCircuitSlotWidget;
2221
import gregtech.api.recipes.RecipeMap;
2322
import gregtech.api.util.GTTransferUtils;
@@ -503,18 +502,21 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager)
503502
yOffset = FONT_HEIGHT;
504503
}
505504

506-
ModularPanel panel = GTGuis.createPanel(this, 176 + 20, 166 + yOffset);
507505
Flow col = Flow.column()
508-
.debugName("special.buttons")
506+
.debugName("col:special.buttons")
509507
.right(7).bottom(7)
510508
.height(18 * 4 + 4)
511509
.width(18);
512510

513511
BooleanSyncValue hasEnergy = new BooleanSyncValue(workable::isHasNotEnoughEnergy);
514512
guiSyncManager.syncValue("has_energy", hasEnergy);
515513

516-
workableRecipeMap.getRecipeMapUI().constructPanel(panel, workable::getProgressPercent,
517-
importItems, exportItems, importFluids, exportFluids, yOffset, guiSyncManager)
514+
ModularPanel panel = workableRecipeMap.getRecipeMapUI()
515+
.setSize(176 + 20, 166 + yOffset)
516+
.constructPanel(this, workable::getProgressPercent,
517+
importItems, exportItems,
518+
importFluids, exportFluids,
519+
yOffset, guiSyncManager)
518520
.child(IKey.lang(getMetaFullName()).asWidget().pos(5, 5))
519521
.child(GTGuiTextures.INDICATOR_NO_ENERGY.asWidget()
520522
.debugName("energy.indicator")

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import gregtech.api.gui.ModularUI;
1010
import gregtech.api.gui.widgets.ImageWidget;
1111
import gregtech.api.mui.GTGuiTheme;
12-
import gregtech.api.mui.GTGuis;
1312
import gregtech.api.recipes.RecipeMap;
1413
import gregtech.api.util.GTUtility;
1514
import gregtech.client.particle.VanillaParticleEffects;
@@ -145,14 +144,13 @@ public boolean usesMui2() {
145144
public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager) {
146145
RecipeMap<?> map = Objects.requireNonNull(getRecipeMap());
147146

148-
ModularPanel modularPanel = GTGuis.defaultPanel(this);
149-
150-
map.getRecipeMapUI().constructPanel(modularPanel, workableHandler::getProgressPercent,
151-
importItems, exportItems, EMPTY, exportFluids, 0, guiSyncManager)
147+
return map.getRecipeMapUI()
148+
.constructPanel(this, workableHandler::getProgressPercent,
149+
importItems, exportItems,
150+
EMPTY, exportFluids,
151+
0, guiSyncManager)
152152
.child(IKey.lang(getMetaFullName()).asWidget().pos(5, 5))
153153
.bindPlayerInventory();
154-
155-
return modularPanel;
156154
}
157155

158156
@Override

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

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import gregtech.api.gui.resources.TextureArea;
77
import gregtech.api.gui.widgets.SlotWidget;
88
import gregtech.api.gui.widgets.TankWidget;
9+
import gregtech.api.metatileentity.MetaTileEntity;
910
import gregtech.api.mui.GTGuiTextures;
11+
import gregtech.api.mui.GTGuis;
1012
import gregtech.api.mui.widget.RecipeProgressWidget;
1113
import gregtech.api.recipes.Recipe;
1214
import gregtech.api.recipes.RecipeMap;
@@ -76,6 +78,9 @@ public class RecipeMapUI<R extends RecipeMap<?>> {
7678
private UITexture progressTexture = GTGuiTextures.PROGRESS_BAR_ARROW;
7779
private ProgressWidget.Direction progressDirection = ProgressWidget.Direction.RIGHT;
7880
private Consumer<Widget<?>> extraOverlays = null;
81+
private int width = GTGuis.DEFAULT_WIDTH;
82+
private int height = GTGuis.DEFAULT_HIEGHT;
83+
private boolean isLeftGreater = false;
7984

8085
/**
8186
* @param recipeMap the recipemap corresponding to this ui
@@ -540,14 +545,31 @@ public void setSlotOverlay(byte key, @NotNull TextureArea texture) {
540545

541546
/* *********************** MUI 2 *********************** */
542547

543-
public ModularPanel constructPanel(ModularPanel panel, DoubleSupplier progressSupplier,
544-
IItemHandlerModifiable importItems,
545-
IItemHandlerModifiable exportItems, FluidTankList importFluids,
546-
FluidTankList exportFluids, int yOffset, PanelSyncManager syncManager) {
548+
public RecipeMapUI<R> setSize(int width, int height) {
549+
this.width = width;
550+
this.height = height;
551+
return this;
552+
}
553+
554+
public ModularPanel constructPanel(MetaTileEntity mte, DoubleSupplier progressSupplier,
555+
IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems,
556+
FluidTankList importFluids, FluidTankList exportFluids,
557+
int yOffset, PanelSyncManager syncManager) {
558+
int inputHeight = calculateHeight(determineSlotsGrid(importItems.getSlots(), importFluids.getTanks()),
559+
importFluids.getTanks());
560+
int outputHeight = calculateHeight(determineSlotsGrid(exportItems.getSlots(), exportFluids.getTanks()),
561+
exportFluids.getTanks());
562+
ModularPanel panel = GTGuis.createPanel(mte, this.width, adjustHeight(inputHeight, outputHeight));
563+
547564
DoubleSyncValue progressValue = new DoubleSyncValue(progressSupplier);
548565

566+
int h = 3 * 18;
567+
if (Math.max(inputHeight, outputHeight) < 3) {
568+
h -= 18;
569+
}
570+
549571
Flow row = Flow.row()
550-
.height(3 * 18)
572+
.height(h)
551573
.debugName("row:recipemapui.parent")
552574
.alignX(0.5f)
553575
.crossAxisAlignment(Alignment.CrossAxis.CENTER)
@@ -582,8 +604,6 @@ public ModularPanel constructPanel(ModularPanel panel, DoubleSupplier progressSu
582604
return panel.child(row);
583605
}
584606

585-
boolean isLeftGreater = false;
586-
587607
private int calculateWidth(int inputItems, int inputFluids,
588608
int outputItems, int outputFluids,
589609
int progressSize, int margin) {
@@ -609,6 +629,23 @@ private boolean isSingleRow(int[] grid, int fluidCount) {
609629
return grid[1] >= fluidCount && grid[0] < 3;
610630
}
611631

632+
private int adjustHeight(int inputHeight, int outputHeight) {
633+
if (Math.max(inputHeight, outputHeight) < 4) {
634+
return this.height - 18;
635+
}
636+
return this.height;
637+
}
638+
639+
private int calculateHeight(int[] inputs, int inputFluids) {
640+
int inputHeight;
641+
if (isSingleRow(inputs, inputFluids)) {
642+
inputHeight = Math.max(inputs[1], inputs[3]);
643+
} else {
644+
inputHeight = inputs[1] + inputs[3];
645+
}
646+
return inputHeight;
647+
}
648+
612649
/**
613650
* @param grid [item grid width, item grid height, fluid grid width, fluid grid height]
614651
*/

0 commit comments

Comments
 (0)