Class ConfirmDialog

java.lang.Object
dev.xichil.mvui.Screen
dev.xichil.mvui.ConfirmDialog

public final class ConfirmDialog extends Screen
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.

  • Method Details

    • builder

      public static ConfirmDialog.Builder builder(String id)
      Starts building a dialog.
      Parameters:
      id - the dialog's id
      Returns:
      a new builder
      Throws:
      IllegalArgumentException - if id is invalid
    • message

      public Text message()
      The question's explanation, shown below the title.
      Returns:
      the explanation given to the builder
    • yesLabel

      public Text yesLabel()
      The label of the "yes" button.
      Returns:
      the text of the yes button, as given to the builder
    • noLabel

      public Text noLabel()
      The label of the "no" button.
      Returns:
      the text of the no button, UiTexts.NO unless 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.