diff options
author | Abdiel Kavash <19243993+AbdielKavash@users.noreply.github.com> | 2024-03-09 00:23:24 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-09 00:23:24 -0600 |
commit | 620649516d077b4ad8612a57486330b624ab88fa (patch) | |
tree | e39d7321a52236c1c7d6b0646a2578da8e5dcf95 | |
parent | 60c9c8632a3864ec58d4e153913ec19ea6911071 (diff) | |
download | GT5-Unofficial-620649516d077b4ad8612a57486330b624ab88fa.tar.gz GT5-Unofficial-620649516d077b4ad8612a57486330b624ab88fa.tar.bz2 GT5-Unofficial-620649516d077b4ad8612a57486330b624ab88fa.zip |
Numeric widget and localized number formatting. (#272)
* Use NumericWidget.
* bs+d
* Localized number formats.
* deps
9 files changed, 49 insertions, 48 deletions
diff --git a/dependencies.gradle b/dependencies.gradle index d1646bb263..bc85b436b3 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -2,14 +2,14 @@ dependencies { shadowImplementation('com.github.GTNewHorizons:AVRcore:1.0.1') - api('com.github.GTNewHorizons:GT5-Unofficial:5.09.45.79:dev') + api('com.github.GTNewHorizons:GT5-Unofficial:5.09.45.95:dev') api('com.github.GTNewHorizons:Yamcl:0.6.0:dev') implementation('com.github.GTNewHorizons:GTNEIOrePlugin:1.2.0:dev') compileOnly("TGregworks:TGregworks:1.7.10-GTNH-1.0.23:deobf") {transitive=false} compileOnly('com.github.GTNewHorizons:TinkersConstruct:1.11.11-GTNH:dev') {transitive=false} - compileOnly('com.github.GTNewHorizons:OpenComputers:1.10.6-GTNH:dev') {transitive=false} - compileOnly('com.github.GTNewHorizons:GTplusplus:1.11.31:dev') {transitive=false} + compileOnly('com.github.GTNewHorizons:OpenComputers:1.10.7-GTNH:dev') {transitive=false} + compileOnly('com.github.GTNewHorizons:GTplusplus:1.11.33:dev') {transitive=false} compileOnly('com.github.GTNewHorizons:Avaritia:1.49:dev') {transitive=false} compileOnly('thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev') {transitive=false} @@ -18,7 +18,7 @@ dependencies { // for testing EOH recipes //runtimeOnlyNonPublishable("TGregworks:TGregworks:1.7.10-GTNH-1.0.23:deobf") //runtimeOnlyNonPublishable('com.github.GTNewHorizons:TinkersConstruct:1.11.11-GTNH:dev') - //runtimeOnlyNonPublishable('com.github.GTNewHorizons:NewHorizonsCoreMod:2.3.31:dev') + //runtimeOnlyNonPublishable('com.github.GTNewHorizons:NewHorizonsCoreMod:2.3.38:dev') //runtimeOnlyNonPublishable('com.github.GTNewHorizons:GoodGenerator:0.8.12:dev') { // exclude group: "com.github.GTNewHorizons", module: "TecTech" //} diff --git a/settings.gradle b/settings.gradle index 16a5b4ca7d..b11efb014f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,7 +17,7 @@ pluginManagement { } plugins { - id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.14' + id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.16' } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Uncertainty.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Uncertainty.java index ab5b110194..6e5a89c4c1 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Uncertainty.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Uncertainty.java @@ -392,7 +392,7 @@ public class GT_MetaTileEntity_Hatch_Uncertainty extends GT_MetaTileEntity_Hatch .widget(new FakeSyncWidget.ByteSyncer(() -> status, val -> status = val)); builder.widget( - TextWidget.dynamicString(() -> "Status: " + (status == 0 ? "OK" : "NG")).setSynced(false) + new TextWidget().setStringSupplier(() -> "Status: " + (status == 0 ? "OK" : "NG")) .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(46, 7)); for (int i = 0; i < 9; i++) { diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java index 12136371cf..dfa1d073cb 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java @@ -48,7 +48,6 @@ import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_H import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_Param; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_Uncertainty; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedExtendedFacingTexture; -import com.github.technus.tectech.util.TT_Utility; import com.google.common.collect.Iterables; import com.gtnewhorizon.structurelib.StructureLibAPI; import com.gtnewhorizon.structurelib.alignment.IAlignment; @@ -56,6 +55,7 @@ import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.IStructureElement; import com.gtnewhorizon.structurelib.util.Vec3Impl; +import com.gtnewhorizons.modularui.api.NumberFormatMUI; import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.drawable.UITexture; import com.gtnewhorizons.modularui.api.math.Alignment; @@ -71,7 +71,7 @@ import com.gtnewhorizons.modularui.common.widget.DynamicPositionedColumn; import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; import com.gtnewhorizons.modularui.common.widget.SlotWidget; import com.gtnewhorizons.modularui.common.widget.TextWidget; -import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.NumericWidget; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -205,6 +205,13 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM /** Flag if the new long power variable should be used */ protected boolean useLongPower = false; + // Locale-aware formatting of numbers. + protected static NumberFormatMUI numberFormat; + static { + numberFormat = new NumberFormatMUI(); + numberFormat.setMaximumFractionDigits(8); + } + // endregion protected GT_MetaTileEntity_MultiblockBase_EM(int aID, String aName, String aNameRegional) { @@ -342,7 +349,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM list.add( EnumChatFormatting.WHITE + "Value: " + EnumChatFormatting.AQUA - + TT_Utility.doubleToString(parametrization.getIn(hatchNo, paramID))); + + numberFormat.format(parametrization.getIn(hatchNo, paramID))); try { list.add(parametrization.groups[hatchNo].parameterIn[paramID].getBrief()); } catch (NullPointerException | IndexOutOfBoundsException e) { @@ -369,7 +376,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM list.add( EnumChatFormatting.WHITE + "Value: " + EnumChatFormatting.AQUA - + TT_Utility.doubleToString(parametrization.getOut(hatchNo, paramID))); + + numberFormat.format(parametrization.getOut(hatchNo, paramID))); try { list.add(parametrization.groups[hatchNo].parameterOut[paramID].getBrief()); } catch (NullPointerException | IndexOutOfBoundsException e) { @@ -2564,15 +2571,11 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM (screenSize.height / 2 - mainWindow.getSize().height / 2))) .widget(ButtonWidget.closeWindowButton(true).setPos(85, 3)) .widget( - new TextFieldWidget().setTextColor(Color.LIGHT_BLUE.normal).setNumbersDouble((val) -> val) - .setGetter(() -> Double.toString(parametrization.iParamsIn[ledID])).setSetter(val -> { - try { - parametrization.iParamsIn[ledID] = Double.parseDouble(val); - } catch (Exception e) { - e.printStackTrace(); - } - }).setTextAlignment(Alignment.CenterLeft).setFocusOnGuiOpen(true) - .setMaximumFractionDigits(8).setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD) + new NumericWidget().setGetter(() -> parametrization.iParamsIn[ledID]) + .setSetter(val -> parametrization.iParamsIn[ledID] = val).setIntegerOnly(false) + .modifyNumberFormat(format -> format.setMaximumFractionDigits(8)) + .setTextColor(Color.LIGHT_BLUE.normal).setTextAlignment(Alignment.CenterLeft) + .setFocusOnGuiOpen(true).setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD) .setPos(5, 20).setSize(90, 15)) .widget( new TextWidget((ledID % 10) + ":" + (ledID / 10) + ":I").setDefaultColor(Color.WHITE.normal) diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_BuckConverter.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_BuckConverter.java index 8d6e399205..a639a96bf0 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_BuckConverter.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_BuckConverter.java @@ -17,6 +17,7 @@ import net.minecraftforge.common.util.ForgeDirection; import com.github.technus.tectech.util.CommonValues; import com.github.technus.tectech.util.TT_Utility; +import com.gtnewhorizons.modularui.api.NumberFormatMUI; import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; @@ -42,6 +43,7 @@ public class GT_MetaTileEntity_BuckConverter extends GT_MetaTileEntity_TieredMac private static GT_RenderedTexture BUCK, BUCK_ACTIVE; public int EUT = 0, AMP = 0; + private static NumberFormatMUI numberFormat = new NumberFormatMUI(); public GT_MetaTileEntity_BuckConverter(int aID, String aName, String aNameRegional, int aTier) { super( @@ -217,16 +219,16 @@ public class GT_MetaTileEntity_BuckConverter extends GT_MetaTileEntity_TieredMac builder.widget( new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK).setSize(90, 72).setPos(43, 4)) .widget( - TextWidget.dynamicString(() -> "EUT: " + EUT).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setPos(46, 8)) + new TextWidget().setStringSupplier(() -> "EUT: " + numberFormat.format(EUT)) + .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(46, 8)) .widget( - TextWidget.dynamicString(() -> "TIER: " + VN[TT_Utility.getTier(Math.abs(EUT))]) + new TextWidget().setStringSupplier(() -> "TIER: " + VN[TT_Utility.getTier(Math.abs(EUT))]) .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(46, 16)) .widget( - TextWidget.dynamicString(() -> "AMP: " + AMP).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setPos(46, 24)) + new TextWidget().setStringSupplier(() -> "AMP: " + numberFormat.format(AMP)) + .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(46, 24)) .widget( - TextWidget.dynamicString(() -> "SUM: " + (long) AMP * EUT) + new TextWidget().setStringSupplier(() -> "SUM: " + numberFormat.format((long) AMP * EUT)) .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(46, 32)); addChangeNumberButton(builder, GT_UITextures.OVERLAY_BUTTON_MINUS_LARGE, val -> EUT -= val, 512, 64, 7, 4); diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPollutor.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPollutor.java index af837aa7ad..3ed89b3cd9 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPollutor.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPollutor.java @@ -16,6 +16,7 @@ import net.minecraftforge.common.util.ForgeDirection; import com.github.technus.tectech.TecTech; import com.github.technus.tectech.util.CommonValues; import com.github.technus.tectech.util.TT_Utility; +import com.gtnewhorizons.modularui.api.NumberFormatMUI; import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; @@ -45,6 +46,7 @@ public class GT_MetaTileEntity_DebugPollutor extends GT_MetaTileEntity_TieredMac private static GT_RenderedTexture POLLUTOR; public int pollution = 0; + private static final NumberFormatMUI numberFormat = new NumberFormatMUI(); public GT_MetaTileEntity_DebugPollutor(int aID, String aName, String aNameRegional, int aTier) { super( @@ -170,7 +172,7 @@ public class GT_MetaTileEntity_DebugPollutor extends GT_MetaTileEntity_TieredMac builder.widget( new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK).setSize(90, 72).setPos(43, 4)) .widget( - TextWidget.dynamicString(() -> "Pollution: " + pollution) + new TextWidget().setStringSupplier(() -> "Pollution: " + numberFormat.format(pollution)) .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(46, 8)); addChangeNumberButton( diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPowerGenerator.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPowerGenerator.java index 4dceb78d2f..2b09d6a22d 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPowerGenerator.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPowerGenerator.java @@ -10,7 +10,8 @@ import static com.github.technus.tectech.util.CommonValues.VN; import static net.minecraft.util.StatCollector.translateToLocal; import java.util.function.Consumer; -import java.util.function.Supplier; +import java.util.function.IntConsumer; +import java.util.function.IntSupplier; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; @@ -25,13 +26,14 @@ import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_H import com.github.technus.tectech.thing.metaTileEntity.pipe.GT_MetaTileEntity_Pipe_Energy; import com.github.technus.tectech.util.CommonValues; import com.github.technus.tectech.util.TT_Utility; +import com.gtnewhorizons.modularui.api.NumberFormatMUI; import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import com.gtnewhorizons.modularui.common.widget.ButtonWidget; import com.gtnewhorizons.modularui.common.widget.DrawableWidget; import com.gtnewhorizons.modularui.common.widget.TextWidget; -import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.NumericWidget; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -58,6 +60,7 @@ public class GT_MetaTileEntity_DebugPowerGenerator extends GT_MetaTileEntity_Tie private boolean LASER = false; public int EUT = 0, AMP = 0; public boolean producing = true; + private static final NumberFormatMUI numberFormat = new NumberFormatMUI(); public GT_MetaTileEntity_DebugPowerGenerator(int aID, String aName, String aNameRegional, int aTier) { super( @@ -325,11 +328,11 @@ public class GT_MetaTileEntity_DebugPowerGenerator extends GT_MetaTileEntity_Tie new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK).setSize(90, 72).setPos(43, 4)) .widget( - TextWidget.dynamicString(() -> "TIER: " + VN[TT_Utility.getTier(Math.abs(EUT))]) + new TextWidget().setStringSupplier(() -> "TIER: " + VN[TT_Utility.getTier(Math.abs(EUT))]) .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(46, 22)) .widget( - TextWidget.dynamicString(() -> "SUM: " + (long) AMP * EUT) + new TextWidget().setStringSupplier(() -> "SUM: " + numberFormat.format((long) AMP * EUT)) .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(46, 46)); addLabelledIntegerTextField(builder, "EUT: ", 24, this::getEUT, this::setEUT, 46, 8); @@ -357,11 +360,10 @@ public class GT_MetaTileEntity_DebugPowerGenerator extends GT_MetaTileEntity_Tie } private void addLabelledIntegerTextField(ModularWindow.Builder builder, String label, int labelWidth, - Supplier<Integer> getter, Consumer<Integer> setter, int xPos, int yPos) { - TextFieldWidget itfw = new TextFieldWidget(); - TextWidget ltw = new TextWidget(label); - builder.widget(ltw.setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(xPos, yPos)).widget( - itfw.setSetterInt(setter).setGetterInt(getter).setTextColor(COLOR_TEXT_WHITE.get()) + IntSupplier getter, IntConsumer setter, int xPos, int yPos) { + builder.widget(new TextWidget(label).setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(xPos, yPos)).widget( + new NumericWidget().setGetter(getter::getAsInt).setSetter(val -> setter.accept((int) val)) + .setTextColor(COLOR_TEXT_WHITE.get()) .setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD.withOffset(-1, -1, 2, 2)) .setPos(xPos + labelWidth, yPos - 1).setSize(56, 10)); } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugStructureWriter.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugStructureWriter.java index 07233a8746..da303fbda2 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugStructureWriter.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugStructureWriter.java @@ -224,19 +224,19 @@ public class GT_MetaTileEntity_DebugStructureWriter extends GT_MetaTileEntity_Ti builder.widget( new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK).setSize(90, 72).setPos(43, 4)) .widget( - TextWidget.dynamicString(() -> size ? "Structure size" : "My position") + new TextWidget().setStringSupplier(() -> size ? "Structure size" : "My position") .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(46, 8)) .widget( - TextWidget.dynamicString(() -> size ? "(Changing scan size)" : "(Moving origin)") + new TextWidget().setStringSupplier(() -> size ? "(Changing scan size)" : "(Moving origin)") .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(46, 16)) .widget( - TextWidget.dynamicString(() -> "A: " + numbers[size ? 3 : 0]) + new TextWidget().setStringSupplier(() -> "A: " + numbers[size ? 3 : 0]) .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(46, 24)) .widget( - TextWidget.dynamicString(() -> "B: " + numbers[size ? 4 : 1]) + new TextWidget().setStringSupplier(() -> "B: " + numbers[size ? 4 : 1]) .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(46, 32)) .widget( - TextWidget.dynamicString(() -> "C: " + numbers[size ? 5 : 2]) + new TextWidget().setStringSupplier(() -> "C: " + numbers[size ? 5 : 2]) .setDefaultColor(COLOR_TEXT_WHITE.get()).setPos(46, 40)); addChangeNumberButtons(builder, GT_UITextures.OVERLAY_BUTTON_MINUS_LARGE, -512, -64, 7); diff --git a/src/main/java/com/github/technus/tectech/util/TT_Utility.java b/src/main/java/com/github/technus/tectech/util/TT_Utility.java index 1ffe19ef0b..e67143f646 100644 --- a/src/main/java/com/github/technus/tectech/util/TT_Utility.java +++ b/src/main/java/com/github/technus/tectech/util/TT_Utility.java @@ -168,12 +168,4 @@ public final class TT_Utility { } return previousValue; } - - public static String doubleToString(double value) { - if (value == (long) value) { - return Long.toString((long) value); - } - return Double.toString(value); - } - } |