Skip to content

Commit

Permalink
add the signEditEnterSubmits behavior (#203, backport)
Browse files Browse the repository at this point in the history
* add the signEditEnterSubmits behavior

* Update src/main/java/codes/cookies/mod/events/mixins/AbstractSignEditScreenMixin.java

Co-authored-by: Moritz <[email protected]>

* Update src/main/java/codes/cookies/mod/events/mixins/AbstractSignEditScreenMixin.java

Co-authored-by: Moritz <[email protected]>

* Update MiscConfig.java

---------

Co-authored-by: Moritz <[email protected]>
(cherry picked from commit d3e140f)
  • Loading branch information
GrahamKracker authored and Morazzer committed Nov 18, 2024
1 parent 4cd80eb commit 0b56639
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ private void addMiscConfig(CookiesTranslationBuilder translationBuilder) {
CTRL + Scroll -> move horizontal
SHIFT + Scroll -> chop tooltips""");
translationBuilder.addConfig(CONFIG_MISC_SIGN_EDIT_ENTER_SUBMITS,
"Sign editing enter submits",
"Enables hitting enter while editing a sign to submit it\n" +
"shift + enter for current enter behavior.");
translationBuilder.addConfig(CONFIG_MISC_STORAGE_PREVIEW,
"Storage Preview",
"Shows a preview of the content in the storage.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21.3 2024-11-17T21:52:35.48846 cookies-mod/Language (en_us)
6e320280d0f984d7ebd402794f17c02815987871 assets/cookies-mod/lang/en_us.json
// 1.21.3 2024-11-17T23:09:20.9370947 cookies-mod/Language (en_us)
9f18fc62d9f1688bfa5af6de8a9d7f91b600ea9c assets\cookies-mod\lang\en_us.json
2 changes: 2 additions & 0 deletions src/main/generated/assets/cookies-mod/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@
"cookies.config.misc.show_pet_rarity_in_level_text.tooltip": "Shows the pet level in the color of the rarity",
"cookies.config.misc.show_ping.name": "Show Ping",
"cookies.config.misc.show_ping.tooltip": "Shows the ping in the action bar",
"cookies.config.misc.sign_edit_enter_submits.name": "Sign editing enter submits",
"cookies.config.misc.sign_edit_enter_submits.tooltip": "Enables hitting enter while editing a sign to submit it\nshift + enter for current enter behavior.",
"cookies.config.misc.storage_preview.name": "Storage Preview",
"cookies.config.misc.storage_preview.tooltip": "Shows a preview of the content in the storage.",
"cookies.config.misc.tooltip": "Miscellaneous settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class MiscConfig extends Category {
@Expose
public BooleanOption enableScrollableTooltips = new BooleanOption(CONFIG_MISC_ENABLE_SCROLL_TOOLTIPS, true);

@Expose
public BooleanOption signEditEnterSubmits = new BooleanOption(CONFIG_MISC_SIGN_EDIT_ENTER_SUBMITS, false);

@Expose
public BooleanOption enableStoragePreview = new BooleanOption(CONFIG_MISC_STORAGE_PREVIEW, false);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package codes.cookies.mod.events.mixins;

import codes.cookies.mod.config.ConfigManager;
import codes.cookies.mod.events.api.ScreenKeyEvents;

import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.AbstractSignEditScreen;
import net.minecraft.text.Text;

import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand All @@ -15,7 +20,10 @@
@Mixin(AbstractSignEditScreen.class)
public abstract class AbstractSignEditScreenMixin extends Screen {

protected AbstractSignEditScreenMixin(Text title) {
@Shadow
protected abstract void finishEditing();

protected AbstractSignEditScreenMixin(Text title) {
super(title);
}

Expand All @@ -26,4 +34,11 @@ private void charTyped(char chr, int modifiers, CallbackInfoReturnable<Boolean>
}
}

@Inject(method = "keyPressed", at = @At("HEAD"), cancellable = true)
private void keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) {
if (ConfigManager.getConfig().miscConfig.signEditEnterSubmits.getValue() && (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER) && !Screen.hasShiftDown()) {
this.finishEditing();
cir.setReturnValue(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ public interface TranslationKeys {
String CONFIG_MISC_EDIT_HUD = CONFIG_MISC + ".edit_hud";
String CONFIG_MISC_SHOW_MUSEUM_ARMOR_SETS = CONFIG_MISC + ".show_museum_armor_sets";
String CONFIG_MISC_ENABLE_SCROLL_TOOLTIPS = CONFIG_MISC + ".scroll_tooltips";
String CONFIG_MISC_SIGN_EDIT_ENTER_SUBMITS = CONFIG_MISC + ".sign_edit_enter_submits";
String CONFIG_MISC_STORAGE_PREVIEW = CONFIG_MISC + ".storage_preview";
String CONFIG_MISC_SHOW_PING = CONFIG_MISC + ".show_ping";
String CONFIG_MISC_CATEGORIES_ITEMS = CONFIG_MISC + CATEGORIES_PART + ".items";
Expand Down

0 comments on commit 0b56639

Please sign in to comment.