diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-05-20 21:48:25 +0300 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-05-20 21:48:25 +0300 |
commit | 48254df84d4e8f58f37b7bbb1ef3cb81446f6df4 (patch) | |
tree | 27d482ae98f259af7cf47d93f715794dbc8ded0b /src/main/java | |
parent | 003bd359141ec6450de960683d964ec35f671aca (diff) | |
download | LibGui-48254df84d4e8f58f37b7bbb1ef3cb81446f6df4.tar.gz LibGui-48254df84d4e8f58f37b7bbb1ef3cb81446f6df4.tar.bz2 LibGui-48254df84d4e8f58f37b7bbb1ef3cb81446f6df4.zip |
Add Inventory label for player inventory panels
Also allows custom label widgets that can be *any* widget.
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java | 22 | ||||
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java | 40 |
2 files changed, 60 insertions, 2 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java b/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java index 272d251..cbefb7a 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java @@ -336,6 +336,28 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr } /** + * Creates a player inventory widget from this panel's {@linkplain #playerInventory player inventory}. + * + * @param hasTitle whether the "Inventory" title should be displayed + * @return the created inventory widget + * @since 2.0.0 + */ + public WPlayerInvPanel createPlayerInventoryPanel(boolean hasTitle) { + return new WPlayerInvPanel(this.playerInventory, hasTitle); + } + + /** + * Creates a player inventory widget from this panel's {@linkplain #playerInventory player inventory}. + * + * @param title the inventory title widget + * @return the created inventory widget + * @since 2.0.0 + */ + public WPlayerInvPanel createPlayerInventoryPanel(WWidget title) { + return new WPlayerInvPanel(this.playerInventory, title); + } + + /** * Gets the block inventory at the context. * * <p>If no inventory is found, returns {@link EmptyInventory#INSTANCE}. diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java index 47df88f..198c708 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java @@ -5,6 +5,8 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.entity.player.PlayerInventory; +import javax.annotation.Nullable; + /** * A player inventory widget that has a visually separate hotbar. */ @@ -12,11 +14,45 @@ public class WPlayerInvPanel extends WPlainPanel { private final WItemSlot inv; private final WItemSlot hotbar; + /** + * Constructs a player inventory panel with a title. + * + * @param playerInventory the player inventory + */ public WPlayerInvPanel(PlayerInventory playerInventory) { + this(playerInventory, true); + } + + /** + * Constructs a player inventory panel. + * + * @param playerInventory the player inventory + * @param hasTitle whether there should be an "Inventory" title + * @since 2.0.0 + */ + public WPlayerInvPanel(PlayerInventory playerInventory, boolean hasTitle) { + this(playerInventory, hasTitle ? new WLabel(playerInventory.getDisplayName()) : null); + } + + /** + * Constructs a player inventory panel. + * + * @param playerInventory the player inventory + * @param title the title widget, can be null + * @since 2.0.0 + */ + public WPlayerInvPanel(PlayerInventory playerInventory, @Nullable WWidget title) { + int y = 0; + + if (title != null) { + this.add(title, 0, 0, 9*18, 11); + y += title.getHeight(); + } + inv = WItemSlot.ofPlayerStorage(playerInventory); hotbar = WItemSlot.of(playerInventory, 0, 9, 1); - this.add(inv, 0, 0); - this.add(hotbar, 0, 58); + this.add(inv, 0, y); + this.add(hotbar, 0, y + 58); } /** |