Beispiel #1
0
        /// <summary>
        /// sets dialogue to a new speech bubble
        /// </summary>
        private void SetBranch(int newBranchID, Entity e, ref DialogueUI dialogue, ref RenderText renderText)
        {
            DialogueDatam dialogueTree = meta[dialogue.treeID];

            dialogue.branchID = newBranchID;
            var branch = dialogueTree.dialogueTree.branches[dialogue.branchID];

            dialogue.SetText(branch.speech, ref renderText);
            renderText.offsetX = ((-branch.speech.Length - 1f) / 2f) * renderText.fontSize;
            RefreshPanelSize(World.EntityManager, e, renderText.fontSize, branch.speech.Length);
        }
Beispiel #2
0
        public override VisualElement CreateInspectorGUI()
        {
            var container = new VisualElement();

            cachedObject = serializedObject;

            //cachedProperty = property;
            //cachedProperty = serializedObject;

            dialogueDatam = (DialogueDatam)cachedObject.targetObject;

            container.styleSheets.Add(Resources.Load <StyleSheet>("DialogueEditor/DialogueStyle"));

            // set up main first
            var dialogueMainLoader = Resources.Load <VisualTreeAsset>("DialogueEditor/DialogueMain");

            dialogueMainLoader.CloneTree(container);
            main = container.Query("Content").First();

            // header buttons
            Button addBranchButton = container.Query("AddBranchButton").First() as Button;

            if (addBranchButton != null)
            {
                addBranchButton.clicked += () =>
                {
                    AddBranchClicked(dialogueDatam);
                };
            }

            // blocks
            blockPrefab = Resources.Load <VisualTreeAsset>("DialogueEditor/DialogueBlock");
            LoadUI();

            // Draw the legacy IMGUI base
            //var imgui = new IMGUIContainer(OnInspectorGUI);
            // Create property fields.
            // Add fields to the container.
            //container.Add(new PropertyField(serializedObject.FindProperty("stats")));
            //container.Add(imgui);

            return(container);
        }
Beispiel #3
0
 private void RemoveBranchClicked(DialogueDatam dialogueDatam, DialogueBranch branch, VisualElement ui)
 {
     // remove any link uis from other branches
     for (int i = 0; i < uis.Count; i++)
     {
         if (uis[i] != ui)
         {
             var linkUIs = uis[i].Query("Links");
             //for (int j = 0; j < linkUIs.Count; j++)
             //foreach (var linkUI in linkUIs.Descendents)
             linkUIs.ForEach((linkUI) =>
             {
                 var content = linkUI.Query("unity-content").First().Query <Button>();
                 content.ForEach((childButton) => {
                     if (childButton.text == "[" + branch.id + "]")
                     {
                         childButton.parent.Remove(childButton);     // remove the link to branch
                     }
                 });
             });
         }
     }
     dialogueDatam.dialogueTree.RemoveBranch(branch);
     // remove the UI as well
     uis.Remove(ui);
     ui.parent.Remove(ui);
     // check for branches - if they are linked to this branch
     for (int i = 0; i < dialogueDatam.dialogueTree.branches.Length; i++)
     {
         var otherBranch = dialogueDatam.dialogueTree.branches[i];
         for (int j = 0; j < otherBranch.links.Length; j++)
         {
             if (otherBranch.links[j] == branch.id)
             {
                 // reset branch link
                 dialogueDatam.SetBranchLink(otherBranch, j, 0);
                 // also set the link ui
                 uis[i].Query <Foldout>("Links").ToList()[j].text = "[Unlinked]";
             }
         }
     }
 }
Beispiel #4
0
 private void OnLinkClicked(Foldout linksFoldout, DialogueDatam dialogueDatam, DialogueBranch branch, int linkIndex, int nextID, string nextSpeech)
 {
     if (nextSpeech == null)
     {
         nextSpeech = "";
     }
     // set id to the text
     if (linkIndex >= branch.links.Length)
     {
         Debug.LogError("Link Index out of bounds: " + branch.id + ":" + linkIndex);
     }
     else
     {
         branch = dialogueDatam.SetBranchLink(branch, linkIndex, nextID);
         //branch.links[linkIndex] = nextID;
         linksFoldout.text = "Next Branch [" + branch.links[linkIndex] + "]: " +
                             nextSpeech.Substring(0, Mathf.Min(nextSpeech.Length, 16)) + "..";
         linksFoldout.value = false;
         EditorUtility.SetDirty(cachedObject.targetObject);
     }
 }
Beispiel #5
0
        private void AddBranchClicked(DialogueDatam dialogueDatam)
        {
            var branch = new DialogueBranch();

            branch.id = Bootstrap.GenerateUniqueID();
            uis.Add(LoadBlockUI(dialogueDatam, branch));
            dialogueDatam.dialogueTree.AddBranch(branch);
            //cachedProperty.SetValue(stats);
            for (int i = 0; i < dialogueDatam.dialogueTree.branches.Length - 1; i++)
            {
                var linkUIs = uis[i].Query("Links");
                //for (int j = 0; j < linkUIs.Count; j++)
                //foreach (var linkUI in linkUIs.Descendents)
                int linkIndex = 0;
                linkUIs.ForEach((linkUI) =>
                {
                    AddLinkChoiceUI(dialogueDatam.dialogueTree.branches[i], branch, linkUI as Foldout, linkIndex);
                    linkIndex++;
                });
            }
            EditorUtility.SetDirty(cachedObject.targetObject);
        }
Beispiel #6
0
        private void AddLinkUI(VisualElement parent, DialogueDatam dialogueDatam, DialogueBranch branch, int linkIndex)
        {
            Foldout linksFoldout = new Foldout();

            linksFoldout.name = "Links";
            parent.Add(linksFoldout);
            if (linkIndex < 0 || linkIndex >= branch.links.Length)
            {
                linksFoldout.text = "[Errored]";
            }
            else if (branch.links[linkIndex] != 0)
            {
                linksFoldout.text = "Next Branch [" + branch.links[linkIndex] + "]";
            }
            else
            {
                linksFoldout.text = "[Unlinked]";
            }
            for (int i = 0; i < dialogueDatam.dialogueTree.branches.Length; i++)
            {
                AddLinkChoiceUI(branch, dialogueDatam.dialogueTree.branches[i], linksFoldout, linkIndex);
            }
            linksFoldout.value = false;
        }
Beispiel #7
0
        private void IncrementDialogue(Entity e, ref DialogueUI dialogue, ref RenderText renderText)
        {
            int           linkChoice    = dialogue.confirmedChoice - 1;
            DialogueDatam dialogueTree  = meta[dialogue.treeID];
            var           currentBranch = dialogueTree.dialogueTree.branches[dialogue.branchID];
            int           branchID      = -1;

            if (currentBranch.links.Length > 0 && linkChoice < currentBranch.links.Length)
            {
                //Debug.LogError("linkChoice was " + linkChoice);
                branchID = currentBranch.links[linkChoice];
            }
            if (branchID == -1)
            {
                OnCompletedDialogue(e, ref dialogue, ref renderText);
                return;
            }
            int linkIndex = -1;

            for (int i = 0; i < dialogueTree.dialogueTree.branches.Length; i++)
            {
                if (dialogueTree.dialogueTree.branches[i].id == branchID)
                {
                    linkIndex = i;
                    break;
                }
            }
            if (linkIndex == -1)
            {
                OnCompletedDialogue(e, ref dialogue, ref renderText);
            }
            else
            {
                SetBranch(linkIndex, e, ref dialogue, ref renderText);
            }
        }
Beispiel #8
0
        //List<Foldout> linksFoldouts = new List<Foldout>();


        private VisualElement LoadBlockUI(DialogueDatam dialogueDatam, DialogueBranch block)
        {
            blockPrefab.CloneTree(main);
            var blockUI = main.Query("DialogueBlock").Last() as Foldout;

            blockUI.text = "Branch [" + block.id + "]";

            TextField dialogueInput = blockUI.Query("DialogueInput").First() as TextField;

            if (dialogueInput != null)
            {
                //Debug.LogError("Setting speech to: " + block.speech);
                dialogueInput.value = block.speech;
                dialogueInput.RegisterValueChangedCallback((eventInfo) =>
                {
                    OnSpeechUpdated(eventInfo, dialogueDatam, block);
                });
            }

            Toggle isPlayerToggle = blockUI.Query("IsPlayerToggle").First() as Toggle;

            if (isPlayerToggle != null)
            {
                if (block.speakerType == 1)
                {
                    isPlayerToggle.value = true;
                }
                else
                {
                    isPlayerToggle.value = false;
                }
                isPlayerToggle.RegisterValueChangedCallback((eventInfo) =>
                {
                    OnSpeakerTypeUpdated(eventInfo, dialogueDatam, block);
                });
            }

            Button deleteButton = blockUI.Query("DeleteButton").First() as Button;

            if (deleteButton != null)
            {
                deleteButton.clicked += () =>
                {
                    RemoveBranchClicked(dialogueDatam, block, blockUI);
                };
            }

            Button newLinkButton = blockUI.Query("AddLinkButton").First() as Button;

            if (newLinkButton != null)
            {
                newLinkButton.clicked += () =>
                {
                    AddBranchLink(newLinkButton.parent, dialogueDatam, block); // , newLinkButton
                };
            }

            //var linksFoldoutPrefab = blockUI.Query("Links").First() as Foldout;
            for (int i = 0; i < block.links.Length; i++)
            {
                AddLinkUI(newLinkButton.parent, dialogueDatam, block, i);
            }

            //linkPrefab.parent.Remove(linkPrefab);
            // for every other dialogue block in the tree, add a new linkChoice

            // add new LinkUI - FoldoutUI for every link in the data

            // Have to also do set text

            // Set character Name

            // Set Next with Dropdown

            return(blockUI);
            // set up buttons here
            // character name text
            // input for speech
            // dropdown for type of Dialogue it is (can change to action)
            // Dropdown for which one it will go to next (blank if missing)

            //var parentFoldout = statsHeader.Query("StatID").First();
        }
Beispiel #9
0
 private void OnSpeakerTypeUpdated(ChangeEvent <bool> eventInfo, DialogueDatam dialogueDatam, DialogueBranch branch)
 {
     dialogueDatam.SetSpeakerType(branch, eventInfo.newValue);
     EditorUtility.SetDirty(cachedObject.targetObject);
 }
Beispiel #10
0
 private void OnSpeechUpdated(ChangeEvent <string> eventInfo, DialogueDatam dialogueDatam, DialogueBranch branch)
 {
     dialogueDatam.SetBranchSpeech(branch, eventInfo.newValue);
     EditorUtility.SetDirty(cachedObject.targetObject);
 }
Beispiel #11
0
 private void AddBranchLink(VisualElement parent, DialogueDatam dialogueDatam, DialogueBranch branch)
 {
     branch = dialogueDatam.AddBranchLink(branch);
     AddLinkUI(parent, dialogueDatam, branch, branch.links.Length - 1);
     EditorUtility.SetDirty(cachedObject.targetObject);
 }
Beispiel #12
0
        protected override void OnUpdate()
        {
            Entities.WithAll <DialogueUI, RenderText>().ForEach((Entity e, ref DialogueUI dialogue, ref RenderText renderText) =>
            {
                if (UnityEngine.Time.time - dialogue.timeBegun >= dialogue.timePerLetter)
                {
                    if (dialogue.HasFinished())
                    {
                        // spawn next button now
                        // if has not spawned next buttons
                        if (dialogue.hasSpawnedButtons == 0)
                        {
                            dialogue.hasSpawnedButtons = 1;
                            Color textColor            = Color.blue; //  uiDatam.menuTextColor
                            DialogueDatam dialogueTree = meta[dialogue.treeID];
                            var currentBranch          = dialogueTree.dialogueTree.branches[dialogue.branchID];
                            Childrens children         = new Childrens {
                            };
                            if (currentBranch.links.Length <= 1)
                            {
                                // spawn next button
                                children.children      = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent);
                                float3 buttonPosition  = new float3(0, (-renderText.fontSize / 2f - buttonFontSize / 2f), 0);
                                string dialogueOptionA = "Next";
                                children.children[0]   = UIUtilities.SpawnButtonWithText(World.EntityManager, e,
                                                                                         buttonPosition, buttonFontSize, dialogueOptionA,
                                                                                         uiDatam.menuButton, uiDatam.defaultMenuColor, textColor);
                            }
                            else
                            {
                                children.children = new BlitableArray <Entity>(currentBranch.links.Length, Unity.Collections.Allocator.Persistent);
                                // spawn a button for all links
                                float3 offset               = new float3();
                                children.children           = new BlitableArray <Entity>(currentBranch.links.Length, Unity.Collections.Allocator.Persistent);
                                DialogueDatam dialogueDatam = meta[dialogue.treeID];
                                for (int i = 0; i < currentBranch.links.Length; i++)
                                {
                                    float3 buttonPosition = new float3(0, (-renderText.fontSize / 2f - buttonFontSize / 2f), 0);
                                    buttonPosition       += offset;
                                    offset = buttonPosition;
                                    string dialogueOptionA = "Leave";
                                    for (int j = 0; j < dialogueDatam.dialogueTree.branches.Length; j++)
                                    {
                                        var otherBranch = dialogueDatam.dialogueTree.branches[j];
                                        if (otherBranch.id == currentBranch.links[i])
                                        {
                                            dialogueOptionA = otherBranch.speech;
                                            break;
                                        }
                                    }
                                    children.children[i] = UIUtilities.SpawnButtonWithText(World.EntityManager, e,
                                                                                           buttonPosition, buttonFontSize, dialogueOptionA,
                                                                                           uiDatam.menuButton, uiDatam.defaultMenuColor, textColor);
                                }
                            }
                            World.EntityManager.SetComponentData(e, children);
                            // set navigation dirty
                            var panelUI             = World.EntityManager.GetComponentData <PanelUI>(e);
                            panelUI.navigationDirty = 1;
                            World.EntityManager.SetComponentData(e, panelUI);
                        }
                        // or spawn dialogue options
                        else if (dialogue.confirmedChoice != 0)
                        {
                            IncrementDialogue(e, ref dialogue, ref renderText);
                            dialogue.confirmedChoice   = 0;
                            dialogue.hasSpawnedButtons = 0;
                            // remove previous buttons
                            Childrens childrens = World.EntityManager.GetComponentData <Childrens>(e);
                            childrens.DestroyEntities(World.EntityManager);
                            World.EntityManager.SetComponentData(e, new Childrens {
                            });

                            var panelUI             = World.EntityManager.GetComponentData <PanelUI>(e);
                            panelUI.navigationDirty = 1;
                            World.EntityManager.SetComponentData(e, panelUI);
                        }
                    }
                    else
                    {
                        IncrementLetters(ref dialogue, ref renderText);
                        if (dialogue.confirmedChoice != 0)
                        {
                            dialogue.confirmedChoice = 0;   // shouldn't be able to get here
                        }
                    }
                }
            });
        }