Skip to content

Commit 87d4404

Browse files
committed
move duplicated code into MTE qstorage class
1 parent 6e3af78 commit 87d4404

File tree

3 files changed

+74
-101
lines changed

3 files changed

+74
-101
lines changed

src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCreativeChest.java

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,11 @@
3636
import com.cleanroommc.modularui.api.drawable.IKey;
3737
import com.cleanroommc.modularui.factory.PosGuiData;
3838
import com.cleanroommc.modularui.screen.ModularPanel;
39-
import com.cleanroommc.modularui.utils.Alignment;
40-
import com.cleanroommc.modularui.value.sync.BooleanSyncValue;
39+
import com.cleanroommc.modularui.value.BoolValue;
4140
import com.cleanroommc.modularui.value.sync.IntSyncValue;
4241
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
4342
import com.cleanroommc.modularui.value.sync.SyncHandlers;
4443
import com.cleanroommc.modularui.widgets.ItemSlot;
45-
import com.cleanroommc.modularui.widgets.ToggleButton;
46-
import com.cleanroommc.modularui.widgets.layout.Flow;
47-
import com.cleanroommc.modularui.widgets.textfield.TextFieldWidget;
4844
import org.apache.commons.lang3.ArrayUtils;
4945
import org.jetbrains.annotations.NotNull;
5046
import org.jetbrains.annotations.Nullable;
@@ -91,51 +87,18 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
9187

9288
@Override
9389
public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager) {
94-
return GTGuis.createPanel(this, 176, 166)
95-
.child(IKey.lang("gregtech.creative.chest.item").asWidget()
96-
.pos(7, 9))
97-
.child(Flow.column()
98-
.pos(7, 28)
99-
.coverChildren()
100-
.crossAxisAlignment(Alignment.CrossAxis.START)
101-
.child(IKey.lang("gregtech.creative.chest.ipc").asWidget()
102-
.marginBottom(2))
103-
.child(new TextFieldWidget()
104-
.left(2)
105-
.marginBottom(15)
106-
.size(152, 14)
107-
.keepScrollBarInArea(true)
108-
.setMaxLength(11)
109-
.setNumbers(1, Integer.MAX_VALUE)
110-
.value(new IntSyncValue(() -> itemsPerCycle, value -> itemsPerCycle = value)))
111-
.child(IKey.lang("gregtech.creative.chest.tpc").asWidget()
112-
.marginBottom(2))
113-
.child(new TextFieldWidget()
114-
.left(2)
115-
.setTextAlignment(Alignment.CenterLeft)
116-
.size(152, 14)
117-
.keepScrollBarInArea(true)
118-
.setMaxLength(11)
119-
.setNumbers(1, Integer.MAX_VALUE)
120-
.value(new IntSyncValue(() -> ticksPerCycle, value -> ticksPerCycle = value))))
121-
.child(new ToggleButton()
122-
.pos(7, 101)
123-
.size(162, 20)
124-
.overlay(IKey.lang(() -> active ?
125-
"gregtech.creative.activity.on" :
126-
"gregtech.creative.activity.off"))
127-
.value(new BooleanSyncValue(() -> active, value -> {
128-
active = value;
129-
scheduleRenderUpdate();
130-
var c = getQuantumController();
131-
if (c != null) c.onHandlerUpdate();
132-
})))
133-
.child(new ItemSlot()
134-
.slot(SyncHandlers.phantomItemSlot(handler, 0)
135-
.changeListener((newItem, onlyAmountChanged, client, init) -> markDirty()))
136-
.pos(36, 6))
137-
.child(createConnectionButton()
138-
.top(7));
90+
return appendCreativeUI(GTGuis.createPanel(this, 176, 166), false,
91+
new BoolValue.Dynamic(() -> active, b -> active = b),
92+
new IntSyncValue(() -> itemsPerCycle, v -> itemsPerCycle = v),
93+
new IntSyncValue(() -> ticksPerCycle, v -> ticksPerCycle = v))
94+
.child(IKey.lang("gregtech.creative.chest.item").asWidget()
95+
.pos(7, 9))
96+
.child(new ItemSlot()
97+
.slot(SyncHandlers.phantomItemSlot(handler, 0)
98+
.changeListener((newItem, onlyAmountChanged, client, init) -> markDirty()))
99+
.pos(36, 6))
100+
.child(createConnectionButton()
101+
.top(7));
139102
}
140103

141104
@Override

src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCreativeTank.java

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@
3838
import com.cleanroommc.modularui.api.drawable.IKey;
3939
import com.cleanroommc.modularui.factory.PosGuiData;
4040
import com.cleanroommc.modularui.screen.ModularPanel;
41-
import com.cleanroommc.modularui.utils.Alignment;
42-
import com.cleanroommc.modularui.value.sync.BooleanSyncValue;
41+
import com.cleanroommc.modularui.value.BoolValue;
4342
import com.cleanroommc.modularui.value.sync.IntSyncValue;
4443
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
45-
import com.cleanroommc.modularui.widgets.ToggleButton;
46-
import com.cleanroommc.modularui.widgets.layout.Flow;
47-
import com.cleanroommc.modularui.widgets.textfield.TextFieldWidget;
4844
import org.apache.commons.lang3.ArrayUtils;
4945
import org.jetbrains.annotations.Nullable;
5046

@@ -92,52 +88,19 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
9288

9389
@Override
9490
public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager) {
95-
return GTGuis.createPanel(this, 176, 166)
96-
.child(IKey.lang("gregtech.creative.tank.fluid").asWidget()
97-
.pos(7, 9))
98-
.child(new GTFluidSlot()
99-
.syncHandler(GTFluidSlot.sync(this.fluidTank)
100-
.phantom(true)
101-
.showAmount(false, false))
102-
.pos(36, 6))
103-
.child(Flow.column()
104-
.pos(7, 28)
105-
.crossAxisAlignment(Alignment.CrossAxis.START)
106-
.coverChildren()
107-
.child(IKey.lang("gregtech.creative.tank.mbpc").asWidget()
108-
.marginBottom(2))
109-
.child(new TextFieldWidget()
110-
.left(2)
111-
.marginBottom(15)
112-
.size(154, 14)
113-
.keepScrollBarInArea(true)
114-
.setNumbers(1, Integer.MAX_VALUE)
115-
.setMaxLength(11)
116-
.value(new IntSyncValue(() -> mBPerCycle, value -> mBPerCycle = value)))
117-
.child(IKey.lang("gregtech.creative.tank.tpc").asWidget()
118-
.marginBottom(2))
119-
.child(new TextFieldWidget()
120-
.left(2)
121-
.size(154, 14)
122-
.keepScrollBarInArea(true)
123-
.setNumbers(1, Integer.MAX_VALUE)
124-
.setMaxLength(11)
125-
.value(new IntSyncValue(() -> ticksPerCycle, value -> ticksPerCycle = value))))
126-
.child(new ToggleButton()
127-
.disableHoverBackground()
128-
.pos(7, 101)
129-
.size(162, 20)
130-
.overlay(IKey.lang(() -> active ?
131-
"gregtech.creative.activity.on" :
132-
"gregtech.creative.activity.off"))
133-
.value(new BooleanSyncValue(() -> active, value -> {
134-
active = value;
135-
scheduleRenderUpdate();
136-
var c = getQuantumController();
137-
if (c != null) c.onHandlerUpdate();
138-
})))
139-
.child(createConnectionButton()
140-
.top(6));
91+
return appendCreativeUI(GTGuis.createPanel(this, 176, 166), true,
92+
new BoolValue.Dynamic(() -> active, b -> active = b),
93+
new IntSyncValue(() -> mBPerCycle, v -> mBPerCycle = v),
94+
new IntSyncValue(() -> ticksPerCycle, v -> ticksPerCycle = v))
95+
.child(IKey.lang("gregtech.creative.tank.fluid").asWidget()
96+
.pos(7, 9))
97+
.child(new GTFluidSlot()
98+
.syncHandler(GTFluidSlot.sync(this.fluidTank)
99+
.phantom(true)
100+
.showAmount(false, false))
101+
.pos(36, 6))
102+
.child(createConnectionButton()
103+
.top(6));
141104
}
142105

143106
@Override

src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorage.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
import com.cleanroommc.modularui.screen.ModularPanel;
3939
import com.cleanroommc.modularui.utils.Alignment;
4040
import com.cleanroommc.modularui.utils.Color;
41+
import com.cleanroommc.modularui.value.BoolValue;
4142
import com.cleanroommc.modularui.value.sync.BooleanSyncValue;
43+
import com.cleanroommc.modularui.value.sync.IntSyncValue;
4244
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
4345
import com.cleanroommc.modularui.value.sync.SyncHandlers;
4446
import com.cleanroommc.modularui.widget.ParentWidget;
@@ -48,6 +50,7 @@
4850
import com.cleanroommc.modularui.widgets.TextWidget;
4951
import com.cleanroommc.modularui.widgets.ToggleButton;
5052
import com.cleanroommc.modularui.widgets.layout.Flow;
53+
import com.cleanroommc.modularui.widgets.textfield.TextFieldWidget;
5154
import org.jetbrains.annotations.NotNull;
5255
import org.jetbrains.annotations.Nullable;
5356

@@ -247,6 +250,50 @@ public Flow createQuantumButtonRow() {
247250
.value(new BooleanSyncValue(this::isVoiding, this::setVoiding)));
248251
}
249252

253+
protected ModularPanel appendCreativeUI(ModularPanel panel, boolean isTank,
254+
BoolValue.Dynamic isActive,
255+
IntSyncValue amountPerCycle,
256+
IntSyncValue ticksPerCycle) {
257+
return panel.child(Flow.column()
258+
.pos(7, 28)
259+
.crossAxisAlignment(Alignment.CrossAxis.START)
260+
.coverChildren()
261+
.child(IKey.lang("gregtech.creative." +
262+
(isTank ? "tank.mbpc" : "chest.ipc"))
263+
.asWidget()
264+
.marginBottom(2))
265+
.child(new TextFieldWidget()
266+
.left(2)
267+
.marginBottom(15)
268+
.size(154, 14)
269+
.keepScrollBarInArea(true)
270+
.setNumbers(1, Integer.MAX_VALUE)
271+
.setMaxLength(11)
272+
.value(amountPerCycle))
273+
.child(IKey.lang("gregtech.creative.tank.tpc").asWidget()
274+
.marginBottom(2))
275+
.child(new TextFieldWidget()
276+
.left(2)
277+
.size(154, 14)
278+
.keepScrollBarInArea(true)
279+
.setNumbers(1, Integer.MAX_VALUE)
280+
.setMaxLength(11)
281+
.value(ticksPerCycle)))
282+
.child(new ToggleButton()
283+
.disableHoverBackground()
284+
.pos(7, 101)
285+
.size(162, 20)
286+
.overlay(IKey.lang(() -> isActive.getBoolValue() ?
287+
"gregtech.creative.activity.on" :
288+
"gregtech.creative.activity.off"))
289+
.value(new BooleanSyncValue(isActive::getBoolValue, value -> {
290+
isActive.setBoolValue(value);
291+
scheduleRenderUpdate();
292+
var c = getQuantumController();
293+
if (c != null) c.onHandlerUpdate();
294+
})));
295+
}
296+
250297
protected boolean isVoiding() {
251298
return this.voiding;
252299
}

0 commit comments

Comments
 (0)