diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2019-05-08 00:55:25 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2019-05-08 00:55:25 +0800 |
| commit | a5c90bb7d4748ba2da024ce468ffeeda99bf4a0f (patch) | |
| tree | 4bcc51bdcee2dbc521d2bf74f0f913ec04485f67 /src/main/java/me/shedaniel/rei/gui | |
| parent | 5357ec90f80768b69b197161e877e3ef884650a4 (diff) | |
| download | RoughlyEnoughItems-a5c90bb7d4748ba2da024ce468ffeeda99bf4a0f.tar.gz RoughlyEnoughItems-a5c90bb7d4748ba2da024ce468ffeeda99bf4a0f.tar.bz2 RoughlyEnoughItems-a5c90bb7d4748ba2da024ce468ffeeda99bf4a0f.zip | |
start of 2.9 update beta
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui')
6 files changed, 213 insertions, 52 deletions
diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 16af460f4..c35c31a5b 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -43,16 +43,15 @@ public class RecipeViewingScreen extends Screen { public int largestWidth, largestHeight; public boolean choosePageActivated; public RecipeChoosePageWidget recipeChoosePageWidget; - private Window window; private Rectangle bounds; private RecipeCategory selectedCategory; private ButtonWidget recipeBack, recipeNext, categoryBack, categoryNext; - public RecipeViewingScreen(Window window, Map<RecipeCategory, List<RecipeDisplay>> categoriesMap) { + public RecipeViewingScreen(Map<RecipeCategory, List<RecipeDisplay>> categoriesMap) { super(new StringTextComponent("")); this.categoryPages = 0; - this.window = window; this.widgets = Lists.newArrayList(); + Window window = MinecraftClient.getInstance().window; this.bounds = new Rectangle(window.getScaledWidth() / 2 - guiWidth / 2, window.getScaledHeight() / 2 - guiHeight / 2, 176, 186); this.categoriesMap = categoriesMap; this.categories = Lists.newArrayList(); @@ -119,11 +118,11 @@ public class RecipeViewingScreen extends Screen { this.children.clear(); this.tabs.clear(); this.widgets.clear(); - this.largestWidth = window.getScaledWidth() - 100; - this.largestHeight = window.getScaledHeight() - 40; + this.largestWidth = width - 100; + this.largestHeight = height - 40; this.guiWidth = MathHelper.clamp(getCurrentDisplayed().stream().map(display -> selectedCategory.getDisplayWidth(display)).max(Integer::compareTo).orElse(150) + 30, 0, largestWidth); this.guiHeight = MathHelper.floor(MathHelper.clamp((selectedCategory.getDisplayHeight() + 7d) * (getRecipesPerPage() + 1d) + 40d, 186d, (double) largestHeight)); - this.bounds = new Rectangle(window.getScaledWidth() / 2 - guiWidth / 2, window.getScaledHeight() / 2 - guiHeight / 2, guiWidth, guiHeight); + this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - guiHeight / 2, guiWidth, guiHeight); this.page = MathHelper.clamp(page, 0, getTotalPages(selectedCategory) - 1); widgets.add(categoryBack = new ButtonWidget((int) bounds.getX() + 5, (int) bounds.getY() + 5, 12, 12, new TranslatableTextComponent("text.rei.left_arrow")) { @@ -250,7 +249,7 @@ public class RecipeViewingScreen extends Screen { return false; } }); - tab.setItem(categories.get(j).getCategoryIcon(), categories.get(j).getCategoryName(), tab.getId() + categoryPages * 6 == categories.indexOf(selectedCategory)); + tab.setRenderable(categories.get(j), categories.get(j).getIcon(), categories.get(j).getCategoryName(), tab.getId() + categoryPages * 6 == categories.indexOf(selectedCategory)); } } Optional<ButtonAreaSupplier> supplier = RecipeHelper.getInstance().getSpeedCraftButtonArea(selectedCategory); diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java new file mode 100644 index 000000000..8bc1d65ec --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -0,0 +1,98 @@ +package me.shedaniel.rei.gui; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.mojang.blaze3d.platform.GlStateManager; +import me.shedaniel.rei.api.RecipeCategory; +import me.shedaniel.rei.api.RecipeDisplay; +import me.shedaniel.rei.api.RecipeHelper; +import me.shedaniel.rei.client.ScreenHelper; +import me.shedaniel.rei.gui.widget.CategoryBaseWidget; +import me.shedaniel.rei.gui.widget.RecipeBaseWidget; +import me.shedaniel.rei.gui.widget.SlotBaseWidget; +import me.shedaniel.rei.gui.widget.Widget; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.Screen; +import net.minecraft.client.render.GuiLighting; +import net.minecraft.text.StringTextComponent; +import net.minecraft.util.math.MathHelper; + +import java.awt.*; +import java.util.List; +import java.util.Map; + +public class VillagerRecipeViewingScreen extends Screen { + + private final Map<RecipeCategory, List<RecipeDisplay>> categoryMap; + private final List<RecipeCategory> categories; + private final List<Widget> widgets; + public Rectangle bounds, scrollListBounds; + private int selectedCategoryIndex, selectedRecipeIndex; + + public VillagerRecipeViewingScreen(Map<RecipeCategory, List<RecipeDisplay>> map) { + super(new StringTextComponent("")); + this.widgets = Lists.newArrayList(); + this.categoryMap = Maps.newLinkedHashMap(); + this.selectedCategoryIndex = 0; + this.selectedRecipeIndex = 0; + this.categories = Lists.newArrayList(); + RecipeHelper.getInstance().getAllCategories().forEach(category -> { + if (map.containsKey(category)) { + categories.add(category); + categoryMap.put(category, map.get(category)); + } + }); + } + + @Override + protected void init() { + super.init(); + this.children.clear(); + this.widgets.clear(); + int largestWidth = width - 100; + int largestHeight = height - 40; + RecipeCategory category = categories.get(selectedCategoryIndex); + RecipeDisplay display = categoryMap.get(category).get(selectedRecipeIndex); + int guiWidth = MathHelper.clamp(category.getDisplayWidth(display) + 30, 0, largestWidth) + 100; + int guiHeight = MathHelper.clamp(category.getDisplayHeight() + 40, 166, largestHeight); + this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - guiHeight / 2, guiWidth, guiHeight); + this.widgets.add(new CategoryBaseWidget(bounds)); + this.scrollListBounds = new Rectangle(bounds.x + 4, bounds.y + 17, 97, guiHeight - 17 - 7); + this.widgets.add(new SlotBaseWidget(scrollListBounds)); + Rectangle recipeBounds = new Rectangle(bounds.x + 100 + (guiWidth - 100) / 2 - category.getDisplayWidth(display) / 2, bounds.y + bounds.height / 2 - category.getDisplayHeight() / 2, category.getDisplayWidth(display), category.getDisplayHeight()); + this.widgets.addAll(category.setupDisplay(() -> display, recipeBounds)); + this.children.addAll(widgets); + this.children.add(ScreenHelper.getLastOverlay(true, false)); + } + + @Override + public void render(int mouseX, int mouseY, float delta) { + this.fillGradient(0, 0, this.width, this.height, -1072689136, -804253680); + this.widgets.forEach(widget -> { + GuiLighting.disable(); + widget.render(mouseX, mouseY, delta); + }); + GuiLighting.disable(); + ScreenHelper.getLastOverlay().render(mouseX, mouseY, delta); + GlStateManager.pushMatrix(); + GlStateManager.translatef((float) bounds.x, (float) bounds.y, 0.0F); + GuiLighting.disable(); + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + String categoryName = categories.get(selectedCategoryIndex).getCategoryName(); + font.draw(categoryName, 4 + scrollListBounds.width / 2 - font.getStringWidth(categoryName) / 2, 6, 4210752); + GlStateManager.popMatrix(); + GuiLighting.disable(); + ScreenHelper.getLastOverlay().lateRender(mouseX, mouseY, delta); + } + + @Override + public boolean keyPressed(int int_1, int int_2, int int_3) { + if ((int_1 == 256 || this.minecraft.options.keyInventory.matchesKey(int_1, int_2)) && this.shouldCloseOnEsc()) { + MinecraftClient.getInstance().openScreen(ScreenHelper.getLastContainerScreen()); + ScreenHelper.getLastOverlay().init(); + return true; + } + return super.keyPressed(int_1, int_2, int_3); + } + +} diff --git a/src/main/java/me/shedaniel/rei/gui/renderables/ItemStackRenderable.java b/src/main/java/me/shedaniel/rei/gui/renderables/ItemStackRenderable.java new file mode 100644 index 000000000..c3904357d --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/renderables/ItemStackRenderable.java @@ -0,0 +1,33 @@ +package me.shedaniel.rei.gui.renderables; + +import com.mojang.blaze3d.platform.GlStateManager; +import me.shedaniel.rei.api.Renderable; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.render.GuiLighting; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; + +public abstract class ItemStackRenderable extends DrawableHelper implements Renderable { + + public static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); + + @Override + public void render(int x, int y, double mouseX, double mouseY, float delta) { + int l = x - 8, i1 = y - 6; + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + this.blitOffset = 100; + ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer(); + itemRenderer.zOffset = 100.0F; + GuiLighting.enableForItems(); + itemRenderer.renderGuiItem(getItemStack(), l, i1); + itemRenderer.renderGuiItemOverlay(MinecraftClient.getInstance().textRenderer, getItemStack(), l, i1); + GlStateManager.disableLighting(); + itemRenderer.zOffset = 0.0F; + this.blitOffset = 0; + } + + protected abstract ItemStack getItemStack(); + +} diff --git a/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java index 57dbd5e89..a139d7d34 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java @@ -12,9 +12,9 @@ import java.util.List; public class RecipeBaseWidget extends HighlightableWidget { private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); - private static final Color INNER_COLOR = new Color(198, 198, 198); private Rectangle bounds; + protected boolean render = true; public RecipeBaseWidget(Rectangle bounds) { this.bounds = bounds; @@ -22,6 +22,14 @@ public class RecipeBaseWidget extends HighlightableWidget { throw new IllegalArgumentException("Base too small, at least 8x8!"); } + public boolean isRender() { + return render; + } + + public void setRender(boolean render) { + this.render = render; + } + @Override public Rectangle getBounds() { return bounds; @@ -38,30 +46,36 @@ public class RecipeBaseWidget extends HighlightableWidget { @Override public void render(int mouseX, int mouseY, float delta) { - GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); - GuiLighting.disable(); - minecraft.getTextureManager().bindTexture(CHEST_GUI_TEXTURE); - int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height; - int textureOffset = getTextureOffset(); - - //Four Corners - this.blit(x, y, 106, 124 + textureOffset, 4, 4); - this.blit(x + width - 4, y, 252, 124 + textureOffset, 4, 4); - this.blit(x, y + height - 4, 106, 186 + textureOffset, 4, 4); - this.blit(x + width - 4, y + height - 4, 252, 186 + textureOffset, 4, 4); - - //Sides - for(int xx = 4; xx < width - 4; xx += 128) { - int thisWidth = Math.min(128, width - 4 - xx); - this.blit(x + xx, y, 110, 124 + textureOffset, thisWidth, 4); - this.blit(x + xx, y + height - 4, 110, 186 + textureOffset, thisWidth, 4); - } - for(int yy = 4; yy < height - 4; yy += 50) { - int thisHeight = Math.min(50, height - 4 - yy); - this.blit(x, y + yy, 106, 128 + textureOffset, 4, thisHeight); - this.blit(x + width - 4, y + yy, 252, 128 + textureOffset, 4, thisHeight); + if (render) { + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + GuiLighting.disable(); + minecraft.getTextureManager().bindTexture(CHEST_GUI_TEXTURE); + int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height; + int textureOffset = getTextureOffset(); + + //Four Corners + this.blit(x, y, 106, 124 + textureOffset, 4, 4); + this.blit(x + width - 4, y, 252, 124 + textureOffset, 4, 4); + this.blit(x, y + height - 4, 106, 186 + textureOffset, 4, 4); + this.blit(x + width - 4, y + height - 4, 252, 186 + textureOffset, 4, 4); + + //Sides + for(int xx = 4; xx < width - 4; xx += 128) { + int thisWidth = Math.min(128, width - 4 - xx); + this.blit(x + xx, y, 110, 124 + textureOffset, thisWidth, 4); + this.blit(x + xx, y + height - 4, 110, 186 + textureOffset, thisWidth, 4); + } + for(int yy = 4; yy < height - 4; yy += 50) { + int thisHeight = Math.min(50, height - 4 - yy); + this.blit(x, y + yy, 106, 128 + textureOffset, 4, thisHeight); + this.blit(x + width - 4, y + yy, 252, 128 + textureOffset, 4, thisHeight); + } + fillGradient(x + 4, y + 4, x + width - 4, y + height - 4, getInnerColor(), getInnerColor()); } - fillGradient(x + 4, y + 4, x + width - 4, y + height - 4, INNER_COLOR.getRGB(), INNER_COLOR.getRGB()); + } + + protected int getInnerColor() { + return -3750202; } protected int getTextureOffset() { diff --git a/src/main/java/me/shedaniel/rei/gui/widget/SlotBaseWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/SlotBaseWidget.java new file mode 100644 index 000000000..8ab19cfd3 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/widget/SlotBaseWidget.java @@ -0,0 +1,21 @@ +package me.shedaniel.rei.gui.widget; + +import java.awt.*; + +public class SlotBaseWidget extends RecipeBaseWidget { + + public SlotBaseWidget(Rectangle bounds) { + super(bounds); + } + + @Override + public int getInnerColor() { + return -7631989; + } + + @Override + protected int getTextureOffset() { + return -66; + } + +} 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 07493792c..b86be1927 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java @@ -1,11 +1,12 @@ package me.shedaniel.rei.gui.widget; import com.mojang.blaze3d.platform.GlStateManager; +import me.shedaniel.rei.api.ClientHelper; +import me.shedaniel.rei.api.RecipeCategory; +import me.shedaniel.rei.api.Renderable; import me.shedaniel.rei.client.ScreenHelper; import me.shedaniel.rei.gui.RecipeViewingScreen; 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.*; @@ -17,28 +18,28 @@ public class TabWidget extends HighlightableWidget { public static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); public boolean shown = false, selected = false; - public ItemStack item; + public Renderable renderable; public int id; public RecipeViewingScreen recipeViewingWidget; public String categoryName; public Rectangle bounds; - private ItemRenderer itemRenderer; + public RecipeCategory category; public TabWidget(int id, RecipeViewingScreen recipeViewingWidget, Rectangle bounds) { this.id = id; this.recipeViewingWidget = recipeViewingWidget; this.bounds = bounds; - this.itemRenderer = minecraft.getItemRenderer(); } - public void setItem(ItemStack item, String categoryName, boolean selected) { - if (item == null) { + public void setRenderable(RecipeCategory category, Renderable renderable, String categoryName, boolean selected) { + if (renderable == null) { shown = false; - this.item = null; + this.renderable = null; } else { shown = true; - this.item = item; + this.renderable = renderable; } + this.category = category; this.selected = selected; this.categoryName = categoryName; } @@ -55,8 +56,8 @@ public class TabWidget extends HighlightableWidget { return shown; } - public ItemStack getItemStack() { - return item; + public Renderable getRenderable() { + return renderable; } @Override @@ -67,26 +68,21 @@ public class TabWidget extends HighlightableWidget { @Override public void render(int mouseX, int mouseY, float delta) { 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(); minecraft.getTextureManager().bindTexture(CHEST_GUI_TEXTURE); this.blit(bounds.x, bounds.y + 2, selected ? 28 : 0, 192, 28, (selected ? 30 : 27)); - this.blitOffset = 100; - this.itemRenderer.zOffset = 100.0F; - GuiLighting.enableForItems(); - this.itemRenderer.renderGuiItem(getItemStack(), l, i1); - this.itemRenderer.renderGuiItemOverlay(minecraft.textRenderer, getItemStack(), l, i1); - GlStateManager.disableLighting(); - this.itemRenderer.zOffset = 0.0F; - this.blitOffset = 0; + renderable.render((int) bounds.getCenterX(), (int) bounds.getCenterY(), mouseX, mouseY, delta); if (isHighlighted(mouseX, mouseY)) drawTooltip(); } } private void drawTooltip() { - ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(categoryName)); + if (this.minecraft.options.advancedItemTooltips) + ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(categoryName, "ยง8" + category.getIdentifier().toString(), ClientHelper.getInstance().getFormattedModFromIdentifier(category.getIdentifier()))); + else + ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(categoryName, ClientHelper.getInstance().getFormattedModFromIdentifier(category.getIdentifier()))); } @Override |
