Class DialogComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.rendering.RenderComponent
com.csse3200.game.ui.UIComponent
com.csse3200.game.components.dialog.DialogComponent
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
,Renderable
,Comparable<Renderable>
A flexible dialog component that can display warning, error, or info messages. Supports
customizable positioning, actions, and animations.
-
Field Summary
Fields inherited from class com.csse3200.game.ui.UIComponent
skin, stage
Fields inherited from class com.csse3200.game.rendering.RenderComponent
colour
-
Constructor Summary
ConstructorsConstructorDescriptionDialogComponent
(DialogService.DialogType dialogType, String title, String message) Creates a new dialog component with the specified type, title, and message. -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Called when the entity is created and registered.void
dispose()
Immediately removes the dialog from the stage.void
draw
(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Draw the renderable.Gets the current dialog type.Gets the dialog message.getTitle()
Gets the dialog title.float
Z index controls rendering order within a layer.void
hide()
Hides the dialog with a fade-out animation.boolean
Checks if the dialog is currently visible.void
resize()
Handles window resize by re-centering the dialog.void
setOnCancel
(Consumer<DialogComponent> onCancel) Sets the callback for when the cancel button is clicked.void
setOnClose
(Consumer<DialogComponent> onClose) Sets the callback for when the dialog is closed.void
setOnConfirm
(Consumer<DialogComponent> onConfirm) Sets the callback for when the confirm/continue button is clicked.void
setPosition
(float x, float y) Sets the position of the dialog.void
setSize
(float width, float height) Sets the size of the dialog.void
show()
Shows the dialog with a fade-in animation.Methods inherited from class com.csse3200.game.ui.UIComponent
getLayer
Methods inherited from class com.csse3200.game.rendering.RenderComponent
compareTo, getColour, render, setColour
Methods inherited from class com.csse3200.game.components.Component
earlyUpdate, getEntity, getPriority, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
DialogComponent
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 dialogmessage
- 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 classUIComponent
-
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 interfacecom.badlogic.gdx.utils.Disposable
- Overrides:
dispose
in classRenderComponent
-
setPosition
public void setPosition(float x, float y) Sets the position of the dialog.- Parameters:
x
- the x coordinatey
- the y coordinate
-
setSize
public void setSize(float width, float height) Sets the size of the dialog.- Parameters:
width
- the widthheight
- the height
-
setOnConfirm
Sets the callback for when the confirm/continue button is clicked.- Parameters:
onConfirm
- the callback function
-
setOnCancel
Sets the callback for when the cancel button is clicked.- Parameters:
onCancel
- the callback function
-
setOnClose
Sets the callback for when the dialog is closed.- Parameters:
onClose
- the callback function
-
getDialogType
Gets the current dialog type.- Returns:
- the dialog type
-
getTitle
Gets the dialog title.- Returns:
- the title
-
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 interfaceRenderable
- Overrides:
getZIndex
in classUIComponent
- 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 classRenderComponent
- Parameters:
batch
- Batch to render to.
-