-
Notifications
You must be signed in to change notification settings - Fork 1
AnimalSelectionActions
The AnimalSelectionActions
class manages the actions and interactions related to the animal selection process within the game. This class is responsible for handling user input, such as clicking on animal images or buttons, and triggering corresponding game logic like selecting an animal, showing dialog boxes, or transitioning to different screens.
The AnimalSelectionActions
class is responsible for:
- Handling user interactions with the animal selection UI, including clicks on animal images and buttons.
- Managing the selection of animals and visually indicating the selected animal.
- Displaying dialogs to provide feedback or alerts to the player.
- Transitioning to the main game screen or returning to the main menu based on user actions.
The constructor initializes the AnimalSelectionActions
class by setting up references to the display and dialog helper, and it also adds listeners to the UI elements.
public AnimalSelectionActions(AnimalSelectionDisplay display, DialogHelper dialogHelper, GdxGame game) {
this.display = display;
this.dialogHelper = dialogHelper;
this.game = game;
addListeners();
}
addListeners(): Attaches click listeners to the animal images, buttons, select button, and back button. These listeners trigger specific actions when the UI elements are interacted with.
private void addListeners() {
// To setup listeners for animal images, buttons, select, and back buttons
}
selectAnimal(Image animalImage): Highlights the selected animal and updates the selected Animal Image reference.
private void selectAnimal(Image animalImage) {
if (selectedAnimalImage != null) {
selectedAnimalImage.setColor(1, 1, 1, 1);
}
selectedAnimalImage = animalImage;
selectedAnimalImage.setColor(1, 0, 0, 1);
logger.debug("Animal selected: {}", animalImage.getName());
}
showSelectionAlert(): Displays an alert dialog if the player attempts to proceed without selecting an animal
private void showSelectionAlert() {
Dialog dialog = new Dialog("Alert", display.getSkin()) {
@Override
protected void result(Object object) {
}
};
dialog.text("Please select an animal first.");
dialog.button("OK", true);
dialog.show(display.getStage());
}
This class relies on the following components:
- AnimalSelectionDisplay: Provides the UI elements that this class interacts with.
- DialogHelper: A helper class for displaying dialog boxes within the game.
- GdxGame: The main game class, used for transitioning between screens.
To use AnimalSelectionActions, instantiate it within the AnimalSelectionScreen class or another relevant context, passing the necessary dependencies:
AnimalSelectionActions actions = new AnimalSelectionActions(display, dialogHelper, game);