Combat Action Display in Combat Screen - UQcsse3200/2024-studio-2 GitHub Wiki
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.
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.
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.
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.
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.
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.
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 eventsThis 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()
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()
The display of Dialogue Box logic and removal of buttons is contained within multiple different files. Here are some key code snippets:
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 ...
}
}
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");
}
}
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());
}
}
-
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. -
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 inCombatManager
. -
Displaying Combat Results: After each action,
CombatManager.displayCombatResults()
is called, which generates the appropriate text and triggers theDialogueBoxService
to display it. -
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. -
Customizing Dialogue: To customize the dialogue displayed, modify the
displayCombatResults()
method inCombatManager
and the various methods inCombatActions
that handle combat end scenarios.
For testing the Combat Action Display functionality, refer to the Combat Testing for Visual Assets wiki page. Key areas to test include:
- Removal and Re-Appearance of Combat Buttons in Combat Screen
- Post-Combat Dialogue Before Screen Exit
- 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:
- Expanded overview and key components sections.
- Updated class diagram showing the relationships between CombatButtonDisplay, CombatManager, and CombatActions.
- Two sequence diagrams illustrating the process of adding and removing dialogue boxes.
- Code snippets from key classes to demonstrate usage.
- A "How to Use" section providing step-by-step instructions for utilizing the functionality.
- Reference to the existing testing plan.