Skip to content

Dialogue

lutianyi edited this page Oct 30, 2025 · 10 revisions

Dialogue System

Overview

The dialogue system wraps story-driven conversations in a reusable IntroDialogueComponent. When a map spawns this component, it pauses world time, shows a dimmed overlay with character portraits and names, and steps through a scripted list of DialogueEntry objects. Each entry can define text, speaker metadata, background art, and optional voice lines managed by DialogueAudioManager. Once the player finishes or skips the dialogue, the component restores the original time scale, cleans up UI resources, and runs a caller-provided callback so gameplay can continue (for example, enabling tower placement or starting enemy waves). 屏幕截图 2025-10-20 161804

freecompress-GdxGame.2025-10-30.21-28-47.mp4

Core Components

  • IntroDialogueComponent: Builds a Scene2D overlay, pauses gameplay, walks through scripted lines, and runs a completion callback to resume the game.
  • DialogueEntry: Represents individual lines with text, portrait, sound, portrait side, dialogue background, and speaker name (all optional except text).
  • DialogueConfig: Groups scripts per map and can pull player name/avatar from services to personalise dialogue.
  • DialogueAudioManager: Handles dialogue audio preloading, playback, volume scaling, and cleanup so each line can provide narration or SFX.

Lifecycle

  1. A game area spawns an entity with IntroDialogueComponent, passing the script and an onComplete runnable.
  2. In create(), the component preloads textures/sounds, pauses the time source, builds the overlay, and shows the first line.
  3. Pressing anywhere on the overlay or the “continue” button advances the script; each step updates UI, portrait, background, and audio.
  4. When the script finishes or the user hits “skip”, the component tears down the overlay, restores the original time scale, fires the completion callback, and disposes itself.

UI Composition

  • The overlay is a dimmed full-screen table with a dialogue card anchored at the bottom, optional portrait anchored left/right, and a speaker name plaque.
  • “Continue” and “skip” buttons use UIStyleHelper styles (images/continue.png, images/skip.png) and resolution-aware fonts.
  • Each line can switch backgrounds; special “talker” backgrounds preserve their aspect ratio while scaling to the dialogue card.

Audio Flow

  • preloadSounds() loads the unique soundPaths ahead of time to prevent runtime hitching.
  • playSound() respects the user’s sound volume and applies a dialogue multiplier so voice lines stand out.
  • Helper methods support pausing, resuming, and adjusting the multiplier globally.

Integration in Game Areas

  • ForestGameArea and ForestGameArea2 delay UI elements (tower hotbar, hero placement) and wave spawning until the dialogue’s completion callback, ensuring the tutorial flow runs first.
  • Components are added via the standard spawnEntity pipeline; no extra rendering hooks are needed.

Gameplay Safeguards

  • Global time scale is set to 0 during dialogue and restored afterward, preserving deterministic wave timing.
  • CameraZoomDragComponent disables zoom while any dialogue is active so the player can’t pan/zoom under the overlay.
  • Input listeners absorb clicks on the overlay to avoid interacting with world UI beneath the dialogue.

UML Diagram

image

Clone this wiki locally