OpenDialogue

From Intrigues Wiki
Revision as of 11:21, 4 January 2024 by Tayfunwiki (talk | contribs) (Created page with "== <code>OpenDialogue</code> Method in DialogueManager Class == === Overview === The <code>OpenDialogue</code> method in the DialogueManager class is responsible for initiating a dialogue with specified parameters. It is essential for creating dynamic and interactive dialogues within the game. === Description === * Parameters: ** <code>title</code> (string): The title of the dialogue. ** <code>content</code> (string): The content or body of the dialogue. ** <code>time...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

OpenDialogue Method in DialogueManager Class

Overview

The OpenDialogue method in the DialogueManager class is responsible for initiating a dialogue with specified parameters. It is essential for creating dynamic and interactive dialogues within the game.

Description

  • Parameters:
    • title (string): The title of the dialogue.
    • content (string): The content or body of the dialogue.
    • time (float, optional): The duration for which the dialogue window remains open. The window automatically closes after this time elapses.
    • onUpdate (Action<float>, optional): An optional callback that is invoked with the remaining time.
    • isSchemeDialog (bool, optional): Indicates whether the dialogue is part of a node flow or standalone.
  • Return Type: Dialogue
    • Returns the newly opened dialogue instance.
  • Functionality:
    • Creates a new DialoguePanel instance for displaying the dialogue.
    • Configures the panel with the provided title, content, and other parameters.
    • Manages the visibility and duration of the dialogue panel.

Usage

This method is used to open dialogues in various scenarios within the game, such as character interactions, narrative progression, or player choices. The method's flexibility allows for a wide range of dialogue presentations.

Example of Usage

public class DialogueTrigger : MonoBehaviour {
    public void TriggerDialogue() {
        // Open a dialogue with a title and content
        var dialogue = DialogueManager.OpenDialogue(
            "Greetings", 
            "Welcome to the realm of Eldoria!", 
            10f); // Dialogue with a 10-second duration

        // Add choices to the dialogue
        dialogue.AddChoice("Explore", ExploreEldoria)
               .AddChoice("Leave", LeaveEldoria);

        // Subscribe to the onTimeout event
        dialogue.onTimeout += () => Debug.Log("Dialogue timed out.");
    }

    private void ExploreEldoria() {
        Debug.Log("Chose to explore Eldoria.");
        // Additional logic for exploring Eldoria
    }

    private void LeaveEldoria() {
        Debug.Log("Chose to leave Eldoria.");
        // Additional logic for leaving Eldoria
    }
}

Description:

  • OpenDialogue: Initiates a dialogue with the title "Greetings" and the message "Welcome to the realm of Eldoria!".
  • AddChoice: Two choices are added to the dialogue:
    • "Explore": Calls the ExploreEldoria method when selected.
    • "Leave": Calls the LeaveEldoria method when selected.
  • onTimeout Event: An event handler is added to log a message when the dialogue times out after 10 seconds.

Remarks

  • This example shows how to create a dialogue with choices, allowing players to interact and make selections.
  • The onTimeout event ensures that actions can be taken if the dialogue closes automatically after a certain duration.
  • This approach is effective for creating engaging and interactive dialogues in the game, providing players with choices that can lead to different outcomes or actions.

Dialogue Class

Overview

The Dialogue class represents an individual dialogue with various functionalities, including adding choices and managing its visibility.

Description

  • Functionalities:
    • Show/Hide/Close: Controls the visibility of the dialogue.
    • AddChoice: Adds interactive choices to the dialogue with various configurations.
    • Event Handling: Includes events like onTimeout for handling dialogue-specific actions.

Usage

Used to manage individual dialogues, the Dialogue class allows for intricate control over the dialogue's presentation and interactivity within the game.

Example of Adding Choices

Dialogue dialogue = DialogueManager.OpenDialogue("Question", "What will you do?");
dialogue.AddChoice("Accept", () => Debug.Log("Accepted"))
       .AddChoice("Decline", () => Debug.Log("Declined"));

In this example, a new dialogue is created with two choices, each triggering a different action when selected. This allows for interactive and dynamic dialogue experiences.

Remarks

  • The Dialogue class is integral for creating rich and engaging dialogue interactions in the game.
  • Its ability to handle different dialogue configurations makes it adaptable for various narrative and gameplay scenarios.