Skip to content

Commit

Permalink
Add feature to close sign screens with the enter key (#1122)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ownwn authored Jan 2, 2025
1 parent 30d8f6e commit 180408f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,14 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.uiAndVisuals.inputCalculator.requiresEquals = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ public static class InputCalculator {

@SerialEntry
public boolean requiresEquals = false;

@SerialEntry
public boolean closeSignsWithEnter = true;
}

public static class FlameOverlay {
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/de/hysky/skyblocker/mixins/SignEditScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand All @@ -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<Boolean> 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();
Expand All @@ -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) {
Expand All @@ -70,4 +87,9 @@ protected SignEditScreenMixin(Text title) {
}
}
}

@Unique
private boolean isInputSign() {
return messages[1].equals("^^^^^^^^^^^^^^^");
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",


Expand Down

0 comments on commit 180408f

Please sign in to comment.