Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the signEditEnterSubmits behavior #203

Merged
merged 4 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, true);

@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,18 @@
package codes.cookies.mod.events.mixins;

import codes.cookies.mod.config.ConfigManager;
import codes.cookies.mod.config.categories.MiscConfig;
import codes.cookies.mod.events.api.ScreenKeyEvents;
import com.mojang.logging.LogUtils;

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.lwjgl.opengl.GL;
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 +23,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 +37,13 @@ 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
Loading