From 77ff77003ff31dabda47388ca2d9727a185b90f8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 11 Jan 2019 17:16:53 +0800 Subject: Crafting Display --- .../me/shedaniel/rei/gui/ContainerGuiOverlay.java | 4 +- .../shedaniel/rei/gui/widget/ItemListOverlay.java | 2 +- .../shedaniel/rei/gui/widget/ItemSlotWidget.java | 7 +++ .../shedaniel/rei/gui/widget/RecipeBaseWidget.java | 36 +++++++++++++++ .../rei/gui/widget/RecipeViewingWidget.java | 51 +++++++++++++++++++--- .../me/shedaniel/rei/gui/widget/TabWidget.java | 9 +++- 6 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java (limited to 'src/main/java/me/shedaniel/rei/gui') diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java index 3ffd95238..643ab5849 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java @@ -81,6 +81,7 @@ public class ContainerGuiOverlay extends Gui { this.widgets.add(new LabelWidget(rectangle.x + (rectangle.width / 2), rectangle.y + 10, "") { @Override public void draw(int mouseX, int mouseY, float partialTicks) { + page = MathHelper.clamp(page, 0, getTotalPage()); this.text = String.format("%s/%s", page + 1, getTotalPage() + 1); super.draw(mouseX, mouseY, partialTicks); } @@ -148,7 +149,8 @@ public class ContainerGuiOverlay extends Gui { int width = window.getScaledWidth() - startX; if (MinecraftClient.getInstance().currentGui instanceof RecipeViewingWidget) { RecipeViewingWidget widget = (RecipeViewingWidget) MinecraftClient.getInstance().currentGui; - width = window.getScaledWidth() - (widget.getBounds().x + widget.getBounds().width + 10); + startX = widget.getBounds().x + widget.getBounds().width + 10; + width = window.getScaledWidth() - startX; } return new Rectangle(startX, 0, width, window.getScaledHeight()); } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java b/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java index 84fe47749..4398f611b 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java @@ -101,7 +101,7 @@ public class ItemListOverlay extends Drawable implements IWidget { if (button == 0) return ClientHelper.executeRecipeKeyBind(containerGuiOverlay, getCurrentStack().copy(), containerGui); else if (button == 1) - return ClientHelper.executeUsageKeyBind(); + return ClientHelper.executeUsageKeyBind(containerGuiOverlay, getCurrentStack().copy(), containerGui); } } return false; diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java index 292f5e5f5..01eee72b2 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java @@ -9,6 +9,7 @@ import net.minecraft.client.gui.Drawable; import net.minecraft.client.render.GuiLighting; import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -90,9 +91,15 @@ public class ItemSlotWidget extends Drawable implements HighlightableWidget { } protected ItemStack getCurrentStack() { + if (itemList.size() == 0) + return new ItemStack(Items.AIR); return itemList.get(MathHelper.clamp((int) (System.currentTimeMillis() / 500) % itemList.size(), 0, itemList.size() - 1)); } + public void setItemList(List itemList) { + this.itemList = itemList; + } + @Override public Rectangle getBounds() { return new Rectangle(this.x, this.y, 18, 18); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java new file mode 100644 index 000000000..4134ad510 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java @@ -0,0 +1,36 @@ +package me.shedaniel.rei.gui.widget; + +import com.mojang.blaze3d.platform.GlStateManager; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.Drawable; +import net.minecraft.client.render.GuiLighting; +import net.minecraft.util.Identifier; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +public class RecipeBaseWidget extends Drawable implements IWidget { + + private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); + + private Rectangle bounds; + + public RecipeBaseWidget(Rectangle bounds) { + this.bounds = bounds; + } + + @Override + public List getListeners() { + return new ArrayList<>(); + } + + @Override + public void draw(int mouseX, int mouseY, float partialTicks) { + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + GuiLighting.disable(); + MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE); + drawTexturedRect(bounds.x, bounds.y, 106, 190, bounds.width, bounds.height); + } + +} diff --git a/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java index 9be303102..8b6dca71e 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java @@ -27,7 +27,7 @@ public class RecipeViewingWidget extends Gui { private static final Identifier CREATIVE_INVENTORY_TABS = new Identifier("textures/gui/container/creative_inventory/tabs.png"); private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); public final int guiWidth = 176; - public final int guiHeight = 158; + public final int guiHeight = 186; private List widgets; private List tabs; @@ -84,11 +84,25 @@ public class RecipeViewingWidget extends Gui { widgets.add(categoryBack = new ButtonWidget((int) bounds.getX() + 5, (int) bounds.getY() + 5, 12, 12, "<") { @Override public void onPressed(int button, double mouseX, double mouseY) { + int currentCategoryIndex = categories.indexOf(selectedCategory); + currentCategoryIndex--; + if (currentCategoryIndex < 0) + currentCategoryIndex = categories.size() - 1; + selectedCategory = categories.get(currentCategoryIndex); + categoryPages = MathHelper.floor(currentCategoryIndex / 6d); + RecipeViewingWidget.this.onInitialized(); } }); widgets.add(categoryNext = new ButtonWidget((int) bounds.getX() + 159, (int) bounds.getY() + 5, 12, 12, ">") { @Override public void onPressed(int button, double mouseX, double mouseY) { + int currentCategoryIndex = categories.indexOf(selectedCategory); + currentCategoryIndex++; + if (currentCategoryIndex >= categories.size()) + currentCategoryIndex = 0; + selectedCategory = categories.get(currentCategoryIndex); + categoryPages = MathHelper.floor(currentCategoryIndex / 6d); + RecipeViewingWidget.this.onInitialized(); } }); categoryBack.enabled = categories.size() > 1; @@ -97,11 +111,19 @@ public class RecipeViewingWidget extends Gui { widgets.add(recipeBack = new ButtonWidget((int) bounds.getX() + 5, (int) bounds.getY() + 21, 12, 12, "<") { @Override public void onPressed(int button, double mouseX, double mouseY) { + page--; + if (page < 0) + page = getTotalPages(selectedCategory) - 1; + RecipeViewingWidget.this.onInitialized(); } }); widgets.add(recipeNext = new ButtonWidget((int) bounds.getX() + 159, (int) bounds.getY() + 21, 12, 12, ">") { @Override public void onPressed(int button, double mouseX, double mouseY) { + page++; + if (page >= getTotalPages(selectedCategory)) + page = 0; + RecipeViewingWidget.this.onInitialized(); } }); recipeBack.enabled = categoriesMap.get(selectedCategory).size() > getRecipesPerPage(); @@ -140,7 +162,15 @@ public class RecipeViewingWidget extends Gui { return false; } }); - tab.setItem(selectedCategory.getCategoryIcon(), selectedCategory.getCategoryName(), tab.getId() + categoryPages * 6 == categories.indexOf(selectedCategory)); + tab.setItem(categories.get(j).getCategoryIcon(), categories.get(j).getCategoryName(), tab.getId() + categoryPages * 6 == categories.indexOf(selectedCategory)); + } + } + if (page * getRecipesPerPage() < categoriesMap.get(selectedCategory).size()) { + IRecipeDisplay topDisplay = categoriesMap.get(selectedCategory).get(page * getRecipesPerPage()); + widgets.addAll(selectedCategory.setupDisplay(getParent(), topDisplay, new Rectangle((int) getBounds().getCenterX() - 75, getBounds().y + 40, 150, selectedCategory.usesFullPage() ? 118 : 66))); + if (!selectedCategory.usesFullPage() && page * getRecipesPerPage() + 1 < categoriesMap.get(selectedCategory).size()) { + IRecipeDisplay middleDisplay = categoriesMap.get(selectedCategory).get(page * getRecipesPerPage() + 1); + widgets.addAll(selectedCategory.setupDisplay(getParent(), middleDisplay, new Rectangle((int) getBounds().getCenterX() - 75, getBounds().y + 108, 150, 66))); } } @@ -159,7 +189,9 @@ public class RecipeViewingWidget extends Gui { @Override public void draw(int mouseX, int mouseY, float partialTicks) { drawBackground(); - tabs.stream().filter(TabWidget::isSelected).forEach(tabWidget -> tabWidget.draw(mouseX, mouseY, partialTicks)); + tabs.stream().filter(tabWidget -> { + return !tabWidget.isSelected(); + }).forEach(tabWidget -> tabWidget.draw(mouseX, mouseY, partialTicks)); GuiLighting.disable(); super.draw(mouseX, mouseY, partialTicks); widgets.forEach(widget -> { @@ -168,10 +200,8 @@ public class RecipeViewingWidget extends Gui { }); GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); GuiLighting.disable(); + tabs.stream().filter(TabWidget::isSelected).forEach(tabWidget -> tabWidget.draw(mouseX, mouseY, partialTicks)); overlay.render(mouseX, mouseY, partialTicks); - tabs.stream().filter(tabWidget -> { - return !tabWidget.isSelected(); - }).forEach(tabWidget -> tabWidget.draw(mouseX, mouseY, partialTicks)); } @Override @@ -199,6 +229,14 @@ public class RecipeViewingWidget extends Gui { return super.charTyped(char_1, int_1); } + @Override + public boolean mouseScrolled(double amount) { + for(GuiEventListener listener : listeners) + if (listener.mouseScrolled(amount)) + return true; + return super.mouseScrolled(amount); + } + @Override public boolean mouseClicked(double double_1, double double_2, int int_1) { for(GuiEventListener entry : getEntries()) @@ -210,4 +248,5 @@ public class RecipeViewingWidget extends Gui { } return false; } + } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java index d9a35c934..d8c0f44e2 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java @@ -8,6 +8,7 @@ import net.minecraft.client.gui.Drawable; import net.minecraft.client.render.GuiLighting; import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; import java.awt.*; import java.util.Arrays; @@ -15,6 +16,8 @@ import java.util.List; public class TabWidget extends Drawable implements HighlightableWidget { + private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); + private boolean shown = false, selected = false; private ItemStack item; private int id; @@ -67,9 +70,11 @@ public class TabWidget extends Drawable implements HighlightableWidget { public void draw(int mouseX, int mouseY, float partialTicks) { if (shown) { int l = (int) this.bounds.getCenterX() - 8, i1 = (int) this.bounds.getCenterY() - 6; - + + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); GuiLighting.disable(); - this.drawTexturedRect(bounds.x, bounds.y, selected ? 28 : 0, 158, 28, (selected ? 31 : 28)); + MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE); + this.drawTexturedRect(bounds.x, bounds.y + 2, selected ? 28 : 0, 192, 28, (selected ? 30 : 27)); this.zOffset = 100.0F; this.itemRenderer.zOffset = 100.0F; GuiLighting.enableForItems(); -- cgit