Exemplo n.º 1
0
    void WindowFunctionPreNode(int windowID)
    {
        bool          keep      = true;
        PrenodeStruct tmpPreode = prenodeSet[windowID];

        GUI.DragWindow(new Rect(0, 0, preWidth, heightElements));
        EditorGUILayout.BeginHorizontal();
        tmpPreode.futureId = EditorGUILayout.IntField(tmpPreode.futureId);

        if (GUILayout.Button("Reference"))
        {
            if (nodeSet.ContainsKey(tmpPreode.futureId))
            {
                NodeStruct        tmpNd = nodeSet[tmpPreode.parentId];
                ConditionStructUI tmpNc = tmpNd.conditions[tmpPreode.condId];
                tmpNc.nextId = tmpPreode.futureId;
                tmpNd.conditions[tmpPreode.condId] = tmpNc;
                nodeSet[tmpPreode.parentId]        = tmpNd;
                prenodeSet.Remove(tmpPreode.nodeId);
                keep = false;
            }
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("New"))
        {
            CreateNode(tmpPreode.parentId, tmpPreode.nodeId);
            keep = false;
        }

        EditorGUILayout.EndHorizontal();

        if (keep)
        {
            prenodeSet[windowID] = tmpPreode;
        }
    }
Exemplo n.º 2
0
    void OnGUI()
    {
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField(text);
        if (GUILayout.Button("Restart"))
        {
            temporalId = 0;
            nodeSet    = new Dictionary <int, NodeStruct>();
            prenodeSet = new Dictionary <int, PrenodeStruct>();
            //listNode = new List<NodeStruct>();
            CreateFirst();
        }

        if (GUILayout.Button("Recover"))
        {
            if (listNode.Count > 0)
            {
                ListToDictionary();
            }
            else
            {
                StorytellController smg = GameObject.Find("Controller").GetComponent <StorytellController>() as StorytellController;
                List <StorytellController.StepStruct> stepList = smg.listSteps;
                if (stepList.Count > 0)
                {
                    foreach (StorytellController.StepStruct scTmp in stepList)
                    {
                        NodeStruct nsTmp = new NodeStruct();
                        nsTmp.nodeId          = scTmp.id;
                        nsTmp.nodeName        = scTmp.nameStep;
                        nsTmp.nodeDescription = scTmp.descriptionStep;
                        nsTmp.rectangle       = scTmp.rectangle;
                        nsTmp.heightWindow    = scTmp.heightWindow;
                        nsTmp.parentId        = scTmp.parentId;

                        List <ConditionStructUI> conditions = new List <ConditionStructUI>();
                        nsTmp.conditionId = 0;
                        foreach (StorytellController.ConditionStruct cdTmp in scTmp.conditions)
                        {
                            ConditionStructUI tmpC = new ConditionStructUI();
                            tmpC.nextId   = cdTmp.nextId;
                            tmpC.popupPos = cdTmp.popupPos;
                            tmpC.time     = cdTmp.time;
                            tmpC.target   = cdTmp.objTarget;
                            tmpC.color    = cdTmp.color;
                            nsTmp.conditionId++;
                            conditions.Add(tmpC);
                        }
                        nsTmp.conditions = conditions;

                        List <ConsequenceStructUI> consequences = new List <ConsequenceStructUI>();
                        nsTmp.consequenceId = 0;
                        foreach (StorytellController.ConsequenceStruct csTmp in scTmp.consequences)
                        {
                            ConsequenceStructUI tmpC = new ConsequenceStructUI();
                            tmpC.popupPos   = csTmp.popupPos;
                            tmpC.integer    = csTmp.integer;
                            tmpC.objectAtr  = csTmp.objectAtr;
                            tmpC.primString = csTmp.secondaryAtribute;
                            nsTmp.consequenceId++;
                            consequences.Add(tmpC);
                        }
                        nsTmp.consequences = consequences;

                        listNode.Add(nsTmp);
                    }
                    ListToDictionary();
                }
                else
                {
                    text = "Create your Storytell: No storytell saved";
                }
            }
        }

        if (nodeSet.Count == 0)
        {
            temporalId = 0;
        }

        List <int> keysN = new List <int>(nodeSet.Keys); //We are going to iterate over dictionary keys

        if (GUILayout.Button("Save"))
        {
            if (prenodeSet.Count == 0) //All prenodes assigned
            {
                savedId = temporalId;
                List <StorytellController.StepStruct> stepList = new List <StorytellController.StepStruct>();
                listNode = new List <NodeStruct>(); //Set listNode values, because it's Serilizable

                foreach (int key in keysN)
                {
                    NodeStruct node = nodeSet[key];
                    listNode.Add(node);
                    StorytellController.StepStruct tmpStep = new StorytellController.StepStruct();
                    tmpStep.id              = node.nodeId;
                    tmpStep.nameStep        = node.nodeName;
                    tmpStep.descriptionStep = node.nodeDescription;
                    tmpStep.rectangle       = node.rectangle;
                    tmpStep.heightWindow    = node.heightWindow;
                    tmpStep.parentId        = node.parentId;
                    List <StorytellController.ConsequenceStruct> consList = new List <StorytellController.ConsequenceStruct>();

                    foreach (ConsequenceStructUI cons in node.consequences)
                    {
                        StorytellController.ConsequenceStruct tcons = new StorytellController.ConsequenceStruct();
                        tcons.type    = optionsConsequences[cons.popupPos];
                        tcons.integer = cons.integer;
                        string TobjArt;

                        if (cons.objectAtr == null)
                        {
                            TobjArt = "null";
                        }
                        else
                        {
                            TobjArt = cons.objectAtr.name;
                        }

                        tcons.primaryAtribute   = TobjArt;
                        tcons.secondaryAtribute = cons.primString;
                        //New
                        tcons.popupPos  = cons.popupPos;
                        tcons.objectAtr = cons.objectAtr;

                        consList.Add(tcons);
                    }

                    tmpStep.consequences = consList;
                    List <StorytellController.ConditionStruct> condList = new List <StorytellController.ConditionStruct>();

                    foreach (ConditionStructUI cond in node.conditions)
                    {
                        StorytellController.ConditionStruct tcond = new StorytellController.ConditionStruct();
                        tcond.nextId = cond.nextId;
                        tcond.type   = optionsConditions[cond.popupPos];
                        tcond.time   = cond.time;
                        string target;

                        if (cond.target == null)
                        {
                            target = "null";
                        }
                        else
                        {
                            target = cond.target.name;
                        }

                        tcond.target = target;
                        //New
                        tcond.popupPos  = cond.popupPos;
                        tcond.objTarget = cond.target;
                        tcond.color     = cond.color;

                        condList.Add(tcond);
                    }

                    tmpStep.conditions = condList;
                    stepList.Add(tmpStep);
                }
                StorytellController smg = GameObject.Find("Controller").GetComponent <StorytellController>() as StorytellController;
                smg.listSteps = stepList;
                text          = "Create your Storytell:";
            }
            else   //Still some prenodes without assign
            {
                text = "Create your Storytell: Assign all steps";
            }
        }

        EditorGUILayout.EndHorizontal();
        BeginWindows();

        foreach (int key in keysN)
        {
            NodeStruct node = nodeSet[key];

            foreach (ConditionStructUI cond in node.conditions)
            {
                int chId = cond.nextId;
                if (nodeSet.ContainsKey(chId) || prenodeSet.ContainsKey(chId))
                {
                    DrawLine(chId, node.nodeId, cond.color);
                }
            }

            node.rectangle        = SetRectangle(node.rectangle);
            node.rectangle        = GUI.Window(node.nodeId, node.rectangle, WindowFunction, "" + node.nodeId);
            node.rectangle.height = node.heightWindow;
            nodeSet[key]          = node;
        }

        List <int> keysP = new List <int>(prenodeSet.Keys);

        foreach (int key in keysP)
        {
            PrenodeStruct prenode = prenodeSet[key];
            prenode.rectangle = SetRectangle(prenode.rectangle);
            prenode.rectangle = GUI.Window(prenode.nodeId, prenode.rectangle, WindowFunctionPreNode, "Create Node");
            prenodeSet[key]   = prenode;
        }

        EndWindows();
    }
Exemplo n.º 3
0
    void WindowFunction(int windowID)
    {
        if (nodeSet.ContainsKey(windowID))
        {
            NodeStruct tmpNode = nodeSet[windowID];
            GUI.DragWindow(new Rect(0, 0, width, heightElements));

            EditorGUILayout.BeginHorizontal();
            tmpNode.nodeName = EditorGUILayout.TextField(nodeSet[windowID].nodeName);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            tmpNode.nodeDescription = EditorGUILayout.TextField(nodeSet[windowID].nodeDescription);
            EditorGUILayout.EndHorizontal();

            for (int i = 0; i < tmpNode.consequences.Count; i++)
            {
                ConsequenceStructUI cons = tmpNode.consequences[i];
                int oldPos = cons.popupPos;

                EditorGUILayout.BeginHorizontal();
                cons.popupPos = EditorGUILayout.Popup(cons.popupPos, optionsConsequences);
                if (oldPos != cons.popupPos)
                {
                    if (oldPos == 6 || oldPos == 7)
                    {
                        tmpNode.heightWindow -= 20f;
                    }
                    if (cons.popupPos == 6 || cons.popupPos == 7)
                    {
                        tmpNode.heightWindow += 20f;
                        cons.primString       = "ComponentName";
                    }

                    if (cons.popupPos == 3 || cons.popupPos == 2)
                    {
                        tmpNode.heightWindow += 20f;
                        cons.primString       = "Reason";
                    }
                }

                if (cons.popupPos < 2)
                {
                    cons.integer = EditorGUILayout.IntField(cons.integer); //Timer
                    if (cons.integer < 0)
                    {
                        cons.integer = 0;
                    }
                }
                else if (cons.popupPos < 4)
                {
                    cons.primString = EditorGUILayout.TextField(cons.primString);                         //Finish
                }
                else if (cons.popupPos < 6)
                {
                    cons.objectAtr = EditorGUILayout.ObjectField(cons.objectAtr, typeof(Object), true);                         //Interact
                }
                else if (cons.popupPos < 8)
                {
                    //Touch
                    cons.objectAtr = EditorGUILayout.ObjectField(cons.objectAtr, typeof(Object), true);
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    cons.primString = EditorGUILayout.TextField(cons.primString);
                }

                EditorGUILayout.EndHorizontal();
                tmpNode.consequences[i] = cons;
            }

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Add Consequence"))
            {
                ConsequenceStructUI tmpCs = new ConsequenceStructUI();
                tmpCs.popupPos   = 0;
                tmpCs.integer    = 1;
                tmpCs.objectAtr  = null;
                tmpCs.primString = "null2";
                tmpNode.consequences.Add(tmpCs);
                tmpNode.consequenceId = tmpNode.consequenceId + 1;
                tmpNode.heightWindow += 20f;
            }

            EditorGUILayout.EndHorizontal();

            for (int i = 0; i < tmpNode.conditions.Count; i++)
            {
                ConditionStructUI cond   = tmpNode.conditions[i];
                GUIStyle          gsTest = new GUIStyle();
                gsTest.normal.textColor = colors[i % colors.Length];
                EditorGUILayout.BeginHorizontal();
                cond.popupPos = EditorGUILayout.Popup(cond.popupPos, optionsConditions, gsTest);

                if (cond.popupPos == 0)
                {
                    cond.time = EditorGUILayout.IntField(cond.time);
                    if (cond.time < 0)
                    {
                        cond.time = 0;
                    }
                }
                else if (cond.popupPos == 1)
                {
                    cond.target = EditorGUILayout.ObjectField(cond.target, typeof(Object), true);
                }
                else if (cond.popupPos == 2)
                {
                    cond.target = EditorGUILayout.ObjectField(cond.target, typeof(Object), true);
                }

                EditorGUILayout.EndHorizontal();
                tmpNode.conditions[i] = cond;
            }

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Add Condition"))
            {
                ConditionStructUI tmpC = new ConditionStructUI();
                tmpC.popupPos = 0;
                tmpC.nextId   = temporalId + 1;
                ++temporalId;
                tmpC.time             = 1;
                tmpC.target           = null;
                tmpNode.consequenceId = tmpNode.conditionId + 1;
                tmpC.color            = colors[tmpNode.conditionId % colors.Length];
                tmpNode.conditions.Add(tmpC);
                tmpNode.heightWindow += 20f;
                CreatePrenode(windowID, tmpC.nextId, tmpNode.conditionId);
                tmpNode.conditionId++;
            }

            EditorGUILayout.EndHorizontal();
            nodeSet[windowID] = tmpNode;
        }
    }