diff options
author | Linnea Gräf <roman.graef@gmail.com> | 2023-09-27 13:29:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-27 21:29:35 +1000 |
commit | 626b7a68c93afb1f90308b396ae45ee445aaa7a2 (patch) | |
tree | f081c38bd4ecd2b8209200fb422991ff47609dc7 /src/main/java/io | |
parent | 666456fb20055e14b9f288fac827950d0d95c5b2 (diff) | |
download | NotEnoughUpdates-626b7a68c93afb1f90308b396ae45ee445aaa7a2.tar.gz NotEnoughUpdates-626b7a68c93afb1f90308b396ae45ee445aaa7a2.tar.bz2 NotEnoughUpdates-626b7a68c93afb1f90308b396ae45ee445aaa7a2.zip |
Replace calculation with result in search bar on return press (#820)
Diffstat (limited to 'src/main/java/io')
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java | 26 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Toolbar.java | 9 |
2 files changed, 32 insertions, 3 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index f7f0049f..88e7a205 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -39,6 +39,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.SunTzu; import io.github.moulberry.notenoughupdates.miscgui.NeuSearchCalculator; import io.github.moulberry.notenoughupdates.miscgui.pricegraph.GuiPriceGraph; import io.github.moulberry.notenoughupdates.options.NEUConfigEditor; +import io.github.moulberry.notenoughupdates.util.Calculator; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.GuiTextures; import io.github.moulberry.notenoughupdates.util.LerpingFloat; @@ -84,8 +85,10 @@ import org.lwjgl.opengl.GL14; import org.lwjgl.util.vector.Vector2f; import java.awt.*; +import java.awt.datatransfer.StringSelection; import java.io.IOException; import java.lang.reflect.InvocationTargetException; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; @@ -103,6 +106,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import static io.github.moulberry.notenoughupdates.miscgui.NeuSearchCalculator.PROVIDE_LOWEST_BIN; + public class NEUOverlay extends Gui { private static final ResourceLocation SUPERGEHEIMNISVERMOGEN = new ResourceLocation( "notenoughupdates:supersecretassets/bald.png"); @@ -111,7 +116,8 @@ public class NEUOverlay extends Gui { "notenoughupdates:supersecretassets/lunar.png"); private static final ResourceLocation SEARCH_BAR = new ResourceLocation("notenoughupdates:search_bar.png"); private static final ResourceLocation SEARCH_BAR_GOLD = new ResourceLocation("notenoughupdates:search_bar_gold.png"); - private static final ResourceLocation SEARCH_MODE_BUTTON = new ResourceLocation("notenoughupdates:search_mode_button.png"); + private static final ResourceLocation SEARCH_MODE_BUTTON = new ResourceLocation( + "notenoughupdates:search_mode_button.png"); private final NEUManager manager; @@ -1059,6 +1065,19 @@ public class NEUOverlay extends Gui { return true; } + if (Keyboard.getEventKey() == Keyboard.KEY_RETURN && searchBarHasFocus) { + try { + BigDecimal calculate = Calculator.calculate(textField.getText(), PROVIDE_LOWEST_BIN); + textField.setText(calculate.toPlainString()); + if (NotEnoughUpdates.INSTANCE.config.toolbar.copyToClipboardWhenGettingResult) { + Toolkit.getDefaultToolkit().getSystemClipboard() + .setContents(new StringSelection(calculate.toPlainString()), null); + + } + } catch (Calculator.CalculatorException | IllegalStateException | HeadlessException ignored) { + } + } + if (searchBarHasFocus) { if (keyPressed == 1) { searchBarHasFocus = false; @@ -1150,7 +1169,8 @@ public class NEUOverlay extends Gui { } else if (keyPressed == manager.keybindViewRecipe.getKeyCode()) { manager.showRecipe(item); return true; - } else if (keyPressed == NotEnoughUpdates.INSTANCE.config.misc.keybindWaypoint && NotEnoughUpdates.INSTANCE.navigation.isValidWaypoint(item)) { + } else if (keyPressed == NotEnoughUpdates.INSTANCE.config.misc.keybindWaypoint && + NotEnoughUpdates.INSTANCE.navigation.isValidWaypoint(item)) { NotEnoughUpdates.INSTANCE.navigation.trackWaypoint(item); } else if (keyPressed == manager.keybindGive.getKeyCode()) { if (Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode) { @@ -1834,6 +1854,7 @@ public class NEUOverlay extends Gui { int guiScaleLast = 0; private boolean showVanillaLast = false; + /** * Renders the search bar, quick commands, item selection (right), item info (left) and armor hud gui elements. */ @@ -2256,7 +2277,6 @@ public class NEUOverlay extends Gui { } } - /** * Used in SettingsInfoPane to redraw the items when a setting changes. */ diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Toolbar.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Toolbar.java index d8fe91d5..c7ff3f70 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Toolbar.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Toolbar.java @@ -82,6 +82,15 @@ public class Toolbar { @Expose @ConfigOption( + name = "Copy calculation result to clipboard", + desc = "Copy the calculation result to clipboard when pressing ENTER in the search bar while calculating" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean copyToClipboardWhenGettingResult = true; + + @Expose + @ConfigOption( name = "Search Bar Width", desc = "Change the width of the search bar" ) |