aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-08-17 17:05:59 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-08-17 17:05:59 +0800
commit5c91a6654e697fdadde79508f3ef994936e4b952 (patch)
treec2d47385603b038dedcba893a7242bc4c04bb5b3 /src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java
parentdab398882cd64f6152078f59ba768e4ffd437ba3 (diff)
downloadRoughlyEnoughItems-5c91a6654e697fdadde79508f3ef994936e4b952.tar.gz
RoughlyEnoughItems-5c91a6654e697fdadde79508f3ef994936e4b952.tar.bz2
RoughlyEnoughItems-5c91a6654e697fdadde79508f3ef994936e4b952.zip
Finishing the auto crafting API
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java')
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java77
1 files changed, 68 insertions, 9 deletions
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 5006dedda..adcaacd8b 100644
--- a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java
+++ b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java
@@ -5,6 +5,7 @@
package me.shedaniel.rei.gui.widget;
+import com.mojang.blaze3d.platform.GlStateManager;
import me.shedaniel.rei.api.AutoTransferHandler;
import me.shedaniel.rei.api.RecipeDisplay;
import me.shedaniel.rei.api.RecipeHelper;
@@ -13,8 +14,10 @@ import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
+import net.minecraft.util.math.MathHelper;
import java.awt.*;
+import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
@@ -23,14 +26,17 @@ public class AutoCraftingButtonWidget extends ButtonWidget {
private final Supplier<RecipeDisplay> displaySupplier;
private String extraTooltip;
private String errorTooltip;
+ private List<Widget> setupDisplay;
private AbstractContainerScreen<?> containerScreen;
+ private boolean visible = false;
- public AutoCraftingButtonWidget(Rectangle rectangle, String text, Supplier<RecipeDisplay> displaySupplier) {
+ public AutoCraftingButtonWidget(Rectangle rectangle, String text, Supplier<RecipeDisplay> displaySupplier, List<Widget> setupDisplay) {
super(rectangle, text);
this.displaySupplier = () -> displaySupplier.get();
Optional<Identifier> recipe = displaySupplier.get().getRecipeLocation();
extraTooltip = recipe.isPresent() ? I18n.translate("text.rei.recipe_id", Formatting.GRAY.toString(), recipe.get().toString()) : "";
this.containerScreen = ScreenHelper.getLastContainerScreen();
+ this.setupDisplay = setupDisplay;
}
@Override
@@ -52,19 +58,72 @@ public class AutoCraftingButtonWidget extends ButtonWidget {
public void render(int mouseX, int mouseY, float delta) {
this.enabled = false;
String error = null;
+ int color = 0;
+ visible = false;
AutoTransferHandler.Context context = AutoTransferHandler.Context.create(false, containerScreen, displaySupplier.get());
for (AutoTransferHandler autoTransferHandler : RecipeHelper.getInstance().getSortedAutoCraftingHandler()) {
- AutoTransferHandler.Result result = autoTransferHandler.handle(context);
- if (result.isSuccessful()) {
- enabled = true;
- error = null;
- break;
- } else if (error == null) {
- error = result.getErrorKey();
+ try {
+ AutoTransferHandler.Result result = autoTransferHandler.handle(context);
+ if (result.isApplicable())
+ visible = true;
+ if (result.isSuccessful()) {
+ enabled = true;
+ error = null;
+ break;
+ } else if (error == null) {
+ error = result.getErrorKey();
+ color = result.getColor();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
+ if (!visible)
+ enabled = false;
errorTooltip = error;
- super.render(mouseX, mouseY, delta);
+ int x = getBounds().x, y = getBounds().y, width = getBounds().width, height = getBounds().height;
+ minecraft.getTextureManager().bindTexture(ScreenHelper.isDarkModeEnabled() ? BUTTON_LOCATION_DARK : BUTTON_LOCATION);
+ GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
+ int textureOffset = this.getTextureId(isHovered(mouseX, mouseY));
+ GlStateManager.enableBlend();
+ GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
+ GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
+ //Four Corners
+ blit(x, y, 0, textureOffset * 80, 4, 4);
+ blit(x + width - 4, y, 252, textureOffset * 80, 4, 4);
+ blit(x, y + height - 4, 0, textureOffset * 80 + 76, 4, 4);
+ blit(x + width - 4, y + height - 4, 252, textureOffset * 80 + 76, 4, 4);
+
+ //Sides
+ blit(x + 4, y, 4, textureOffset * 80, MathHelper.ceil((width - 8) / 2f), 4);
+ blit(x + 4, y + height - 4, 4, textureOffset * 80 + 76, MathHelper.ceil((width - 8) / 2f), 4);
+ blit(x + 4 + MathHelper.ceil((width - 8) / 2f), y + height - 4, 252 - MathHelper.floor((width - 8) / 2f), textureOffset * 80 + 76, MathHelper.floor((width - 8) / 2f), 4);
+ blit(x + 4 + MathHelper.ceil((width - 8) / 2f), y, 252 - MathHelper.floor((width - 8) / 2f), textureOffset * 80, MathHelper.floor((width - 8) / 2f), 4);
+ for (int i = y + 4; i < y + height - 4; i += 76) {
+ blit(x, i, 0, 4 + textureOffset * 80, MathHelper.ceil(width / 2f), MathHelper.clamp(y + height - 4 - i, 0, 76));
+ blit(x + MathHelper.ceil(width / 2f), i, 256 - MathHelper.floor(width / 2f), 4 + textureOffset * 80, MathHelper.floor(width / 2f), MathHelper.clamp(y + height - 4 - i, 0, 76));
+ }
+
+ int colour = 14737632;
+ if (!this.visible) {
+ colour = 10526880;
+ } else if (enabled && isHovered(mouseX, mouseY)) {
+ colour = 16777120;
+ }
+
+ fillGradient(x, y, x + width, y + height, color, color);
+ this.drawCenteredString(font, text, x + width / 2, y + (height - 8) / 2, colour);
+
+ 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(new Point(x + width / 2, y + height / 2), getTooltips().get().split("\n")));
+ }
+
+ @Override
+ protected int getTextureId(boolean boolean_1) {
+ return !visible ? 0 :boolean_1 && enabled ? 2 : 1;
}
@Override