Package com.csse3200.game.ui
Class CustomButton
java.lang.Object
com.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.Group
com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
com.badlogic.gdx.scenes.scene2d.ui.Stack
com.csse3200.game.ui.CustomButton
- All Implemented Interfaces:
com.badlogic.gdx.scenes.scene2d.utils.Cullable
,com.badlogic.gdx.scenes.scene2d.utils.Layout
public class CustomButton
extends com.badlogic.gdx.scenes.scene2d.ui.Stack
A customizable button class that combines a button with a label and hover/click effects.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCustomButton
(String labelText, com.badlogic.gdx.scenes.scene2d.ui.Skin skin) Constructs a new CustomButton that automatically uses predefined textures and sounds. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addClickListener
(Runnable clickAction) Adds a click listener to the button that triggers a sound effect and a specified action.void
dispose()
Disposes of any additional resources if needed (textures are static and should not be disposed here).com.badlogic.gdx.scenes.scene2d.ui.Button
com.badlogic.gdx.scenes.scene2d.ui.Label
getLabel()
void
void
resize
(float screenWidth, float screenHeight, float scaleFactor) Resize the button according to the screen's dimensions and a scaling factor.void
setButtonSize
(float width, float height) Updates the button size.void
setButtonStyle
(CustomButton.Style style, com.badlogic.gdx.scenes.scene2d.ui.Skin skin) Update the button stylevoid
setLabelText
(String newText) Updates the button label text.void
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Stack
add, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getPrefHeight, getPrefWidth, invalidate, layout
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
childrenChanged, draw, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Group
act, addActor, addActorAfter, addActorAt, addActorBefore, applyTransform, applyTransform, clear, clear, clearChildren, clearChildren, computeTransform, debugAll, drawChildren, drawDebug, drawDebugChildren, findActor, getChild, getChildren, getCullingArea, hasChildren, hit, isTransform, localToDescendantCoordinates, removeActor, removeActor, removeActorAt, resetTransform, resetTransform, setCullingArea, setDebug, setStage, setTransform, swapActor, swapActor, toString
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebugBounds, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, scaleChanged, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront
-
Constructor Details
-
CustomButton
Constructs a new CustomButton that automatically uses predefined textures and sounds.- Parameters:
labelText
- The text to display on the button.skin
- The skin for styling the label.
-
-
Method Details
-
addClickListener
Adds a click listener to the button that triggers a sound effect and a specified action.- Parameters:
clickAction
- The action to perform when the button is clicked.
-
setLabelText
Updates the button label text.- Parameters:
newText
- The new text to display on the button.
-
setButtonSize
public void setButtonSize(float width, float height) Updates the button size.- Parameters:
width
- The new width of the button.height
- The new height of the button.
-
setButtonStyle
Update the button style- Parameters:
style
- The style of the button.skin
- The skin for styling the label.
-
resize
public void resize(float screenWidth, float screenHeight, float scaleFactor) Resize the button according to the screen's dimensions and a scaling factor. This allows dynamic resizing based on the screen size.- Parameters:
screenWidth
- The current screen width.screenHeight
- The current screen height.scaleFactor
- The scale factor for resizing.
-
getButton
public com.badlogic.gdx.scenes.scene2d.ui.Button getButton() -
getLabel
public com.badlogic.gdx.scenes.scene2d.ui.Label getLabel() -
hideCustomButton
public void hideCustomButton() -
showCustomButton
public void showCustomButton() -
dispose
public void dispose()Disposes of any additional resources if needed (textures are static and should not be disposed here).
-