aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/gui/widget
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-01-11 17:16:53 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-01-11 17:16:53 +0800
commit77ff77003ff31dabda47388ca2d9727a185b90f8 (patch)
tree73f735d0bfd3a386f0f6551cbc02675ea43206d4 /src/main/java/me/shedaniel/rei/gui/widget
parentdef24dd1d0ebd6e12a3a459ece05c0fc94aae4de (diff)
downloadRoughlyEnoughItems-77ff77003ff31dabda47388ca2d9727a185b90f8.tar.gz
RoughlyEnoughItems-77ff77003ff31dabda47388ca2d9727a185b90f8.tar.bz2
RoughlyEnoughItems-77ff77003ff31dabda47388ca2d9727a185b90f8.zip
Crafting Display
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui/widget')
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java2
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java7
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java36
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java51
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java9
5 files changed, 96 insertions, 9 deletions
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<ItemStack> 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<IWidget> 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<IWidget> widgets;
private List<TabWidget> 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
@@ -200,6 +230,14 @@ public class RecipeViewingWidget extends Gui {
}
@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())
if (entry.mouseClicked(double_1, double_2, int_1)) {
@@ -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();