From cd4051b7eb9dfd200636bb9d0b41b260e36c2966 Mon Sep 17 00:00:00 2001 From: lothrazar Date: Mon, 18 Nov 2024 12:57:58 -0800 Subject: [PATCH] refactor expanded inventory texture to tileable per row records --- .../ScreenNetworkInventoryExpanded.java | 37 +++++++++++++++--- .../inventory/ScreenNetworkInventory.java | 10 ++++- .../block/request/ScreenNetworkTable.java | 12 ++++-- .../storagenetwork/gui/NetworkWidget.java | 9 ++++- .../storagenetwork/gui/TileableTexture.java | 7 ++++ .../remote/ScreenNetworkCraftingRemote.java | 7 ++++ .../item/remote/ScreenNetworkRemote.java | 7 ++++ .../gui/inventory_expanded_bottom.png | Bin 962 -> 0 bytes .../textures/gui/inventory_expanded_top.png | Bin 811 -> 0 bytes 9 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/lothrazar/storagenetwork/gui/TileableTexture.java delete mode 100644 src/main/resources/assets/storagenetwork/textures/gui/inventory_expanded_bottom.png delete mode 100644 src/main/resources/assets/storagenetwork/textures/gui/inventory_expanded_top.png diff --git a/src/main/java/com/lothrazar/storagenetwork/block/expand/ScreenNetworkInventoryExpanded.java b/src/main/java/com/lothrazar/storagenetwork/block/expand/ScreenNetworkInventoryExpanded.java index a9e4880a..aae49b6d 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/expand/ScreenNetworkInventoryExpanded.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/expand/ScreenNetworkInventoryExpanded.java @@ -5,6 +5,9 @@ import com.lothrazar.storagenetwork.block.AbstractNetworkScreen; import com.lothrazar.storagenetwork.gui.NetworkScreenSize; import com.lothrazar.storagenetwork.gui.NetworkWidget; +import com.lothrazar.storagenetwork.gui.TileableTexture; +import com.lothrazar.storagenetwork.util.SsnConsts; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; @@ -12,14 +15,18 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraftforge.fml.ModList; -public class ScreenNetworkInventoryExpanded extends AbstractNetworkScreen {//AbstractContainerScreen implements IGuiNetwork { +public class ScreenNetworkInventoryExpanded extends AbstractNetworkScreen { protected int HEIGHT = 256; public int WIDTH = 176; + //i know they could all be in the same png file and i pull out sprites from it, but split images is easier to work with + private TileableTexture head = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_head.png"), WIDTH, 10); + private TileableTexture row = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_row.png"), WIDTH, SsnConsts.SQ); + private TileableTexture crafting = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_crafting.png"), WIDTH, 58); + private TileableTexture player = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_player.png"), WIDTH, 104); + protected final NetworkWidget network; private TileInventoryExpanded tile; - private ResourceLocation top = new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/inventory_expanded_top.png"); - private ResourceLocation bot = new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/inventory_expanded_bottom.png"); public ScreenNetworkInventoryExpanded(ContainerNetworkInventoryExpanded container, Inventory inv, Component name) { super(container, inv, name); @@ -46,13 +53,33 @@ public void init() { @Override public void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY) { + //get center points from screen size int xCenter = (width - imageWidth) / 2; int yCenter = (height - imageHeight) / 2; - ms.blit(top, xCenter, yCenter - imageHeight / 2, 0, 0, imageWidth, imageHeight); - ms.blit(bot, xCenter, yCenter + imageHeight / 2, 0, imageHeight, imageWidth, imageHeight); + //render the top + int ypos = yCenter - imageHeight / 2; + ms.blit(head.texture(), xCenter, ypos, 0, 0, imageWidth, head.height()); + //render the rows + // -1 for the top header row, and pixel to math ratio of 2x + final int textureLines = (network.getLines() - 1)*2; + for(int line = 0; line < textureLines; line++) { + + ypos += head.height(); + ms.blit(row.texture(), xCenter, ypos, 0, 0, imageWidth, row.height()); + } + //render player inventory + ypos = ypos - 12; //border buffers of 8+4 overlap + ms.blit(player.texture(), xCenter, ypos, 0, imageHeight, imageWidth, imageHeight); + //update network network.applySearchTextToSlots(); network.renderItemSlots(ms, mouseX, mouseY, font); } + + @Override + public void resize(Minecraft mc, int w, int h) { + super.resize(mc,w,h); + network.resize(mc,w,h); + } // all the IGUINETWORK implementations @Override diff --git a/src/main/java/com/lothrazar/storagenetwork/block/inventory/ScreenNetworkInventory.java b/src/main/java/com/lothrazar/storagenetwork/block/inventory/ScreenNetworkInventory.java index 4226fa31..800ea417 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/inventory/ScreenNetworkInventory.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/inventory/ScreenNetworkInventory.java @@ -5,6 +5,7 @@ import com.lothrazar.storagenetwork.block.AbstractNetworkScreen; import com.lothrazar.storagenetwork.gui.NetworkScreenSize; import com.lothrazar.storagenetwork.gui.NetworkWidget; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; @@ -12,7 +13,7 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraftforge.fml.ModList; -public class ScreenNetworkInventory extends AbstractNetworkScreen {//AbstractContainerScreen implements IGuiNetwork { +public class ScreenNetworkInventory extends AbstractNetworkScreen { protected int HEIGHT = 256; public int WIDTH = 176; @@ -51,6 +52,13 @@ public void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY) network.applySearchTextToSlots(); network.renderItemSlots(ms, mouseX, mouseY, font); } + + + @Override + public void resize(Minecraft mc, int w, int h) { + super.resize(mc,w,h); + network.resize(mc,w,h); + } // all the IGUINETWORK implementations @Override diff --git a/src/main/java/com/lothrazar/storagenetwork/block/request/ScreenNetworkTable.java b/src/main/java/com/lothrazar/storagenetwork/block/request/ScreenNetworkTable.java index ca9c9c74..aa42c020 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/request/ScreenNetworkTable.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/request/ScreenNetworkTable.java @@ -5,6 +5,7 @@ import com.lothrazar.storagenetwork.block.AbstractNetworkScreen; import com.lothrazar.storagenetwork.gui.NetworkScreenSize; import com.lothrazar.storagenetwork.gui.NetworkWidget; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; @@ -12,9 +13,7 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraftforge.fml.ModList; -public class ScreenNetworkTable extends - AbstractNetworkScreen { - //AbstractContainerScreen implements IGuiNetwork { +public class ScreenNetworkTable extends AbstractNetworkScreen { private static final int HEIGHT = 256; public static final int WIDTH = 176; @@ -54,6 +53,13 @@ public void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY) network.applySearchTextToSlots(); network.renderItemSlots(ms, mouseX, mouseY, font); } + + + @Override + public void resize(Minecraft mc, int w, int h) { + super.resize(mc,w,h); + network.resize(mc,w,h); + } // all the IGUINETWORK implementations @Override diff --git a/src/main/java/com/lothrazar/storagenetwork/gui/NetworkWidget.java b/src/main/java/com/lothrazar/storagenetwork/gui/NetworkWidget.java index 00c2f1b4..f72b2759 100644 --- a/src/main/java/com/lothrazar/storagenetwork/gui/NetworkWidget.java +++ b/src/main/java/com/lothrazar/storagenetwork/gui/NetworkWidget.java @@ -156,7 +156,7 @@ public boolean canClick() { return System.currentTimeMillis() > lastClick + 100L; } - int getLines() { + public int getLines() { return lines; } @@ -452,4 +452,11 @@ public void render() { jeiBtn.setTextureId(gui.isJeiSearchSynced() ? TextureEnum.JEI_GREEN : TextureEnum.JEI_RED); } } + + public void resize(Minecraft mc, int width, int height) { + + //todo: how many rows? dynamically change size on screen resize from client + //System.out.println("resized width="+width); + // System.out.println("resized height="+height); + } } diff --git a/src/main/java/com/lothrazar/storagenetwork/gui/TileableTexture.java b/src/main/java/com/lothrazar/storagenetwork/gui/TileableTexture.java new file mode 100644 index 00000000..bf2393e2 --- /dev/null +++ b/src/main/java/com/lothrazar/storagenetwork/gui/TileableTexture.java @@ -0,0 +1,7 @@ +package com.lothrazar.storagenetwork.gui; + +import net.minecraft.resources.ResourceLocation; + +public record TileableTexture(ResourceLocation texture, int width, int height) { + +} diff --git a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java index 5368032e..32fe4a25 100644 --- a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java +++ b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java @@ -5,6 +5,7 @@ import com.lothrazar.storagenetwork.block.AbstractNetworkScreen; import com.lothrazar.storagenetwork.gui.NetworkScreenSize; import com.lothrazar.storagenetwork.gui.NetworkWidget; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -53,6 +54,12 @@ protected void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mous network.renderItemSlots(ms, mouseX, mouseY, font); } + @Override + public void resize(Minecraft mc, int w, int h) { + super.resize(mc,w,h); + network.resize(mc,w,h); + } + @Override public boolean getDownwards() { return ItemStorageCraftingRemote.getDownwards(remote); diff --git a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkRemote.java b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkRemote.java index 021ca8f6..9a096288 100644 --- a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkRemote.java +++ b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkRemote.java @@ -5,6 +5,7 @@ import com.lothrazar.storagenetwork.block.AbstractNetworkScreen; import com.lothrazar.storagenetwork.gui.NetworkScreenSize; import com.lothrazar.storagenetwork.gui.NetworkWidget; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -54,6 +55,12 @@ protected void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mous network.renderItemSlots(ms, mouseX, mouseY, font); } + @Override + public void resize(Minecraft mc, int w, int h) { + super.resize(mc,w,h); + network.resize(mc,w,h); + } + @Override public boolean getDownwards() { return ItemStorageCraftingRemote.getDownwards(remote); diff --git a/src/main/resources/assets/storagenetwork/textures/gui/inventory_expanded_bottom.png b/src/main/resources/assets/storagenetwork/textures/gui/inventory_expanded_bottom.png deleted file mode 100644 index 8ee440c336b2e3f4df066924b4bb851c50c99577..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 962 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5D>38$lZxy-8q?;Kn_c~qpu?a z!^VE@KZ&eBzC?geh%1o(|NsB7W5>+R%|k;&ySuy9)YO22nF4hSfD}hbkY6xR0SGYM zYu+0P6yq%Lh%9Dc;M)(vj25iHDnLQ864!{5;QX|b^2DN4hJeJ(yb?V>*AN9$J;U$K z-zNiAY)OsqO!M^AV&DLBSQ(@kS-}qW0`jDxY@i<)G#Ht|;!HrcAtMt5ACQg$;>>my zuy_WL4FbJoj0`V;UWL&pRx$u3Ca^QG0M!{785=MzfS3siAl3yCb0z`VAixAPl?kje z$kGDHg6c9fFaXJxX?b5|*_HqdOD0=S7srr_xVJYBdL0fBXuB8^{rO-1n%sKn3%;7h z7UJi(bDmKuw{hVrzwNht`}%vw%kO@wx%cf6$P_RrI`sg`Vz{|m2gYoeV`KqkJABjQ zh6yVy=K*;f1Sae~4GIe|IHB1Lid_&$dA|w50Fv}K`XkeJRcppJ?mOiHsU|2(3ejxYbDu$H%pBV1kvy*>N^y<~GZ>$VeuNfme7#!ps z^5*sFRm%PSxJ3HFr^T1Ia6Q{OC%M(>$&%qTUW~2n!aQ^G5y<$ zkI8kpu#h=%FBKHIVDRPclMvroj79H@u2gKF{QP3@@v27+S9wkSNwUupQ+}rw9e()m%G0G6~4DS=aH|qqCCh}Pgg&e IbxsLQ02Av0vj6}9 diff --git a/src/main/resources/assets/storagenetwork/textures/gui/inventory_expanded_top.png b/src/main/resources/assets/storagenetwork/textures/gui/inventory_expanded_top.png deleted file mode 100644 index c3c801d7e3b4a1aa4c75fbbfab8297559afc500c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 811 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5D>38$lZxy-8q?;Kn_c~qpu?a z!^VE@KZ&eBzEFTqh%1o(|NsB7W5+^6L(R?2fn2|^yRU#0TS<^#Fi`6Me}>Kbm+S|M za29w(7BevL0oi=}87)|YRe*wGC9V-A!TD(=<%vb93;~Imc_n&&t|1DhdWPSdzfT6L z*peFInda%K#lQjNurf$7vVtAz1>{LX*+925XfQH^#hHL?Lq;YBJ|GG*&wHZ!IM)Dpe%-)vD`4GLO2^clzrkIC^#Tsr;!De0C14Bd1kZ|%T ahU$8T7H*Yej<2l1p7V6|b6Mw<&;$UyqM>>K