using EasyTalk.Controller; using EasyTalk.Nodes.Core; using System; using System.Collections.Generic; using UnityEngine; namespace EasyTalk.Nodes.Common { /// /// A node which allows presented dialogue options to be modified during runtime. /// [Serializable] public class OptionModifierNode : Node, FunctionalNode { /// /// Whether the option should be displayed. /// [SerializeField] private bool isDisplayed = true; /// /// Whether the option should be selectable. /// [SerializeField] private bool isSelectable = true; /// /// Creates a new OptionModifierNode. /// public OptionModifierNode() { this.name = "OPTION_FILTER"; this.nodeType = NodeType.OPTION_MOD; } /// /// Gets or sets whether the option(s) this modifier node is connected to should be displayed. /// public bool IsDisplayed { get { return this.isDisplayed; } set { this.isDisplayed = value; } } /// /// Gets or sets whether the option(s) this modifier node is connected to should be selectable. /// public bool IsSelectable { get { return this.isSelectable; } set { this.isSelectable = value; } } /// public bool DetermineAndStoreValue(NodeHandler nodeHandler, Dictionary nodeValues, GameObject convoOwner = null) { OptionModifier modifier = new OptionModifier(); if(Inputs[0].AttachedIDs.Count > 0) { string textValue = null; object incomingTextValue = nodeValues[Inputs[0].AttachedIDs[0]]; if(incomingTextValue != null) { textValue = incomingTextValue.ToString(); } modifier.text = textValue; } if (Inputs[1].AttachedIDs.Count > 0) { bool displayedValue = true; object incomingDisplayedValue = nodeValues[Inputs[1].AttachedIDs[0]]; if(incomingDisplayedValue != null) { bool.TryParse(incomingDisplayedValue.ToString(), out displayedValue); } modifier.displayed = displayedValue; } else { modifier.displayed = IsDisplayed; } if (Inputs[2].AttachedIDs.Count > 0) { bool selectableValue = true; object incomingSelectableValue = nodeValues[Inputs[2].AttachedIDs[0]]; if (incomingSelectableValue != null) { bool.TryParse(incomingSelectableValue.ToString(), out selectableValue); } modifier.selectable = selectableValue; } else { modifier.selectable = isSelectable; } NodeConnection output = Outputs[0]; nodeValues.TryAdd(output.ID, modifier); return true; } /// public List GetDependencyOutputIDs() { return FindDependencyOutputIDs(); } /// public bool HasDependencies() { return FindDependencyOutputIDs().Count > 0; } } /// /// Defines the values set by an option modifier. /// public class OptionModifier { /// /// The text to set on an option. /// public string text = null; /// /// Whether an option should be displayed. /// public bool displayed; /// /// Whether an option should be selectable. /// public bool selectable; } }