Class GuiDialog

All Implemented Interfaces:
ElementEvents, GuiParent<GuiDialog>, TooltipHandler<GuiDialog>

public class GuiDialog extends GuiElement<GuiDialog>
This class is designed to assist with the easy creation of a number of standard dialog windows.

Created by brandon3055 on 14/12/2023

  • Constructor Details

    • GuiDialog

      protected GuiDialog(@NotNull @NotNull GuiParent<?> parent)
  • Method Details

    • optionsDialog

      public static GuiDialog optionsDialog(@NotNull @NotNull GuiParent<?> parent, @Nullable @Nullable net.minecraft.network.chat.Component title, net.minecraft.network.chat.Component dialogText, int width, GuiDialog.Option... options)
      Option dialog builder with pre-configured background and button builders.
      Parameters:
      parent - Can be any gui element (Will just be used to get the root element)
      title - Sets a separate title that will be displayed above the main dialog text. (Optional)
      dialogText - The main dialog text.
      width - The dialog width, (Height will automatically adjust based on content.)
      options - The list of options for this dialog.
    • optionsDialog

      public static GuiDialog optionsDialog(@NotNull @NotNull GuiParent<?> parent, net.minecraft.network.chat.Component dialogText, int width, GuiDialog.Option... options)
      Option dialog builder with pre-configured background and button builders.
      Parameters:
      parent - Can be any gui element (Will just be used to get the root element)
      dialogText - The main dialog text.
      width - The dialog width, (Height will automatically adjust based on content.)
      options - The list of options for this dialog.
    • infoDialog

      public static GuiDialog infoDialog(@NotNull @NotNull GuiParent<?> parent, @Nullable @Nullable net.minecraft.network.chat.Component title, net.minecraft.network.chat.Component dialogText, int width, @Nullable @Nullable Runnable okAction)
      Creates a simple info dialog for displaying information to the user. The dialog has a single "Ok" button that will close the dialog
      Parameters:
      parent - Can be any gui element (Will just be used to get the root element)
      title - Sets a separate title that will be displayed above the main dialog text. (Optional)
      dialogText - The main dialog text.
      width - The dialog width, (Height will automatically adjust based on content.)
    • infoDialog

      public static GuiDialog infoDialog(@NotNull @NotNull GuiParent<?> parent, @Nullable @Nullable net.minecraft.network.chat.Component title, net.minecraft.network.chat.Component dialogText, int width)
      Creates a simple info dialog for displaying information to the user. The dialog has a single "Ok" button that will close the dialog
      Parameters:
      parent - Can be any gui element (Will just be used to get the root element)
      title - Sets a separate title that will be displayed above the main dialog text. (Optional)
      dialogText - The main dialog text.
      width - The dialog width, (Height will automatically adjust based on content.)
    • infoDialog

      public static GuiDialog infoDialog(@NotNull @NotNull GuiParent<?> parent, net.minecraft.network.chat.Component dialogText, int width)
      Creates a simple info dialog for displaying information to the user. The dialog has a single "Ok" button that will close the dialog
      Parameters:
      parent - Can be any gui element (Will just be used to get the root element)
      dialogText - The main dialog text.
      width - The dialog width, (Height will automatically adjust based on content.)
    • primary

      public static GuiDialog.Option primary(net.minecraft.network.chat.Component text, @Nullable @Nullable Runnable action)
      Create a green "Primary" button option.
    • neutral

      public static GuiDialog.Option neutral(net.minecraft.network.chat.Component text, @Nullable @Nullable Runnable action)
      Create a grey "Neutral" button option.
    • caution

      public static GuiDialog.Option caution(net.minecraft.network.chat.Component text, @Nullable @Nullable Runnable action)
      Create a red "Caution" button option.
    • setBlockKeyInput

      public GuiDialog setBlockKeyInput(boolean blockKeyInput)
      Parameters:
      blockKeyInput - Prevent keyboard inputs from being sent to the rest of the gui while this dialog is open. Default: true.
    • setBlockMouseInput

      public GuiDialog setBlockMouseInput(boolean blockMouseInput)
      Parameters:
      blockMouseInput - Prevent mouse inputs from being sent to the rest of the gui while this dialog is open. Default: true.
    • close

      public void close()
    • keyPressed

      public boolean keyPressed(int key, int scancode, int modifiers)
      Description copied from interface: ElementEvents
      Override this method to implement handling for the keyPressed event. This event propagates through the entire gui element stack from top to bottom, If eny element consumes the event it will not propagate any further. For rare cases where you need to receive this even if it has been consumed, you can override ElementEvents.keyPressed(int, int, int, boolean)

      Note: You do not need to call super when overriding this interface method.

      Parameters:
      key - the keyboard key that was pressed.
      scancode - the system-specific scancode of the key
      modifiers - bitfield describing which modifier keys were held down.
      Returns:
      true to consume event.
    • mouseClicked

      public boolean mouseClicked(double mouseX, double mouseY, int button)
      Description copied from interface: ElementEvents
      Override this method to implement handling for the mouseClicked event. This event propagates through the entire gui element stack from top to bottom, If eny element consumes the event it will not propagate any further. For rare cases where you need to receive this even if it has been consumed, you can override ElementEvents.mouseClicked(double, double, int, boolean)

      Note: You do not need to call super when overriding this interface method.

      Parameters:
      mouseX - Mouse X position
      mouseY - Mouse Y position
      button - Mouse Button
      Returns:
      true to consume event.
    • optionsDialog

      public static GuiDialog optionsDialog(@NotNull @NotNull GuiParent<?> parent, @Nullable @Nullable net.minecraft.network.chat.Component title, net.minecraft.network.chat.Component dialogText, Function<GuiDialog,GuiElement<?>> backgroundBuilder, BiFunction<GuiDialog,GuiDialog.Option,GuiButton> buttonBuilder, int width, GuiDialog.Option... options)
      This is the core dialog builder method. It takes a title text component and a map of Component>Runnable map that is used to define the options. Dialog will automatically be centered on the screen.
      Parameters:
      parent - Can be any gui element (Will just be used to get the root element)
      title - Sets a separate title that will be displayed above the main dialog text. (Optional)
      dialogText - The main dialog text.
      backgroundBuilder - A function that is used to create the background of the dialog.
      buttonBuilder - A function that is used to create the dialog buttons.
      width - The dialog width, (Height will automatically adjust based on content.)
      options - The list of options for this dialog.