diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java index 2e683f51a..9f7fe44b9 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java @@ -57,18 +57,18 @@ public abstract class Widget extends AbstractContainerEventHandler implements ne * The font for rendering text */ protected final Font font = minecraft.font; - private static final Stack mouseStack = new Stack<>(); + private static final Stack MOUSE_STACK = new Stack<>(); public static Point mouse() { - return mouseStack.empty() ? PointHelper.ofMouse() : mouseStack.peek(); + return MOUSE_STACK.empty() ? PointHelper.ofMouse() : MOUSE_STACK.peek(); } public static Point pushMouse(Point mouse) { - return mouseStack.push(mouse); + return MOUSE_STACK.push(mouse); } public static Point popMouse() { - return mouseStack.pop(); + return MOUSE_STACK.pop(); } public static Point translateMouse(PoseStack poses) { diff --git a/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java b/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java index 9954a57a9..496fb72d9 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java @@ -31,6 +31,7 @@ import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; import me.shedaniel.rei.api.client.search.SearchFilter; +import me.shedaniel.rei.api.common.display.Display; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import org.jetbrains.annotations.ApiStatus; @@ -134,4 +135,14 @@ public boolean isNotInExclusionZones(Rectangle bounds) { * @param tooltip the tooltip */ public abstract void renderTooltip(PoseStack matrices, Tooltip tooltip); + + /** + * Returns whether slot highlighting is on for the current search filter. + * + * @return whether slot highlighting is on for the current search filter. + */ + public abstract boolean isHighlighting(); + + @ApiStatus.Experimental + public abstract boolean submitDisplayHistory(Display display, @Nullable Rectangle fromBounds); } diff --git a/gradle.properties b/gradle.properties index d287dec04..92c5ff156 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,4 @@ +org.gradle.java.home=C:\\Program Files\\OpenJDK\\jdk-17.0.2 org.gradle.jvmargs=-Xmx10G base_version=8.4 unstable=false diff --git a/runtime-frontend/favorites-entries/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/FavoritesListWidgetImpl.java b/runtime-frontend/favorites-entries/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/FavoritesListWidgetImpl.java index 82eb891be..8a3dace66 100644 --- a/runtime-frontend/favorites-entries/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/FavoritesListWidgetImpl.java +++ b/runtime-frontend/favorites-entries/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/FavoritesListWidgetImpl.java @@ -251,4 +251,9 @@ public Widget asWidget() { public Rectangle getFavoritesBounds() { return favoritesBounds; } + + @Override + public void submitDisplayHistory(Display display, @Nullable Rectangle fromBounds) { + displayHistory.addDisplay(fromBounds, display); + } } diff --git a/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/ConfigButtonWidgetProvider.java b/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/ConfigButtonWidgetProvider.java index eabe883a5..eef3e2686 100644 --- a/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/ConfigButtonWidgetProvider.java +++ b/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/ConfigButtonWidgetProvider.java @@ -36,7 +36,6 @@ import me.shedaniel.rei.api.client.gui.config.SyntaxHighlightingMode; import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; import me.shedaniel.rei.api.client.gui.widgets.Button; -import me.shedaniel.rei.api.client.gui.widgets.TextField; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.gui.widgets.Widgets; import me.shedaniel.rei.api.client.overlay.ScreenOverlay; @@ -53,14 +52,13 @@ import java.util.Collection; import java.util.List; import java.util.UUID; -import java.util.function.Consumer; import java.util.function.UnaryOperator; public class ConfigButtonWidgetProvider implements OverlayWidgetProvider { private static final UUID CONFIG_MENU_UUID = UUID.fromString("4357bc36-0a4e-47d2-8e07-ddc220df4a0f"); @Override - public List provide(ScreenOverlay overlay, MenuAccess access, Consumer textFieldSink, UnaryOperator lateRenderable) { + public List provide(ScreenOverlay overlay, MenuAccess access, TextFieldSink textFieldSink, UnaryOperator lateRenderable) { return List.of(create(overlay, access, lateRenderable)); } diff --git a/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/CraftableFilterButtonWidgetProvider.java b/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/CraftableFilterButtonWidgetProvider.java index f5fbc42a0..b470678b0 100644 --- a/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/CraftableFilterButtonWidgetProvider.java +++ b/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/CraftableFilterButtonWidgetProvider.java @@ -30,40 +30,34 @@ import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry; import me.shedaniel.rei.api.client.gui.config.SearchFieldLocation; -import me.shedaniel.rei.api.client.gui.widgets.*; +import me.shedaniel.rei.api.client.gui.widgets.Button; +import me.shedaniel.rei.api.client.gui.widgets.Widget; +import me.shedaniel.rei.api.client.gui.widgets.Widgets; import me.shedaniel.rei.api.client.overlay.OverlayListWidget; import me.shedaniel.rei.api.client.overlay.ScreenOverlay; -import me.shedaniel.rei.api.client.search.method.InputMethod; -import me.shedaniel.rei.api.client.search.method.InputMethodRegistry; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.impl.client.config.ConfigManagerInternal; import me.shedaniel.rei.impl.client.gui.menu.MenuAccess; +import me.shedaniel.rei.impl.client.gui.overlay.menu.entries.SeparatorMenuEntry; import me.shedaniel.rei.impl.client.gui.overlay.menu.entries.SubMenuEntry; import me.shedaniel.rei.impl.client.gui.overlay.menu.entries.ToggleMenuEntry; -import me.shedaniel.rei.impl.client.gui.screen.ConfigReloadingScreen; -import me.shedaniel.rei.impl.common.InternalLogger; +import me.shedaniel.rei.impl.client.gui.overlay.menu.provider.OverlayMenuEntryProvider; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; -import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.renderer.entity.ItemRenderer; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Blocks; import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.function.Consumer; import java.util.function.UnaryOperator; public class CraftableFilterButtonWidgetProvider implements OverlayWidgetProvider { public static final UUID FILTER_MENU_UUID = UUID.fromString("2839e998-1679-4f9e-a257-37411d16f1e6"); @Override - public List provide(ScreenOverlay overlay, MenuAccess access, Consumer textFieldSink, UnaryOperator lateRenderable) { + public List provide(ScreenOverlay overlay, MenuAccess access, TextFieldSink textFieldSink, UnaryOperator lateRenderable) { if (ConfigObject.getInstance().isCraftableFilterEnabled()) { return List.of(create(overlay, access, lateRenderable)); } else { @@ -111,60 +105,33 @@ private static Collection menuEntries() { .toList()) )); - List>> applicableInputMethods = getApplicableInputMethods(); - if (applicableInputMethods.size() > 1) { - entries.add(new SubMenuEntry(new TranslatableComponent("text.rei.config.menu.search_field.input_method"), createInputMethodEntries(applicableInputMethods))); + List> additionalEntries = new ArrayList<>(); + + for (OverlayMenuEntryProvider provider : OverlayMenuEntryProvider.PROVIDERS) { + List provided = provider.provide(OverlayMenuEntryProvider.Type.CRAFTABLE_FILTER); + + if (provided != null && !provided.isEmpty()) { + additionalEntries.add(provided); + } + } + + for (List additionalEntryList : additionalEntries) { + if (additionalEntryList.size() > 1) { + entries.add(new SeparatorMenuEntry()); + entries.addAll(additionalEntryList); + } + } + + List singleEntries = CollectionUtils.flatMap(CollectionUtils.filterToList(additionalEntries, list -> list.size() == 1), list -> list); + + if (!singleEntries.isEmpty()) { + entries.add(new SeparatorMenuEntry()); + entries.addAll(singleEntries); } return entries; } - public static List>> getApplicableInputMethods() { - String languageCode = Minecraft.getInstance().options.languageCode; - return InputMethodRegistry.getInstance().getAll().entrySet().stream() - .filter(entry -> CollectionUtils.anyMatch(entry.getValue().getMatchingLocales(), locale -> locale.code().equals(languageCode))) - .toList(); - } - - public static List createInputMethodEntries(List>> applicableInputMethods) { - ConfigManagerInternal manager = ConfigManagerInternal.getInstance(); - ConfigObject config = ConfigObject.getInstance(); - return applicableInputMethods.stream() - .map(pair -> ToggleMenuEntry.of(pair.getValue().getName(), - () -> Objects.equals(config.getInputMethodId(), pair.getKey()), - bool -> { - ExecutorService service = Executors.newSingleThreadExecutor(); - InputMethod active = InputMethod.active(); - active.dispose(service).whenComplete((unused, throwable) -> { - if (throwable != null) { - InternalLogger.getInstance().error("Failed to dispose input method", throwable); - } - - manager.set("functionality.inputMethod", new ResourceLocation("rei:default")); - }).join(); - CompletableFuture future = pair.getValue().prepare(service).whenComplete((unused, throwable) -> { - if (throwable != null) { - InternalLogger.getInstance().error("Failed to prepare input method", throwable); - manager.set("functionality.inputMethod", new ResourceLocation("rei:default")); - } else { - manager.set("functionality.inputMethod", pair.getKey()); - } - }); - Screen screen = Minecraft.getInstance().screen; - Minecraft.getInstance().setScreen(new ConfigReloadingScreen(new TranslatableComponent("text.rei.input.methods.initializing"), - () -> !future.isDone(), () -> { - Minecraft.getInstance().setScreen(screen); - })); - future.whenComplete((unused, throwable) -> { - service.shutdown(); - }); - }) - .withActive(() -> !Objects.equals(config.getInputMethodId(), pair.getKey())) - .withTooltip(() -> Tooltip.create(TooltipContext.ofMouse(), pair.getValue().getDescription())) - ) - .toList(); - } - private static Rectangle getCraftableFilterBounds() { Rectangle area = REIRuntime.getInstance().getSearchTextField().asWidget().getBounds().clone(); area.setLocation(area.x + area.width + 4, area.y - 1); diff --git a/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/SearchFieldWidgetProvider.java b/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/SearchFieldWidgetProvider.java index 7fb67cf34..85d305568 100644 --- a/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/SearchFieldWidgetProvider.java +++ b/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/SearchFieldWidgetProvider.java @@ -1,25 +1,56 @@ package me.shedaniel.rei.impl.client.gui.overlay.widgets; -import me.shedaniel.rei.api.client.gui.widgets.TextField; +import com.mojang.blaze3d.platform.Window; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.REIRuntime; +import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.overlay.ScreenOverlay; +import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; import me.shedaniel.rei.impl.client.gui.menu.MenuAccess; import me.shedaniel.rei.impl.client.gui.overlay.widgets.search.OverlaySearchField; +import net.minecraft.client.Minecraft; import java.util.List; -import java.util.function.Consumer; import java.util.function.UnaryOperator; public class SearchFieldWidgetProvider implements OverlayWidgetProvider { private OverlaySearchField searchField; @Override - public List provide(ScreenOverlay overlay, MenuAccess access, Consumer textFieldSink, UnaryOperator lateRenderable) { + public List provide(ScreenOverlay overlay, MenuAccess access, TextFieldSink textFieldSink, UnaryOperator lateRenderable) { if (searchField == null) { searchField = new OverlaySearchField(access); } - textFieldSink.accept(searchField); + searchField.getBounds().setBounds(getSearchFieldArea(overlay)); + textFieldSink.accept(searchField, searchField::isHighlighting); return List.of(lateRenderable.apply(searchField)); } + + private Rectangle getSearchFieldArea(ScreenOverlay overlay) { + int widthRemoved = 1; + if (ConfigObject.getInstance().isCraftableFilterEnabled()) widthRemoved += 22; + if (ConfigObject.getInstance().isLowerConfigButton()) widthRemoved += 22; + return switch (REIRuntime.getInstance().getContextualSearchFieldLocation()) { + case TOP_SIDE -> getTopSideSearchFieldArea(overlay, widthRemoved); + case BOTTOM_SIDE -> getBottomSideSearchFieldArea(overlay, widthRemoved); + case CENTER -> getCenterSearchFieldArea(overlay, widthRemoved); + }; + } + + private Rectangle getTopSideSearchFieldArea(ScreenOverlay overlay, int widthRemoved) { + return new Rectangle(overlay.getBounds().x + 2, 4, overlay.getBounds().width - 6 - widthRemoved, 18); + } + + private Rectangle getBottomSideSearchFieldArea(ScreenOverlay overlay, int widthRemoved) { + Window window = Minecraft.getInstance().getWindow(); + return new Rectangle(overlay.getBounds().x + 2, window.getGuiScaledHeight() - 22, overlay.getBounds().width - 6 - widthRemoved, 18); + } + + private Rectangle getCenterSearchFieldArea(ScreenOverlay overlay, int widthRemoved) { + Window window = Minecraft.getInstance().getWindow(); + Rectangle screenBounds = ScreenRegistry.getInstance().getScreenBounds(Minecraft.getInstance().screen); + return new Rectangle(screenBounds.x, window.getGuiScaledHeight() - 22, screenBounds.width - widthRemoved, 18); + } } diff --git a/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/search/OverlaySearchField.java b/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/search/OverlaySearchField.java index 6484f82e2..8428270d6 100644 --- a/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/search/OverlaySearchField.java +++ b/runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/search/OverlaySearchField.java @@ -73,10 +73,10 @@ @SuppressWarnings("UnstableApiUsage") @ApiStatus.Internal public class OverlaySearchField extends DelegateWidget implements DelegateTextField, TextField.TextFormatter, TextField.SuggestionRenderer, TextField.BorderColorProvider { - public static boolean isHighlighting = false; private static final Style SPLITTER_STYLE = Style.EMPTY.withColor(ChatFormatting.GRAY); private static final Style QUOTES_STYLE = Style.EMPTY.withColor(ChatFormatting.GOLD); private static final Style ERROR_STYLE = Style.EMPTY.withColor(TextColor.fromRgb(0xff5555)); + private boolean isHighlighting = false; private final TextField textField; private final MenuAccess access; private boolean previouslyClicking = false; @@ -383,7 +383,7 @@ public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { super.render(matrices, mouseX, mouseY, delta); RenderSystem.enableDepthTest(); if (isMain && isHighlighting) { - this.renderEntryHighlighting(matrices); + renderEntryHighlighting(matrices); } } @@ -427,4 +427,8 @@ public static void renderEntryHighlighting(PoseStack matrices) { RenderSystem.colorMask(true, true, true, true); RenderSystem.enableDepthTest(); } + + public boolean isHighlighting() { + return isHighlighting; + } } diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/ScreenOverlayImpl.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/ScreenOverlayImpl.java index ba55096b4..f4d8a1875 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/ScreenOverlayImpl.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/ScreenOverlayImpl.java @@ -24,56 +24,36 @@ package me.shedaniel.rei.impl.client.gui.overlay; import com.mojang.blaze3d.platform.InputConstants; -import com.mojang.blaze3d.platform.Window; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigObject; -import me.shedaniel.rei.api.client.gui.config.SearchFieldLocation; import me.shedaniel.rei.api.client.gui.widgets.DelegateWidget; import me.shedaniel.rei.api.client.gui.widgets.TextField; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.gui.widgets.Widgets; import me.shedaniel.rei.api.client.overlay.OverlayListWidget; -import me.shedaniel.rei.api.client.overlay.ScreenOverlay; -import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; import me.shedaniel.rei.api.client.search.SearchFilter; -import me.shedaniel.rei.impl.client.ClientInternals; +import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.impl.client.gui.overlay.entries.EntryListProvider; import me.shedaniel.rei.impl.client.gui.overlay.entries.EntryListWidget; import me.shedaniel.rei.impl.client.gui.overlay.entries.FavoritesListProvider; import me.shedaniel.rei.impl.client.gui.overlay.entries.FavoritesListWidget; import me.shedaniel.rei.impl.client.gui.overlay.widgets.OverlayWidgetProvider; import me.shedaniel.rei.impl.common.InternalLogger; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.function.BooleanSupplier; @ApiStatus.Internal public final class ScreenOverlayImpl extends AbstractScreenOverlay { - private static final List ENTRY_LIST_PROVIDERS = ClientInternals.resolveServices(EntryListProvider.class); - private static final List FAVORITES_LIST_PROVIDERS = ClientInternals.resolveServices(FavoritesListProvider.class); - private static final List OVERLAY_WIDGET_PROVIDERS = ClientInternals.resolveServices(OverlayWidgetProvider.class); private EntryListWidget entryListWidget = null; private FavoritesListWidget favoritesListWidget = null; private TextField searchField = null; - - public static EntryListWidget getEntryListWidget() { - return getInstanceInternal().getEntryList(); - } - - @Nullable - public static FavoritesListWidget getFavoritesListWidget() { - return getInstanceInternal().getFavoritesListNullable(); - } - - private static ScreenOverlayImpl getInstanceInternal() { - return (ScreenOverlayImpl) ScreenOverlay.getInstance().orElseThrow(); - } + private BooleanSupplier isHighlighted = null; public ScreenOverlayImpl() { this.init(); @@ -84,27 +64,29 @@ public void init() { super.init(); this.searchField = null; + this.isHighlighted = null; - FavoritesListWidget favoritesListWidget = getFavoritesListWidget(); + FavoritesListWidget favoritesListWidget = getFavoritesListNullable(); if (favoritesListWidget != null) { this.children().add(favoritesListWidget.asWidget()); } - EntryListWidget entryListWidget = getEntryListWidget(); + EntryListWidget entryListWidget = getEntryList(); entryListWidget.initBounds(this.getBounds()); entryListWidget.initSearch(searchField.getText(), true); this.children().add(entryListWidget.asWidget()); searchField.setResponder(s -> entryListWidget.initSearch(s, false)); entryListWidget.init(this); - for (OverlayWidgetProvider provider : OVERLAY_WIDGET_PROVIDERS) { - provider.provide(this, menuAccess(), textField -> this.searchField = textField, - LateRenderableWidget::new); + for (OverlayWidgetProvider provider : OverlayWidgetProvider.PROVIDERS) { + provider.provide(this, menuAccess(), (textField, isHighlighted) -> { + this.searchField = textField; + this.isHighlighted = isHighlighted; + }, LateRenderableWidget::new); } if (this.searchField != null) { - this.searchField.asWidget().getBounds().setBounds(getSearchFieldArea()); this.children().add(this.searchField.asWidget()); } else { InternalLogger.getInstance().warn("Search Field is not found! This might cause problems!"); @@ -117,36 +99,9 @@ private LateRenderableWidget(Widget widget) { } } - private Rectangle getSearchFieldArea() { - int widthRemoved = 1; - if (ConfigObject.getInstance().isCraftableFilterEnabled()) widthRemoved += 22; - if (ConfigObject.getInstance().isLowerConfigButton()) widthRemoved += 22; - SearchFieldLocation searchFieldLocation = REIRuntime.getInstance().getContextualSearchFieldLocation(); - return switch (searchFieldLocation) { - case TOP_SIDE -> getTopSideSearchFieldArea(widthRemoved); - case BOTTOM_SIDE -> getBottomSideSearchFieldArea(widthRemoved); - case CENTER -> getCenterSearchFieldArea(widthRemoved); - }; - } - - private Rectangle getTopSideSearchFieldArea(int widthRemoved) { - return new Rectangle(getBounds().x + 2, 4, getBounds().width - 6 - widthRemoved, 18); - } - - private Rectangle getBottomSideSearchFieldArea(int widthRemoved) { - Window window = Minecraft.getInstance().getWindow(); - return new Rectangle(getBounds().x + 2, window.getGuiScaledHeight() - 22, getBounds().width - 6 - widthRemoved, 18); - } - - private Rectangle getCenterSearchFieldArea(int widthRemoved) { - Window window = Minecraft.getInstance().getWindow(); - Rectangle screenBounds = ScreenRegistry.getInstance().getScreenBounds(minecraft.screen); - return new Rectangle(screenBounds.x, window.getGuiScaledHeight() - 22, screenBounds.width - widthRemoved, 18); - } - @Override protected void updateSearch() { - getEntryListWidget().initSearch(getSearchField().getText(), true); + getEntryList().initSearch(getSearchField().getText(), true); } @Override @@ -184,7 +139,7 @@ public void setFocused(@Nullable GuiEventListener focused) { @Override public EntryListWidget getEntryList() { EntryListWidget current = null; - for (EntryListProvider provider : ENTRY_LIST_PROVIDERS) { + for (EntryListProvider provider : EntryListProvider.PROVIDERS) { current = provider.getEntryList(); if (current != null) break; } @@ -205,7 +160,7 @@ public Optional getFavoritesList() { private FavoritesListWidget getFavoritesListNullable() { if (ConfigObject.getInstance().isFavoritesEnabled()) { FavoritesListWidget current = null; - for (FavoritesListProvider provider : FAVORITES_LIST_PROVIDERS) { + for (FavoritesListProvider provider : FavoritesListProvider.PROVIDERS) { current = provider.getFavoritesList(); if (current != null) break; } @@ -230,4 +185,21 @@ public TextField getSearchField() { public SearchFilter getCurrentSearchFilter() { return getEntryList().getSearchFilter(); } + + @Override + public boolean isHighlighting() { + return this.isHighlighted != null && this.isHighlighted.getAsBoolean(); + } + + @Override + public boolean submitDisplayHistory(Display display, @Nullable Rectangle fromBounds) { + FavoritesListWidget favoritesListWidget = getFavoritesListNullable(); + + if (favoritesListWidget != null) { + favoritesListWidget.submitDisplayHistory(display, fromBounds); + return true; + } else { + return false; + } + } } diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/EntryListProvider.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/EntryListProvider.java index 0e736a595..7e47f29e7 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/EntryListProvider.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/EntryListProvider.java @@ -23,11 +23,16 @@ package me.shedaniel.rei.impl.client.gui.overlay.entries; +import me.shedaniel.rei.impl.client.ClientInternals; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; +import java.util.List; + @ApiStatus.Internal public interface EntryListProvider { + List PROVIDERS = ClientInternals.resolveServices(EntryListProvider.class); + @Nullable EntryListWidget getEntryList(); } diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/FavoritesListProvider.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/FavoritesListProvider.java index ca88d3934..66b43975b 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/FavoritesListProvider.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/FavoritesListProvider.java @@ -23,12 +23,16 @@ package me.shedaniel.rei.impl.client.gui.overlay.entries; -import me.shedaniel.rei.api.client.overlay.OverlayListWidget; +import me.shedaniel.rei.impl.client.ClientInternals; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; +import java.util.List; + @ApiStatus.Internal public interface FavoritesListProvider { + List PROVIDERS = ClientInternals.resolveServices(FavoritesListProvider.class); + @Nullable FavoritesListWidget getFavoritesList(); } diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/FavoritesListWidget.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/FavoritesListWidget.java index ee75003eb..f81c751fa 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/FavoritesListWidget.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/FavoritesListWidget.java @@ -26,6 +26,9 @@ import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.overlay.OverlayListWidget; +import me.shedaniel.rei.api.common.display.Display; + +import javax.annotation.Nullable; public interface FavoritesListWidget extends OverlayListWidget { void initBounds(); @@ -33,4 +36,6 @@ public interface FavoritesListWidget extends OverlayListWidget { Widget asWidget(); Rectangle getFavoritesBounds(); + + void submitDisplayHistory(Display display, @Nullable Rectangle fromBounds); } diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/hints/InputMethodWatcher.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/hints/InputMethodWatcher.java new file mode 100644 index 000000000..005d367ef --- /dev/null +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/hints/InputMethodWatcher.java @@ -0,0 +1,172 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.client.gui.overlay.hints; + +import me.shedaniel.math.Color; +import me.shedaniel.math.Point; +import me.shedaniel.rei.api.client.config.ConfigObject; +import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry; +import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; +import me.shedaniel.rei.api.client.overlay.ScreenOverlay; +import me.shedaniel.rei.api.client.search.method.InputMethod; +import me.shedaniel.rei.api.client.search.method.InputMethodRegistry; +import me.shedaniel.rei.api.common.plugins.PluginManager; +import me.shedaniel.rei.api.common.util.CollectionUtils; +import me.shedaniel.rei.impl.client.config.ConfigManagerInternal; +import me.shedaniel.rei.impl.client.gui.hints.HintProvider; +import me.shedaniel.rei.impl.client.gui.menu.MenuAccess; +import me.shedaniel.rei.impl.client.gui.overlay.menu.entries.SubMenuEntry; +import me.shedaniel.rei.impl.client.gui.overlay.menu.entries.ToggleMenuEntry; +import me.shedaniel.rei.impl.client.gui.overlay.menu.provider.OverlayMenuEntryProvider; +import me.shedaniel.rei.impl.client.gui.screen.ConfigReloadingScreen; +import me.shedaniel.rei.impl.common.InternalLogger; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; + +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class InputMethodWatcher implements HintProvider, OverlayMenuEntryProvider { + public static final UUID MENU_UUID = UUID.fromString("b93cc166-d06f-4c5f-9bf0-334d18b4adaf"); + + @Override + public List provide() { + if (PluginManager.areAnyReloading() || ScreenOverlay.getInstance().orElseThrow().isHighlighting()) return Collections.emptyList(); + ResourceLocation id = ConfigObject.getInstance().getInputMethodId(); + if (id == null) { + String languageCode = Minecraft.getInstance().options.languageCode; + MutableComponent component = new TextComponent(""); + int match = 0; + for (Map.Entry> entry : InputMethodRegistry.getInstance().getAll().entrySet()) { + InputMethod method = entry.getValue(); + if (entry.getKey().equals(new ResourceLocation("rei:default"))) continue; + if (CollectionUtils.anyMatch(method.getMatchingLocales(), locale -> locale.code().equals(languageCode))) { + if (!component.getString().isEmpty()) { + component.append(", "); + } + + component.append(method.getName()); + match++; + } + } + if (match > 0) { + return List.of(new TranslatableComponent("text.rei.input.methods.hint"), + new TextComponent(" "), component); + } + } + + return Collections.emptyList(); + } + + @Override + @Nullable + public Tooltip provideTooltip(Point mouse) { + return null; + } + + @Override + public Color getColor() { + return Color.ofTransparent(0x50ffadca); + } + + @Override + public List getButtons(MenuAccess access) { + return List.of( + new HintButton(new TranslatableComponent("text.rei.input.methods.hint.configure"), bounds -> { + access.openOrClose(MENU_UUID, bounds.clone(), + () -> createInputMethodEntries(getApplicableInputMethods())); + }), + new HintButton(new TranslatableComponent("text.rei.input.methods.hint.ignore"), bounds -> { + ConfigManagerInternal.getInstance().set("functionality.inputMethod", new ResourceLocation("rei:default")); + }) + ); + } + + @Override + public List provide(Type type) { + if (type != Type.CRAFTABLE_FILTER) return List.of(); + + List>> applicableInputMethods = getApplicableInputMethods(); + if (applicableInputMethods.size() > 1) { + return List.of(new SubMenuEntry(new TranslatableComponent("text.rei.config.menu.search_field.input_method"), createInputMethodEntries(applicableInputMethods))); + } + + return List.of(); + } + + public static List>> getApplicableInputMethods() { + String languageCode = Minecraft.getInstance().options.languageCode; + return InputMethodRegistry.getInstance().getAll().entrySet().stream() + .filter(entry -> CollectionUtils.anyMatch(entry.getValue().getMatchingLocales(), locale -> locale.code().equals(languageCode))) + .toList(); + } + + public static List createInputMethodEntries(List>> applicableInputMethods) { + ConfigManagerInternal manager = ConfigManagerInternal.getInstance(); + ConfigObject config = ConfigObject.getInstance(); + return applicableInputMethods.stream() + .map(pair -> ToggleMenuEntry.of(pair.getValue().getName(), + () -> Objects.equals(config.getInputMethodId(), pair.getKey()), + bool -> { + ExecutorService service = Executors.newSingleThreadExecutor(); + InputMethod active = InputMethod.active(); + active.dispose(service).whenComplete((unused, throwable) -> { + if (throwable != null) { + InternalLogger.getInstance().error("Failed to dispose input method", throwable); + } + + manager.set("functionality.inputMethod", new ResourceLocation("rei:default")); + }).join(); + CompletableFuture future = pair.getValue().prepare(service).whenComplete((unused, throwable) -> { + if (throwable != null) { + InternalLogger.getInstance().error("Failed to prepare input method", throwable); + manager.set("functionality.inputMethod", new ResourceLocation("rei:default")); + } else { + manager.set("functionality.inputMethod", pair.getKey()); + } + }); + Screen screen = Minecraft.getInstance().screen; + Minecraft.getInstance().setScreen(new ConfigReloadingScreen(new TranslatableComponent("text.rei.input.methods.initializing"), + () -> !future.isDone(), () -> { + Minecraft.getInstance().setScreen(screen); + })); + future.whenComplete((unused, throwable) -> { + service.shutdown(); + }); + }) + .withActive(() -> !Objects.equals(config.getInputMethodId(), pair.getKey())) + .withTooltip(() -> Tooltip.create(TooltipContext.ofMouse(), pair.getValue().getDescription())) + ) + .toList(); + } +} diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/provider/OverlayMenuEntryProvider.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/provider/OverlayMenuEntryProvider.java index 401659300..367f16c46 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/provider/OverlayMenuEntryProvider.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/provider/OverlayMenuEntryProvider.java @@ -2,9 +2,11 @@ import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry; import me.shedaniel.rei.impl.client.ClientInternals; +import org.jetbrains.annotations.ApiStatus; import java.util.List; +@ApiStatus.Internal public interface OverlayMenuEntryProvider { List PROVIDERS = ClientInternals.resolveServices(OverlayMenuEntryProvider.class); diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/OverlayWidgetProvider.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/OverlayWidgetProvider.java index e89e4e98f..3c19aa6b7 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/OverlayWidgetProvider.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/OverlayWidgetProvider.java @@ -26,12 +26,19 @@ import me.shedaniel.rei.api.client.gui.widgets.TextField; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.overlay.ScreenOverlay; +import me.shedaniel.rei.impl.client.ClientInternals; import me.shedaniel.rei.impl.client.gui.menu.MenuAccess; import java.util.List; -import java.util.function.Consumer; +import java.util.function.BooleanSupplier; import java.util.function.UnaryOperator; public interface OverlayWidgetProvider { - List provide(ScreenOverlay overlay, MenuAccess access, Consumer textFieldSink, UnaryOperator lateRenderable); + List PROVIDERS = ClientInternals.resolveServices(OverlayWidgetProvider.class); + + List provide(ScreenOverlay overlay, MenuAccess access, TextFieldSink textFieldSink, UnaryOperator lateRenderable); + + interface TextFieldSink { + void accept(TextField textField, BooleanSupplier isHighlighted); + } } diff --git a/runtime-frontend/overlay/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.gui.hints.HintProvider b/runtime-frontend/overlay/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.gui.hints.HintProvider new file mode 100644 index 000000000..cde887e18 --- /dev/null +++ b/runtime-frontend/overlay/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.gui.hints.HintProvider @@ -0,0 +1 @@ +me.shedaniel.rei.impl.client.gui.overlay.hints.InputMethodWatcher \ No newline at end of file diff --git a/runtime-frontend/overlay/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.gui.overlay.menu.provider.OverlayMenuEntryProvider b/runtime-frontend/overlay/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.gui.overlay.menu.provider.OverlayMenuEntryProvider new file mode 100644 index 000000000..cde887e18 --- /dev/null +++ b/runtime-frontend/overlay/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.gui.overlay.menu.provider.OverlayMenuEntryProvider @@ -0,0 +1 @@ +me.shedaniel.rei.impl.client.gui.overlay.hints.InputMethodWatcher \ No newline at end of file diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index 9526129fe..50877066c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -104,11 +104,11 @@ public static void attachClientInternals() { ClientInternals.attachInstance((BiFunction<@Nullable Point, Collection, Tooltip>) TooltipImpl::impl, "tooltipProvider"); ClientInternals.attachInstance((TriFunction) TooltipContextImpl::new, "tooltipContextProvider"); ClientInternals.attachInstance((Function) TooltipImpl.TooltipEntryImpl::new, "tooltipEntryProvider"); - ClientInternals.attachInstance((Function<@Nullable Boolean, ClickArea.Result>) successful -> new ClickArea.Result() { + ClientInternals.attachInstance((Function) successful -> new ClickArea.Result() { private final List> categories = Lists.newArrayList(); private BooleanSupplier execute = () -> false; private Supplier tooltip = () -> { - if (categories != null && !categories.isEmpty()) { + if (!categories.isEmpty()) { Component collect = CollectionUtils.mapAndJoinToComponent(categories, identifier -> CategoryRegistry.getInstance().tryGet(identifier) .map(config -> config.getCategory().getTitle()) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/AutoCraftingButtonWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/AutoCraftingButtonWidget.java index f05c24317..9dc8675c7 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/AutoCraftingButtonWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/AutoCraftingButtonWidget.java @@ -29,12 +29,11 @@ import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.gui.widgets.*; +import me.shedaniel.rei.api.client.overlay.ScreenOverlay; import me.shedaniel.rei.api.client.registry.display.DisplayCategory; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.impl.client.ClientInternals; -import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.toast.CopyRecipeIdentifierToast; -import me.shedaniel.rei.impl.client.gui.widget.favorites.FavoritesListWidget; import me.shedaniel.rei.impl.client.provider.AutoCraftingEvaluator; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.resources.language.I18n; @@ -105,10 +104,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { return true; } else if (ConfigObject.getInstance().isFavoritesEnabled() && containsMouse(PointHelper.ofMouse())) { if (ConfigObject.getInstance().getFavoriteKeyCode().matchesKey(keyCode, scanCode)) { - FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget(); - - if (favoritesListWidget != null) { - favoritesListWidget.displayHistory.addDisplay(displayBounds.clone(), displaySupplier.get()); + if (ScreenOverlay.getInstance().get().submitDisplayHistory(displaySupplier.get(), displayBounds.clone())) { return true; } } @@ -127,10 +123,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { return true; } else if (ConfigObject.getInstance().isFavoritesEnabled() && containsMouse(PointHelper.ofMouse())) { if (ConfigObject.getInstance().getFavoriteKeyCode().matchesMouse(button)) { - FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget(); - - if (favoritesListWidget != null) { - favoritesListWidget.displayHistory.addDisplay(displayBounds.clone(), displaySupplier.get()); + if (ScreenOverlay.getInstance().get().submitDisplayHistory(displaySupplier.get(), displayBounds.clone())) { return true; } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayCompositeWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayCompositeWidget.java index d35ae8d32..829217f6e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayCompositeWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayCompositeWidget.java @@ -34,9 +34,8 @@ import me.shedaniel.rei.api.client.gui.widgets.DelegateWidgetWithBounds; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.gui.widgets.Widgets; +import me.shedaniel.rei.api.client.overlay.ScreenOverlay; import me.shedaniel.rei.api.common.display.Display; -import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; -import me.shedaniel.rei.impl.client.gui.widget.favorites.FavoritesListWidget; import me.shedaniel.rei.impl.display.DisplaySpec; import net.minecraft.client.gui.screens.Screen; import org.jetbrains.annotations.Nullable; @@ -77,10 +76,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { if (ConfigObject.getInstance().isFavoritesEnabled() && containsMouse(mouse())) { if (ConfigObject.getInstance().getFavoriteKeyCode().matchesKey(keyCode, scanCode)) { - FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget(); - - if (favoritesListWidget != null) { - favoritesListWidget.displayHistory.addDisplay(getBounds().clone(), display.provideInternalDisplay()); + if (ScreenOverlay.getInstance().get().submitDisplayHistory(display.provideInternalDisplay(), getBounds().clone())) { return true; } } @@ -97,10 +93,7 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) { if (ConfigObject.getInstance().isFavoritesEnabled() && containsMouse(mouseX, mouseY)) { if (ConfigObject.getInstance().getFavoriteKeyCode().matchesMouse(button)) { - FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget(); - - if (favoritesListWidget != null) { - favoritesListWidget.displayHistory.addDisplay(getBounds().clone(), display.provideInternalDisplay()); + if (ScreenOverlay.getInstance().get().submitDisplayHistory(display.provideInternalDisplay(), getBounds().clone())) { return true; } } diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/InputMethodWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/InputMethodWatcher.java deleted file mode 100644 index 94d1514f9..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/InputMethodWatcher.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.plugin.client.runtime; - -import me.shedaniel.math.Color; -import me.shedaniel.math.Point; -import me.shedaniel.rei.api.client.config.ConfigObject; -import me.shedaniel.rei.api.client.gui.widgets.Tooltip; -import me.shedaniel.rei.api.client.search.method.InputMethod; -import me.shedaniel.rei.api.client.search.method.InputMethodRegistry; -import me.shedaniel.rei.api.common.plugins.PluginManager; -import me.shedaniel.rei.api.common.util.CollectionUtils; -import me.shedaniel.rei.impl.client.config.ConfigManagerInternal; -import me.shedaniel.rei.impl.client.gui.hints.HintProvider; -import me.shedaniel.rei.impl.client.gui.menu.MenuAccess; -import me.shedaniel.rei.impl.client.gui.widget.CraftableFilterButtonWidget; -import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; -import net.minecraft.client.Minecraft; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -public class InputMethodWatcher implements HintProvider { - public static final UUID MENU_UUID = UUID.fromString("b93cc166-d06f-4c5f-9bf0-334d18b4adaf"); - - @Override - public List provide() { - if (PluginManager.areAnyReloading() || OverlaySearchField.isHighlighting) return Collections.emptyList(); - ResourceLocation id = ConfigObject.getInstance().getInputMethodId(); - if (id == null) { - String languageCode = Minecraft.getInstance().options.languageCode; - MutableComponent component = new TextComponent(""); - int match = 0; - for (Map.Entry> entry : InputMethodRegistry.getInstance().getAll().entrySet()) { - InputMethod method = entry.getValue(); - if (entry.getKey().equals(new ResourceLocation("rei:default"))) continue; - if (CollectionUtils.anyMatch(method.getMatchingLocales(), locale -> locale.code().equals(languageCode))) { - if (!component.getString().isEmpty()) { - component.append(", "); - } - - component.append(method.getName()); - match++; - } - } - if (match > 0) { - return List.of(new TranslatableComponent("text.rei.input.methods.hint"), - new TextComponent(" "), component); - } - } - - return Collections.emptyList(); - } - - @Override - @Nullable - public Tooltip provideTooltip(Point mouse) { - return null; - } - - @Override - public Color getColor() { - return Color.ofTransparent(0x50ffadca); - } - - @Override - public List getButtons(MenuAccess access) { - return List.of( - new HintButton(new TranslatableComponent("text.rei.input.methods.hint.configure"), bounds -> { - access.openOrClose(MENU_UUID, bounds.clone(), - () -> CraftableFilterButtonWidget.createInputMethodEntries(CraftableFilterButtonWidget.getApplicableInputMethods())); - }), - new HintButton(new TranslatableComponent("text.rei.input.methods.hint.ignore"), bounds -> { - ConfigManagerInternal.getInstance().set("functionality.inputMethod", new ResourceLocation("rei:default")); - }) - ); - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchBarHighlightWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchBarHighlightWatcher.java index 157c0b098..0d711ee4c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchBarHighlightWatcher.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchBarHighlightWatcher.java @@ -26,9 +26,9 @@ import me.shedaniel.math.Color; import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.client.overlay.ScreenOverlay; import me.shedaniel.rei.impl.client.gui.hints.HintProvider; import me.shedaniel.rei.impl.client.gui.menu.MenuAccess; -import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TranslatableComponent; import org.jetbrains.annotations.Nullable; @@ -39,7 +39,7 @@ public class SearchBarHighlightWatcher implements HintProvider { @Override public List provide() { - return OverlaySearchField.isHighlighting ? Collections.singletonList(new TranslatableComponent("text.rei.inventory.highlighting.enabled")) : + return ScreenOverlay.getInstance().get().isHighlighting() ? Collections.singletonList(new TranslatableComponent("text.rei.inventory.highlighting.enabled")) : Collections.emptyList(); } diff --git a/runtime/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.gui.hints.HintProvider b/runtime/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.gui.hints.HintProvider index 5e8ecf8d2..a63183fb2 100644 --- a/runtime/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.gui.hints.HintProvider +++ b/runtime/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.gui.hints.HintProvider @@ -1,3 +1,2 @@ me.shedaniel.rei.plugin.client.runtime.PluginStageExecutionWatcher -me.shedaniel.rei.plugin.client.runtime.SearchBarHighlightWatcher -me.shedaniel.rei.plugin.client.runtime.InputMethodWatcher \ No newline at end of file +me.shedaniel.rei.plugin.client.runtime.SearchBarHighlightWatcher \ No newline at end of file