private static void LayoutConditionSelectionUI(DialogueNode node)
        {
            int conditionSize = node.GetConditionSize();

            for (int k = 0; k < conditionSize; k++)
            {
                bool foldout = node.GetFoldout(k);
                node.SetFold(EditorGUILayout.BeginFoldoutHeaderGroup(foldout, $"Condition Group {k}"), k);
                if (foldout)
                {
                    ConditionPredicate[] predicates = node.GetConditionPredicates(k).ToArray();
                    for (int i = 0; i < predicates.Length; i++)
                    {
                        GUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("Condition:", GUILayout.Width(60));
                        ConditionPredicate newPredicate = (ConditionPredicate)EditorGUILayout.EnumPopup(predicates[i]);
                        node.SetConditionPredicate(newPredicate, k, i);
                        if (GUILayout.Button("-"))
                        {
                            node.RemoveCondition(k, i);
                            conditionSize = node.GetConditionSize();
                        }
                        GUILayout.EndHorizontal();

                        List <string> parameterList = new List <string>();
                        int           removeCount   = 1;

                        if (newPredicate == ConditionPredicate.None)
                        {
                        }
                        else if (newPredicate == ConditionPredicate.HasQuest)
                        {
                            EditorQuestSelect(node, parameterList, k, i);
                        }
                        else if (newPredicate == ConditionPredicate.CompleteQuest)
                        {
                            EditorQuestSelect(node, parameterList, k, i);
                        }
                        else if (newPredicate == ConditionPredicate.CompleteObjective)
                        {
                            string[] objectiveList = node.GetParameters(k, i).ToArray();
                            if (objectiveList.Length > 0)
                            {
                                Quest questSelect = GenerateQuestSelect(objectiveList[0]);
                                if (questSelect != null)
                                {
                                    parameterList.Add(questSelect.name);
                                }
                                else
                                {
                                    parameterList.Add("");
                                }
                                for (int j = 1; j < objectiveList.Length; j++)
                                {
                                    GUILayout.BeginHorizontal();
                                    EditorGUILayout.LabelField("Objective:", GUILayout.Width(58));
                                    if (questSelect != null)
                                    {
                                        string[] questObjectives = questSelect.GetObjectives().ToArray();
                                        int      objectiveIndex  = EditorGUILayout.Popup(node.GetObjectiveIndex(k, i), questObjectives);
                                        node.SetObjectiveIndex(objectiveIndex, k, i);
                                        parameterList.Add(questObjectives[objectiveIndex]);
                                    }
                                    else
                                    {
                                        EditorGUILayout.Popup(0, new string[] { "" });
                                        parameterList.Add("");
                                    }
                                    GUILayout.EndHorizontal();
                                }
                            }
                        }
                        else if (newPredicate == ConditionPredicate.HasItem)
                        {
                            removeCount = 2;
                            string[] itemList = node.GetParameters(k, i).ToArray();
                            if (itemList.Length > 0)
                            {
                                for (int j = 0; j < itemList.Length; j++)
                                {
                                    InventoryItem item = InventoryItem.GetFromID(itemList[j]);
                                    item = GenerateItemSelect(item);
                                    j++;
                                    if (item != null)
                                    {
                                        parameterList.Add(item.GetItemID());
                                        if (j < itemList.Length)
                                        {
                                            parameterList.Add(GenerateItemCountField(itemList[j]).ToString());
                                        }
                                        else
                                        {
                                            parameterList.Add("");
                                        }
                                    }
                                    else
                                    {
                                        parameterList.Add("");
                                    }
                                }
                            }
                        }
                        GUILayout.BeginHorizontal();
                        if (GUILayout.Button("Add"))
                        {
                            parameterList.Add("");
                        }
                        if (GUILayout.Button("Remove"))
                        {
                            for (int j = 0; j < removeCount; j++)
                            {
                                parameterList.RemoveAt(parameterList.Count() - 1);
                            }
                        }
                        node.SetConditionNegate(EditorGUILayout.Toggle(node.GetConditionNegate(k, i)), k, i);
                        EditorGUILayout.LabelField("Negate", GUILayout.Width(74));
                        if (GUILayout.Button("New"))
                        {
                            node.AddNewCondition(k);
                        }
                        GUILayout.EndHorizontal();

                        node.SetConditionParameters(parameterList, k, i);
                    }
                }
                EditorGUILayout.EndFoldoutHeaderGroup();
            }
        }
Exemplo n.º 2
0
        private static void LayoutConditionSelectionUI(DialogueNode node)
        {
            int conditionSize = node.GetConditionSize();

            for (int k = 0; k < conditionSize; k++)
            {
                bool foldout = node.GetFoldout(k);
                node.SetFold(EditorGUILayout.BeginFoldoutHeaderGroup(foldout, $"Condition Group {k}"), k);
                if (foldout)
                {
                    ConditionPredicate[] predicates = node.GetConditionPredicates(k).ToArray();
                    for (int i = 0; i < predicates.Length; i++)
                    {
                        GUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("Condition:", GUILayout.Width(60));
                        ConditionPredicate newPredicate = (ConditionPredicate)EditorGUILayout.EnumPopup(predicates[i]);
                        node.SetConditionPredicate(newPredicate, k, i);
                        if (GUILayout.Button("-"))
                        {
                            node.RemoveCondition(k, i);
                            conditionSize = node.GetConditionSize();
                        }
                        GUILayout.EndHorizontal();

                        List <string> parameterList = new List <string>();
                        int           removeCount   = 1;

                        if (newPredicate == ConditionPredicate.None)
                        {
                        }
                        // else if (newPredicate == ConditionPredicate.HasItem)
                        // {
                        //     removeCount = 2;
                        //     string[] itemList = node.GetParameters(k, i).ToArray();
                        //     if (itemList.Length > 0)
                        //     {
                        //         for (int j = 0; j < itemList.Length; j++)
                        //         {
                        //             InventoryItem item = InventoryItem.GetFromID(itemList[j]);
                        //             item = GenerateItemSelect(item);
                        //             j++;
                        //             if (item != null)
                        //             {
                        //                 parameterList.Add(item.GetItemID());
                        //                 if (j < itemList.Length)
                        //                 {
                        //                     parameterList.Add(GenerateItemCountField(itemList[j]));
                        //                 }
                        //                 else
                        //                 {
                        //                     parameterList.Add("");
                        //                 }
                        //             }
                        //             else
                        //             {
                        //                 parameterList.Add("");
                        //             }
                        //         }
                        //     }

                        // }
                        GUILayout.BeginHorizontal();
                        if (GUILayout.Button("Add"))
                        {
                            parameterList.Add("");
                        }
                        if (GUILayout.Button("Remove"))
                        {
                            for (int j = 0; j < removeCount; j++)
                            {
                                parameterList.RemoveAt(parameterList.Count() - 1);
                            }
                        }
                        node.SetConditionNegate(EditorGUILayout.Toggle(node.GetConditionNegate(k, i)), k, i);
                        EditorGUILayout.LabelField("Negate", GUILayout.Width(74));
                        if (GUILayout.Button("New"))
                        {
                            node.AddNewCondition(k);
                        }
                        GUILayout.EndHorizontal();

                        node.SetConditionParameters(parameterList, k, i);
                    }
                }
                EditorGUILayout.EndFoldoutHeaderGroup();
            }
        }