From f955ea0ba0891c28967552d07aae6a7b9389673c Mon Sep 17 00:00:00 2001 From: Danielshe Date: Thu, 24 Oct 2019 23:21:57 +0800 Subject: Close #176 --- gradle.properties | 2 +- .../java/me/shedaniel/rei/api/ClientHelper.java | 2 + .../java/me/shedaniel/rei/api/ConfigObject.java | 2 + .../rei/gui/toast/CopyRecipeIdentifierToast.java | 52 +++++++++++++++++++++ .../rei/gui/widget/AutoCraftingButtonWidget.java | 15 ++++++ .../me/shedaniel/rei/impl/ClientHelperImpl.java | 9 +++- .../me/shedaniel/rei/impl/ConfigObjectImpl.java | 11 +++++ .../assets/roughlyenoughitems/lang/en_us.json | 4 ++ .../roughlyenoughitems/textures/gui/toasts.png | Bin 0 -> 593 bytes 9 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 src/main/java/me/shedaniel/rei/gui/toast/CopyRecipeIdentifierToast.java create mode 100644 src/main/resources/assets/roughlyenoughitems/textures/gui/toasts.png diff --git a/gradle.properties b/gradle.properties index ceb564a16..f543d7b0d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -mod_version=3.1.5-unstable +mod_version=3.1.6-unstable minecraft_version=19w41a yarn_version=19w41a+build.3 fabricloader_version=0.6.3+build.167 diff --git a/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/src/main/java/me/shedaniel/rei/api/ClientHelper.java index 68b8f2e0d..458379457 100644 --- a/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -80,6 +80,8 @@ public interface ClientHelper { FabricKeyBinding getFocusSearchFieldKeyBinding(); + FabricKeyBinding getCopyRecipeIdentifierKeyBinding(); + /** * Gets the mod from an item * diff --git a/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/src/main/java/me/shedaniel/rei/api/ConfigObject.java index c037b612c..e87662de3 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigObject.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigObject.java @@ -28,6 +28,8 @@ public interface ConfigObject { boolean isUsingDarkTheme(); + boolean isToastDisplayedOnCopyIdentifier(); + boolean doesRenderEntryExtraOverlay(); boolean isEntryListWidgetScrolled(); diff --git a/src/main/java/me/shedaniel/rei/gui/toast/CopyRecipeIdentifierToast.java b/src/main/java/me/shedaniel/rei/gui/toast/CopyRecipeIdentifierToast.java new file mode 100644 index 000000000..1c42b3e89 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/toast/CopyRecipeIdentifierToast.java @@ -0,0 +1,52 @@ +package me.shedaniel.rei.gui.toast; + +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.toast.Toast; +import net.minecraft.client.toast.ToastManager; +import net.minecraft.util.Identifier; + +import javax.annotation.Nullable; + +public class CopyRecipeIdentifierToast implements Toast { + + protected static final Identifier TOASTS_TEX = new Identifier("roughlyenoughitems", "textures/gui/toasts.png"); + private String title; + private String subtitle; + private long startTime; + + public CopyRecipeIdentifierToast(String title, @Nullable String subtitleNullable) { + this.title = title; + this.subtitle = subtitleNullable; + } + + public static void addToast(String title, @Nullable String subtitleNullable) { + MinecraftClient.getInstance().getToastManager().add(new CopyRecipeIdentifierToast(title, subtitleNullable)); + } + + @Override + public Visibility draw(ToastManager toastManager, long var2) { + toastManager.getGame().getTextureManager().bindTexture(TOASTS_TEX); + RenderSystem.color3f(1.0F, 1.0F, 1.0F); + toastManager.blit(0, 0, 0, 0, 160, 32); + if (this.subtitle == null) { + toastManager.getGame().textRenderer.draw(this.title, 18.0F, 12.0F, 11141120); + } else { + toastManager.getGame().textRenderer.draw(this.title, 18.0F, 7.0F, 11141120); + toastManager.getGame().textRenderer.draw(this.subtitle, 18.0F, 18.0F, -16777216); + } + + return var2 - this.startTime < 5000L ? Visibility.SHOW : Visibility.HIDE; + } + + @Override + public Object getType() { + return Type.THIS_IS_SURE_A_TYPE; + } + + public enum Type { + THIS_IS_SURE_A_TYPE + } + +} diff --git a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java index 74ca3d8f9..fbb942235 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java @@ -10,7 +10,10 @@ import com.mojang.blaze3d.systems.RenderSystem; import it.unimi.dsi.fastutil.ints.IntList; import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; +import me.shedaniel.math.impl.PointHelper; +import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.*; +import me.shedaniel.rei.gui.toast.CopyRecipeIdentifierToast; import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; import net.minecraft.client.resource.language.I18n; @@ -170,4 +173,16 @@ public class AutoCraftingButtonWidget extends ButtonWidget { } return Optional.of(str); } + + @Override + public boolean keyPressed(int int_1, int int_2, int int_3) { + if (displaySupplier.get().getRecipeLocation().isPresent() && ClientHelper.getInstance().getCopyRecipeIdentifierKeyBinding().matchesKey(int_1, int_2) && containsMouse(PointHelper.fromMouse())) { + minecraft.keyboard.setClipboard(displaySupplier.get().getRecipeLocation().get().toString()); + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().isToastDisplayedOnCopyIdentifier()) { + CopyRecipeIdentifierToast.addToast(I18n.translate("msg.rei.copied_recipe_id"), I18n.translate("msg.rei.recipe_id_details", displaySupplier.get().getRecipeLocation().get().toString())); + } + return true; + } + return super.keyPressed(int_1, int_2, int_3); + } } diff --git a/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java b/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java index fba9c0e82..748869a3c 100644 --- a/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java @@ -55,8 +55,9 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { private final Identifier previousPageKeybind = new Identifier("roughlyenoughitems", "previous_page"); private final Identifier nextPageKeybind = new Identifier("roughlyenoughitems", "next_page"); private final Identifier focusSearchFieldKeybind = new Identifier("roughlyenoughitems", "focus_search"); + private final Identifier copyRecipeIdentifierKeybind = new Identifier("roughlyenoughitems", "copy_recipe_id"); private final Map modNameCache = Maps.newHashMap(); - public FabricKeyBinding recipe, usage, hide, previousPage, nextPage, focusSearchField; + public FabricKeyBinding recipe, usage, hide, previousPage, nextPage, focusSearchField, copyRecipeIdentifier; @Override public String getFormattedModFromItem(Item item) { @@ -104,6 +105,11 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { return focusSearchField; } + @Override + public FabricKeyBinding getCopyRecipeIdentifierKeyBinding() { + return copyRecipeIdentifier; + } + @Override public String getModFromItem(Item item) { if (item.equals(Items.AIR)) @@ -265,6 +271,7 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { KeyBindingRegistryImpl.INSTANCE.register(previousPage = FabricKeyBinding.Builder.create(previousPageKeybind, InputUtil.Type.KEYSYM, -1, category).build()); KeyBindingRegistryImpl.INSTANCE.register(nextPage = FabricKeyBinding.Builder.create(nextPageKeybind, InputUtil.Type.KEYSYM, -1, category).build()); KeyBindingRegistryImpl.INSTANCE.register(focusSearchField = FabricKeyBinding.Builder.create(focusSearchFieldKeybind, InputUtil.Type.KEYSYM, -1, category).build()); + KeyBindingRegistryImpl.INSTANCE.register(copyRecipeIdentifier = FabricKeyBinding.Builder.create(copyRecipeIdentifierKeybind, InputUtil.Type.KEYSYM, -1, category).build()); } } diff --git a/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java b/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java index 12521e09e..9c56f5b95 100644 --- a/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java @@ -84,6 +84,12 @@ public class ConfigObjectImpl implements ConfigObject { .withName("enableCraftableOnlyButton") .build(); + private ConfigValue toastDisplayedOnCopyIdentifier = ConfigValue.builder(Boolean.class) + .withParent(modules) + .withDefaultValue(true) + .withName("toastDisplayedOnCopyIdentifier") + .build(); + private ConfigValue gamemodeCommand = ConfigValue.builder(String.class) .withParent(technical) .withDefaultValue("/gamemode {gamemode}") @@ -228,6 +234,11 @@ public class ConfigObjectImpl implements ConfigObject { return darkTheme.getValue().booleanValue(); } + @Override + public boolean isToastDisplayedOnCopyIdentifier() { + return toastDisplayedOnCopyIdentifier.getValue(); + } + @Override public boolean doesRenderEntryExtraOverlay() { return renderEntryExtraOverlay.getValue().booleanValue(); diff --git a/src/main/resources/assets/roughlyenoughitems/lang/en_us.json b/src/main/resources/assets/roughlyenoughitems/lang/en_us.json index 8a11a3565..177459d71 100755 --- a/src/main/resources/assets/roughlyenoughitems/lang/en_us.json +++ b/src/main/resources/assets/roughlyenoughitems/lang/en_us.json @@ -6,6 +6,7 @@ "key.roughlyenoughitems.next_page": "Next Page", "key.roughlyenoughitems.previous_page": "Previous Page", "key.roughlyenoughitems.focus_search": "Focus Search Field", + "key.roughlyenoughitems.copy_recipe_id": "Copy Recipe Identifier", "text.rei.cheating": "Cheating", "text.rei.cheating_disabled": "§7Cheating Disabled", "text.rei.cheating_enabled": "§cCheating Enabled", @@ -78,6 +79,8 @@ "text.rei.recipe_screen_type.selection": "Recipe Screen Type Selection", "text.rei.recipe_screen_type.selection.sub": "You can always edit this setting again via the config screen.", "text.rei.view_recipes_for": "View Recipes for %s", + "msg.rei.copied_recipe_id": "Copied Recipe Identifier", + "msg.rei.recipe_id_details": "Recipe ID: %s", "_comment": "Config Tooltips", "config.roughlyenoughitems.title": "Roughly Enough Items Config", "config.roughlyenoughitems.!general": "General", @@ -134,6 +137,7 @@ "config.roughlyenoughitems.itemCheatingMode.rei_like": "Normal", "config.roughlyenoughitems.itemCheatingMode.jei_like": "Inverted", "config.roughlyenoughitems.appendModNames": "Append Mod Names:", + "config.roughlyenoughitems.toastDisplayedOnCopyIdentifier": "Copy Identifier Toast:", "config.roughlyenoughitems.scrollingEntryListWidget": "Entry List Action:", "config.roughlyenoughitems.scrollingEntryListWidget.boolean.true": "Scrolled", "config.roughlyenoughitems.scrollingEntryListWidget.boolean.false": "Paginated", diff --git a/src/main/resources/assets/roughlyenoughitems/textures/gui/toasts.png b/src/main/resources/assets/roughlyenoughitems/textures/gui/toasts.png new file mode 100644 index 000000000..cbb2c026e Binary files /dev/null and b/src/main/resources/assets/roughlyenoughitems/textures/gui/toasts.png differ -- cgit