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

Commit

Permalink
NumericWidget and number formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdielKavash committed Mar 11, 2024
1 parent a39fdcf commit 059f5c7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 48 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
1 change: 1 addition & 0 deletions repositories.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Add any additional repositories for your dependencies here

repositories {
mavenLocal()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@
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;
import gregtech.api.util.GT_CoverBehavior;
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 {

Expand Down Expand Up @@ -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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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));
}
}

0 comments on commit 059f5c7

Please sign in to comment.