private void GenerateChoices() { // Exit if not a choice if (handler.currentMessageInfo.Type != QD_NodeType.Choice) { return; } // Clear the old choices ClearChoices(); // Generate new choices QD_Choice choice = handler.GetChoice(); int added = 0; // Use inactive choices instead of making new ones, if possible while (inactiveChoices.Count > 0 && added < choice.Choices.Count) { int i = inactiveChoices.Count - 1; TextMeshProUGUI cText = inactiveChoices[i]; cText.text = choice.Choices[added]; QD_ChoiceButton button = cText.GetComponent <QD_ChoiceButton>(); button.number = added; cText.gameObject.SetActive(true); activeChoices.Add(cText); inactiveChoices.RemoveAt(i); added++; } // Make new choices if any left to make while (added < choice.Choices.Count) { TextMeshProUGUI newChoice = Instantiate(choiceTemplate, choices); newChoice.text = choice.Choices[added]; QD_ChoiceButton button = newChoice.GetComponent <QD_ChoiceButton>(); button.number = added; newChoice.gameObject.SetActive(true); activeChoices.Add(newChoice); added++; } }
/// <summary> /// Creates a new node of the given type at the given position. /// </summary> /// <param name="type"></param> /// <param name="position"></param> public void CreateNode(QD_NodeType type, Vector2 position) { int id = NextID++; var node = new QD_Node(id, type, position.x, position.y); if (type == QD_NodeType.Speaker) { var speakerNode = new QD_SpeakerNode(id, type, position.x, position.y); node.Window.width = speakerNode.Window.width; node.Window.height = speakerNode.Window.height; node.Inputs = speakerNode.CloneKnobs(QD_KnobType.Input); node.Outputs = speakerNode.CloneKnobs(QD_KnobType.Output); node.AllowedInputs = speakerNode.AllowedInputs; node.AllowedOutputs = speakerNode.AllowedOutputs; var speakerData = new QD_Speaker(id); DataDB.Speakers.Add(speakerData); speakerNode.Data = speakerData; SpeakerNodes.Add(speakerNode); } else if (type == QD_NodeType.Message) { var messageNode = new QD_MessageNode(id, type, position.x, position.y); node.Window.width = messageNode.Window.width; node.Window.height = messageNode.Window.height; node.Inputs = messageNode.CloneKnobs(QD_KnobType.Input); node.Outputs = messageNode.CloneKnobs(QD_KnobType.Output); node.AllowedInputs = messageNode.AllowedInputs; node.AllowedOutputs = messageNode.AllowedOutputs; var messageData = new QD_Message(id); DataDB.Messages.Add(messageData); messageNode.Data = messageData; MessageNodes.Add(messageNode); } else if (type == QD_NodeType.Conversation) { var conversationNode = new QD_ConversationNode(id, type, position.x, position.y); node.Window.width = conversationNode.Window.width; node.Window.height = conversationNode.Window.height; node.Inputs = conversationNode.CloneKnobs(QD_KnobType.Input); node.Outputs = conversationNode.CloneKnobs(QD_KnobType.Output); node.AllowedInputs = conversationNode.AllowedInputs; node.AllowedOutputs = conversationNode.AllowedOutputs; var conversationData = new QD_Conversation(id); DataDB.Conversations.Add(conversationData); conversationNode.Data = conversationData; ConversationNodes.Add(conversationNode); } else if (type == QD_NodeType.Choice) { var choiceNode = new QD_ChoiceNode(id, type, position.x, position.y); node.Window.width = choiceNode.Window.width; node.Window.height = choiceNode.Window.height; node.Inputs = choiceNode.CloneKnobs(QD_KnobType.Input); node.Outputs = choiceNode.CloneKnobs(QD_KnobType.Output); node.AllowedInputs = choiceNode.AllowedInputs; node.AllowedOutputs = choiceNode.AllowedOutputs; var choiceData = new QD_Choice(id); DataDB.Choices.Add(choiceData); choiceNode.Data = choiceData; ChoiceNodes.Add(choiceNode); } Nodes.Add(node); }