using System.Collections.Generic; using UnityEngine; using EasyTalk.Nodes.Core; using EasyTalk.Controller; using System; namespace EasyTalk.Nodes.Utility { /// /// A node for getting text input from the player. /// public class PlayerInputNode : Node, DialogueFlowNode, FunctionalNode, AsyncNode { /// /// The hint text to show to the player. /// [SerializeField] private string hintText = "Enter Response..."; /// /// The text obtained from the player. /// private string inputText = ""; /// /// Whether or not execution is completed on the node. /// [NonSerialized] private bool isExecutionComplete = false; /// /// The NodeHandler used to process the node. /// private NodeHandler nodeHandler = null; /// /// Indicates whether the node is being executed along the normal dialogue flow path, rather than via back/forward value propagation. /// [NonSerialized] private bool isExecutingFromDialogueFlow = true; /// /// Creates a new PlayerInput node. /// public PlayerInputNode() { this.name = "PLAYER INPUT"; this.nodeType = NodeType.PLAYER_INPUT; } /// /// Gets or sets the hint text for the node. /// public string HintText { get { return this.hintText; } set { this.hintText = value; } } /// /// Gets or sets the text which was input by the player. /// public string InputText { get { return this.inputText; } set { this.inputText = value; } } /// public bool DetermineAndStoreValue(NodeHandler nodeHandler, Dictionary nodeValues, GameObject convoOwner = null) { //Tell the node handler to display and retrieve input from the player, then set the entered value. if (!IsExecutionComplete()) { return false; } else { NodeConnection valueOutput = FindOutputOfType(InputOutputType.STRING); nodeValues.TryAdd(valueOutput.ID, inputText); nodeValues.TryAdd(this.ID, inputText); this.inputText = ""; return true; } } /// public List GetDependencyOutputIDs() { return FindDependencyOutputIDs(); } /// public NodeConnection GetFlowInput() { return FindFlowInputs()[0]; } /// public NodeConnection GetFlowOutput() { return FindFlowOutputs()[0]; } /// public bool HasDependencies() { return false; } /// public void Reset() { this.isExecutionComplete = false; } /// public void Execute(NodeHandler nodeHandler, Dictionary nodeValues, GameObject convoOwner = null) { //Send signal to listeners so that node execution gets handled by UI interaction this.nodeHandler = nodeHandler; nodeHandler.Listener.OnExecuteAsyncNode(this); } /// public void ExecutionCompleted() { this.isExecutionComplete = true; //Tell the node handler to continue nodeHandler.ExecutionCompleted(this); } /// public bool IsExecutionComplete() { return isExecutionComplete; } /// public bool IsSkippable() { return false; } /// public void Interrupt() { throw new System.Exception("Cannot interrupt PlayerInputNode since it is not interruptable."); } /// public AsyncCompletionMode AsyncCompletionMode { get { return AsyncCompletionMode.REPROCESS_CURRENT; } } /// public bool IsExecutingFromDialogueFlow { get { return isExecutingFromDialogueFlow; } set { this.isExecutingFromDialogueFlow = value; } } } }