aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-05-21 20:07:11 +0800
committershedaniel <daniel@shedaniel.me>2022-05-21 20:07:11 +0800
commite3ee348765d229b3d33e77dc896a21162861d6a2 (patch)
tree383cd56093aa58fd6fe390d2a0172b1d6980b188
parent4960d84012b2512bd1ef39491d8a891bc910876e (diff)
downloadRoughlyEnoughItems-e3ee348765d229b3d33e77dc896a21162861d6a2.tar.gz
RoughlyEnoughItems-e3ee348765d229b3d33e77dc896a21162861d6a2.tar.bz2
RoughlyEnoughItems-e3ee348765d229b3d33e77dc896a21162861d6a2.zip
Add way to interact with the saved display
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayedEntryWidget.java17
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java187
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/ButtonWidget.java28
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListStackEntry.java84
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java151
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayHistoryWidget.java29
10 files changed, 345 insertions, 163 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 09d43c2a1..6070fc06a 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
@@ -269,7 +269,7 @@ public class ClientHelperImpl implements ClientHelper {
}
@ApiStatus.Internal
- public void openRecipeViewingScreen(Map<DisplayCategory<?>, List<DisplaySpec>> map, @Nullable CategoryIdentifier<?> category, List<EntryStack<?>> ingredientNotice, List<EntryStack<?>> resultNotice) {
+ public void openDisplayViewingScreen(Map<DisplayCategory<?>, List<DisplaySpec>> map, @Nullable CategoryIdentifier<?> category, List<EntryStack<?>> ingredientNotice, List<EntryStack<?>> resultNotice) {
LegacyWrapperViewSearchBuilder builder = new LegacyWrapperViewSearchBuilder(map);
for (EntryStack<?> stack : ingredientNotice) {
builder.addInputNotice(stack);
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java
index 212152aae..cafdb44be 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java
@@ -131,7 +131,7 @@ public abstract class AbstractDisplayViewingScreen extends Screen implements Dis
currentCategoryIndex--;
if (currentCategoryIndex < 0)
currentCategoryIndex = categories.size() - 1;
- ClientHelperImpl.getInstance().openRecipeViewingScreen(categoryMap, categories.get(currentCategoryIndex).getCategoryIdentifier(), ingredientStackToNotice, resultStackToNotice);
+ ClientHelperImpl.getInstance().openDisplayViewingScreen(categoryMap, categories.get(currentCategoryIndex).getCategoryIdentifier(), ingredientStackToNotice, resultStackToNotice);
}
@Override
@@ -140,7 +140,7 @@ public abstract class AbstractDisplayViewingScreen extends Screen implements Dis
currentCategoryIndex++;
if (currentCategoryIndex >= categories.size())
currentCategoryIndex = 0;
- ClientHelperImpl.getInstance().openRecipeViewingScreen(categoryMap, categories.get(currentCategoryIndex).getCategoryIdentifier(), ingredientStackToNotice, resultStackToNotice);
+ ClientHelperImpl.getInstance().openDisplayViewingScreen(categoryMap, categories.get(currentCategoryIndex).getCategoryIdentifier(), ingredientStackToNotice, resultStackToNotice);
}
protected void transformIngredientNotice(List<Widget> setupDisplay, List<EntryStack<?>> noticeStacks) {
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java
index 1613d7f18..2cf0c9ac4 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java
@@ -203,7 +203,7 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
if (widget.selected)
return false;
- ClientHelperImpl.getInstance().openRecipeViewingScreen(categoryMap, tabCategory.getCategoryIdentifier(), ingredientStackToNotice, resultStackToNotice);
+ ClientHelperImpl.getInstance().openDisplayViewingScreen(categoryMap, tabCategory.getCategoryIdentifier(), ingredientStackToNotice, resultStackToNotice);
return true;
}));
tab.setRenderer(tabCategory, tabCategory.getIcon(), tabCategory.getTitle(), j == selectedCategoryIndex);
@@ -306,7 +306,7 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen
else if (amount > 0) selectedCategoryIndex--;
if (selectedCategoryIndex < 0) selectedCategoryIndex = categories.size() - 1;
else if (selectedCategoryIndex >= categories.size()) selectedCategoryIndex = 0;
- ClientHelperImpl.getInstance().openRecipeViewingScreen(categoryMap, categories.get(selectedCategoryIndex).getCategoryIdentifier(), ingredientStackToNotice, resultStackToNotice);
+ ClientHelperImpl.getInstance().openDisplayViewingScreen(categoryMap, categories.get(selectedCategoryIndex).getCategoryIdentifier(), ingredientStackToNotice, resultStackToNotice);
return true;
}
if (bounds.contains(PointHelper.ofMouse())) {
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java
index c2f49fb6a..bc9339ba7 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java
@@ -239,7 +239,7 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen {
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
if (widget.getId() + categoryPages * tabsPerPage == selectedCategoryIndex)
return false;
- ClientHelperImpl.getInstance().openRecipeViewingScreen(categoryMap, categories.get(widget.getId() + categoryPages * tabsPerPage).getCategoryIdentifier(), ingredientStackToNotice, resultStackToNotice);
+ ClientHelperImpl.getInstance().openDisplayViewingScreen(categoryMap, categories.get(widget.getId() + categoryPages * tabsPerPage).getCategoryIdentifier(), ingredientStackToNotice, resultStackToNotice);
return true;
}));
tab.setRenderer(categories.get(tabIndex), categories.get(tabIndex).getIcon(), categories.get(tabIndex).getTitle(), tab.getId() + categoryPages * tabsPerPage == selectedCategoryIndex);
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayedEntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayedEntryWidget.java
index 2dbc66f93..867e3002f 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayedEntryWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayedEntryWidget.java
@@ -60,21 +60,6 @@ public abstract class DisplayedEntryWidget extends EntryWidget {
}
@Override
- public boolean mouseReleased(double mouseX, double mouseY, int button) {
- if (!interactable)
- return super.mouseReleased(mouseX, mouseY, button);
- if (containsMouse(mouseX, mouseY)) {
- if (wasClicked()) {
- if (doAction(mouseX, mouseY, button)) {
- return true;
- } else {
- wasClicked = true;
- }
- }
- }
- return super.mouseReleased(mouseX, mouseY, button);
- }
-
protected boolean doAction(double mouseX, double mouseY, int button) {
if (!(ClientHelper.getInstance().isCheating() && !(Minecraft.getInstance().screen instanceof DisplayScreen))) return false;
EntryStack<?> entry = getCurrentEntry().copy();
@@ -88,7 +73,7 @@ public abstract class DisplayedEntryWidget extends EntryWidget {
return ClientHelper.getInstance().tryCheatingEntry(entry);
}
- return false;
+ return super.doAction(mouseX, mouseY, button);
}
@Override
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java
index db4fb921c..1628c9670 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java
@@ -32,6 +32,7 @@ import me.shedaniel.clothconfig2.api.animator.ValueAnimator;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.math.impl.PointHelper;
+import me.shedaniel.rei.api.client.ClientHelper;
import me.shedaniel.rei.api.client.REIRuntime;
import me.shedaniel.rei.api.client.config.ConfigManager;
import me.shedaniel.rei.api.client.config.ConfigObject;
@@ -40,22 +41,34 @@ import me.shedaniel.rei.api.client.gui.drag.DraggableStack;
import me.shedaniel.rei.api.client.gui.drag.DraggableStackProviderWidget;
import me.shedaniel.rei.api.client.gui.drag.DraggedAcceptorResult;
import me.shedaniel.rei.api.client.gui.drag.DraggingContext;
+import me.shedaniel.rei.api.client.gui.screen.DisplayScreen;
import me.shedaniel.rei.api.client.gui.widgets.Slot;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
+import me.shedaniel.rei.api.client.overlay.ScreenOverlay;
+import me.shedaniel.rei.api.client.registry.display.DisplayRegistry;
+import me.shedaniel.rei.api.client.registry.transfer.TransferHandler;
import me.shedaniel.rei.api.client.view.ViewSearchBuilder;
+import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.plugins.PluginManager;
import me.shedaniel.rei.impl.client.REIRuntimeImpl;
import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl;
import me.shedaniel.rei.impl.client.gui.widget.favorites.FavoritesListWidget;
+import me.shedaniel.rei.impl.client.view.ViewsImpl;
import net.minecraft.ChatFormatting;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
+import net.minecraft.Util;
+import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.resources.language.I18n;
+import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
+import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.Mth;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
@@ -83,6 +96,9 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget {
public ResourceLocation tagMatch;
public boolean removeTagMatch = true;
+ private long lastCheckTime = -1;
+ private Display display;
+
public EntryWidget(Point point) {
this(new Rectangle(point.x - 1, point.y - 1, 18, 18));
}
@@ -278,6 +294,49 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget {
return new Rectangle(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2);
}
+ @Nullable
+ private TransferHandler _getTransferHandler() {
+ lastCheckTime = Util.getMillis();
+
+ for (List<Display> displays : DisplayRegistry.getInstance().getAll().values()) {
+ for (Display display : displays) {
+ if (ViewsImpl.isRecipesFor(getEntries(), display)) {
+ AutoCraftingEvaluator.AutoCraftingResult result = AutoCraftingEvaluator.evaluateAutoCrafting(false, false, display, null);
+ if (result.successful) {
+ this.display = display;
+ return result.successfulHandler;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private TransferHandler getTransferHandler() {
+ if (PluginManager.areAnyReloading()) {
+ return null;
+ }
+
+ if (display != null) {
+ if (ViewsImpl.isRecipesFor(getEntries(), display)) {
+ AutoCraftingEvaluator.AutoCraftingResult result = AutoCraftingEvaluator.evaluateAutoCrafting(false, false, display, null);
+ if (result.successful) {
+ return result.successfulHandler;
+ }
+ }
+
+ display = null;
+ lastCheckTime = -1;
+ }
+
+ if (lastCheckTime != -1 && Util.getMillis() - lastCheckTime < 2000) {
+ return null;
+ }
+
+ return _getTransferHandler();
+ }
+
@Override
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
drawBackground(matrices, mouseX, mouseY, delta);
@@ -353,7 +412,14 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget {
@Override
@Nullable
public Tooltip getCurrentTooltip(me.shedaniel.math.Point point) {
- return getCurrentEntry().getTooltip(point);
+ Tooltip tooltip = getCurrentEntry().getTooltip(point);
+
+ if (tooltip != null && !ClientHelper.getInstance().isCheating() && getTransferHandler() != null
+ && !(Minecraft.getInstance().screen instanceof DisplayScreen)) {
+ tooltip.add(new TranslatableComponent("text.auto_craft.move_items.tooltip").withStyle(ChatFormatting.YELLOW));
+ }
+
+ return tooltip;
}
private final NumberAnimator<Float> darkHighlightedAlpha = ValueAnimator.ofFloat()
@@ -409,30 +475,62 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget {
if (!interactable)
return false;
if (wasClicked() && containsMouse(mouseX, mouseY)) {
- if (interactableFavorites && ConfigObject.getInstance().isFavoritesEnabled() && containsMouse(PointHelper.ofMouse()) && !getCurrentEntry().isEmpty()) {
- ModifierKeyCode keyCode = ConfigObject.getInstance().getFavoriteKeyCode();
- if (keyCode.matchesMouse(button)) {
- FavoriteEntry favoriteEntry = asFavoriteEntry();
- if (favoriteEntry != null) {
- if (reverseFavoritesAction())
- ConfigObject.getInstance().getFavoriteEntries().remove(favoriteEntry);
- else {
- ConfigObject.getInstance().getFavoriteEntries().remove(favoriteEntry);
- ConfigObject.getInstance().getFavoriteEntries().add(favoriteEntry);
+ if (doAction(mouseX, mouseY, button)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected boolean doAction(double mouseX, double mouseY, int button) {
+ if (interactableFavorites && ConfigObject.getInstance().isFavoritesEnabled() && containsMouse(PointHelper.ofMouse()) && !getCurrentEntry().isEmpty()) {
+ ModifierKeyCode keyCode = ConfigObject.getInstance().getFavoriteKeyCode();
+ if (keyCode.matchesMouse(button)) {
+ FavoriteEntry favoriteEntry = asFavoriteEntry();
+ if (favoriteEntry != null) {
+ if (reverseFavoritesAction())
+ ConfigObject.getInstance().getFavoriteEntries().remove(favoriteEntry);
+ else {
+ ConfigObject.getInstance().getFavoriteEntries().remove(favoriteEntry);
+ ConfigObject.getInstance().getFavoriteEntries().add(favoriteEntry);
+ }
+ ConfigManager.getInstance().saveConfig();
+ FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget();
+ if (favoritesListWidget != null)
+ favoritesListWidget.updateSearch();
+ return true;
+ }
+ }
+ }
+
+ if (!ClientHelper.getInstance().isCheating() && !(Minecraft.getInstance().screen instanceof DisplayScreen) && Screen.hasControlDown()) {
+ try {
+ TransferHandler handler = getTransferHandler();
+
+ if (handler != null) {
+ AbstractContainerScreen<?> containerScreen = REIRuntime.getInstance().getPreviousContainerScreen();
+ TransferHandler.Context context = TransferHandler.Context.create(true, Screen.hasShiftDown() || button == 1, containerScreen, display);
+ TransferHandler.Result transferResult = handler.handle(context);
+
+ if (transferResult.isBlocking()) {
+ minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
+ if (transferResult.isReturningToScreen() && Minecraft.getInstance().screen != containerScreen) {
+ Minecraft.getInstance().setScreen(containerScreen);
+ REIRuntime.getInstance().getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay);
}
- ConfigManager.getInstance().saveConfig();
- FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget();
- if (favoritesListWidget != null)
- favoritesListWidget.updateSearch();
return true;
}
}
+ } catch (Throwable e) {
+ e.printStackTrace();
}
- if ((ConfigObject.getInstance().getRecipeKeybind().getType() != InputConstants.Type.MOUSE && button == 0) || ConfigObject.getInstance().getRecipeKeybind().matchesMouse(button))
- return ViewSearchBuilder.builder().addRecipesFor(getCurrentEntry()).open();
- else if ((ConfigObject.getInstance().getUsageKeybind().getType() != InputConstants.Type.MOUSE && button == 1) || ConfigObject.getInstance().getUsageKeybind().matchesMouse(button))
- return ViewSearchBuilder.builder().addUsagesFor(getCurrentEntry()).open();
}
+
+ if ((ConfigObject.getInstance().getRecipeKeybind().getType() != InputConstants.Type.MOUSE && button == 0) || ConfigObject.getInstance().getRecipeKeybind().matchesMouse(button))
+ return ViewSearchBuilder.builder().addRecipesFor(getCurrentEntry()).open();
+ else if ((ConfigObject.getInstance().getUsageKeybind().getType() != InputConstants.Type.MOUSE && button == 1) || ConfigObject.getInstance().getUsageKeybind().matchesMouse(button))
+ return ViewSearchBuilder.builder().addUsagesFor(getCurrentEntry()).open();
+
return false;
}
@@ -458,34 +556,39 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget {
}
@Override
- public boolean keyPressed(int int_1, int int_2, int int_3) {
- if (!interactable)
- return false;
+ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (containsMouse(PointHelper.ofMouse())) {
- if (interactableFavorites && ConfigObject.getInstance().isFavoritesEnabled() && containsMouse(PointHelper.ofMouse()) && !getCurrentEntry().isEmpty()) {
- ModifierKeyCode keyCode = ConfigObject.getInstance().getFavoriteKeyCode();
- if (keyCode.matchesKey(int_1, int_2)) {
- FavoriteEntry favoriteEntry = asFavoriteEntry();
- if (favoriteEntry != null) {
- if (reverseFavoritesAction())
- ConfigObject.getInstance().getFavoriteEntries().remove(favoriteEntry);
- else {
- ConfigObject.getInstance().getFavoriteEntries().remove(favoriteEntry);
- ConfigObject.getInstance().getFavoriteEntries().add(favoriteEntry);
- }
- ConfigManager.getInstance().saveConfig();
- FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget();
- if (favoritesListWidget != null)
- favoritesListWidget.updateSearch();
- return true;
+ return keyPressedIgnoreContains(keyCode, scanCode, modifiers);
+ }
+
+ return false;
+ }
+
+ public boolean keyPressedIgnoreContains(int keyCode, int scanCode, int modifiers) {
+ if (!interactable) return false;
+
+ if (interactableFavorites && ConfigObject.getInstance().isFavoritesEnabled() && containsMouse(PointHelper.ofMouse()) && !getCurrentEntry().isEmpty()) {
+ if (ConfigObject.getInstance().getFavoriteKeyCode().matchesKey(keyCode, scanCode)) {
+ FavoriteEntry favoriteEntry = asFavoriteEntry();
+ if (favoriteEntry != null) {
+ if (reverseFavoritesAction())
+ ConfigObject.getInstance().getFavoriteEntries().remove(favoriteEntry);
+ else {
+ ConfigObject.getInstance().getFavoriteEntries().remove(favoriteEntry);
+ ConfigObject.getInstance().getFavoriteEntries().add(favoriteEntry);
}
+ ConfigManager.getInstance().saveConfig();
+ FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget();
+ if (favoritesListWidget != null)
+ favoritesListWidget.updateSearch();
+ return true;
}
}
- if (ConfigObject.getInstance().getRecipeKeybind().matchesKey(int_1, int_2))
- return ViewSearchBuilder.builder().addRecipesFor(getCurrentEntry()).open();
- else if (ConfigObject.getInstance().getUsageKeybind().matchesKey(int_1, int_2))
- return ViewSearchBuilder.builder().addUsagesFor(getCurrentEntry()).open();
}
+ if (ConfigObject.getInstance().getRecipeKeybind().matchesKey(keyCode, scanCode))
+ return ViewSearchBuilder.builder().addRecipesFor(getCurrentEntry()).open();
+ else if (ConfigObject.getInstance().getUsageKeybind().matchesKey(keyCode, scanCode))
+ return ViewSearchBuilder.builder().addUsagesFor(getCurrentEntry()).open();
return false;
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/ButtonWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/ButtonWidget.java
index 3ed9e3016..f6d495e13 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/ButtonWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/ButtonWidget.java
@@ -27,6 +27,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import me.shedaniel.clothconfig2.api.animator.ValueAnimator;
+import me.shedaniel.clothconfig2.api.animator.ValueProvider;
import me.shedaniel.math.Color;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
@@ -71,12 +72,14 @@ public class ButtonWidget extends Button {
@Nullable
private BiFunction<Button, Point, Integer> textureIdFunction;
private final ValueAnimator<Color> darkBackground;
+ private ValueProvider<Double> alpha;
public ButtonWidget(Rectangle rectangle, Component text) {
this.bounds = new Rectangle(Objects.requireNonNull(rectangle));
this.text = Objects.requireNonNull(text);
this.darkBackground = ValueAnimator.ofColor()
.withConvention(() -> Color.ofTransparent(REIRuntime.getInstance().isDarkThemeEnabled() ? 0xFFFFFFFF : 0x00FFFFFF), ValueAnimator.typicalTransitionTime());
+ this.alpha = ValueProvider.constant(1.0);
}
@Override
@@ -150,6 +153,10 @@ public class ButtonWidget extends Button {
this.focusable = focusable;
}
+ public void setAlpha(ValueProvider<Double> alpha) {
+ this.alpha = alpha;
+ }
+
@Override
@Nullable
public final Component[] getTooltip() {
@@ -196,24 +203,31 @@ public class ButtonWidget extends Button {
@Override
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
darkBackground.update(delta);
+ alpha.update(delta);
if (onRender != null) {
onRender.accept(matrices, this);
}
int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height;
- renderBackground(matrices, x, y, width, height, this.getTextureId(new Point(mouseX, mouseY)), false, Color.ofTransparent(0xFFFFFFFF));
- renderBackground(matrices, x, y, width, height, this.getTextureId(new Point(mouseX, mouseY)), true, darkBackground.value());
+ int alphaAsInt = (int) (alpha.value() * 255);
+ renderBackground(matrices, x, y, width, height, this.getTextureId(new Point(mouseX, mouseY)), false, Color.ofTransparent(0xFFFFFF | (alphaAsInt << 24)));
+ Color darkBackgroundColor = darkBackground.value();
+ darkBackgroundColor = Color.ofRGBA(darkBackgroundColor.getRed(), darkBackgroundColor.getGreen(), darkBackgroundColor.getBlue(), (int) Math.round(darkBackgroundColor.getAlpha() * alpha.value()));
+ renderBackground(matrices, x, y, width, height, this.getTextureId(new Point(mouseX, mouseY)), true, darkBackgroundColor);
- int color = 14737632;
+ int color = 0xe0e0e0;
if (!this.enabled) {
- color = 10526880;
+ color = 0xa0a0a0;
} else if (isFocused(mouseX, mouseY)) {
- color = 16777120;
+ color = 0xffffa0;
}
- if (tint != null)
+ if (tint != null) {
fillGradient(matrices, x + 1, y + 1, x + width - 1, y + height - 1, tint, tint);
+ }
- drawCenteredString(matrices, font, getText(), x + width / 2, y + (height - 8) / 2, color);
+ if (alphaAsInt > 10) {
+ drawCenteredString(matrices, font, getText(), x + width / 2, y + (height - 8) / 2, color | (alphaAsInt << 24));
+ }
Component[] tooltip = getTooltip();
if (tooltip != null) {
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListStackEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListStackEntry.java
index ce86740fe..015a23cc8 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListStackEntry.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListStackEntry.java
@@ -59,8 +59,6 @@ import static me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListWidget.
@SuppressWarnings("UnstableApiUsage")
public class EntryListStackEntry extends DisplayedEntryWidget {
private final EntryListWidget parent;
- private long lastCheckTime = -1;
- private Display display;
public EntryStack<?> our;
private NumberAnimator<Double> size = null;
@@ -108,86 +106,4 @@ public class EntryListStackEntry extends DisplayedEntryWidget {
public boolean containsMouse(double mouseX, double mouseY) {
return super.containsMouse(mouseX, mouseY) && parent.containsChecked(mouseX, mouseY, true);
}
-
- public TransferHandler getTransferHandler() {
- if (PluginManager.areAnyReloading()) {
- return null;
- }
-
- if (display != null) {
- if (ViewsImpl.isRecipesFor(getEntries(), display)) {
- AutoCraftingEvaluator.AutoCraftingResult result = AutoCraftingEvaluator.evaluateAutoCrafting(false, false, display, null);
- if (result.successful) {
- return result.successfulHandler;
- }
- }
-
- display = null;
- lastCheckTime = -1;
- }
-
- if (lastCheckTime != -1 && Util.getMillis() - lastCheckTime < 2000) {
- return null;
- }
-
- return _getTransferHandler();
- }
-
- @Nullable
- private TransferHandler _getTransferHandler() {
- lastCheckTime = Util.getMillis();
-
- for (List<Display> displays : DisplayRegistry.getInstance().getAll().values()) {
- for (Display display : displays) {
- if (ViewsImpl.isRecipesFor(getEntries(), display)) {
- AutoCraftingEvaluator.AutoCraftingResult result = AutoCraftingEvaluator.evaluateAutoCrafting(false, false, display, null);
- if (result.successful) {
- this.display = display;
- return result.successfulHandler;
- }
- }
- }
- }
-
- return null;
- }
-
- @Override
- @Nullable
- public Tooltip getCurrentTooltip(Point point) {
- Tooltip tooltip = super.getCurrentTooltip(point);
-
- if (tooltip != null && !ClientHelper.getInstance().isCheating() && getTransferHandler() != null) {
- tooltip.add(new TranslatableComponent("text.auto_craft.move_items.tooltip").withStyle(ChatFormatting.YELLOW));
- }
-
- return tooltip;
- }
-
- @Override
- protected boolean doAction(double mouseX, double mouseY, int button) {
- if (!ClientHelper.getInstance().isCheating() && !(Minecraft.getInstance().screen instanceof DisplayScreen) && Screen.hasControlDown()) {
- try {
- TransferHandler handler = getTransferHandler();
-
- if (handler != null) {
- AbstractContainerScreen<?> containerScreen = REIRuntime.getInstance().getPreviousContainerScreen();
- TransferHandler.Context context = TransferHandler.Context.create(true, Screen.hasShiftDown() || button == 1, containerScreen, display);
- TransferHandler.Result transferResult = handler.handle(context);
-
- if (transferResult.isBlocking()) {
- minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
- if (transferResult.isReturningToScreen() && Minecraft.getInstance().screen != containerScreen) {
- Minecraft.getInstance().setScreen(containerScreen);
- REIRuntime.getInstance().getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay);
- }
- return true;
- }
- }
- } catch (Throwable e) {
- e.printStackTrace();
- }
- }
- return super.doAction(mouseX, mouseY, button);
- }
} \ No newline at end of file
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java
index 6354bd73d..4a9bbee52 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java
@@ -24,21 +24,29 @@
package me.shedaniel.rei.impl.client.gui.widget.favorites.history;
import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.math.Vector4f;
import me.shedaniel.clothconfig2.api.LazyResettable;
import me.shedaniel.clothconfig2.api.animator.ValueAnimator;
import me.shedaniel.math.Dimension;
import me.shedaniel.math.FloatingRectangle;
+import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
-import me.shedaniel.rei.api.client.gui.widgets.Widget;
-import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds;
+import me.shedaniel.math.impl.PointHelper;
+import me.shedaniel.rei.api.client.gui.widgets.*;
import me.shedaniel.rei.api.client.registry.category.CategoryRegistry;
import me.shedaniel.rei.api.client.registry.display.DisplayCategory;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.Display;
+import me.shedaniel.rei.impl.client.ClientHelperImpl;
+import me.shedaniel.rei.impl.client.gui.widget.AutoCraftingEvaluator;
+import me.shedaniel.rei.impl.client.gui.widget.EntryWidget;
import net.minecraft.client.gui.components.events.GuiEventListener;
+import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.network.chat.TextComponent;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
public class DisplayEntry extends WidgetWithBounds {
private final LazyResettable<List<Widget>> widgets = new LazyResettable<>(this::setupWidgets);
@@ -46,6 +54,7 @@ public class DisplayEntry extends WidgetWithBounds {
private final Display display;
private final Dimension size = new Dimension(1, 1);
private final ValueAnimator<FloatingRectangle> bounds = ValueAnimator.ofFloatingRectangle();
+ private final Button plusButton;
private double xOffset = 0;
private boolean reachedStable = false;
@@ -53,6 +62,7 @@ public class DisplayEntry extends WidgetWithBounds {
this.display = display;
this.parent = parent;
this.bounds.setAs(initialBounds.getFloatingBounds());
+ this.plusButton = Widgets.createButton(new Rectangle(initialBounds.getMaxX() - 16, initialBounds.getMaxY() - 16, 10, 10), new TextComponent("+"));
}
public void markBoundsDirty() {
@@ -120,17 +130,142 @@ public class DisplayEntry extends WidgetWithBounds {
}
poses.pushPose();
- poses.translate(bounds.x, bounds.y, 0);
- if (stable && target.equals(bounds)) {
- poses.translate(