private bool ValidDrag(TreeViewItem parentItem, TreeViewItem draggedItem)
        {
            IDialogueItem draggedItemInstance = this.dialogueEditor.InstanceIDToObject(draggedItem.id);
            IDialogueItem parentItemInstance  = this.dialogueEditor.InstanceIDToObject(parentItem.id);

            if (draggedItemInstance == null || parentItemInstance == null)
            {
                return(false);
            }
            if (!draggedItemInstance.CanHaveParent(parentItemInstance))
            {
                return(false);
            }

            TreeViewItem currentParent = parentItem;

            while (currentParent != null)
            {
                if (draggedItem == currentParent)
                {
                    return(false);
                }
                currentParent = currentParent.parent;
            }

            return(true);
        }
        private void BuildTree(ref TreeViewItem parentTree, IDialogueItem parentAsset)
        {
            this.treeItems.Add(parentAsset.GetInstanceID(), parentTree);

            IDialogueItemEditor editor = this.dialogueEditor.itemsEditors[parentAsset.GetInstanceID()];

            parentTree.displayName = editor.UpdateContent();
            parentTree.icon        = editor.UpdateIcon();

            List <IDialogueItem> childrenAssets = parentAsset.children;
            int childrenAssetsCount             = childrenAssets.Count;

            for (int i = 0; i < childrenAssetsCount; ++i)
            {
                IDialogueItem childAsset = childrenAssets[i];
                if (childAsset == null)
                {
                    continue;
                }

                int          childAssetID = childAsset.GetInstanceID();
                int          depth        = parentTree.depth + 1;
                TreeViewItem childTree    = new TreeViewItem(childAssetID, depth, "Loading...");

                if (!this.dialogueEditor.itemsEditors.ContainsKey(childAssetID))
                {
                    Debug.LogError("No IDialogueItem Editor found with instanceID: " + childAssetID);
                    continue;
                }

                this.BuildTree(ref childTree, childAsset);
                parentTree.AddChild(childTree);
            }
        }
Example #3
0
        public void AddChild(IDialogueItem item, IDialogueItem parent, Dialogue dialogue)
        {
            serializedObject.ApplyModifiedPropertiesWithoutUndo();
            serializedObject.Update();

            if (parent == null)
            {
                Debug.LogError("Adding null parent");
                return;
            }

            SerializedProperty children = serializedObject.FindProperty(PROP_CHILDREN);
            int index = children.arraySize;

            SerializedObject childSerializedObject = new SerializedObject(item);

            childSerializedObject.FindProperty(PROP_DIALOGUE).objectReferenceValue = dialogue;
            childSerializedObject.FindProperty(PROP_PARENT).objectReferenceValue   = parent;
            childSerializedObject.ApplyModifiedPropertiesWithoutUndo();
            childSerializedObject.Update();

            children.InsertArrayElementAtIndex(index);
            SerializedProperty child = children.GetArrayElementAtIndex(index);

            child.objectReferenceValue = item;

            serializedObject.ApplyModifiedPropertiesWithoutUndo();
            serializedObject.Update();
        }
Example #4
0
 public override bool CanHaveParent(IDialogueItem parent)
 {
     if (parent.GetType() == typeof(DialogueItemChoiceGroup))
     {
         return(false);
     }
     return(base.CanHaveParent(parent));
 }
        public static void AddElement(DialogueEditor dialogueEditor)
        {
            List <int> selections = new List <int> {
                dialogueEditor.editorRoot.target.GetInstanceID()
            };
            List <int> nextSelections = new List <int>();

            if (dialogueEditor.dialogueTree.HasSelection())
            {
                selections = new List <int>(dialogueEditor.dialogueTree.GetSelection());
            }

            for (int i = 0; i < selections.Count; ++i)
            {
                int selectionID             = selections[i];
                UnityEngine.Object instance = dialogueEditor.InstanceIDToObject(selectionID);
                dialogueEditor.dialogueTree.SetExpandedRecursive(selectionID, true);

                IDialogueItem itemInstance = dialogueEditor.CreateDialogueItem <DialogueItemChoice>();
                nextSelections.Add(itemInstance.GetInstanceID());

                if (instance != null && instance.GetType() == typeof(DialogueItemChoiceGroup))
                {
                    dialogueEditor.itemsEditors[selectionID].AddChild(
                        itemInstance,
                        (IDialogueItem)instance,
                        dialogueEditor.targetDialogue
                        );
                }
                else if (instance != null && instance.GetType() == typeof(DialogueItemChoice))
                {
                    dialogueEditor.itemsEditors[selectionID].AddSibling(
                        itemInstance,
                        (IDialogueItem)instance,
                        dialogueEditor.targetDialogue,
                        selectionID
                        );
                }
                else
                {
                    Debug.LogError("Forbidden or Unknown type: " + instance.GetType());
                }

                dialogueEditor.itemsEditors.Add(
                    itemInstance.GetInstanceID(),
                    IDialogueItemEditor.CreateEditor(itemInstance)
                    );

                dialogueEditor.dialogueTree.Reload();

                dialogueEditor.serializedObject.ApplyModifiedPropertiesWithoutUndo();
                dialogueEditor.serializedObject.Update();
            }

            dialogueEditor.dialogueTree.SetFocusAndEnsureSelectedItem();
            dialogueEditor.dialogueTree.SetSelection(nextSelections, TreeViewSelectionOptions.RevealAndFrame);
        }
Example #6
0
        public static string GetContent(IDialogueItem item)
        {
            string content = item.content.content;

            if (string.IsNullOrEmpty(content))
            {
                return("[ Empty Message ]");
            }
            return(content.Replace("\n", " "));
        }
Example #7
0
        // PUBLIC METHODS: ------------------------------------------------------------------------

        public IEnumerator Run()
        {
            Stack <IDialogueItem> stackItems = new Stack <IDialogueItem>();

            stackItems.Push(this.dialogue);

            while (stackItems.Count > 0)
            {
                IDialogueItem item = stackItems.Pop();
                yield return(item.Run());

                if (item.afterRun == IDialogueItem.AfterRunBehaviour.Jump && item.jumpTo != null)
                {
                    stackItems.Clear();

                    int jumpToID = item.jumpTo.GetInstanceID();
                    List <IDialogueItem> parentChildren = item.jumpTo.parent.children;
                    int parentChildrenCount             = parentChildren.Count;

                    for (int i = parentChildrenCount - 1; i >= 0; --i)
                    {
                        if (parentChildren[i] == null)
                        {
                            continue;
                        }
                        stackItems.Push(parentChildren[i]);
                        if (parentChildren[i].GetInstanceID() == jumpToID)
                        {
                            break;
                        }
                    }
                }
                else if (item.afterRun == IDialogueItem.AfterRunBehaviour.Exit)
                {
                    stackItems.Clear();
                    yield break;
                }
                else
                {
                    IDialogueItem[] childItems = item.GetNextItem();
                    if (childItems != null)
                    {
                        int numChildItems = childItems.Length;
                        for (int i = numChildItems - 1; i >= 0; --i)
                        {
                            if (childItems[i] == null)
                            {
                                continue;
                            }
                            stackItems.Push(childItems[i]);
                        }
                    }
                }
            }
        }
Example #8
0
        // PUBLIC METHODS: ------------------------------------------------------------------------

        public void Add(IDialogueItem item, bool isChoice)
        {
            Log log = new Log(
                item.GetContent(),
                isChoice,
                item.actor,
                item.actorSpriteIndex
                );

            this.logs.Add(log);
            this.eventAdd.Invoke(log);
        }
Example #9
0
        protected void OnEnableBase()
        {
            this.targetItem = (IDialogueItem)target;

            this.spDialogue = this.serializedObject.FindProperty(PROP_DIALOGUE);
            this.spParent   = this.serializedObject.FindProperty(PROP_PARENT);
            this.spChildren = serializedObject.FindProperty(PROP_CHILDREN);

            this.spConfig         = this.serializedObject.FindProperty(PROP_CONFIG);
            this.spOverrideConfig = this.serializedObject.FindProperty(PROP_OVERR_CONFIG);

            this.spExecuteBehavior = serializedObject.FindProperty(PROP_EXECUTE_BEHAVIOR);

            this.spActionsList = serializedObject.FindProperty(PROP_ACTIONS);
            if (this.spActionsList.objectReferenceValue == null)
            {
                IActionsList actionsList = this.targetItem.gameObject.AddComponent <IActionsList>();
                actionsList.hideFlags = HideFlags.HideInInspector;

                this.spActionsList.objectReferenceValue = actionsList;
                serializedObject.ApplyModifiedPropertiesWithoutUndo();
                serializedObject.Update();
            }

            this.spConditionList = serializedObject.FindProperty(PROP_CONDITIONS);
            if (this.spConditionList.objectReferenceValue == null)
            {
                IConditionsList conditionList = this.targetItem.gameObject.AddComponent <IConditionsList>();
                conditionList.hideFlags = HideFlags.HideInInspector;

                this.spConditionList.objectReferenceValue = conditionList;
                serializedObject.ApplyModifiedPropertiesWithoutUndo();
                serializedObject.Update();
            }

            this.spContent       = serializedObject.FindProperty(PROP_CONTENT);
            this.spContentString = this.spContent.FindPropertyRelative(PROP_CONTENT_STR);
            this.spVoice         = this.serializedObject.FindProperty(PROP_VOICE);
            this.spAutoPlay      = this.serializedObject.FindProperty(PROP_AUTOPLAY);
            this.spAutoPlayTime  = this.serializedObject.FindProperty(PROP_AUTOPLAY_TIME);

            this.spActor            = this.serializedObject.FindProperty(PROP_ACTOR);
            this.spActorSpriteIndex = this.serializedObject.FindProperty(PROP_ACTOR_SPRITE);
            this.spActorTransform   = this.serializedObject.FindProperty(PROP_ACTOR_TRANSFORM);

            this.spAfterRun       = this.serializedObject.FindProperty(PROP_AFTERRUN);
            this.spAfterRunJumpTo = this.serializedObject.FindProperty(PROP_AFTERRUN_JUMPTO);
            this.SetupJumpOptions();

            this.target.hideFlags = HideFlags.HideInInspector;
        }
Example #10
0
        // PUBLIC METHODS: ------------------------------------------------------------------------

        public static void ShowText(IDialogueItem item, DatabaseDialogue.ConfigData config)
        {
            DialogueUI.RequireInstance(config);

            DialogueUI.Instance.currentMessage         = (item.content != null ? item.content.GetText() : "");
            DialogueUI.Instance.typewritterEnabled     = config.enableTypewritterEffect;
            DialogueUI.Instance.typewritterCharsPerSec = config.charactersPerSecond;
            DialogueUI.Instance.typewritterStartTime   = Time.time;

            string msg = (config.enableTypewritterEffect ? "" : DialogueUI.Instance.currentMessage);

            DialogueUI.Instance.textMessage.text = msg;
            DialogueUI.Instance.wrapMessage.SetActive(true);
        }
Example #11
0
        private void DeleteItems(List <int> items)
        {
            if (items == null || items.Count == 0)
            {
                return;
            }

            for (int i = 0; i < items.Count; ++i)
            {
                int selectionID = items[i];

                UnityEngine.Object instance = this.InstanceIDToObject(selectionID);
                if (instance == null)
                {
                    continue;
                }

                IDialogueItem instanceAsDialogue = (IDialogueItem)instance;
                this.DeleteItems(instanceAsDialogue.GetChildrenIDs());

                instanceAsDialogue.parent.children.Remove(instanceAsDialogue);

                this.itemInstances.Remove(instance.GetInstanceID());
                int spItemInstancesSize = this.spItemInstances.arraySize;
                for (int j = spItemInstancesSize - 1; j >= 0; --j)
                {
                    SerializedProperty property = spItemInstances.GetArrayElementAtIndex(j);
                    if (property.objectReferenceValue == null ||
                        property.objectReferenceValue.GetInstanceID() == instance.GetInstanceID())
                    {
                        this.spItemInstances.RemoveFromObjectArrayAt(j);
                    }
                }

                serializedObject.ApplyModifiedProperties();
                serializedObject.Update();

                if (this.itemsEditors.ContainsKey(selectionID) &&
                    this.itemsEditors[selectionID] != null)
                {
                    this.itemsEditors[selectionID].OnDestroyItem();
                }

                DestroyImmediate(instance, true);
            }
        }
Example #12
0
        public void MoveItemTo(TreeViewItem draggedItem, TreeViewItem parent, int insertIndex)
        {
            this.editorRoot.spChildren.InsertArrayElementAtIndex(this.editorRoot.spChildren.arraySize);

            IDialogueItem draggedDialogueItem = this.InstanceIDToObject(draggedItem.id);

            if (draggedDialogueItem != null && draggedDialogueItem.parent != null)
            {
                int           draggedItemParentID = draggedItem.parent.id;
                IDialogueItem draggedItemParent   = this.InstanceIDToObject(draggedItemParentID);

                if (draggedItemParent != null)
                {
                    int rmIndex = draggedDialogueItem.parent.children.IndexOf(draggedDialogueItem);
                    SerializedObject spDraggedItemParent = new SerializedObject(draggedItemParent);
                    spDraggedItemParent.FindProperty(PROP_CHILDREN).RemoveFromObjectArrayAt(rmIndex);
                }
            }

            IDialogueItem parentDialogueItem = this.InstanceIDToObject(parent.id);

            if (parentDialogueItem != null)
            {
                SerializedObject   spParentDialogueItem         = new SerializedObject(parentDialogueItem);
                SerializedProperty spParentDialogueItemChildren = spParentDialogueItem.FindProperty(PROP_CHILDREN);

                insertIndex = Mathf.Min(spParentDialogueItemChildren.arraySize, insertIndex);

                spParentDialogueItemChildren.InsertArrayElementAtIndex(insertIndex);
                spParentDialogueItemChildren.GetArrayElementAtIndex(insertIndex).objectReferenceValue = draggedDialogueItem;

                spParentDialogueItemChildren.serializedObject.ApplyModifiedProperties();
                spParentDialogueItemChildren.serializedObject.Update();

                SerializedObject spDraggedDialogueItem = new SerializedObject(draggedDialogueItem);
                spDraggedDialogueItem.FindProperty(PROP_PARENT).objectReferenceValue = parentDialogueItem;

                spDraggedDialogueItem.ApplyModifiedProperties();
                spDraggedDialogueItem.Update();
            }
        }
Example #13
0
        protected void PaintAfterRunTab()
        {
            EditorGUILayout.PropertyField(this.spAfterRun);
            if (this.spAfterRun.intValue == (int)IDialogueItem.AfterRunBehaviour.Jump)
            {
                int jmpCurrIndex = this.jumpOptionsIndex;
                this.jumpOptionsIndex = EditorGUILayout.Popup("Jump To", jmpCurrIndex, this.jumpOptions);
                if (jmpCurrIndex != this.jumpOptionsIndex)
                {
                    Dialogue dialogue = (Dialogue)this.spDialogue.objectReferenceValue;
                    if (dialogue != null)
                    {
                        IDialogueItem reference = dialogue.itemInstances[this.jumpOptionsIndex];
                        this.spAfterRunJumpTo.objectReferenceValue = reference;

                        serializedObject.ApplyModifiedPropertiesWithoutUndo();
                        serializedObject.Update();
                    }
                }
            }
        }
        protected override void RowGUI(TreeView.RowGUIArgs args)
        {
            IDialogueItem item = this.dialogueEditor.InstanceIDToObject(args.item.id);

            Rect altRect = new Rect(
                args.rowRect.x,
                args.rowRect.y,
                args.rowRect.width - ROW_ICON_WIDTH,
                args.rowRect.height
                );

            Rect iconRect = new Rect(
                args.rowRect.x + args.rowRect.width - ROW_ICON_WIDTH,
                args.rowRect.y,
                ROW_ICON_WIDTH,
                EditorGUIUtility.singleLineHeight
                );

            if (item != null)
            {
                switch (item.afterRun)
                {
                case IDialogueItem.AfterRunBehaviour.Exit:
                    args.rowRect = altRect;
                    base.RowGUI(args);
                    EditorGUI.LabelField(iconRect, GetIconExit());
                    break;

                case IDialogueItem.AfterRunBehaviour.Jump:
                    args.rowRect = altRect;
                    base.RowGUI(args);
                    EditorGUI.LabelField(iconRect, GetIconJump());
                    break;

                default:
                    base.RowGUI(args);
                    break;
                }
            }
        }
Example #15
0
        public void AddSibling(IDialogueItem item, IDialogueItem sibling, Dialogue dialogue, int siblingID = -1)
        {
            if (sibling.parent == null)
            {
                Debug.LogError("Unable to add sibling. Unknown parent");
                return;
            }

            SerializedObject   parentSerializedObject = new SerializedObject(sibling.parent);
            SerializedProperty spParentChildren       = parentSerializedObject.FindProperty(PROP_CHILDREN);

            int index = spParentChildren.arraySize;

            if (siblingID != -1)
            {
                int childrenCount = this.targetItem.parent.children.Count;
                for (int i = 0; i < childrenCount; ++i)
                {
                    if (this.targetItem.parent.children[i].GetInstanceID() == siblingID)
                    {
                        index = i + 1;
                        break;
                    }
                }
            }

            spParentChildren.InsertArrayElementAtIndex(index);
            spParentChildren.GetArrayElementAtIndex(index).objectReferenceValue = item;

            parentSerializedObject.ApplyModifiedPropertiesWithoutUndo();
            parentSerializedObject.Update();

            SerializedObject itemSerializedObject = new SerializedObject(item);

            itemSerializedObject.FindProperty(PROP_DIALOGUE).objectReferenceValue = dialogue;
            itemSerializedObject.FindProperty(PROP_PARENT).objectReferenceValue   = sibling.parent;
            itemSerializedObject.ApplyModifiedPropertiesWithoutUndo();
            itemSerializedObject.Update();
        }
        public static void StartLine(IDialogueItem item, DatabaseDialogue.ConfigData config)
        {
            DialogueUI.RequireInstance(config);
            DialogueUI dialogue = DialogueUI.Instance;

            dialogue.currentMessage        = item.GetContent();
            dialogue.typewriterEnabled     = config.enableTypewriterEffect;
            dialogue.typewriterCharsPerSec = config.charactersPerSecond;
            dialogue.typewriterStartTime   = Time.time;
            dialogue.gibberish             = null;

            string msg = (config.enableTypewriterEffect ? "" : dialogue.currentMessage);

            dialogue.textMessage.text = msg;

            if (dialogue.wrapLogs != null)
            {
                dialogue.wrapLogs.SetActive(true);
            }
            if (dialogue.wrapGraphic != null)
            {
                dialogue.wrapGraphic.SetActive(true);
            }
            if (dialogue.wrapMessage != null)
            {
                dialogue.wrapMessage.SetActive(true);
            }

            if (dialogue.textTitle != null)
            {
                dialogue.textTitle.gameObject.SetActive(false);
            }
            if (dialogue.actorColor != null)
            {
                dialogue.actorColor.gameObject.SetActive(false);
            }
            if (dialogue.actorImage != null)
            {
                dialogue.actorImage.gameObject.SetActive(false);
            }
            if (dialogue.actorRawImage != null)
            {
                dialogue.actorRawImage.gameObject.SetActive(false);
            }
            if (dialogue.actorPrefabContainer != null)
            {
                dialogue.actorPrefabContainer.gameObject.SetActive(false);
            }

            if (item.actor != null)
            {
                if (dialogue.textTitle != null)
                {
                    dialogue.textTitle.gameObject.SetActive(true);
                    dialogue.textTitle.text = item.actor.GetName();
                }

                if (dialogue.actorColor != null)
                {
                    dialogue.actorColor.gameObject.SetActive(true);
                    dialogue.actorColor.color = item.actor.color;
                }

                if (item.actorSpriteIndex < item.actor.actorSprites.data.Length)
                {
                    ActorSprites.Data spriteData = item.actor.actorSprites.data[item.actorSpriteIndex];
                    switch (spriteData.type)
                    {
                    case ActorSprites.DataType.Sprite:
                        if (dialogue.actorImage != null)
                        {
                            dialogue.actorImage.gameObject.SetActive(true);
                            dialogue.actorImage.sprite = spriteData.sprite;
                        }
                        break;

                    case ActorSprites.DataType.Texture:
                        if (dialogue.actorRawImage != null)
                        {
                            dialogue.actorRawImage.gameObject.SetActive(true);
                            dialogue.actorRawImage.texture = spriteData.texture;
                        }
                        break;

                    case ActorSprites.DataType.Prefab:
                        if (dialogue.actorPrefabContainer != null)
                        {
                            dialogue.actorPrefabContainer.gameObject.SetActive(true);
                            for (int i = dialogue.actorPrefabContainer.childCount - 1; i >= 0; --i)
                            {
                                Destroy(dialogue.actorPrefabContainer.GetChild(i).gameObject);
                            }

                            GameObject instance = Instantiate(
                                spriteData.prefab,
                                dialogue.actorPrefabContainer
                                );
                            instance.transform.localScale = Vector3.one;
                        }
                        break;
                    }
                }

                if (item.actor.useGibberish)
                {
                    dialogue.gibberish = new GibberishEffect(
                        item.actor.gibberishAudio,
                        item.actor.gibberishPitch,
                        item.actor.gibberishVariation
                        );
                }
            }

            if (config.enableTypewriterEffect)
            {
                DialogueUI.Instance.typewriter = new TypeWriterEffect(
                    DialogueUI.Instance.currentMessage
                    );
            }
        }
 public static void CompleteLine(IDialogueItem item)
 {
     LOG.Add(item, false);
 }
Example #18
0
 public virtual bool CanHaveParent(IDialogueItem parent)
 {
     return(true);
 }
 public override bool CanHaveParent(IDialogueItem parent)
 {
     return(base.CanHaveParent(parent));
 }
 public static void CompleteChoice(IDialogueItem item)
 {
     LOG.Add(item, true);
 }
        protected override void RowGUI(TreeView.RowGUIArgs args)
        {
            IDialogueItem item = this.dialogueEditor.InstanceIDToObject(args.item.id);

            Rect altRect = new Rect(
                args.rowRect.x,
                args.rowRect.y,
                args.rowRect.width - (EditorGUIUtility.singleLineHeight * 3f),
                args.rowRect.height
                );

            Rect icon1Rect = new Rect(
                args.rowRect.x + args.rowRect.width - EditorGUIUtility.singleLineHeight,
                args.rowRect.y,
                EditorGUIUtility.singleLineHeight,
                EditorGUIUtility.singleLineHeight
                );

            Rect icon2Rect = new Rect(
                icon1Rect.x - icon1Rect.width,
                icon1Rect.y,
                icon1Rect.width,
                icon1Rect.height
                );

            Rect icon3Rect = new Rect(
                icon2Rect.x - icon2Rect.width,
                icon2Rect.y,
                icon2Rect.width,
                icon2Rect.height
                );

            if (item != null)
            {
                args.rowRect = altRect;
                base.RowGUI(args);

                switch (item.afterRun)
                {
                case IDialogueItem.AfterRunBehaviour.Exit:
                    GUI.DrawTexture(icon1Rect, GetIconExit());
                    break;

                case IDialogueItem.AfterRunBehaviour.Jump:
                    GUI.DrawTexture(icon1Rect, GetIconJump());
                    break;
                }

                Texture actions = (item.actionsList.actions.Length > 0
                    ? GetIconActions()
                    : GetIconNoActions()
                                   );

                GUI.DrawTexture(icon3Rect, actions);

                Texture conditions = (item.conditionsList.conditions.Length > 0
                    ? GetIconConditions()
                    : GetIconNoConditions()
                                      );

                GUI.DrawTexture(icon2Rect, conditions);
            }
        }