From 180408fabb236c1ee8a26206921695d97984ad98 Mon Sep 17 00:00:00 2001 From: Owen <64725743+Ownwn@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:25:01 +1300 Subject: [PATCH] Add feature to close sign screens with the enter key (#1122) --- .../categories/UIAndVisualsCategory.java | 8 ++++++ .../config/configs/UIAndVisualsConfig.java | 3 +++ .../mixins/SignEditScreenMixin.java | 26 +++++++++++++++++-- .../assets/skyblocker/lang/en_us.json | 2 ++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hysky/skyblocker/config/categories/UIAndVisualsCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/UIAndVisualsCategory.java index 38dff23f62..0f58011dec 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/UIAndVisualsCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/UIAndVisualsCategory.java @@ -431,6 +431,14 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig newValue -> config.uiAndVisuals.inputCalculator.requiresEquals = newValue) .controller(ConfigUtils::createBooleanController) .build()) + .option(Option.createBuilder() + .name(Text.translatable("skyblocker.config.uiAndVisuals.inputCalculator.closeSignsWithEnter")) + .description(OptionDescription.of(Text.translatable("skyblocker.config.uiAndVisuals.inputCalculator.closeSignsWithEnter.@Tooltip"))) + .binding(defaults.uiAndVisuals.inputCalculator.closeSignsWithEnter, + () -> config.uiAndVisuals.inputCalculator.closeSignsWithEnter, + newValue -> config.uiAndVisuals.inputCalculator.closeSignsWithEnter = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) .build()) //Flame Overlay diff --git a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java index c2f94a362e..01671c7912 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java @@ -306,6 +306,9 @@ public static class InputCalculator { @SerialEntry public boolean requiresEquals = false; + + @SerialEntry + public boolean closeSignsWithEnter = true; } public static class FlameOverlay { diff --git a/src/main/java/de/hysky/skyblocker/mixins/SignEditScreenMixin.java b/src/main/java/de/hysky/skyblocker/mixins/SignEditScreenMixin.java index 14769a7618..4248a3e51c 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/SignEditScreenMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/SignEditScreenMixin.java @@ -13,11 +13,13 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.llamalad7.mixinextras.sugar.Local; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(AbstractSignEditScreen.class) public abstract class SignEditScreenMixin extends Screen { @@ -26,6 +28,9 @@ public abstract class SignEditScreenMixin extends Screen { @Final private String[] messages; + @Shadow + public abstract void close(); + protected SignEditScreenMixin(Text title) { super(title); } @@ -42,12 +47,24 @@ protected SignEditScreenMixin(Text title) { } } //if the sign is being used to enter number send it to the sign calculator - if (messages[1].equals("^^^^^^^^^^^^^^^") && config.uiAndVisuals.inputCalculator.enabled) { + if (isInputSign() && config.uiAndVisuals.inputCalculator.enabled) { SignCalculator.renderCalculator(context, messages[0], context.getScaledWindowWidth() / 2, 55); } } } + @Inject(method = "keyPressed", at = @At("HEAD")) + private void skyblocker$keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable cir) { + // enter key + if (keyCode != 257 || !Utils.isOnSkyblock() || !isInputSign()) { + return; + } + + if (SkyblockerConfigManager.get().uiAndVisuals.inputCalculator.closeSignsWithEnter) { + this.close(); + } + } + @Inject(method = "finishEditing", at = @At("HEAD")) private void skyblocker$finishEditing(CallbackInfo ci) { var config = SkyblockerConfigManager.get(); @@ -60,7 +77,7 @@ protected SignEditScreenMixin(Text title) { } } //if the sign is being used to enter number get number from calculator for if maths has been done - if (messages[1].equals("^^^^^^^^^^^^^^^") && config.uiAndVisuals.inputCalculator.enabled) { + if (isInputSign() && config.uiAndVisuals.inputCalculator.enabled) { boolean isPrice = messages[2].contains("price"); String value = SignCalculator.getNewValue(isPrice); if (value.length() >= 15) { @@ -70,4 +87,9 @@ protected SignEditScreenMixin(Text title) { } } } + + @Unique + private boolean isInputSign() { + return messages[1].equals("^^^^^^^^^^^^^^^"); + } } diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 97d73019ac..aff2313e88 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -815,6 +815,8 @@ "skyblocker.config.uiAndVisuals.inputCalculator.enabled.@Tooltip": "Enables the ability for you to do calculations when inputting values such as price for the ah.\n Key:\n S = 64\n E = 160\n K = 1,000\n M = 1,000,000\n B = 1,000,000,000\n\n purse/P = current purse value", "skyblocker.config.uiAndVisuals.inputCalculator.requiresEquals": "Only show with \"=\".", "skyblocker.config.uiAndVisuals.inputCalculator.requiresEquals.@Tooltip": "Only show the calculator when the message starts with \"=\".", + "skyblocker.config.uiAndVisuals.inputCalculator.closeSignsWithEnter": "Close signs with enter", + "skyblocker.config.uiAndVisuals.inputCalculator.closeSignsWithEnter.@Tooltip": "Close the current open sign screen with the enter key", "skyblocker.config.uiAndVisuals.inputCalculator.invalidEquation": "Invalid Equation",