diff options
| author | shedaniel <daniel@shedaniel.me> | 2024-09-24 11:53:57 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2024-09-24 11:59:18 +0800 |
| commit | 106896bce86f1984df7be0bda33aba93c8815c4a (patch) | |
| tree | 80467a55723325bbe30076f5ea616f060305567c /runtime/src/main/java | |
| parent | 20317a973895ad237fb58adc2b2b1ece8a45cea4 (diff) | |
| parent | 91cc0c43de61b97b54477f90710a45bc71b744b9 (diff) | |
| download | RoughlyEnoughItems-106896bce86f1984df7be0bda33aba93c8815c4a.tar.gz RoughlyEnoughItems-106896bce86f1984df7be0bda33aba93c8815c4a.tar.bz2 RoughlyEnoughItems-106896bce86f1984df7be0bda33aba93c8815c4a.zip | |
Merge branch '12.x-1.20' into 14.x-1.20.4
# Conflicts:
# build.gradle
# gradle/wrapper/gradle-wrapper.properties
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java
Diffstat (limited to 'runtime/src/main/java')
11 files changed, 124 insertions, 23 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java index 7840fa6cd..41e91b7c9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java @@ -658,6 +658,8 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @Comment("Declares whether subsets is enabled.") public boolean isSubsetsEnabled = false; public boolean allowInventoryHighlighting = true; + public double inventoryHighlightingDarkenOpacity = 0.85; + public double inventoryHighlightingOpacity = 1.0; public ItemCheatingMode itemCheatingMode = ItemCheatingMode.REI_LIKE; } 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 cdc5c8c88..b0cea2bb6 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 @@ -82,6 +82,8 @@ public class REIConfigScreen extends Screen implements ConfigAccess { @Nullable private Menu menu; @Nullable + private Widget menuWidget; + @Nullable private CompositeOption<ModifierKeyCode> focusedKeycodeOption = null; private ModifierKeyCode partialKeycode = null; @@ -398,14 +400,18 @@ public class REIConfigScreen extends Screen implements ConfigAccess { @Override public void openMenu(Menu menu) { + if (this.menu != null) { + this.widgets.remove(this.menuWidget); + } this.menu = menu; - this.widgets.add(menu); + this.widgets.add(this.menuWidget = Widgets.withTranslate(menu, 0, 0, 300)); } @Override public void closeMenu() { - this.widgets.remove(menu); + this.widgets.remove(this.menuWidget); this.menu = null; + this.menuWidget = null; } @Override 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 40e94ae10..0749f11a8 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 @@ -51,6 +51,7 @@ public interface AllREIConfigCategories { OptionCategory ACCESSIBILITY = make("accessibility") .add(ACCESSIBILITY_DISPLAY) .add(ACCESSIBILITY_WIDGETS) + .add(ACCESSIBILITY_INVENTORY_SEARCH) .add(ACCESSIBILITY_FEATURES); OptionCategory FILTERING = make("filtering") .add(FILTERING_FILTERING) 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 b206fd6e5..474132b8e 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 @@ -68,10 +68,13 @@ public interface AllREIConfigGroups { OptionGroup ACCESSIBILITY_WIDGETS = make("accessibility.widgets") .add(SCROLLBAR_VISIBILITY) .add(CLICKABLE_RECIPE_ARROWS); + OptionGroup ACCESSIBILITY_INVENTORY_SEARCH = make("accessibility.inventory_search") + .add(INVENTORY_SEARCH_MODE) + .add(INVENTORY_SEARCH_DARKEN_OPACITY) + .add(INVENTORY_SEARCH_OPACITY); OptionGroup ACCESSIBILITY_FEATURES = make("accessibility.features") .add(VANILLA_RECIPE_BOOK) - .add(STATUS_EFFECTS_LOCATION) - .add(INVENTORY_SEARCH); + .add(STATUS_EFFECTS_LOCATION); OptionGroup FILTERING_FILTERING = make("filtering.filtering") .add(CATEGORIES) .add(CUSTOMIZED_FILTERING); 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 97119df2e..30a673e38 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 @@ -60,6 +60,15 @@ public interface AllREIConfigOptions { translatable("config.rei.options." + id + ".desc"), bind, save); } + static ComparableValue<Double>[] doubleRange(double start, double end, double step) { + int length = (int) Math.ceil((end - start) / step + 1); + ComparableValue<Double>[] result = new ComparableValue[length]; + for (int i = 0; i < length; i++) { + result[i] = ComparableValue.ofDouble(Math.min(start + i * step, end)); + } + return result; + } + CompositeOption<AppearanceTheme> THEME = make("appearance.theme", i -> i.appearance.theme, (i, v) -> i.appearance.theme = v) .enumOptions(); CompositeOption<RecipeBorderType> RECIPE_BORDER = make("appearance.recipe_border", i -> i.appearance.recipeBorder, (i, v) -> i.appearance.recipeBorder = v) @@ -140,12 +149,18 @@ public interface AllREIConfigOptions { .ofBoolean(translatable("config.rei.value.accessibility.scrollbar_visibility.when_scrolling"), translatable("config.rei.value.accessibility.scrollbar_visibility.always")); CompositeOption<Boolean> CLICKABLE_RECIPE_ARROWS = make("accessibility.clickable_recipe_arrows", i -> i.advanced.miscellaneous.clickableRecipeArrows, (i, v) -> i.advanced.miscellaneous.clickableRecipeArrows = v) .enabledDisabled(); + CompositeOption<Boolean> INVENTORY_SEARCH_MODE = make("accessibility.inventory_search_mode", i -> i.functionality.allowInventoryHighlighting, (i, v) -> i.functionality.allowInventoryHighlighting = v) + .enabledDisabled(); + CompositeOption<ComparableValue<Double>> INVENTORY_SEARCH_DARKEN_OPACITY = make("accessibility.inventory_search_darken_opacity", i -> ComparableValue.ofDouble(i.functionality.inventoryHighlightingDarkenOpacity), (i, v) -> i.functionality.inventoryHighlightingDarkenOpacity = v.value()) + .entry(OptionValueEntry.options(doubleRange(0.0, 1.0, 0.05)) + .overrideText(d -> literal("%.0f%%".formatted(d.value() * 100)))); + CompositeOption<ComparableValue<Double>> INVENTORY_SEARCH_OPACITY = make("accessibility.inventory_search_opacity", i -> ComparableValue.ofDouble(i.functionality.inventoryHighlightingOpacity), (i, v) -> i.functionality.inventoryHighlightingOpacity = v.value()) + .entry(OptionValueEntry.options(doubleRange(0.0, 1.0, 0.05)) + .overrideText(d -> literal("%.0f%%".formatted(d.value() * 100)))); CompositeOption<Boolean> VANILLA_RECIPE_BOOK = make("accessibility.vanilla_recipe_book", i -> !i.functionality.disableRecipeBook, (i, v) -> i.functionality.disableRecipeBook = !v) .enabledDisabled(); CompositeOption<Boolean> STATUS_EFFECTS_LOCATION = make("accessibility.status_effects_location", i -> i.functionality.leftSideMobEffects, (i, v) -> i.functionality.leftSideMobEffects = v) .ofBoolean(translatable("config.rei.value.accessibility.status_effects_location.right"), translatable("config.rei.value.accessibility.status_effects_location.left")); - CompositeOption<Boolean> INVENTORY_SEARCH = make("accessibility.inventory_search", i -> i.functionality.allowInventoryHighlighting, (i, v) -> i.functionality.allowInventoryHighlighting = v) - .enabledDisabled(); CompositeOption<ConfigureCategoriesScreen> CATEGORIES = make("filtering.categories", i -> { return new ConfigureCategoriesScreen( new HashMap<>(i.getFilteringQuickCraftCategories()), @@ -182,7 +197,9 @@ public interface AllREIConfigOptions { .ofBoolean(translatable("config.rei.value.list.display_mode.paginated"), translatable("config.rei.value.list.display_mode.scrolled")); CompositeOption<EntryPanelOrderingConfig> ORDERING = make("list.ordering", i -> i.advanced.layout.entryPanelOrdering, (i, v) -> i.advanced.layout.entryPanelOrdering = v) .enumOptions(); - CompositeOption<Double> ZOOM = make("list.zoom", i -> i.advanced.accessibility.entrySize, (i, v) -> i.advanced.accessibility.entrySize = v); + CompositeOption<ComparableValue<Double>> ZOOM = make("list.zoom", i -> ComparableValue.ofDouble(i.advanced.accessibility.entrySize), (i, v) -> i.advanced.accessibility.entrySize = v.value()) + .entry(OptionValueEntry.options(doubleRange(0.25, 4.0, 0.25)) + .overrideText(d -> literal("%.0f%%".formatted(d.value() * 100)))); CompositeOption<Boolean> FOCUS_MODE = make("list.focus_mode", i -> i.appearance.isFocusModeZoomed, (i, v) -> i.appearance.isFocusModeZoomed = v) .ofBoolean(translatable("config.rei.value.list.focus_mode.highlighted"), translatable("config.rei.value.list.focus_mode.zoomed")); CompositeOption<CollapsibleConfigManager.CollapsibleConfigObject> COLLAPSIBLE_ENTRIES = make("list.collapsible_entries", i -> { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ComparableValue.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ComparableValue.java new file mode 100644 index 000000000..d3cea57a3 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ComparableValue.java @@ -0,0 +1,70 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.config.options; + +import org.jetbrains.annotations.ApiStatus; + +import java.util.Objects; +import java.util.function.BiPredicate; + +@ApiStatus.Internal +public final class ComparableValue<T> { + private final T value; + private final BiPredicate<T, Object> equals; + + private ComparableValue(T value, BiPredicate<T, Object> equals) { + this.value = value; + this.equals = equals; + } + + public static <T> ComparableValue<T> of(T value, BiPredicate<T, Object> equals) { + return new ComparableValue<>(value, equals); + } + + public static ComparableValue<Float> ofFloat(float value) { + return of(value, (a, b) -> b instanceof Float f && Math.abs(a - f) <= 0.001F); + } + + public static ComparableValue<Double> ofDouble(double value) { + return of(value, (a, b) -> b instanceof Double d && Math.abs(a - d) <= 0.001D); + } + + public T value() { + return value; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ComparableValue) { + return equals.test(value, ((ComparableValue<?>) obj).value); + } + + return false; + } + + @Override + public int hashCode() { + return Objects.hashCode(value); + } +} 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 d1ef77787..fa058a1d9 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 @@ -82,7 +82,7 @@ public interface OptionValueEntry<T> { }; } - static <T> OptionValueEntry<T> options(T... options) { + static <T> OptionValueEntry.Selection<T> options(T... options) { return new Selection<>() { @Override public List<T> getOptions() { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/configure/PanelBoundariesConfiguration.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/configure/PanelBoundariesConfiguration.java index 38c259e8c..b90ca9a37 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/configure/PanelBoundariesConfiguration.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/configure/PanelBoundariesConfiguration.java @@ -308,7 +308,7 @@ public enum PanelBoundariesConfiguration implements OptionValueEntry.Configurato } private void renderPreview(GuiGraphics graphics, Rectangle panelBounds, float delta) { - int entrySize = Mth.ceil(18 * access.get(AllREIConfigOptions.ZOOM)); + int entrySize = Mth.ceil(18 * access.get(AllREIConfigOptions.ZOOM).value()); Rectangle overlayBounds; DisplayPanelLocation location = access.get(AllREIConfigOptions.LOCATION); PanelBoundary boundary = access.get(option); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryHighlighter.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryHighlighter.java index 72e579ade..be711e98c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryHighlighter.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryHighlighter.java @@ -24,34 +24,39 @@ package me.shedaniel.rei.impl.client.gui.widget; import com.mojang.blaze3d.systems.RenderSystem; +import me.shedaniel.math.Color; import me.shedaniel.rei.api.common.util.EntryStacks; +import me.shedaniel.rei.impl.client.config.ConfigManagerImpl; import me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListSearchManager; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.client.renderer.RenderType; import net.minecraft.world.inventory.Slot; public class EntryHighlighter { public static void render(GuiGraphics graphics) { + float dimOpacity = (float) ConfigManagerImpl.getInstance().getConfig().functionality.inventoryHighlightingDarkenOpacity; + float opacity = (float) ConfigManagerImpl.getInstance().getConfig().functionality.inventoryHighlightingOpacity; + int dimColor = Color.ofRGBA(20 / 255F, 20 / 255F, 20 / 255F, dimOpacity).getColor(); + int borderColor = Color.ofRGBA(0x5f / 255F, 0xff / 255F, 0x3b / 255F, opacity).getColor(); + int color = Color.ofRGBA(0x5f / 255F, 0xff / 255F, 0x3b / 255F, opacity * 0x34 / 255F).getColor(); RenderSystem.disableDepthTest(); RenderSystem.colorMask(true, true, true, false); if (Minecraft.getInstance().screen instanceof AbstractContainerScreen<?> containerScreen) { int x = containerScreen.leftPos, y = containerScreen.topPos; for (Slot slot : containerScreen.getMenu().slots) { if (!slot.hasItem() || !EntryListSearchManager.INSTANCE.matches(EntryStacks.of(slot.getItem()))) { - graphics.pose().pushPose(); - graphics.pose().translate(0, 0, 500f); - graphics.fillGradient(x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, 0xdc202020, 0xdc202020); - graphics.pose().popPose(); + graphics.fillGradient(RenderType.guiOverlay(), x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, dimColor, dimColor, 0); } else { graphics.pose().pushPose(); graphics.pose().translate(0, 0, 200f); - graphics.fillGradient(x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, 0x345fff3b, 0x345fff3b); - - graphics.fillGradient(x + slot.x - 1, y + slot.y - 1, x + slot.x, y + slot.y + 16 + 1, 0xff5fff3b, 0xff5fff3b); - graphics.fillGradient(x + slot.x + 16, y + slot.y - 1, x + slot.x + 16 + 1, y + slot.y + 16 + 1, 0xff5fff3b, 0xff5fff3b); - graphics.fillGradient(x + slot.x - 1, y + slot.y - 1, x + slot.x + 16, y + slot.y, 0xff5fff3b, 0xff5fff3b); - graphics.fillGradient(x + slot.x - 1, y + slot.y + 16, x + slot.x + 16, y + slot.y + 16 + 1, 0xff5fff3b, 0xff5fff3b); + graphics.fillGradient(x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, color, color); + + graphics.fillGradient(x + slot.x - 1, y + slot.y - 1, x + slot.x, y + slot.y + 16 + 1, borderColor, borderColor); + graphics.fillGradient(x + slot.x + 16, y + slot.y - 1, x + slot.x + 16 + 1, y + slot.y + 16 + 1, borderColor, borderColor); + graphics.fillGradient(x + slot.x - 1, y + slot.y - 1, x + slot.x + 16, y + slot.y, borderColor, borderColor); + graphics.fillGradient(x + slot.x - 1, y + slot.y + 16, x + slot.x + 16, y + slot.y + 16 + 1, borderColor, borderColor); graphics.pose().popPose(); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java index 8159ff88a..831fa2cda 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java @@ -172,7 +172,7 @@ public abstract class EntryListWidget extends WidgetWithBounds implements Overla if (Screen.hasControlDown()) { ConfigObjectImpl config = ConfigManagerImpl.getInstance().getConfig(); scaleIndicator.setAs(10.0D); - if (config.setEntrySize(config.getEntrySize() + amountY * 0.075)) { + if (config.setEntrySize(config.getEntrySize() + Double.compare(amountY, 0) * 0.05)) { ConfigManager.getInstance().saveConfig(); REIRuntime.getInstance().getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay); return true; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/collapsed/CollapsedEntriesCache.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/collapsed/CollapsedEntriesCache.java index 4b5fb44ff..a97721bd0 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/collapsed/CollapsedEntriesCache.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/collapsed/CollapsedEntriesCache.java @@ -23,7 +23,6 @@ package me.shedaniel.rei.impl.client.search.collapsed; -import com.google.common.collect.Lists; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import me.shedaniel.rei.api.client.registry.entry.CollapsibleEntryRegistry; @@ -35,9 +34,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.HashSet; -import java.util.List; import java.util.Set; -import java.util.concurrent.CompletableFuture; public class CollapsedEntriesCache { private static CollapsedEntriesCache instance = new CollapsedEntriesCache(); |
