public void OnConfirmed() { Dialogue dialogue = ScriptableObject.CreateInstance <Dialogue>(); dialogue.nodes = new List <Dialogue.Node>(); var node = new Dialogue.Node(); node.ID = 0; node.text = taskConfirmedDialogue != null ? taskConfirmedDialogue : "Complete the task."; // TODO: Why is this (and the color(?)) sometimes null? Is the task node not loaded correctly? node.textColor = dialogueColor; node.nextNodes = new List <int>() { 1 }; var node1 = new Dialogue.Node(); node1.ID = 1; node1.action = Dialogue.DialogueAction.Exit; node1.buttonText = "Alright."; // TODO: allow customizing in World Creator? dialogue.nodes.Add(node); dialogue.nodes.Add(node1); TaskManager.speakerID = entityIDforConfirmedResponse; DialogueSystem.StartDialogue(dialogue, TaskManager.GetSpeaker()); }
/// <summary> /// Initialize this choice UI to display the given node. /// </summary> public void Init(Dialogue.Node node) { this.node = node; layout = GetComponent <LayoutElement>(); text = GetComponentInChildren <Text>(); text.text = node.Data.Text; }
public DialogueNode(Vector2 position, GUIStyle nodeStyle, GUIStyle selectedStyle , GUIStyle inPointStyle, GUIStyle outPointStyle, Action <ConnectionPoint> OnClickInPoint , Action <ConnectionPoint> OnClickOutPoint, Action <Node> OnClickRemoveNode, string inPointID , string outPointID, string id = null) : base(position, nodeStyle, selectedStyle, inPointStyle, outPointStyle , OnClickInPoint, OnClickOutPoint, OnClickRemoveNode, inPointID, outPointID, true, id) { m_RectWithMargin = new Rect(m_Margin, m_Margin, GetWidth() - 2 * m_Margin, GetHeight() - 2 * m_Margin); m_OnClickOutPoint = OnClickOutPoint; m_OutPointStyle = outPointStyle; m_Node = new Dialogue.Node("Name", "Text", m_ID); }
public void next(Dialogue dialogue, int ID, Entity speaker) { if (dialogue.nodes.Count == 0) { Debug.LogWarning("Empty dialogue: " + dialogue.name); endDialogue(0, false); return; } if (player.GetIsDead()) { Debug.Log("Dead player"); endDialogue(0, false); return; } // clear everything if (buttons != null) { for (int i = 0; i < buttons.Length; i++) { Destroy(buttons[i]); } } // find dialogue index int currentIndex = getNodeIndex(dialogue, ID); if (currentIndex == -1) { Debug.LogWarning("Missing node '" + ID + "' in " + dialogue.name); endDialogue(); return; } Dialogue.Node current = dialogue.nodes[currentIndex]; // check if the node has an action switch (current.action) { case Dialogue.DialogueAction.None: AudioManager.PlayClipByID("clip_typing", true); break; case Dialogue.DialogueAction.Outpost: endDialogue(0, false); if (speaker.faction != player.faction) { return; } if (((Vector3)speakerPos - player.transform.position).magnitude < dialogue.vendingBlueprint.range) { vendorUI.SetVendor(speaker as IVendor, player); vendorUI.openUI(); } endDialogue(0, false); return; case Dialogue.DialogueAction.Shop: OpenTrader((Vector3)speakerPos, dialogue.traderInventory); endDialogue(0, false); return; case Dialogue.DialogueAction.Yard: OpenBuilder((Vector3)speakerPos); endDialogue(0, false); return; case Dialogue.DialogueAction.Exit: endDialogue(0, true); return; case Dialogue.DialogueAction.Workshop: workshop.yardPosition = (Vector3)speakerPos; workshop.InitializeSelectionPhase(); endDialogue(0, false); return; case Dialogue.DialogueAction.Upgrader: upgraderScript.initialize(); endDialogue(0, false); return; default: break; } // radio image window.GetComponentInChildren <SelectionDisplayHandler>().AssignDisplay(speaker.blueprint, null); window.transform.Find("Name").GetComponent <Text>().text = speaker.blueprint.entityName; // change text text = current.text.Replace("<br>", "\n"); characterCount = 0; nextCharacterTime = (float)(Time.time + timeBetweenCharacters); textRenderer.color = current.textColor; // create buttons buttons = new GameObject[current.nextNodes.Count]; for (int i = 0; i < current.nextNodes.Count; i++) { int nextIndex = getNodeIndex(dialogue, current.nextNodes[i]); if (nextIndex == -1) { Debug.LogWarning("Missing node '" + current.nextNodes[i] + "' in " + dialogue.name); endDialogue(); return; } Dialogue.Node next = dialogue.nodes[nextIndex]; Transform button = CreateButton(next.buttonText, null, 24 + 16 * (current.nextNodes.Count - (i + 1))).transform; button.GetComponent <Button>().onClick.AddListener(() => { Next(dialogue, nextIndex, speaker); }); if (dialogue.nodes[nextIndex].action != Dialogue.DialogueAction.Exit) { button.GetComponent <Button>().onClick.AddListener(() => { AudioManager.PlayClipByID("clip_select", true); // need condition to ensure no sound clashes occur }); } buttons[i] = button.gameObject; } }