aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuuz <6596629+Juuxel@users.noreply.github.com>2023-11-18 20:56:13 +0200
committerJuuz <6596629+Juuxel@users.noreply.github.com>2023-11-18 20:56:13 +0200
commitd6eb8b0b58df96673f21fa71bedd744ef5c7c92c (patch)
tree05ea75ce8c6b96bc44eba056375370cf99c1635e
parent6e8ecd21ed2f214a645b88ea100e6f2e8a2ecdbf (diff)
downloadLibGui-d6eb8b0b58df96673f21fa71bedd744ef5c7c92c.tar.gz
LibGui-d6eb8b0b58df96673f21fa71bedd744ef5c7c92c.tar.bz2
LibGui-d6eb8b0b58df96673f21fa71bedd744ef5c7c92c.zip
WItemSlot: Add toggle for hiding icons for slots with items
Resolves #203.
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java29
1 files changed, 28 insertions, 1 deletions
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;
@@ -251,6 +252,32 @@ public class WItemSlot extends WWidget {
}
/**
+ * Checks whether icons should be rendered when the first slot of this widget
+ * contains an item.
+ *
+ * <p>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.
*
* @return true if items can be inserted into or taken from this slot widget, false otherwise
@@ -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);
}
}