Class DialogComponent

All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable, Renderable, Comparable<Renderable>

public class DialogComponent extends UIComponent
A flexible dialog component that can display warning, error, or info messages. Supports customizable positioning, actions, and animations.
  • Constructor Details

    • DialogComponent

      public DialogComponent(DialogService.DialogType dialogType, String title, String message)
      Creates a new dialog component with the specified type, title, and message.
      Parameters:
      dialogType - the type of dialog (INFO, WARNING, ERROR)
      title - the title of the dialog
      message - the message content of the dialog
  • Method Details

    • create

      public void create()
      Description copied from class: Component
      Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished.
      Overrides:
      create in class UIComponent
    • resize

      public void resize()
      Handles window resize by re-centering the dialog.
    • show

      public void show()
      Shows the dialog with a fade-in animation.
    • hide

      public void hide()
      Hides the dialog with a fade-out animation.
    • dispose

      public void dispose()
      Immediately removes the dialog from the stage.
      Specified by:
      dispose in interface com.badlogic.gdx.utils.Disposable
      Overrides:
      dispose in class RenderComponent
    • setPosition

      public void setPosition(float x, float y)
      Sets the position of the dialog.
      Parameters:
      x - the x coordinate
      y - the y coordinate
    • setSize

      public void setSize(float width, float height)
      Sets the size of the dialog.
      Parameters:
      width - the width
      height - the height
    • setOnConfirm

      public void setOnConfirm(Consumer<DialogComponent> onConfirm)
      Sets the callback for when the confirm/continue button is clicked.
      Parameters:
      onConfirm - the callback function
    • setOnCancel

      public void setOnCancel(Consumer<DialogComponent> onCancel)
      Sets the callback for when the cancel button is clicked.
      Parameters:
      onCancel - the callback function
    • setOnClose

      public void setOnClose(Consumer<DialogComponent> onClose)
      Sets the callback for when the dialog is closed.
      Parameters:
      onClose - the callback function
    • getDialogType

      public DialogService.DialogType getDialogType()
      Gets the current dialog type.
      Returns:
      the dialog type
    • getTitle

      public String getTitle()
      Gets the dialog title.
      Returns:
      the title
    • getMessage

      public String getMessage()
      Gets the dialog message.
      Returns:
      the message
    • isVisible

      public boolean isVisible()
      Checks if the dialog is currently visible.
      Returns:
      true if visible, false otherwise
    • getZIndex

      public float getZIndex()
      Description copied from interface: Renderable
      Z index controls rendering order within a layer. Higher Z index is drawn on top.
      Specified by:
      getZIndex in interface Renderable
      Overrides:
      getZIndex in class UIComponent
      Returns:
      Z index
    • draw

      public void draw(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
      Description copied from class: RenderComponent
      Draw the renderable. Should be called only by the renderer, not manually.
      Specified by:
      draw in class RenderComponent
      Parameters:
      batch - Batch to render to.