From d6eb8b0b58df96673f21fa71bedd744ef5c7c92c Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Sat, 18 Nov 2023 20:56:13 +0200 Subject: WItemSlot: Add toggle for hiding icons for slots with items Resolves #203. --- .../cottonmc/cotton/gui/widget/WItemSlot.java | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java index 4da52cc..76e72aa 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java @@ -88,6 +88,7 @@ public class WItemSlot extends WWidget { private BackgroundPainter backgroundPainter = null; @Nullable private Icon icon = null; + private boolean iconOnlyPaintedForEmptySlots = true; private Inventory inventory; private int startIndex = 0; private int slotsWide = 1; @@ -250,6 +251,32 @@ public class WItemSlot extends WWidget { return this; } + /** + * Checks whether icons should be rendered when the first slot of this widget + * contains an item. + * + *
This property is {@code true} by default. + * + * @return {@code true} if the icon should always be painted, {@code false} otherwise + * @since 9.1.0 + */ + public boolean isIconOnlyPaintedForEmptySlots() { + return iconOnlyPaintedForEmptySlots; + } + + /** + * Sets whether icons should be rendered when the first slot of this widget + * contains an item. + * + * @param iconOnlyPaintedForEmptySlots {@code true} if the icon should always be painted, {@code false} otherwise + * @return this item slot + * @since 9.1.0 + */ + public WItemSlot setIconOnlyPaintedForEmptySlots(boolean iconOnlyPaintedForEmptySlots) { + this.iconOnlyPaintedForEmptySlots = iconOnlyPaintedForEmptySlots; + return this; + } + /** * Returns true if the contents of this {@code WItemSlot} can be modified by players. * @@ -487,7 +514,7 @@ public class WItemSlot extends WWidget { backgroundPainter.paintBackground(context, x, y, this); } - if (icon != null) { + if (icon != null && (iconOnlyPaintedForEmptySlots || inventory.getStack(startIndex).isEmpty())) { icon.paint(context, x + 1, y + 1, 16); } } -- cgit