private static void ValidateDialogInterrupt(DialogInterrupt interrupt)
    {
        if (string.IsNullOrEmpty(interrupt.label.text))
        {
            throw new UnityException("EXPORT ERROR: DialogInterrupt missing flag text!");
        }

        if (interrupt.outPoint.connections.Count < 1)
        {
            throw new UnityException("EXPORT ERROR: DialogInterrupt missing out-connections!");
        }
    }
Exemple #2
0
    /*
     * UpdateInterrupts() heavily modifies the editor by updating connected InterruptNodes
     * and associated connections depending on the interrupt flags defined in the textArea.
     */
    private void UpdateInterrupts(SDEComponent textComponent)
    {
        HistoryManager.RecordEditor();

        string text = ((TextArea)textComponent).text;

        // parse the text for interrupts flags
        List <string> flags;

        try {
            flags = GetFlags(text);
        } catch (UnityException e) {
            Debug.Log(e.Message);
            return;
        }

        // find an Interrupt Node that's connected to this
        Node interruptNode = DialogBoxManager.GetInterruptNode(outPoint);

        if (interruptNode == null)
        {
            interruptNode = ConnectInterruptNode();
        }

        // update the Interrupt Node's bottom level status
        if (child == null)
        {
            interruptNode.SetBottomLevelInterrupt(true);
        }
        else
        {
            interruptNode.SetBottomLevelInterrupt(false);
        }

        // update the Interrupt Node
        DialogInterrupt        interrupt     = (DialogInterrupt)interruptNode.childContainer;
        List <DialogInterrupt> oldInterrupts = new List <DialogInterrupt>();

        // remove all the old Interrupt Nodes, but queue the interrupts that need to be added.
        while (interrupt != null)
        {
            if (flags.Contains(interrupt.label.text))
            {
                oldInterrupts.Add(interrupt);
                SDEContainerManager.RemoveContainer(interrupt, removeConnections: false, markHistory: false);
            }
            else
            {
                SDEContainerManager.RemoveContainer(interrupt, removeConnections: true, markHistory: false);
            }

            interrupt = (DialogInterrupt)interrupt.child;
        }

        // rebuild the nodes
        bool            appendNode   = true;
        bool            foundMatch   = false;
        DialogInterrupt newInterrupt = null;

        for (int i = 0; i < flags.Count; i++)
        {
            // look for pre-existing nodes that match the flag
            for (int j = 0; j < oldInterrupts.Count; j++)
            {
                if (flags[i] == oldInterrupts[j].label.text)
                {
                    newInterrupt = oldInterrupts[j];
                    oldInterrupts.RemoveAt(j);
                    foundMatch = true;
                    break;
                }
            }

            if (!foundMatch)
            {
                newInterrupt = ScriptableObject.CreateInstance <DialogInterrupt>();
                newInterrupt.Init();
                newInterrupt.label.text = flags[i];
            }

            // guarantee that we are dealing with a new, unlinked Container.
            SDEContainerManager.CleanLinks(newInterrupt);

            if (appendNode)
            {
                SDEContainerManager.InsertChild(interruptNode, newInterrupt);
                appendNode = false;
            }
            else
            {
                SDEContainerManager.InsertChild(interrupt, newInterrupt);
            }

            interrupt  = newInterrupt;
            foundMatch = false;
        }
    }