diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-01-16 16:10:19 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-01-16 16:10:19 +0800 |
| commit | b4be45e414504afb49910d766bebcd00f55b052b (patch) | |
| tree | 05c36b311681a120c0e3c85131531a159fbc59c2 /src/main/java/me | |
| parent | 01e8ede4fc41f6f113ae623044c3a4e98ed81eb4 (diff) | |
| download | RoughlyEnoughItems-b4be45e414504afb49910d766bebcd00f55b052b.tar.gz RoughlyEnoughItems-b4be45e414504afb49910d766bebcd00f55b052b.tar.bz2 RoughlyEnoughItems-b4be45e414504afb49910d766bebcd00f55b052b.zip | |
3.3.11
Diffstat (limited to 'src/main/java/me')
40 files changed, 603 insertions, 306 deletions
diff --git a/src/main/java/me/shedaniel/rei/api/OptimalEntryStack.java b/src/main/java/me/shedaniel/rei/api/OptimalEntryStack.java new file mode 100644 index 000000000..0a98ccf72 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/OptimalEntryStack.java @@ -0,0 +1,25 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.api; + +import me.shedaniel.math.api.Rectangle; +import me.shedaniel.rei.api.annotations.Internal; + +@Internal +@Deprecated +public interface OptimalEntryStack { + default void optimisedRenderStart(float delta) { + } + + default void optimisedRenderBase(Rectangle bounds, int mouseX, int mouseY, float delta) { + } + + default void optimisedRenderOverlay(Rectangle bounds, int mouseX, int mouseY, float delta) { + } + + default void optimisedRenderEnd(float delta) { + } +} diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java index fea0cf166..7378fb862 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java @@ -9,7 +9,6 @@ import me.shedaniel.math.api.Rectangle; import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.entries.RecipeEntry; import me.shedaniel.rei.gui.entries.SimpleRecipeEntry; -import me.shedaniel.rei.gui.widget.CategoryBaseWidget; import me.shedaniel.rei.gui.widget.PanelWidget; import me.shedaniel.rei.gui.widget.RecipeBaseWidget; import me.shedaniel.rei.gui.widget.Widget; diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index 7e51678b2..576f74ee6 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -294,11 +294,6 @@ public class ContainerScreenOverlay extends WidgetWithBounds { } @Override - public Optional<String> getTooltips() { - return Optional.ofNullable(I18n.translate("text.rei.go_back_first_page")); - } - - @Override public void onLabelClicked() { MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); ENTRY_LIST_WIDGET.setPage(0); @@ -309,7 +304,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { public boolean changeFocus(boolean boolean_1) { return false; } - }); + }.tooltip(() -> I18n.translate("text.rei.go_back_first_page"))); } if (ConfigObject.getInstance().isCraftableFilterEnabled()) this.widgets.add(toggleButtonWidget = new CraftableToggleButtonWidget(getCraftableToggleArea()) { diff --git a/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java b/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java index 46ffc30ba..31b4a5d7b 100644 --- a/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java +++ b/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java @@ -7,6 +7,7 @@ package me.shedaniel.rei.gui; import com.google.common.collect.Lists; import com.mojang.blaze3d.systems.RenderSystem; +import me.shedaniel.math.api.Point; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.annotations.Internal; import me.shedaniel.rei.gui.widget.TextFieldWidget; @@ -16,15 +17,18 @@ import net.minecraft.client.resource.language.I18n; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.client.util.InputUtil; import net.minecraft.sound.SoundEvents; +import net.minecraft.util.Pair; import java.util.List; +@Internal +@Deprecated public class OverlaySearchField extends TextFieldWidget { public static boolean isSearching = false; public long keybindFocusTime = -1; public int keybindFocusKey = -1; - protected long lastClickedTime = -1; + protected Pair<Long, Point> lastClickedDetails = null; private List<String> history = Lists.newArrayListWithCapacity(100); OverlaySearchField(int x, int y, int width, int height) { @@ -67,14 +71,25 @@ public class OverlaySearchField extends TextFieldWidget { this.font.drawWithShadow(this.font.trimToWidth(this.getSuggestion(), this.getWidth()), x, y, -6250336); } + @SuppressWarnings("deprecation") @Override public void renderBorder() { - if (!isSearching) - super.renderBorder(); - else if (this.hasBorder()) { + boolean hasError = ContainerScreenOverlay.getEntryListWidget().getAllStacks().isEmpty() && !getText().isEmpty(); + if (isSearching) { fill(this.getBounds().x - 1, this.getBounds().y - 1, this.getBounds().x + this.getBounds().width + 1, this.getBounds().y + this.getBounds().height + 1, -852212); - fill(this.getBounds().x, this.getBounds().y, this.getBounds().x + this.getBounds().width, this.getBounds().y + this.getBounds().height, -16777216); + } else if (hasError) { + fill(this.getBounds().x - 1, this.getBounds().y - 1, this.getBounds().x + this.getBounds().width + 1, this.getBounds().y + this.getBounds().height + 1, -43691); + } else { + super.renderBorder(); + return; } + fill(this.getBounds().x, this.getBounds().y, this.getBounds().x + this.getBounds().width, this.getBounds().y + this.getBounds().height, -16777216); + } + + public int getManhattanDistance(Point point1, Point point2) { + int e = Math.abs(point1.getX() - point2.getX()); + int f = Math.abs(point1.getY() - point2.getY()); + return e + f; } @Override @@ -83,14 +98,16 @@ public class OverlaySearchField extends TextFieldWidget { if (isVisible() && contains && int_1 == 1) setText(""); if (contains && int_1 == 0) - if (lastClickedTime == -1) - lastClickedTime = System.currentTimeMillis(); - else if (System.currentTimeMillis() - lastClickedTime > 700) - lastClickedTime = -1; - else { - lastClickedTime = -1; + if (lastClickedDetails == null) + lastClickedDetails = new Pair<>(System.currentTimeMillis(), new Point(double_1, double_2)); + else if (System.currentTimeMillis() - lastClickedDetails.getLeft() > 1500) + lastClickedDetails = null; + else if (getManhattanDistance(lastClickedDetails.getRight(), new Point(double_1, double_2)) <= 25) { + lastClickedDetails = null; isSearching = !isSearching; minecraft.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); + } else { + lastClickedDetails = new Pair<>(System.currentTimeMillis(), new Point(double_1, double_2)); } return super.mouseClicked(double_1, double_2, int_1); } @@ -140,7 +157,7 @@ public class OverlaySearchField extends TextFieldWidget { } @Override - public void render(int int_1, int int_2, float float_1) { + public void render(int mouseX, int mouseY, float delta) { } } diff --git a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java index c45868256..1220a4df2 100644 --- a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java @@ -11,6 +11,7 @@ import me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWi import me.shedaniel.clothconfig2.impl.EasingMethod; import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; +import me.shedaniel.rei.api.annotations.Internal; import me.shedaniel.rei.gui.config.RecipeScreenType; import me.shedaniel.rei.gui.widget.ButtonWidget; import me.shedaniel.rei.gui.widget.LabelWidget; @@ -30,6 +31,8 @@ import net.minecraft.util.math.MathHelper; import java.util.Collections; import java.util.List; +@Internal +@Deprecated public class PreRecipeViewingScreen extends Screen { private static final Identifier IDENTIFIER = new Identifier("roughlyenoughitems", "textures/gui/screenshot.png"); @@ -96,9 +99,9 @@ public class PreRecipeViewingScreen extends Screen { } }); this.widgets.add(new ScreenTypeSelection(width / 2 - 200 - 5, height / 2 - 112 / 2 - 10, 0)); - this.widgets.add(new LabelWidget(new Point(width / 2 - 200 - 5 + 104, height / 2 - 112 / 2 + 115), I18n.translate("config.roughlyenoughitems.recipeScreenType.original")).noShadow().color(-1124073473)); + this.widgets.add(LabelWidget.create(new Point(width / 2 - 200 - 5 + 104, height / 2 - 112 / 2 + 115), I18n.translate("config.roughlyenoughitems.recipeScreenType.original")).noShadow().color(-1124073473)); this.widgets.add(new ScreenTypeSelection(width / 2 + 5, height / 2 - 112 / 2 - 10, 112)); - this.widgets.add(new LabelWidget(new Point(width / 2 + 5 + 104, height / 2 - 112 / 2 + 115), I18n.translate("config.roughlyenoughitems.recipeScreenType.villager")).noShadow().color(-1124073473)); + this.widgets.add(LabelWidget.create(new Point(width / 2 + 5 + 104, height / 2 - 112 / 2 + 115), I18n.translate("config.roughlyenoughitems.recipeScreenType.villager")).noShadow().color(-1124073473)); this.children.addAll(widgets); } diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 7347c0694..e4fa346be 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -11,6 +11,7 @@ import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.*; +import me.shedaniel.rei.api.annotations.Internal; import me.shedaniel.rei.gui.widget.*; import me.shedaniel.rei.impl.ScreenHelper; import me.shedaniel.rei.utils.CollectionUtils; @@ -30,6 +31,8 @@ import javax.annotation.Nullable; import java.util.*; import java.util.function.Supplier; +@Deprecated +@Internal public class RecipeViewingScreen extends Screen { public static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); @@ -359,7 +362,7 @@ public class RecipeViewingScreen extends Screen { public static class WorkstationSlotWidget extends EntryWidget { public WorkstationSlotWidget(int x, int y, List<EntryStack> widgets) { - super(x, y); + super(new Point(x, y)); entries(widgets); noBackground(); } diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index b49b1f50b..f12f7e8d1 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -14,6 +14,7 @@ import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.*; +import me.shedaniel.rei.api.annotations.Internal; import me.shedaniel.rei.gui.entries.RecipeEntry; import me.shedaniel.rei.gui.widget.*; import me.shedaniel.rei.impl.ScreenHelper; @@ -37,6 +38,8 @@ import java.util.List; import java.util.Map; import java.util.Optional; +@Deprecated +@Internal public class VillagerRecipeViewingScreen extends Screen { private int tabsPerPage = 8; diff --git a/src/main/java/me/shedaniel/rei/gui/credits/CreditsEntryListWidget.java b/src/main/java/me/shedaniel/rei/gui/credits/CreditsEntryListWidget.java index 6c8248788..e76c9294e 100644 --- a/src/main/java/me/shedaniel/rei/gui/credits/CreditsEntryListWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/credits/CreditsEntryListWidget.java @@ -11,13 +11,13 @@ import net.minecraft.client.gui.DrawableHelper; import net.minecraft.text.Text; public class CreditsEntryListWidget extends DynamicNewSmoothScrollingEntryListWidget<CreditsEntryListWidget.CreditsItem> { - + private boolean inFocus; - + public CreditsEntryListWidget(MinecraftClient client, int width, int height, int startY, int endY) { super(client, width, height, startY, endY, DrawableHelper.BACKGROUND_LOCATION); } - + @Override public boolean changeFocus(boolean boolean_1) { if (!this.inFocus && this.getItemCount() == 0) { @@ -29,58 +29,58 @@ public class CreditsEntryListWidget extends DynamicNewSmoothScrollingEntryListWi } else if (this.inFocus && this.getFocused() != null) { this.moveSelection(0); } - + return this.inFocus; } } - + public void creditsClearEntries() { clearItems(); } - + private CreditsItem rei_getEntry(int int_1) { return this.children().get(int_1); } - + public void creditsAddEntry(CreditsItem entry) { addItem(entry); } - + @Override public int getItemWidth() { return width - 80; } - + @Override protected int getScrollbarPosition() { return width - 40; } - + public static class CreditsItem extends DynamicNewSmoothScrollingEntryListWidget.Entry<CreditsItem> { private String text; - + public CreditsItem(Text textComponent) { this(textComponent.asFormattedString()); } - + public CreditsItem(String text) { this.text = text; } - + @Override public void render(int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { MinecraftClient.getInstance().textRenderer.drawWithShadow(text, x + 5, y + 5, -1); } - + @Override public int getItemHeight() { return 12; } - + @Override public boolean changeFocus(boolean boolean_1) { return false; } } - + } diff --git a/src/main/java/me/shedaniel/rei/gui/toast/CopyRecipeIdentifierToast.java b/src/main/java/me/shedaniel/rei/gui/toast/CopyRecipeIdentifierToast.java index 18cf9f54e..7169e13d6 100644 --- a/src/main/java/me/shedaniel/rei/gui/toast/CopyRecipeIdentifierToast.java +++ b/src/main/java/me/shedaniel/rei/gui/toast/CopyRecipeIdentifierToast.java @@ -14,21 +14,21 @@ import net.minecraft.util.Identifier; import javax.annotation.Nullable; public class CopyRecipeIdentifierToast implements Toast { - + protected static final Identifier TOASTS_TEX = new Identifier("roughlyenoughitems", "textures/gui/toasts.png"); private String title; private String subtitle; private long startTime; - + public CopyRecipeIdentifierToast(String title, @Nullable String subtitleNullable) { this.title = title; this.subtitle = subtitleNullable; } - + public static void addToast(String title, @Nullable String subtitleNullable) { MinecraftClient.getInstance().getToastManager().add(new CopyRecipeIdentifierToast(title, subtitleNullable)); } - + @Override public Visibility draw(ToastManager toastManager, long var2) { toastManager.getGame().getTextureManager().bindTexture(TOASTS_TEX); @@ -40,17 +40,17 @@ public class CopyRecipeIdentifierToast implements Toast { toastManager.getGame().textRenderer.draw(this.title, 18.0F, 7.0F, 11141120); toastManager.getGame().textRenderer.draw(this.subtitle, 18.0F, 18.0F, -16777216); } - + return var2 - this.startTime < 5000L ? Visibility.SHOW : Visibility.HIDE; } - + @Override public Object getType() { return Type.THIS_IS_SURE_A_TYPE; } - + public enum Type { THIS_IS_SURE_A_TYPE } - + } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java index d425b9376..0fe31025b 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java @@ -11,6 +11,7 @@ import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.*; +import me.shedaniel.rei.api.annotations.Internal; import me.shedaniel.rei.gui.toast.CopyRecipeIdentifierToast; import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.client.MinecraftClient; @@ -27,6 +28,8 @@ import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; +@Internal +@Deprecated public class AutoCraftingButtonWidget extends ButtonWidget { private static final Lazy<Boolean> IS_YOG = new Lazy(() -> { diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java index 315f272a6..2599e906e 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java @@ -9,6 +9,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; import me.shedaniel.rei.api.ConfigObject; +import me.shedaniel.rei.api.annotations.Internal; import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.client.gui.Element; import net.minecraft.client.sound.PositionedSoundInstance; @@ -22,6 +23,8 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +@Internal +@Deprecated public abstract class ButtonWidget extends WidgetWithBounds { protected static final Identifier BUTTON_LOCATION = new Identifier("roughlyenoughitems", "textures/gui/button.png"); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ClickableActionedLabelWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ClickableActionedLabelWidget.java new file mode 100644 index 000000000..85adca39e --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/widget/ClickableActionedLabelWidget.java @@ -0,0 +1,27 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.gui.widget; + +import me.shedaniel.math.api.Point; +import me.shedaniel.rei.api.annotations.Internal; + +import java.util.function.Consumer; + +@Deprecated +@Internal +public class ClickableActionedLabelWidget extends ClickableLabelWidget { + private Consumer<ClickableLabelWidget> onClicked; + + ClickableActionedLabelWidget(Point point, String text, Consumer<ClickableLabelWidget> onClicked) { + super(point, text); + this.onClicked = onClicked; + } + + @Override + public void onLabelClicked() { + onClicked.accept(this); + } +} diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ClickableLabelWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ClickableLabelWidget.java index 53effc029..f6304a985 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ClickableLabelWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ClickableLabelWidget.java @@ -8,8 +8,6 @@ package me.shedaniel.rei.gui.widget; import me.shedaniel.math.api.Point; import me.shedaniel.rei.impl.ScreenHelper; -import java.util.Optional; - public abstract class ClickableLabelWidget extends LabelWidget { public boolean focused; @@ -32,6 +30,7 @@ public abstract class ClickableLabelWidget extends LabelWidget { clickable(clickable); } + @Deprecated public ClickableLabelWidget(Point point, String text) { super(point, text); this.hoveredColor = ScreenHelper.isDarkModeEnabled() ? -1 : 0xFF66FFCC; @@ -69,11 +68,16 @@ public abstract class ClickableLabelWidget extends LabelWidget { else font.draw(getText(), pos.x, pos.y, color); } - if (isClickable() && getTooltips().isPresent()) + drawTooltips(mouseX, mouseY); + } + + @Override + protected void drawTooltips(int mouseX, int mouseY) { + if (getTooltips().isPresent()) if (!focused && containsMouse(mouseX, mouseY)) ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(getTooltips().get().split("\n"))); else if (focused) - ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(pos, getTooltips().get().split("\n"))); + ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(getPosition(), getTooltips().get().split("\n"))); } public int getHoveredColor() { @@ -89,10 +93,6 @@ public abstract class ClickableLabelWidget extends LabelWidget { return false; } - public Optional<String> getTooltips() { - return Optional.empty(); - } - @Override public boolean keyPressed(int int_1, int int_2, int int_3) { if (!isClickable() || !focused) |
