|
1 | 1 | package io.papermc.paper.registry.data.dialog.input; |
2 | 2 |
|
3 | | -import io.papermc.paper.registry.data.dialog.input.type.DialogInputConfig; |
| 3 | +import java.util.List; |
| 4 | +import net.kyori.adventure.text.Component; |
4 | 5 | import org.jetbrains.annotations.Contract; |
| 6 | +import org.jspecify.annotations.Nullable; |
5 | 7 |
|
6 | 8 | /** |
7 | | - * Represents a configured input for a dialog. |
| 9 | + * Represents an input for dialog. |
8 | 10 | */ |
9 | | -public sealed interface DialogInput permits DialogInputImpl { |
| 11 | +public sealed interface DialogInput permits BooleanDialogInput, NumberRangeDialogInput, SingleOptionDialogInput, TextDialogInput { |
10 | 12 |
|
11 | 13 | /** |
12 | | - * Creates a new dialog input with the specified key and input type. |
| 14 | + * Creates a boolean dialog input. |
13 | 15 | * |
14 | | - * @param key the key for this input |
15 | | - * @param inputType the type of this input |
16 | | - * @return a new dialog input instance |
| 16 | + * @param key the key identifier for the input |
| 17 | + * @param label the label for the input |
| 18 | + * @param initial the initial value of the input |
| 19 | + * @param onTrue the input's value in a template when the value is true |
| 20 | + * @param onFalse the input's value in a template when the value is false |
| 21 | + * @return a new boolean dialog input instance |
| 22 | + */ |
| 23 | + @Contract(pure = true, value = "_, _, _, _, _ -> new") |
| 24 | + static BooleanDialogInput bool(final String key, final Component label, final boolean initial, final String onTrue, final String onFalse) { |
| 25 | + return new BooleanDialogInputImpl(key, label, initial, onTrue, onFalse); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Creates a new builder for a boolean dialog input. |
| 30 | + * |
| 31 | + * @param key the key identifier for the input |
| 32 | + * @param label the label for the input |
| 33 | + * @return a new builder instance |
17 | 34 | */ |
18 | 35 | @Contract(pure = true, value = "_, _ -> new") |
19 | | - static DialogInput create(final String key, final DialogInputConfig inputType) { |
20 | | - return new DialogInputImpl(key, inputType); |
| 36 | + static BooleanDialogInput.Builder bool(final String key, final Component label) { |
| 37 | + return new BooleanDialogInputImpl.BuilderImpl(key, label); |
21 | 38 | } |
22 | 39 |
|
23 | 40 | /** |
24 | | - * The key for this input. |
25 | | - * <p>Used in dialog actions to identify this dialog input's value</p> |
| 41 | + * Creates a number range dialog input. |
26 | 42 | * |
27 | | - * @return the key of this input |
| 43 | + * @param key the key identifier for the input |
| 44 | + * @param width the width of the input |
| 45 | + * @param label the label for the input |
| 46 | + * @param labelFormat the format for the label (a translation key or format string) |
| 47 | + * @param start the start of the range |
| 48 | + * @param end the end of the range |
| 49 | + * @param initial the initial value, or null if not set |
| 50 | + * @param step the step size, or null if not set |
| 51 | + * @return a new number range dialog input instance |
28 | 52 | */ |
29 | | - @Contract(pure = true) |
30 | | - String key(); |
| 53 | + @Contract(pure = true, value = "_, _, _, _, _, _, _, _ -> new") |
| 54 | + static NumberRangeDialogInput numberRange(final String key, final int width, final Component label, final String labelFormat, final float start, final float end, final @Nullable Float initial, final @Nullable Float step) { |
| 55 | + return new NumberRangeDialogInputImpl(key, width, label, labelFormat, start, end, initial, step); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Creates a new builder for a number range dialog input. |
| 60 | + * |
| 61 | + * @param key the key identifier for the input |
| 62 | + * @param label the label for the input |
| 63 | + * @param start the start of the range |
| 64 | + * @param end the end of the range |
| 65 | + * @return a new builder instance |
| 66 | + */ |
| 67 | + @Contract(value = "_, _, _, _ -> new", pure = true) |
| 68 | + static NumberRangeDialogInput.Builder numberRange(final String key, final Component label, final float start, final float end) { |
| 69 | + return new NumberRangeDialogInputImpl.BuilderImpl(key, label, start, end); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Creates a single option dialog input (radio input). |
| 74 | + * |
| 75 | + * @param key the key identifier for the input |
| 76 | + * @param width the width of the input |
| 77 | + * @param entries the list of options for the input |
| 78 | + * @param label the label for the input |
| 79 | + * @param labelVisible whether the label should be visible |
| 80 | + * @return a new single option dialog input instance |
| 81 | + */ |
| 82 | + @Contract(pure = true, value = "_, _, _, _, _ -> new") |
| 83 | + static SingleOptionDialogInput singleOption(final String key, final int width, final List<SingleOptionDialogInput.OptionEntry> entries, final Component label, final boolean labelVisible) { |
| 84 | + return new SingleOptionDialogInputImpl(key, width, entries, label, labelVisible); |
| 85 | + } |
31 | 86 |
|
32 | 87 | /** |
33 | | - * The type of this input. |
34 | | - * <p>Used to determine how the input should be rendered and processed</p> |
| 88 | + * Creates a new builder for a single option dialog input. |
35 | 89 | * |
36 | | - * @return the type of this input |
| 90 | + * @param key the key identifier for the input |
| 91 | + * @param label the label for the input |
| 92 | + * @param entries the list of options for the input |
| 93 | + * @return a new builder instance |
37 | 94 | */ |
38 | | - @Contract(pure = true) |
39 | | - DialogInputConfig inputType(); |
| 95 | + @Contract(value = "_, _, _ -> new", pure = true) |
| 96 | + static SingleOptionDialogInput.Builder singleOption(final String key, final Component label, final List<SingleOptionDialogInput.OptionEntry> entries) { |
| 97 | + return new SingleOptionDialogInputImpl.BuilderImpl(key, entries, label); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Creates a text dialog input. |
| 102 | + * |
| 103 | + * @param key the key identifier for the input |
| 104 | + * @param width the width of the input |
| 105 | + * @param label the label for the input |
| 106 | + * @param labelVisible whether the label should be visible |
| 107 | + * @param initial the initial value of the input |
| 108 | + * @param maxLength the maximum length of the input |
| 109 | + * @param multilineOptions the multiline options |
| 110 | + * @return a new text dialog input instance |
| 111 | + */ |
| 112 | + @Contract(pure = true, value = "_, _, _, _, _, _, _ -> new") |
| 113 | + static TextDialogInput text(final String key, final int width, final Component label, final boolean labelVisible, final String initial, final int maxLength, final TextDialogInput.@Nullable MultilineOptions multilineOptions) { |
| 114 | + return new TextDialogInputImpl(key, width, label, labelVisible, initial, maxLength, multilineOptions); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Creates a new builder for a text dialog input. |
| 119 | + * |
| 120 | + * @param key the key identifier for the input |
| 121 | + * @param label the label for the input |
| 122 | + * @return a new builder instance |
| 123 | + */ |
| 124 | + @Contract(value = "_, _ -> new", pure = true) |
| 125 | + static TextDialogInput.Builder text(final String key, final Component label) { |
| 126 | + return new TextDialogInputImpl.BuilderImpl(key, label); |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * Gets the key for this input. |
| 131 | + * <p>Used in dialog actions to identify this dialog input's value</p> |
| 132 | + * |
| 133 | + * @return the key |
| 134 | + */ |
| 135 | + @Contract(pure = true, value = " -> new") |
| 136 | + String key(); |
40 | 137 | } |
0 commit comments