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:
@@ -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
|
||||||
|
|||||||
@@ -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 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
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
|||||||
@@ -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());
|
||||||
|
|||||||
@@ -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<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user