From 72e618fd4e63356c5775b01ac33cc5a8af090170 Mon Sep 17 00:00:00 2001 From: Guillaume Mercier <17766417+C0bra5@users.noreply.github.com> Date: Tue, 10 Nov 2026 18:59:04 -0500 Subject: [PATCH] add formatted electron volt commands --- .../TooltipTemplatedTextLoader.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/templatedtext/TooltipTemplatedTextLoader.java b/src/main/java/com/gtnewhorizon/gtnhlib/templatedtext/TooltipTemplatedTextLoader.java index 2c6e1810..5df04cf9 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/templatedtext/TooltipTemplatedTextLoader.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/templatedtext/TooltipTemplatedTextLoader.java @@ -8,6 +8,8 @@ import com.gtnewhorizon.gtnhlib.templatedtext.command.UnitCommand; import com.gtnewhorizon.gtnhlib.util.TextFormatUtil; import com.gtnewhorizon.gtnhlib.util.numberformatting.NumberFormatUtil; +import java.util.function.Supplier; + public class TooltipTemplatedTextLoader extends TemplatedTextLoader { public TooltipTemplatedTextLoader(@NotNull String style) { @@ -31,8 +33,13 @@ public class TooltipTemplatedTextLoader extends TemplatedTextLoader { this.addCommand(new UnitCommand(new ThemedEUCapacityFormatter()), "fmt-eu-capacity"); this.addCommand(new UnitCommand(new ThemedAmpFormatter()), "fmt-amps"); this.addCommand(new UnitCommand(new ThemedHeatFormatter()), "fmt-heat"); - // TODO: make electron volt commands dynamic based on value. (rely on engineering exponential format) - // maybe do the same for time + // spotless:off + this.addCommand(new UnitCommand(new ThemedElectronVoltFormatter(NumberFormatUtil.LOC_CACHE::getUnitElectronVolt)), "fmt-electron-volt-unit"); + this.addCommand(new UnitCommand(new ThemedElectronVoltFormatter(NumberFormatUtil.LOC_CACHE::getUnitKiloElectronVolt)), "fmt-KeV", "fmt-kev"); + this.addCommand(new UnitCommand(new ThemedElectronVoltFormatter(NumberFormatUtil.LOC_CACHE::getUnitMegaElectronVolt)), "fmt-MeV", "fmt-mev"); + this.addCommand(new UnitCommand(new ThemedElectronVoltFormatter(NumberFormatUtil.LOC_CACHE::getUnitGigaElectronVolt)), "fmt-GeV", "fmt-gev"); + this.addCommand(new UnitCommand(new ThemedElectronVoltFormatter(NumberFormatUtil.LOC_CACHE::getUnitTeraElectronVolt)), "fmt-TeV", "fmt-tev"); + // spotless:on } private static class ThemedEUThroughputFormatter extends TextFormatUtil.ThroughputUnitFormatterWithDualTheme { @@ -78,6 +85,16 @@ public class TooltipTemplatedTextLoader extends TemplatedTextLoader { } } + private static class ThemedElectronVoltFormatter extends TextFormatUtil.UnitFormatterWithTheme { + + public ThemedElectronVoltFormatter(@NotNull Supplier<@NotNull String> unitSupplier) { + super( + TextThemingGuidelines.TOOLTIPS::getElectronVolt, + NumberFormatUtil.LOC_CACHE::getSpacingElectronVolt, + unitSupplier); + } + } + @Override protected String formatLine(String parsedLine) { return TextThemingGuidelines.TOOLTIPS.getDefault() + parsedLine;