mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancydialogs: Allow inputs to be null
This commit is contained in:
@@ -1 +1 @@
|
||||
0.0.9
|
||||
0.0.10
|
||||
@@ -2,6 +2,7 @@ package com.fancyinnovations.fancydialogs.api.data;
|
||||
|
||||
import com.fancyinnovations.fancydialogs.api.data.inputs.DialogInputs;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -10,7 +11,7 @@ public record DialogData(
|
||||
@NotNull String title,
|
||||
boolean canCloseWithEscape,
|
||||
@NotNull List<DialogBodyData> body,
|
||||
@NotNull DialogInputs inputs,
|
||||
@Nullable DialogInputs inputs,
|
||||
@NotNull List<DialogButton> buttons
|
||||
) {
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.fancyinnovations.fancydialogs.api.data.inputs;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public record DialogInputs(
|
||||
List<DialogTextField> textFields,
|
||||
List<DialogSelect> selects
|
||||
@Nullable List<DialogTextField> textFields,
|
||||
@Nullable List<DialogSelect> selects
|
||||
) {
|
||||
|
||||
public static final DialogInputs EMPTY = new DialogInputs(List.of(), List.of());
|
||||
|
||||
@@ -47,38 +47,40 @@ public class DialogImpl extends Dialog {
|
||||
}
|
||||
|
||||
List<FS_DialogInput> inputs = new ArrayList<>();
|
||||
for (DialogInput input : data.inputs().all()) {
|
||||
FS_DialogInputControl control = null;
|
||||
if (input instanceof DialogTextField textField) {
|
||||
control = new FS_DialogTextInput(
|
||||
200, // default width
|
||||
textField.getLabel(),
|
||||
!textField.getLabel().isEmpty(),
|
||||
textField.getPlaceholder(),
|
||||
textField.getMaxLength(),
|
||||
textField.getMaxLines() > 0 ?
|
||||
new FS_DialogTextInput.MultilineOptions(textField.getMaxLines(), null) :
|
||||
null
|
||||
);
|
||||
} else if (input instanceof DialogSelect select) {
|
||||
List<FS_DialogSingleOptionInput.Entry> entries = new ArrayList<>();
|
||||
for (DialogSelect.Entry entry : select.getOptions()) {
|
||||
entries.add(new FS_DialogSingleOptionInput.Entry(entry.value(), entry.display(), entry.initial()));
|
||||
if (data.inputs() != null) {
|
||||
for (DialogInput input : data.inputs().all()) {
|
||||
FS_DialogInputControl control = null;
|
||||
if (input instanceof DialogTextField textField) {
|
||||
control = new FS_DialogTextInput(
|
||||
200, // default width
|
||||
textField.getLabel(),
|
||||
!textField.getLabel().isEmpty(),
|
||||
textField.getPlaceholder(),
|
||||
textField.getMaxLength(),
|
||||
textField.getMaxLines() > 0 ?
|
||||
new FS_DialogTextInput.MultilineOptions(textField.getMaxLines(), null) :
|
||||
null
|
||||
);
|
||||
} else if (input instanceof DialogSelect select) {
|
||||
List<FS_DialogSingleOptionInput.Entry> entries = new ArrayList<>();
|
||||
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) {
|
||||
throw new IllegalArgumentException("Unsupported input type: " + input.getClass().getSimpleName());
|
||||
}
|
||||
if (control == null) {
|
||||
throw new IllegalArgumentException("Unsupported input type: " + input.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
FS_DialogInput fsDialogInput = new FS_DialogInput(input.getKey(), control);
|
||||
inputs.add(fsDialogInput);
|
||||
FS_DialogInput fsDialogInput = new FS_DialogInput(input.getKey(), control);
|
||||
inputs.add(fsDialogInput);
|
||||
}
|
||||
}
|
||||
|
||||
List<FS_DialogActionButton> actions = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user