From 5f33cd70f43977a519a808c3941d2fb75d18fdff Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Fri, 10 Sep 2021 19:16:33 +0300 Subject: Fix narration element indices and more JD tricks --- .../io/github/cottonmc/cotton/gui/impl/client/NarrationHelper.java | 2 +- src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java | 1 + src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java | 2 +- src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java | 7 +++++++ .../github/cottonmc/cotton/gui/widget/data/ObservableProperty.java | 4 ++++ .../io/github/cottonmc/cotton/gui/widget/data/ObservableView.java | 3 +++ 6 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NarrationHelper.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NarrationHelper.java index 55095a3..54567be 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NarrationHelper.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NarrationHelper.java @@ -18,11 +18,11 @@ public final class NarrationHelper { public static void addNarrations(WPanel rootPanel, NarrationMessageBuilder builder) { List narratableWidgets = getAllWidgets(rootPanel) .filter(WWidget::isNarratable) - .filter(widget -> widget.isFocused() || widget.isHovered()) .collect(Collectors.toList()); for (int i = 0, childCount = narratableWidgets.size(); i < childCount; i++) { WWidget child = narratableWidgets.get(i); + if (!child.isFocused() && !child.isHovered()) continue; // replicates Screen.addElementNarrations if (narratableWidgets.size() > 1) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java index 3358d0a..204ea93 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java @@ -251,6 +251,7 @@ public abstract class WPanel extends WWidget { /** * {@return a stream of all visible widgets in this panel} * + * @experimental * @since 4.2.0 */ @ApiStatus.Experimental diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java index 88c0db5..718e44b 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java @@ -367,7 +367,7 @@ public class WTabPanel extends WPanel { @Environment(EnvType.CLIENT) @Override public void addNarrations(NarrationMessageBuilder builder) { - Text label = data.getTitle(); // TODO: a separate narration message + Text label = data.getTitle(); if (label != null) { builder.put(NarrationPart.TITLE, new TranslatableText(NarrationMessages.TAB_TITLE_KEY, label)); 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 b300d43..27e62f8 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 @@ -11,6 +11,7 @@ import io.github.cottonmc.cotton.gui.GuiDescription; import io.github.cottonmc.cotton.gui.impl.VisualLogger; import io.github.cottonmc.cotton.gui.widget.data.InputResult; import io.github.cottonmc.cotton.gui.widget.data.ObservableProperty; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -466,9 +467,11 @@ public class WWidget { * Returns whether the user is hovering over this widget. * The result is an observable property that can be modified and listened to. * + * @experimental * @return the {@code hovered} property * @since 4.2.0 */ + @ApiStatus.Experimental public ObservableProperty hoveredProperty() { return hovered; } @@ -477,9 +480,11 @@ public class WWidget { * Returns whether the user is hovering over this widget. * This is equivalent to calling {@link #hoveredProperty()}.get(). * + * @experimental * @return true if this widget is hovered, false otherwise * @since 4.2.0 */ + @ApiStatus.Experimental public final boolean isHovered() { return hoveredProperty().get(); } @@ -487,9 +492,11 @@ public class WWidget { /** * Sets the {@link #hoveredProperty() hovered} property. * + * @experimental * @param hovered the new value; true if hovered, false otherwise * @since 4.2.0 */ + @ApiStatus.Experimental public final void setHovered(boolean hovered) { hoveredProperty().set(hovered); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableProperty.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableProperty.java index 39a078b..3bd24ef 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableProperty.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableProperty.java @@ -1,5 +1,7 @@ package io.github.cottonmc.cotton.gui.widget.data; +import org.jetbrains.annotations.ApiStatus; + import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -13,9 +15,11 @@ import java.util.function.Supplier; * {@code Property}. For example, the {@code WWidget.hovered} property can be retrieved with * {@link io.github.cottonmc.cotton.gui.widget.WWidget#hoveredProperty() hoveredProperty()}. * + * @experimental * @param the contained value type * @since 4.2.0 */ +@ApiStatus.Experimental public final class ObservableProperty implements ObservableView { private Supplier value; private final List> listeners = new ArrayList<>(); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableView.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableView.java index c670c07..8439e80 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableView.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableView.java @@ -1,5 +1,6 @@ package io.github.cottonmc.cotton.gui.widget.data; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.function.Supplier; @@ -7,9 +8,11 @@ import java.util.function.Supplier; /** * A read-only {@linkplain ObservableProperty observable property}. * + * @experimental * @param the contained value type * @since 4.2.0 */ +@ApiStatus.Experimental public interface ObservableView extends Supplier { /** * Adds a change listener to this property view. -- cgit