fancydialogs: Allow inputs to be null

This commit is contained in:
Oliver
2025-06-29 00:15:46 +02:00
parent f08fa67a84
commit 08e1d70ebd
5 changed files with 42 additions and 33 deletions

View File

@@ -5,6 +5,10 @@ order: 1
# FancyDialogs v0.x.x # FancyDialogs v0.x.x
## v0.0.9 [!badge variant="info" text="2025-06-29"]
- Allow inputs to be null
## v0.0.9 [!badge variant="info" text="2025-06-28"] ## v0.0.9 [!badge variant="info" text="2025-06-28"]
- Added `open_random_dialog` action to open a random dialog from a list - Added `open_random_dialog` action to open a random dialog from a list

View File

@@ -1 +1 @@
0.0.9 0.0.10

View File

@@ -2,6 +2,7 @@ package com.fancyinnovations.fancydialogs.api.data;
import com.fancyinnovations.fancydialogs.api.data.inputs.DialogInputs; import com.fancyinnovations.fancydialogs.api.data.inputs.DialogInputs;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
@@ -10,7 +11,7 @@ public record DialogData(
@NotNull String title, @NotNull String title,
boolean canCloseWithEscape, boolean canCloseWithEscape,
@NotNull List<DialogBodyData> body, @NotNull List<DialogBodyData> body,
@NotNull DialogInputs inputs, @Nullable DialogInputs inputs,
@NotNull List<DialogButton> buttons @NotNull List<DialogButton> buttons
) { ) {

View File

@@ -1,11 +1,13 @@
package com.fancyinnovations.fancydialogs.api.data.inputs; package com.fancyinnovations.fancydialogs.api.data.inputs;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public record DialogInputs( public record DialogInputs(
List<DialogTextField> textFields, @Nullable List<DialogTextField> textFields,
List<DialogSelect> selects @Nullable List<DialogSelect> selects
) { ) {
public static final DialogInputs EMPTY = new DialogInputs(List.of(), List.of()); public static final DialogInputs EMPTY = new DialogInputs(List.of(), List.of());

View File

@@ -47,38 +47,40 @@ public class DialogImpl extends Dialog {
} }
List<FS_DialogInput> inputs = new ArrayList<>(); List<FS_DialogInput> inputs = new ArrayList<>();
for (DialogInput input : data.inputs().all()) { if (data.inputs() != null) {
FS_DialogInputControl control = null; for (DialogInput input : data.inputs().all()) {
if (input instanceof DialogTextField textField) { FS_DialogInputControl control = null;
control = new FS_DialogTextInput( if (input instanceof DialogTextField textField) {
200, // default width control = new FS_DialogTextInput(
textField.getLabel(), 200, // default width
!textField.getLabel().isEmpty(), textField.getLabel(),
textField.getPlaceholder(), !textField.getLabel().isEmpty(),
textField.getMaxLength(), textField.getPlaceholder(),
textField.getMaxLines() > 0 ? textField.getMaxLength(),
new FS_DialogTextInput.MultilineOptions(textField.getMaxLines(), null) : textField.getMaxLines() > 0 ?
null new FS_DialogTextInput.MultilineOptions(textField.getMaxLines(), null) :
); null
} else if (input instanceof DialogSelect select) { );
List<FS_DialogSingleOptionInput.Entry> entries = new ArrayList<>(); } else if (input instanceof DialogSelect select) {
for (DialogSelect.Entry entry : select.getOptions()) { List<FS_DialogSingleOptionInput.Entry> entries = new ArrayList<>();
entries.add(new FS_DialogSingleOptionInput.Entry(entry.value(), entry.display(), entry.initial())); for (DialogSelect.Entry entry : select.getOptions()) {
entries.add(new FS_DialogSingleOptionInput.Entry(entry.value(), entry.display(), entry.initial()));
}
control = new FS_DialogSingleOptionInput(
200, // default width
entries,
select.getLabel(),
!select.getLabel().isEmpty()
);
} }
control = new FS_DialogSingleOptionInput(
200, // default width
entries,
select.getLabel(),
!select.getLabel().isEmpty()
);
}
if (control == null) { if (control == null) {
throw new IllegalArgumentException("Unsupported input type: " + input.getClass().getSimpleName()); throw new IllegalArgumentException("Unsupported input type: " + input.getClass().getSimpleName());
} }
FS_DialogInput fsDialogInput = new FS_DialogInput(input.getKey(), control); FS_DialogInput fsDialogInput = new FS_DialogInput(input.getKey(), control);
inputs.add(fsDialogInput); inputs.add(fsDialogInput);
}
} }
List<FS_DialogActionButton> actions = new ArrayList<>(); List<FS_DialogActionButton> actions = new ArrayList<>();