Class ConfirmDialog
java.lang.Object
dev.xichil.mvui.Screen
dev.xichil.mvui.ConfirmDialog
A yes/no question on its own screen, drawn as the version's vanilla confirm screen (like "Delete world?"). Use it
before destructive actions. Open it with
UiHost.open(Screen); it covers the current screen until the player answers.
Button.builder("reset")
.label(Text.translatable("mymod.reset", "Reset..."))
.onPress(() -> host.open(ConfirmDialog.builder("reset.confirm")
.title(Text.translatable("mymod.reset.title", "Reset every setting?"))
.message(Text.translatable("mymod.reset.message", "This can't be undone."))
.yesLabel(Text.translatable("mymod.reset.yes", "Reset"))
.onYes(() -> {
config.reset();
status.show(StatusLine.Kind.SUCCESS, Text.translatable("mymod.reset.done", "Reset"));
})
.build()))
.build();
When the player picks an answer, the host first closes the dialog (as UiHost.back(), returning to the
screen that opened it) and then runs that answer's action, so the action runs with the previous screen current and
can open another screen or write to its StatusLine. That screen is refreshed afterwards.
Required: title, message, onYes. The answer
buttons default to UiTexts.YES and UiTexts.NO; "no" does nothing by default.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilds aConfirmDialog; frombuilder(String). -
Method Summary
Modifier and TypeMethodDescriptionstatic ConfirmDialog.BuilderStarts building a dialog.voidcancel()Runs the no action (none by default).voidconfirm()Runs the yes action.message()The question's explanation, shown below the title.noLabel()The label of the "no" button.yesLabel()The label of the "yes" button.
-
Method Details
-
builder
Starts building a dialog.- Parameters:
id- the dialog's id- Returns:
- a new builder
- Throws:
IllegalArgumentException- ifidis invalid
-
message
The question's explanation, shown below the title.- Returns:
- the explanation given to the builder
-
yesLabel
The label of the "yes" button.- Returns:
- the text of the yes button, as given to the builder
-
noLabel
The label of the "no" button.- Returns:
- the text of the no button,
UiTexts.NOunless set on the builder
-
confirm
public void confirm()Runs the yes action. Backends call it after closing the dialog; whatever the action throws passes through. -
cancel
public void cancel()Runs the no action (none by default). Backends call it after closing the dialog; whatever the action throws passes through.
-