diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-08-28 18:50:24 +0900 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-08-28 18:50:24 +0900 |
| commit | 94e323f75c17e297c33fba1d3afb5c47ae66a8ad (patch) | |
| tree | 3c6cb6c1721fbda792050b96707fad50d1db64e9 /runtime/src/main/java | |
| parent | f5061d043cac7f0217bbe9d4c041b77f9ef911a1 (diff) | |
| download | RoughlyEnoughItems-94e323f75c17e297c33fba1d3afb5c47ae66a8ad.tar.gz RoughlyEnoughItems-94e323f75c17e297c33fba1d3afb5c47ae66a8ad.tar.bz2 RoughlyEnoughItems-94e323f75c17e297c33fba1d3afb5c47ae66a8ad.zip | |
Separate EntryListWidget and FavoritesListWidget more
Diffstat (limited to 'runtime/src/main/java')
60 files changed, 73 insertions, 7722 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java index 3c1cbcb01..c132fa569 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java @@ -23,7 +23,6 @@ package me.shedaniel.rei.impl.client; -import com.google.common.base.Suppliers; import me.shedaniel.rei.api.client.ClientHelper; import me.shedaniel.rei.api.client.config.ConfigManager; import me.shedaniel.rei.api.client.config.ConfigObject; @@ -44,23 +43,12 @@ import net.minecraft.client.gui.screens.Screen; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.time.LocalDateTime; import java.util.List; import java.util.Map; -import java.util.function.Supplier; @ApiStatus.Internal @Environment(EnvType.CLIENT) public class ClientHelperImpl extends ClientNetworkHelperImpl implements ClientModNameHelperImpl { - public final Supplier<Boolean> isAprilFools = Suppliers.memoize(() -> { - try { - LocalDateTime now = LocalDateTime.now(); - return now.getMonthValue() == 4 && now.getDayOfMonth() == 1; - } catch (Throwable ignored) { - } - return false; - }); - /** * @return the instance of {@link ClientHelperImpl} * @see ClientHelper#getInstance() diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientNetworkHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientNetworkHelperImpl.java index 18efbbf22..746c29a06 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientNetworkHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientNetworkHelperImpl.java @@ -68,7 +68,7 @@ public abstract class ClientNetworkHelperImpl implements ClientHelper { return NetworkManager.canServerReceive(RoughlyEnoughItemsNetwork.CREATE_ITEMS_HOTBAR_PACKET); } - public boolean canDeleteItems() { + public boolean canUseDeletePackets() { return hasPermissionToUsePackets() || Minecraft.getInstance().gameMode.hasInfiniteItems(); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java index 0c4007509..a38354ff6 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java @@ -28,7 +28,6 @@ import com.mojang.blaze3d.systems.RenderSystem; import dev.architectury.event.EventResult; import dev.architectury.event.events.client.ClientGuiEvent; import dev.architectury.event.events.client.ClientTickEvent; -import dev.architectury.platform.Platform; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigObject; @@ -52,7 +51,6 @@ import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.InvocationTargetException; import java.util.Optional; import static me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListWidget.entrySize; @@ -76,14 +74,7 @@ public class REIRuntimeImpl implements REIRuntime { @Override public Optional<ScreenOverlay> getOverlay(boolean reset, boolean init) { if ((overlay == null && init) || reset) { - try { - overlay = (ScreenOverlayImpl) Class.forName(Platform.isForge() ? "me.shedaniel.rei.impl.client.gui.forge.ScreenOverlayImplForge" - : "me.shedaniel.rei.impl.client.gui.fabric.ScreenOverlayImplFabric") - .getDeclaredConstructor() - .newInstance(); - } catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { - throw new RuntimeException(e); - } + overlay = new ScreenOverlayImpl(); overlay.init(); overlay.getSearchField().setFocused(false); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/DisplayScreenStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/DisplayScreenStack.java index 4b12aa5d6..9b590da56 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/DisplayScreenStack.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/DisplayScreenStack.java @@ -1,3 +1,26 @@ +/* + * 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; import com.google.common.collect.Iterables; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java deleted file mode 100644 index 1943ad379..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java +++ /dev/null @@ -1,208 +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.impl.client.gui; - -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.TextField; -import me.shedaniel.rei.api.client.overlay.OverlayListWidget; -import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; -import me.shedaniel.rei.impl.client.gui.overlay.AbstractScreenOverlay; -import me.shedaniel.rei.impl.client.gui.widget.ConfigButtonWidget; -import me.shedaniel.rei.impl.client.gui.widget.CraftableFilterButtonWidget; -import me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListWidget; -import me.shedaniel.rei.impl.client.gui.widget.entrylist.PaginatedEntryListWidget; -import me.shedaniel.rei.impl.client.gui.widget.entrylist.ScrolledEntryListWidget; -import me.shedaniel.rei.impl.client.gui.widget.favorites.FavoritesListWidget; -import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; -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.Objects; -import java.util.Optional; - -@ApiStatus.Internal -public abstract class ScreenOverlayImpl extends AbstractScreenOverlay { - private EntryListWidget entryListWidget = null; - private FavoritesListWidget favoritesListWidget = null; - private OverlaySearchField searchField = null; - - public static EntryListWidget getEntryListWidget() { - return getInstance().getEntryList(); - } - - @Nullable - public static FavoritesListWidget getFavoritesListWidget() { - return getInstance().getFavoritesListNullable(); - } - - public static ScreenOverlayImpl getInstance() { - return (ScreenOverlayImpl) REIRuntime.getInstance().getOverlay().get(); - } - - @Override - public void init() { - super.init(); - - TextField searchField = getSearchField(); - searchField.asWidget().getBounds().setBounds(getSearchFieldArea()); - this.children().add(searchField.asWidget()); - - if (ConfigObject.getInstance().isFavoritesEnabled()) { - getFavoritesListWidget().favoritePanel.resetRows(); - this.children().add(getFavoritesListWidget()); - } - - EntryListWidget entryListWidget = getEntryListWidget(); - entryListWidget.updateArea(this.getBounds(), searchField.getText()); - this.children().add(entryListWidget); - searchField.setResponder(s -> entryListWidget.updateSearch(s, false)); - entryListWidget.init(this); - - this.children().add(ConfigButtonWidget.create(this)); - if (ConfigObject.getInstance().isCraftableFilterEnabled()) { - this.children().add(CraftableFilterButtonWidget.create(this)); - } - } - - 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().updateSearch(getSearchField().getText(), true); - } - - @Override - public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (super.keyPressed(keyCode, scanCode, modifiers)) return true; - if (!hasSpace()) return false; - if (!REIRuntime.getInstance().isOverlayVisible()) return false; - if (ConfigObject.getInstance().getFocusSearchFieldKeybind().matchesKey(keyCode, scanCode)) { - getSearchField().setFocused(true); - setFocused(getSearchField()); - getSearchField().keybindFocusTime = System.currentTimeMillis(); - getSearchField().keybindFocusKey = keyCode; - return true; - } - return false; - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (super.mouseClicked(mouseX, mouseY, button)) return true; - boolean visible = REIRuntime.getInstance().isOverlayVisible(); - if (!hasSpace() || !visible) return false; - if (ConfigObject.getInstance().getFocusSearchFieldKeybind().matchesMouse(button)) { - getSearchField().setFocused(true); - setFocused(getSearchField().asWidget()); - getSearchField().keybindFocusTime = -1; - getSearchField().keybindFocusKey = -1; - return true; - } - return false; - } - - @Override |
