Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Numeric widget and localized number formatting. (#272)
Browse files Browse the repository at this point in the history
* Use NumericWidget.

* bs+d

* Localized number formats.

* deps
  • Loading branch information
AbdielKavash authored Mar 9, 2024
1 parent 60c9c86 commit 6206495
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 48 deletions.
8 changes: 4 additions & 4 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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"
//}
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.14'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.16'
}


Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont
.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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
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;
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;
Expand All @@ -71,7 +71,7 @@
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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -342,7 +349,7 @@ public ArrayList<String> getFullLedDescriptionIn(int hatchNo, int paramID) {
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) {
Expand All @@ -369,7 +376,7 @@ public ArrayList<String> getFullLedDescriptionOut(int hatchNo, int paramID) {
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) {
Expand Down Expand Up @@ -2564,15 +2571,11 @@ private ModularWindow createLEDConfigurationWindow(int ledID) {
(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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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;
Expand All @@ -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(
Expand Down Expand Up @@ -217,16 +219,16 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -170,7 +172,7 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
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;
Expand All @@ -25,13 +26,14 @@
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;
Expand All @@ -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(
Expand Down Expand Up @@ -325,11 +328,11 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont
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);
Expand Down Expand Up @@ -357,11 +360,10 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont
}

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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,19 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont
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);
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/com/github/technus/tectech/util/TT_Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,4 @@ public static int receiveInteger(int previousValue, int startIndex, int index, i
}
return previousValue;
}

public static String doubleToString(double value) {
if (value == (long) value) {
return Long.toString((long) value);
}
return Double.toString(value);
}

}

0 comments on commit 6206495

Please sign in to comment.