Example #1
0
        private CharacterDialogVM ElementTextEditTestCreation()
        {
            NpcChatProject   project = new NpcChatProject();
            DialogTree       tree    = project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch branch  = tree.CreateNewBranch();

            Assert.AreEqual(0, branch.Dialog.Count, "This is a new branch and shouldn't have any dialog inside it!");

            int charId;

            Assert.IsTrue(project.ProjectCharacters.RegisterNewCharacter(out charId, "Gerald"));
            DialogSegment dialogSegment = branch.CreateNewDialog(charId);

            Assert.AreEqual(1, branch.Dialog.Count, "Failed to create sample dialog segment");

            dialogSegment.ClearElements();
            Assert.AreEqual(0, dialogSegment.SegmentParts.Count);
            Assert.AreEqual("", dialogSegment.Text);

            CharacterDialogVM testVM = new CharacterDialogVM(project, dialogSegment)
            {
                EditMode         = EditMode.Elements,
                InspectionActive = false
            };

            // make sure creation was valid
            Assert.NotNull(testVM);
            Assert.AreSame(dialogSegment, testVM.DialogSegment);
            Assert.AreEqual(0, testVM.DialogSegment.SegmentParts.Count);

            return(testVM);
        }
Example #2
0
 public ChatHandler(DesyncContext context, Character npc, DialogTree pool, PaletteType palette = PaletteType.Glass)
 {
     Context = context;
     Npc     = npc;
     Tree    = pool;
     Palette = GraphicsService.GetPalette(palette);
 }
        public void StartPartCreation()
        {
            DialogTree tree = m_project.ProjectDialogs.CreateNewDialogTree();

            Assert.IsNotNull(tree.GetStart());
            Assert.IsTrue(tree.GetStart().IsTreeRoot);
        }
Example #4
0
        /// <summary>
        /// Shows the script diagram panel for the given <see cref="tree"/> identifier
        /// </summary>
        /// <param name="tree">Dialog Tree to show</param>
        public void ShowScriptDiagramPanel(DialogTreeIdentifier tree)
        {
            DialogTree dialogTree = m_project[tree];

            if (dialogTree == null)
            {
                return;
            }

            ScriptDiagramVM window = Windows.Select(w => w as ScriptDiagramVM)
                                     .Where(s => s != null)
                                     .FirstOrDefault(s => s.Tree == tree);

            if (window == null)
            {
                window = new ScriptDiagramVM(m_project, dialogTree);
                Windows.Add(window);
            }

            window.IsSelected = true;
            if (m_dockingManager != null)
            {
                m_dockingManager.ActiveContent = window;
            }
        }
Example #5
0
        /// <summary>
        /// Would adding <see cref="potentialChild"/> as a child of <see cref="parent"/> result in a circular dependency?
        /// </summary>
        /// <returns>true if adding this item would have a circular dependency</returns>
        public static bool CheckForCircularDependency(this DialogTree tree, DialogTreeBranchIdentifier parent, DialogTreeBranchIdentifier potentialChild)
        {
            if (!tree.Id.Compatible(parent) || !tree.Id.Compatible(potentialChild) ||
                !tree.HasBranch(parent) || !tree.HasBranch(potentialChild))
            {
                // If the segment isn't compatible with the tree there can't be a circular dependency
                return(false);
            }

            if (parent == potentialChild)
            {
                // Adding yourself would defiantly cause a circular dependency
                return(true);
            }

            foreach (DialogTreeBranchIdentifier childParent in tree[parent].Parents)
            {
                if (childParent == potentialChild ||
                    CheckCircularDependencyParents(tree, childParent, potentialChild))
                {
                    return(true);
                }
            }

            return(false);
        }
        public void ChangeCharacter()
        {
            NpcChatProject project = new NpcChatProject();

            if (project.ProjectCharacters.RegisterNewCharacter(out int bill, "bill") &&
                project.ProjectCharacters.RegisterNewCharacter(out int tommy, "tommy"))
            {
                DialogTree       tree   = project.ProjectDialogs.CreateNewDialogTree();
                DialogTreeBranch branch = tree.CreateNewBranch();

                DialogSegment segment = branch.CreateNewDialog(bill);
                Assert.NotNull(segment);
                Assert.AreEqual(segment.CharacterId, bill, "Unexpected Character");

                bool callback = false;
                segment.PropertyChanged += (sender, args) => callback = true;

                segment.ChangeCharacter(tommy);

                Assert.AreEqual(segment.CharacterId, tommy, "Failed change character");
                Assert.IsTrue(callback, "Failed to send callback for character change");

                callback = false;
                segment.ChangeCharacter(bill);

                Assert.AreEqual(segment.CharacterId, bill, "Failed change character");
                Assert.IsTrue(callback, "Failed to send callback for character change");
            }
Example #7
0
 protected void Awake()
 {
     if (m_dialogtree != null)
     {
         m_dialogtree = DialogTree.CreateInstance(m_dialogtree);
     }
 }
Example #8
0
        public void PossibleBranchLinkPreExisting()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch a = tree.GetStart();

            a.Name = "A";
            BranchTestScriptView branchTest = new BranchTestScriptView();
            TreeBranchVM         aBranch    = new TreeBranchVM(project, branchTest, a);

            branchTest.Branches.Add(aBranch);

            //no other branches so there shouldn't be any possibilities
            TestBranchPossibility(aBranch);

            DialogTreeBranch b = tree.CreateNewBranch();

            b.Name = "B";
            RelationshipCreate(a, b);

            TreeBranchVM bBranch = new TreeBranchVM(project, branchTest, b);

            branchTest.Branches.Add(bBranch);

            //branches already linked so there shouldn't be any possible links
            TestBranchPossibility(aBranch);
            TestBranchPossibility(bBranch);
        }
        public void DialogGetter(int offset)
        {
            DialogTree tree = m_project.ProjectDialogs.CreateNewDialogTree();

            Assert.IsNotNull(tree);
            Assert.IsNotNull(m_project.ProjectDialogs[tree]);
            DialogTreeIdentifier fakeTreeId = new DialogTreeIdentifier(tree.Id.DialogTreeId + offset);

            Assert.IsNull(m_project.ProjectDialogs[fakeTreeId]);

            DialogTreeBranch branch = tree.CreateNewBranch();

            Assert.IsNotNull(branch);
            Assert.IsNotNull(m_project.ProjectDialogs[branch]);
            DialogTreeBranchIdentifier fakeBranchId = new DialogTreeBranchIdentifier(branch.Id, branch.Id.DialogTreeBranchId + offset);

            Assert.IsNull(m_project.ProjectDialogs[fakeBranchId]);

            DialogSegment dialogSegment = branch.CreateNewDialog(CharacterId.DefaultId);

            Assert.IsNotNull(dialogSegment);
            Assert.IsNotNull(m_project.ProjectDialogs[dialogSegment.Id]);
            DialogSegmentIdentifier fakeSegmentId = new DialogSegmentIdentifier(dialogSegment.Id, dialogSegment.Id.DialogSegmentId + offset);

            Assert.IsNull(m_project.ProjectDialogs[fakeSegmentId]);
        }
        public void ClearElements()
        {
            NpcChatProject project = new NpcChatProject();

            if (project.ProjectCharacters.RegisterNewCharacter(out int id, "bill"))
            {
                DialogTree       tree   = project.ProjectDialogs.CreateNewDialogTree();
                DialogTreeBranch branch = tree.CreateNewBranch();

                DialogSegment segment = branch.CreateNewDialog(id);
                Assert.NotNull(segment);

                DialogText one = DialogTypeStore.Instance.CreateEntity <DialogText>();
                one.Text = "one";
                segment.AddDialogElement(one);

                Assert.IsTrue(segment.SegmentParts.Count > 0);

                bool callback = false;
                segment.PropertyChanged += (sender, args) => callback = true;

                segment.ClearElements();

                Assert.AreEqual(0, segment.SegmentParts.Count);
                Assert.IsTrue(callback, "Failed to send callback for added type");
            }
            else
            {
                Assert.Fail("Failed to create character");
            }
        }
        public void AddElement(Type dialogType)
        {
            NpcChatProject project = new NpcChatProject();

            if (project.ProjectCharacters.RegisterNewCharacter(out int id, "bill"))
            {
                DialogTree       tree   = project.ProjectDialogs.CreateNewDialogTree();
                DialogTreeBranch branch = tree.CreateNewBranch();

                DialogSegment segment = branch.CreateNewDialog(id);
                Assert.NotNull(segment);

                bool callback = false;
                segment.PropertyChanged += (sender, args) => callback = true;

                int            before  = segment.SegmentParts.Count;
                IDialogElement element = DialogTypeStore.Instance.CreateEntity(dialogType);
                segment.AddDialogElement(element);

                Assert.AreEqual(before + 1, segment.SegmentParts.Count);
                Assert.IsTrue(callback, "Failed to send callback for added type");
            }
            else
            {
                Assert.Fail("Failed to create character");
            }
        }
    public static DialogTree CreateInstance(string _name)
    {
        DialogTree ret = CreateInstance <DialogTree>();

        ret.name = _name;
        return(ret);
    }
Example #13
0
    // RefreshDisplay prompts the prompt text and response buttons to be updated
    // depending on a supplied DialogPromptNode
    public void RefreshDisplay(DialogPromptNode nextPrompt)
    {
        this.AssignControllers();
        currentTreeObj = dialogCtrl.GetDemoTree();

        promptText.text = "";
        foreach (ResponseButton button in buttons)
        {
            Destroy(button.gameObject);
        }
        buttons.Clear();

        if (index == 0)
        {
            Debug.Log("index is 0!");
            this.AssignControllers();
            prompts = dialogCtrl.GetDemoTreePrompts(currentTreeObj);
            this.ShowPromptAndResponses(prompts[index]);
        }
        else if (nextPrompt != null)
        {
            this.AssignControllers();
            this.ShowPromptAndResponses(nextPrompt);
        }
    }
Example #14
0
    public void Initialize(bool re_init)
    {
        if (initedBefore == false || re_init == true)
        {
            Player         = GameObject.FindGameObjectWithTag("Player");
            dialogDatabase = DialogDatabase.Instance;
            dialogTree     = dialogDatabase.GetDialogTree(Application.loadedLevelName);

            for (int i = 0; i < reservedOptionRectCount; ++i)
            {
                //init some temp rect for later uses.
                optionRects.Add(new Rect(0, 0, 0, 0));
            }

            dialogBox = new Rect(0.0f, Screen.height * 0.70f, Screen.width, Screen.height * 0.30f);

            personBoxHeight = dialogBox.height * 0.20f;
            personBoxWidth  = dialogBox.width * 0.20f;

            personBox    = new Rect(dialogBox.xMin, dialogBox.yMin - personBoxHeight, personBoxWidth, personBoxHeight);
            initedBefore = true;

            skin = (GUISkin)Resources.Load("Skins/UI");
        }
    }
Example #15
0
        public void PossibleBranchLinkAdded2()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch a = tree.GetStart();

            a.Name = "A";
            BranchTestScriptView branchTest = new BranchTestScriptView();
            TreeBranchVM         aBranch    = new TreeBranchVM(project, branchTest, a);

            branchTest.Branches.Add(aBranch);

            Assert.IsFalse(aBranch.AreBranchLinksPossible, "Branch links are possible as there are no other branches");
            Assert.AreEqual(0, aBranch.PotentialBranchLinks.Count);

            DialogTreeBranch b = tree.CreateNewBranch();

            b.Name = "B";
            TreeBranchVM bBranch = new TreeBranchVM(project, branchTest, b);

            branchTest.Branches.Add(bBranch);

            //no relation between the branches so all links are possible
            TestBranchPossibility(aBranch, b);
            TestBranchPossibility(bBranch, a);

            // link a to b so that the options for both branches are limited
            RelationshipCreate(a, b);

            //A is parent of B so there should be no possible actions
            TestBranchPossibility(aBranch);
            TestBranchPossibility(bBranch);
        }
Example #16
0
        public void NewBranchNameDuplication()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            List <string> newNames = new List <string>();

            for (int i = 0; i < 10; i++)
            {
                DialogTreeBranch newBranch = tree.CreateNewBranch();
                Assert.NotNull(newBranch);

                newNames.Add(newBranch.Name);
            }

            for (int inner = 0; inner < newNames.Count; inner++)
            {
                for (int outer = 0; inner < newNames.Count; inner++)
                {
                    if (inner == outer)
                    {
                        continue;
                    }
                    Assert.AreNotEqual(newNames[inner], newNames[outer]);
                }
            }
        }
Example #17
0
        public void AddBranch2()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            for (int i = 0; i < 10; i++)
            {
                DialogTreeBranch newBranch = tree.CreateNewBranch();
                Assert.NotNull(newBranch);
            }

            IReadOnlyList <DialogTreeBranchIdentifier> branches = tree.Branches;

            for (int inner = 0; inner < branches.Count; inner++)
            {
                for (int outer = 0; inner < branches.Count; inner++)
                {
                    if (inner == outer)
                    {
                        continue;
                    }
                    Assert.AreNotEqual(branches[inner], branches[outer]);
                    Assert.AreNotEqual(tree[branches[inner]], tree[branches[outer]]);
                }
            }
        }
Example #18
0
    // RenameEditingTree renames the current dialog tree being edited
    public void RenameEditingTree(string newName)
    {
        string oldName = treeObj.treeId;

        Debug.Log("renaming " + oldName + " to " + newName);

        // rename actual id associated with obj in dialogTrees list
        getTree(oldName).Rename(newName);

        // remove old treeId and add new treeId from id list, refresh array list of ids
        dialogTreeIds.Remove(oldName);
        dialogTreeIds.Add(newName);
        dialogTreeArr = dialogTreeIds.ToArray();

        // reset tree obj we're editing
        editingTreeName = newName;
        foreach (DialogTree t in dialogTrees)
        {
            if (t.treeId == editingTreeName)
            {
                treeObj = t;
                break;
            }
        }

        this.raiseTreeUpdate();
    }
Example #19
0
        public void ClearBranchListAfterParentRemoteBranch()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch start = tree.GetStart();

            Assert.AreEqual(1, tree.Branches.Count);

            DialogTreeBranch unusedBranch    = tree.CreateNewBranch();
            bool             branchesChanged = false;

            ScriptPanelVM script = new ScriptPanelVM(project, tree);

            script.OnVisibleBranchChange += (t) => branchesChanged = true;
            DialogTreeBranchIdentifier firstChild  = script.AddNewBranch(start, true);
            DialogTreeBranchIdentifier secondChild = script.AddNewBranch(firstChild, true);

            // ensure all 3 branches are currently visible
            Assert.IsTrue(script.Branches.Any(b => b.DialogBranch == start), $"Should be able to see '{nameof(start)}'");
            Assert.IsTrue(script.Branches.Any(b => b.DialogBranch == firstChild), $"Should be able to see '{nameof(firstChild)}'");
            Assert.IsTrue(script.Branches.Any(b => b.DialogBranch == secondChild), $"Should be able to see '{nameof(firstChild)}'");
            Assert.IsFalse(script.Branches.Any(b => b.DialogBranch == unusedBranch), $"Shouldn't be able to see '{nameof(unusedBranch)}'");
            Assert.IsTrue(branchesChanged, $"Branches changed since creation");

            branchesChanged = false;
            script.ClearBranchListAfterParent(unusedBranch);

            // ensure same branches are still currently visible
            Assert.IsTrue(script.Branches.Any(b => b.DialogBranch == start), $"Should be able to see '{nameof(start)}'");
            Assert.IsTrue(script.Branches.Any(b => b.DialogBranch == firstChild), $"Should be able to see '{nameof(firstChild)}'");
            Assert.IsTrue(script.Branches.Any(b => b.DialogBranch == secondChild), $"Should be able to see '{nameof(firstChild)}'");
            Assert.IsFalse(script.Branches.Any(b => b.DialogBranch == unusedBranch), $"Shouldn't be able to see '{nameof(unusedBranch)}'");
            Assert.IsFalse(branchesChanged, $"No branches changed");
        }
Example #20
0
        static void Main(string[] args)
        {
            DialogTree tree = DialogTree.Load("exempel.txt");

            Console.WriteLine(tree.ToString());

            Console.ReadLine();
        }
 public static DialogTree CreateInstance(DialogTree _tree)
 {
     //DialogTree ret = CreateInstance<DialogTree>();
     //ret.name = _tree.name;
     //ret.m_root1 = DialogNode.CreateInstance(_tree.m_root1);
     //return ret;
     return(Instantiate(_tree));
 }
Example #22
0
 void ChangeIterator()
 {
     iterator = iterator.yes;
     if (iterator != null)
     {
         WriteNextDialog();
     }
 }
Example #23
0
        public void Start()
        {
            NpcChatProject   project = new NpcChatProject();
            DialogTree       tree    = project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch start   = tree.GetStart();

            Assert.NotNull(start, "There should be a default start node when creating a dialog tree");
        }
Example #24
0
    // Use this for initialization
    void Awake()
    {
        s = this;

        /*if(!Application.isEditor)
         * if (dialogs.Length > 0)
         *      dialogs [dialogs.Length - 1].callWhenDone.AddListener (EndDialog);*/
    }
        public void DuplicateIdTest()
        {
            DialogTree       tree   = m_project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch branch = tree.CreateNewBranch();
            DialogSegment    one    = branch.CreateNewDialog(12);
            DialogSegment    two    = branch.CreateNewDialog(13);

            Assert.AreNotEqual(one.Id, two.Id);
        }
        public void DuplicateIdTest()
        {
            DialogTree       tree    = m_project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch branch1 = tree.CreateNewBranch();
            DialogTreeBranch branch2 = tree.CreateNewBranch();

            Assert.AreEqual(branch1.Id.DialogTreeId, branch2.Id.DialogTreeId);
            Assert.AreNotEqual(branch1.Id.DialogTreeBranchId, branch2.Id.DialogTreeBranchId);
        }
Example #27
0
    void CreateTree()
    {
        DialogTree dt = DialogTree.CreateInstance(Name);
        Dictionary <string, DialogNode> keyValuePairs = new Dictionary <string, DialogNode>();

        AssetDatabase.CreateAsset(dt, "Assets/" + Location + Name + ".asset");
        dt.m_root1 = RecursiveCreation(Root);
        AssetDatabase.SaveAssets();
    }
Example #28
0
        public void GetBranch()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch aBranch = tree.CreateNewBranch();

            Assert.AreSame(aBranch, tree.GetBranch(aBranch));
        }
        public void NullRemove()
        {
            DialogTree       tree   = m_project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch branch = tree.CreateNewBranch();
            DialogSegment    one    = branch.CreateNewDialog(12);

            // remove existing
            Assert.IsFalse(branch.RemoveDialog((DialogSegment)null));
            Assert.IsFalse(branch.RemoveDialog((DialogSegmentIdentifier)null));
        }
Example #30
0
        public void GetBranchFromAnotherTree()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();
            DialogTree     tree2   = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch aBranch = tree.CreateNewBranch();

            Assert.Null(tree2.GetBranch(aBranch));
        }
 public static ITree getTreeFromFile(string path,TreeType treeType,  GlobalFlags gf)
 {
     ITree t = null;
         List<ITreeNode> treeNodeList = null;
         switch (treeType)
         {
             case TreeType.World:
                 WorldTree worldTree = new WorldTree(gf, treeType);
                     treeNodeList = getTreeNodeListFromFile(path,treeType);
                    worldTree.treeNodeDictionary = getWorldTreeNodeFromList(treeNodeList);
                    worldTree.currentIndex = treeNodeList[0].index;
                 t = worldTree;
                 break;
             case TreeType.Zone:
                 ZoneTree zoneTree = new ZoneTree(gf, treeType);
                    treeNodeList = getTreeNodeListFromFile(path,treeType);
                    zoneTree.treeNodeDictionary = getZoneTreeNodeFromList(treeNodeList);
                    zoneTree.currentIndex = treeNodeList[0].index;
                    t = zoneTree;
                 break;
             case TreeType.Dialog:
                 DialogTree dialogTree = new DialogTree(gf, treeType);
                     treeNodeList = getTreeNodeListFromFile(path,treeType);
                     dialogTree.treeNodeDictionary = getDialogTreeNodeFromList(treeNodeList);
                     dialogTree.currentIndex = treeNodeList[0].index;
                     t = dialogTree;
                 break;
             case TreeType.Quest:
                 QuestTree questTree = new QuestTree(gf, treeType);
                     treeNodeList = getTreeNodeListFromFile(path,treeType);
                     questTree.treeNodeDictionary = getQuestTreeNodeFromList(treeNodeList);
                     questTree.currentIndex = treeNodeList[0].index;
                     t = questTree;
                 break;
             default:
                 break;
         }
         return t;
 }
 public static ITree getTreeFromString(string data, TreeType treeType, GlobalFlags gf)
 {
     ITree t = null;
         List<ITreeNode> treeNodeList = null;
         switch (treeType)
         {
             case TreeType.World:
                 WorldTree worldTree = new WorldTree(gf, treeType);
                 treeNodeList = getTreeNodeListFromString(data, treeType);
                 worldTree.treeNodeDictionary = getWorldTreeNodeFromList(treeNodeList);
                 worldTree.currentIndex = treeNodeList[0].index;
                 t = worldTree;
                 break;
             case TreeType.Zone:
                 ZoneTree zoneTree = new ZoneTree(gf, treeType);
                 treeNodeList = getTreeNodeListFromString(data, treeType);
                 zoneTree.treeNodeDictionary = getZoneTreeNodeFromList(treeNodeList);
                 zoneTree.currentIndex = treeNodeList[0].index;
                 t = zoneTree;
                 break;
             case TreeType.Dialog:
                 DialogTree dialogTree = new DialogTree(gf, treeType);
                 treeNodeList = getTreeNodeListFromString(data, treeType);
                 dialogTree.treeNodeDictionary = getDialogTreeNodeFromList(treeNodeList);
                 dialogTree.currentIndex = treeNodeList[0].index;
                 t = dialogTree;
                 break;
             case TreeType.Quest:
                 QuestTree questTree = new QuestTree(gf, treeType);
                 treeNodeList = getTreeNodeListFromString(data, treeType);
                 questTree.treeNodeDictionary = getQuestTreeNodeFromList(treeNodeList);
                 questTree.currentIndex = treeNodeList[0].index;
                 t = questTree;
                 break;
             case TreeType.Battle:
                 BattleTree battleTree = new BattleTree(gf, treeType);
                 treeNodeList = getTreeNodeListFromString(data, treeType);
                 battleTree.treeNodeDictionary = getBattleTreeNodeFromList(treeNodeList);
                 battleTree.currentIndex = treeNodeList[0].index;
                 t = battleTree;
                 break;
             case TreeType.Info:
                 InfoTree infoTree = new InfoTree(gf, treeType);
                 treeNodeList = getTreeNodeListFromString(data, treeType);
                 infoTree.treeNodeDictionary = getInfoTreeNodeFromList(treeNodeList);
                 infoTree.currentIndex = treeNodeList[0].index;
                 t = infoTree;
                 break;
             default:
                 break;
         }
         return t;
 }