Combat Action Display in Combat Screen - UQcsse3200/2024-studio-2 GitHub Wiki

Overview

The Combat Action Display enhances the player's experience by illustrating combat actions through the use of the Dialogue Box Service. As the player and enemy make combat moves, these actions are displayed on the screen in Dialogue Boxes, stating the move that was made, the stat changes incurred, status effects caused by special moves and their related effects, as well as ending combat dialogue that changes depending on whether you win or lose.

Combat Action Display Example

Key Components

1. Animation of Statistics Bars

Each of the statistics bars of the players and enemies are initialized and handled within this UI Component. More details can be found in the Animation of Stats Bars wiki page.

2. Real-time Status Reflection

The dialogue boxes illustrate the current changes in both the player and enemy stats. After stating the moves made by each entity, the dialogue boxes state the value changes in stats.

Player Stats Change Enemy Stats Change Player Status Effect Combat End Dialogue

3. Dialogue Box Service Integration

To reduce duplicated code, the Dialogue Box Service developed by Team 4 was used to display the desired text within the combat screen. This integration allows for seamless text display in sync with combat animations and actions.

4. Comprehensive Dialogue Generation

The text displayed is dynamically generated to suit all possible situations in combat, using the actions made in combat, as well as the CombatStatsComponents and StatusEffects applied to player entities.

5. Dynamic Combat Button Management

To reduce screen clutter when Dialogue Boxes appear, the combat buttons are temporarily removed and re-added once the Dialogue Boxes disappear through the use of event listeners and triggers.

Class Diagram

classDiagram class CombatButtonDisplay { -Table table -Screen screen -ServiceContainer container -TextButton attackButton -TextButton guardButton -TextButton sleepButton -TextButton itemsButton -ChangeListener dialogueBoxListener +create() +hideButtons() +displayEndCombatDialogue(Entity, boolean) +displayBossEndCombatDialogue(Entity, boolean) -addActors() -onItemClicked(AbstractItem, int, ItemUsageContext) } class CombatManager { -Entity player -Entity enemy -CombatStatsComponent playerStats -CombatStatsComponent enemyStats -Action playerAction -Action enemyAction +onPlayerActionSelected(String) -executeMoveCombination(Action, Action) -displayCombatResults() -checkCombatEnd() } class CombatActions { -GdxGame game -CombatManager manager -Screen previousScreen -ServiceContainer previousServices +create() -onCombatWin(Entity) -onCombatLoss(Entity) -onBossCombatWin(Entity) -onBossCombatLoss(Entity) -onAttack(Screen, ServiceContainer) -onGuard(Screen, ServiceContainer) -onSleep(Screen, ServiceContainer) -onItems(Screen, ServiceContainer) } CombatButtonDisplay --> CombatManager : uses CombatActions --> CombatManager : uses CombatButtonDisplay --> CombatActions : triggers events

Sequence Diagrams

Addition of Dialogue Boxes to the Screen

This sequence diagram illustrates the process after the player has selected a move and executeMoveCombination() has been called in the CombatManager.

sequenceDiagram
    participant P as Player
    participant CBD as CombatButtonDisplay
    participant CM as CombatManager
    participant DBS as DialogueBoxService
    P->>CBD: Select move
    CBD->>CM: onPlayerActionSelected(move)
    CM->>CM: executeMoveCombination()
    CM->>CM: displayCombatResults()
    CM->>DBS: updateText(moveText)
    CM->>CBD: trigger("displayCombatResults")
    CBD->>CBD: hideButtons()

Loading

Removal of Dialogue Boxes from Screen

This sequence diagram shows the process after the player has clicked the continue button on the dialogue box.

sequenceDiagram
    participant P as Player
    participant DBS as DialogueBoxService
    participant CBD as CombatButtonDisplay
    P->>DBS: Click continue
    DBS->>DBS: setVisible(false)
    DBS->>CBD: changed() (via listener)
    CBD->>CBD: addActors()

Loading

Usage

The display of Dialogue Box logic and removal of buttons is contained within multiple different files. Here are some key code snippets:

CombatButtonDisplay.java

public class CombatButtonDisplay extends UIComponent {
    // ... other fields and methods ...

    @Override
    public void create() {
        super.create();
        addActors();
        entity.getEvents().addListener("displayCombatResults", this::hideButtons);
        entity.getEvents().addListener("endOfCombatDialogue", this::displayEndCombatDialogue);
        
        dialogueBoxListener = new ChangeListener() {
            @Override
            public void changed(ChangeEvent event, Actor actor) {
                if (!ServiceLocator.getDialogueBoxService().getIsVisible()) {
                    addActors();
                }
            }
        };
        stage.addListener(dialogueBoxListener);
    }

    public void hideButtons() {
        table.remove();
    }

    public void displayEndCombatDialogue(Entity enemyEntity, boolean winStatus) {
        // ... implementation ...
    }
}

CombatManager.java

public class CombatManager extends Component {
    // ... other fields and methods ...

    private void displayCombatResults() {
        List<String> moveTextList = new ArrayList<>();
        // ... populate moveTextList ...

        String[][] moveText = new String[1][moveTextList.size()];
        moveText[0] = moveTextList.toArray(new String[0]);

        ServiceLocator.getDialogueBoxService().updateText(moveText);
        entity.getEvents().trigger("displayCombatResults");
    }
}

CombatActions.java

public class CombatActions extends Component {
    // ... other fields and methods ...

    @Override
    public void create() {
        entity.getEvents().addListener("combatWin", this::onCombatWin);
        entity.getEvents().addListener("combatLoss", this::onCombatLoss);
        entity.getEvents().addListener("Attack", this::onAttack);
        // ... other event listeners ...
    }

    private void onCombatWin(Entity enemy) {
        // ... handle combat win ...
        entity.getEvents().trigger("endOfCombatDialogue", enemy, true);
    }

    private void onAttack(Screen screen, ServiceContainer container) {
        manager.onPlayerActionSelected("ATTACK");
        entity.getEvents().trigger("onAttack", manager.getPlayerStats(), manager.getEnemyStats());
    }
}

How to Use

  1. Initializing Combat Display: The CombatButtonDisplay class is responsible for creating and managing the combat buttons and dialogue boxes. It's automatically initialized when the combat screen is created.

  2. Triggering Combat Actions: When a player selects an action (e.g., Attack, Guard, Sleep, or Items), the corresponding method in CombatActions is called, which then triggers the action in CombatManager.

  3. Displaying Combat Results: After each action, CombatManager.displayCombatResults() is called, which generates the appropriate text and triggers the DialogueBoxService to display it.

  4. Handling Combat End: When combat ends (either win or loss), the appropriate method in CombatActions is called, which triggers the end combat dialogue and handles the transition back to the main game screen or to the game over screen.

  5. Customizing Dialogue: To customize the dialogue displayed, modify the displayCombatResults() method in CombatManager and the various methods in CombatActions that handle combat end scenarios.

Testing Plan

For testing the Combat Action Display functionality, refer to the Combat Testing for Visual Assets wiki page. Key areas to test include:

  1. Removal and Re-Appearance of Combat Buttons in Combat Screen
  2. Post-Combat Dialogue Before Screen Exit
  3. Display of Dialogue Boxes Reflecting the Actions made by Player and Enemy

Ensure that all these components work together seamlessly to provide a cohesive and informative combat experience for the player.

I've updated the Combat Action Display wiki page with more detailed information, including updated class and sequence diagrams using Mermaid syntax. The content now provides a comprehensive overview of the system, its components, and how they interact.

Key updates include:

  1. Expanded overview and key components sections.
  2. Updated class diagram showing the relationships between CombatButtonDisplay, CombatManager, and CombatActions.
  3. Two sequence diagrams illustrating the process of adding and removing dialogue boxes.
  4. Code snippets from key classes to demonstrate usage.
  5. A "How to Use" section providing step-by-step instructions for utilizing the functionality.
  6. Reference to the existing testing plan.
⚠️ **GitHub.com Fallback** ⚠️