Beispiel #1
0
    private void OnEnable()
    {
        questCache  = Resources.LoadAll <Quest>("Configuration");
        quest       = target as Quest;
        talkerCache = Resources.LoadAll <TalkerInformation>("Configuration").Where(x => x.Enable).ToArray();
        holder      = talkerCache.FirstOrDefault(x => x.QuestsStored.Contains(quest));
        itemCache   = Resources.LoadAll <ItemBase>("Configuration");

        lineHeight            = EditorGUIUtility.singleLineHeight;
        lineHeightSpace       = lineHeight + 2;
        _ID                   = serializedObject.FindProperty("_ID");
        title                 = serializedObject.FindProperty("title");
        description           = serializedObject.FindProperty("description");
        abandonable           = serializedObject.FindProperty("abandonable");
        group                 = serializedObject.FindProperty("group");
        questType             = serializedObject.FindProperty("questType");
        repeatFrequancy       = serializedObject.FindProperty("repeatFrequancy");
        timeUnit              = serializedObject.FindProperty("timeUnit");
        acceptCondition       = serializedObject.FindProperty("acceptCondition");
        beginDialogue         = serializedObject.FindProperty("beginDialogue");
        ongoingDialogue       = serializedObject.FindProperty("ongoingDialogue");
        completeDialogue      = serializedObject.FindProperty("completeDialogue");
        rewardItems           = serializedObject.FindProperty("rewardItems");
        _NPCToSubmit          = serializedObject.FindProperty("_NPCToSubmit");
        cmpltObjctvInOrder    = serializedObject.FindProperty("cmpltObjctvInOrder");
        objectives            = serializedObject.FindProperty("objectives");
        groupSelector         = new ObjectSelectionDrawer <QuestGroup>(group, "_name", "", "归属组", "无");
        npcSelector           = new ObjectSelectionDrawer <TalkerInformation>(_NPCToSubmit, "_name", talkerCache, "在此NPC处提交", "接取处NPC");
        acceptConditionDrawer = new ConditionGroupDrawer(serializedObject, acceptCondition, lineHeight, lineHeightSpace, "接取条件列表");
        rewardDrawer          = new ItemAmountListDrawer(serializedObject, rewardItems, lineHeight, lineHeightSpace, "奖励列表");
        HandlingObjectiveList();
        showState = new AnimBool(objectives.isExpanded);
        AddAnimaListener(OnAnima);
    }
Beispiel #2
0
    void HandlingConditionDialogueList()
    {
        conditionDialogList = new ReorderableList(serializedObject, conditionDialogues, true, true, true, true)
        {
            drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                serializedObject.UpdateIfRequiredOrScript();
                EditorGUI.BeginChangeCheck();
                SerializedProperty conditionDialogue = conditionDialogues.GetArrayElementAtIndex(index);
                SerializedProperty dialogue          = conditionDialogue.FindPropertyRelative("dialogue");
                SerializedProperty condition         = conditionDialogue.FindPropertyRelative("condition");
                EditorGUI.PropertyField(new Rect(rect.x + 8, rect.y, rect.width / 2, lineHeight),
                                        conditionDialogue, new GUIContent("触发对话" + (conditionDialogue.isExpanded ? string.Empty : "(展开填写条件)")), false);
                EditorGUI.PropertyField(new Rect(rect.x + 8 + rect.width / 2, rect.y, rect.width / 2 - 8, lineHeight),
                                        dialogue, new GUIContent(string.Empty));
                int lineCount = 1;
                if (dialogue.objectReferenceValue)
                {
                    Dialogue dialog = dialogue.objectReferenceValue as Dialogue;
                    if (dialog.Words[0])
                    {
                        GUI.enabled = false;
                        EditorGUI.TextField(new Rect(rect.x, rect.y + lineHeightSpace * lineCount, rect.width, lineHeight), $"[{dialog.Words[0].TalkerName}]说:{dialog.Words[0].Content}");
                        GUI.enabled = true;
                        lineCount++;
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
                if (conditionDialogue.isExpanded)
                {
                    if (!conditionDrawers.TryGetValue(talker.ConditionDialogues[index], out var drawer))
                    {
                        drawer = new ConditionGroupDrawer(conditionDialogue.serializedObject, condition, lineHeight, lineHeightSpace);
                        conditionDrawers.Add(talker.ConditionDialogues[index], drawer);
                    }
                    serializedObject.UpdateIfRequiredOrScript();
                    drawer.DoDraw(new Rect(rect.x, rect.y + lineHeightSpace * lineCount, rect.width, lineHeight));
                    serializedObject.ApplyModifiedProperties();
                }
            },

            elementHeightCallback = (index) =>
            {
                SerializedProperty conditionDialogue = conditionDialogues.GetArrayElementAtIndex(index);
                SerializedProperty dialogue          = conditionDialogue.FindPropertyRelative("dialogue");
                int lineCount = 1;
                if (dialogue.objectReferenceValue)
                {
                    lineCount++;
                }
                float listHeight = 0;
                if (conditionDialogue.isExpanded)
                {
                    if (conditionDrawers.TryGetValue(talker.ConditionDialogues[index], out var drawer))
                    {
                        listHeight = drawer.GetDrawHeight();
                    }
                }
                return(lineHeightSpace * lineCount + listHeight);
            },

            onRemoveCallback = (list) =>
            {
                serializedObject.UpdateIfRequiredOrScript();
                EditorGUI.BeginChangeCheck();
                if (EditorUtility.DisplayDialog("删除", "确定删除这个对话吗?", "确定", "取消"))
                {
                    conditionDrawers.Remove(talker.ConditionDialogues[list.index]);
                    conditionDialogues.DeleteArrayElementAtIndex(list.index);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
            },

            onCanRemoveCallback = (list) =>
            {
                return(list.IsSelected(list.index));
            },

            drawHeaderCallback = (rect) =>
            {
                int notCmpltCount = talker.ConditionDialogues.FindAll(x => !x.Dialogue ||
                                                                      x.Condition.Conditions.Exists(x => (x.Type == ConditionType.AcceptQuest || x.Type == ConditionType.CompleteQuest) && !x.RelatedQuest ||
                                                                                                    x.Type == ConditionType.HasItem && !x.RelatedItem || (x.Type == ConditionType.TriggerSet || x.Type == ConditionType.TriggerReset) && string.IsNullOrEmpty(x.TriggerName))).Count;
                EditorGUI.LabelField(rect, "条件对话列表", notCmpltCount > 0 ? "未补全:" + notCmpltCount : string.Empty);
            },

            drawNoneElementCallback = (rect) =>
            {
                EditorGUI.LabelField(rect, "空列表");
            }
        };
    }

    void HandlingGiftDialogueList()
    {
        giftDialoguesList = new ReorderableList(serializedObject, giftDialogues, true, true, true, true)
        {
            drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                serializedObject.UpdateIfRequiredOrScript();
                EditorGUI.BeginChangeCheck();
                SerializedProperty giftDialogue = giftDialogues.GetArrayElementAtIndex(index);
                SerializedProperty dialogue     = giftDialogue.FindPropertyRelative("dialogue");
                SerializedProperty lowerBound   = giftDialogue.FindPropertyRelative("lowerBound");
                SerializedProperty upperBound   = giftDialogue.FindPropertyRelative("upperBound");
                EditorGUI.PropertyField(new Rect(rect.x + 8, rect.y, rect.width / 2, lineHeight),
                                        giftDialogue, new GUIContent($"对话[{lowerBound.intValue}~{upperBound.intValue}]"));
                EditorGUI.PropertyField(new Rect(rect.x + 8 + rect.width / 2, rect.y, rect.width / 2 - 8, lineHeight),
                                        dialogue, new GUIContent(string.Empty));
                int lineCount = 1;
                if (dialogue.objectReferenceValue)
                {
                    Dialogue dialog = dialogue.objectReferenceValue as Dialogue;
                    if (dialog.Words[0])
                    {
                        GUI.enabled = false;
                        EditorGUI.TextField(new Rect(rect.x, rect.y + lineHeightSpace * lineCount, rect.width, lineHeight), $"[{dialog.Words[0].TalkerName}]说:{dialog.Words[0].Content}");
                        GUI.enabled = true;
                        lineCount++;
                    }
                }
                if (giftDialogue.isExpanded)
                {
                    EditorGUI.PropertyField(new Rect(rect.x, rect.y + lineHeightSpace * lineCount, rect.width, lineHeight),
                                            lowerBound, new GUIContent("增加值高于此值时"));
                    lineCount++;
                    EditorGUI.PropertyField(new Rect(rect.x, rect.y + lineHeightSpace * lineCount, rect.width, lineHeight),
                                            upperBound, new GUIContent("增加值低于此值时"));
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
            },

            elementHeightCallback = (index) =>
            {
                SerializedProperty giftDialogue = giftDialogues.GetArrayElementAtIndex(index);
                SerializedProperty dialogue     = giftDialogue.FindPropertyRelative("dialogue");
                int lineCount = 2;
                if (giftDialogue.isExpanded)
                {
                    lineCount++;
                    if (dialogue.objectReferenceValue)
                    {
                        lineCount++;
                    }
                }
                return(lineHeightSpace * lineCount);
            },

            onRemoveCallback = (list) =>
            {
                serializedObject.UpdateIfRequiredOrScript();
                EditorGUI.BeginChangeCheck();
                if (EditorUtility.DisplayDialog("删除", "确定删除这个对话吗?", "确定", "取消"))
                {
                    giftDialogues.DeleteArrayElementAtIndex(list.index);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
            },

            onCanRemoveCallback = (list) =>
            {
                return(list.IsSelected(list.index));
            },

            drawHeaderCallback = (rect) =>
            {
                int notCmpltCount = talker.AffectiveItems.FindAll(x => !x.Item).Count;
                EditorGUI.LabelField(rect, "送礼对话列表", notCmpltCount > 0 ? "未补全:" + notCmpltCount : string.Empty);
            },

            drawNoneElementCallback = (rect) =>
            {
                EditorGUI.LabelField(rect, "空列表");
            }
        };
    }

    void HandlingAffectiveItemsList()
    {
        affectiveItemsList = new ReorderableList(serializedObject, affectiveItems, true, true, true, true)
        {
            drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                serializedObject.UpdateIfRequiredOrScript();
                if (talker.AffectiveItems[index].Item != null)
                {
                    EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width, lineHeight), talker.AffectiveItems[index].Item.Name);
                }
                else
                {
                    EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width, lineHeight), "(空)");
                }
                EditorGUI.BeginChangeCheck();
                SerializedProperty favoriteItem  = affectiveItems.GetArrayElementAtIndex(index);
                SerializedProperty item          = favoriteItem.FindPropertyRelative("item");
                SerializedProperty intimacyValue = favoriteItem.FindPropertyRelative("intimacyValue");
                EditorGUI.PropertyField(new Rect(rect.x + rect.width / 2f, rect.y, rect.width / 2f, lineHeight),
                                        item, new GUIContent(string.Empty));
                EditorGUI.PropertyField(new Rect(rect.x, rect.y + lineHeightSpace, rect.width, lineHeight),
                                        intimacyValue, new GUIContent("亲密值"));
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
            },

            elementHeightCallback = (index) =>
            {
                return(2 * lineHeightSpace);
            },

            onRemoveCallback = (list) =>
            {
                serializedObject.UpdateIfRequiredOrScript();
                EditorGUI.BeginChangeCheck();
                if (EditorUtility.DisplayDialog("删除", "确定删除这个道具吗?", "确定", "取消"))
                {
                    affectiveItems.DeleteArrayElementAtIndex(list.index);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
            },

            onCanRemoveCallback = (list) =>
            {
                return(list.IsSelected(list.index));
            },

            drawHeaderCallback = (rect) =>
            {
                int notCmpltCount = talker.AffectiveItems.FindAll(x => !x.Item).Count;
                EditorGUI.LabelField(rect, "亲密值道具列表", notCmpltCount > 0 ? "未补全:" + notCmpltCount : string.Empty);
            },

            drawNoneElementCallback = (rect) =>
            {
                EditorGUI.LabelField(rect, "空列表");
            }
        };
    }

    void HandlingQuestList()
    {
        questList = new ReorderableList(serializedObject, questsStored, true, true, true, true)
        {
            drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                serializedObject.UpdateIfRequiredOrScript();
                SerializedProperty quest = questsStored.GetArrayElementAtIndex(index);
                if (quest.objectReferenceValue != null)
                {
                    EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width, lineHeight), talker.QuestsStored[index].Title);
                    if (GUI.Button(new Rect(rect.x + rect.width * 0.8f, rect.y, rect.width * 0.2f, lineHeight), "编辑"))
                    {
                        EditorUtility.OpenPropertyEditor(quest.objectReferenceValue);
                    }
                }
                else
                {
                    EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width, lineHeight), "(空)");
                    if (GUI.Button(new Rect(rect.x + rect.width * 0.8f, rect.y, rect.width * 0.2f, lineHeight), "新建"))
                    {
                        Quest questInstance = ZetanUtility.Editor.SaveFilePanel(CreateInstance <Quest>, "quest", ping: true);
                        if (questInstance)
                        {
                            quest.objectReferenceValue = questInstance;
                            SerializedObject   newQuest = new SerializedObject(quest.objectReferenceValue);
                            SerializedProperty _ID      = newQuest.FindProperty("_ID");
                            SerializedProperty title    = newQuest.FindProperty("title");
                            _ID.stringValue   = Quest.GetAutoID();
                            title.stringValue = $"{_name.stringValue}的委托";
                            newQuest.ApplyModifiedProperties();

                            EditorUtility.OpenPropertyEditor(questInstance);
                        }
                    }
                }
                EditorGUI.BeginChangeCheck();
                Quest qBef = quest.objectReferenceValue as Quest;
                EditorGUI.PropertyField(new Rect(rect.x, rect.y + lineHeightSpace, rect.width, lineHeight), quest, new GUIContent(string.Empty));
                if (qBef != quest.objectReferenceValue as Quest && talker.QuestsStored.Contains(quest.objectReferenceValue as Quest))
                {
                    EditorUtility.DisplayDialog("错误", "已添加该任务。", "确定");
                    quest.objectReferenceValue = qBef;
                }
                else
                {
                    var conflictTalker = allTalkers.Find(x => x.QuestsStored.Count > 0 && x.QuestsStored.Contains(quest.objectReferenceValue as Quest));
                    if (conflictTalker && conflictTalker != talker)
                    {
                        EditorUtility.DisplayDialog("错误", "[" + conflictTalker.Name + "]已使用该任务,无法添加。", "确定");
                        quest.objectReferenceValue = qBef;
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
            },

            elementHeightCallback = (int index) =>
            {
                return(2 * lineHeightSpace);
            },

            onAddCallback = (list) =>
            {
                serializedObject.UpdateIfRequiredOrScript();
                EditorGUI.BeginChangeCheck();
                if (list.index + 1 < talker.QuestsStored.Count)
                {
                    talker.QuestsStored.Insert(list.index + 1, null);
                }
                else
                {
                    talker.QuestsStored.Add(null);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
            },

            onRemoveCallback = (list) =>
            {
                serializedObject.UpdateIfRequiredOrScript();
                EditorGUI.BeginChangeCheck();
                if (EditorUtility.DisplayDialog("删除", "确定删除这个任务吗?", "确定", "取消"))
                {
                    talker.QuestsStored.RemoveAt(list.index);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
            },

            onCanRemoveCallback = (list) =>
            {
                return(list.IsSelected(list.index));
            },

            drawHeaderCallback = (rect) =>
            {
                int notCmpltCount = talker.QuestsStored.FindAll(x => !x).Count;
                EditorGUI.LabelField(rect, "任务列表", "数量:" + talker.QuestsStored.Count + (notCmpltCount > 0 ? "\t未补全:" + notCmpltCount : string.Empty));
            },

            drawNoneElementCallback = (rect) =>
            {
                EditorGUI.LabelField(rect, "空列表");
            }
        };
    }
}