Skip to content

Commit

Permalink
update synchandlers after creation
Browse files Browse the repository at this point in the history
handle bucketmode
  • Loading branch information
ghzdude committed Jan 18, 2024
1 parent 646ff95 commit 31d6e51
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
14 changes: 12 additions & 2 deletions src/main/java/gregtech/common/covers/CoverFluidRegulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,19 +366,29 @@ public ModularPanel buildUI(SidedPosGuiData guiData, GuiSyncManager guiSyncManag
@Override
protected ParentWidget<?> createUI(ModularPanel mainPanel, GuiSyncManager syncManager) {
var transferMode = new EnumSyncValue<>(TransferMode.class, this::getTransferMode, this::setTransferMode);
transferMode.updateCacheFromSource(true);
syncManager.syncValue("transfer_mode", transferMode);

var bucketMode = new EnumSyncValue<>(BucketMode.class, this::getBucketMode, this::setBucketMode);
bucketMode.updateCacheFromSource(true);
syncManager.syncValue("bucket_mode", bucketMode);

var filterTransferSize = new StringSyncValue(
this::getTransferAmountString,
s -> setTransferAmount(Integer.parseInt(s)));
s -> setTransferAmount(getBucketMode() == BucketMode.MILLI_BUCKET ?
Integer.parseInt(s) :
Integer.parseInt(s) * 1000));
filterTransferSize.updateCacheFromSource(true);

return super.createUI(mainPanel, syncManager)
.child(new EnumRowBuilder<>(TransferMode.class)
.value(transferMode)
.lang("Transfer Mode")
.build())
.child(new Row().right(0).coverChildrenHeight()
.child(new EnumRowBuilder<>(BucketMode.class)
.value(bucketMode)
// .overlay() todo bucket mode overlays
.build()
.child(new TextFieldWidget().widthRel(0.5f).right(0)
.setEnabledIf(w -> shouldDisplayAmountSlider())
.setNumbers(0, Integer.MAX_VALUE)
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/gregtech/common/covers/CoverPump.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,15 @@ protected ParentWidget<?> createUI(ModularPanel mainPanel, GuiSyncManager syncMa
var throughput = new IntSyncValue(this::getTransferRate, this::setTransferRate);
throughput.updateCacheFromSource(true);

var throughputString = new StringSyncValue(throughput::getStringValue, throughput::setStringValue);
var throughputString = new StringSyncValue(
() -> String.valueOf(switch (getBucketMode()) {
case BUCKET -> throughput.getIntValue() / 1000;
case MILLI_BUCKET -> throughput.getIntValue();
}),
s -> throughput.setValue(switch (getBucketMode()) {
case BUCKET -> Integer.parseInt(s) * 1000;
case MILLI_BUCKET -> Integer.parseInt(s);
}));
throughputString.updateCacheFromSource(true);

var pumpMode = new EnumSyncValue<>(PumpMode.class, this::getPumpMode, this::setPumpMode);
Expand All @@ -281,7 +289,6 @@ protected ParentWidget<?> createUI(ModularPanel mainPanel, GuiSyncManager syncMa
.child(new ButtonWidget<>()
.left(0).width(18)
.onMousePressed(mouseButton -> {
throughput.updateCacheFromSource(false);
int val = throughput.getValue() - getIncrementValue(MouseData.create(mouseButton));
throughput.setValue(val, true, true);
Interactable.playButtonClickSound();
Expand All @@ -293,16 +300,10 @@ protected ParentWidget<?> createUI(ModularPanel mainPanel, GuiSyncManager syncMa
.setTextColor(Color.WHITE.darker(1))
.setNumbers(1, maxFluidTransferRate)
.value(throughputString)
.background(GTGuiTextures.DISPLAY)
.onUpdateListener(w -> {
if (throughput.updateCacheFromSource(false)) {
w.setText(throughput.getStringValue());
}
}))
.background(GTGuiTextures.DISPLAY))
.child(new ButtonWidget<>()
.right(0).width(18)
.onMousePressed(mouseButton -> {
throughput.updateCacheFromSource(false);
int val = throughput.getValue() + getIncrementValue(MouseData.create(mouseButton));
throughput.setValue(val, true, true);
Interactable.playButtonClickSound();
Expand Down

0 comments on commit 31d6e51

Please sign in to comment.