aboutsummaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2023-10-27 23:22:11 +0800
committershedaniel <daniel@shedaniel.me>2024-04-16 00:38:18 +0900
commita03262e1c825ff8a877c90113137edb9dabce28d (patch)
treef4398c14e1cadc0355a93be3ccc93725b66682f4 /runtime/src
parent0ff828b4c53079de978824f54d73a6ac340ae9f9 (diff)
downloadRoughlyEnoughItems-a03262e1c825ff8a877c90113137edb9dabce28d.tar.gz
RoughlyEnoughItems-a03262e1c825ff8a877c90113137edb9dabce28d.tar.bz2
RoughlyEnoughItems-a03262e1c825ff8a877c90113137edb9dabce28d.zip
Implement keybinds
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/ConfigAccess.java12
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java131
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionValueWidget.java101
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java12
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java12
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java21
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java7
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java20
-rwxr-xr-xruntime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json13
10 files changed, 279 insertions, 52 deletions
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> T get(CompositeOption<T> option);
@@ -31,4 +34,13 @@ public interface ConfigAccess {
<T> void set(CompositeOption<T> option, T value);
<T> T getDefault(CompositeOption<T> option);
+
+ void closeMenu();
+
+ void openMenu(Menu menu);
+
+ void focusKeycode(CompositeOption<ModifierKeyCode> option);
+
+ @Nullable
+ CompositeOption<ModifierKeyCode> 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<ModifierKeyCode> focusedKeycodeOption = null;
+ private ModifierKeyCode partialKeycode = null;
public REIConfigScreen(Screen parent) {
this(parent, AllREIConfigCategories.CATEGORIES);
@@ -168,8 +174,40 @@ public class REIConfigScreen extends Screen implements ConfigAccess {
@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 class REIConfigScreen extends Screen implements ConfigAccess {
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 class REIConfigScreen extends Screen implements ConfigAccess {
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 class REIConfigScreen extends Screen implements ConfigAccess {
public <T> T getDefault(CompositeOption<T> option) {
return (T) getDefaultOptions().get(option);
}
+
+ @Override
+ public void focusKeycode(CompositeOption<ModifierKeyCode> 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<ModifierKeyCode> 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.network.chat.Component;
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 <T> WidgetWithBounds create(ConfigAccess access, CompositeOption<T> option) {
OptionValueEntry<T> entry = option.getEntry();
T value = access.get(option);
- Component[] text = new Component[1];
-
- if (entry instanceof OptionValueEntry.Selection<T> 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 class ConfigOptionValueWidget {
});
if (entry instanceof OptionValueEntry.Selection<T> 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 class ConfigOptionValueWidget {
new Rectangle(1, 1, 4, 6), 0, 0, 1, 1, 1, 1), 0, 0.5, 0)
);
}
+
+ private static <T> void applySelection(ConfigAccess access, CompositeOption<T> option, OptionValueEntry.Selection<T> 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 <T> void applyKeycode(ConfigAccess access, CompositeOption<T> option, Label label, Component[] text, Matrix4f[] matrix) {
+ label.clickable().onClick($ -> {
+ access.closeMenu();
+ access.focusKeycode((CompositeOption<ModifierKeyCode>) option);
+ });
+ BiConsumer<PoseStack, Label> 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.api.client.util.MatrixUtils;
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 org.jetbrains.annotations.Nullable;
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 class ConfigOptionWidget {
WidgetWithBounds optionValue = ConfigOptionValueWidget.create(access, option);
widgets.add(Widgets.withTranslate(optionValue, () -> 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<FormattedCharSequence> 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 @@ public interface AllREIConfigCategories {
.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 @@ public interface AllREIConfigGroups {
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 @@ public interface AllREIConfigOptions {
.enabledDisabled();
CompositeOption<Boolean> APPEND_FAVORITES_HINT = make("appearance.append_favorites_hint", i -> i.advanced.tooltips.displayFavoritesTooltip, (i, v) -> i.advanced.tooltips.displayFavoritesTooltip = v)
.enabledDisabled();
+ CompositeOption<ModifierKeyCode> RECIPE_KEYBIND = make("keybinds.recipe", i -> i.basics.keyBindings.recipeKeybind.copy(), (i, v) -> i.basics.keyBindings.recipeKeybind = v)
+ .keybind();
+ CompositeOption<ModifierKeyCode> USAGE_KEYBIND = make("keybinds.usage", i -> i.basics.keyBindings.usageKeybind.copy(), (i, v) -> i.basics.keyBindings.usageKeybind = v)
+ .keybind();
+ CompositeOption<ModifierKeyCode> HIDE_KEYBIND = make("keybinds.hide", i -> i.basics.keyBindings.hideKeybind.copy(), (i, v) -> i.basics.keyBindings.hideKeybind = v)
+ .keybind();
+ CompositeOption<ModifierKeyCode> PREVIOUS_PAGE_KEYBIND = make("keybinds.previous_page", i -> i.basics.keyBindings.previousPageKeybind.copy(), (i, v) -> i.basics.keyBindings.previousPageKeybind = v)
+ .keybind();
+ CompositeOption<ModifierKeyCode> NEXT_PAGE_KEYBIND = make("keybinds.next_page", i -> i.basics.keyBindings.nextPageKeybind.copy(), (i, v) -> i.basics.keyBindings.nextPageKeybind = v)
+ .keybind();
+ CompositeOption<ModifierKeyCode> FOCUS_SEARCH_KEYBIND = make("keybinds.focus_search", i -> i.basics.keyBindings.focusSearchFieldKeybind.copy(), (i, v) -> i.basics.keyBindings.focusSearchFieldKeybind = v)
+ .keybind();
+ CompositeOption<ModifierKeyCode> COPY_RECIPE_ID_KEYBIND = make("keybinds.copy_recipe_id", i -> i.basics.keyBindings.copyRecipeIdentifierKeybind.copy(), (i, v) -> i.basics.keyBindings.copyRecipeIdentifierKeybind = v)
+ .keybind();
+ CompositeOption<ModifierKeyCode> FAVORITE_KEYBIND = make("keybinds.favorite", i -> i.basics.keyBindings.favoriteKeybind.copy(), (i, v) -> i.basics.keyBindings.favoriteKeybind = v)
+ .keybind();
+ CompositeOption<ModifierKeyCode> EXPORT_IMAGE_KEYBIND = make("keybinds.export_image", i -> i.basics.keyBindings.exportImageKeybind.copy(), (i, v) -> i.basics.keyBindings.exportImageKeybind = v)
+ .keybind();
+ CompositeOption<ModifierKeyCode> BACK_KEYBIND = make("keybinds.back", i -> i.basics.keyBindings.previousScreenKeybind.copy(), (i, v) -> i.basics.keyBindings.previousScreenKeybind = v)
+ .keybind();
// TODO: NATIVE KEYBINDS
CompositeOption<Boolean> 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<T> {
private ConfigPreviewer<T> previewer;
@Nullable
private Supplier<T> defaultValue = null;
- private OptionValueEntry<T> entry;
+ private OptionValueEntry<T> entry = OptionValueEntry.noOp();
public CompositeOption(Component name, Component description, Function<ConfigObjectImpl, T> bind, BiConsumer<ConfigObjectImpl, T> save) {
this.name = name;
@@ -66,6 +67,10 @@ public class CompositeOption<T> {
return ((CompositeOption<Boolean>) this).entry(OptionValueEntry.enabledDisabled());
}
+ public CompositeOption<ModifierKeyCode> keybind() {
+ return ((CompositeOption<ModifierKeyCode>) this).entry(OptionValueEntry.keybind());
+ }
+
public CompositeOption<T> 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.litera
import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable;
public interface OptionValueEntry<T> {
+ Component getOption(T value);
+
static <T> OptionValueEntry<T> noOp() {
- return new OptionValueEntry<T>() {
- };
+ return value -> literal(value.toString());
}
static OptionValueEntry.Selection<Boolean> ofBoolean(Component falseText, Component trueText) {
- return new Selection<Boolean>() {
+ return new Selection<>() {
@Override
public List<Boolean> getOptions() {
return List.of(false, true);
@@ -66,7 +68,7 @@ public interface OptionValueEntry<T> {
static <T> OptionValueEntry.Selection<T> enumOptions(T... array) {
Class<T> type = (Class<T>) array.getClass().getComponentType();
Object[] constants = type.getEnumConstants();
- return new Selection<T>() {
+ return new Selection<>() {
@Override
public List<T> getOptions() {
return CollectionUtils.map(constants, type::cast);
@@ -80,7 +82,7 @@ public interface OptionValueEntry<T> {
}
static <T> OptionValueEntry<T> options(T... options) {
- return new Selection<T>() {
+ return new Selection<>() {
@Override
public List<T> getOptions() {
return Arrays.asList(options);
@@ -93,13 +95,15 @@ public interface OptionValueEntry<T> {
};
}
+ static OptionValueEntry<ModifierKeyCode> keybind() {
+ return ModifierKeyCode::getLocalizedName;
+ }
+
interface Selection<T> extends OptionValueEntry<T> {
List<T> getOptions();
- Component getOption(T value);
-
default Selection<T> overrideText(Function<T, Component> textFunction) {
- return new Selection<T>() {
+ return new Selection<>() {
@Override
public List<T> 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).",