diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/ConfigAccess.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/ConfigAccess.java index 3c6391f69..be9a6d498 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/ConfigAccess.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/ConfigAccess.java @@ -23,7 +23,10 @@ package me.shedaniel.rei.impl.client.gui.config; +import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption; +import me.shedaniel.rei.impl.client.gui.modules.Menu; +import org.jetbrains.annotations.Nullable; public interface ConfigAccess { T get(CompositeOption option); @@ -31,4 +34,13 @@ public interface ConfigAccess { void set(CompositeOption option, T value); T getDefault(CompositeOption option); + + void closeMenu(); + + void openMenu(Menu menu); + + void focusKeycode(CompositeOption option); + + @Nullable + CompositeOption getFocusedKeycode(); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java index 3a0566b8e..7fd498bdc 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java @@ -24,8 +24,11 @@ package me.shedaniel.rei.impl.client.gui.config; import com.google.common.base.Preconditions; +import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.vertex.PoseStack; import dev.architectury.utils.value.IntValue; +import me.shedaniel.clothconfig2.api.Modifier; +import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.widgets.Widget; @@ -61,6 +64,9 @@ public class REIConfigScreen extends Screen implements ConfigAccess { private OptionCategory activeCategory; @Nullable private Menu menu; + @Nullable + private CompositeOption focusedKeycodeOption = null; + private ModifierKeyCode partialKeycode = null; public REIConfigScreen(Screen parent) { this(parent, AllREIConfigCategories.CATEGORIES); @@ -168,8 +174,40 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (menu != null && menu.mouseClicked(mouseX, mouseY, button)) + if (menu != null) { + if (!menu.mouseClicked(mouseX, mouseY, button)) + closeMenu(); + return true; + } + + if (this.focusedKeycodeOption != null && this.partialKeycode != null) { + if (this.partialKeycode.isUnknown()) { + this.partialKeycode.setKeyCode(InputConstants.Type.MOUSE.getOrCreate(button)); + } else if (this.partialKeycode.getType() == InputConstants.Type.KEYSYM) { + Modifier modifier = this.partialKeycode.getModifier(); + int code = this.partialKeycode.getKeyCode().getValue(); + if (Minecraft.ON_OSX ? code == 343 || code == 347 : code == 341 || code == 345) { + this.partialKeycode.setModifier(Modifier.of(modifier.hasAlt(), true, modifier.hasShift())); + this.partialKeycode.setKeyCode(InputConstants.Type.MOUSE.getOrCreate(button)); + return true; + } + + if (code == 344 || code == 340) { + this.partialKeycode.setModifier(Modifier.of(modifier.hasAlt(), modifier.hasControl(), true)); + this.partialKeycode.setKeyCode(InputConstants.Type.MOUSE.getOrCreate(button)); + return true; + } + + if (code == 342 || code == 346) { + this.partialKeycode.setModifier(Modifier.of(true, modifier.hasControl(), modifier.hasShift())); + this.partialKeycode.setKeyCode(InputConstants.Type.MOUSE.getOrCreate(button)); + return true; + } + } + return true; + } + return super.mouseClicked(mouseX, mouseY, button); } @@ -177,6 +215,11 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { public boolean mouseReleased(double mouseX, double mouseY, int button) { if (menu != null && menu.mouseReleased(mouseX, mouseY, button)) return true; + if (this.focusedKeycodeOption != null && this.partialKeycode != null && !this.partialKeycode.isUnknown()) { + this.set(this.focusedKeycodeOption, this.partialKeycode); + this.focusKeycode(null); + return true; + } for (GuiEventListener entry : children()) if (entry.mouseReleased(mouseX, mouseY, button)) return true; @@ -193,11 +236,79 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) { return super.mouseScrolled(mouseX, mouseY, amount); } + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + if (this.focusedKeycodeOption != null) { + if (keyCode != 256) { + if (this.partialKeycode.isUnknown()) { + this.partialKeycode.setKeyCode(InputConstants.getKey(keyCode, scanCode)); + } else { + Modifier modifier = this.partialKeycode.getModifier(); + if (this.partialKeycode.getType() == InputConstants.Type.KEYSYM) { + int code = this.partialKeycode.getKeyCode().getValue(); + if (Minecraft.ON_OSX ? code == 343 || code == 347 : code == 341 || code == 345) { + this.partialKeycode.setModifier(Modifier.of(modifier.hasAlt(), true, modifier.hasShift())); + this.partialKeycode.setKeyCode(InputConstants.getKey(keyCode, scanCode)); + return true; + } + + if (code == 344 || code == 340) { + this.partialKeycode.setModifier(Modifier.of(modifier.hasAlt(), modifier.hasControl(), true)); + this.partialKeycode.setKeyCode(InputConstants.getKey(keyCode, scanCode)); + return true; + } + + if (code == 342 || code == 346) { + this.partialKeycode.setModifier(Modifier.of(true, modifier.hasControl(), modifier.hasShift())); + this.partialKeycode.setKeyCode(InputConstants.getKey(keyCode, scanCode)); + return true; + } + } + + if (Minecraft.ON_OSX ? keyCode == 343 || keyCode == 347 : keyCode == 341 || keyCode == 345) { + this.partialKeycode.setModifier(Modifier.of(modifier.hasAlt(), true, modifier.hasShift())); + return true; + } + + if (keyCode == 344 || keyCode == 340) { + this.partialKeycode.setModifier(Modifier.of(modifier.hasAlt(), modifier.hasControl(), true)); + return true; + } + + if (keyCode == 342 || keyCode == 346) { + this.partialKeycode.setModifier(Modifier.of(true, modifier.hasControl(), modifier.hasShift())); + return true; + } + } + } else { + this.set(this.focusedKeycodeOption, ModifierKeyCode.unknown()); + this.focusKeycode(null); + } + + return true; + } + + return super.keyPressed(keyCode, scanCode, modifiers); + } + + @Override + public boolean keyReleased(int keyCode, int scanCode, int modifiers) { + if (this.focusedKeycodeOption != null && this.partialKeycode != null) { + this.set(this.focusedKeycodeOption, this.partialKeycode); + this.focusKeycode(null); + return true; + } + + return super.keyReleased(keyCode, scanCode, modifiers); + } + + @Override public void openMenu(Menu menu) { this.menu = menu; this.widgets.add(menu); } + @Override public void closeMenu() { this.widgets.remove(menu); this.menu = null; @@ -217,4 +328,22 @@ public void set(CompositeOption option, T value) { public T getDefault(CompositeOption option) { return (T) getDefaultOptions().get(option); } + + @Override + public void focusKeycode(CompositeOption option) { + this.focusedKeycodeOption = option; + + if (this.focusedKeycodeOption != null) { + this.partialKeycode = this.get(this.focusedKeycodeOption); + this.partialKeycode.setKeyCodeAndModifier(InputConstants.UNKNOWN, Modifier.none()); + } else { + this.partialKeycode = null; + } + } + + @Override + @Nullable + public CompositeOption getFocusedKeycode() { + return this.focusedKeycodeOption; + } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionValueWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionValueWidget.java index fa7b6ea22..b4c25dc64 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionValueWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionValueWidget.java @@ -23,7 +23,9 @@ package me.shedaniel.rei.impl.client.gui.config.components; +import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; +import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; @@ -44,6 +46,7 @@ import net.minecraft.resources.ResourceLocation; import java.util.Objects; +import java.util.function.BiConsumer; import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.literal; import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable; @@ -52,13 +55,7 @@ public class ConfigOptionValueWidget { public static WidgetWithBounds create(ConfigAccess access, CompositeOption option) { OptionValueEntry entry = option.getEntry(); T value = access.get(option); - Component[] text = new Component[1]; - - if (entry instanceof OptionValueEntry.Selection selection) { - text[0] = selection.getOption(value); - } else { - text[0] = literal(value.toString()); - } + Component[] text = {entry.getOption(value)}; if (value.equals(Objects.requireNonNullElseGet(option.getDefaultValue(), () -> access.getDefault(option)))) { text[0] = translatable("config.rei.value.default", text[0]); @@ -77,38 +74,9 @@ public static WidgetWithBounds create(ConfigAccess access, CompositeOption selection) { - int noOfOptions = selection.getOptions().size(); - if (noOfOptions == 2) { - label.clickable().onClick($ -> { - access.set(option, selection.getOptions().get((selection.getOptions().indexOf(access.get(option)) + 1) % 2)); - text[0] = selection.getOption(access.get(option)); - - if (access.get(option).equals(Objects.requireNonNullElseGet(option.getDefaultValue(), () -> access.getDefault(option)))) { - text[0] = translatable("config.rei.value.default", text[0]); - } - }); - } else if (noOfOptions >= 2) { - label.clickable().onClick($ -> { - Menu menu = new Menu(MatrixUtils.transform(matrix[0], label.getBounds()), CollectionUtils.map(selection.getOptions(), opt -> { - Component selectionOption = selection.getOption(opt); - if (opt.equals(access.getDefault(option))) { - selectionOption = translatable("config.rei.value.default", selectionOption); - } - - return ToggleMenuEntry.of(selectionOption, () -> false, o -> { - ((REIConfigScreen) Minecraft.getInstance().screen).closeMenu(); - access.set(option, opt); - text[0] = selection.getOption(opt); - - if (access.get(option).equals(access.getDefault(option))) { - text[0] = translatable("config.rei.value.default", text[0]); - } - }); - }), false); - ((REIConfigScreen) Minecraft.getInstance().screen).closeMenu(); - ((REIConfigScreen) Minecraft.getInstance().screen).openMenu(menu); - }); - } + applySelection(access, option, selection, label, text, matrix); + } else if (access.get(option) instanceof ModifierKeyCode) { + applyKeycode(access, option, label, text, matrix); } return Widgets.concatWithBounds(() -> new Rectangle(-label.getBounds().width, 0, label.getBounds().width + 8, 14), @@ -118,4 +86,59 @@ public static WidgetWithBounds create(ConfigAccess access, CompositeOption void applySelection(ConfigAccess access, CompositeOption option, OptionValueEntry.Selection selection, Label label, Component[] text, Matrix4f[] matrix) { + int noOfOptions = selection.getOptions().size(); + if (noOfOptions == 2) { + label.clickable().onClick($ -> { + access.set(option, selection.getOptions().get((selection.getOptions().indexOf(access.get(option)) + 1) % 2)); + text[0] = selection.getOption(access.get(option)); + + if (access.get(option).equals(Objects.requireNonNullElseGet(option.getDefaultValue(), () -> access.getDefault(option)))) { + text[0] = translatable("config.rei.value.default", text[0]); + } + }); + } else if (noOfOptions >= 2) { + label.clickable().onClick($ -> { + Menu menu = new Menu(MatrixUtils.transform(matrix[0], label.getBounds()), CollectionUtils.map(selection.getOptions(), opt -> { + Component selectionOption = selection.getOption(opt); + if (opt.equals(access.getDefault(option))) { + selectionOption = translatable("config.rei.value.default", selectionOption); + } + + return ToggleMenuEntry.of(selectionOption, () -> false, o -> { + ((REIConfigScreen) Minecraft.getInstance().screen).closeMenu(); + access.set(option, opt); + text[0] = selection.getOption(opt); + + if (access.get(option).equals(access.getDefault(option))) { + text[0] = translatable("config.rei.value.default", text[0]); + } + }); + }), false); + access.closeMenu(); + access.openMenu(menu); + }); + } + } + + private static void applyKeycode(ConfigAccess access, CompositeOption option, Label label, Component[] text, Matrix4f[] matrix) { + label.clickable().onClick($ -> { + access.closeMenu(); + access.focusKeycode((CompositeOption) option); + }); + BiConsumer render = label.getOnRender(); + label.onRender((poses, $) -> { + render.accept(poses, $); + text[0] = ((ModifierKeyCode) access.get(option)).getLocalizedName(); + + if (access.getFocusedKeycode() == option) { + text[0] = literal("> ").withStyle(ChatFormatting.YELLOW) + .append(text[0].copy().withStyle(ChatFormatting.YELLOW)) + .append(literal(" <").withStyle(ChatFormatting.YELLOW)); + } else if (access.get(option).equals(access.getDefault(option))) { + text[0] = translatable("config.rei.value.default", text[0]); + } + }); + } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java index ba546edd1..7e0dbd25f 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java @@ -38,6 +38,7 @@ import me.shedaniel.rei.impl.client.gui.config.ConfigAccess; import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption; import me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils; +import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.network.chat.MutableComponent; @@ -47,6 +48,7 @@ import java.util.ArrayList; import java.util.List; +import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.literal; import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable; public class ConfigOptionWidget { @@ -59,7 +61,15 @@ public static WidgetWithBounds create(ConfigAccess access, CompositeOption Matrix4f.createTranslateMatrix(width - optionValue.getBounds().width - optionValue.getBounds().x, 0, 0))); widgets.add(new WidgetWithBounds() { - final MutableComponent description = option.getDescription().copy().withStyle(style -> style.withColor(0xFF757575)); + final MutableComponent description = Util.make(() -> { + MutableComponent description = option.getDescription().copy().withStyle(style -> style.withColor(0xFF757575)); + if (description.getString().endsWith(".desc")) { + return literal(""); + } else { + return description; + } + }); + final List split = Minecraft.getInstance().font.split(description, width); final boolean hasPreview = option.hasPreview(); final Label previewLabel = Widgets.createLabel(new Point(), translatable("config.rei.texts.preview")) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java index ee44e733d..96a889968 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java @@ -42,7 +42,7 @@ static OptionCategory make(String key) { .add(APPEARANCE_TOOLTIPS); OptionCategory KEYBINDS = make("keybinds") .add(KEYBINDS_KEYBINDS) - .add(KEYBINDS_ADVANCED); + /*.add(KEYBINDS_ADVANCED)*/; OptionCategory CHEATS = make("cheats") .add(CHEATS_CHEATS) .add(CHEATS_ADVANCED); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java index a3a6a463d..b68a36297 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java @@ -39,7 +39,17 @@ static OptionGroup make(String id) { OptionGroup APPEARANCE_TOOLTIPS = make("appearance.tooltips") .add(APPEND_MOD_NAMES) .add(APPEND_FAVORITES_HINT); - OptionGroup KEYBINDS_KEYBINDS = make("keybinds.keybinds"); + OptionGroup KEYBINDS_KEYBINDS = make("keybinds.keybinds") + .add(RECIPE_KEYBIND) + .add(USAGE_KEYBIND) + .add(HIDE_KEYBIND) + .add(PREVIOUS_PAGE_KEYBIND) + .add(NEXT_PAGE_KEYBIND) + .add(FOCUS_SEARCH_KEYBIND) + .add(COPY_RECIPE_ID_KEYBIND) + .add(FAVORITE_KEYBIND) + .add(EXPORT_IMAGE_KEYBIND) + .add(BACK_KEYBIND); OptionGroup KEYBINDS_ADVANCED = make("keybinds.advanced") .add(USE_NATIVE_KEYBINDS); OptionGroup CHEATS_CHEATS = make("cheats.cheats") diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java index 257088865..aaa20c76c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl.client.gui.config.options; +import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.rei.api.client.gui.config.*; import me.shedaniel.rei.impl.client.config.ConfigObjectImpl; import me.shedaniel.rei.impl.client.gui.config.REIConfigScreen; @@ -54,6 +55,26 @@ static CompositeOption make(String id, Function bind .enabledDisabled(); CompositeOption APPEND_FAVORITES_HINT = make("appearance.append_favorites_hint", i -> i.advanced.tooltips.displayFavoritesTooltip, (i, v) -> i.advanced.tooltips.displayFavoritesTooltip = v) .enabledDisabled(); + CompositeOption RECIPE_KEYBIND = make("keybinds.recipe", i -> i.basics.keyBindings.recipeKeybind.copy(), (i, v) -> i.basics.keyBindings.recipeKeybind = v) + .keybind(); + CompositeOption USAGE_KEYBIND = make("keybinds.usage", i -> i.basics.keyBindings.usageKeybind.copy(), (i, v) -> i.basics.keyBindings.usageKeybind = v) + .keybind(); + CompositeOption HIDE_KEYBIND = make("keybinds.hide", i -> i.basics.keyBindings.hideKeybind.copy(), (i, v) -> i.basics.keyBindings.hideKeybind = v) + .keybind(); + CompositeOption PREVIOUS_PAGE_KEYBIND = make("keybinds.previous_page", i -> i.basics.keyBindings.previousPageKeybind.copy(), (i, v) -> i.basics.keyBindings.previousPageKeybind = v) + .keybind(); + CompositeOption NEXT_PAGE_KEYBIND = make("keybinds.next_page", i -> i.basics.keyBindings.nextPageKeybind.copy(), (i, v) -> i.basics.keyBindings.nextPageKeybind = v) + .keybind(); + CompositeOption FOCUS_SEARCH_KEYBIND = make("keybinds.focus_search", i -> i.basics.keyBindings.focusSearchFieldKeybind.copy(), (i, v) -> i.basics.keyBindings.focusSearchFieldKeybind = v) + .keybind(); + CompositeOption COPY_RECIPE_ID_KEYBIND = make("keybinds.copy_recipe_id", i -> i.basics.keyBindings.copyRecipeIdentifierKeybind.copy(), (i, v) -> i.basics.keyBindings.copyRecipeIdentifierKeybind = v) + .keybind(); + CompositeOption FAVORITE_KEYBIND = make("keybinds.favorite", i -> i.basics.keyBindings.favoriteKeybind.copy(), (i, v) -> i.basics.keyBindings.favoriteKeybind = v) + .keybind(); + CompositeOption EXPORT_IMAGE_KEYBIND = make("keybinds.export_image", i -> i.basics.keyBindings.exportImageKeybind.copy(), (i, v) -> i.basics.keyBindings.exportImageKeybind = v) + .keybind(); + CompositeOption BACK_KEYBIND = make("keybinds.back", i -> i.basics.keyBindings.previousScreenKeybind.copy(), (i, v) -> i.basics.keyBindings.previousScreenKeybind = v) + .keybind(); // TODO: NATIVE KEYBINDS CompositeOption USE_NATIVE_KEYBINDS = make("keybinds.use_native_keybinds", i -> i.basics.keyBindings.useNativeKeybinds, (i, v) -> i.basics.keyBindings.useNativeKeybinds = v) .enabledDisabled(); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java index b0eb11a08..50a982b81 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl.client.gui.config.options; +import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.rei.impl.client.config.ConfigObjectImpl; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; @@ -40,7 +41,7 @@ public class CompositeOption { private ConfigPreviewer previewer; @Nullable private Supplier defaultValue = null; - private OptionValueEntry entry; + private OptionValueEntry entry = OptionValueEntry.noOp(); public CompositeOption(Component name, Component description, Function bind, BiConsumer save) { this.name = name; @@ -66,6 +67,10 @@ public CompositeOption enabledDisabled() { return ((CompositeOption) this).entry(OptionValueEntry.enabledDisabled()); } + public CompositeOption keybind() { + return ((CompositeOption) this).entry(OptionValueEntry.keybind()); + } + public CompositeOption enumOptions(T... entry) { return this.entry(OptionValueEntry.enumOptions(entry)); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java index 303d16607..da457c5c8 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl.client.gui.config.options; +import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.rei.api.common.util.CollectionUtils; import net.minecraft.network.chat.Component; @@ -34,13 +35,14 @@ import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable; public interface OptionValueEntry { + Component getOption(T value); + static OptionValueEntry noOp() { - return new OptionValueEntry() { - }; + return value -> literal(value.toString()); } static OptionValueEntry.Selection ofBoolean(Component falseText, Component trueText) { - return new Selection() { + return new Selection<>() { @Override public List getOptions() { return List.of(false, true); @@ -66,7 +68,7 @@ static OptionValueEntry.Selection enabledDisabled() { static OptionValueEntry.Selection enumOptions(T... array) { Class type = (Class) array.getClass().getComponentType(); Object[] constants = type.getEnumConstants(); - return new Selection() { + return new Selection<>() { @Override public List getOptions() { return CollectionUtils.map(constants, type::cast); @@ -80,7 +82,7 @@ public Component getOption(T value) { } static OptionValueEntry options(T... options) { - return new Selection() { + return new Selection<>() { @Override public List getOptions() { return Arrays.asList(options); @@ -93,13 +95,15 @@ public Component getOption(T value) { }; } + static OptionValueEntry keybind() { + return ModifierKeyCode::getLocalizedName; + } + interface Selection extends OptionValueEntry { List getOptions(); - Component getOption(T value); - default Selection overrideText(Function textFunction) { - return new Selection() { + return new Selection<>() { @Override public List getOptions() { return Selection.this.getOptions(); diff --git a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json index fc0e561c1..4ee933f76 100755 --- a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json +++ b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json @@ -265,6 +265,19 @@ "config.rei.options.appearance.append_favorites_hint": "Append Favorites Hint", "config.rei.options.appearance.append_favorites_hint.desc": "Shows a hint on how to favorite an entry, or a recipe.", "config.rei.options.groups.keybinds.keybinds": "Keybinds", + "config.rei.options.keybinds.recipe": "View Recipes", + "config.rei.options.keybinds.usage": "View Usages", + "config.rei.options.keybinds.hide": "Show / Hide REI", + "config.rei.options.keybinds.previous_page": "Navigate to Previous Page", + "config.rei.options.keybinds.next_page": "Navigate to Next Page", + "config.rei.options.keybinds.focus_search": "Focus Search Field", + "config.rei.options.keybinds.copy_recipe_id": "Copy Recipe Identifier", + "config.rei.options.keybinds.copy_recipe_id.desc": "Copy a recipe's identifier by pressing the keybind, while hovering over a recipe's info button (shown with \"+\", or \"?\").", + "config.rei.options.keybinds.favorite": "Favorite Entry", + "config.rei.options.keybinds.export_image": "Export Image", + "config.rei.options.keybinds.export_image.desc": "Export a recipe as an image by pressing the keybind, while hovering over a recipe.", + "config.rei.options.keybinds.back": "Back", + "config.rei.options.keybinds.back.desc": "Quickly navigate back to the previous recipes by pressing the keybind.", "config.rei.options.groups.keybinds.advanced": "Advanced", "config.rei.options.keybinds.use_native_keybinds": "Use Native Keybinds", "config.rei.options.keybinds.use_native_keybinds.desc": "Instead of listing the keybindings in this configuration menu, create vanilla Minecraft-like keybinds in the Controls screen. Restarting Minecraft is required to disable this option.\nNote that Minecraft-like keybinds suffer from conflicts and lack of support for modifier keys (Fabric).",