From 059f5c7c4b733fecc0378888481bbafad4a291cc Mon Sep 17 00:00:00 2001 From: Abdiel Kavash <19243993+AbdielKavash@users.noreply.github.com> Date: Sun, 10 Mar 2024 18:51:01 -0600 Subject: [PATCH 1/3] NumericWidget and number formatting. --- dependencies.gradle | 2 +- repositories.gradle | 1 + .../common/covers/GTPP_Cover_Overflow.java | 45 +++++-------------- ...aTileEntity_PowerSubStationController.java | 34 +++++++++----- .../GT_MetaTileEntity_TieredChest.java | 5 ++- 5 files changed, 39 insertions(+), 48 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 51e33d12f7..ab91211a90 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,5 +1,5 @@ dependencies { - api('com.github.GTNewHorizons:GT5-Unofficial:5.09.45.95:dev') + api('com.github.GTNewHorizons:GT5-Unofficial:5.09.45.97:dev') api("com.github.GTNewHorizons:bartworks:0.9.17:dev") implementation('curse.maven:cofh-core-69162:2388751') diff --git a/repositories.gradle b/repositories.gradle index c227b16ec2..033d07fda4 100644 --- a/repositories.gradle +++ b/repositories.gradle @@ -1,4 +1,5 @@ // Add any additional repositories for your dependencies here repositories { + mavenLocal() } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/GTPP_Cover_Overflow.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/GTPP_Cover_Overflow.java index d3b8dc3498..c92d223eb3 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/GTPP_Cover_Overflow.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/GTPP_Cover_Overflow.java @@ -8,11 +8,8 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidHandler; -import com.gtnewhorizons.modularui.api.drawable.Text; -import com.gtnewhorizons.modularui.api.math.MathExpression; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.common.widget.TextWidget; -import com.gtnewhorizons.modularui.common.widget.textfield.BaseTextFieldWidget; import gregtech.api.gui.modularui.GT_CoverUIBuildContext; import gregtech.api.interfaces.tileentity.ICoverable; @@ -20,7 +17,7 @@ import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; -import gregtech.common.gui.modularui.widget.CoverDataFollower_TextFieldWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_NumericWidget; public class GTPP_Cover_Overflow extends GT_CoverBehavior { @@ -189,39 +186,17 @@ protected void addUIWidgets(ModularWindow.Builder builder) { builder.widget( new CoverDataControllerWidget<>(this::getCoverData, this::setCoverData, GTPP_Cover_Overflow.this) .addFollower( - new CoverDataFollower_TextFieldWidget<>(), - coverData -> String.valueOf(convert(coverData)), - (coverData, state) -> new ISerializableObject.LegacyCoverData( - (int) MathExpression.parseMathExpression(state)), - widget -> widget.setOnScrollNumbersLong(1, 5, 50).setNumbersLong(val -> { - warn.set(false); - if (val > mMaxTransferRate) { - val = (long) mMaxTransferRate; - warn.set(true); - } else if (val < 0) { - val = 0L; - } - return val; - }).setPattern(BaseTextFieldWidget.NATURAL_NUMS).setFocusOnGuiOpen(true) - .setPos(startX + spaceX * 0, startY + spaceY * 0 + 8) + new CoverDataFollower_NumericWidget<>(), + coverData -> (double) convert(coverData), + (coverData, state) -> new ISerializableObject.LegacyCoverData(state.intValue()), + widget -> widget.setBounds(0, mMaxTransferRate).setScrollValues(1000, 144, 100000) + .setFocusOnGuiOpen(true) + .setPos(startX + spaceX * 0, startY + spaceY * 1 + 8) .setSize(spaceX * 4 - 3, 12))) .widget( - new TextWidget(GT_Utility.trans("323", "L")).setDefaultColor(COLOR_TEXT_GRAY.get()) - .setPos(startX + spaceX * 4, 4 + startY + spaceY * 0 + 8)) - .widget( - TextWidget - .dynamicText( - () -> new Text( - (warn.get() ? GT_Utility.trans("325", "Max") - : GT_Utility.trans("324", "Now")) + ": " - + convert(getCoverData()) - + " / " - + GT_Utility.formatNumbers(mMaxTransferRate) - + " " - + GT_Utility.trans("323", "L")).color( - warn.get() ? COLOR_TEXT_WARN.get() - : COLOR_TEXT_GRAY.get())) - .setSynced(false).setPos(startX + spaceX * 0, 4 + startY + spaceY * 1 + 6)); + new TextWidget(GT_Utility.trans("322", "Overflow point: ")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX, 4 + startY + spaceY * 0 + 8)); } } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java index 175d2be7a2..8d56d35265 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java @@ -38,6 +38,7 @@ import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; import com.gtnewhorizon.structurelib.structure.StructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureUtility; +import com.gtnewhorizons.modularui.api.NumberFormatMUI; import com.gtnewhorizons.modularui.api.drawable.Text; import com.gtnewhorizons.modularui.api.forge.PlayerMainInvWrapper; import com.gtnewhorizons.modularui.api.screen.ModularWindow; @@ -839,6 +840,11 @@ public void addGregTechLogo(ModularWindow.Builder builder) { .setPos(175, 166)); } + private long clientEUIn, clientEUOut, clientEULoss, clientEUStored; + private float clientProgress; + + protected static final NumberFormatMUI numberFormat = new NumberFormatMUI(); + @Override public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { builder.widget( @@ -866,33 +872,39 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont val -> getBaseMetaTileEntity().setErrorDisplayID(val))) .widget(new TextWidget("In").setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(178, 10)) .widget(new TextWidget("Out").setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(176, 28)) + .widget(new FakeSyncWidget.LongSyncer(this::getAverageEuAdded, val -> clientEUIn = val)) .widget( - TextWidget - .dynamicString(() -> "Avg In: " + GT_Utility.formatNumbers(getAverageEuAdded()) + " EU") + new TextWidget().setStringSupplier(() -> "Avg In: " + numberFormat.format(clientEUIn) + " EU") .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(10, 20)) + .widget(new FakeSyncWidget.LongSyncer(this::getAverageEuConsumed, val -> clientEUOut = val)) .widget( - TextWidget - .dynamicString( - () -> "Avg Out: " + GT_Utility.formatNumbers(getAverageEuConsumed()) + " EU") + new TextWidget().setStringSupplier(() -> "Avg Out: " + numberFormat.format(clientEUOut) + " EU") .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(10, 30)) + .widget(new FakeSyncWidget.LongSyncer(this::computeEnergyTax, val -> clientEULoss = val)) .widget( - TextWidget.dynamicString( - () -> "Powerloss: " + GT_Utility.formatNumbers(computeEnergyTax()) + " EU per tick") + new TextWidget() + .setStringSupplier( + () -> "Powerloss: " + numberFormat.format(clientEULoss) + " EU per tick") .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(10, 40)) .widget( new DrawableWidget().setDrawable(GTPP_UITextures.PICTURE_ENERGY_FRAME).setPos(4, 155) .setSize(149, 7)) + .widget(new FakeSyncWidget.FloatSyncer(this::getProgress, val -> clientProgress = val)) .widget( new ProgressBar().setProgress(this::getProgress) .setTexture(GTPP_UITextures.PROGRESSBAR_PSS_ENERGY, 147) .setDirection(ProgressBar.Direction.RIGHT).setPos(5, 156).setSize(147, 5)) .widget(new TextWidget("Stored:").setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(10, 132)) - .widget(TextWidget.dynamicText(() -> { - int colorScale = (int) (getProgress() * 100 * 2.55); - return new Text(GT_Utility.formatNumbers(getBaseMetaTileEntity().getStoredEU()) + " EU") + .widget( + new FakeSyncWidget.LongSyncer( + () -> getBaseMetaTileEntity().getStoredEU(), + val -> clientEUStored = val)) + .widget(new TextWidget().setTextSupplier(() -> { + int colorScale = (int) (clientProgress * 100 * 2.55); + return new Text(numberFormat.format(clientEUStored) + " EU") .color(Utils.rgbtoHexValue((255 - colorScale), colorScale, 0)); }).setPos(10, 142)).widget( - TextWidget.dynamicString(() -> GT_Utility.formatNumbers(getProgress() * 100) + "%") + new TextWidget().setStringSupplier(() -> numberFormat.format(clientProgress * 100) + "%") .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(70, 155)); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredChest.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredChest.java index f0c91ec34f..41262b46ff 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredChest.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredChest.java @@ -7,6 +7,7 @@ import org.apache.commons.lang3.ArrayUtils; +import com.gtnewhorizons.modularui.api.NumberFormatMUI; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import com.gtnewhorizons.modularui.common.widget.DrawableWidget; @@ -215,6 +216,8 @@ public boolean useModularUI() { return true; } + protected static final NumberFormatMUI numberFormat = new NumberFormatMUI(); + @Override public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { builder.widget( @@ -231,7 +234,7 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont SlotWidget.phantom(inventoryHandler, 2).disableInteraction() .setBackground(GT_UITextures.TRANSPARENT).setPos(59, 42)) .widget(new TextWidget("Item Amount").setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(10, 20)).widget( - TextWidget.dynamicString(() -> GT_Utility.parseNumberToString(mItemCount)) + new TextWidget().setStringSupplier(() -> numberFormat.format(mItemCount)) .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(10, 30)); } } From 9a2d635164856324a082f31377b0c00dc26d8f6c Mon Sep 17 00:00:00 2001 From: Abdiel Kavash <19243993+AbdielKavash@users.noreply.github.com> Date: Sun, 10 Mar 2024 18:55:09 -0600 Subject: [PATCH 2/3] oopsies --- repositories.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/repositories.gradle b/repositories.gradle index 033d07fda4..c227b16ec2 100644 --- a/repositories.gradle +++ b/repositories.gradle @@ -1,5 +1,4 @@ // Add any additional repositories for your dependencies here repositories { - mavenLocal() } From 6c44771d51775a559fce7f83c0b4b4e5417f68ff Mon Sep 17 00:00:00 2001 From: Martin Robertz Date: Wed, 13 Mar 2024 08:01:17 +0100 Subject: [PATCH 3/3] Update dependencies.gradle --- dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.gradle b/dependencies.gradle index adb619a6cb..d09d895ed1 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,5 +1,5 @@ dependencies { - api('com.github.GTNewHorizons:GT5-Unofficial:5.09.45.103:dev') + api('com.github.GTNewHorizons:GT5-Unofficial:5.09.45.102:dev') api("com.github.GTNewHorizons:bartworks:0.9.17:dev") implementation('curse.maven:cofh-core-69162:2388751')