From 9ab901717e430a48db6e30d5117dd28f15ff8f72 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Fri, 4 Jun 2021 16:08:18 +0300 Subject: Make WBar.validate safe to call multiple times --- src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java | 4 +++- src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java index 1b45a5a..60fb7a9 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java @@ -57,6 +57,7 @@ public class WBar extends WWidget { */ protected int maxValue; protected PropertyDelegate properties; + private boolean manuallySetProperties = false; protected final Direction direction; protected String tooltipLabel; protected Text tooltipTextComponent; @@ -197,7 +198,7 @@ public class WBar extends WWidget { @Override public void validate(GuiDescription host) { super.validate(host); - if (properties==null) properties = host.getPropertyDelegate(); + if (properties==null || !manuallySetProperties) properties = host.getPropertyDelegate(); } /** @@ -221,6 +222,7 @@ public class WBar extends WWidget { */ public WBar setProperties(PropertyDelegate properties) { this.properties = properties; + manuallySetProperties = properties != null; return this; } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java index d94a4b9..1091201 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java @@ -370,7 +370,7 @@ public class WWidget { if (host != null) { this.host = host; } else { - LOGGER.warn("Validating {} with a null host", this); + LOGGER.warn("Validating {} with a null host", this); } } -- cgit