diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-09-11 02:32:57 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-09-11 02:32:57 +0800 |
| commit | 229b1fecdac427d3debe68f52ed7276e54a11cd0 (patch) | |
| tree | dad0bbe34d45fd2ec3424890f3f4085f116ad584 /runtime | |
| parent | fb91ed996b01f986492de4007cb86be5e68ad192 (diff) | |
| download | RoughlyEnoughItems-229b1fecdac427d3debe68f52ed7276e54a11cd0.tar.gz RoughlyEnoughItems-229b1fecdac427d3debe68f52ed7276e54a11cd0.tar.bz2 RoughlyEnoughItems-229b1fecdac427d3debe68f52ed7276e54a11cd0.zip | |
Improve Overlay Menus
Diffstat (limited to 'runtime')
6 files changed, 11 insertions, 133 deletions
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 class RoughlyEnoughItemsCoreClient { ClientInternals.attachInstance((BiFunction<@Nullable Point, Collection<Tooltip.Entry>, Tooltip>) TooltipImpl::impl, "tooltipProvider"); ClientInternals.attachInstance((TriFunction<Point, @Nullable TooltipFlag, Boolean, TooltipContext>) TooltipContextImpl::new, "tooltipContextProvider"); ClientInternals.attachInstance((Function<Object, Tooltip.Entry>) TooltipImpl.TooltipEntryImpl::new, "tooltipEntryProvider"); - ClientInternals.attachInstance((Function<@Nullable Boolean, ClickArea.Result>) successful -> new ClickArea.Result() { + ClientInternals.attachInstance((Function<Boolean, ClickArea.Result>) successful -> new ClickArea.Result() { private final List<CategoryIdentifier<?>> categories = Lists.newArrayList(); private BooleanSupplier execute = () -> false; private Supplier<Component @Nullable []> 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.Rectangle; 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 class AutoCraftingButtonWidget { 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 class AutoCraftingButtonWidget { 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.drag.component.DraggableComponentProvider 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 class DisplayCompositeWidget extends DelegateWidgetWithBounds implements 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 class DisplayCompositeWidget extends DelegateWidgetWithBounds implements 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<Component> 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<ResourceLocation, InputMethod<?>> 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<HintButton> 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 @@ package me.shedaniel.rei.plugin.client.runtime; 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 @@ import java.util.List; public class SearchBarHighlightWatcher implements HintProvider { @Override public List<Component> 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 |
